Search in sources :

Example 41 with TwoPools

use of org.webpieces.data.api.TwoPools 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 42 with TwoPools

use of org.webpieces.data.api.TwoPools 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)

Example 43 with TwoPools

use of org.webpieces.data.api.TwoPools in project webpieces by deanhiller.

the class TestBackpressure method create4BuffersWith3Messags.

private List<ByteBuffer> create4BuffersWith3Messags() {
    HpackStatefulParser parser = HpackParserFactory.createStatefulParser(new TwoPools("pl", new SimpleMeterRegistry()), new HpackConfig("tests"));
    Http2Response response1 = Requests.createResponse(1);
    DataFrame response2 = Requests.createBigData(1, false);
    DataFrame response3 = Requests.createBigData(1, true);
    DataWrapper buf1 = parser.marshal(response1);
    DataWrapper buf2 = parser.marshal(response2);
    DataWrapper buf3 = parser.marshal(response3);
    // one big wrapper that we can slice up..
    DataWrapper all = DATA_GEN.chainDataWrappers(buf1, buf2, buf3);
    byte[] part1 = all.readBytesAt(0, 10);
    byte[] part2 = all.readBytesAt(10, buf1.getReadableSize());
    byte[] part3 = all.readBytesAt(10 + buf1.getReadableSize(), buf2.getReadableSize());
    int offset = 10 + buf1.getReadableSize() + buf2.getReadableSize();
    int remaining = all.getReadableSize() - offset;
    byte[] part4 = all.readBytesAt(offset, remaining);
    List<ByteBuffer> buffers = new ArrayList<>();
    buffers.add(ByteBuffer.wrap(part1));
    buffers.add(ByteBuffer.wrap(part2));
    buffers.add(ByteBuffer.wrap(part3));
    buffers.add(ByteBuffer.wrap(part4));
    return buffers;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) HpackStatefulParser(com.webpieces.hpack.api.HpackStatefulParser) TwoPools(org.webpieces.data.api.TwoPools) HpackConfig(com.webpieces.hpack.api.HpackConfig) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TwoPools (org.webpieces.data.api.TwoPools)43 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)39 Before (org.junit.Before)15 BufferPool (org.webpieces.data.api.BufferPool)15 ChannelManager (org.webpieces.nio.api.ChannelManager)12 InetSocketAddress (java.net.InetSocketAddress)11 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)11 NamedThreadFactory (org.webpieces.util.threading.NamedThreadFactory)10 Executor (java.util.concurrent.Executor)8 SSLEngine (javax.net.ssl.SSLEngine)8 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)8 DirectExecutor (org.webpieces.util.threading.DirectExecutor)8 ByteBuffer (java.nio.ByteBuffer)7 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)7 BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)7 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)6 HttpParser (org.webpieces.httpparser.api.HttpParser)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)5 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)5 ArrayList (java.util.ArrayList)4