BAEL-4595: Upgrade to hazelcast-jet 4.2 (#10035)

This commit is contained in:
kwoyke 2020-09-15 20:33:11 +02:00 committed by GitHub
parent b64433bb36
commit 4ae6ecbb39
5 changed files with 30 additions and 39 deletions

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>hazelcast</artifactId>
<version>0.0.1-SNAPSHOT</version>
@ -15,7 +15,6 @@
</parent>
<dependencies>
<!-- Hazelcast Jet -->
<dependency>
<groupId>com.hazelcast.jet</groupId>
<artifactId>hazelcast-jet</artifactId>
@ -34,8 +33,7 @@
</build>
<properties>
<!-- hazelcast jet -->
<hazelcast.jet.version>0.6</hazelcast.jet.version>
<hazelcast.jet.version>4.2</hazelcast.jet.version>
</properties>
</project>

View File

@ -1,24 +1,20 @@
package com.baeldung.hazelcast.cluster;
import java.util.Map.Entry;
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.config.GroupConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
import java.util.Map;
public class NativeClient {
public static void main(String[] args) throws InterruptedException {
public static void main(String[] args) {
ClientConfig config = new ClientConfig();
GroupConfig groupConfig = config.getGroupConfig();
groupConfig.setName("dev");
groupConfig.setPassword("dev-pass");
config.setClusterName("dev");
HazelcastInstance hazelcastInstanceClient = HazelcastClient.newHazelcastClient(config);
IMap<Long, String> map = hazelcastInstanceClient.getMap("data");
for (Entry<Long, String> entry : map.entrySet()) {
System.out.println(String.format("Key: %d, Value: %s", entry.getKey(), entry.getValue()));
Map<Long, String> map = hazelcastInstanceClient.getMap("data");
for (Map.Entry<Long, String> entry : map.entrySet()) {
System.out.printf("Key: %d, Value: %s%n", entry.getKey(), entry.getValue());
}
}
}

View File

@ -1,19 +1,19 @@
package com.baeldung.hazelcast.cluster;
import java.util.Map;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IdGenerator;
import com.hazelcast.flakeidgen.FlakeIdGenerator;
import java.util.Map;
public class ServerNode {
public static void main(String[] args) {
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance();
Map<Long, String> map = hazelcastInstance.getMap("data");
IdGenerator idGenerator = hazelcastInstance.getIdGenerator("newid");
FlakeIdGenerator idGenerator = hazelcastInstance.getFlakeIdGenerator("newid");
for (int i = 0; i < 10; i++) {
map.put(idGenerator.newId(), "message" + 1);
map.put(idGenerator.newId(), "message" + i);
}
}
}

View File

@ -1,33 +1,31 @@
package com.baeldung.hazelcast.jet;
import java.util.List;
import java.util.Map;
import static com.hazelcast.jet.Traversers.traverseArray;
import static com.hazelcast.jet.aggregate.AggregateOperations.counting;
import static com.hazelcast.jet.function.DistributedFunctions.wholeItem;
import com.hazelcast.jet.Jet;
import com.hazelcast.jet.JetInstance;
import com.hazelcast.jet.pipeline.Pipeline;
import com.hazelcast.jet.pipeline.Sinks;
import com.hazelcast.jet.pipeline.Sources;
import java.util.List;
import java.util.Map;
import static com.hazelcast.function.Functions.wholeItem;
import static com.hazelcast.jet.Traversers.traverseArray;
import static com.hazelcast.jet.aggregate.AggregateOperations.counting;
public class WordCounter {
private static final String LIST_NAME = "textList";
private static final String MAP_NAME = "countMap";
private Pipeline createPipeLine() {
Pipeline p = Pipeline.create();
p.drawFrom(Sources.<String> list(LIST_NAME))
.flatMap(word -> traverseArray(word.toLowerCase()
.split("\\W+")))
p.readFrom(Sources.<String>list(LIST_NAME))
.flatMap(word -> traverseArray(word.toLowerCase().split("\\W+")))
.filter(word -> !word.isEmpty())
.groupingKey(wholeItem())
.aggregate(counting())
.drainTo(Sinks.map(MAP_NAME));
.writeTo(Sinks.map(MAP_NAME));
return p;
}
@ -38,8 +36,7 @@ public class WordCounter {
List<String> textList = jet.getList(LIST_NAME);
textList.addAll(sentences);
Pipeline p = createPipeLine();
jet.newJob(p)
.join();
jet.newJob(p).join();
Map<String, Long> counts = jet.getMap(MAP_NAME);
count = counts.get(word);
} finally {

View File

@ -1,11 +1,11 @@
package com.baeldung.hazelcast.jet;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class WordCounterUnitTest {
@ -15,7 +15,7 @@ public class WordCounterUnitTest {
sentences.add("The first second was alright, but the second second was tough.");
WordCounter wordCounter = new WordCounter();
long countSecond = wordCounter.countWord(sentences, "second");
assertTrue(countSecond == 3);
assertEquals(3, countSecond);
}
}