use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class ZNioFailureSuperclass method expectServerChannel.
static TCPChannel expectServerChannel(MockNIOServer mockServer, Class c) {
CalledMethod method = mockServer.expect(MockNIOServer.CONNECTED);
TCPChannel svrChan = (TCPChannel) method.getAllParams()[0];
assertEquals("should be instance of correct channel type", c, svrChan.getClass());
return svrChan;
}
use of biz.xsoftware.mock.CalledMethod 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());
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class ZNioFailureSuperclass method verifyDataPassing.
// public void testClientThrowsIntoAcceptHandlerConnect() throws Exception {
// setNumberOfExpectedWarnings(1);
//
// //make sure we are testing the right one....
// Class c = Class.forName(getChannelImplName());
// assertEquals("should be instance of correct channel type", c, client1.getClass());
//
// String msg = "some exception message";
// IOException e = new IOException(msg);
// mockServer.addThrowException("connected", e);
//
// client1.bind(loopBackAnyPort);
// client1.oldConnect(svrAddr, (ConnectionCallback)mockConnect);
// client1.registerForReads((DataListener)mockHandler);
//
// mockConnect.expect("connected");
// TCPChannel svrChan = expectServerChannel(mockServer, c);
//
// verifyDataPassing(svrChan);
// verifyTearDown();
// }
private ByteBuffer verifyDataPassing(TCPChannel svrChan) throws Exception {
ByteBuffer b = ByteBuffer.allocate(10);
helper.putString(b, "de");
helper.doneFillingBuffer(b);
int expectedWrote = b.remaining();
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());
log.info("result len=" + result.length());
assertEquals("de", result);
b.rewind();
svrChan.oldWrite(b);
m = mockHandler.expect(MockDataHandler.INCOMING_DATA);
actualBuf = (ByteBuffer) m.getAllParams()[1];
log.info("buffer remain=" + actualBuf.remaining());
result = helper.readString(actualBuf, actualBuf.remaining());
log.info("---1st char=" + (result.substring(0, 1).equals("de".substring(0, 1))));
log.info("---2nd char=" + (result.substring(1, 2).equals("de".substring(1, 2))));
log.info("substring='" + result.substring(0, 1) + "'");
log.info("len=" + "de".length() + " 2ndlen=" + result.length());
log.info("'de'" + " actual='" + result + "'" + " result=" + ("de".equals(result)));
assertEquals("de", result);
return b;
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class ZNioSuperclassTest method testUnregisterReregisterForReads.
public void testUnregisterReregisterForReads() throws Exception {
Class c = Class.forName(getChannelImplName());
client1.bind(loopBackAnyPort);
client1.oldConnect(svrAddr);
TCPChannel svrChan = ZNioFailureSuperclass.expectServerChannel(mockServer, c);
client1.registerForReads((DataListener) mockHandler);
ByteBuffer b = verifyDataPassing(svrChan);
client1.unregisterForReads();
b.rewind();
svrChan.oldWrite(b);
Thread.sleep(5000);
mockHandler.expect(MockObject.NONE);
client1.registerForReads((DataListener) mockHandler);
CalledMethod m = mockHandler.expect(MockNIOServer.INCOMING_DATA);
ByteBuffer actualBuf = (ByteBuffer) m.getAllParams()[1];
String result = helper.readString(actualBuf, actualBuf.remaining());
assertEquals("de", result);
verifyTearDown();
}
use of biz.xsoftware.mock.CalledMethod in project webpieces by deanhiller.
the class TestUdpIntegration method setupPortUnreachable.
/**
* @param svrAddr
* @throws IOException
* @throws InterruptedException
*/
private InetSocketAddress setupPortUnreachable(InetSocketAddress svrAddr) throws IOException, InterruptedException {
InetAddress localhost = InetAddress.getLocalHost();
client.bind(new InetSocketAddress(localhost, 0));
InetSocketAddress clientAddr = client.getLocalAddress();
client.oldConnect(svrAddr);
client.registerForReads((DataListener) clientHandler);
String msg = "aaaaa";
//should result in port unreachable
writePacket(client, msg);
//expect the exception
CalledMethod m = clientHandler.expect("failure");
PortUnreachableException exc = (PortUnreachableException) m.getAllParams()[2];
log.log(Level.FINE, "this is expected", exc);
return clientAddr;
}
Aggregations