Skip to content

Commit 50b2787

Browse files
authored
add equals hashCode to BoundedToUnboundedSourceAdapter (#34057)
1 parent f15ce02 commit 50b2787

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

sdks/java/core/src/main/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSource.java

+15
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.Iterator;
2929
import java.util.List;
3030
import java.util.NoSuchElementException;
31+
import java.util.Objects;
3132
import java.util.stream.Collectors;
3233
import org.apache.beam.sdk.coders.Coder;
3334
import org.apache.beam.sdk.coders.CoderException;
@@ -121,6 +122,20 @@ public BoundedToUnboundedSourceAdapter(BoundedSource<T> boundedSource) {
121122
this.boundedSource = boundedSource;
122123
}
123124

125+
@Override
126+
public boolean equals(Object other) {
127+
if (!(other instanceof BoundedToUnboundedSourceAdapter)) {
128+
return false;
129+
}
130+
return Objects.equals(
131+
boundedSource, ((BoundedToUnboundedSourceAdapter<?>) other).boundedSource);
132+
}
133+
134+
@Override
135+
public int hashCode() {
136+
return Objects.hash(boundedSource);
137+
}
138+
124139
@Override
125140
public void validate() {
126141
boundedSource.validate();

sdks/java/core/src/test/java/org/apache/beam/sdk/util/construction/UnboundedReadFromBoundedSourceTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.beam.sdk.util.construction;
1919

2020
import static org.junit.Assert.assertEquals;
21-
import static org.junit.Assert.assertNotEquals;
2221
import static org.junit.Assert.assertNull;
2322
import static org.junit.Assert.assertTrue;
2423

@@ -262,7 +261,7 @@ public void testInvokesSplitWithDefaultNumSplitsTooLarge() throws Exception {
262261
PipelineOptions options = PipelineOptionsFactory.create();
263262
List<?> splits = unboundedCountingSource.split(100, options);
264263
assertEquals(1, splits.size());
265-
assertNotEquals(splits.get(0), unboundedCountingSource);
264+
assertEquals(splits.get(0), unboundedCountingSource);
266265
}
267266

268267
@Test
@@ -272,7 +271,7 @@ public void testInvokingSplitProducesAtLeastOneSplit() throws Exception {
272271
PipelineOptions options = PipelineOptionsFactory.create();
273272
List<?> splits = unboundedCountingSource.split(100, options);
274273
assertEquals(1, splits.size());
275-
assertNotEquals(splits.get(0), unboundedCountingSource);
274+
assertEquals(splits.get(0), unboundedCountingSource);
276275
}
277276

278277
@Test

0 commit comments

Comments
 (0)