lukecwik commented on a change in pull request #11199: [BEAM-9562] Update Timer 
encoding with respect of dynamic timers
URL: https://github.com/apache/beam/pull/11199#discussion_r402433871
 
 

 ##########
 File path: 
runners/core-construction-java/src/test/java/org/apache/beam/runners/core/construction/TimerTest.java
 ##########
 @@ -36,39 +38,121 @@
   private static final Instant INSTANT = Instant.now();
 
   @Test
-  public void testTimer() {
-    Timer<Void> timerA = Timer.of(INSTANT);
-    assertEquals(INSTANT, timerA.getTimestamp());
-    assertNull(timerA.getPayload());
+  public void testClearTimer() {
+    Timer<String> clearedTimer = Timer.cleared("timer", "tag");
+    assertTrue(clearedTimer.getClearBit());
+    assertEquals("timer", clearedTimer.getUserKey());
+    assertEquals("tag", clearedTimer.getDynamicTimerTag());
+  }
 
-    Timer<String> timerB = Timer.of(INSTANT, "ABC");
-    assertEquals(INSTANT, timerB.getTimestamp());
-    assertEquals("ABC", timerB.getPayload());
+  @Test
+  public void testTimer() {
+    Timer<String> timer =
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singleton(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING);
+    assertEquals("key", timer.getUserKey());
+    assertEquals("tag", timer.getDynamicTimerTag());
+    assertEquals(INSTANT, timer.getFireTimestamp());
+    assertEquals(INSTANT, timer.getHoldTimestamp());
+    assertEquals(Collections.singleton(GlobalWindow.INSTANCE), 
timer.getWindows());
+    assertEquals(PaneInfo.NO_FIRING, timer.getPane());
+    assertFalse(timer.getClearBit());
   }
 
   @Test
-  public void testTimerCoderWithInconsistentWithEqualsPayloadCoder() throws 
Exception {
-    Coder<Timer<byte[]>> coder = Timer.Coder.of(ByteArrayCoder.of());
+  public void testTimerCoderWithInconsistentWithEqualsComponentCoders() throws 
Exception {
+    Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of(), 
GlobalWindow.Coder.INSTANCE);
     CoderProperties.coderSerializable(coder);
     CoderProperties.structuralValueDecodeEncodeEqual(
-        coder, Timer.of(INSTANT, "ABC".getBytes(UTF_8)));
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singleton(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING));
     CoderProperties.structuralValueConsistentWithEquals(
-        coder, Timer.of(INSTANT, "ABC".getBytes(UTF_8)), Timer.of(INSTANT, 
"ABC".getBytes(UTF_8)));
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singleton(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING),
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singleton(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING));
   }
 
   @Test
-  public void testTimerCoderWithConsistentWithEqualsPayloadCoder() throws 
Exception {
-    Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of());
-    CoderProperties.coderDecodeEncodeEqual(coder, Timer.of(INSTANT, "ABC"));
+  public void testTimerCoderWithConsistentWithEqualsComponentCoders() throws 
Exception {
+    Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of(), 
GlobalWindow.Coder.INSTANCE);
+    CoderProperties.coderDecodeEncodeEqual(
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singletonList(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING));
     CoderProperties.coderConsistentWithEquals(
-        coder, Timer.of(INSTANT, "ABC"), Timer.of(INSTANT, "ABC"));
-    CoderProperties.coderDeterministic(coder, Timer.of(INSTANT, "ABC"), 
Timer.of(INSTANT, "ABC"));
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singletonList(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING),
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singletonList(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING));
+    CoderProperties.coderDeterministic(
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singletonList(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING),
+        Timer.of(
+            "key",
+            "tag",
+            INSTANT,
+            INSTANT,
+            Collections.singletonList(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING));
   }
 
   @Test
   public void testTimerCoderWireFormat() throws Exception {
-    Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of());
+    Coder<Timer<String>> coder = Timer.Coder.of(StringUtf8Coder.of(), 
GlobalWindow.Coder.INSTANCE);
     CoderProperties.coderEncodesBase64(
-        coder, Timer.of(new Instant(255L), "ABC"), "gAAAAAAAAP8DQUJD");
+        coder,
+        Timer.of(
+            "key",
+            "tag",
+            new Instant(225L),
+            new Instant(225L),
+            Collections.singleton(GlobalWindow.INSTANCE),
+            PaneInfo.NO_FIRING),
+        "A2tleQN0YWcAgAAAAAAAAOGAAAAAAAAA4QAAAAEP");
   }
 
 Review comment:
   We can get rid of this test since standard_coders.yaml covers it.

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


With regards,
Apache Git Services

Reply via email to