You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by lc...@apache.org on 2016/04/26 01:16:29 UTC
[3/6] incubator-beam git commit: Add test
Add test
Project: http://git-wip-us.apache.org/repos/asf/incubator-beam/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-beam/commit/62b61197
Tree: http://git-wip-us.apache.org/repos/asf/incubator-beam/tree/62b61197
Diff: http://git-wip-us.apache.org/repos/asf/incubator-beam/diff/62b61197
Branch: refs/heads/master
Commit: 62b6119791a1c248ad2846b331db4b59de169031
Parents: 0236bc1
Author: Mark Shields <ma...@google.com>
Authored: Fri Apr 22 17:45:58 2016 -0700
Committer: Mark Shields <ma...@google.com>
Committed: Mon Apr 25 14:10:50 2016 -0700
----------------------------------------------------------------------
.../runners/dataflow/TestCountingSource.java | 4 +-
.../dataflow/TestCountingSourceTest.java | 55 ++++++++++++++++++++
2 files changed, 57 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/62b61197/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSource.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSource.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSource.java
index 1ea3521..010a19b 100644
--- a/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSource.java
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSource.java
@@ -155,7 +155,7 @@ public class TestCountingSource
return dedup;
}
- private class CountingSourceReader extends UnboundedReader<KV<Integer, Integer>> {
+ public class CountingSourceReader extends UnboundedReader<KV<Integer, Integer>> {
private int current;
public CountingSourceReader(int startingPoint) {
@@ -215,7 +215,7 @@ public class TestCountingSource
}
@Override
- public CheckpointMark getCheckpointMark() {
+ public CounterMark getCheckpointMark() {
if (throwOnFirstSnapshot && !thrown) {
thrown = true;
LOG.error("Throwing exception while checkpointing counter");
http://git-wip-us.apache.org/repos/asf/incubator-beam/blob/62b61197/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSourceTest.java
----------------------------------------------------------------------
diff --git a/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSourceTest.java b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSourceTest.java
new file mode 100644
index 0000000..b122bc0
--- /dev/null
+++ b/sdks/java/core/src/test/java/org/apache/beam/sdk/runners/dataflow/TestCountingSourceTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.beam.sdk.runners.dataflow;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.beam.sdk.options.PipelineOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+import java.io.IOException;
+
+/**
+ * Test the TestCountingSource.
+ */
+@RunWith(JUnit4.class)
+public class TestCountingSourceTest {
+ @Test
+ public void testRespectsCheckpointContract() throws IOException {
+ TestCountingSource source = new TestCountingSource(3);
+ PipelineOptions options = PipelineOptionsFactory.create();
+ TestCountingSource.CountingSourceReader reader = source.createReader(options, null);
+ assertTrue(reader.start());
+ assertEquals(0L, (long) reader.getCurrent().getValue());
+ assertTrue(reader.advance());
+ assertEquals(1L, (long) reader.getCurrent().getValue());
+ TestCountingSource.CounterMark checkpoint = reader.getCheckpointMark();
+ checkpoint.finalizeCheckpoint();
+ reader = source.createReader(options, checkpoint);
+ assertTrue(reader.start());
+ assertEquals(2L, (long) reader.getCurrent().getValue());
+ assertFalse(reader.advance());
+ }
+}