sashidhar commented on a change in pull request #7933: #7858 Throwing 
UnsupportedOperationException from ImmutableDruidDataSource's equals() and 
hashCode() methods
URL: https://github.com/apache/incubator-druid/pull/7933#discussion_r303553372
 
 

 ##########
 File path: 
server/src/test/java/org/apache/druid/client/ImmutableDruidDataSourceTest.java
 ##########
 @@ -26,39 +26,85 @@
 import com.google.common.collect.ImmutableSortedMap;
 import org.apache.druid.jackson.DefaultObjectMapper;
 import org.apache.druid.java.util.common.Intervals;
+import org.apache.druid.test.utils.ImmutableDruidDataSourceTestUtils;
 import org.apache.druid.timeline.DataSegment;
 import org.apache.druid.timeline.DataSegment.PruneLoadSpecHolder;
-import org.junit.Assert;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 import java.io.IOException;
 
 public class ImmutableDruidDataSourceTest
 {
+
+  @Rule
+  public ExpectedException expectedException = ExpectedException.none();
+
   @Test
   public void testSerde() throws IOException
   {
-    final DataSegment segment = new DataSegment(
-        "test",
-        Intervals.of("2017/2018"),
-        "version",
-        null,
-        ImmutableList.of("dim1", "dim2"),
-        ImmutableList.of("met1", "met2"),
-        null,
-        1,
-        100L,
-        PruneLoadSpecHolder.DEFAULT
-    );
-    final ImmutableDruidDataSource dataSource = new ImmutableDruidDataSource(
-        "test",
-        ImmutableMap.of("prop1", "val1", "prop2", "val2"),
-        ImmutableSortedMap.of(segment.getId(), segment)
-    );
+    final DataSegment segment = getTestSegment();
+    final ImmutableDruidDataSource dataSource = 
getImmutableDruidDataSource(segment);
 
     final ObjectMapper objectMapper = new DefaultObjectMapper()
         .setInjectableValues(new Std().addValue(PruneLoadSpecHolder.class, 
PruneLoadSpecHolder.DEFAULT));
     final String json = objectMapper.writeValueAsString(dataSource);
-    Assert.assertEquals(dataSource, objectMapper.readValue(json, 
ImmutableDruidDataSource.class));
+
+    ImmutableDruidDataSourceTestUtils.assertEquals(dataSource, 
objectMapper.readValue(json,
+        ImmutableDruidDataSource.class));
+  }
+
+  @Test
+  public void testEqualsMethodThrowsUnsupportedOperationException()
+  {
+    expectedException.expect(UnsupportedOperationException.class);
+    expectedException.expectMessage("ImmutableDruidDataSource shouldn't be 
used as the key in containers");
+
+    final DataSegment segment1 = getTestSegment();
+
+    final ImmutableDruidDataSource dataSource1 = 
getImmutableDruidDataSource(segment1);
+
+    final DataSegment segment2 = getTestSegment();
+
+    final ImmutableDruidDataSource dataSource2 = 
getImmutableDruidDataSource(segment2);
+
+    dataSource1.equals(dataSource2);
+  }
+
+  private ImmutableDruidDataSource getImmutableDruidDataSource(DataSegment 
segment1)
+  {
+    return new ImmutableDruidDataSource(
+      "test",
+      ImmutableMap.of("prop1", "val1", "prop2", "val2"),
+      ImmutableSortedMap.of(segment1.getId(), segment1)
+    );
+  }
+
+  private DataSegment getTestSegment()
+  {
+    return new DataSegment(
+      "test",
+      Intervals.of("2017/2018"),
+      "version",
+      null,
+      ImmutableList.of("dim1", "dim2"),
+      ImmutableList.of("met1", "met2"),
+      null,
+      1,
+      100L,
+      PruneLoadSpecHolder.DEFAULT
+    );
+  }
+
+  @Test
+  public void testhashCodeMethodThrowsUnsupportedOperationException()
 
 Review comment:
   Oops.. fixed 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

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to