Package ch.unifr.nio.framework.mockups

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


        Logger logger = Logger.getLogger("InputClosedTest");
        logger.setLevel(Level.FINEST);
        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(
                "trigger another selection round by blocking write operation");
        ChannelWriter channelWriter = testChannelHandler.getChannelWriter();
        StringToByteBufferTransformer transformer =
                new StringToByteBufferTransformer();
        transformer.setNextForwarder(channelWriter);
        transformer.forward(
                "this must block and trigger another selection round");

        logger.finest("push dispatcher some selection rounds forward");
        // (we REALLY need two calls here as the first round does not have the
        // incomplete write in its selected set...)
        steppingDispatcher.continueDispatcher();
        steppingDispatcher.continueDispatcher();

        // test that closeCounter is still at one after the selection rounds
        // above
        assertEquals(1, testChannelHandler.getCloseCounter());
    }
View Full Code Here


        Logger logger = Logger.getLogger("CachedOpsTest");
        logger.setLevel(Level.FINEST);
        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();
        assertEquals("cachedInterestOps: "
                + HandlerAdapter.interestToString(cachedInterestOps),
                SelectionKey.OP_READ | SelectionKey.OP_WRITE,
                cachedInterestOps);

        SelectionKey selectionKey = testChannelHandler.getSelectionKey();
        int interestOps = steppingDispatcher.getInterestOps(selectionKey);
        assertEquals("selectionKey interestOps: "
                + HandlerAdapter.interestToString(interestOps), 0, interestOps);
    }
View Full Code Here

TOP

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

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.