Search in sources :

Example 1 with CachingCostBalancerStrategy

use of org.apache.druid.server.coordinator.CachingCostBalancerStrategy 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)

Example 2 with CachingCostBalancerStrategy

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

the class LoadRuleTest method setUp.

@Before
public void setUp() {
    EmittingLogger.registerEmitter(EMITTER);
    EMITTER.start();
    throttler = EasyMock.createMock(ReplicationThrottler.class);
    exec = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(1));
    balancerStrategy = new CostBalancerStrategyFactory().createBalancerStrategy(exec);
    cachingCostBalancerStrategy = new CachingCostBalancerStrategy(ClusterCostCache.builder().build(), exec);
    mockBalancerStrategy = EasyMock.createMock(BalancerStrategy.class);
}
Also used : BalancerStrategy(org.apache.druid.server.coordinator.BalancerStrategy) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) ReplicationThrottler(org.apache.druid.server.coordinator.ReplicationThrottler) CostBalancerStrategyFactory(org.apache.druid.server.coordinator.CostBalancerStrategyFactory) CachingCostBalancerStrategy(org.apache.druid.server.coordinator.CachingCostBalancerStrategy) Before(org.junit.Before)

Aggregations

CachingCostBalancerStrategy (org.apache.druid.server.coordinator.CachingCostBalancerStrategy)2 Before (org.junit.Before)2 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 BalancerStrategy (org.apache.druid.server.coordinator.BalancerStrategy)1 CostBalancerStrategy (org.apache.druid.server.coordinator.CostBalancerStrategy)1 CostBalancerStrategyFactory (org.apache.druid.server.coordinator.CostBalancerStrategyFactory)1 LoadQueuePeonTester (org.apache.druid.server.coordinator.LoadQueuePeonTester)1 ReplicationThrottler (org.apache.druid.server.coordinator.ReplicationThrottler)1