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 2020/04/22 19:30:11 UTC

[GitHub] [beam] chamikaramj commented on a change in pull request #11450: [BEAM-9779] Hl7v2 io patches

chamikaramj commented on a change in pull request #11450:
URL: https://github.com/apache/beam/pull/11450#discussion_r413255742



##########
File path: sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/HL7v2IOReadWriteIT.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.healthcare;
+
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.HEALTHCARE_DATASET_TEMPLATE;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.MESSAGES;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.deleteAllHL7v2Messages;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.writeHL7v2Messages;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.Collections;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.ListHL7v2MessageIDs;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Count;
+import org.apache.beam.sdk.values.PCollection;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * This should catch that we read {@link HL7v2Message} with schematized data but do not fail inserts
+ * with schematized data which should be output only.
+ */
+@RunWith(JUnit4.class)
+public class HL7v2IOReadWriteIT {
+
+  private transient HealthcareApiClient client;
+  private static String healthcareDataset;
+  private static final String BASE =
+      "hl7v2_store_rw_it_" + System.currentTimeMillis() + "_" + (new SecureRandom().nextInt(32));
+  private static final String INPUT_HL7V2_STORE_NAME = BASE + "INPUT";
+  private static final String OUTPUT_HL7V2_STORE_NAME = BASE + "OUTPUT";
+
+  @Rule public transient TestPipeline pipeline = TestPipeline.create();
+
+  @BeforeClass
+  public static void createHL7v2tores() throws IOException {
+    String project = TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+    healthcareDataset = String.format(HEALTHCARE_DATASET_TEMPLATE, project);
+    HealthcareApiClient client = new HttpHealthcareApiClient();
+    client.createHL7v2Store(healthcareDataset, INPUT_HL7V2_STORE_NAME);
+    client.createHL7v2Store(healthcareDataset, OUTPUT_HL7V2_STORE_NAME);
+  }
+
+  @AfterClass
+  public static void deleteHL7v2tores() throws IOException {
+    HealthcareApiClient client = new HttpHealthcareApiClient();
+    client.deleteHL7v2Store(healthcareDataset + "/hl7V2Stores/" + INPUT_HL7V2_STORE_NAME);
+    client.deleteHL7v2Store(healthcareDataset + "/hl7V2Stores/" + OUTPUT_HL7V2_STORE_NAME);
+  }
+
+  @Before
+  public void setup() throws Exception {
+    if (client == null) {
+      client = new HttpHealthcareApiClient();
+    }
+
+    // Create HL7 messages and write them to HL7v2 Store.
+    writeHL7v2Messages(this.client, healthcareDataset + "/hl7V2Stores/" + INPUT_HL7V2_STORE_NAME);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    deleteAllHL7v2Messages(client, healthcareDataset + "/hl7V2Stores/" + OUTPUT_HL7V2_STORE_NAME);
+  }
+
+  @Test
+  public void testHL7v2IOE2E() throws Exception {
+    HL7v2IO.Read.Result readResult =
+        pipeline
+            .apply(
+                new ListHL7v2MessageIDs(
+                    Collections.singletonList(
+                        healthcareDataset + "/hl7V2Stores/" + INPUT_HL7V2_STORE_NAME)))
+            .apply(HL7v2IO.getAll());
+
+    PCollection<Long> numReadMessages =
+        readResult.getMessages().setCoder(new HL7v2MessageCoder()).apply(Count.globally());
+    PAssert.thatSingleton(numReadMessages).isEqualTo((long) MESSAGES.size());
+    PAssert.that(readResult.getFailedReads()).empty();

Review comment:
       Seems like read and write sections are unrelated. Should these be two different tests ?
   
   Alternatively we can convert this to a single "write and then read pipeline" where data needed for the read step are generated in the write step (and remove data generation in the setUp method.

##########
File path: sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/HL7v2IOTestUtil.java
##########
@@ -91,10 +92,13 @@ static void deleteAllHL7v2Messages(HealthcareApiClient client, String hl7v2Store
   }
 
   /** Populate the test messages into the HL7v2 store. */
-  static void writeHL7v2Messages(HealthcareApiClient client, String hl7v2Store) throws IOException {
+  static void writeHL7v2Messages(HealthcareApiClient client, String hl7v2Store)
+      throws IOException, InterruptedException {
     for (HL7v2Message msg : MESSAGES) {
       client.createHL7v2Message(hl7v2Store, msg.toModel());
     }
+    // [BEAM-9779] HL7v2 indexing is asyncronous. Add sleep to stabilize this IT.
+    Sleeper.DEFAULT.sleep(5000);

Review comment:
       How do we know that 5000 is enough ? If not the test will be flaky.

##########
File path: sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/healthcare/HL7v2IOReadWriteIT.java
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.healthcare;
+
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.HEALTHCARE_DATASET_TEMPLATE;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.MESSAGES;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.deleteAllHL7v2Messages;
+import static org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.writeHL7v2Messages;
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.security.SecureRandom;
+import java.util.Collections;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.healthcare.HL7v2IOTestUtil.ListHL7v2MessageIDs;
+import org.apache.beam.sdk.testing.PAssert;
+import org.apache.beam.sdk.testing.TestPipeline;
+import org.apache.beam.sdk.transforms.Count;
+import org.apache.beam.sdk.values.PCollection;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * This should catch that we read {@link HL7v2Message} with schematized data but do not fail inserts
+ * with schematized data which should be output only.
+ */
+@RunWith(JUnit4.class)
+public class HL7v2IOReadWriteIT {
+
+  private transient HealthcareApiClient client;
+  private static String healthcareDataset;
+  private static final String BASE =
+      "hl7v2_store_rw_it_" + System.currentTimeMillis() + "_" + (new SecureRandom().nextInt(32));
+  private static final String INPUT_HL7V2_STORE_NAME = BASE + "INPUT";
+  private static final String OUTPUT_HL7V2_STORE_NAME = BASE + "OUTPUT";
+
+  @Rule public transient TestPipeline pipeline = TestPipeline.create();
+
+  @BeforeClass
+  public static void createHL7v2tores() throws IOException {
+    String project = TestPipeline.testingPipelineOptions().as(GcpOptions.class).getProject();
+    healthcareDataset = String.format(HEALTHCARE_DATASET_TEMPLATE, project);
+    HealthcareApiClient client = new HttpHealthcareApiClient();
+    client.createHL7v2Store(healthcareDataset, INPUT_HL7V2_STORE_NAME);
+    client.createHL7v2Store(healthcareDataset, OUTPUT_HL7V2_STORE_NAME);
+  }
+
+  @AfterClass
+  public static void deleteHL7v2tores() throws IOException {
+    HealthcareApiClient client = new HttpHealthcareApiClient();
+    client.deleteHL7v2Store(healthcareDataset + "/hl7V2Stores/" + INPUT_HL7V2_STORE_NAME);
+    client.deleteHL7v2Store(healthcareDataset + "/hl7V2Stores/" + OUTPUT_HL7V2_STORE_NAME);
+  }
+
+  @Before
+  public void setup() throws Exception {
+    if (client == null) {
+      client = new HttpHealthcareApiClient();
+    }
+
+    // Create HL7 messages and write them to HL7v2 Store.
+    writeHL7v2Messages(this.client, healthcareDataset + "/hl7V2Stores/" + INPUT_HL7V2_STORE_NAME);
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    deleteAllHL7v2Messages(client, healthcareDataset + "/hl7V2Stores/" + OUTPUT_HL7V2_STORE_NAME);

Review comment:
       Does the store name here uniquely identify the set of data being deleted (just to confirm) ?




----------------------------------------------------------------
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.

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