Search in sources :

Example 1 with AsyncMap

use of com.hazelcast.connector.map.AsyncMap in project hazelcast by hazelcast.

the class Hz3EnrichmentTest method testMapUsingIMap.

@Test
public void testMapUsingIMap() {
    IMap<Object, Object> map = hz3.getMap("test-map");
    map.put(1, "a");
    map.put(2, "b");
    HazelcastInstance hz = createHazelcastInstance();
    IList<String> results = hz.getList("result-list");
    Pipeline p = Pipeline.create();
    ServiceFactory<Hz3MapAdapter, AsyncMap<Integer, String>> hz3MapSF = hz3MapServiceFactory("test-map", HZ3_CLIENT_CONFIG);
    BiFunctionEx<? super Map<Integer, String>, ? super Integer, String> mapFn = mapUsingIMap(FunctionEx.identity(), (Integer i, String s) -> s);
    BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingService(hz3MapSF, mapFn);
    mapStage.writeTo(Sinks.list(results));
    JobConfig config = getJobConfig(mapStage.name());
    hz.getJet().newJob(p, config).join();
    assertThat(results).containsOnly("a", "b");
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AsyncMap(com.hazelcast.connector.map.AsyncMap) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Test(org.junit.Test)

Example 2 with AsyncMap

use of com.hazelcast.connector.map.AsyncMap in project hazelcast by hazelcast.

the class Hz3EnrichmentTest method testMapUsingIMapAsync.

@Test
public void testMapUsingIMapAsync() {
    IMap<Object, Object> map = hz3.getMap("test-map");
    map.put(1, "a");
    map.put(2, "b");
    HazelcastInstance hz = createHazelcastInstance();
    IList<String> results = hz.getList("result-list");
    Pipeline p = Pipeline.create();
    ServiceFactory<Hz3MapAdapter, AsyncMap<Integer, String>> hz3MapSF = hz3MapServiceFactory("test-map", HZ3_CLIENT_CONFIG);
    BiFunctionEx<? super AsyncMap<Integer, String>, ? super Integer, CompletableFuture<String>> mapFn = mapUsingIMapAsync(FunctionEx.identity(), (Integer i, String s) -> s);
    BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingServiceAsync(hz3MapSF, mapFn);
    mapStage.writeTo(Sinks.list(results));
    JobConfig config = getJobConfig(mapStage.name());
    hz.getJet().newJob(p, config).join();
    assertThat(results).containsOnly("a", "b");
}
Also used : JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AsyncMap(com.hazelcast.connector.map.AsyncMap) CompletableFuture(java.util.concurrent.CompletableFuture) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Test(org.junit.Test)

Example 3 with AsyncMap

use of com.hazelcast.connector.map.AsyncMap in project hazelcast by hazelcast.

the class Hz3EnrichmentTest method when_enrichFromInstanceDown_then_shouldThrowJetException.

@Test
public void when_enrichFromInstanceDown_then_shouldThrowJetException() {
    HazelcastInstance hz = createHazelcastInstance();
    IList<String> results = hz.getList("result-list");
    Pipeline p = Pipeline.create();
    ServiceFactory<Hz3MapAdapter, AsyncMap<Integer, String>> hz3MapSF = hz3MapServiceFactory("test-map", HZ3_DOWN_CLIENT_CONFIG);
    BiFunctionEx<? super Map<Integer, String>, ? super Integer, String> mapFn = mapUsingIMap(FunctionEx.identity(), (Integer i, String s) -> s);
    BatchStage<String> mapStage = p.readFrom(TestSources.items(1, 2, 3)).mapUsingService(hz3MapSF, mapFn);
    mapStage.writeTo(Sinks.list(results));
    JobConfig config = getJobConfig(mapStage.name());
    Job job = hz.getJet().newJob(p, config);
    assertThatThrownBy(() -> job.join()).hasStackTraceContaining(JetException.class.getName()).hasStackTraceContaining("Unable to connect to any cluster");
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Job(com.hazelcast.jet.Job) JobConfig(com.hazelcast.jet.config.JobConfig) Pipeline(com.hazelcast.jet.pipeline.Pipeline) AsyncMap(com.hazelcast.connector.map.AsyncMap) Test(org.junit.Test)

Aggregations

AsyncMap (com.hazelcast.connector.map.AsyncMap)3 Hz3MapAdapter (com.hazelcast.connector.map.Hz3MapAdapter)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 JobConfig (com.hazelcast.jet.config.JobConfig)3 Pipeline (com.hazelcast.jet.pipeline.Pipeline)3 Test (org.junit.Test)3 Job (com.hazelcast.jet.Job)1 CompletableFuture (java.util.concurrent.CompletableFuture)1