kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From guozh...@apache.org
Subject kafka git commit: MINOR: add equals to SessionWindows
Date Tue, 17 Oct 2017 01:01:35 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk f931febc8 -> 6c416acee


MINOR: add equals to SessionWindows

Author: Damian Guy <damian.guy@gmail.com>

Reviewers: Guozhang Wang <wangguoz@gmail.com>, Matthias J. Sax<matthias@confluent.io>,
Bill Bejeck <bill@confluent.io>

Closes #4074 from dguy/minor-session-window-equals


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/6c416ace
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/6c416ace
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/6c416ace

Branch: refs/heads/trunk
Commit: 6c416aceeb172dc6b0103855f3c1ecbfc9f4d411
Parents: f931feb
Author: Damian Guy <damian.guy@gmail.com>
Authored: Mon Oct 16 18:01:32 2017 -0700
Committer: Guozhang Wang <wangguoz@gmail.com>
Committed: Mon Oct 16 18:01:32 2017 -0700

----------------------------------------------------------------------
 .../kafka/streams/kstream/SessionWindows.java      | 16 ++++++++++++++++
 .../kafka/streams/kstream/SessionWindowsTest.java  | 17 +++++++++++++++++
 2 files changed, 33 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/6c416ace/streams/src/main/java/org/apache/kafka/streams/kstream/SessionWindows.java
----------------------------------------------------------------------
diff --git a/streams/src/main/java/org/apache/kafka/streams/kstream/SessionWindows.java b/streams/src/main/java/org/apache/kafka/streams/kstream/SessionWindows.java
index 693bee0..aa3dec1 100644
--- a/streams/src/main/java/org/apache/kafka/streams/kstream/SessionWindows.java
+++ b/streams/src/main/java/org/apache/kafka/streams/kstream/SessionWindows.java
@@ -18,6 +18,8 @@ package org.apache.kafka.streams.kstream;
 
 import org.apache.kafka.streams.processor.TimestampExtractor;
 
+import java.util.Objects;
+
 /**
  * A session based window specification used for aggregating events into sessions.
  * <p>
@@ -121,4 +123,18 @@ public final class SessionWindows {
     public long maintainMs() {
         return Math.max(maintainDurationMs, gapMs);
     }
+
+    @Override
+    public boolean equals(final Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+        final SessionWindows that = (SessionWindows) o;
+        return gapMs == that.gapMs &&
+                maintainDurationMs == that.maintainDurationMs;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hash(gapMs, maintainDurationMs);
+    }
 }

http://git-wip-us.apache.org/repos/asf/kafka/blob/6c416ace/streams/src/test/java/org/apache/kafka/streams/kstream/SessionWindowsTest.java
----------------------------------------------------------------------
diff --git a/streams/src/test/java/org/apache/kafka/streams/kstream/SessionWindowsTest.java
b/streams/src/test/java/org/apache/kafka/streams/kstream/SessionWindowsTest.java
index 803080b..8c0a0b9 100644
--- a/streams/src/test/java/org/apache/kafka/streams/kstream/SessionWindowsTest.java
+++ b/streams/src/test/java/org/apache/kafka/streams/kstream/SessionWindowsTest.java
@@ -18,6 +18,9 @@ package org.apache.kafka.streams.kstream;
 
 import org.junit.Test;
 
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.IsNot.not;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
@@ -62,4 +65,18 @@ public class SessionWindowsTest {
         }
     }
 
+    @Test
+    public void shouldBeEqualWhenGapAndMaintainMsAreTheSame() {
+        assertThat(SessionWindows.with(5), equalTo(SessionWindows.with(5)));
+    }
+
+    @Test
+    public void shouldNotBeEqualWhenMaintainMsDifferent() {
+        assertThat(SessionWindows.with(5), not(equalTo(SessionWindows.with(5).until(10))));
+    }
+
+    @Test
+    public void shouldNotBeEqualWhenGapIsDifferent() {
+        assertThat(SessionWindows.with(5), not(equalTo(SessionWindows.with(10))));
+    }
 }
\ No newline at end of file


Mime
View raw message