Package ch.unifr.nio.framework.mockups

Examples of ch.unifr.nio.framework.mockups.TestChannelHandler$TestTransformer


        // 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


        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

        dataChannel = DatagramChannel.open();
        dataChannel.configureBlocking(false);

        // we need a ChannelHandler...
        // for this test we will use the EchoChannelHandler
        channelHandler = new TestChannelHandler();
    }
View Full Code Here

        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
        final ChannelWriter channelWriter = testChannelHandler.getChannelWriter();
        Thread testThread = new Thread() {

            @Override
            public void run() {
                try {
View Full Code Here

        // for this we need a Dispatcher and a channel with a registered
        // interest. to register a channel we need a SelectableChannel and a
        // ChannelHandler
        Dispatcher dispatcher = new Dispatcher();

        ChannelHandler channelHandler = new TestChannelHandler();
        DatagramChannel channel = DatagramChannel.open();
        channel.configureBlocking(false);
        dispatcher.registerChannel(channel, channelHandler);

        // to get access to the HandlerAdapter we need to break open the
View Full Code Here

        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

                new MyTrafficShaper[numberOfTrafficShapers];
        for (int i = 0; i < numberOfTrafficShapers; i++) {
            MyTrafficShaper myTrafficShaper = new MyTrafficShaper(i);
            myTrafficShapers[i] = myTrafficShaper;
            trafficShaperCoordinator.addTrafficShaper(
                    new TestChannelHandler(), myTrafficShaper);
        }

        // let the trafficShaperCoordinator run twice the necessary time
        // (just to be sure that we call the trafficShapers often enough)
        trafficShaperCoordinator.start();
View Full Code Here

        assertNull("TrafficShaperCoordinator must not be scheduled without "
                + "any traffic shapers added!", futureObject);

        // check that adding a traffic shaper actually starts the
        // TrafficShaperCoordinator
        TestChannelHandler testChannelHandler = new TestChannelHandler();
        BufferForwarder bufferForwarder =
                new BufferForwarder(ByteBufferForwardingMode.DIRECT);
        trafficShaperCoordinator.addTrafficShaper(
                testChannelHandler, bufferForwarder);
        Future future = (Future) futureField.get(trafficShaperCoordinator);
View Full Code Here

TOP

Related Classes of ch.unifr.nio.framework.mockups.TestChannelHandler$TestTransformer

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.