Search in sources :

Example 1 with Hz3MapAdapter

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

the class Hz3Util method createMapAdapter.

static Hz3MapAdapter createMapAdapter(String clientXml) {
    try {
        Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass("com.hazelcast.connector.map.impl.MapAdapterImpl");
        Constructor<?> constructor = clazz.getDeclaredConstructor(String.class);
        return (Hz3MapAdapter) constructor.newInstance(clientXml);
    } catch (InvocationTargetException e) {
        throw new JetException("Could not create instance of MapAdapterImpl", e.getCause());
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | NoSuchMethodException e) {
        throw new HazelcastException(e);
    }
}
Also used : HazelcastException(com.hazelcast.core.HazelcastException) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) JetException(com.hazelcast.jet.JetException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with Hz3MapAdapter

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

the class Hz3EnrichmentTest method testMapUsingReplicatedMap.

@Test
public void testMapUsingReplicatedMap() {
    ReplicatedMap<Object, Object> map = hz3.getReplicatedMap("test-replicated-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, Map<Integer, String>> hz3MapSF = hz3ReplicatedMapServiceFactory("test-replicated-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) HazelcastInstance(com.hazelcast.core.HazelcastInstance) Hz3MapAdapter(com.hazelcast.connector.map.Hz3MapAdapter) Map(java.util.Map) ReplicatedMap(com.hazelcast.replicatedmap.ReplicatedMap) AsyncMap(com.hazelcast.connector.map.AsyncMap) Hz3Enrichment.mapUsingIMap(com.hazelcast.connector.Hz3Enrichment.mapUsingIMap) IMap(com.hazelcast.map.IMap) Test(org.junit.Test)

Example 3 with Hz3MapAdapter

use of com.hazelcast.connector.map.Hz3MapAdapter 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 4 with Hz3MapAdapter

use of com.hazelcast.connector.map.Hz3MapAdapter 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 5 with Hz3MapAdapter

use of com.hazelcast.connector.map.Hz3MapAdapter 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

Hz3MapAdapter (com.hazelcast.connector.map.Hz3MapAdapter)5 AsyncMap (com.hazelcast.connector.map.AsyncMap)4 HazelcastInstance (com.hazelcast.core.HazelcastInstance)4 JobConfig (com.hazelcast.jet.config.JobConfig)4 Pipeline (com.hazelcast.jet.pipeline.Pipeline)4 Test (org.junit.Test)4 Hz3Enrichment.mapUsingIMap (com.hazelcast.connector.Hz3Enrichment.mapUsingIMap)1 HazelcastException (com.hazelcast.core.HazelcastException)1 JetException (com.hazelcast.jet.JetException)1 Job (com.hazelcast.jet.Job)1 IMap (com.hazelcast.map.IMap)1 ReplicatedMap (com.hazelcast.replicatedmap.ReplicatedMap)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1