kileys commented on a change in pull request #17015:
URL: https://github.com/apache/beam/pull/17015#discussion_r823277899



##########
File path: 
examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
##########
@@ -75,6 +69,9 @@
 })
 public class UserScore {
 
+  // TODO: remove

Review comment:
       Remove

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();
+  private UserScoreOptions options =
+      TestPipeline.testingPipelineOptions().as(UserScoreOptions.class);
+  private static String projectId;
+  // temp-storage-for-end-to-end-tests
+  @Rule public final transient TestPipeline testPipeline = 
TestPipeline.fromOptions(options);
+
+  public interface UserScoreOptions extends TestPipelineOptions, 
UserScore.Options {}
+
+  @Before
+  public void setupTestEnvironment() throws Exception {
+
+    PipelineOptionsFactory.register(TestPipelineOptions.class);
+    projectId = 
TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+
+    setupPipelineOptions();
+  }
+
+  @Test
+  public void testE2EUserScore() throws Exception {
+    UserScore.runUserScore(options, testPipeline);
+
+    testPipeline.run().waitUntilFinish();

Review comment:
       What results do we have to validate?

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */

Review comment:
       ```suggestion
   /** Integration tests for {@link UserScore}. */
   ```

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();
+  private UserScoreOptions options =
+      TestPipeline.testingPipelineOptions().as(UserScoreOptions.class);
+  private static String projectId;
+  // temp-storage-for-end-to-end-tests
+  @Rule public final transient TestPipeline testPipeline = 
TestPipeline.fromOptions(options);
+
+  public interface UserScoreOptions extends TestPipelineOptions, 
UserScore.Options {}
+
+  @Before
+  public void setupTestEnvironment() throws Exception {
+
+    PipelineOptionsFactory.register(TestPipelineOptions.class);
+    projectId = 
TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+
+    setupPipelineOptions();
+  }
+
+  @Test
+  public void testE2EUserScore() throws Exception {
+    UserScore.runUserScore(options, testPipeline);
+
+    testPipeline.run().waitUntilFinish();
+  }
+
+  @After
+  public void cleanupTestEnvironment() throws Exception {}

Review comment:
       Remove if there's no cleanup needed

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();
+  private UserScoreOptions options =
+      TestPipeline.testingPipelineOptions().as(UserScoreOptions.class);
+  private static String projectId;
+  // temp-storage-for-end-to-end-tests
+  @Rule public final transient TestPipeline testPipeline = 
TestPipeline.fromOptions(options);
+
+  public interface UserScoreOptions extends TestPipelineOptions, 
UserScore.Options {}
+
+  @Before
+  public void setupTestEnvironment() throws Exception {
+
+    PipelineOptionsFactory.register(TestPipelineOptions.class);
+    projectId = 
TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+
+    setupPipelineOptions();
+  }
+
+  @Test
+  public void testE2EUserScore() throws Exception {
+    UserScore.runUserScore(options, testPipeline);
+
+    testPipeline.run().waitUntilFinish();
+  }
+
+  @After
+  public void cleanupTestEnvironment() throws Exception {}
+
+  private void setupPipelineOptions() {
+    options.as(GcpOptions.class).setProject(projectId);
+    options.as(DirectOptions.class).setBlockOnRun(false);

Review comment:
       We shouldn't need to add a direct runner specific option. Is there an 
issue with the direct runner?

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/GameStatsIT.java
##########
@@ -0,0 +1,248 @@
+/*
+ * 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.examples.complete.game;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.api.gax.grpc.GrpcTransportChannel;
+import com.google.api.gax.rpc.FixedTransportChannelProvider;
+import com.google.api.gax.rpc.TransportChannelProvider;
+import com.google.api.services.bigquery.model.QueryResponse;
+import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
+import com.google.cloud.pubsub.v1.SubscriptionAdminSettings;
+import com.google.cloud.pubsub.v1.TopicAdminClient;
+import com.google.cloud.pubsub.v1.TopicAdminSettings;
+import com.google.pubsub.v1.PushConfig;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import java.io.IOException;
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.beam.examples.complete.game.utils.GameConstants;
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.TextIO;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions;
+import org.apache.beam.sdk.io.gcp.testing.BigqueryClient;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.apache.beam.sdk.util.FluentBackoff;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link GameStats}. */

Review comment:
       ```suggestion
   /** Integration tests for {@link GameStats}. */
   ```

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";

Review comment:
       Let's use a larger dataset

##########
File path: examples/java/build.gradle
##########
@@ -65,6 +65,13 @@ dependencies {
   implementation library.java.google_api_client
   implementation library.java.google_api_services_bigquery
   implementation library.java.google_api_services_pubsub
+  // GCP PubSub client is used in LeaderBoardIT and StatefulTeamScoreIT
+  implementation library.java.google_cloud_pubsub

Review comment:
       Can we add only to testImplementation?

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();
+  private UserScoreOptions options =
+      TestPipeline.testingPipelineOptions().as(UserScoreOptions.class);
+  private static String projectId;
+  // temp-storage-for-end-to-end-tests
+  @Rule public final transient TestPipeline testPipeline = 
TestPipeline.fromOptions(options);

Review comment:
       UserScore.java should create the pipeline, is there a reason we need 
this? Also, why is it a @Rule and transient?

##########
File path: 
examples/java/src/main/java/org/apache/beam/examples/complete/game/GameStats.java
##########
@@ -242,13 +242,20 @@ public static void main(String[] args) throws Exception {
     ExampleUtils exampleUtils = new ExampleUtils(options);
     Pipeline pipeline = Pipeline.create(options);
 
+    // Run the pipeline and wait for the pipeline to finish; capture 
cancellation requests from the
+    // command line.
+    PipelineResult result = runGameStats(options, pipeline);
+    exampleUtils.waitToFinish(result);
+  }
+
+  static PipelineResult runGameStats(Options options, Pipeline pipeline) {
     // Read Events from Pub/Sub using custom timestamps
     PCollection<GameActionInfo> rawEvents =
         pipeline
             .apply(
                 PubsubIO.readStrings()
-                    .withTimestampAttribute(GameConstants.TIMESTAMP_ATTRIBUTE)
-                    .fromTopic(options.getTopic()))
+                    .fromSubscription(options.getSubscription())

Review comment:
       Is there a reason we need to read from the subscription vs topic?

##########
File path: 
examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
##########
@@ -244,17 +241,22 @@ public static void main(String[] args) throws Exception {
     Options options = 
PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
     Pipeline pipeline = Pipeline.create(options);
 
+    // Run the pipeline and wait for the pipeline to finish; capture 
cancellation requests from the
+    // command line.
+    runUserScore(options, pipeline);
+    pipeline.run().waitUntilFinish();
+  }
+
+  static void runUserScore(Options options, Pipeline pipeline) {
+
     // Read events from a text file and parse them.
+
     pipeline
         .apply(TextIO.read().from(options.getInput()))
         .apply("ParseGameEvent", ParDo.of(new ParseEventFn()))
-        // Extract and sum username/score pairs from the event data.

Review comment:
       Leave comment

##########
File path: 
examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
##########
@@ -28,16 +30,8 @@
 import org.apache.beam.sdk.io.TextIO;
 import org.apache.beam.sdk.metrics.Counter;
 import org.apache.beam.sdk.metrics.Metrics;
-import org.apache.beam.sdk.options.Default;
-import org.apache.beam.sdk.options.Description;
-import org.apache.beam.sdk.options.PipelineOptions;
-import org.apache.beam.sdk.options.PipelineOptionsFactory;
-import org.apache.beam.sdk.options.Validation;
-import org.apache.beam.sdk.transforms.DoFn;
-import org.apache.beam.sdk.transforms.MapElements;
-import org.apache.beam.sdk.transforms.PTransform;
-import org.apache.beam.sdk.transforms.ParDo;
-import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.options.*;

Review comment:
       Leave the imports as the specific packages

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();

Review comment:
       This might override results if it's run in parallel. Can you take a look 
at 
https://github.com/apache/beam/blob/master/examples/java/src/test/java/org/apache/beam/examples/complete/TopWikipediaSessionsIT.java#L58

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/UserScoreIT.java
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.examples.complete.game;
+
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link UserScore}. */
+@RunWith(JUnit4.class)
+public class UserScoreIT {
+  public static final String GAMING_DATA_CSV =
+      "gs://apache-beam-samples/game/small/gaming_data.csv";
+  public static final String TEMP_STORAGE_FOR_UPLOAD_TESTS =
+      "gs://temp-storage-for-end-to-end-tests/UserScoreIT/game/"
+          + UserScoreIT.class.getSimpleName();
+  private UserScoreOptions options =
+      TestPipeline.testingPipelineOptions().as(UserScoreOptions.class);
+  private static String projectId;
+  // temp-storage-for-end-to-end-tests

Review comment:
       ?

##########
File path: 
examples/java/src/test/java/org/apache/beam/examples/complete/game/GameStatsIT.java
##########
@@ -0,0 +1,248 @@
+/*
+ * 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.examples.complete.game;
+
+import static org.junit.Assert.assertEquals;
+
+import com.google.api.gax.grpc.GrpcTransportChannel;
+import com.google.api.gax.rpc.FixedTransportChannelProvider;
+import com.google.api.gax.rpc.TransportChannelProvider;
+import com.google.api.services.bigquery.model.QueryResponse;
+import com.google.cloud.pubsub.v1.SubscriptionAdminClient;
+import com.google.cloud.pubsub.v1.SubscriptionAdminSettings;
+import com.google.cloud.pubsub.v1.TopicAdminClient;
+import com.google.cloud.pubsub.v1.TopicAdminSettings;
+import com.google.pubsub.v1.PushConfig;
+import io.grpc.ManagedChannel;
+import io.grpc.ManagedChannelBuilder;
+import java.io.IOException;
+import java.util.concurrent.ThreadLocalRandom;
+import org.apache.beam.examples.complete.game.utils.GameConstants;
+import org.apache.beam.runners.direct.DirectOptions;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.TextIO;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubOptions;
+import org.apache.beam.sdk.io.gcp.testing.BigqueryClient;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.apache.beam.sdk.util.FluentBackoff;
+import org.checkerframework.checker.nullness.qual.Nullable;
+import org.joda.time.Duration;
+import org.joda.time.Instant;
+import org.joda.time.format.DateTimeFormat;
+import org.joda.time.format.DateTimeFormatter;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/** Tests for {@link GameStats}. */
+@RunWith(JUnit4.class)
+public class GameStatsIT {
+  private static final DateTimeFormatter DATETIME_FORMAT =
+      DateTimeFormat.forPattern("YYYY-MM-dd-HH-mm-ss-SSS");
+  private static final String EVENTS_TOPIC_NAME = "events";
+  public static final String GAME_STATS_TEAM_TABLE = "game_stats_team";
+  private static final Integer DEFAULT_ACK_DEADLINE_SECONDS = 60;
+  public static final String SELECT_COUNT_AS_TOTAL_QUERY =
+      "SELECT total_score FROM `%s.%s.%s` where team like(\"AmaranthKoala\")";
+  private GameStatsOptions options =
+      
TestPipeline.testingPipelineOptions().as(GameStatsIT.GameStatsOptions.class);
+  @Rule public final transient TestPipeline testPipeline = 
TestPipeline.fromOptions(options);
+  private static String pubsubEndpoint;
+  private @Nullable ManagedChannel channel = null;
+  private @Nullable TransportChannelProvider channelProvider = null;
+  private @Nullable TopicAdminClient topicAdmin = null;
+  private @Nullable SubscriptionAdminClient subscriptionAdmin = null;
+  private @Nullable TopicPath eventsTopicPath = null;
+  private @Nullable SubscriptionPath subscriptionPath = null;
+  private String projectId;
+  private static final String TOPIC_PREFIX = "gamestats-";
+  private BigqueryClient bqClient;
+  private final String OUTPUT_DATASET = "game_stats_e2e";
+
+  public interface GameStatsOptions extends TestPipelineOptions, 
GameStats.Options {};
+
+  @Before
+  public void setupTestEnvironment() throws Exception {
+    PipelineOptionsFactory.register(TestPipelineOptions.class);
+    projectId = 
TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+
+    setupBigQuery();

Review comment:
       Can you look into using ExamplesUtils for the setup/breakdown?
   
https://github.com/apache/beam/blob/master/examples/java/src/main/java/org/apache/beam/examples/common/ExampleUtils.java

##########
File path: 
examples/java/src/main/java/org/apache/beam/examples/complete/game/UserScore.java
##########
@@ -244,17 +241,22 @@ public static void main(String[] args) throws Exception {
     Options options = 
PipelineOptionsFactory.fromArgs(args).withValidation().as(Options.class);
     Pipeline pipeline = Pipeline.create(options);
 
+    // Run the pipeline and wait for the pipeline to finish; capture 
cancellation requests from the
+    // command line.
+    runUserScore(options, pipeline);
+    pipeline.run().waitUntilFinish();
+  }
+
+  static void runUserScore(Options options, Pipeline pipeline) {
+
     // Read events from a text file and parse them.
+
     pipeline
         .apply(TextIO.read().from(options.getInput()))
         .apply("ParseGameEvent", ParDo.of(new ParseEventFn()))
-        // Extract and sum username/score pairs from the event data.
         .apply("ExtractUserScore", new ExtractAndSumScore("user"))
         .apply(
             "WriteUserScoreSums", new WriteToText<>(options.getOutput(), 
configureOutput(), false));
-
-    // Run the batch pipeline.
-    pipeline.run().waitUntilFinish();

Review comment:
       It makes more sense to leave this call in the method that says 
"runUserScore"




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to