Skip to content

Commit

Permalink
Fix ClientDisconnectTest failure
Browse files Browse the repository at this point in the history
In the failing tests, the client is issuing an async operation and then terminating afterwards. If the client termination occurs before the invocation is started & registered on the server, that invocation will not be notified during handling termination of the client. Therefore, before terminating the client, tests should wait until its operations are registered on the server.

Fixes hazelcast#13680
  • Loading branch information
metanet authored and Jiří Holuša committed Sep 3, 2018
1 parent f57849a commit c37a4b0
Showing 1 changed file with 28 additions and 8 deletions.
Expand Up @@ -28,7 +28,6 @@
import com.hazelcast.core.Message;
import com.hazelcast.spi.impl.NodeEngineImpl;
import com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl;
import com.hazelcast.spi.impl.operationservice.impl.Invocation;
import com.hazelcast.spi.impl.operationservice.impl.InvocationRegistry;
import com.hazelcast.spi.impl.operationservice.impl.OperationServiceImpl;
import com.hazelcast.spi.properties.GroupProperty;
Expand All @@ -38,19 +37,17 @@
import com.hazelcast.test.annotation.ParallelTest;
import com.hazelcast.test.annotation.QuickTest;
import com.hazelcast.topic.ReliableMessageListener;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.Map;
import java.util.concurrent.CountDownLatch;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

@RunWith(HazelcastParallelClassRunner.class)
@Category({QuickTest.class, ParallelTest.class})
Expand Down Expand Up @@ -190,7 +187,7 @@ public void run() {
}
});

sleepSeconds(3);
assertNonEmptyPendingInvocationAndWaitSet(server);

client.shutdown();

Expand All @@ -206,11 +203,34 @@ public void testPendingInvocationAndWaitEntryCancelled_whenDisconnected_withReli
// ReliableTopic listener registers a blocking invocation
client.getReliableTopic(randomName()).addMessageListener(new NopReliableMessageListener());

assertNonEmptyPendingInvocationAndWaitSet(server);

client.shutdown();

assertEmptyPendingInvocationAndWaitSet(server);
}

private void assertNonEmptyPendingInvocationAndWaitSet(HazelcastInstance server) {
NodeEngineImpl nodeEngine = getNodeEngineImpl(server);
OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();
final InvocationRegistry invocationRegistry = operationService.getInvocationRegistry();
final OperationParkerImpl operationParker = (OperationParkerImpl) nodeEngine.getOperationParker();

assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertFalse(invocationRegistry.entrySet().isEmpty());
}
});

assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertTrue(operationParker.getTotalParkedOperationCount() > 0);
}
});
}

private void assertEmptyPendingInvocationAndWaitSet(HazelcastInstance server) {
NodeEngineImpl nodeEngine = getNodeEngineImpl(server);
OperationServiceImpl operationService = (OperationServiceImpl) nodeEngine.getOperationService();
Expand All @@ -220,16 +240,16 @@ private void assertEmptyPendingInvocationAndWaitSet(HazelcastInstance server) {
assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertThat(invocationRegistry.entrySet(), Matchers.<Map.Entry<Long, Invocation>>empty());
assertTrue(invocationRegistry.entrySet().isEmpty());
}
}, 10);
});

assertTrueEventually(new AssertTask() {
@Override
public void run() {
assertEquals(0, operationParker.getTotalParkedOperationCount());
}
}, 10);
});
}

private static class NopReliableMessageListener implements ReliableMessageListener<Object> {
Expand Down

0 comments on commit c37a4b0

Please sign in to comment.