Skip to content
This repository was archived by the owner on Mar 11, 2024. It is now read-only.

Commit 263c421

Browse files
author
Alexander Kolb
committed
additional tests
1 parent dade2fa commit 263c421

File tree

7 files changed

+32
-27
lines changed

7 files changed

+32
-27
lines changed

flinkspector-core/src/main/java/org/flinkspector/core/quantify/MatchTuples.java renamed to flinkspector-core/src/main/java/org/flinkspector/core/quantify/MatchFields.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
* <p/>
3434
* <pre>
3535
* {@code
36-
* new MatchTuples<Tuple2<String,Integer>>("name","age")
36+
* new MatchFields<Tuple2<String,Integer>>("name","age")
3737
* .assertThat("age", greaterThan(21))
3838
* .assertThat("name", either(is("fritz")).or(is("peter")))
3939
* .anyOfThem().onEachRecord();
4040
* </pre>
4141
*
4242
* @param <T>
4343
*/
44-
public class MatchTuples<T extends Tuple> extends MatchRecords<T> {
44+
public class MatchFields<T extends Tuple> extends MatchRecords<T> {
4545

4646
/**
4747
* {@link TupleMask} used to map the keys to the inspected tuples.
@@ -53,18 +53,18 @@ public class MatchTuples<T extends Tuple> extends MatchRecords<T> {
5353
*
5454
* @param mask {@link TupleMask} to use.
5555
* @param <T> type of output
56-
* @return new instance of {@link MatchTuples}
56+
* @return new instance of {@link MatchFields}
5757
*/
58-
public static <T extends Tuple> MatchTuples<T> fromMask(TupleMask<T> mask) {
59-
return new MatchTuples<T>(mask);
58+
public static <T extends Tuple> MatchFields<T> fromMask(TupleMask<T> mask) {
59+
return new MatchFields<T>(mask);
6060
}
6161

6262
/**
6363
* Default Constructor.
6464
*
6565
* @param mask {@link TupleMask} to use.
6666
*/
67-
public MatchTuples(TupleMask<T> mask) {
67+
public MatchFields(TupleMask<T> mask) {
6868
super();
6969
this.mask = mask;
7070
}
@@ -76,7 +76,7 @@ public MatchTuples(TupleMask<T> mask) {
7676
* @param first key
7777
* @param rest of keys
7878
*/
79-
public MatchTuples(String first, String... rest) {
79+
public MatchFields(String first, String... rest) {
8080
this(new TupleMask<T>(first,rest));
8181
}
8282

@@ -86,7 +86,7 @@ public MatchTuples(String first, String... rest) {
8686
* @param key of the field
8787
* @param match matcher to use on the field
8888
*/
89-
public MatchTuples<T> assertThat(String key, Matcher match) {
89+
public MatchFields<T> assertThat(String key, Matcher match) {
9090
assertThat(new TupleMatcher<T>(KeyMatcherPair.of(key, match),mask));
9191
return this;
9292
}
@@ -95,7 +95,7 @@ public MatchTuples<T> assertThat(String key, Matcher match) {
9595
* Add a {@link Matcher} to the list of assertions to verify.
9696
* @param matcher testing the output records
9797
*/
98-
public MatchTuples<T> assertThatRecord(Matcher<? super T> matcher) {
98+
public MatchFields<T> assertThatRecord(Matcher<? super T> matcher) {
9999
super.assertThat(matcher);
100100
return this;
101101
}

flinkspector-core/src/test/scala/org/flinkspector/core/quantify/MatchTuplesSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import org.hamcrest.core.Is
2323
import scala.collection.JavaConversions._
2424

2525
class MatchTuplesSpec extends CoreSpec {
26-
"The MatchTuples" should "store a list of [[KeyMatcherPair]]s" in {
26+
"The MatchFields" should "store a list of [[KeyMatcherPair]]s" in {
2727
val matcher = Is.is(1)
28-
val block = new MatchTuples[Fluple3[Int, Int, Int]]("1", "2", "3")
28+
val block = new MatchFields[Fluple3[Int, Int, Int]]("1", "2", "3")
2929
block.assertThat("1", matcher)
3030
block.assertThat("2", matcher)
3131
block.assertThat("2", matcher)
@@ -88,7 +88,7 @@ class MatchTuplesSpec extends CoreSpec {
8888
trait AssertBlockCase {
8989
val matcher = Is.is(1)
9090
val block =
91-
new MatchTuples[Fluple4[Int, Int, Int, Int]]("1", "2", "3", "4")
91+
new MatchFields[Fluple4[Int, Int, Int, Int]]("1", "2", "3", "4")
9292
block.assertThat("1", matcher)
9393
block.assertThat("2", matcher)
9494
block.assertThat("3", matcher)

flinkspector-dataset/src/test/java/org/flinkspector/dataset/examples/BatchTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.apache.flink.api.java.DataSet;
2121
import org.apache.flink.api.java.tuple.Tuple2;
2222
import org.flinkspector.core.collection.ExpectedRecords;
23-
import org.flinkspector.core.quantify.MatchTuples;
23+
import org.flinkspector.core.quantify.MatchFields;
2424
import org.flinkspector.core.quantify.OutputMatcher;
2525
import org.flinkspector.core.trigger.FinishAtCount;
2626
import org.flinkspector.dataset.DataSetTestBase;
@@ -77,7 +77,7 @@ public void testMap() throws Throwable {
7777
*/
7878
OutputMatcher<Tuple2<String, Integer>> matcher =
7979
//name the values in your tuple with keys:
80-
new MatchTuples<Tuple2<String, Integer>>("name", "value")
80+
new MatchFields<Tuple2<String, Integer>>("name", "value")
8181
//add an assertion using a value and hamcrest matchers
8282
.assertThat("name", isA(String.class))
8383
.assertThat("value", lessThan(5))

flinkspector-datastream-scala_2.11/src/main/scala/org/flinkspector/scala/datastream/DataStreamTestEnvironment.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ import _root_.scala.language.implicitConversions
3232
import scala.collection.JavaConverters._
3333
import scala.reflect.ClassTag
3434

35-
class DataStreamTestEnvironment(testEnv: org.flinkspector.datastream.DataStreamTestEnvironment) extends StreamExecutionEnvironment(testEnv) {
35+
class DataStreamTestEnvironment(testEnv: org.flinkspector.datastream.DataStreamTestEnvironment)
36+
extends StreamExecutionEnvironment(testEnv) {
3637

3738

3839
@throws(classOf[Throwable])

flinkspector-datastream-scala_2.11/src/main/scala/org/flinkspector/scala/datastream/FlinkDataStream.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ trait FlinkDataStream extends BeforeAndAfterEach { this: Suite =>
4343
*/
4444
private var testEnv: DataStreamTestEnvironment = _
4545

46-
private var executed = false
47-
4846
override def beforeEach() {
4947
testEnv = DataStreamTestEnvironment.createTestEnvironment(1)
5048
testEnv.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)
@@ -55,16 +53,12 @@ trait FlinkDataStream extends BeforeAndAfterEach { this: Suite =>
5553
try super.afterEach() // To be stackable, must call super.afterEach
5654
finally {
5755
testEnv.close()
58-
executed = false
5956
}
6057
}
6158

6259

6360
def executeTest(): Unit = {
64-
if(!executed) {
65-
executed = true
6661
testEnv.executeTest()
67-
}
6862
}
6963

7064
/**
@@ -172,7 +166,6 @@ trait FlinkDataStream extends BeforeAndAfterEach { this: Suite =>
172166
case None =>
173167
stream.addSink(createTestSink(matcher))
174168
}
175-
executeTest()
176169
}
177170
}
178171

flinkspector-datastream-scala_2.11/src/test/scala/org/flinkspector/scala/datastream/DataStreamSpec.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package org.flinkspector.scala.datastream
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18+
1819
import org.apache.flink.api.scala._
1920
import org.flinkspector.core.collection.ExpectedRecords
2021
import org.flinkspector.core.input.InputBuilder
@@ -38,6 +39,9 @@ class DataStreamSpec extends CoreSpec with FlinkDataStream{
3839

3940
//use the matcher on the datastream
4041
stream should fulfill(expected)
42+
executeTest()
43+
44+
"arstarie".trim().toLowerCase()
4145
}
4246

4347

@@ -58,6 +62,7 @@ class DataStreamSpec extends CoreSpec with FlinkDataStream{
5862
field(v.value should be > 4)
5963
}
6064
}
65+
executeTest()
6166
}
6267
}
6368

flinkspector-datastream/src/test/java/org/flinkspector/datastream/examples/WindowingTest.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
import org.apache.flink.api.java.tuple.Tuple2;
1919
import org.apache.flink.streaming.api.datastream.DataStream;
2020
import org.apache.flink.streaming.api.windowing.time.Time;
21-
import org.flinkspector.core.quantify.MatchTuples;
21+
import org.flinkspector.core.quantify.MatchFields;
22+
import org.flinkspector.core.quantify.MatchRecords;
2223
import org.flinkspector.core.quantify.OutputMatcher;
2324
import org.flinkspector.datastream.StreamTestBase;
2425

@@ -31,7 +32,7 @@
3132

3233
/**
3334
* This example shows how to startWith test input with time characteristics.
34-
* And the usage of {@link MatchTuples} to build an {@link OutputMatcher}.
35+
* And the usage of {@link MatchFields} to build an {@link OutputMatcher}.
3536
* <p/>
3637
* To ensure test cases run in a few seconds the framework sets the time characteristic of the data flow, to
3738
* EventTime. The test source emitting the input, calculates and emits watermarks based on the timestamped input.
@@ -79,14 +80,14 @@ public void testWindowing() {
7980
.close();
8081

8182
/*
82-
* Creates an OutputMatcher using MatchTuples.
83-
* MatchTuples builds an OutputMatcher working on Tuples.
83+
* Creates an OutputMatcher using MatchFields.
84+
* MatchFields builds an OutputMatcher working on Tuples.
8485
* You assign String identifiers to your Tuple,
8586
* and add hamcrest matchers testing the values.
8687
*/
8788
OutputMatcher<Tuple2<Integer, String>> matcher =
8889
//name the values in your tuple with keys:
89-
new MatchTuples<Tuple2<Integer, String>>("value", "name")
90+
new MatchFields<Tuple2<Integer, String>>("value", "name")
9091
//add an assertion using a value and hamcrest matchers
9192
.assertThat("value", is(3))
9293
.assertThat("name", either(is("fritz")).or(is("peter")))
@@ -95,6 +96,11 @@ public void testWindowing() {
9596
//define how many records need to fulfill the
9697
.onEachRecord();
9798

99+
OutputMatcher<Tuple2<Integer,String>> records =
100+
new MatchRecords<Tuple2<Integer,String>>()
101+
.assertThat(is(Tuple2.of(3, "fritz")))
102+
.onAnyRecord();
103+
98104
/*
99105
* Use assertStream to map DataStream to an OutputMatcher.
100106
* You're also able to combine OutputMatchers with any

0 commit comments

Comments
 (0)