Search in sources :

Example 6 with SemaphoreReleaseOnlyOnce

use of org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce in project rocketmq by apache.

the class NettyRemotingAbstractTest method testProcessResponseCommand.

@Test
public void testProcessResponseCommand() throws InterruptedException {
    final Semaphore semaphore = new Semaphore(0);
    ResponseFuture responseFuture = new ResponseFuture(1, 3000, new InvokeCallback() {

        @Override
        public void operationComplete(final ResponseFuture responseFuture) {
            assertThat(semaphore.availablePermits()).isEqualTo(0);
        }
    }, new SemaphoreReleaseOnlyOnce(semaphore));
    remotingAbstract.responseTable.putIfAbsent(1, responseFuture);
    RemotingCommand response = RemotingCommand.createResponseCommand(0, "Foo");
    response.setOpaque(1);
    remotingAbstract.processResponseCommand(null, response);
    // Acquire the release permit after call back
    semaphore.acquire(1);
    assertThat(semaphore.availablePermits()).isEqualTo(0);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) InvokeCallback(org.apache.rocketmq.remoting.InvokeCallback) Semaphore(java.util.concurrent.Semaphore) SemaphoreReleaseOnlyOnce(org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce) Test(org.junit.Test)

Example 7 with SemaphoreReleaseOnlyOnce

use of org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce in project rocketmq by apache.

the class NettyRemotingAbstractTest method testProcessResponseCommand_NullCallBack.

@Test
public void testProcessResponseCommand_NullCallBack() throws InterruptedException {
    final Semaphore semaphore = new Semaphore(0);
    ResponseFuture responseFuture = new ResponseFuture(1, 3000, null, new SemaphoreReleaseOnlyOnce(semaphore));
    remotingAbstract.responseTable.putIfAbsent(1, responseFuture);
    RemotingCommand response = RemotingCommand.createResponseCommand(0, "Foo");
    response.setOpaque(1);
    remotingAbstract.processResponseCommand(null, response);
    assertThat(semaphore.availablePermits()).isEqualTo(1);
}
Also used : RemotingCommand(org.apache.rocketmq.remoting.protocol.RemotingCommand) Semaphore(java.util.concurrent.Semaphore) SemaphoreReleaseOnlyOnce(org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce) Test(org.junit.Test)

Aggregations

SemaphoreReleaseOnlyOnce (org.apache.rocketmq.remoting.common.SemaphoreReleaseOnlyOnce)7 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)4 RemotingSendRequestException (org.apache.rocketmq.remoting.exception.RemotingSendRequestException)4 RemotingTimeoutException (org.apache.rocketmq.remoting.exception.RemotingTimeoutException)4 RemotingTooMuchRequestException (org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException)4 Semaphore (java.util.concurrent.Semaphore)3 RemotingCommand (org.apache.rocketmq.remoting.protocol.RemotingCommand)3 Test (org.junit.Test)3 InvokeCallback (org.apache.rocketmq.remoting.InvokeCallback)2