Issue #2135 - Correct testHelloWorld failure by backporting test from 9.4.x

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
Joakim Erdfelt 2018-06-06 14:24:53 -05:00
parent c4ea4a2d96
commit df29e292af
1 changed files with 26 additions and 19 deletions

View File

@ -45,6 +45,7 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.util.thread.Scheduler;
import org.eclipse.jetty.util.thread.TimerScheduler;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
@ -139,6 +140,12 @@ public class SslConnectionTest
__sslCtxFactory.start();
}
@AfterClass
public static void stopSsl() throws Exception
{
__sslCtxFactory.stop();
}
@Before
public void startManager() throws Exception
{
@ -259,27 +266,27 @@ public class SslConnectionTest
@Test
public void testHelloWorld() throws Exception
{
Socket client = newClient();
client.setSoTimeout(60000);
try (Socket client = newClient())
{
client.setSoTimeout(60000);
try (SocketChannel server = _connector.accept())
{
server.configureBlocking(false);
_manager.accept(server);
SocketChannel server = _connector.accept();
server.configureBlocking(false);
_manager.accept(server);
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));
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(1, _dispatches.get());
client.close();
_dispatches.set(0);
client.getOutputStream().write("World".getBytes(StandardCharsets.UTF_8));
len = 5;
while (len > 0)
len -= client.getInputStream().read(buffer);
}
}
}