Search in sources :

Example 1 with FutureOperation

use of org.webpieces.nio.api.handlers.FutureOperation in project webpieces by deanhiller.

the class TestNewChannelManager method verifyTearDown.

private void verifyTearDown() throws IOException {
    log.info("local=" + client1.getLocalAddress() + " remote=" + client1.getRemoteAddress());
    log.info("CLIENT1 CLOSE");
    FutureOperation future = client1.close();
    serverHandler.expect(MockNIOServer.FAR_END_CLOSED);
    future.setListener((OperationCallback) clientConnect);
    clientConnect.expect("finished");
}
Also used : FutureOperation(org.webpieces.nio.api.handlers.FutureOperation)

Example 2 with FutureOperation

use of org.webpieces.nio.api.handlers.FutureOperation in project webpieces by deanhiller.

the class TestNewChannelManager method testBasic.

public void testBasic() throws Exception {
    client1.bind(loopBackAnyPort);
    InetSocketAddress remoteAddr = new InetSocketAddress(loopBack, srvrChannel.getLocalAddress().getPort());
    FutureOperation future = client1.connect(remoteAddr);
    future.setListener((OperationCallback) clientConnect);
    clientConnect.expect("finished");
    client1.registerForReads((DataListener) clientHandler);
    //should return immediately since listener fired
    future.waitForOperation();
    serverHandler = MockObjectFactory.createMock(DataListener.class);
    CalledMethod m = serverAccept.expect("connected");
    serverTcpChannel = (Channel) m.getAllParams()[0];
    serverTcpChannel.registerForReads((DataListener) serverHandler);
    boolean isConnected = client1.isConnected();
    assertTrue("Client should be connected", isConnected);
    verifyDataPassing();
    verifyTearDown();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) DataListener(org.webpieces.nio.api.handlers.DataListener) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 3 with FutureOperation

use of org.webpieces.nio.api.handlers.FutureOperation 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 4 with FutureOperation

use of org.webpieces.nio.api.handlers.FutureOperation in project webpieces by deanhiller.

the class ZPerformanceSuper method testVerySmallReadWrite.

/**
	 * This is the difference in performance of writing/reading secure data vs.
	 * writing/reading non-secure data for a VERY SMALL payload.  Realize though,
	 * in this test, the data is encrypted, decrypted, encrypted again, and 
	 * decrypted again, so the server takes half this load, and the client the
	 * other half.  
	 * Basic seems to be 75% of secure's time. This is a slowdown of 133% 
	 * for echoing 'hello'.
	 * 
     * Basic....
     * total write time         =1732 ms
     * total write/response time=1802 ms
     * time per write/response  =45   ms
     * Secure....
     * total write time         =2374 ms
     * total write/response time=2424 ms
     * time per write/response  =60   ms
     * Basic with network delay of 1 seconds....
     * total write time         =1522 ms
     * total write/response time=3585 ms
     * time per write/response  =89   ms
	 * @throws Exception
	 */
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] = "finished";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
        FutureOperation future = clients[i].connect(svrAddr);
        future.setListener((OperationCallback) mockConnectOp);
    }
    mockConnectOp.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);
    int numBytes = b.remaining();
    methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "incomingData";
    }
    String[] finNames = new String[size];
    for (int i = 0; i < size; i++) {
        finNames[i] = "finished";
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    timer.start();
    timer2.start();
    CalledMethod[] methods = null;
    for (int i = 0; i < numWrites; i++) {
        for (TCPChannel client : clients) {
            FutureOperation write = client.write(b);
            write.setListener((OperationCallback) mockConnectOp);
            //client.oldWrite(b);
            b.rewind();
        }
        mockConnectOp.expect(finNames);
        methods = mockHandler.expect(methodNames);
    }
    long result2 = timer2.stop();
    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[5].getAllParams()[1];
    String actual = helper.readString(actualBuf, actualBuf.remaining());
    assertEquals(payload, actual);
    log.info("payload=" + actual);
    long readWriteTime = result / size;
    long byteTime = 100 * result / (numWrites * numBytes);
    log.info("total write time         =" + result2);
    log.info("total write/read time    =" + result);
    log.info("--time per 100 bytes     =" + byteTime);
    log.info("test result info:");
    log.info("--time per write/read    =" + readWriteTime);
    log.info("  time to beat           =" + getSmallReadWriteTimeLimit());
    assertTrue(readWriteTime < getSmallReadWriteTimeLimit());
}
Also used : PerfTimer(org.webpieces.nio.test.PerfTimer) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) ByteBuffer(java.nio.ByteBuffer) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation) CalledMethod(biz.xsoftware.mock.CalledMethod)

Example 5 with FutureOperation

use of org.webpieces.nio.api.handlers.FutureOperation in project webpieces by deanhiller.

the class ZPerformanceSuper method testBasicConnect.

/**
	 * Testing difference between secureChanMgr with Basic, and just Basic
	 * and whatever other combinations are in PerfTestZ<Subclassname>.  Here
	 * we are testing the performance of connect method.  As you can see the
	 * establishing of a link is very expensive. 57 times difference!
	 * 
	 * Basic ChannelMgr....
	 * time for initiating all connects           = 180 ms
	 * time for initiating/finishing all connects = 180 ms
	 * time per connection                        = 4 ms
	 * 
	 * Secure ChannelMgr....
	 * time for initiating all connects           = 8,072 ms
	 * time for initiating/finishing all connects = 9,174 ms
	 * time per connection                        = 229 ms
	 * 
	 * 
	 * If you want to test difference between asynch connect and connect, you
	 * need to simulate a network delay in EchoServer class.  
	 * I did this and simulated one second.
	 * Then changing the connect from synchronous to asynchronous results in going
	 * from 7.401 seconds to .531 seconds.  ie. the thread calling connect is free
	 * to go do more work while in the process of connecting to a server or
	 * client for that matter.
	 */
public void testBasicConnect() throws Exception {
    int size = 40;
    String[] methodNames = new String[size];
    for (int i = 0; i < size; i++) {
        methodNames[i] = "finished";
    }
    TCPChannel[] clients = new TCPChannel[size];
    for (int i = 0; i < size; i++) {
        clients[i] = chanMgr.createTCPChannel("Client[" + i + "]", getClientFactoryHolder());
    }
    PerfTimer timer = new PerfTimer();
    PerfTimer timer2 = new PerfTimer();
    log.info("Starting test connecting to=" + svrAddr);
    timer.start();
    timer2.start();
    for (int i = 0; i < size; i++) {
        FutureOperation future = clients[i].connect(svrAddr);
        future.setListener((OperationCallback) mockConnectOp);
    }
    long result2 = timer2.stop();
    mockConnectOp.expect(methodNames);
    long result = timer.stop();
    long timePerConnect = result / size;
    log.info("time for initiating connects          =" + result2);
    log.info("time for initiating/finishing connects=" + result);
    log.info("connected per connection time         =" + timePerConnect);
    log.info("--time to beat           =" + getBasicConnectTimeLimit());
    assertTrue(timePerConnect < getBasicConnectTimeLimit());
}
Also used : PerfTimer(org.webpieces.nio.test.PerfTimer) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) FutureOperation(org.webpieces.nio.api.handlers.FutureOperation)

Aggregations

FutureOperation (org.webpieces.nio.api.handlers.FutureOperation)6 CalledMethod (biz.xsoftware.mock.CalledMethod)4 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)4 ByteBuffer (java.nio.ByteBuffer)3 PerfTimer (org.webpieces.nio.test.PerfTimer)3 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)2 InetSocketAddress (java.net.InetSocketAddress)1 DataListener (org.webpieces.nio.api.handlers.DataListener)1