Search in sources :

Example 11 with AssertTask

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

the class InternalPartitionServiceLiteMemberTest method test_getPartitionOwnerOrWait_onLiteMemberAfterDataMemberTerminates.

@Test
public void test_getPartitionOwnerOrWait_onLiteMemberAfterDataMemberTerminates() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance master = factory.newHazelcastInstance();
    final HazelcastInstance lite = factory.newHazelcastInstance(liteMemberConfig);
    warmUpPartitions(master, lite);
    master.getLifecycleService().terminate();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            try {
                final InternalPartitionServiceImpl partitionService = getInternalPartitionServiceImpl(lite);
                partitionService.getPartitionOwnerOrWait(0);
                fail();
            } catch (NoDataMemberInClusterException expected) {
                ignore(expected);
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 12 with AssertTask

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

the class InternalPartitionServiceLiteMemberTest method test_getPartitionOwnerOrWait_onLiteMemberAfterDataMemberShutsDown.

@Test
public void test_getPartitionOwnerOrWait_onLiteMemberAfterDataMemberShutsDown() {
    final TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance master = factory.newHazelcastInstance();
    final HazelcastInstance lite = factory.newHazelcastInstance(liteMemberConfig);
    assertClusterSizeEventually(2, master);
    assertClusterSizeEventually(2, lite);
    warmUpPartitions(master, lite);
    master.getLifecycleService().shutdown();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            try {
                final InternalPartitionServiceImpl partitionService = getInternalPartitionServiceImpl(lite);
                partitionService.getPartitionOwnerOrWait(0);
                fail();
            } catch (NoDataMemberInClusterException expected) {
                ignore(expected);
            }
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) NoDataMemberInClusterException(com.hazelcast.partition.NoDataMemberInClusterException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 13 with AssertTask

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

the class LocalMapStatsTest method testLastAccessTime_updatedConcurrently.

@Test
public void testLastAccessTime_updatedConcurrently() throws InterruptedException {
    final long startTime = Clock.currentTimeMillis();
    final IMap<String, String> map = getMap();
    final String key = "key";
    map.put(key, "value");
    map.put(key, "value");
    final LocalMapStats localMapStats = map.getLocalMapStats();
    final long lastUpdateTime = localMapStats.getLastUpdateTime();
    new Thread(new Runnable() {

        @Override
        public void run() {
            sleepAtLeastMillis(1);
            map.put(key, "value2");
            // causes the local stats object to update
            map.getLocalMapStats();
        }
    }).start();
    assertTrue(lastUpdateTime >= startTime);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(localMapStats.getLastUpdateTime() > lastUpdateTime);
        }
    });
}
Also used : LocalMapStats(com.hazelcast.monitor.LocalMapStats) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 14 with AssertTask

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

the class LocalMapStatsTest_WhenMigration method testHitsGenerated_newNode.

@Test
public void testHitsGenerated_newNode() throws Exception {
    for (int i = 0; i < 100; i++) {
        map.put(i, i);
        map.get(i);
    }
    hz2 = factory.newHazelcastInstance();
    final IMap<Object, Object> trial = hz2.getMap("trial");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            long hits2 = trial.getLocalMapStats().getHits();
            long hits1 = map.getLocalMapStats().getHits();
            assertEquals(100, hits1 + hits2);
        }
    });
}
Also used : AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 15 with AssertTask

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

the class ListenerTest method testMapPartitionLostListener_registeredViaImplementationInConfigObject.

@Test
public void testMapPartitionLostListener_registeredViaImplementationInConfigObject() {
    final String name = randomString();
    Config config = getConfig();
    MapConfig mapConfig = config.getMapConfig(name);
    MapPartitionLostListener listener = mock(MapPartitionLostListener.class);
    mapConfig.addMapPartitionLostListenerConfig(new MapPartitionLostListenerConfig(listener));
    mapConfig.setBackupCount(0);
    HazelcastInstance instance = createHazelcastInstance(config);
    instance.getMap(name);
    final EventService eventService = getNode(instance).getNodeEngine().getEventService();
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            final Collection<EventRegistration> registrations = eventService.getRegistrations(MapService.SERVICE_NAME, name);
            assertFalse(registrations.isEmpty());
        }
    });
}
Also used : MapPartitionLostListener(com.hazelcast.map.listener.MapPartitionLostListener) HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) MapConfig(com.hazelcast.config.MapConfig) EntryListenerConfig(com.hazelcast.config.EntryListenerConfig) Config(com.hazelcast.config.Config) MapPartitionLostListenerConfig(com.hazelcast.config.MapPartitionLostListenerConfig) AssertTask(com.hazelcast.test.AssertTask) Collection(java.util.Collection) EventService(com.hazelcast.spi.EventService) MapConfig(com.hazelcast.config.MapConfig) IOException(java.io.IOException) 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