use of org.webpieces.nio.api.mocks.MockAsyncListener in project webpieces by deanhiller.
the class TestSvrReading method setup.
@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
MeterRegistry meters = Metrics.globalRegistry;
ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, meters);
DirectExecutor exec = new DirectExecutor();
BackpressureConfig config = new BackpressureConfig();
config.setMaxBytes(6);
config.setStartReadingThreshold(2);
ChannelManager mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), config, exec);
AsyncServerManager svrMgr = AsyncServerMgrFactory.createAsyncServer(mgr, meters);
listener = new MockAsyncListener();
AsyncServer server = svrMgr.createTcpServer(new AsyncConfig(), listener);
XFuture<Void> future = server.start(new InetSocketAddress(4444));
Assert.assertFalse(future.isDone());
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
future.get(2, TimeUnit.SECONDS);
mockSvrChannel.addNewChannel(mockChannel);
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
Assert.assertEquals(1, listener.getNumTimesCalledConnectionOpen());
}
use of org.webpieces.nio.api.mocks.MockAsyncListener in project webpieces by deanhiller.
the class TestAccepting method testBasicConnectingOnSelectorThread.
@Test
public void testBasicConnectingOnSelectorThread() {
MockAsyncListener listener = new MockAsyncListener();
AsyncServer server = svrMgr.createTcpServer(new AsyncConfig(), listener);
XFuture<Void> future = server.start(new InetSocketAddress(4444));
Assert.assertFalse(future.isDone());
mockSvrChannel.addNewChannel(mockChannel);
mockJdk.setThread(Thread.currentThread());
mockJdk.fireSelector();
Assert.assertEquals(1, listener.getNumTimesCalledConnectionOpen());
}
Aggregations