Search in sources :

Example 1 with CostBalancerStrategy

use of org.apache.druid.server.coordinator.CostBalancerStrategy in project druid by druid-io.

the class CachingCostBalancerStrategyTest method decisionTest.

@Test
public void decisionTest() {
    CachingCostBalancerStrategy cachingCostBalancerStrategy = createCachingCostBalancerStrategy(serverHolderList, executorService);
    CostBalancerStrategy costBalancerStrategy = createCostBalancerStrategy(executorService);
    int notEqual = segmentQueries.stream().mapToInt(s -> {
        ServerHolder s1 = cachingCostBalancerStrategy.findNewSegmentHomeBalancer(s, serverHolderList);
        ServerHolder s2 = costBalancerStrategy.findNewSegmentHomeBalancer(s, serverHolderList);
        return (s1.getServer().getName().equals(s2.getServer().getName())) ? 0 : 1;
    }).sum();
    Assert.assertTrue(((double) notEqual / (double) segmentQueries.size()) < 0.01);
}
Also used : IntStream(java.util.stream.IntStream) DateTimes(org.apache.druid.java.util.common.DateTimes) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Execs(org.apache.druid.java.util.common.concurrent.Execs) CostBalancerStrategy(org.apache.druid.server.coordinator.CostBalancerStrategy) DruidServer(org.apache.druid.client.DruidServer) DateTime(org.joda.time.DateTime) Test(org.junit.Test) Random(java.util.Random) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) Interval(org.joda.time.Interval) List(java.util.List) After(org.junit.After) ServerType(org.apache.druid.server.coordination.ServerType) DataSegment(org.apache.druid.timeline.DataSegment) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) Assert(org.junit.Assert) Collections(java.util.Collections) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) LoadQueuePeonTester(org.apache.druid.server.coordinator.LoadQueuePeonTester) Before(org.junit.Before) CostBalancerStrategy(org.apache.druid.server.coordinator.CostBalancerStrategy) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) ServerHolder(org.apache.druid.server.coordinator.ServerHolder) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) Test(org.junit.Test)

Aggregations

ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 MoreExecutors (com.google.common.util.concurrent.MoreExecutors)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 TimeUnit (java.util.concurrent.TimeUnit)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 DruidServer (org.apache.druid.client.DruidServer)1 DateTimes (org.apache.druid.java.util.common.DateTimes)1 Execs (org.apache.druid.java.util.common.concurrent.Execs)1 ServerType (org.apache.druid.server.coordination.ServerType)1 CachingCostBalancerStrategy (org.apache.druid.server.coordinator.CachingCostBalancerStrategy)1 CostBalancerStrategy (org.apache.druid.server.coordinator.CostBalancerStrategy)1 LoadQueuePeonTester (org.apache.druid.server.coordinator.LoadQueuePeonTester)1 ServerHolder (org.apache.druid.server.coordinator.ServerHolder)1 DataSegment (org.apache.druid.timeline.DataSegment)1 DateTime (org.joda.time.DateTime)1 Interval (org.joda.time.Interval)1