Package ch.unifr.nio.framework.mockups

Examples of ch.unifr.nio.framework.mockups.TestTarget


        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setLevel(Level.FINEST);
        logger.addHandler(consoleHandler);
        SteppingDispatcher steppingDispatcher = new SteppingDispatcher();
        steppingDispatcher.start();
        TestTarget testTarget = new TestTarget(12345);
        testTarget.start();
        SocketChannel channel = testTarget.getSocketChannel();
        BlockingSocketChannel blockingChannel =
                new BlockingSocketChannel(channel);
        blockingChannel.configureBlocking(false);
        TestChannelHandler testChannelHandler = new TestChannelHandler();
        steppingDispatcher.registerChannel(blockingChannel, testChannelHandler);

        // trigger selection by writing some bytes from testTarget
        testTarget.write(testString.getBytes());

        testChannelHandler.waitForBlock();

        // test cachedInterestOps
        int cachedInterestOps = testChannelHandler.getCachedInterestOps();
View Full Code Here


        LOGGER.addHandler(consoleHandler);

        Selector selector = Selector.open();

        LOGGER.finest("starting TestTarget");
        TestTarget testTarget = new TestTarget(11111);
        testTarget.start();
        SocketChannel socketChannel = testTarget.getSocketChannel();
        Thread.sleep(1000);

        LOGGER.finest("configure non-blocking");
        socketChannel.configureBlocking(false);
        LOGGER.finest("registering");
        socketChannel.register(selector, SelectionKey.OP_READ);
        checkIterestOps(selector);

        LOGGER.finest("writing some test data");
        testTarget.write("some test data".getBytes());
        checkIterestOps(selector);
    }
View Full Code Here

        logger.addHandler(consoleHandler);
        Dispatcher dispatcher = new Dispatcher();
        dispatcher.start();

        // prepare target 1
        TestTarget target1 = new TestTarget(11111);
        target1.start();
        SocketChannel channel1 = target1.getSocketChannel();
        channel1.configureBlocking(false);
        TestChannelHandler handler1 = new TestChannelHandler();
        handler1.setInputHandling(TestChannelHandler.InputHandling.FORWARD);
        dispatcher.registerChannel(channel1, handler1);

        // prepare target 2
        TestTarget target2 = new TestTarget(22222);
        target2.start();
        SocketChannel channel2 = target2.getSocketChannel();
        channel2.configureBlocking(false);
        TestChannelHandler handler2 = new TestChannelHandler();
        handler2.setInputHandling(TestChannelHandler.InputHandling.FORWARD);
        dispatcher.registerChannel(channel2, handler2);

        // set up cross references
        handler1.setPeer(handler2);
        handler2.setPeer(handler1);

        // start communication
        target1.write("message1".getBytes());
        target2.write("message2".getBytes());

        // test for deadlock
        assertTrue(handler1.hasForwarded());
        assertTrue(handler2.hasForwarded());
    }
View Full Code Here

        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setLevel(Level.FINEST);
        logger.addHandler(consoleHandler);
        SteppingDispatcher steppingDispatcher = new SteppingDispatcher();
        steppingDispatcher.start();
        TestTarget testTarget = new TestTarget(12345);
        testTarget.start();
        SocketChannel channel = testTarget.getSocketChannel();
        BlockingSocketChannel blockingChannel =
                new BlockingSocketChannel(channel);
        blockingChannel.configureBlocking(false);
        TestChannelHandler testChannelHandler = new TestChannelHandler();
        steppingDispatcher.registerChannel(blockingChannel, testChannelHandler);

        logger.finest("close input from target");
        testTarget.shutdownOutput();

        logger.finest("wait until shutdown propagated through framework");
        testChannelHandler.waitForInputClosed();

        logger.finest(
View Full Code Here

        ConsoleHandler consoleHandler = new ConsoleHandler();
        consoleHandler.setLevel(Level.FINEST);
        logger.addHandler(consoleHandler);
        CacheStopDispatcher cacheStopDispatcher = new CacheStopDispatcher();
        cacheStopDispatcher.start();
        TestTarget testTarget = new TestTarget(12345);
        testTarget.start();
        SocketChannel channel = testTarget.getSocketChannel();
        BlockingSocketChannel blockingChannel = new BlockingSocketChannel(channel);
        blockingChannel.configureBlocking(false);
        final TestChannelHandler testChannelHandler = new TestChannelHandler();
        cacheStopDispatcher.registerChannel(blockingChannel, testChannelHandler);

        // trigger selection by writing some bytes from testTarget
        testTarget.write(testString.getBytes());

        // wait for caching
        cacheStopDispatcher.waitForHandlerAdapter();

        // now test if another thread can write something to the writer
View Full Code Here

        Dispatcher dispatcher = new Dispatcher();
        dispatcher.start();

        // start a dummy target
        final int PORT = 11111;
        TestTarget testTarget = new TestTarget(PORT);
        testTarget.start();
        testTarget.getSocketChannel();

        MyClientSocketChannelHandler handler =
                new MyClientSocketChannelHandler();
        dispatcher.registerClientSocketChannelHandler(
                "localhost", PORT, handler);
View Full Code Here

TOP

Related Classes of ch.unifr.nio.framework.mockups.TestTarget

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.