Search in sources :

Example 36 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class WriteBehindExceptionTest method testWriteBehindStoreWithException.

@Test
public void testWriteBehindStoreWithException() throws InterruptedException {
    final MapStore mapStore = new MapStore();
    mapStore.setLoadAllKeys(false);
    Config config = newConfig(mapStore, 5);
    config.setProperty("hazelcast.local.localAddress", "127.0.0.1");
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<Integer, String> map = instance.getMap("map");
    IMap<Integer, String> map2 = instance.getMap("map2");
    IMap<Integer, String> map3 = instance.getMap("map3");
    for (int i = 0; i < 10; i++) {
        map.put(i, "value-" + i);
    }
    for (int i = 0; i < 10; i++) {
        map2.put(i + 10, "value-" + i);
    }
    for (int i = 0; i < 10; i++) {
        map3.put(i + 20, "value-" + i);
    }
    assertOpenEventually(latch1);
    Thread.sleep(2000);
    assertSizeEventually(29, mapStore.store);
    for (int i = 0; i < 30; i++) {
        map.delete(i);
    }
    assertOpenEventually(latch2);
    Thread.sleep(2000);
    assertSizeEventually(1, mapStore.store);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Config(com.hazelcast.config.Config) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 37 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testOneMemberWriteBehindWithEvictions.

@Test(timeout = 120000)
public void testOneMemberWriteBehindWithEvictions() throws Exception {
    final String mapName = "testOneMemberWriteBehindWithEvictions";
    final EventBasedMapStore testMapStore = new EventBasedMapStore();
    testMapStore.loadAllLatch = new CountDownLatch(1);
    final Config config = newConfig(testMapStore, 2, InitialLoadMode.EAGER);
    final HazelcastInstance instance = createHazelcastInstance(config);
    final IMap<Integer, String> map = instance.getMap(mapName);
    // check if load all called.
    assertTrue("map store loadAllKeys must be called", testMapStore.loadAllLatch.await(10, SECONDS));
    // map population count.
    final int populationCount = 100;
    // latch for store & storeAll events.
    testMapStore.storeLatch = new CountDownLatch(populationCount);
    //populate map.
    for (int i = 0; i < populationCount; i++) {
        map.put(i, "value" + i);
    }
    //wait for all store ops.
    assertOpenEventually(testMapStore.storeLatch);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(0, writeBehindQueueSize(instance, mapName));
        }
    });
    // init before eviction
    testMapStore.storeLatch = new CountDownLatch(populationCount);
    //evict.
    for (int i = 0; i < populationCount; i++) {
        map.evict(i);
    }
    // expect no store op
    assertEquals(populationCount, testMapStore.storeLatch.getCount());
    // check store size
    assertEquals(populationCount, testMapStore.getStore().size());
    // check map size
    assertEquals(0, map.size());
    // re-populate map
    for (int i = 0; i < populationCount; i++) {
        map.put(i, "value" + i);
    }
    // evict again
    for (int i = 0; i < populationCount; i++) {
        map.evict(i);
    }
    // wait for all store ops
    testMapStore.storeLatch.await(10, SECONDS);
    // check store size
    assertEquals(populationCount, testMapStore.getStore().size());
    // check map size
    assertEquals(0, map.size());
    // re-populate map
    for (int i = 0; i < populationCount; i++) {
        map.put(i, "value" + i);
    }
    testMapStore.deleteLatch = new CountDownLatch(populationCount);
    // clear map
    for (int i = 0; i < populationCount; i++) {
        map.remove(i);
    }
    testMapStore.deleteLatch.await(10, SECONDS);
    // check map size
    assertEquals(0, map.size());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) CountDownLatch(java.util.concurrent.CountDownLatch) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 38 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testIssue1085WriteBehindBackupTransactional.

@Test(timeout = 120000)
public void testIssue1085WriteBehindBackupTransactional() throws InterruptedException {
    final String name = randomMapName();
    final int size = 1000;
    MapStoreTest.MapStoreWithStoreCount mapStore = new MapStoreTest.MapStoreWithStoreCount(size, 120);
    Config config = newConfig(name, mapStore, 5);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
    HazelcastInstance instance = factory.newHazelcastInstance(config);
    HazelcastInstance instance2 = factory.newHazelcastInstance(config);
    TransactionContext context = instance.newTransactionContext();
    context.beginTransaction();
    TransactionalMap<Object, Object> tmap = context.getMap(name);
    for (int i = 0; i < size; i++) {
        tmap.put(i, i);
    }
    context.commitTransaction();
    instance2.getLifecycleService().shutdown();
    mapStore.awaitStores();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) TransactionContext(com.hazelcast.transaction.TransactionContext) MapStoreWithStoreCount(com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount) MapStoreWithStoreCount(com.hazelcast.map.impl.mapstore.MapStoreTest.MapStoreWithStoreCount) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 39 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testWriteBehindDestroy.

@Test(timeout = 120000)
@Category(NightlyTest.class)
public // issue #2747: when MapStore configured with write behind, distributed objects' destroy method does not work
void testWriteBehindDestroy() throws InterruptedException {
    final int writeDelaySeconds = 5;
    String mapName = randomMapName();
    final MapStore<String, String> store = new SimpleMapStore<String, String>();
    Config config = newConfig(mapName, store, writeDelaySeconds);
    HazelcastInstance hzInstance = createHazelcastInstance(config);
    IMap<String, String> map = hzInstance.getMap(mapName);
    map.put("key", "value");
    map.destroy();
    sleepSeconds(2 * writeDelaySeconds);
    assertNotEquals("value", store.load("key"));
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) SimpleMapStore(com.hazelcast.map.impl.mapstore.MapStoreTest.SimpleMapStore) Category(org.junit.experimental.categories.Category) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 40 with Config

use of com.hazelcast.config.Config in project hazelcast by hazelcast.

the class MapStoreWriteBehindTest method testOneMemberWriteBehind2.

@Test(timeout = 120000)
public void testOneMemberWriteBehind2() throws Exception {
    final EventBasedMapStore testMapStore = new EventBasedMapStore();
    testMapStore.setLoadAllKeys(false);
    Config config = newConfig(testMapStore, 1, InitialLoadMode.EAGER);
    HazelcastInstance instance = createHazelcastInstance(config);
    IMap<String, String> map = instance.getMap("default");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            Object event = testMapStore.getEvents().poll();
            assertEquals(EventBasedMapStore.STORE_EVENTS.LOAD_ALL_KEYS, event);
        }
    });
    map.put("1", "value1");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(EventBasedMapStore.STORE_EVENTS.LOAD, testMapStore.getEvents().poll());
        }
    });
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(EventBasedMapStore.STORE_EVENTS.STORE, testMapStore.getEvents().poll());
        }
    });
    map.remove("1");
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertEquals(EventBasedMapStore.STORE_EVENTS.DELETE, testMapStore.getEvents().poll());
        }
    });
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapConfig(com.hazelcast.config.MapConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) QuickTest(com.hazelcast.test.annotation.QuickTest) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Config (com.hazelcast.config.Config)2458 Test (org.junit.Test)1570 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1465 QuickTest (com.hazelcast.test.annotation.QuickTest)1286 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1003 MapConfig (com.hazelcast.config.MapConfig)599 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)497 MapStoreConfig (com.hazelcast.config.MapStoreConfig)300 NearCacheConfig (com.hazelcast.config.NearCacheConfig)270 Before (org.junit.Before)242 ClientConfig (com.hazelcast.client.config.ClientConfig)228 SlowTest (com.hazelcast.test.annotation.SlowTest)204 NightlyTest (com.hazelcast.test.annotation.NightlyTest)186 CountDownLatch (java.util.concurrent.CountDownLatch)182 IndexConfig (com.hazelcast.config.IndexConfig)162 JoinConfig (com.hazelcast.config.JoinConfig)142 ParallelTest (com.hazelcast.test.annotation.ParallelTest)141 AssertTask (com.hazelcast.test.AssertTask)131 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)126 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)125