[
https://issues.apache.org/jira/browse/BEAM-3659?focusedWorklogId=171126&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-171126
]
ASF GitHub Bot logged work on BEAM-3659:
----------------------------------------
Author: ASF GitHub Bot
Created on: 30/Nov/18 17:20
Start Date: 30/Nov/18 17:20
Worklog Time Spent: 10m
Work Description: aromanenko-dev closed pull request #7126: [BEAM-3659]
Port UserScoreTest off DoFnTester
URL: https://github.com/apache/beam/pull/7126
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git
a/examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
b/examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
index a8d81005e8a1..db5b7222298e 100644
---
a/examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
+++
b/examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
@@ -19,6 +19,7 @@
import java.util.HashMap;
import java.util.Map;
+import java.util.Objects;
import org.apache.avro.reflect.Nullable;
import org.apache.beam.examples.complete.game.utils.WriteToText;
import org.apache.beam.sdk.Pipeline;
@@ -100,6 +101,10 @@ public Integer getScore() {
return this.score;
}
+ public Long getTimestamp() {
+ return this.timestamp;
+ }
+
public String getKey(String keyname) {
if ("team".equals(keyname)) {
return this.team;
@@ -108,8 +113,35 @@ public String getKey(String keyname) {
}
}
- public Long getTimestamp() {
- return this.timestamp;
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || o.getClass() != this.getClass()) {
+ return false;
+ }
+
+ GameActionInfo gameActionInfo = (GameActionInfo) o;
+
+ if (!this.getUser().equals(gameActionInfo.getUser())) {
+ return false;
+ }
+
+ if (!this.getTeam().equals(gameActionInfo.getTeam())) {
+ return false;
+ }
+
+ if (!this.getScore().equals(gameActionInfo.getScore())) {
+ return false;
+ }
+
+ return this.getTimestamp().equals(gameActionInfo.getTimestamp());
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(user, team, score, timestamp);
}
}
diff --git
a/examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreTest.java
b/examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreTest.java
index 8288e5bc2ae1..8b518a14b248 100644
---
a/examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreTest.java
+++
b/examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreTest.java
@@ -17,6 +17,7 @@
*/
package org.apache.beam.examples.complete.game;
+import com.google.common.collect.Lists;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
@@ -28,13 +29,11 @@
import org.apache.beam.sdk.testing.TestPipeline;
import org.apache.beam.sdk.testing.ValidatesRunner;
import org.apache.beam.sdk.transforms.Create;
-import org.apache.beam.sdk.transforms.DoFnTester;
import org.apache.beam.sdk.transforms.MapElements;
import org.apache.beam.sdk.transforms.ParDo;
import org.apache.beam.sdk.values.KV;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.TypeDescriptors;
-import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -69,6 +68,19 @@
static final List<String> GAME_EVENTS = Arrays.asList(GAME_EVENTS_ARRAY);
static final List<String> GAME_EVENTS2 = Arrays.asList(GAME_EVENTS_ARRAY2);
+ static final List<GameActionInfo> GAME_ACTION_INFO_LIST =
+ Lists.newArrayList(
+ new GameActionInfo("user0_MagentaKangaroo", "MagentaKangaroo", 3,
1447955630000L),
+ new GameActionInfo("user13_ApricotQuokka", "ApricotQuokka", 15,
1447955630000L),
+ new GameActionInfo("user6_AmberNumbat", "AmberNumbat", 11,
1447955630000L),
+ new GameActionInfo("user7_AlmondWallaby", "AlmondWallaby", 15,
1447955630000L),
+ new GameActionInfo(
+ "user7_AndroidGreenKookaburra", "AndroidGreenKookaburra", 12,
1447955630000L),
+ new GameActionInfo(
+ "user7_AndroidGreenKookaburra", "AndroidGreenKookaburra", 11,
1447955630000L),
+ new GameActionInfo("user19_BisqueBilby", "BisqueBilby", 6,
1447955630000L),
+ new GameActionInfo("user19_BisqueBilby", "BisqueBilby", 8,
1447955630000L));
+
static final List<KV<String, Integer>> USER_SUMS =
Arrays.asList(
KV.of("user0_MagentaKangaroo", 3),
@@ -92,13 +104,12 @@
/** Test the {@link ParseEventFn} {@link
org.apache.beam.sdk.transforms.DoFn}. */
@Test
public void testParseEventFn() throws Exception {
- DoFnTester<String, GameActionInfo> parseEventFn = DoFnTester.of(new
ParseEventFn());
+ PCollection<String> input = p.apply(Create.of(GAME_EVENTS));
+ PCollection<GameActionInfo> output = input.apply(ParDo.of(new
ParseEventFn()));
+
+ PAssert.that(output).containsInAnyOrder(GAME_ACTION_INFO_LIST);
- List<GameActionInfo> results =
parseEventFn.processBundle(GAME_EVENTS_ARRAY);
- Assert.assertEquals(8, results.size());
- Assert.assertEquals("user0_MagentaKangaroo", results.get(0).getUser());
- Assert.assertEquals("MagentaKangaroo", results.get(0).getTeam());
- Assert.assertEquals(Integer.valueOf(3), results.get(0).getScore());
+ p.run().waitUntilFinish();
}
/** Tests ExtractAndSumScore("user"). */
@@ -106,7 +117,7 @@ public void testParseEventFn() throws Exception {
@Category(ValidatesRunner.class)
public void testUserScoreSums() throws Exception {
- PCollection<String> input =
p.apply(Create.of(GAME_EVENTS).withCoder(StringUtf8Coder.of()));
+ PCollection<String> input = p.apply(Create.of(GAME_EVENTS));
PCollection<KV<String, Integer>> output =
input
@@ -125,7 +136,7 @@ public void testUserScoreSums() throws Exception {
@Category(ValidatesRunner.class)
public void testTeamScoreSums() throws Exception {
- PCollection<String> input =
p.apply(Create.of(GAME_EVENTS).withCoder(StringUtf8Coder.of()));
+ PCollection<String> input = p.apply(Create.of(GAME_EVENTS));
PCollection<KV<String, Integer>> output =
input
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 171126)
Time Spent: 3h 40m (was: 3.5h)
> Port UserScoreTest off DoFnTester
> ---------------------------------
>
> Key: BEAM-3659
> URL: https://issues.apache.org/jira/browse/BEAM-3659
> Project: Beam
> Issue Type: Sub-task
> Components: examples-java
> Reporter: Kenneth Knowles
> Assignee: Cade Markegard
> Priority: Major
> Labels: beginner, newbie, starter
> Time Spent: 3h 40m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)