Search in sources :

Example 1 with CloneByteBuffer

use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.

the class TestNewAsynchSSLEngine2 method setUp.

@Override
protected void setUp() throws Exception {
    HandlerForTests.setupLogging();
    serverList.setDefaultBehavior("packetEncrypted", new CloneByteBuffer());
    clientList.setDefaultBehavior("packetEncrypted", new CloneByteBuffer());
    SSLEngineFactory sslEngineFactory = new MockSSLEngineFactory();
    FactoryCreator creator = FactoryCreator.createFactory(null);
    SSLEngine wrappedSvr = sslEngineFactory.createEngineForServerSocket();
    serverEngine = creator.createSSLEngine("[serverAsynch] ", wrappedSvr, null);
    serverEngine.setListener((SSLListener) serverList);
    SSLEngine wrappedClient = sslEngineFactory.createEngineForSocket();
    clientEngine = creator.createSSLEngine("[clientEngine] ", wrappedClient, null);
    clientEngine.setListener((SSLListener) clientList);
}
Also used : CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) AsyncSSLEngine(org.webpieces.nio.api.libs.AsyncSSLEngine) SSLEngine(javax.net.ssl.SSLEngine) FactoryCreator(org.webpieces.nio.api.libs.FactoryCreator) MockSSLEngineFactory(org.webpieces.nio.api.testutil.MockSSLEngineFactory) SSLEngineFactory(org.webpieces.nio.api.libs.SSLEngineFactory) MockSSLEngineFactory(org.webpieces.nio.api.testutil.MockSSLEngineFactory)

Example 2 with CloneByteBuffer

use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.

the class XTestDelayServer method setUp.

protected void setUp() throws Exception {
    FactoryCreator creator = FactoryCreator.createFactory(null);
    procFactory = creator.createPacketProcFactory(null);
    factoryHolder = new Settings(null, procFactory);
    HandlerForTests.setupLogging();
    LoggerFactory.getLogger("").setLevel(Level.INFO);
    // and started back up cleanly.....
    if (chanMgr == null) {
        chanMgr = createClientChanMgr("[client]");
    }
    if (echoServer == null) {
        ChannelService svrChanMgr = createSvrChanMgr("[echoServer]");
        echoServer = new EchoServer(svrChanMgr, factoryHolder);
    }
    if (delayServer == null) {
        delayServer = new DelayServer();
    }
    chanMgr.start();
    InetSocketAddress echoSvrAddr = echoServer.start();
    log.trace("echo server port =" + echoSvrAddr);
    delaySvrAddr = delayServer.start(echoSvrAddr);
    log.trace("delay server port =" + delaySvrAddr);
    mockHandler = MockObjectFactory.createMock(DataListener.class);
    mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
    mockConnect = MockObjectFactory.createMock(ConnectionCallback.class);
}
Also used : ChannelService(org.webpieces.nio.api.deprecated.ChannelService) InetSocketAddress(java.net.InetSocketAddress) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FactoryCreator(org.webpieces.nio.api.libs.FactoryCreator) DataListener(org.webpieces.nio.api.handlers.DataListener) ConnectionCallback(org.webpieces.nio.api.deprecated.ConnectionCallback) Settings(org.webpieces.nio.api.deprecated.Settings)

Example 3 with CloneByteBuffer

use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.

the class TestWrites method runBasic.

private void runBasic() throws IOException {
    mockSelect.setDefaultReturnValue("getThread", null);
    mockSunsChannel.setDefaultBehavior("write", new CloneByteBuffer());
    ByteBuffer b = ByteBuffer.allocate(1000);
    String expected = "abc";
    HELPER.putString(b, expected);
    HELPER.doneFillingBuffer(b);
    // mockSunsChannel.addReturnValue("write", b.remaining());
    client1.oldWrite(b);
    CalledMethod m = mockSunsChannel.expect("write");
    ByteBuffer actual = (ByteBuffer) m.getAllParams()[0];
    String msg = HELPER.readString(actual, actual.remaining());
    assertEquals(expected, msg);
}
Also used : CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) ByteBuffer(java.nio.ByteBuffer) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 4 with CloneByteBuffer

use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.

the class TestWrites method xxtestQueuedAsynchWrite.

/**
 * This tests the situation where client writes something which can't be written and
 * so that gets queued, and then client writes another thing which gets queued.  finally
 * the selector is fired, and this tests that both buffers were written.
 *
 * @throws Exception
 */
public void xxtestQueuedAsynchWrite() throws Exception {
    mockSelect.setDefaultReturnValue("getThread", Thread.currentThread());
    MySelectableChannel channel = new MySelectableChannel((SocketChannel) mockSunsChannel);
    MyKey key = new MyKey(channel);
    mockSunsChannel.setDefaultReturnValue("getSelectableChannel", channel);
    MockObject mockKey = key.getMock();
    mockKey.addIgnore("readyOps");
    mockKey.setDefaultReturnValue("channel", mockSunsChannel);
    mockKey.setDefaultReturnValue("readyOps", SelectionKey.OP_WRITE);
    // mockSunsChannel.addBehavior("write", new NoReadByteBuffer2());
    // mockSunsChannel.addBehavior("write", new CloneByteBuffer());
    String expected = "abc";
    String expected2 = "def";
    mockKey.addReturnValue("interestOps", SelectionKey.OP_WRITE);
    fireSelector(key, expected, expected2, false);
    String[] methodNames = new String[] { "write", "write" };
    CalledMethod[] methods = mockSunsChannel.expect(methodNames);
    ByteBuffer actual = (ByteBuffer) methods[0].getAllParams()[0];
    String msg = HELPER.readString(actual, actual.remaining());
    assertEquals(expected, msg);
    ByteBuffer actual2 = (ByteBuffer) methods[1].getAllParams()[0];
    msg = HELPER.readString(actual2, actual2.remaining());
    assertEquals(expected2, msg);
    // expect that an unregistration happened
    methodNames = new String[] { "interestOps", "interestOps" };
    methods = mockKey.expect(methodNames);
    // expect that this channel is no longer interested in anything
    int ops = (Integer) methods[1].getAllParams()[0];
    assertEquals(0, ops);
    // make sure data can flow through as usual...
    runBasic();
}
Also used : ByteBuffer(java.nio.ByteBuffer) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) MockObject(biz.xsoftware.mock.MockObject) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 5 with CloneByteBuffer

use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.

the class ZNioSuperclassTest method setUp.

protected void setUp() throws Exception {
    HandlerForTests.setupLogging();
    // and started back up cleanly.....
    if (chanMgr == null) {
        chanMgr = getClientChanMgr();
    }
    if (mockServer == null) {
        ChannelService svcChanMgr = getServerChanMgr();
        mockServer = new MockNIOServer(svcChanMgr, getServerFactoryHolder());
    }
    chanMgr.start();
    svrAddr = mockServer.start();
    log.trace("server port =" + svrAddr);
    loopBack = InetAddress.getByName("127.0.0.1");
    loopBackAnyPort = new InetSocketAddress(loopBack, 0);
    mockHandler = MockObjectFactory.createMock(DataListener.class);
    mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
    mockConnect = MockObjectFactory.createMock(ConnectionCallback.class);
    client1 = chanMgr.createTCPChannel("ClientChannel", getClientFactoryHolder());
}
Also used : ChannelService(org.webpieces.nio.api.deprecated.ChannelService) InetSocketAddress(java.net.InetSocketAddress) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) DataListener(org.webpieces.nio.api.handlers.DataListener) ConnectionCallback(org.webpieces.nio.api.deprecated.ConnectionCallback) MockNIOServer(org.webpieces.nio.api.testutil.MockNIOServer)

Aggregations

CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)13 DataListener (org.webpieces.nio.api.handlers.DataListener)7 ChannelService (org.webpieces.nio.api.deprecated.ChannelService)6 FactoryCreator (org.webpieces.nio.api.libs.FactoryCreator)6 MockObject (biz.xsoftware.mock.MockObject)5 InetSocketAddress (java.net.InetSocketAddress)5 HashMap (java.util.HashMap)4 ConnectionCallback (org.webpieces.nio.api.deprecated.ConnectionCallback)4 MockNIOServer (org.webpieces.nio.api.testutil.MockNIOServer)4 CalledMethod (biz.xsoftware.mock.CalledMethod)3 ChannelServiceFactory (org.webpieces.nio.api.deprecated.ChannelServiceFactory)3 ByteBuffer (java.nio.ByteBuffer)2 SSLEngine (javax.net.ssl.SSLEngine)2 Settings (org.webpieces.nio.api.deprecated.Settings)2 OperationCallback (org.webpieces.nio.api.handlers.OperationCallback)2 AsyncSSLEngine (org.webpieces.nio.api.libs.AsyncSSLEngine)2 SSLEngineFactory (org.webpieces.nio.api.libs.SSLEngineFactory)2 MockSSLEngineFactory (org.webpieces.nio.api.testutil.MockSSLEngineFactory)2 DatagramListener (org.webpieces.nio.api.handlers.DatagramListener)1 PacketListener (org.webpieces.nio.api.libs.PacketListener)1