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);
}
}
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");
}
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");
}
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");
}
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");
}
Aggregations