Examples of DummySession


Examples of org.apache.mina.common.DummySession

        StringBuffer buf = new StringBuffer();
        chain.addLast("A", new TestCommand(buf, 'A'));
        chain.addLast("B", new TestCommand(buf, 'B'));
        chain.addLast("C", new TestCommand(buf, 'C'));

        new ChainedIoHandler(chain).messageReceived(new DummySession(), null);

        Assert.assertEquals("ABC", buf.toString());
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        StringBuilder buf = new StringBuilder();
        chain.addLast("A", new TestCommand(buf, 'A'));
        chain.addLast("B", new TestCommand(buf, 'B'));
        chain.addLast("C", new TestCommand(buf, 'C'));

        new ChainedIoHandler(chain).messageReceived(new DummySession(), null);

        assertEquals("ABC", buf.toString());
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

    public void setUp() throws Exception {
        scheduler = Executors.newScheduledThreadPool(1);
        filter = new RequestResponseFilter(new MessageInspector(), scheduler);

        // Set up mock objects.
        session = new DummySession();
        chain = session.getFilterChain();
        nextFilterControl = MockControl.createControl(NextFilter.class);
        nextFilter = (NextFilter) nextFilterControl.getMock();

        // Initialize the filter.
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        IoBuffer dest = IoBuffer.allocate(1);
        assertEquals(false, dest.isAutoExpand());
    }

    public void testBasicBuffering() {
        DummySession sess = new DummySession();
        sess.getFilterChain().addFirst("peer", new IoFilterAdapter() {

            private int counter;

            @Override
            public void filterClose(NextFilter nextFilter, IoSession session)
                    throws Exception {
                logger.debug("Filter closed !");
                assertEquals(3, counter);
            }

            @Override
            public void filterWrite(NextFilter nextFilter, IoSession session,
                    WriteRequest writeRequest) throws Exception {
                logger.debug("New buffered message written !");
                counter++;
                try {
                    IoBuffer buf = (IoBuffer) writeRequest.getMessage();
                    if (counter == 3) {
                        assertEquals(1, buf.limit());
                        assertEquals(0, buf.get());
                    } else {
                        assertEquals(10, buf.limit());
                    }
                } catch (Exception ex) {
                    throw new AssertionError("Wrong message type");
                }
            }

        });
        sess.getFilterChain().addFirst("logger", new LoggingFilter());
        BufferedWriteFilter bFilter = new BufferedWriteFilter(10);
        sess.getFilterChain().addLast("buffer", bFilter);

        IoBuffer data = IoBuffer.allocate(1);
        for (byte i = 0; i < 20; i++) {
            data.put((byte) (0x30 + i));
            data.flip();
            sess.write(data);
            data.clear();
        }

        // Add one more byte to overflow the final buffer
        data.put((byte) 0);
        data.flip();
        sess.write(data);
       
        // Flush the final byte
        bFilter.flush(sess);
       
        sess.close(true);
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

    @Override
    protected void setUp() throws Exception
    {
        filter = new ConnectionThrottleFilter();

        sessionOne = new DummySession();
        sessionOne.setRemoteAddress( new InetSocketAddress(1234) );
        sessionTwo = new DummySession();
        sessionTwo.setRemoteAddress( new InetSocketAddress(1235) );
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        assertNull(future.getException());

        TestThread thread = new TestThread(future);
        thread.start();

        IoSession session = new DummySession();

        future.setSession(session);
        thread.join();

        assertTrue(thread.success);
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        map.put("uri", "/dir/index.html");
        map.put("username", USER);

        String response = null;
        try {
            response = DigestUtilities.computeResponseValue(new DummySession(),
                    map, METHOD, PWD, CHARSET_IN_USE, null);
            assertEquals("6629fae49393a05397450978507c4ef1", response);
            writeResponse(map, response);
        } catch (Exception e) {
            //e.printStackTrace();
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

    @Test
    public void testSessionLifecycle() throws Exception {
        IoServiceListenerSupport support = new IoServiceListenerSupport(
                mockService);

        DummySession session = new DummySession();
        session.setService(mockService);
        session.setLocalAddress(ADDRESS);

        IoHandler handler = EasyMock.createStrictMock( IoHandler.class );
        session.setHandler(handler);

        IoServiceListener listener = EasyMock.createStrictMock(IoServiceListener.class);

        // Test creation
        listener.sessionCreated(session);
        handler.sessionCreated(session);
        handler.sessionOpened(session);

        EasyMock.replay(listener);
        EasyMock.replay(handler);

        support.add(listener);
        support.fireSessionCreated(session);

        EasyMock.verify(listener);
        EasyMock.verify(handler);

        assertEquals(1, support.getManagedSessions().size());
        assertSame(session, support.getManagedSessions().get(session.getId()));

        // Test destruction & other side effects
        EasyMock.reset(listener);
        EasyMock.reset(handler);
        handler.sessionClosed(session);
        listener.sessionDestroyed(session);

        EasyMock.replay(listener);
        //// Activate more than once
        support.fireSessionCreated(session);
        //// Deactivate
        support.fireSessionDestroyed(session);
        //// Deactivate more than once
        support.fireSessionDestroyed(session);

        EasyMock.verify(listener);

        assertTrue(session.isClosing());
        assertEquals(0, support.getManagedSessions().size());
        assertNull(support.getManagedSessions().get(session.getId()));
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        IoAcceptor acceptor = EasyMock.createStrictMock(IoAcceptor.class);

        final IoServiceListenerSupport support = new IoServiceListenerSupport(
                acceptor);

        final DummySession session = new DummySession();
        session.setService(acceptor);
        session.setLocalAddress(ADDRESS);

        IoHandler handler = EasyMock.createStrictMock(IoHandler.class);
        session.setHandler(handler);

        final IoServiceListener listener = EasyMock.createStrictMock(IoServiceListener.class);

        // Activate a service and create a session.
        listener.serviceActivated(acceptor);
        listener.sessionCreated(session);
        handler.sessionCreated(session);
        handler.sessionOpened(session);

        EasyMock.replay(listener);
        EasyMock.replay(handler);

        support.add(listener);
        support.fireServiceActivated();
        support.fireSessionCreated(session);

        EasyMock.verify(listener);
        EasyMock.verify(handler);

        // Deactivate a service and make sure the session is closed & destroyed.
        EasyMock.reset(listener);
        EasyMock.reset(handler);

        listener.serviceDeactivated(acceptor);
        EasyMock.expect(acceptor.isCloseOnDeactivation()).andReturn(true);
        listener.sessionDestroyed(session);
        handler.sessionClosed(session);

        EasyMock.replay(listener);
        EasyMock.replay(acceptor);
        EasyMock.replay(handler);

        new Thread() {
            // Emulate I/O service
            @Override
            public void run() {
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    //e.printStackTrace();
                }
                // This synchronization block is a workaround for
                // the visibility problem of simultaneous EasyMock
                // state update. (not sure if it fixes the failing test yet.)
                synchronized (listener) {
                    support.fireSessionDestroyed(session);
                }
            }
        }.start();
        support.fireServiceDeactivated();

        synchronized (listener) {
            EasyMock.verify(listener);
        }
        EasyMock.verify(acceptor);
        EasyMock.verify(handler);

        assertTrue(session.isClosing());
        assertEquals(0, support.getManagedSessions().size());
        assertNull(support.getManagedSessions().get(session.getId()));
    }
View Full Code Here

Examples of org.apache.mina.core.session.DummySession

        IoConnector connector = EasyMock.createStrictMock(IoConnector.class);

        IoServiceListenerSupport support = new IoServiceListenerSupport(
                connector);

        final DummySession session = new DummySession();
        session.setService(connector);
        session.setRemoteAddress(ADDRESS);

        IoHandler handler = EasyMock.createStrictMock(IoHandler.class);
        session.setHandler(handler);

        IoServiceListener listener = EasyMock.createStrictMock(IoServiceListener.class);

        // Creating a session should activate a service automatically.
        listener.serviceActivated(connector);
        listener.sessionCreated(session);
        handler.sessionCreated(session);
        handler.sessionOpened(session);

        EasyMock.replay(listener);
        EasyMock.replay(handler);

        support.add(listener);
        support.fireSessionCreated(session);

        EasyMock.verify(listener);
        EasyMock.verify(handler);

        // Destroying a session should deactivate a service automatically.
        EasyMock.reset(listener);
        EasyMock.reset(handler);
        listener.sessionDestroyed(session);
        handler.sessionClosed(session);
        listener.serviceDeactivated(connector);

        EasyMock.replay(listener);
        EasyMock.replay(handler);

        support.fireSessionDestroyed(session);

        EasyMock.verify(listener);
        EasyMock.verify(handler);

        assertEquals(0, support.getManagedSessions().size());
        assertNull(support.getManagedSessions().get(session.getId()));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.