Skip to content

Commit 3286018

Browse files
tomekl007pivovarit
authored andcommitted
Bael 766 flink (eugenp#1632)
* BAEL-756 code for flink article * reorder * simpler wordCount example * BAEL-766 changes according to PR * BAEL-766 change datasource to dataset * BAEL-766 add sorting example * BAEL-766 add simple streaming example * one missing change to dataSet * windowing example * add window example * add dependency explicitly * add plugin * add surefire plugin, change neme of the test to *IntegrationTest * fluent assertions
1 parent 6cafa3d commit 3286018

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎libraries/pom.xml‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,21 @@
152152
<artifactId>flink-test-utils_2.10</artifactId>
153153
<version>${flink.version}</version>
154154
</dependency>
155+
<dependency>
156+
<groupId>org.apache.flink</groupId>
157+
<artifactId>flink-core</artifactId>
158+
<version>${flink.version}</version>
159+
</dependency>
160+
<dependency>
161+
<groupId>org.apache.flink</groupId>
162+
<artifactId>flink-java</artifactId>
163+
<version>${flink.version}</version>
164+
</dependency>
165+
<dependency>
166+
<groupId>org.apache.flink</groupId>
167+
<artifactId>flink-test-utils_2.10</artifactId>
168+
<version>${flink.version}</version>
169+
</dependency>
155170
</dependencies>
156171

157172
<properties>

‎libraries/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java‎

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.baeldung.flink;
22

3-
import org.apache.flink.api.common.functions.ReduceFunction;
43
import org.apache.flink.api.common.operators.Order;
54
import org.apache.flink.api.java.DataSet;
65
import org.apache.flink.api.java.ExecutionEnvironment;
@@ -35,14 +34,10 @@ public void givenDataSet_whenExecuteWordCount_thenReturnWordCount() throws Excep
3534

3635
//then
3736
List<Tuple2<String, Integer>> collect = result.collect();
38-
assertThat(collect.size()).isEqualTo(9);
39-
assertThat(collect.contains(new Tuple2<>("a", 3))).isTrue();
40-
assertThat(collect.contains(new Tuple2<>("sentence", 2))).isTrue();
41-
assertThat(collect.contains(new Tuple2<>("word", 1))).isTrue();
42-
assertThat(collect.contains(new Tuple2<>("is", 2))).isTrue();
43-
assertThat(collect.contains(new Tuple2<>("this", 2))).isTrue();
44-
assertThat(collect.contains(new Tuple2<>("second", 1))).isTrue();
45-
assertThat(collect.contains(new Tuple2<>("first", 1))).isTrue();
37+
assertThat(collect).containsExactlyInAnyOrder(
38+
new Tuple2<>("a", 3), new Tuple2<>("sentence", 2), new Tuple2<>("word", 1),
39+
new Tuple2<>("is", 2), new Tuple2<>("this", 2), new Tuple2<>("second", 1),
40+
new Tuple2<>("first", 1), new Tuple2<>("with", 1), new Tuple2<>("one", 1));
4641
}
4742

4843
@Test
@@ -54,7 +49,7 @@ public void givenListOfAmounts_whenUseMapReduce_thenSumAmountsThatAreOnlyAboveTh
5449
//when
5550
List<Integer> collect = amounts
5651
.filter(a -> a > threshold)
57-
.reduce((ReduceFunction<Integer>) (integer, t1) -> integer + t1)
52+
.reduce((integer, t1) -> integer + t1)
5853
.collect();
5954

6055
//then
@@ -92,12 +87,7 @@ public void givenDataSet_whenSortItByOneField_thenShouldReturnSortedDataSet() th
9287
.collect();
9388

9489
//then
95-
assertThat(sorted.size()).isEqualTo(4);
96-
assertThat(sorted.get(0)).isEqualTo(firstPerson);
97-
assertThat(sorted.get(1)).isEqualTo(secondPerson);
98-
assertThat(sorted.get(2)).isEqualTo(thirdPerson);
99-
assertThat(sorted.get(3)).isEqualTo(fourthPerson);
100-
90+
assertThat(sorted).containsExactly(firstPerson, secondPerson, thirdPerson, fourthPerson);
10191
}
10292

10393

0 commit comments

Comments
 (0)