Made the test pass under Windows.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2954 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Simone Bordet 2011-04-01 15:26:21 +00:00
parent 35558971d9
commit c7cd3c3233
1 changed files with 16 additions and 32 deletions

View File

@ -14,11 +14,9 @@
package org.eclipse.jetty.server.session; package org.eclipse.jetty.server.session;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.util.Random; import java.util.Random;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.client.ContentExchange; import org.eclipse.jetty.client.ContentExchange;
@ -27,34 +25,23 @@ import org.eclipse.jetty.http.HttpMethods;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
/** /**
* AbstractWebAppObjectInSessionTest * AbstractWebAppObjectInSessionTest
* *
* Target of this test is to check that when a webapp on nodeA puts in the session * Target of this test is to check that when a webapp on nodeA puts in the session
* an object of a class loaded from the war (and hence with a WebAppClassLoader), * an object of a class loaded from the war (and hence with a WebAppClassLoader),
* the same webapp on nodeB is able to load that object from the session. * the same webapp on nodeB is able to load that object from the session.
* *
* This test is only appropriate for clustered session managers. * This test is only appropriate for clustered session managers.
*/ */
public abstract class AbstractWebAppObjectInSessionTest public abstract class AbstractWebAppObjectInSessionTest
{ {
public abstract AbstractTestServer createServer(int port); public abstract AbstractTestServer createServer(int port);
private void copy(File source, File target) throws Exception
{
FileInputStream input = new FileInputStream(source);
FileOutputStream output = new FileOutputStream(target);
int read = -1;
byte[] bytes = new byte[64];
while ((read = input.read(bytes)) >= 0) output.write(bytes, 0, read);
input.close();
output.close();
}
@Test @Test
public void testWebappObjectInSession() throws Exception public void testWebappObjectInSession() throws Exception
{ {
@ -85,24 +72,21 @@ public abstract class AbstractWebAppObjectInSessionTest
String packageName = WebAppObjectInSessionServlet.class.getPackage().getName(); String packageName = WebAppObjectInSessionServlet.class.getPackage().getName();
File packageDirs = new File(classesDir, packageName.replace('.', File.separatorChar)); File packageDirs = new File(classesDir, packageName.replace('.', File.separatorChar));
packageDirs.mkdirs(); packageDirs.mkdirs();
String resourceName = WebAppObjectInSessionServlet.class.getName().replace('.', File.separatorChar) + ".class";
String resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + ".class";
Resource resource = Resource.newResource(getClass().getResource(resourceName));
Resource res = Resource.newResource(getClass().getClassLoader().getResource(resourceName));
//File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI());
//File sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); File targetFile = new File(packageDirs, resourceName);
File targetFile = new File(packageDirs, resourceName.substring(packageName.length()));
//copy(sourceFile, targetFile); //copy(sourceFile, targetFile);
resourceName = WebAppObjectInSessionServlet.TestSharedNonStatic.class.getName().replace('.', File.separatorChar) + ".class"; IO.copy(resource.getInputStream(), new FileOutputStream(targetFile));
IO.copy(res.getInputStream(), new FileOutputStream(targetFile));
resourceName = WebAppObjectInSessionServlet.class.getSimpleName() + "$" + WebAppObjectInSessionServlet.TestSharedStatic.class.getSimpleName() + ".class";
resource = Resource.newResource(getClass().getResource(resourceName));
resourceName = WebAppObjectInSessionServlet.TestSharedStatic.class.getName().replace('.', File.separatorChar) + ".class";
res = Resource.newResource(getClass().getClassLoader().getResource(resourceName));
//sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI()); //sourceFile = new File(getClass().getClassLoader().getResource(resourceName).toURI());
targetFile = new File(packageDirs, resourceName.substring(packageName.length())); targetFile = new File(packageDirs, resourceName);
//copy(sourceFile, targetFile); //copy(sourceFile, targetFile);
IO.copy(res.getInputStream(), new FileOutputStream(targetFile)); IO.copy(resource.getInputStream(), new FileOutputStream(targetFile));
Random random = new Random(System.nanoTime()); Random random = new Random(System.nanoTime());
int port1 = random.nextInt(50000) + 10000; int port1 = random.nextInt(50000) + 10000;
@ -141,7 +125,7 @@ public abstract class AbstractWebAppObjectInSessionTest
exchange2.getRequestFields().add("Cookie", sessionCookie); exchange2.getRequestFields().add("Cookie", sessionCookie);
client.send(exchange2); client.send(exchange2);
exchange2.waitForDone(); exchange2.waitForDone();
assertEquals(HttpServletResponse.SC_OK,exchange2.getResponseStatus()); assertEquals(HttpServletResponse.SC_OK,exchange2.getResponseStatus());
} }
finally finally