use of com.google.cloud.dataflow.examples.complete.game.UserScore.ParseEventFn in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class UserScoreTest method testTeamScoreSums.
/** Tests ExtractAndSumScore("team"). */
@Test
@Category(ValidatesRunner.class)
public void testTeamScoreSums() throws Exception {
PCollection<String> input = p.apply(Create.of(GAME_EVENTS).withCoder(StringUtf8Coder.of()));
PCollection<KV<String, Integer>> output = input.apply(ParDo.of(new ParseEventFn())).apply("ExtractTeamScore", new ExtractAndSumScore("team"));
// Check the team score sums.
PAssert.that(output).containsInAnyOrder(TEAM_SUMS);
p.run().waitUntilFinish();
}
use of com.google.cloud.dataflow.examples.complete.game.UserScore.ParseEventFn in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class UserScoreTest method testParseEventFn.
/** 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());
List<GameActionInfo> results = parseEventFn.processBundle(GAME_EVENTS_ARRAY);
Assert.assertEquals(results.size(), 8);
Assert.assertEquals(results.get(0).getUser(), "user0_MagentaKangaroo");
Assert.assertEquals(results.get(0).getTeam(), "MagentaKangaroo");
Assert.assertEquals(results.get(0).getScore(), new Integer(3));
}
use of com.google.cloud.dataflow.examples.complete.game.UserScore.ParseEventFn in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class HourlyTeamScoreTest method testUserScoresFilter.
/** Test the filtering. */
@Test
@Category(ValidatesRunner.class)
public void testUserScoresFilter() throws Exception {
final Instant startMinTimestamp = new Instant(1447965680000L);
PCollection<String> input = p.apply(Create.of(GAME_EVENTS).withCoder(StringUtf8Coder.of()));
PCollection<KV<String, Integer>> output = input.apply("ParseGameEvent", ParDo.of(new ParseEventFn())).apply("FilterStartTime", Filter.by((GameActionInfo gInfo) -> gInfo.getTimestamp() > startMinTimestamp.getMillis())).apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.integers())).via((GameActionInfo gInfo) -> KV.of(gInfo.getUser(), gInfo.getScore())));
PAssert.that(output).containsInAnyOrder(FILTERED_EVENTS);
p.run().waitUntilFinish();
}
use of com.google.cloud.dataflow.examples.complete.game.UserScore.ParseEventFn in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class UserScoreTest method testUserScoreSums.
/** Tests ExtractAndSumScore("user"). */
@Test
@Category(ValidatesRunner.class)
public void testUserScoreSums() throws Exception {
PCollection<String> input = p.apply(Create.of(GAME_EVENTS).withCoder(StringUtf8Coder.of()));
PCollection<KV<String, Integer>> output = input.apply(ParDo.of(new ParseEventFn())).apply("ExtractUserScore", new ExtractAndSumScore("user"));
// Check the user score sums.
PAssert.that(output).containsInAnyOrder(USER_SUMS);
p.run().waitUntilFinish();
}
use of com.google.cloud.dataflow.examples.complete.game.UserScore.ParseEventFn in project DataflowJavaSDK-examples by GoogleCloudPlatform.
the class UserScoreTest method testUserScoresBadInput.
/** Test that bad input data is dropped appropriately. */
@Test
@Category(ValidatesRunner.class)
public void testUserScoresBadInput() throws Exception {
PCollection<String> input = p.apply(Create.of(GAME_EVENTS2).withCoder(StringUtf8Coder.of()));
PCollection<KV<String, Integer>> extract = input.apply(ParDo.of(new ParseEventFn())).apply(MapElements.into(TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.integers())).via((GameActionInfo gInfo) -> KV.of(gInfo.getUser(), gInfo.getScore())));
PAssert.that(extract).empty();
p.run().waitUntilFinish();
}
Aggregations