lukecwik commented on a change in pull request #15137:
URL: https://github.com/apache/beam/pull/15137#discussion_r670728664



##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/transforms/windowing/IntervalWindow.java
##########
@@ -174,6 +175,19 @@ public boolean consistentWithEquals() {
       return instantCoder.consistentWithEquals() && 
durationCoder.consistentWithEquals();
     }
 
+    @Override
+    public boolean isRegisterByteSizeObserverCheap(IntervalWindow value) {

Review comment:
       Great!

##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/coders/TimestampPrefixingWindowCoderTest.java
##########
@@ -107,15 +140,32 @@ public void testEncodeAndDecode() throws Exception {
         TimestampPrefixingWindowCoder.of(GlobalWindow.Coder.INSTANCE);
     CoderProperties.coderDecodeEncodeEqual(coder2, globalWindow);
 
-    List<CustomWindow> customWindowsToTest =
-        Lists.newArrayList(
-            new CustomWindow(new Instant(0L), new Instant(1L), true),
-            new CustomWindow(new Instant(100L), new Instant(200L), false),
-            new CustomWindow(new Instant(0L), 
BoundedWindow.TIMESTAMP_MAX_VALUE, true));
-    TimestampPrefixingWindowCoder<CustomWindow> coder3 =
-        TimestampPrefixingWindowCoder.of(CustomWindowCoder.of());
-    for (CustomWindow window : customWindowsToTest) {
-      CoderProperties.coderDecodeEncodeEqual(coder3, window);
+    for (CustomWindow window : CUSTOM_WINDOW_LIST) {
+      CoderProperties.coderDecodeEncodeEqual(TEST_CODER, window);
+    }
+  }
+
+  @Test
+  public void testConsistentWithEquals() {
+    assertThat(TEST_CODER.consistentWithEquals(), equalTo(true));
+  }
+
+  @Test
+  public void testIsRegisterByteSizeObserverCheap() {
+    assertThat(

Review comment:
       You'll also want to add a variant showing that if the window coder 
returns false then this is false.

##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/coders/TimestampPrefixingWindowCoderTest.java
##########
@@ -107,15 +140,32 @@ public void testEncodeAndDecode() throws Exception {
         TimestampPrefixingWindowCoder.of(GlobalWindow.Coder.INSTANCE);
     CoderProperties.coderDecodeEncodeEqual(coder2, globalWindow);
 
-    List<CustomWindow> customWindowsToTest =
-        Lists.newArrayList(
-            new CustomWindow(new Instant(0L), new Instant(1L), true),
-            new CustomWindow(new Instant(100L), new Instant(200L), false),
-            new CustomWindow(new Instant(0L), 
BoundedWindow.TIMESTAMP_MAX_VALUE, true));
-    TimestampPrefixingWindowCoder<CustomWindow> coder3 =
-        TimestampPrefixingWindowCoder.of(CustomWindowCoder.of());
-    for (CustomWindow window : customWindowsToTest) {
-      CoderProperties.coderDecodeEncodeEqual(coder3, window);
+    for (CustomWindow window : CUSTOM_WINDOW_LIST) {
+      CoderProperties.coderDecodeEncodeEqual(TEST_CODER, window);
+    }
+  }
+
+  @Test
+  public void testConsistentWithEquals() {
+    assertThat(TEST_CODER.consistentWithEquals(), equalTo(true));
+  }
+
+  @Test
+  public void testIsRegisterByteSizeObserverCheap() {
+    assertThat(
+        TEST_CODER.isRegisterByteSizeObserverCheap(CUSTOM_WINDOW_LIST.get(0)), 
equalTo(true));
+  }
+
+  @Test
+  public void testGetEncodedElementByteSize() throws Exception {
+    TestElementByteSizeObserver observer = new TestElementByteSizeObserver();
+    for (CustomWindow value : CUSTOM_WINDOW_LIST) {
+      TEST_CODER.registerByteSizeObserver(value, observer);
+      observer.advance();
+      assertThat(
+          observer.getSumAndReset(),

Review comment:
       To verify that the CustomWindowCoder is being used, you should have it 
"lie" about the size so you know that it isn't the true encoded size which is 
the default implementation of registerByteSizeObserver.

##########
File path: 
sdks/java/core/src/test/java/org/apache/beam/sdk/coders/TimestampPrefixingWindowCoderTest.java
##########
@@ -107,15 +140,32 @@ public void testEncodeAndDecode() throws Exception {
         TimestampPrefixingWindowCoder.of(GlobalWindow.Coder.INSTANCE);
     CoderProperties.coderDecodeEncodeEqual(coder2, globalWindow);
 
-    List<CustomWindow> customWindowsToTest =
-        Lists.newArrayList(
-            new CustomWindow(new Instant(0L), new Instant(1L), true),
-            new CustomWindow(new Instant(100L), new Instant(200L), false),
-            new CustomWindow(new Instant(0L), 
BoundedWindow.TIMESTAMP_MAX_VALUE, true));
-    TimestampPrefixingWindowCoder<CustomWindow> coder3 =
-        TimestampPrefixingWindowCoder.of(CustomWindowCoder.of());
-    for (CustomWindow window : customWindowsToTest) {
-      CoderProperties.coderDecodeEncodeEqual(coder3, window);
+    for (CustomWindow window : CUSTOM_WINDOW_LIST) {
+      CoderProperties.coderDecodeEncodeEqual(TEST_CODER, window);
+    }
+  }
+
+  @Test
+  public void testConsistentWithEquals() {
+    assertThat(TEST_CODER.consistentWithEquals(), equalTo(true));

Review comment:
       You'll also want to add a variant showing that if the window coder 
returns false then this is false.

##########
File path: 
sdks/java/core/src/main/java/org/apache/beam/sdk/coders/TimestampPrefixingWindowCoder.java
##########
@@ -67,4 +74,20 @@ public T decode(InputStream inStream) throws CoderException, 
IOException {
   public void verifyDeterministic() throws NonDeterministicException {
     windowCoder.verifyDeterministic();
   }
+
+  @Override
+  public boolean consistentWithEquals() {
+    return windowCoder.consistentWithEquals();
+  }
+
+  @Override
+  public boolean isRegisterByteSizeObserverCheap(T value) {
+    return windowCoder.isRegisterByteSizeObserverCheap(value);
+  }
+
+  @Override
+  public void registerByteSizeObserver(T value, ElementByteSizeObserver 
observer) throws Exception {
+    InstantCoder.of().registerByteSizeObserver(new Instant(), observer);

Review comment:
       Did you mean to pass in the max timestamp of value instead of `new 
Instant()`?




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