Search in sources :

Example 11 with TwoPools

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

the class TestHttp1Backpressure method create4BuffersWith3Messags.

private List<ByteBuffer> create4BuffersWith3Messags(Http2Response response1, HttpChunk response2, HttpLastChunk lastChunk) {
    HttpStatefulParser parser = HttpParserFactory.createStatefulParser("a", new SimpleMeterRegistry(), new TwoPools("pl", new SimpleMeterRegistry()));
    HttpResponse resp1 = Http2ToHttp11.translateResponse(response1);
    ByteBuffer buf1 = parser.marshalToByteBuffer(resp1);
    ByteBuffer buf2 = parser.marshalToByteBuffer(response2);
    ByteBuffer buf3 = parser.marshalToByteBuffer(lastChunk);
    byte[] part1 = new byte[10];
    byte[] part2 = new byte[buf1.remaining()];
    buf1.get(part1);
    int toWrite = buf1.remaining();
    buf1.get(part2, 0, toWrite);
    buf2.get(part2, toWrite, part2.length - toWrite);
    byte[] part3 = new byte[buf2.remaining() + 2];
    int toWrite2 = buf2.remaining();
    buf2.get(part3, 0, toWrite2);
    buf3.get(part3, toWrite2, 2);
    byte[] part4 = new byte[buf3.remaining()];
    buf3.get(part4);
    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 : HttpStatefulParser(org.webpieces.httpparser.api.HttpStatefulParser) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) ArrayList(java.util.ArrayList) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) ByteBuffer(java.nio.ByteBuffer)

Example 12 with TwoPools

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

the class TestConnecting method setup.

@Before
public void setup() {
    BufferPool pool = new TwoPools("pl", new SimpleMeterRegistry());
    httpClient = Http2to11ClientFactory.createHttpClient("myClient2", mockChannelMgr, new SimpleMeterRegistry(), pool);
}
Also used : BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Before(org.junit.Before)

Example 13 with TwoPools

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

the class TestWriteReads method setup.

@Before
public void setup() throws InterruptedException, ExecutionException, TimeoutException {
    BufferPool pool = new TwoPools("pl", new SimpleMeterRegistry());
    httpClient = Http2to11ClientFactory.createHttpClient("myClient4", mockChannelMgr, new SimpleMeterRegistry(), pool);
    mockChannelMgr.addTCPChannelToReturn(mockChannel);
    socket = httpClient.createHttpSocket(new Http2CloseListener());
    mockChannel.setConnectFuture(XFuture.completedFuture(null));
    XFuture<Void> future = socket.connect(new InetSocketAddress(8080));
    future.get(2, TimeUnit.SECONDS);
}
Also used : Http2CloseListener(org.webpieces.httpclient.Http2CloseListener) BufferPool(org.webpieces.data.api.BufferPool) TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Before(org.junit.Before)

Example 14 with TwoPools

use of org.webpieces.data.api.TwoPools 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());
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) AsyncConfig(org.webpieces.asyncserver.api.AsyncConfig) AsyncServerManager(org.webpieces.asyncserver.api.AsyncServerManager) SslAction(org.webpieces.ssl.api.dto.SslAction) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) ConnectionOpen(org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen) BufferPool(org.webpieces.data.api.BufferPool) DirectExecutor(org.webpieces.util.threading.DirectExecutor) SSLMetrics(org.webpieces.ssl.api.SSLMetrics) Before(org.junit.Before)

Example 15 with TwoPools

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

the class IntegTestClientNotRead method testSoTimeoutOnSocket.

public void testSoTimeoutOnSocket() throws InterruptedException {
    TwoPools pool = new TwoPools("pl", new SimpleMeterRegistry());
    AsyncServerManager serverMgr = AsyncServerMgrFactory.createAsyncServer("server", pool, new BackpressureConfig(), Metrics.globalRegistry);
    AsyncServer server = serverMgr.createTcpServer(new AsyncConfig("tcpServer"), new IntegTestClientNotReadListener());
    server.start(new InetSocketAddress(8080));
    TwoPools pool2 = new TwoPools("pl", new SimpleMeterRegistry());
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(Metrics.globalRegistry);
    ChannelManager mgr = factory.createSingleThreadedChanMgr("client", pool2, new BackpressureConfig());
    TCPChannel channel = mgr.createTCPChannel("clientChan");
    log.info("client");
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            logBytesTxfrd();
        }
    }, 1000, 5000);
    XFuture<Void> connect = channel.connect(new InetSocketAddress(8080), new ClientDataListener());
    connect.thenAccept(p -> runWriting(channel));
    Thread.sleep(1000000000);
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) InetSocketAddress(java.net.InetSocketAddress) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) 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) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) TimerTask(java.util.TimerTask)

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