Search in sources :

Example 6 with MockDataListener

use of org.webpieces.nio.api.mocks.MockDataListener in project webpieces by deanhiller.

the class TestReading method setup.

@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    DirectExecutor exec = new DirectExecutor();
    BackpressureConfig config = new BackpressureConfig();
    config.setMaxBytes(6);
    config.setStartReadingThreshold(2);
    mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), config, exec);
    listener = new MockDataListener();
    channel = mgr.createTCPChannel("myid");
    mockChannel.addConnectReturnValue(true);
    mockJdk.setThread(Thread.currentThread());
    XFuture<Void> future = channel.connect(new InetSocketAddress(4444), listener);
    future.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(mockChannel.isRegisteredForReads());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MockDataListener(org.webpieces.nio.api.mocks.MockDataListener) DirectExecutor(org.webpieces.util.threading.DirectExecutor) Before(org.junit.Before)

Example 7 with MockDataListener

use of org.webpieces.nio.api.mocks.MockDataListener in project webpieces by deanhiller.

the class TestWriting method setup.

@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    DirectExecutor exec = new DirectExecutor();
    mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), exec);
    MockDataListener listener = new MockDataListener();
    channel = mgr.createTCPChannel("myid");
    mockChannel.addConnectReturnValue(true);
    mockJdk.setThread(Thread.currentThread());
    XFuture<Void> future = channel.connect(new InetSocketAddress(4444), listener);
    future.get(2, TimeUnit.SECONDS);
    Assert.assertTrue(mockChannel.isRegisteredForReads());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MockDataListener(org.webpieces.nio.api.mocks.MockDataListener) DirectExecutor(org.webpieces.util.threading.DirectExecutor) Before(org.junit.Before)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)7 MockDataListener (org.webpieces.nio.api.mocks.MockDataListener)7 Test (org.junit.Test)5 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)5 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)2 Before (org.junit.Before)2 TwoPools (org.webpieces.data.api.TwoPools)2 DirectExecutor (org.webpieces.util.threading.DirectExecutor)2 NioException (org.webpieces.util.exceptions.NioException)1