From 6da6b9eeda9f7814b7b81087d323b6291b82ca62 Mon Sep 17 00:00:00 2001 From: nishantmonu51 Date: Tue, 3 Feb 2015 13:20:40 +0530 Subject: [PATCH] fix integer value overflow and add test --- .../coordinator/CostBalancerStrategy.java | 6 +-- .../CostBalancerStrategyTest.java | 38 ++++++++++++++++++- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java b/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java index 12961b4810c..049874d4cbe 100644 --- a/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java +++ b/server/src/main/java/io/druid/server/coordinator/CostBalancerStrategy.java @@ -37,9 +37,9 @@ import java.util.concurrent.Executors; public class CostBalancerStrategy implements BalancerStrategy { private static final EmittingLogger log = new EmittingLogger(CostBalancerStrategy.class); - private static final int DAY_IN_MILLIS = 1000 * 60 * 60 * 24; - private static final int SEVEN_DAYS_IN_MILLIS = 7 * DAY_IN_MILLIS; - private static final int THIRTY_DAYS_IN_MILLIS = 30 * DAY_IN_MILLIS; + private static final long DAY_IN_MILLIS = 1000 * 60 * 60 * 24; + private static final long SEVEN_DAYS_IN_MILLIS = 7 * DAY_IN_MILLIS; + private static final long THIRTY_DAYS_IN_MILLIS = 30 * DAY_IN_MILLIS; private final long referenceTimestamp; private final int threadCount; diff --git a/server/src/test/java/io/druid/server/coordination/CostBalancerStrategyTest.java b/server/src/test/java/io/druid/server/coordination/CostBalancerStrategyTest.java index 7f917d8b4c8..920737c7cf7 100644 --- a/server/src/test/java/io/druid/server/coordination/CostBalancerStrategyTest.java +++ b/server/src/test/java/io/druid/server/coordination/CostBalancerStrategyTest.java @@ -100,10 +100,15 @@ public class CostBalancerStrategyTest * @return segment */ private DataSegment getSegment(int index) + { + return getSegment(index, "DUMMY", day); + } + + private DataSegment getSegment(int index, String dataSource, Interval interval) { // Not using EasyMock as it hampers the performance of multithreads. DataSegment segment = new DataSegment( - "DUMMY", day, String.valueOf(index), Maps.newConcurrentMap(), + dataSource, interval, String.valueOf(index), Maps.newConcurrentMap(), Lists.newArrayList(), Lists.newArrayList(), null, 0, index * 100L ); return segment; @@ -135,7 +140,8 @@ public class CostBalancerStrategyTest Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName()); } - @Test @Ignore + @Test + @Ignore public void testBenchmark() throws InterruptedException { setupDummyCluster(100, 500); @@ -156,4 +162,32 @@ public class CostBalancerStrategyTest System.err.println("Latency - Single Threaded (ms): " + latencySingleThread); System.err.println("Latency - Multi Threaded (ms): " + latencyMultiThread); } + + @Test + public void testComputeJointSegmentCost() + { + DateTime referenceTime = new DateTime("2014-01-01T00:00:00"); + CostBalancerStrategy strategy = new CostBalancerStrategy(referenceTime, 4); + double segmentCost = strategy.computeJointSegmentCosts( + getSegment( + 100, + "DUMMY", + new Interval( + referenceTime, + referenceTime.plusHours(1) + ) + ), + getSegment( + 101, + "DUMMY", + new Interval( + referenceTime.minusDays(2), + referenceTime.minusDays(2).plusHours(1) + ) + ) + ); + Assert.assertEquals(138028.62811791385d, segmentCost, 0); + + } + }