mirror of https://github.com/apache/druid.git
fix integer value overflow and add test
This commit is contained in:
parent
b94b24c46e
commit
6da6b9eeda
|
@ -37,9 +37,9 @@ import java.util.concurrent.Executors;
|
||||||
public class CostBalancerStrategy implements BalancerStrategy
|
public class CostBalancerStrategy implements BalancerStrategy
|
||||||
{
|
{
|
||||||
private static final EmittingLogger log = new EmittingLogger(CostBalancerStrategy.class);
|
private static final EmittingLogger log = new EmittingLogger(CostBalancerStrategy.class);
|
||||||
private static final int DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
private static final long DAY_IN_MILLIS = 1000 * 60 * 60 * 24;
|
||||||
private static final int SEVEN_DAYS_IN_MILLIS = 7 * DAY_IN_MILLIS;
|
private static final long SEVEN_DAYS_IN_MILLIS = 7 * DAY_IN_MILLIS;
|
||||||
private static final int THIRTY_DAYS_IN_MILLIS = 30 * DAY_IN_MILLIS;
|
private static final long THIRTY_DAYS_IN_MILLIS = 30 * DAY_IN_MILLIS;
|
||||||
private final long referenceTimestamp;
|
private final long referenceTimestamp;
|
||||||
private final int threadCount;
|
private final int threadCount;
|
||||||
|
|
||||||
|
|
|
@ -100,10 +100,15 @@ public class CostBalancerStrategyTest
|
||||||
* @return segment
|
* @return segment
|
||||||
*/
|
*/
|
||||||
private DataSegment getSegment(int index)
|
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.
|
// Not using EasyMock as it hampers the performance of multithreads.
|
||||||
DataSegment segment = new DataSegment(
|
DataSegment segment = new DataSegment(
|
||||||
"DUMMY", day, String.valueOf(index), Maps.<String, Object>newConcurrentMap(),
|
dataSource, interval, String.valueOf(index), Maps.<String, Object>newConcurrentMap(),
|
||||||
Lists.<String>newArrayList(), Lists.<String>newArrayList(), null, 0, index * 100L
|
Lists.<String>newArrayList(), Lists.<String>newArrayList(), null, 0, index * 100L
|
||||||
);
|
);
|
||||||
return segment;
|
return segment;
|
||||||
|
@ -135,7 +140,8 @@ public class CostBalancerStrategyTest
|
||||||
Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName());
|
Assert.assertEquals("Best Server should be BEST_SERVER", "BEST_SERVER", holder.getServer().getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test @Ignore
|
@Test
|
||||||
|
@Ignore
|
||||||
public void testBenchmark() throws InterruptedException
|
public void testBenchmark() throws InterruptedException
|
||||||
{
|
{
|
||||||
setupDummyCluster(100, 500);
|
setupDummyCluster(100, 500);
|
||||||
|
@ -156,4 +162,32 @@ public class CostBalancerStrategyTest
|
||||||
System.err.println("Latency - Single Threaded (ms): " + latencySingleThread);
|
System.err.println("Latency - Single Threaded (ms): " + latencySingleThread);
|
||||||
System.err.println("Latency - Multi Threaded (ms): " + latencyMultiThread);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue