Search in sources :

Example 1 with DirectExecutor

use of org.webpieces.util.threading.DirectExecutor in project webpieces by deanhiller.

the class TestConnecting method setup.

@Before
public void setup() {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    DirectExecutor exec = new DirectExecutor();
    mgr = factory.createMultiThreadedChanMgr("test'n", new TwoPools("pl", new SimpleMeterRegistry()), new BackpressureConfig(), exec);
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) Before(org.junit.Before)

Example 2 with DirectExecutor

use of org.webpieces.util.threading.DirectExecutor in project webpieces by deanhiller.

the class TestSslCloseClient method createClientChannel.

public static TCPChannel createClientChannel(String name, MockJdk mockJdk) throws GeneralSecurityException, IOException {
    ChannelManagerFactory factory = ChannelManagerFactory.createFactory(mockJdk, Metrics.globalRegistry);
    BufferPool pool = new TwoPools("pClient", new SimpleMeterRegistry());
    ChannelManager chanMgr = factory.createMultiThreadedChanMgr(name + "Mgr", pool, new BackpressureConfig(), new DirectExecutor());
    MockSSLEngineFactory sslFactory = new MockSSLEngineFactory();
    SSLEngine clientSsl = sslFactory.createEngineForSocket();
    TCPChannel channel1 = chanMgr.createTCPChannel("client", clientSsl);
    return channel1;
}
Also used : BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) BufferPool(org.webpieces.data.api.BufferPool) ChannelManager(org.webpieces.nio.api.ChannelManager) TwoPools(org.webpieces.data.api.TwoPools) SSLEngine(javax.net.ssl.SSLEngine) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory)

Example 3 with DirectExecutor

use of org.webpieces.util.threading.DirectExecutor 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 4 with DirectExecutor

use of org.webpieces.util.threading.DirectExecutor 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 5 with DirectExecutor

use of org.webpieces.util.threading.DirectExecutor in project webpieces by deanhiller.

the class TestAccepting method setup.

@Before
public void setup() {
    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());
    svrMgr = AsyncServerMgrFactory.createAsyncServer(mgr, meters);
}
Also used : TwoPools(org.webpieces.data.api.TwoPools) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) DirectExecutor(org.webpieces.util.threading.DirectExecutor) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) MeterRegistry(io.micrometer.core.instrument.MeterRegistry) Before(org.junit.Before)

Aggregations

SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)8 TwoPools (org.webpieces.data.api.TwoPools)8 DirectExecutor (org.webpieces.util.threading.DirectExecutor)8 Before (org.junit.Before)6 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)4 InetSocketAddress (java.net.InetSocketAddress)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 SSLEngine (javax.net.ssl.SSLEngine)2 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)2 BufferPool (org.webpieces.data.api.BufferPool)2 MockDataListener (org.webpieces.nio.api.mocks.MockDataListener)2 BackpressureConfig (org.webpieces.nio.api.BackpressureConfig)1 ChannelManager (org.webpieces.nio.api.ChannelManager)1 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 MockAsyncListener (org.webpieces.nio.api.mocks.MockAsyncListener)1 ConnectionOpen (org.webpieces.nio.api.mocks.MockAsyncListener.ConnectionOpen)1 SSLMetrics (org.webpieces.ssl.api.SSLMetrics)1 SslAction (org.webpieces.ssl.api.dto.SslAction)1