Search in sources :

Example 31 with IMap

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);
        });
    }
}
Also used : S3Object(software.amazon.awssdk.services.s3.model.S3Object) S3Exception(software.amazon.awssdk.services.s3.model.S3Exception) GetObjectResponse(software.amazon.awssdk.services.s3.model.GetObjectResponse) Collections.singletonList(java.util.Collections.singletonList) Charset(java.nio.charset.Charset) Map(java.util.Map) ResponseInputStream(software.amazon.awssdk.core.ResponseInputStream) Assert.fail(org.junit.Assert.fail) Before(org.junit.Before) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) JetTestSupport(com.hazelcast.jet.core.JetTestSupport) S3Client(software.amazon.awssdk.services.s3.S3Client) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Sinks(com.hazelcast.jet.pipeline.Sinks) NoSuchBucketException(software.amazon.awssdk.services.s3.model.NoSuchBucketException) AggregateOperations(com.hazelcast.jet.aggregate.AggregateOperations) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Predicates.alwaysTrue(com.hazelcast.query.Predicates.alwaysTrue) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) SupplierEx(com.hazelcast.function.SupplierEx) Sources(com.hazelcast.jet.pipeline.Sources) TestSources(com.hazelcast.jet.pipeline.test.TestSources) List(java.util.List) Stream(java.util.stream.Stream) ResponseTransformer.toInputStream(software.amazon.awssdk.core.sync.ResponseTransformer.toInputStream) BufferedReader(java.io.BufferedReader) Assertions(com.hazelcast.jet.pipeline.test.Assertions) Assert.assertEquals(org.junit.Assert.assertEquals) IMap(com.hazelcast.map.IMap) InputStream(java.io.InputStream) S3Client(software.amazon.awssdk.services.s3.S3Client) Pipeline(com.hazelcast.jet.pipeline.Pipeline)

Example 32 with IMap

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());
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 33 with IMap

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());
    });
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Config(com.hazelcast.config.Config) IndexConfig(com.hazelcast.config.IndexConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) MapStoreConfig(com.hazelcast.config.MapStoreConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IMap(com.hazelcast.map.IMap) PortableEmployee(com.hazelcast.query.SampleTestObjects.PortableEmployee) Employee(com.hazelcast.query.SampleTestObjects.Employee) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 34 with IMap

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);
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Employee(com.hazelcast.query.SampleTestObjects.Employee) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 35 with IMap

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapUtil.createHashMap(com.hazelcast.internal.util.MapUtil.createHashMap) Map(java.util.Map) IMap(com.hazelcast.map.IMap) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) SlowTest(com.hazelcast.test.annotation.SlowTest)

Aggregations

IMap (com.hazelcast.map.IMap)294 Test (org.junit.Test)259 QuickTest (com.hazelcast.test.annotation.QuickTest)237 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)228 HazelcastInstance (com.hazelcast.core.HazelcastInstance)139 Config (com.hazelcast.config.Config)103 HazelcastTestSupport.randomString (com.hazelcast.test.HazelcastTestSupport.randomString)82 Map (java.util.Map)75 CountDownLatch (java.util.concurrent.CountDownLatch)65 MapStoreConfig (com.hazelcast.config.MapStoreConfig)54 Category (org.junit.experimental.categories.Category)51 Assert.assertEquals (org.junit.Assert.assertEquals)50 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)48 HashMap (java.util.HashMap)48 Collection (java.util.Collection)41 RunWith (org.junit.runner.RunWith)41 MapConfig (com.hazelcast.config.MapConfig)36 Set (java.util.Set)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)33 AssertTask (com.hazelcast.test.AssertTask)32