Search in sources :

Example 1 with ChannelServiceFactory

use of org.webpieces.nio.api.deprecated.ChannelServiceFactory in project webpieces by deanhiller.

the class TestXEvaluateNIOBehavior method setUp.

public void setUp() {
    String os = System.getProperty("os.name");
    //String osArch = System.getProperty("os.arch");
    log.info("os=" + os);
    if (os.equals("linux")) {
        log.info("RUNNING LINUX TESTS ONLY");
        isLinux = true;
    }
    try {
        if (mockServer == null) {
            ChannelServiceFactory factory = ChannelServiceFactory.createFactory(null);
            Map<String, Object> p = new HashMap<String, Object>();
            p.put(ChannelManagerOld.KEY_ID, "[server]");
            p.put(ChannelManagerOld.KEY_BUFFER_FACTORY, bufFactory);
            ChannelService chanMgr = factory.createChannelManager(p);
            mockServer = new MockNIOServer(chanMgr, null);
        }
        svrAddr = mockServer.start();
        log.info("svrPort=" + svrAddr);
    } catch (IOException e) {
        throw new RuntimeException("test failed", e);
    } catch (InterruptedException e) {
        throw new RuntimeException("test failed2", e);
    }
}
Also used : HashMap(java.util.HashMap) ChannelService(org.webpieces.nio.api.deprecated.ChannelService) ChannelServiceFactory(org.webpieces.nio.api.deprecated.ChannelServiceFactory) MockNIOServer(org.webpieces.nio.api.testutil.MockNIOServer) IOException(java.io.IOException)

Example 2 with ChannelServiceFactory

use of org.webpieces.nio.api.deprecated.ChannelServiceFactory in project webpieces by deanhiller.

the class TryRealConnection method setUp.

protected void setUp() throws Exception {
    if (chanMgr == null) {
        Map<String, Object> factoryName = new HashMap<String, Object>();
        factoryName.put(ChannelServiceFactory.KEY_IMPLEMENTATION_CLASS, ChannelServiceFactory.VAL_SECURE_CHANNEL_MGR);
        ChannelServiceFactory secureFactory = ChannelServiceFactory.createFactory(factoryName);
        //ChannelManagerFactory secureFactory = ChannelManagerFactory.createFactory(null);
        Map<String, Object> p = new HashMap<String, Object>();
        p.put(ChannelManagerOld.KEY_ID, "[client]");
        chanMgr = secureFactory.createChannelManager(p);
        chanMgr.start();
    }
    loopBack = InetAddress.getByName("192.168.1.100");
    loopBackAddr = new InetSocketAddress(loopBack, 0);
}
Also used : HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) ChannelServiceFactory(org.webpieces.nio.api.deprecated.ChannelServiceFactory) MockObject(biz.xsoftware.mock.MockObject)

Example 3 with ChannelServiceFactory

use of org.webpieces.nio.api.deprecated.ChannelServiceFactory in project webpieces by deanhiller.

the class TestWrites method setUp.

protected void setUp() throws Exception {
    HandlerForTests.setupLogging();
    if (bufFactory == null) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(FactoryCreator.KEY_IS_DIRECT, false);
        FactoryCreator creator = FactoryCreator.createFactory(null);
        bufFactory = creator.createBufferFactory(map);
    }
    mockSunsChannel = MockObjectFactory.createMock(SocketChannel.class);
    mockSunsChannel.addIgnore("isBlocking");
    mockSunsChannel.addIgnore("getSelectableChannel");
    mockSunsChannel.setDefaultReturnValue("isBlocking", false);
    mockSunsChannel.addReturnValue("connect", true);
    mockSelect = MockObjectFactory.createMock(Select.class);
    mockSelect.addIgnore("isRunning");
    mockSelect.addIgnore("getThread");
    mockSelect.addIgnore("setRunning");
    mockSelect.setDefaultReturnValue("isRunning", true);
    mockSelect.setDefaultReturnValue("isWantShutdown", false);
    mockWriteHandler = MockObjectFactory.createMock(OperationCallback.class);
    mockRegListener = MockObjectFactory.createMock(ChannelRegistrationListener.class);
    MockObject mockChannels = MockObjectFactory.createMock(ChannelsFactory.class);
    MockObject mockSelectorProv = MockObjectFactory.createMock(SelectorProviderFactory.class);
    ChannelServiceFactory basic = ChannelServiceFactory.createFactory(null);
    Map<String, Object> props2 = new HashMap<String, Object>();
    props2.put(ChannelServiceFactory.KEY_IMPLEMENTATION_CLASS, ChannelServiceFactory.VAL_EXCEPTION_CHANNEL_MGR);
    props2.put(ChannelServiceFactory.KEY_CHILD_CHANNELMGR_FACTORY, basic);
    factory = ChannelServiceFactory.createFactory(props2);
    Map<String, Object> p = new HashMap<String, Object>();
    p.put(ChannelManagerOld.KEY_ID, "[client]");
    p.put(ChannelManagerOld.KEY_BUFFER_FACTORY, bufFactory);
    p.put("mock.channelsFactory", mockChannels);
    p.put("mock.selectorProvider", mockSelectorProv);
    chanMgr = factory.createChannelManager(p);
    mockSelectorProv.addReturnValue("provider", mockSelect);
    chanMgr.start();
    CalledMethod m = mockSelect.expect("startPollingThread");
    listener = (SelectorListener) m.getAllParams()[0];
    mockHandler = MockObjectFactory.createMock(DataListener.class);
    mockHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
    //mockConnect = MockObjectFactory.createMock(ConnectCallback.class);
    mockChannels.addReturnValue("open", mockSunsChannel);
    client1 = chanMgr.createTCPChannel("ClientChannel", null);
    mockSunsChannel.expect("configureBlocking");
}
Also used : SocketChannel(org.webpieces.nio.api.testutil.chanapi.SocketChannel) HashMap(java.util.HashMap) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FactoryCreator(org.webpieces.nio.api.libs.FactoryCreator) ChannelServiceFactory(org.webpieces.nio.api.deprecated.ChannelServiceFactory) CalledMethod(biz.xsoftware.mock.CalledMethod) ChannelRegistrationListener(org.webpieces.nio.api.testutil.nioapi.ChannelRegistrationListener) OperationCallback(org.webpieces.nio.api.handlers.OperationCallback) Select(org.webpieces.nio.api.testutil.nioapi.Select) MockObject(biz.xsoftware.mock.MockObject) DataListener(org.webpieces.nio.api.handlers.DataListener) MockObject(biz.xsoftware.mock.MockObject)

Example 4 with ChannelServiceFactory

use of org.webpieces.nio.api.deprecated.ChannelServiceFactory in project webpieces by deanhiller.

the class TestMoreSecureChanMgr method getClientChanMgr.

protected ChannelService getClientChanMgr() throws Exception {
    Map<String, Object> factoryName = new HashMap<String, Object>();
    factoryName.put(ChannelServiceFactory.KEY_IMPLEMENTATION_CLASS, ChannelServiceFactory.VAL_SECURE_CHANNEL_MGR);
    factoryName.put(ChannelServiceFactory.KEY_CHILD_CHANNELMGR_FACTORY, basicFactory);
    ChannelServiceFactory secureFactory = ChannelServiceFactory.createFactory(factoryName);
    Map<String, Object> p = new HashMap<String, Object>();
    p.put(ChannelManagerOld.KEY_ID, "client");
    p.put(ChannelManagerOld.KEY_BUFFER_FACTORY, bufFactory);
    ChannelService chanMgr = secureFactory.createChannelManager(p);
    return chanMgr;
}
Also used : HashMap(java.util.HashMap) ChannelService(org.webpieces.nio.api.deprecated.ChannelService) ChannelServiceFactory(org.webpieces.nio.api.deprecated.ChannelServiceFactory) MockObject(biz.xsoftware.mock.MockObject)

Example 5 with ChannelServiceFactory

use of org.webpieces.nio.api.deprecated.ChannelServiceFactory in project webpieces by deanhiller.

the class TestUdpIntegration method setUpImpl.

/*
     * @see TestCase#setUp()
     */
protected void setUpImpl() throws Exception {
    if (bufFactory == null) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put(FactoryCreator.KEY_IS_DIRECT, false);
        FactoryCreator creator = FactoryCreator.createFactory(null);
        bufFactory = creator.createBufferFactory(map);
    }
    ChannelServiceFactory basic = ChannelServiceFactory.createFactory(null);
    Map<String, Object> props2 = new HashMap<String, Object>();
    props2.put(ChannelServiceFactory.KEY_IMPLEMENTATION_CLASS, ChannelServiceFactory.VAL_EXCEPTION_CHANNEL_MGR);
    props2.put(ChannelServiceFactory.KEY_CHILD_CHANNELMGR_FACTORY, basic);
    ChannelServiceFactory factory = ChannelServiceFactory.createFactory(props2);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(ChannelManagerOld.KEY_BUFFER_FACTORY, bufFactory);
    map.put(ChannelManagerOld.KEY_ID, "server+client");
    svc = factory.createChannelManager(map);
    svc.start();
    client = svc.createUDPChannel("client", null);
    server = svc.createUDPChannel("server", null);
    clientHandler = createMock(DataListener.class);
    svrHandler = createMock(DataListener.class);
    clientHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
    svrHandler.setDefaultBehavior("incomingData", new CloneByteBuffer());
}
Also used : HashMap(java.util.HashMap) CloneByteBuffer(org.webpieces.nio.api.testutil.CloneByteBuffer) FactoryCreator(org.webpieces.nio.api.libs.FactoryCreator) ChannelServiceFactory(org.webpieces.nio.api.deprecated.ChannelServiceFactory) MockObject(biz.xsoftware.mock.MockObject) DataListener(org.webpieces.nio.api.handlers.DataListener)

Aggregations

HashMap (java.util.HashMap)6 ChannelServiceFactory (org.webpieces.nio.api.deprecated.ChannelServiceFactory)6 MockObject (biz.xsoftware.mock.MockObject)5 FactoryCreator (org.webpieces.nio.api.libs.FactoryCreator)3 CloneByteBuffer (org.webpieces.nio.api.testutil.CloneByteBuffer)3 ChannelService (org.webpieces.nio.api.deprecated.ChannelService)2 DataListener (org.webpieces.nio.api.handlers.DataListener)2 CalledMethod (biz.xsoftware.mock.CalledMethod)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 DatagramListener (org.webpieces.nio.api.handlers.DatagramListener)1 OperationCallback (org.webpieces.nio.api.handlers.OperationCallback)1 MockNIOServer (org.webpieces.nio.api.testutil.MockNIOServer)1 SocketChannel (org.webpieces.nio.api.testutil.chanapi.SocketChannel)1 ChannelRegistrationListener (org.webpieces.nio.api.testutil.nioapi.ChannelRegistrationListener)1 Select (org.webpieces.nio.api.testutil.nioapi.Select)1