use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method testReallyDelayedRunTask.
/**
* This tests the situation where the Runnable must tell the engine
* to reprocess the buffer itself.
*/
public void testReallyDelayedRunTask() 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];
serverEngine.feedEncryptedPacket(b0, null);
ByteBuffer b1 = (ByteBuffer) methods[1].getAllParams()[0];
m = serverList.expect("runTask");
r = (Runnable) m.getAllParams()[0];
serverEngine.feedEncryptedPacket(b1, null);
ByteBuffer b2 = (ByteBuffer) methods[2].getAllParams()[0];
serverEngine.feedEncryptedPacket(b2, null);
String[] methodNames1 = new String[3];
//THIS IS THE REALLY DELAYED RUN TASK run after all 3 packets are fed
//to ssl engine
r.run();
methodNames1[0] = "packetEncrypted";
methodNames1[1] = "packetEncrypted";
methodNames1[2] = "encryptedLinkEstablished";
CalledMethod[] methods1 = serverList.expect(methodNames1);
ByteBuffer b01 = (ByteBuffer) methods1[0].getAllParams()[0];
clientEngine.feedEncryptedPacket(b01, null);
ByteBuffer b11 = (ByteBuffer) methods1[1].getAllParams()[0];
clientEngine.feedEncryptedPacket(b11, null);
clientList.expect("encryptedLinkEstablished");
log.trace("E*******************************************");
}
use of biz.xsoftware.mock.CalledMethod 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();
}
use of biz.xsoftware.mock.CalledMethod 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 biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestUnpacketizer method testNormalBehavior.
/**
* Test normal behavior by running 2 full normal packets through.
*
*/
public void testNormalBehavior() throws IOException {
ByteBuffer b = ByteBuffer.allocate(100);
for (int i = 0; i < 2; i++) {
b.clear();
String fullString = HALF1 + HALF2 + i;
helper.putString(b, fullString);
helper.doneFillingBuffer(b);
ByteBuffer outgoing = unpacketizer.processOutgoing(b);
//contract is a rewound buffer that it can read to begin with.
unpacketizer.incomingData(outgoing, null);
CalledMethod method = listener.expect(PACKET_METHOD);
verifyBuffer(method, fullString, 11);
}
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestUnpacketizer method testTwoAndHalfPackets.
/**
*
* Throw 2 and 1/2 packets at the unpacketizer and then
* throw last half and first half of next one and then finally
* the very last packet.
*
*/
public void testTwoAndHalfPackets() throws IOException {
if (log.isTraceEnabled())
log.log(Level.FINE, "started");
ByteBuffer b = ByteBuffer.allocate(200);
String fullString = HALF1 + HALF2;
int size = fullString.getBytes().length;
//2*10 because chars are 2 bytes.
b.putInt(size);
helper.putString(b, fullString);
b.put(PACKET_SEPARATOR);
b.putInt(size);
helper.putString(b, fullString);
b.put(PACKET_SEPARATOR);
b.putInt(size);
helper.putString(b, HALF1);
helper.doneFillingBuffer(b);
String[] methods = new String[2];
methods[0] = PACKET_METHOD;
methods[1] = PACKET_METHOD;
unpacketizer.incomingData(b, null);
CalledMethod[] calledMethods = listener.expect(methods);
//need to verify first 2 packets and then send
//both half of last and half of next to finish off tests.
verifyBuffer(calledMethods[0], fullString, size);
verifyBuffer(calledMethods[1], fullString, size);
helper.eraseBuffer(b);
helper.putString(b, HALF2);
b.put(PACKET_SEPARATOR);
//2*10 because chars are 2 bytes.
b.putInt(size);
helper.putString(b, HALF1);
helper.doneFillingBuffer(b);
if (log.isTraceEnabled())
log.log(Level.FINE, "FEED NEXT BUFFER********************");
unpacketizer.incomingData(b, null);
CalledMethod method = listener.expect(PACKET_METHOD);
verifyBuffer(method, fullString, size);
//finish up by feeding last half of last packet
helper.eraseBuffer(b);
helper.putString(b, HALF2);
b.put(PACKET_SEPARATOR);
helper.doneFillingBuffer(b);
unpacketizer.incomingData(b, null);
method = listener.expect(PACKET_METHOD);
verifyBuffer(method, fullString, size);
if (log.isTraceEnabled())
log.log(Level.FINE, "ended");
}
Aggregations