Search in sources :

Example 1 with MockAsyncListener

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());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) MockAsyncListener(org.webpieces.nio.api.mocks.MockAsyncListener) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) Before(org.junit.Before)

Example 2 with MockAsyncListener

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());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) AsyncServer(org.webpieces.asyncserver.api.AsyncServer) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) MockAsyncListener(org.webpieces.nio.api.mocks.MockAsyncListener) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)2 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)2 MockAsyncListener (org.webpieces.nio.api.mocks.MockAsyncListener)2 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)1 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)1 Before (org.junit.Before)1 Test (org.junit.Test)1 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)1 TwoPools (org.webpieces.data.api.TwoPools)1 DirectExecutor (org.webpieces.util.threading.DirectExecutor)1