@Test public void testAllUpdatesReflectedToMapStore() throws Exception { int nodeCount = 3; final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>(); TestMapUsingMapStoreBuilder builder = TestMapUsingMapStoreBuilder.create() .withMapStore(mapStore) .withNodeCount(nodeCount) .withNodeFactory(createHazelcastInstanceFactory(nodeCount)) .withBackupCount(0) .withWriteCoalescing(false) .withWriteDelaySeconds(3); IMap<Object, Object> map = builder.build(); for (int i = 0; i < 500; i++) { map.put(i, randomString()); } for (int i = 0; i < 500; i++) { map.remove(i); } assertTrueEventually( new AssertTask() { @Override public void run() throws Exception { final int storeCount = mapStore.countStore.get(); final int deleteCount = mapStore.countDelete.get(); assertEquals(1000, storeCount + deleteCount); assertTrue(mapStore.store.isEmpty()); } }); }
@Test(expected = ReachedMaxSizeException.class) public void testCounter_whenMaxCapacityExceeded() throws Exception { final int maxCapacityPerNode = 100; final int nodeCount = 1; final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>(); final TestMapUsingMapStoreBuilder builder = TestMapUsingMapStoreBuilder.create() .withMapStore(mapStore) .withNodeCount(nodeCount) .withNodeFactory(createHazelcastInstanceFactory(1)) .withBackupCount(0) .withWriteCoalescing(false) .withWriteBehindQueueCapacity(maxCapacityPerNode) .withWriteDelaySeconds(100); final IMap<Object, Object> map = builder.build(); // exceed max write-behind queue capacity per node. populateMap(map, 2 * maxCapacityPerNode); }
@Test public void testCounter_against_one_node_zero_backup() throws Exception { final int maxCapacityPerNode = 100; final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>(); final TestMapUsingMapStoreBuilder builder = TestMapUsingMapStoreBuilder.create() .withMapStore(mapStore) .withNodeCount(1) .withNodeFactory(createHazelcastInstanceFactory(1)) .withBackupCount(0) .withWriteDelaySeconds(100) .withWriteCoalescing(false) .withWriteBehindQueueCapacity(maxCapacityPerNode); final IMap<Object, Object> map = builder.build(); populateMap(map, maxCapacityPerNode); assertEquals(maxCapacityPerNode, map.size()); }
@Test public void testCounter_against_many_nodes() throws Exception { final int maxCapacityPerNode = 100; final int nodeCount = 2; final MapStoreWithCounter mapStore = new MapStoreWithCounter<Integer, String>(); final TestMapUsingMapStoreBuilder builder = TestMapUsingMapStoreBuilder.create() .withMapStore(mapStore) .withNodeCount(nodeCount) .withNodeFactory(createHazelcastInstanceFactory(nodeCount)) .withBackupCount(0) .withWriteCoalescing(false) .withWriteBehindQueueCapacity(maxCapacityPerNode) .withWriteDelaySeconds(100); final IMap<Object, Object> map = builder.build(); // put slightly more number of entries which is higher than max write-behind queue capacity per // node. populateMap(map, maxCapacityPerNode + 3); assertTrue(map.size() > maxCapacityPerNode); }