use of org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class ZNioFailureSuperclass method testClientThrowsIntoDataHandlerFarEndClosed.
public void testClientThrowsIntoDataHandlerFarEndClosed() 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("farEndClosed", e);
client1.bind(loopBackAnyPort);
client1.oldConnect(svrAddr, (ConnectionCallback) mockConnect);
client1.registerForReads((DataListener) mockHandler);
mockConnect.expect("connected");
TCPChannel svrChan = expectServerChannel(mockServer, c);
verifyDataPassing(svrChan);
verifyTearDown();
//shutdown of threaded CM is complicated...set stop method on threaded CM.
//We must sleep or thread could be interrupted and never log an error.
//This is a race condition, but only when we are stopping the ChannelManager
specialCaseThreadedCM();
}
use of org.webpieces.nio.api.channels.TCPChannel 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 org.webpieces.nio.api.channels.TCPChannel 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 org.webpieces.nio.api.channels.TCPChannel in project webpieces by deanhiller.
the class ZNioSuperclassTest method testCloseSocketAfterChannelMgrShutdown.
/**
* There was a bug where calling ChannelManager.shutdown before closing any sockets
* registered with that ChannelManager cannot be closed...well, at least this test
* proves when we close the test, the other side should receive that -1 indicating
* the far end closed the socket.
*
* @throws Exception
*/
public void testCloseSocketAfterChannelMgrShutdown() throws Exception {
Class c = Class.forName(getChannelImplName());
client1.bind(loopBackAnyPort);
client1.oldConnect(svrAddr);
TCPChannel svrChan = ZNioFailureSuperclass.expectServerChannel(mockServer, c);
client1.registerForReads((DataListener) mockHandler);
verifyDataPassing(svrChan);
//shutdown channel manager first....should all sockets be closed? Right now
//someone has to manually close all accepted sockets...ie. client responsibility.
svrChan.oldClose();
mockServer.stop();
//notice the Channelmanager on the client side has not shut down so we should
//see a close event....
mockHandler.expect(MockNIOServer.FAR_END_CLOSED);
}
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);
}
Aggregations