Merge branch 'master' of ssh://git.eclipse.org/gitroot/jetty/org.eclipse.jetty.project
This commit is contained in:
commit
8e38c52431
|
@ -18,9 +18,6 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
@ -29,22 +26,29 @@ import java.io.PrintWriter;
|
|||
import java.net.Socket;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.eclipse.jetty.io.ArrayByteBufferPool;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
import org.eclipse.jetty.toolchain.test.http.SimpleHttpParser;
|
||||
import org.eclipse.jetty.toolchain.test.http.SimpleHttpResponse;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.StdErrLog;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public abstract class AbstractHttpTest
|
||||
{
|
||||
@Rule
|
||||
public TestTracker tracker = new TestTracker();
|
||||
|
||||
protected static Server server;
|
||||
protected static ServerConnector connector;
|
||||
protected String httpVersion;
|
||||
|
@ -80,11 +84,10 @@ public abstract class AbstractHttpTest
|
|||
socket.setSoTimeout((int)connector.getIdleTimeout());
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8));
|
||||
PrintWriter writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||
String request = "GET / " + httpVersion + "\r\n";
|
||||
|
||||
writer.write(request);
|
||||
writer.write("Host: localhost");
|
||||
writer.println("\r\n");
|
||||
writer.write("GET / " + httpVersion + "\r\n");
|
||||
writer.write("Host: localhost\r\n");
|
||||
writer.write("\r\n");
|
||||
writer.flush();
|
||||
|
||||
SimpleHttpResponse response = httpParser.readResponse(reader);
|
||||
|
|
|
@ -411,7 +411,6 @@ public abstract class IteratingCallback implements Callback
|
|||
case IDLE:
|
||||
case SUCCEEDED:
|
||||
case FAILED:
|
||||
case PROCESSING:
|
||||
_state=State.CLOSED;
|
||||
break;
|
||||
|
||||
|
|
|
@ -24,40 +24,40 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
|
||||
import org.eclipse.jetty.util.thread.Scheduler;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class IteratingCallbackTest
|
||||
{
|
||||
static Scheduler scheduler = new ScheduledExecutorScheduler();
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception
|
||||
private Scheduler scheduler;
|
||||
|
||||
@Before
|
||||
public void prepare() throws Exception
|
||||
{
|
||||
scheduler = new ScheduledExecutorScheduler();
|
||||
scheduler.start();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception
|
||||
|
||||
@After
|
||||
public void dispose() throws Exception
|
||||
{
|
||||
scheduler.stop();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNonWaitingProcess() throws Exception
|
||||
{
|
||||
|
||||
TestCB cb=new TestCB()
|
||||
TestCB cb = new TestCB()
|
||||
{
|
||||
int i=10;
|
||||
|
||||
int i = 10;
|
||||
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
processed++;
|
||||
if (i-->1)
|
||||
if (i-- > 1)
|
||||
{
|
||||
succeeded(); // fake a completed IO operation
|
||||
return Action.SCHEDULED;
|
||||
|
@ -65,61 +65,59 @@ public class IteratingCallbackTest
|
|||
return Action.SUCCEEDED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
Assert.assertTrue(cb.waitForComplete());
|
||||
Assert.assertEquals(10,cb.processed);
|
||||
Assert.assertTrue(cb.waitForComplete());
|
||||
Assert.assertEquals(10, cb.processed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testWaitingProcess() throws Exception
|
||||
{
|
||||
TestCB cb=new TestCB()
|
||||
TestCB cb = new TestCB()
|
||||
{
|
||||
int i=4;
|
||||
|
||||
int i = 4;
|
||||
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
processed++;
|
||||
if (i-->1)
|
||||
if (i-- > 1)
|
||||
{
|
||||
scheduler.schedule(successTask,50,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(successTask, 50, TimeUnit.MILLISECONDS);
|
||||
return Action.SCHEDULED;
|
||||
}
|
||||
return Action.SUCCEEDED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
|
||||
|
||||
Assert.assertTrue(cb.waitForComplete());
|
||||
|
||||
Assert.assertEquals(4,cb.processed);
|
||||
|
||||
Assert.assertEquals(4, cb.processed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWaitingProcessSpuriousInterate() throws Exception
|
||||
public void testWaitingProcessSpuriousIterate() throws Exception
|
||||
{
|
||||
final TestCB cb=new TestCB()
|
||||
final TestCB cb = new TestCB()
|
||||
{
|
||||
int i=4;
|
||||
|
||||
int i = 4;
|
||||
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
processed++;
|
||||
if (i-->1)
|
||||
if (i-- > 1)
|
||||
{
|
||||
scheduler.schedule(successTask,50,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(successTask, 50, TimeUnit.MILLISECONDS);
|
||||
return Action.SCHEDULED;
|
||||
}
|
||||
return Action.SUCCEEDED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
scheduler.schedule(new Runnable()
|
||||
{
|
||||
|
@ -128,29 +126,29 @@ public class IteratingCallbackTest
|
|||
{
|
||||
cb.iterate();
|
||||
if (!cb.isSucceeded())
|
||||
scheduler.schedule(this,50,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(this, 50, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
},49,TimeUnit.MILLISECONDS);
|
||||
|
||||
}, 49, TimeUnit.MILLISECONDS);
|
||||
|
||||
Assert.assertTrue(cb.waitForComplete());
|
||||
|
||||
Assert.assertEquals(4,cb.processed);
|
||||
|
||||
Assert.assertEquals(4, cb.processed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonWaitingProcessFailure() throws Exception
|
||||
{
|
||||
TestCB cb=new TestCB()
|
||||
TestCB cb = new TestCB()
|
||||
{
|
||||
int i=10;
|
||||
|
||||
int i = 10;
|
||||
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
processed++;
|
||||
if (i-->1)
|
||||
if (i-- > 1)
|
||||
{
|
||||
if (i>5)
|
||||
if (i > 5)
|
||||
succeeded(); // fake a completed IO operation
|
||||
else
|
||||
failed(new Exception("testing"));
|
||||
|
@ -159,63 +157,63 @@ public class IteratingCallbackTest
|
|||
return Action.SUCCEEDED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
Assert.assertFalse(cb.waitForComplete());
|
||||
Assert.assertEquals(5,cb.processed);
|
||||
Assert.assertFalse(cb.waitForComplete());
|
||||
Assert.assertEquals(5, cb.processed);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWaitingProcessFailure() throws Exception
|
||||
{
|
||||
TestCB cb=new TestCB()
|
||||
TestCB cb = new TestCB()
|
||||
{
|
||||
int i=4;
|
||||
|
||||
int i = 4;
|
||||
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
processed++;
|
||||
if (i-->1)
|
||||
if (i-- > 1)
|
||||
{
|
||||
scheduler.schedule(i>2?successTask:failTask,50,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(i > 2 ? successTask : failTask, 50, TimeUnit.MILLISECONDS);
|
||||
return Action.SCHEDULED;
|
||||
}
|
||||
return Action.SUCCEEDED;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
|
||||
|
||||
Assert.assertFalse(cb.waitForComplete());
|
||||
Assert.assertEquals(2,cb.processed);
|
||||
Assert.assertEquals(2, cb.processed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testIdleWaiting() throws Exception
|
||||
{
|
||||
final CountDownLatch idle = new CountDownLatch(1);
|
||||
|
||||
TestCB cb=new TestCB()
|
||||
|
||||
TestCB cb = new TestCB()
|
||||
{
|
||||
int i=5;
|
||||
|
||||
int i = 5;
|
||||
|
||||
@Override
|
||||
protected Action process()
|
||||
{
|
||||
processed++;
|
||||
|
||||
switch(i--)
|
||||
|
||||
switch (i--)
|
||||
{
|
||||
case 5:
|
||||
succeeded();
|
||||
return Action.SCHEDULED;
|
||||
|
||||
|
||||
case 4:
|
||||
scheduler.schedule(successTask,5,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(successTask, 5, TimeUnit.MILLISECONDS);
|
||||
return Action.SCHEDULED;
|
||||
|
||||
|
||||
case 3:
|
||||
scheduler.schedule(new Runnable()
|
||||
{
|
||||
|
@ -224,49 +222,99 @@ public class IteratingCallbackTest
|
|||
{
|
||||
idle.countDown();
|
||||
}
|
||||
},5,TimeUnit.MILLISECONDS);
|
||||
}, 5, TimeUnit.MILLISECONDS);
|
||||
return Action.IDLE;
|
||||
|
||||
case 2:
|
||||
succeeded();
|
||||
return Action.SCHEDULED;
|
||||
|
||||
|
||||
case 1:
|
||||
scheduler.schedule(successTask,5,TimeUnit.MILLISECONDS);
|
||||
scheduler.schedule(successTask, 5, TimeUnit.MILLISECONDS);
|
||||
return Action.SCHEDULED;
|
||||
|
||||
|
||||
case 0:
|
||||
return Action.SUCCEEDED;
|
||||
|
||||
default:
|
||||
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cb.iterate();
|
||||
idle.await(10,TimeUnit.SECONDS);
|
||||
idle.await(10, TimeUnit.SECONDS);
|
||||
Assert.assertTrue(cb.isIdle());
|
||||
|
||||
|
||||
cb.iterate();
|
||||
Assert.assertTrue(cb.waitForComplete());
|
||||
Assert.assertEquals(6,cb.processed);
|
||||
Assert.assertEquals(6, cb.processed);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testCloseDuringProcessingReturningScheduled() throws Exception
|
||||
{
|
||||
testCloseDuringProcessing(IteratingCallback.Action.SCHEDULED);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCloseDuringProcessingReturningSucceeded() throws Exception
|
||||
{
|
||||
testCloseDuringProcessing(IteratingCallback.Action.SUCCEEDED);
|
||||
}
|
||||
|
||||
private void testCloseDuringProcessing(final IteratingCallback.Action action) throws Exception
|
||||
{
|
||||
final CountDownLatch failureLatch = new CountDownLatch(1);
|
||||
IteratingCallback callback = new IteratingCallback()
|
||||
{
|
||||
@Override
|
||||
protected Action process() throws Exception
|
||||
{
|
||||
close();
|
||||
return action;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCompleteFailure(Throwable cause)
|
||||
{
|
||||
failureLatch.countDown();
|
||||
}
|
||||
};
|
||||
|
||||
callback.iterate();
|
||||
|
||||
Assert.assertTrue(failureLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
private abstract static class TestCB extends IteratingCallback
|
||||
{
|
||||
CountDownLatch completed = new CountDownLatch(1);
|
||||
int processed=0;
|
||||
protected Runnable successTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
succeeded();
|
||||
}
|
||||
};
|
||||
protected Runnable failTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
failed(new Exception("testing failure"));
|
||||
}
|
||||
};
|
||||
protected CountDownLatch completed = new CountDownLatch(1);
|
||||
protected int processed = 0;
|
||||
|
||||
@Override
|
||||
protected void onCompleteSuccess()
|
||||
{
|
||||
completed.countDown();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCompleteFailure(Throwable x)
|
||||
{
|
||||
|
@ -275,26 +323,8 @@ public class IteratingCallbackTest
|
|||
|
||||
boolean waitForComplete() throws InterruptedException
|
||||
{
|
||||
completed.await(10,TimeUnit.SECONDS);
|
||||
completed.await(10, TimeUnit.SECONDS);
|
||||
return isSucceeded();
|
||||
}
|
||||
|
||||
Runnable successTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
succeeded();
|
||||
}
|
||||
};
|
||||
Runnable failTask = new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
failed(new Exception("testing failure"));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1058,9 +1058,8 @@ public class FileSystemResourceTest
|
|||
|
||||
try (Resource fileres = newResource(refQuoted))
|
||||
{
|
||||
// FileResource on OSX does not pass this test!
|
||||
// on OSX "foo's.txt" with FileResource becomes "foo%27s.txt" incorrectly.
|
||||
assumeFalse( (fileres instanceof FileResource) && (OS.IS_OSX) );
|
||||
// This test does not pass on FileResource
|
||||
assumeFalse(fileres instanceof FileResource);
|
||||
|
||||
assertThat("Exists: " + refQuoted,fileres.exists(),is(true));
|
||||
assertThat("Alias: " + refQuoted,fileres,hasNoAlias());
|
||||
|
|
Loading…
Reference in New Issue