use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.
the class TestNewAsynchSSLEngine2 method setUp.
@Override
protected void setUp() throws Exception {
HandlerForTests.setupLogging();
serverList.setDefaultBehavior("packetEncrypted", new CloneByteBuffer());
clientList.setDefaultBehavior("packetEncrypted", new CloneByteBuffer());
SSLEngineFactory sslEngineFactory = new MockSSLEngineFactory();
FactoryCreator creator = FactoryCreator.createFactory(null);
SSLEngine wrappedSvr = sslEngineFactory.createEngineForServerSocket();
serverEngine = creator.createSSLEngine("[serverAsynch] ", wrappedSvr, null);
serverEngine.setListener((SSLListener) serverList);
SSLEngine wrappedClient = sslEngineFactory.createEngineForSocket();
clientEngine = creator.createSSLEngine("[clientEngine] ", wrappedClient, null);
clientEngine.setListener((SSLListener) clientList);
}
use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.
the class XTestDelayServer method setUp.
protected void setUp() throws Exception {
FactoryCreator creator = FactoryCreator.createFactory(null);
procFactory = creator.createPacketProcFactory(null);
factoryHolder = new Settings(null, procFactory);
HandlerForTests.setupLogging();
LoggerFactory.getLogger("").setLevel(Level.INFO);
// and started back up cleanly.....
if (chanMgr == null) {
chanMgr = createClientChanMgr("[client]");
}
if (echoServer == null) {
ChannelService svrChanMgr = createSvrChanMgr("[echoServer]");
echoServer = new EchoServer(svrChanMgr, factoryHolder);
}
if (delayServer == null) {
delayServer = new DelayServer();
}
chanMgr.start();
InetSocketAddress echoSvrAddr = echoServer.start();
log.trace("echo server port =" + echoSvrAddr);
delaySvrAddr = delayServer.start(echoSvrAddr);
log.trace("delay server port =" + delaySvrAddr);
mockHandler = MockObjectFactory.createMock(DataListener.class);
mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
mockConnect = MockObjectFactory.createMock(ConnectionCallback.class);
}
use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.
the class TestWrites method runBasic.
private void runBasic() throws IOException {
mockSelect.setDefaultReturnValue("getThread", null);
mockSunsChannel.setDefaultBehavior("write", new CloneByteBuffer());
ByteBuffer b = ByteBuffer.allocate(1000);
String expected = "abc";
HELPER.putString(b, expected);
HELPER.doneFillingBuffer(b);
// mockSunsChannel.addReturnValue("write", b.remaining());
client1.oldWrite(b);
CalledMethod m = mockSunsChannel.expect("write");
ByteBuffer actual = (ByteBuffer) m.getAllParams()[0];
String msg = HELPER.readString(actual, actual.remaining());
assertEquals(expected, msg);
}
use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.
the class TestWrites method xxtestQueuedAsynchWrite.
/**
* This tests the situation where client writes something which can't be written and
* so that gets queued, and then client writes another thing which gets queued. finally
* the selector is fired, and this tests that both buffers were written.
*
* @throws Exception
*/
public void xxtestQueuedAsynchWrite() throws Exception {
mockSelect.setDefaultReturnValue("getThread", Thread.currentThread());
MySelectableChannel channel = new MySelectableChannel((SocketChannel) mockSunsChannel);
MyKey key = new MyKey(channel);
mockSunsChannel.setDefaultReturnValue("getSelectableChannel", channel);
MockObject mockKey = key.getMock();
mockKey.addIgnore("readyOps");
mockKey.setDefaultReturnValue("channel", mockSunsChannel);
mockKey.setDefaultReturnValue("readyOps", SelectionKey.OP_WRITE);
// mockSunsChannel.addBehavior("write", new NoReadByteBuffer2());
// mockSunsChannel.addBehavior("write", new CloneByteBuffer());
String expected = "abc";
String expected2 = "def";
mockKey.addReturnValue("interestOps", SelectionKey.OP_WRITE);
fireSelector(key, expected, expected2, false);
String[] methodNames = new String[] { "write", "write" };
CalledMethod[] methods = mockSunsChannel.expect(methodNames);
ByteBuffer actual = (ByteBuffer) methods[0].getAllParams()[0];
String msg = HELPER.readString(actual, actual.remaining());
assertEquals(expected, msg);
ByteBuffer actual2 = (ByteBuffer) methods[1].getAllParams()[0];
msg = HELPER.readString(actual2, actual2.remaining());
assertEquals(expected2, msg);
// expect that an unregistration happened
methodNames = new String[] { "interestOps", "interestOps" };
methods = mockKey.expect(methodNames);
// expect that this channel is no longer interested in anything
int ops = (Integer) methods[1].getAllParams()[0];
assertEquals(0, ops);
// make sure data can flow through as usual...
runBasic();
}
use of org.webpieces.nio.api.testutil.CloneByteBuffer in project webpieces by deanhiller.
the class ZNioSuperclassTest method setUp.
protected void setUp() throws Exception {
HandlerForTests.setupLogging();
// and started back up cleanly.....
if (chanMgr == null) {
chanMgr = getClientChanMgr();
}
if (mockServer == null) {
ChannelService svcChanMgr = getServerChanMgr();
mockServer = new MockNIOServer(svcChanMgr, getServerFactoryHolder());
}
chanMgr.start();
svrAddr = mockServer.start();
log.trace("server port =" + svrAddr);
loopBack = InetAddress.getByName("127.0.0.1");
loopBackAnyPort = new InetSocketAddress(loopBack, 0);
mockHandler = MockObjectFactory.createMock(DataListener.class);
mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
mockConnect = MockObjectFactory.createMock(ConnectionCallback.class);
client1 = chanMgr.createTCPChannel("ClientChannel", getClientFactoryHolder());
}
Aggregations