use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWithPredicateTest method testValuesWithPredicate_checksMapStoreLoad.
@Test
public void testValuesWithPredicate_checksMapStoreLoad() {
EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
Map<String, Integer> mapForStore = new HashMap<String, Integer>();
mapForStore.put("key1", 17);
mapForStore.put("key2", 37);
mapForStore.put("key3", 47);
testMapStore.getStore().putAll(mapForStore);
Config config = newConfig(testMapStore, 0);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap("default");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
final Collection values = map.values(Predicates.greaterThan("value", 1));
assertEquals(3, values.size());
assertContains(values, 17);
assertContains(values, 37);
assertContains(values, 47);
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWithPredicateTest method testKeySetWithPredicate_checksMapStoreLoad.
@Test
public void testKeySetWithPredicate_checksMapStoreLoad() {
EventBasedMapStore<String, Integer> testMapStore = new EventBasedMapStore<String, Integer>();
Map<String, Integer> mapForStore = new HashMap<String, Integer>();
mapForStore.put("key1", 17);
mapForStore.put("key2", 37);
mapForStore.put("key3", 47);
testMapStore.getStore().putAll(mapForStore);
Config config = newConfig(testMapStore, 0);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap("default");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
Set expected = map.keySet(Predicates.greaterThan("value", 1));
assertEquals(3, expected.size());
assertContains(expected, "key1");
assertContains(expected, "key2");
assertContains(expected, "key3");
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapStoreWriteBehindTest method testWriteBehindUpdateSameKey.
@Test(timeout = 120000)
public void testWriteBehindUpdateSameKey() throws Exception {
final TestMapStore testMapStore = new TestMapStore(2, 0, 0);
testMapStore.setLoadAllKeys(false);
Config config = newConfig(testMapStore, 5);
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
nodeFactory.newHazelcastInstance(config);
IMap<Object, Object> map = instance.getMap("map");
map.put("key", "value");
Thread.sleep(2000);
map.put("key", "value2");
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals("value2", testMapStore.getStore().get("key"));
}
});
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class MapReduceTest method testMapperReducerChunked.
@Test(timeout = TEST_TIMEOUT)
public void testMapperReducerChunked() throws Exception {
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
assertClusterSizeEventually(3, h1);
assertClusterSizeEventually(3, h2);
assertClusterSizeEventually(3, h3);
try {
IMap<Integer, Integer> m1 = h1.getMap(MAP_NAME);
for (int i = 0; i < 10000; i++) {
m1.put(i, i);
}
JobTracker tracker = h1.getJobTracker("default");
Job<Integer, Integer> job = tracker.newJob(integerKvSource(m1));
JobCompletableFuture<Map<String, Integer>> future = job.chunkSize(10).mapper(new GroupingTestMapper()).reducer(new TestReducerFactory()).submit();
TrackableJob trackableJob = tracker.getTrackableJob(future.getJobId());
final JobProcessInformation processInformation = trackableJob.getJobProcessInformation();
Map<String, Integer> result = future.get();
// pre-calculate results
int[] expectedResults = new int[4];
for (int i = 0; i < 10000; i++) {
int index = i % 4;
expectedResults[index] += i;
}
for (int i = 0; i < 4; i++) {
assertEquals(expectedResults[i], (int) result.get(String.valueOf(i)));
}
assertTrueEventually(new AssertTask() {
@Override
public void run() {
if (processInformation.getProcessedRecords() < 10000) {
System.err.println(processInformation.getProcessedRecords());
}
assertEquals(10000, processInformation.getProcessedRecords());
}
});
} finally {
tripTerminate(h1, h2, h3);
}
}
use of com.hazelcast.test.AssertTask in project hazelcast by hazelcast.
the class PartitionLostListenerTest method test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed.
@Test
public void test_partitionLostListenerInvoked_whenAllPartitionReplicasCrashed() {
HazelcastInstance lite = factory.newHazelcastInstance(new Config().setLiteMember(true));
warmUpPartitions(instances);
warmUpPartitions(lite);
waitAllForSafeState(instances);
waitInstanceForSafeState(lite);
final EventCollectingPartitionLostListener listener = new EventCollectingPartitionLostListener();
lite.getPartitionService().addPartitionLostListener(listener);
instances[0].getLifecycleService().terminate();
instances[1].getLifecycleService().terminate();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
List<PartitionLostEvent> events = listener.getEvents();
assertFalse(events.isEmpty());
}
});
}
Aggregations