Search in sources :

Example 1 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class TestNewChannelManager method verifyDataPassing.

private ByteBuffer verifyDataPassing() throws Exception {
    ByteBuffer b = ByteBuffer.allocate(10);
    helper.putString(b, "de");
    helper.doneFillingBuffer(b);
    log.trace("***********************************************");
    FutureOperation write = client1.write(b);
    write.waitForOperation(5000);
    CalledMethod m = serverHandler.expect("incomingData");
    TCPChannel actualChannel = (TCPChannel) m.getAllParams()[0];
    ByteBuffer actualBuf = (ByteBuffer) m.getAllParams()[1];
    String result = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals("de", result);
    b.rewind();
    FutureOperation future = actualChannel.write(b);
    //synchronously wait for write to happen
    future.waitForOperation(5000);
    m = clientHandler.expect(MockDataHandler.INCOMING_DATA);
    actualBuf = (ByteBuffer) m.getAllParams()[1];
    result = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals("de", result);
    b.rewind();
    FutureOperation future2 = actualChannel.write(b);
    //synchronously wait for write to happen
    future2.waitForOperation(5000);
    m = clientHandler.expect(MockDataHandler.INCOMING_DATA);
    actualBuf = (ByteBuffer) m.getAllParams()[1];
    result = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals("de", result);
    return b;
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 2 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class XTestDelayServer method testVerySmallReadWrite.

public void testVerySmallReadWrite() throws Exception {
    ByteBuffer b = ByteBuffer.allocate(4000);
    log.info("getting all proper connections");
    int size = 40;
    String[] methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "connected";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", factoryHolder);
        log.trace("starting connect");
        Thread.sleep(100);
        clients[i].oldConnect(delaySvrAddr, (ConnectionCallback) mockConnect);
    }
    mockConnect.expect(methodNames);
    log.info("done getting all connections");
    for (TCPChannel client : clients) {
        client.registerForReads((DataListener) mockHandler);
    }
    int numWrites = 200;
    String payload = "hello";
    HELPER.putString(b, payload);
    HELPER.doneFillingBuffer(b);
    methodNames = new String[size * numWrites];
    for (int i = 0; i < size * numWrites; i++) {
        methodNames[i] = "incomingData";
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    timer.start();
    timer2.start();
    for (TCPChannel client : clients) {
        for (int i = 0; i < numWrites; i++) {
            client.oldWrite(b);
            b.rewind();
        }
    }
    mockHandler.setExpectTimeout(10000);
    long result2 = timer2.stop();
    CalledMethod[] methods = mockHandler.expect(methodNames);
    long result = timer.stop();
    //pick a method and verify right data came back for performance test
    //to make sure performance test is valid....
    ByteBuffer actualBuf = (ByteBuffer) methods[0].getAllParams()[1];
    String actual = HELPER.readString(actualBuf, actualBuf.remaining());
    assertEquals(payload, actual);
    log.info("payload=" + actual);
    long readWriteTime = result / size;
    log.info("total write time         =" + result2);
    log.info("total write/read time    =" + result);
    log.info("--time per write/read    =" + readWriteTime);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) ByteBuffer(java.nio.ByteBuffer) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 3 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ProxyDataListener method farEndClosed.

@Override
public void farEndClosed(Channel channel) {
    log.error(channel + "far end closed");
    connectedChannels.removeChannel((TCPChannel) channel);
    TCPChannel proxy = lookupExistingOrCreateNew(channel);
    dataListener.farEndClosed(proxy);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Example 4 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ProxyDataListener method failure.

@Override
public void failure(Channel channel, ByteBuffer data, Exception e) {
    TCPChannel proxy = lookupExistingOrCreateNew(channel);
    dataListener.failure(proxy, data, e);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Example 5 with TCPChannel

use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.

the class ProxyDataListener method connectionOpened.

public void connectionOpened(Channel channel, boolean isReadyForWrites) {
    TCPChannel proxy = lookupExistingOrCreateNew(channel);
    dataListener.connectionOpened(proxy, isReadyForWrites);
}
Also used : TCPChannel(org.webpieces.nio.api.channels.TCPChannel)

Aggregations

TCPChannel (org.webpieces.nio.api.channels.TCPChannel)39 InetSocketAddress (java.net.InetSocketAddress)12 ByteBuffer (java.nio.ByteBuffer)10 CalledMethod (biz.xsoftware.mock.CalledMethod)8 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)6 ChannelManager (org.webpieces.nio.api.ChannelManager)5 Channel (org.webpieces.nio.api.channels.Channel)5 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)4 ChannelManagerFactory (org.webpieces.nio.api.ChannelManagerFactory)4 FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)4 AsyncConfig (org.webpieces.asyncserver.api.AsyncConfig)3 AsyncServer (org.webpieces.asyncserver.api.AsyncServer)3 AsyncServerManager (org.webpieces.asyncserver.api.AsyncServerManager)3 BufferPool (org.webpieces.data.api.BufferPool)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 IOException (java.io.IOException)2 InetAddress (java.net.InetAddress)2 Executor (java.util.concurrent.Executor)2 Test (org.junit.Test)2 TCPServerChannel (org.webpieces.nio.api.channels.TCPServerChannel)2