use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class S3TestBase method testSink.
void testSink(String bucketName, String prefix, int itemCount, String payload) {
IMap<Integer, String> map = hz.getMap("map");
for (int i = 0; i < itemCount; i++) {
map.put(i, payload);
}
Pipeline p = Pipeline.create();
p.readFrom(Sources.map(map, alwaysTrue(), Map.Entry::getValue)).writeTo(S3Sinks.s3(bucketName, prefix, CHARSET, clientSupplier(), Object::toString));
hz.getJet().newJob(p).join();
try (S3Client client = clientSupplier().get()) {
assertTrueEventually(() -> {
long lineCount = client.listObjectsV2(req -> req.bucket(bucketName).prefix(prefix)).contents().stream().flatMap(o -> s3ObjectToLines(o, client, bucketName)).peek(line -> assertEquals(payload, line)).count();
assertEquals(itemCount, lineCount);
});
}
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryAdvancedTest method testTwoMembersWithIndexesAndShutdown.
@Test
public void testTwoMembersWithIndexesAndShutdown() {
Config config = getConfig();
TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
IMap<String, Employee> map = instance1.getMap("employees");
map.addIndex(IndexType.HASH, "name");
map.addIndex(IndexType.SORTED, "age");
map.addIndex(IndexType.HASH, "active");
QueryBasicTest.doFunctionalQueryTest(map);
assertEquals(101, map.size());
instance2.getLifecycleService().shutdown();
assertEquals(101, map.size());
Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("active and age=23"));
assertEquals(2, entries.size());
for (Map.Entry<String, Employee> entry : entries) {
Employee employee = entry.getValue();
assertEquals(employee.getAge(), 23);
assertTrue(employee.isActive());
}
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryAdvancedTest method testQueryAfterInitialLoad.
// issue 1404 "to be fixed by issue 1404"
@Test
public void testQueryAfterInitialLoad() {
final int size = 100;
String name = "default";
Config config = getConfig();
MapStoreConfig mapStoreConfig = new MapStoreConfig();
mapStoreConfig.setEnabled(true);
mapStoreConfig.setImplementation(new MapStoreAdapter<Integer, Employee>() {
@Override
public Map<Integer, Employee> loadAll(Collection<Integer> keys) {
Map<Integer, Employee> map = new HashMap<>();
for (Integer key : keys) {
Employee emp = new Employee();
emp.setActive(true);
map.put(key, emp);
}
return map;
}
@Override
public Set<Integer> loadAllKeys() {
Set<Integer> set = new HashSet<>();
for (int i = 0; i < size; i++) {
set.add(i);
}
return set;
}
});
config.getMapConfig(name).setMapStoreConfig(mapStoreConfig);
HazelcastInstance instance = createHazelcastInstance(config);
final IMap map = instance.getMap(name);
assertTrueEventually(() -> {
Collection values = map.values(Predicates.sql("active = true"));
assertEquals(size, values.size());
});
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class QueryBasicTest method testWithDashInTheNameAndSqlPredicate.
@Test(timeout = 1000 * 90)
public void testWithDashInTheNameAndSqlPredicate() {
HazelcastInstance instance = createHazelcastInstance(getConfig());
IMap<String, Employee> map = instance.getMap("employee");
Employee toto = new Employee("toto", 23, true, 165765.0);
map.put("1", toto);
Employee toto2 = new Employee("toto-super+hero", 23, true, 165765.0);
map.put("2", toto2);
// works well
Set<Map.Entry<String, Employee>> entries = map.entrySet(Predicates.sql("name='toto-super+hero'"));
assertTrue(entries.size() > 0);
for (Map.Entry<String, Employee> entry : entries) {
Employee e = entry.getValue();
assertEquals(e, toto2);
}
}
use of com.hazelcast.map.IMap in project hazelcast by hazelcast.
the class MemberMapInvalidationMetaDataMigrationTest method sequences_migrated_when_source_node_shutdown.
@Test
public void sequences_migrated_when_source_node_shutdown() {
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
IMap<Object, Object> map = instance1.getMap(MAP_NAME);
for (int i = 0; i < MAP_SIZE; i++) {
map.put(i, i);
}
assertInvalidationCountEventually(MAP_NAME, MAP_SIZE, instance1);
Map<Integer, Long> source = getPartitionToSequenceMap(MAP_NAME, instance1);
HazelcastInstance instance2 = factory.newHazelcastInstance(config);
HazelcastInstance instance3 = factory.newHazelcastInstance(config);
instance1.shutdown();
waitAllForSafeState(factory.getAllHazelcastInstances());
Map<Integer, Long> destination2 = getPartitionToSequenceMap(MAP_NAME, instance2);
Map<Integer, Long> destination3 = getPartitionToSequenceMap(MAP_NAME, instance3);
for (Map.Entry<Integer, Long> entry : destination2.entrySet()) {
Integer key = entry.getKey();
Long value = entry.getValue();
if (value != 0) {
destination3.put(key, value);
}
}
assertSequenceNumbersEqual(source, destination3);
}
Aggregations