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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations