Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java')
-rw-r--r--jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java72
1 files changed, 67 insertions, 5 deletions
diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
index 3df4d2352c..06d11bd49f 100644
--- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
+++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java
@@ -35,6 +35,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
+import org.eclipse.jetty.io.SelectorManager.ManagedSelector;
import org.eclipse.jetty.io.ssl.SslConnection;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.BufferUtil;
@@ -88,14 +89,45 @@ public class SslConnectionTest
@Override
protected SelectChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector selectSet, SelectionKey selectionKey) throws IOException
{
- SelectChannelEndPoint endp = new SelectChannelEndPoint(channel,selectSet, selectionKey, getScheduler(), 60000);
+ SelectChannelEndPoint endp = new TestEP(channel,selectSet, selectionKey, getScheduler(), 60000);
_lastEndp=endp;
return endp;
}
};
- // Must be volatile or the test may fail spuriously
- protected volatile int _blockAt=0;
+ static final AtomicInteger __startBlocking = new AtomicInteger();
+ static final AtomicInteger __blockFor = new AtomicInteger();
+ private static class TestEP extends SelectChannelEndPoint
+ {
+
+ public TestEP(SocketChannel channel, ManagedSelector selector, SelectionKey key, Scheduler scheduler, long idleTimeout)
+ {
+ super(channel,selector,key,scheduler,idleTimeout);
+ }
+
+ @Override
+ protected void onIncompleteFlush()
+ {
+ super.onIncompleteFlush();
+ }
+
+
+ @Override
+ public boolean flush(ByteBuffer... buffers) throws IOException
+ {
+ if (__startBlocking.get()==0 || __startBlocking.decrementAndGet()==0)
+ {
+ if (__blockFor.get()>0 && __blockFor.getAndDecrement()>0)
+ {
+ return false;
+ }
+ }
+ String s=BufferUtil.toDetailString(buffers[0]);
+ boolean flushed=super.flush(buffers);
+ return flushed;
+ }
+ }
+
@BeforeClass
public static void initSslEngine() throws Exception
@@ -138,7 +170,7 @@ public class SslConnectionTest
public TestConnection(EndPoint endp)
{
- super(endp, _threadPool,false);
+ super(endp, _threadPool,true);
}
@Override
@@ -245,7 +277,7 @@ public class SslConnectionTest
len=5;
while(len>0)
len-=client.getInputStream().read(buffer);
- Assert.assertEquals(0, _dispatches.get());
+ Assert.assertEquals(1, _dispatches.get());
client.close();
}
@@ -270,6 +302,36 @@ public class SslConnectionTest
Assert.assertEquals(null,_writeCallback.get(100,TimeUnit.MILLISECONDS));
client.close();
}
+
+
+
+ @Test
+ public void testBlockedWrite() throws Exception
+ {
+ Socket client = newClient();
+ client.setSoTimeout(60000);
+
+ SocketChannel server = _connector.accept();
+ server.configureBlocking(false);
+ _manager.accept(server);
+
+ __startBlocking.set(5);
+ __blockFor.set(3);
+
+ client.getOutputStream().write("Hello".getBytes(StandardCharsets.UTF_8));
+ byte[] buffer = new byte[1024];
+ int len=client.getInputStream().read(buffer);
+ Assert.assertEquals(5, len);
+ Assert.assertEquals("Hello",new String(buffer,0,len,StandardCharsets.UTF_8));
+
+ _dispatches.set(0);
+ client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
+ len=5;
+ while(len>0)
+ len-=client.getInputStream().read(buffer);
+ Assert.assertEquals(0, len);
+ client.close();
+ }
@Test
public void testManyLines() throws Exception

Back to the top