use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testRunInMiddleOfPacket.
public void testRunInMiddleOfPacket() throws Exception {
log.trace("B*******************************************");
clientEngine.beginHandshake();
CalledMethod m = clientList.expect("packetEncrypted");
ByteBuffer b = (ByteBuffer) m.getAllParams()[0];
serverEngine.feedEncryptedPacket(b, null);
m = serverList.expect("runTask");
Runnable r = (Runnable) m.getAllParams()[0];
r.run();
m = serverList.expect("packetEncrypted");
b = (ByteBuffer) m.getAllParams()[0];
clientEngine.feedEncryptedPacket(b, null);
m = clientList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
String[] methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "packetEncrypted";
CalledMethod[] methods = clientList.expect(methodNames);
ByteBuffer b0 = (ByteBuffer) methods[0].getAllParams()[0];
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
serverEngine.feedEncryptedPacket(b0, null);
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
int total = b1.remaining() + b2.remaining();
ByteBuffer combined = ByteBuffer.allocate(total);
int lim = b1.limit();
//we only want to put part of b1 in payload
b1.limit(3);
combined.put(b1);
helper.doneFillingBuffer(combined);
serverEngine.feedEncryptedPacket(combined, null);
//run the task after some of the previous packet fed, then feed rest of packet
r.run();
combined.clear();
b1.limit(lim);
combined.put(b1);
combined.put(b2);
helper.doneFillingBuffer(combined);
serverEngine.feedEncryptedPacket(combined, null);
String[] methodNames1 = new String[3];
methodNames1[0] = "packetEncrypted";
methodNames1[1] = "packetEncrypted";
methodNames1[2] = "encryptedLinkEstablished";
CalledMethod[] methods1 = serverList.expect(methodNames1);
b0 = (ByteBuffer) methods1[0].getAllParams()[0];
clientEngine.feedEncryptedPacket(b0, null);
b1 = (ByteBuffer) methods1[1].getAllParams()[0];
clientEngine.feedEncryptedPacket(b1, null);
clientList.expect("encryptedLinkEstablished");
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testCombinedPackets.
public void testCombinedPackets() throws Exception {
clientEngine.beginHandshake();
CalledMethod m;
ByteBuffer b;
CalledMethod m1 = clientList.expect("packetEncrypted");
ByteBuffer b3 = (ByteBuffer) m1.getAllParams()[0];
serverEngine.feedEncryptedPacket(b3, null);
m = serverList.expect("runTask");
Runnable r = (Runnable) m.getAllParams()[0];
r.run();
m = serverList.expect("packetEncrypted");
b = (ByteBuffer) m.getAllParams()[0];
clientEngine.feedEncryptedPacket(b, null);
m = clientList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
String[] methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "packetEncrypted";
CalledMethod[] methods = clientList.expect(methodNames);
ByteBuffer b0 = (ByteBuffer) methods[0].getAllParams()[0];
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
int total = b0.remaining() + b1.remaining() + b2.remaining();
ByteBuffer combined = ByteBuffer.allocate(total);
combined.put(b0);
combined.put(b1);
combined.put(b2);
helper.doneFillingBuffer(combined);
serverEngine.feedEncryptedPacket(combined, null);
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
r.run();
methodNames = new String[3];
methodNames[0] = "packetEncrypted";
methodNames[1] = "packetEncrypted";
methodNames[2] = "encryptedLinkEstablished";
methods = serverList.expect(methodNames);
b0 = (ByteBuffer) methods[0].getAllParams()[0];
b1 = (ByteBuffer) methods[1].getAllParams()[0];
total = b0.remaining() + b1.remaining();
combined = ByteBuffer.allocate(total);
combined.put(b0);
combined.put(b1);
helper.doneFillingBuffer(combined);
clientEngine.feedEncryptedPacket(combined, null);
clientList.expect("encryptedLinkEstablished");
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class ZNioSuperclassTest method verifyDataPassing.
private ByteBuffer verifyDataPassing(TCPChannel svrChan) throws Exception {
ByteBuffer b = ByteBuffer.allocate(10);
helper.putString(b, "de");
helper.doneFillingBuffer(b);
int expectedWrote = b.remaining();
log.trace("***********************************************");
int actualWrite = client1.oldWrite(b);
assertEquals(expectedWrote, actualWrite);
CalledMethod m = mockServer.expect(MockNIOServer.INCOMING_DATA);
TCPChannel actualChannel = (TCPChannel) m.getAllParams()[0];
Class c = Class.forName(getChannelImplName());
assertEquals("should be correct type of channel", c, actualChannel.getClass());
ByteBuffer actualBuf = (ByteBuffer) m.getAllParams()[1];
String result = helper.readString(actualBuf, actualBuf.remaining());
assertEquals("de", result);
b.rewind();
svrChan.oldWrite(b);
m = mockHandler.expect(MockDataHandler.INCOMING_DATA);
actualBuf = (ByteBuffer) m.getAllParams()[1];
result = helper.readString(actualBuf, actualBuf.remaining());
assertEquals("de", result);
return b;
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class ZPerformanceSuper method testLargeReadWrite.
/**
* This is the difference in performance of writing/reading secure data vs.
* writing/reading non-secure data for a very small payload.
* Basic seems to be 75% of secure's time. This is a slowdown of 133%
* for echoing 'hello'.
*
* Basic....
* total write time = 1402 ms
* total write/response time= 1433 ms
* time per write/response = 35 ms
* Secure....
* total write time = 6119 ms
* total write/response time= 6159 ms
* time per write/response = 153 ms
*
* @throws Exception
*/
public void testLargeReadWrite() 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 + "]", getClientFactoryHolder());
clients[i].oldConnect(svrAddr, (ConnectionCallback) mockConnect);
}
mockConnect.expect(methodNames);
log.info("done getting all connections");
for (TCPChannel client : clients) {
client.registerForReads((DataListener) mockHandler);
}
int numWrites = 100;
String payload = "hello";
for (int i = 0; i < 3000; i++) {
payload += "i";
}
helper.putString(b, payload);
helper.doneFillingBuffer(b);
int numBytes = b.remaining();
log.info("size=" + b.remaining());
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++) {
FutureOperation future = client.write(b);
future.waitForOperation(5000);
b.rewind();
}
}
long result2 = timer2.stop();
CalledMethod[] methods = mockHandler.expect(methodNames);
long result = timer.stop();
ByteBuffer actualBuf = (ByteBuffer) methods[6].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 =" + getLargerReadWriteTimeLimit());
assertTrue(readWriteTime < getLargerReadWriteTimeLimit());
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestUdpIntegration method sendReceivePacket.
/**
* @throws IOException
*/
private void sendReceivePacket() throws IOException {
String msg = "Asfdsf";
writePacket(client, msg);
CalledMethod m = svrHandler.expect("incomingData");
ByteBuffer actualBuf = (ByteBuffer) m.getAllParams()[1];
String actual = HELPER.readString(actualBuf, actualBuf.remaining());
assertEquals(msg, actual);
String msg2 = "xyasdf";
writePacket(server, msg2);
CalledMethod m2 = clientHandler.expect("incomingData");
ByteBuffer actualBuf2 = (ByteBuffer) m2.getAllParams()[1];
String actual2 = HELPER.readString(actualBuf2, actualBuf2.remaining());
assertEquals(msg2, actual2);
}
Aggregations