[ 
https://issues.apache.org/jira/browse/BEAM-449?focusedWorklogId=571182&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-571182
 ]

ASF GitHub Bot logged work on BEAM-449:
---------------------------------------

                Author: ASF GitHub Bot
            Created on: 24/Mar/21 14:15
            Start Date: 24/Mar/21 14:15
    Worklog Time Spent: 10m 
      Work Description: KhaninArtur commented on a change in pull request 
#14322:
URL: https://github.com/apache/beam/pull/14322#discussion_r600517005



##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/testing/PAssertTest.java
##########
@@ -596,4 +598,59 @@ public void countAssertsMultipleCallsIndependent() {
 
     assertThat(PAssert.countAsserts(pipeline), equalTo(3));
   }
+
+  @Test
+  public void testPAssertThatFlattened() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatFlattened(collectionList).containsInAnyOrder(1, 2, 3, 4, 5, 6);
+    PAssert.thatFlattened("Reason", collectionList).containsInAnyOrder(1, 2, 
3, 4, 5, 6);
+  }
+
+  @Test
+  public void testPAssertThatListSatisfiesOneMatcher() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatList(collectionList)
+        .satisfies(
+            input -> {
+              for (Integer element : input) {
+                assertTrue(element > 0);
+              }
+              return null;
+            });
+  }
+
+  @Test
+  public void testPAssertThatListSatisfiesMultipleMatchers() {
+    PCollection<Integer> firstCollection = pipeline.apply("FirstCreate", 
Create.of(1, 2, 3));
+    PCollection<Integer> secondCollection = pipeline.apply("SecondCreate", 
Create.of(4, 5, 6));
+
+    PCollectionList<Integer> collectionList =
+        PCollectionList.of(firstCollection).and(secondCollection);
+
+    PAssert.thatList(collectionList)
+        .satisfies(
+            ImmutableList.of(
+                input -> {
+                  for (Integer element : input) {
+                    assertTrue(element < 4);
+                  }
+                  return null;
+                },
+                input -> {
+                  for (Integer element : input) {
+                    assertTrue(element < 7);
+                  }
+                  return null;
+                }));
+  }

Review comment:
       Should we also check that PAssert fails correctly? I.e. add negative 
test cases?




-- 
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 571182)
    Time Spent: 0.5h  (was: 20m)

> Support PCollectionList in PAssert
> ----------------------------------
>
>                 Key: BEAM-449
>                 URL: https://issues.apache.org/jira/browse/BEAM-449
>             Project: Beam
>          Issue Type: Improvement
>          Components: sdk-java-core
>            Reporter: Thomas Groh
>            Assignee: Vitaly Terentyev
>            Priority: P3
>              Labels: Clarified
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> The assertion takes an input PCollectionList and takes a list of matchers of 
> the same size, and applies each matcher to the identical index of the 
> PCollectionList
> e.g. PAssert.that(PCollectionList[0]).satisfies(matchers[0])
> Potentially also worthwhile is a "PAssert.thatFlattened(PCollectionList)" 
> static constructor, that runs an assertion on the flattened contents of the 
> list.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to