You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2022/04/13 20:33:00 UTC

[GitHub] [beam] Abacn commented on a diff in pull request #17305: [BEAM-14267] Update watchForNewFiles to allow watching updated files

Abacn commented on code in PR #17305:
URL: https://github.com/apache/beam/pull/17305#discussion_r849875918


##########
sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/storage/GcsMatchIT.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.io.gcp.storage;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.io.ByteStreams;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.channels.Channels;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.PipelineResult;
+import org.apache.beam.sdk.PipelineResult.State;
+import org.apache.beam.sdk.extensions.gcp.options.GcsOptions;
+import org.apache.beam.sdk.extensions.gcp.util.gcsfs.GcsPath;
+import org.apache.beam.sdk.io.FileIO;
+import org.apache.beam.sdk.io.FileSystems;
+import org.apache.beam.sdk.io.fs.MatchResult.Metadata;
+import org.apache.beam.sdk.io.fs.ResourceId;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.testing.TestPipelineOptions;
+import org.apache.beam.sdk.transforms.Create;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.Watch;
+import org.apache.beam.sdk.util.MimeTypes;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.joda.time.Duration;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class GcsMatchIT {
+  /** Integration test for TextIO.MatchAll watching for file updates in gcs filesystem */
+  @Test
+  public void testGcsMatchContinuously() throws InterruptedException {
+    TestPipelineOptions options =
+        TestPipeline.testingPipelineOptions().as(TestPipelineOptions.class);
+    assertNotNull(options.getTempRoot());
+    options.setTempLocation(options.getTempRoot() + "/testGcsMatchContinuouslyTest");
+    GcsOptions gcsOptions = options.as(GcsOptions.class);
+    String dstFolderName =
+        gcsOptions.getGcpTempLocation()
+            + String.format(
+                "/GcsMatchIT-%tF-%<tH-%<tM-%<tS-%<tL.testGcsMatchContinuously.copy/", new Date());
+    final GcsPath watchPath = GcsPath.fromUri(dstFolderName);
+
+    Pipeline p = Pipeline.create(options);
+
+    PCollection<Metadata> matchAllUpdatedMetadata =
+        p.apply("create for matchAll updated files", Create.of(watchPath.resolve("*").toString()))
+            .apply(
+                "matchAll updated",
+                FileIO.matchAll()
+                    .continuously(
+                        Duration.millis(250),
+                        Watch.Growth.afterTimeSinceNewOutput(Duration.standardSeconds(3)),
+                        true));
+
+    // Copy the files to the "watch" directory;
+    Thread writer =
+        new Thread(
+            () -> {
+              try {
+                Thread.sleep(1000);

Review Comment:
   This test basically duplicates `org.apache.beam.sdk.io.testMatchWatchForNewFiles` and I am aware of that adding sleep makes the test time consuming. Also curious to see if there is a good idea



-- 
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: github-unsubscribe@beam.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org