Search in sources :

Example 61 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ReplicatedMapTest method testValues.

private void testValues(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    int half = keys.size() / 2, i = 0;
    for (String key : keys) {
        final ReplicatedMap<String, String> map = i++ < half ? map1 : map2;
        map.put(key, key);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(keys, new HashSet<String>(map1.values()));
            assertEquals(keys, new HashSet<String>(map2.values()));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) HashSet(java.util.HashSet)

Example 62 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ReplicatedMapTest method testKeySet.

private void testKeySet(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    int half = keys.size() / 2, i = 0;
    for (String key : keys) {
        final ReplicatedMap<String, String> map = i++ < half ? map1 : map2;
        map.put(key, key);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(keys, new HashSet<String>(map1.keySet()));
            assertEquals(keys, new HashSet<String>(map2.keySet()));
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException) HashSet(java.util.HashSet)

Example 63 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class ReplicatedMapTest method testAddTtl.

private void testAddTtl(Config config) throws Exception {
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final ReplicatedMap<String, String> map1 = instance1.getReplicatedMap("default");
    final ReplicatedMap<String, String> map2 = instance2.getReplicatedMap("default");
    final int partitionCount = getPartitionService(instance1).getPartitionCount();
    final Set<String> keys = generateRandomKeys(instance1, partitionCount);
    for (String key : keys) {
        map1.put(key, "bar", 10, TimeUnit.MINUTES);
    }
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                assertEquals("bar", map1.get(key));
                ReplicatedRecord<String, String> record = getReplicatedRecord(map1, key);
                assertNotNull(record);
                assertNotEquals(0, record.getTtlMillis());
            }
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            for (String key : keys) {
                assertEquals("bar", map2.get(key));
                ReplicatedRecord<String, String> record = getReplicatedRecord(map2, key);
                assertNotNull(record);
                assertNotEquals(0, record.getTtlMillis());
            }
        }
    });
}
Also used : ReplicatedRecord(com.hazelcast.replicatedmap.impl.record.ReplicatedRecord) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) TimeoutException(java.util.concurrent.TimeoutException)

Example 64 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class Invocation_NetworkSplitTest method testWaitNotifyService_whenNodeSplitFromCluster.

private void testWaitNotifyService_whenNodeSplitFromCluster(SplitAction action) throws Exception {
    Config config = createConfig();
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
    HazelcastInstance hz1 = factory.newHazelcastInstance(config);
    HazelcastInstance hz2 = factory.newHazelcastInstance(config);
    HazelcastInstance hz3 = factory.newHazelcastInstance(config);
    final Node node1 = TestUtil.getNode(hz1);
    Node node2 = TestUtil.getNode(hz2);
    Node node3 = TestUtil.getNode(hz3);
    warmUpPartitions(hz1, hz2, hz3);
    int partitionId = getPartitionId(hz3);
    NodeEngineImpl nodeEngine1 = node1.getNodeEngine();
    OperationService operationService1 = nodeEngine1.getOperationService();
    operationService1.invokeOnPartition("", new AlwaysBlockingOperation(), partitionId);
    final OperationParkerImpl waitNotifyService3 = (OperationParkerImpl) node3.getNodeEngine().getOperationParker();
    assertEqualsEventually(new Callable<Integer>() {

        @Override
        public Integer call() throws Exception {
            return waitNotifyService3.getTotalParkedOperationCount();
        }
    }, 1);
    action.run(node1, node2, node3);
    // create a new node to prevent same partition assignments
    // after node3 rejoins
    factory.newHazelcastInstance(config);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Assert.assertEquals(0, node1.partitionService.getMigrationQueueSize());
        }
    });
    // Let node3 detect the split and merge it back to other two.
    ClusterServiceImpl clusterService3 = node3.getClusterService();
    clusterService3.merge(node1.address);
    assertEquals(4, node1.getClusterService().getSize());
    assertEquals(4, node2.getClusterService().getSize());
    assertEquals(4, node3.getClusterService().getSize());
    assertEquals(0, waitNotifyService3.getTotalParkedOperationCount());
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) Node(com.hazelcast.instance.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) TimeoutException(java.util.concurrent.TimeoutException) MemberLeftException(com.hazelcast.core.MemberLeftException) OperationParkerImpl(com.hazelcast.spi.impl.operationparker.impl.OperationParkerImpl) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) OperationService(com.hazelcast.spi.OperationService) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory)

Example 65 with AssertTask

use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.

the class Invocation_RetryTest method testNoStuckInvocationsWhenRetriedMultipleTimes.

@Test
public void testNoStuckInvocationsWhenRetriedMultipleTimes() throws Exception {
    Config config = new Config();
    config.setProperty(GroupProperty.OPERATION_CALL_TIMEOUT_MILLIS.getName(), "3000");
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    HazelcastInstance local = factory.newHazelcastInstance(config);
    HazelcastInstance remote = factory.newHazelcastInstance(config);
    warmUpPartitions(local, remote);
    NodeEngineImpl localNodeEngine = getNodeEngineImpl(local);
    NodeEngineImpl remoteNodeEngine = getNodeEngineImpl(remote);
    final OperationServiceImpl operationService = (OperationServiceImpl) localNodeEngine.getOperationService();
    NonResponsiveOperation op = new NonResponsiveOperation();
    op.setValidateTarget(false);
    op.setPartitionId(1);
    InvocationFuture future = (InvocationFuture) operationService.invokeOnTarget(null, op, remoteNodeEngine.getThisAddress());
    Field invocationField = InvocationFuture.class.getDeclaredField("invocation");
    invocationField.setAccessible(true);
    Invocation invocation = (Invocation) invocationField.get(future);
    invocation.notifyError(new RetryableHazelcastException());
    invocation.notifyError(new RetryableHazelcastException());
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Iterator<Invocation> invocations = operationService.invocationRegistry.iterator();
            assertFalse(invocations.hasNext());
        }
    });
}
Also used : NodeEngineImpl(com.hazelcast.spi.impl.NodeEngineImpl) Config(com.hazelcast.config.Config) TimeoutException(java.util.concurrent.TimeoutException) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) MemberLeftException(com.hazelcast.core.MemberLeftException) ExecutionException(java.util.concurrent.ExecutionException) Field(java.lang.reflect.Field) HazelcastInstance(com.hazelcast.core.HazelcastInstance) RetryableHazelcastException(com.hazelcast.spi.exception.RetryableHazelcastException) Iterator(java.util.Iterator) AssertTask(com.hazelcast.test.AssertTask) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

AssertTask (com.hazelcast.test.AssertTask)575 Test (org.junit.Test)489 QuickTest (com.hazelcast.test.annotation.QuickTest)428 ParallelTest (com.hazelcast.test.annotation.ParallelTest)347 HazelcastInstance (com.hazelcast.core.HazelcastInstance)263 Config (com.hazelcast.config.Config)113 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)94 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)75 ExecutionException (java.util.concurrent.ExecutionException)57 MapConfig (com.hazelcast.config.MapConfig)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)48 IOException (java.io.IOException)46 CountDownLatch (java.util.concurrent.CountDownLatch)42 IMap (com.hazelcast.core.IMap)39 NearCacheConfig (com.hazelcast.config.NearCacheConfig)38 TimeoutException (java.util.concurrent.TimeoutException)33 ClientConfig (com.hazelcast.client.config.ClientConfig)32 MapStoreConfig (com.hazelcast.config.MapStoreConfig)29 ExpectedRuntimeException (com.hazelcast.test.ExpectedRuntimeException)23 AtomicReference (java.util.concurrent.atomic.AtomicReference)20