use of org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen in project webpieces by deanhiller.
the class TestSslBasicSvr method setup.
@Before
public void setup() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
System.setProperty("jdk.tls.server.protocols", "TLSv1.2");
System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
SSLEngineFactoryForTestOld sslFactory = new SSLEngineFactoryForTestOld();
MeterRegistry meters = Metrics.globalRegistry;
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, meters);
ChannelManager mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), new DirectExecutor());
AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(mgr, meters);
server = svrMgr.createTcpServer(new AsyncConfig(), listener, sslFactory);
XFuture<Void> future = server.start(new InetSocketAddress(8443));
Assert.assertFalse(future.isDone());
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
future.get(2, TimeUnit.SECONDS);
BufferPool pool = new TwoPools("p1", new SimpleMeterRegistry());
SSLEngine clientSsl = sslFactory.createEngineForSocket();
SSLMetrics sslMetrics = new SSLMetrics("", meters);
clientSslParser = AsyncSSLFactory.create("svr", clientSsl, pool, sslMetrics);
SslAction result = clientSslParser.beginHandshake();
// simulate the jdk firing the selector with a new channel...
mockSvrChannel.addNewChannel(mockChannel);
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
// assert connectionOpened was called with value of isReadyForWrites=false
// (This feature is specifically so clients can start a time and timeout the connection if they do not
// receive a valid payload in a certain amount of time).
ConnectionOpen connectionOpenedInfo = listener.getConnectionOpenedInfo();
channel = connectionOpenedInfo.channel;
Assert.assertEquals(false, connectionOpenedInfo.isReadyForWrites);
mockChannel.setNumBytesToConsume(100000);
mockChannel.forceDataRead(mockJdk, result.getEncryptedData());
}
use of org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen in project webpieces by deanhiller.
the class TestSslCloseSvr method setup.
@Before
public void setup() throws GeneralSecurityException, IOException, InterruptedException, ExecutionException, TimeoutException {
System.setProperty("jdk.tls.server.protocols", "TLSv1.2");
System.setProperty("jdk.tls.client.protocols", "TLSv1.2");
server = createServer();
clientSslParser = createClientParser();
XFuture<Void> future = server.start(new InetSocketAddress(8443));
Assert.assertFalse(future.isDone());
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
future.get(2, TimeUnit.SECONDS);
SslAction result = clientSslParser.beginHandshake();
// simulate the jdk firing the selector with a new channel...
mockSvrChannel.addNewChannel(mockChannel);
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
// assert connectionOpened was called with value of isReadyForWrites=false
// (This feature is specifically so clients can start a time and timeout the connection if they do not
// receive a valid payload in a certain amount of time).
ConnectionOpen connectionOpenedInfo = listener.getConnectionOpenedInfo();
channel = connectionOpenedInfo.channel;
Assert.assertEquals(false, connectionOpenedInfo.isReadyForWrites);
mockChannel.setNumBytesToConsume(100000);
mockChannel.forceDataRead(mockJdk, result.getEncryptedData());
// 3 encrypted packets sent here
SslAction action = parseIncoming();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, parseIncoming().getSslAction());
ConnectionOpen openedInfo = listener.getConnectionOpenedInfo();
Assert.assertEquals(true, openedInfo.isReadyForWrites);
Assert.assertEquals(channel, openedInfo.channel);
transferBigData();
}
use of org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen in project webpieces by deanhiller.
the class TestSslBasicSvr method testSplitData.
// @Test
public void testSplitData() throws InterruptedException, ExecutionException, TimeoutException {
// 3 encrypted packets sent here
SslAction action = parseIncoming();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
List<DataWrapper> split = split(action.getEncryptedData());
DataWrapper back = dataGen.chainDataWrappers(split.get(0), split.get(1), split.get(2), split.get(3));
byte[] b1 = action.getEncryptedData().createByteArray();
byte[] b2 = back.createByteArray();
Assert.assertEquals(b1.length, b2.length);
for (int i = 0; i < b1.length; i++) {
Assert.assertEquals(b1[i], b2[i]);
}
mockChannel.forceDataRead(mockJdk, split.get(0));
Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
mockChannel.forceDataRead(mockJdk, split.get(1));
Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
mockChannel.forceDataRead(mockJdk, split.get(2));
Assert.assertEquals(0, mockChannel.getPayloadQueueSize());
mockChannel.forceDataRead(mockJdk, split.get(3));
Assert.assertEquals(2, mockChannel.getPayloadQueueSize());
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, parseIncoming().getSslAction());
ConnectionOpen openedInfo = listener.getConnectionOpenedInfo();
Assert.assertEquals(true, openedInfo.isReadyForWrites);
Assert.assertEquals(channel, openedInfo.channel);
transferBigData();
}
use of org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen in project webpieces by deanhiller.
the class TestSslBasicSvr method testBasic.
// begin handshake results in ONE packet client -> server (server creates runnable, creating ONE
// server creates runnable, runs it creating ONE packet server -> client
// client creates runnable, runs it creating THREE packets client -> server
// all 3 received, server creates TWO packets client -> server (server is connected here)
// client receives two packets and is connected
// @Test
public void testBasic() throws InterruptedException, ExecutionException, TimeoutException, GeneralSecurityException, IOException {
// 3 encrypted packets sent here
SslAction action = parseIncoming();
Assert.assertEquals(SslActionEnum.SEND_TO_SOCKET, action.getSslAction());
mockChannel.forceDataRead(mockJdk, action.getEncryptedData());
Assert.assertEquals(SslActionEnum.WAIT_FOR_MORE_DATA_FROM_REMOTE_END, parseIncoming().getSslAction());
Assert.assertEquals(SslActionEnum.SEND_LINK_ESTABLISHED_TO_APP, parseIncoming().getSslAction());
ConnectionOpen openedInfo = listener.getConnectionOpenedInfo();
Assert.assertEquals(true, openedInfo.isReadyForWrites);
Assert.assertEquals(channel, openedInfo.channel);
transferBigData();
}
Aggregations