Search in sources :

Example 1 with ConnectionOrderedChannelHandler

use of org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler in project dubbo by alibaba.

the class ConnectChannelHandlerTest method test_Received_Event_invoke_direct.

/**
 * Events do not pass through the thread pool and execute directly on the IO
 */
@SuppressWarnings("deprecation")
@Disabled("Heartbeat is processed in HeartbeatHandler not WrappedChannelHandler.")
@Test
public void test_Received_Event_invoke_direct() throws RemotingException {
    handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
    ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "SHARED_EXECUTOR", 1);
    executor.shutdown();
    executor = (ThreadPoolExecutor) getField(handler, "executor", 1);
    executor.shutdown();
    Request req = new Request();
    req.setHeartbeat(true);
    final AtomicInteger count = new AtomicInteger(0);
    handler.received(new MockedChannel() {

        @Override
        public void send(Object message) throws RemotingException {
            Assertions.assertTrue(((Response) message).isHeartbeat(), "response.heartbeat");
            count.incrementAndGet();
        }
    }, req);
    Assertions.assertEquals(1, count.get(), "channel.send must be invoke");
}
Also used : Response(org.apache.dubbo.remoting.exchange.Response) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RemotingException(org.apache.dubbo.remoting.RemotingException) Request(org.apache.dubbo.remoting.exchange.Request) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 2 with ConnectionOrderedChannelHandler

use of org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler in project dubbo by alibaba.

the class ConnectChannelHandlerTest method test_Connect_Execute_Error.

@Test
public void test_Connect_Execute_Error() throws RemotingException {
    Assertions.assertThrows(ExecutionException.class, () -> {
        handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
        ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "connectionExecutor", 1);
        executor.shutdown();
        handler.connected(new MockedChannel());
    });
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test)

Example 3 with ConnectionOrderedChannelHandler

use of org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler in project dubbo by alibaba.

the class ConnectChannelHandlerTest method test_Received_InvokeInExecuter.

@Test
@Disabled("FIXME")
public void test_Received_InvokeInExecuter() throws RemotingException {
    Assertions.assertThrows(ExecutionException.class, () -> {
        handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
        ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "SHARED_EXECUTOR", 1);
        executor.shutdown();
        executor = (ThreadPoolExecutor) getField(handler, "executor", 1);
        executor.shutdown();
        handler.received(new MockedChannel(), "");
    });
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test) Disabled(org.junit.jupiter.api.Disabled)

Example 4 with ConnectionOrderedChannelHandler

use of org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler in project dubbo by alibaba.

the class ConnectChannelHandlerTest method test_Connect_Blocked.

@Test
public void test_Connect_Blocked() throws RemotingException {
    handler = new ConnectionOrderedChannelHandler(new BizChannelHander(false), url);
    ThreadPoolExecutor executor = (ThreadPoolExecutor) getField(handler, "connectionExecutor", 1);
    Assertions.assertEquals(1, executor.getMaximumPoolSize());
    int runs = 20;
    int taskCount = runs * 2;
    for (int i = 0; i < runs; i++) {
        handler.connected(new MockedChannel());
        handler.disconnected(new MockedChannel());
        Assertions.assertTrue(executor.getActiveCount() <= 1, executor.getActiveCount() + " must <=1");
    }
    // queue.size
    Assertions.assertEquals(taskCount - 1, executor.getQueue().size());
    for (int i = 0; i < taskCount; i++) {
        if (executor.getCompletedTaskCount() < taskCount) {
            sleep(100);
        }
    }
    Assertions.assertEquals(taskCount, executor.getCompletedTaskCount());
}
Also used : ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test)

Example 5 with ConnectionOrderedChannelHandler

use of org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler in project dubbo by alibaba.

the class ConnectChannelHandlerTest method test_Connect_Biz_Error.

// biz error should not throw and affect biz thread.
@Test
public void test_Connect_Biz_Error() throws RemotingException {
    handler = new ConnectionOrderedChannelHandler(new BizChannelHander(true), url);
    handler.connected(new MockedChannel());
}
Also used : ConnectionOrderedChannelHandler(org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler) Test(org.junit.jupiter.api.Test)

Aggregations

ConnectionOrderedChannelHandler (org.apache.dubbo.remoting.transport.dispatcher.connection.ConnectionOrderedChannelHandler)7 Test (org.junit.jupiter.api.Test)7 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5 Disabled (org.junit.jupiter.api.Disabled)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 RemotingException (org.apache.dubbo.remoting.RemotingException)1 Request (org.apache.dubbo.remoting.exchange.Request)1 Response (org.apache.dubbo.remoting.exchange.Response)1