Search in sources :

Example 26 with ImmutableWorkerInfo

use of io.druid.indexing.overlord.ImmutableWorkerInfo in project druid by druid-io.

the class SimpleResourceManagementStrategyTest method testDoSuccessfulTerminate.

@Test
public void testDoSuccessfulTerminate() throws Exception {
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0);
    EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.<List<String>>anyObject())).andReturn(Lists.<String>newArrayList());
    EasyMock.expect(autoScaler.terminate(EasyMock.<List<String>>anyObject())).andReturn(new AutoScalingData(Lists.<String>newArrayList()));
    EasyMock.replay(autoScaler);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    EasyMock.expect(runner.getPendingTasks()).andReturn(Collections.singletonList(new RemoteTaskRunnerWorkItem(testTask.getId(), null, null).withQueueInsertionTime(new DateTime()))).times(2);
    EasyMock.expect(runner.getWorkers()).andReturn(Collections.singletonList(new TestZkWorker(testTask).toImmutable())).times(2);
    EasyMock.expect(runner.markWorkersLazy(EasyMock.<Predicate<ImmutableWorkerInfo>>anyObject(), EasyMock.anyInt())).andReturn(Collections.<Worker>singletonList(new TestZkWorker(testTask).getWorker()));
    EasyMock.expect(runner.getLazyWorkers()).andReturn(Lists.<Worker>newArrayList());
    EasyMock.replay(runner);
    boolean terminatedSomething = simpleResourceManagementStrategy.doTerminate(runner);
    Assert.assertTrue(terminatedSomething);
    Assert.assertTrue(simpleResourceManagementStrategy.getStats().toList().size() == 1);
    Assert.assertTrue(simpleResourceManagementStrategy.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.TERMINATE);
    EasyMock.verify(autoScaler);
}
Also used : RemoteTaskRunnerWorkItem(io.druid.indexing.overlord.RemoteTaskRunnerWorkItem) RemoteTaskRunner(io.druid.indexing.overlord.RemoteTaskRunner) DateTime(org.joda.time.DateTime) ImmutableWorkerInfo(io.druid.indexing.overlord.ImmutableWorkerInfo) Test(org.junit.Test)

Example 27 with ImmutableWorkerInfo

use of io.druid.indexing.overlord.ImmutableWorkerInfo in project druid by druid-io.

the class PendingTaskBasedResourceManagementStrategyTest method testSomethingTerminating.

@Test
public void testSomethingTerminating() throws Exception {
    EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0).times(1);
    EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.<List<String>>anyObject())).andReturn(Lists.<String>newArrayList("ip")).times(2);
    EasyMock.expect(autoScaler.terminate(EasyMock.<List<String>>anyObject())).andReturn(new AutoScalingData(Lists.<String>newArrayList("ip")));
    EasyMock.replay(autoScaler);
    RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
    EasyMock.expect(runner.getWorkers()).andReturn(Arrays.asList(new TestZkWorker(testTask).toImmutable())).times(2);
    EasyMock.expect(runner.getLazyWorkers()).andReturn(Lists.<Worker>newArrayList()).times(2);
    EasyMock.expect(runner.markWorkersLazy((Predicate<ImmutableWorkerInfo>) EasyMock.anyObject(), EasyMock.anyInt())).andReturn(Arrays.asList(new TestZkWorker(testTask).toImmutable().getWorker()));
    EasyMock.replay(runner);
    boolean terminatedSomething = strategy.doTerminate(runner);
    Assert.assertTrue(terminatedSomething);
    Assert.assertTrue(strategy.getStats().toList().size() == 1);
    Assert.assertTrue(strategy.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.TERMINATE);
    terminatedSomething = strategy.doTerminate(runner);
    Assert.assertFalse(terminatedSomething);
    Assert.assertTrue(strategy.getStats().toList().size() == 1);
    Assert.assertTrue(strategy.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.TERMINATE);
    EasyMock.verify(autoScaler);
    EasyMock.verify(runner);
}
Also used : RemoteTaskRunner(io.druid.indexing.overlord.RemoteTaskRunner) Worker(io.druid.indexing.worker.Worker) ZkWorker(io.druid.indexing.overlord.ZkWorker) List(java.util.List) ImmutableWorkerInfo(io.druid.indexing.overlord.ImmutableWorkerInfo) Test(org.junit.Test)

Example 28 with ImmutableWorkerInfo

use of io.druid.indexing.overlord.ImmutableWorkerInfo in project druid by druid-io.

the class JavaScriptWorkerSelectStrategyTest method testNoWorkerCanRunTask.

@Test
public void testNoWorkerCanRunTask() {
    ImmutableMap<String, ImmutableWorkerInfo> workerMap = ImmutableMap.of("10.0.0.1", createMockWorker(1, false, true), "10.0.0.4", createMockWorker(1, false, true));
    Optional<ImmutableWorkerInfo> workerForBatchTask = STRATEGY.findWorkerForTask(new TestRemoteTaskRunnerConfig(new Period("PT1S")), workerMap, createMockTask("index_hadoop"));
    Assert.assertFalse(workerForBatchTask.isPresent());
    Optional<ImmutableWorkerInfo> workerForOtherTask = STRATEGY.findWorkerForTask(new TestRemoteTaskRunnerConfig(new Period("PT1S")), workerMap, createMockTask("otherTask"));
    // all other tasks should be sent to worker2
    Assert.assertFalse(workerForOtherTask.isPresent());
}
Also used : TestRemoteTaskRunnerConfig(io.druid.indexing.overlord.TestRemoteTaskRunnerConfig) Period(org.joda.time.Period) ImmutableWorkerInfo(io.druid.indexing.overlord.ImmutableWorkerInfo) Test(org.junit.Test)

Example 29 with ImmutableWorkerInfo

use of io.druid.indexing.overlord.ImmutableWorkerInfo in project druid by druid-io.

the class JavaScriptWorkerSelectStrategyTest method createMockWorker.

private ImmutableWorkerInfo createMockWorker(int currCapacityUsed, boolean canRunTask, boolean isValidVersion) {
    ImmutableWorkerInfo worker = EasyMock.createMock(ImmutableWorkerInfo.class);
    EasyMock.expect(worker.canRunTask(EasyMock.anyObject(Task.class))).andReturn(canRunTask).anyTimes();
    EasyMock.expect(worker.getCurrCapacityUsed()).andReturn(currCapacityUsed).anyTimes();
    EasyMock.expect(worker.isValidVersion(EasyMock.anyString())).andReturn(isValidVersion).anyTimes();
    EasyMock.replay(worker);
    return worker;
}
Also used : ImmutableWorkerInfo(io.druid.indexing.overlord.ImmutableWorkerInfo)

Aggregations

ImmutableWorkerInfo (io.druid.indexing.overlord.ImmutableWorkerInfo)29 Test (org.junit.Test)20 Worker (io.druid.indexing.worker.Worker)10 RemoteTaskRunner (io.druid.indexing.overlord.RemoteTaskRunner)9 RemoteTaskRunnerConfig (io.druid.indexing.overlord.config.RemoteTaskRunnerConfig)9 DateTime (org.joda.time.DateTime)9 NoopTask (io.druid.indexing.common.task.NoopTask)8 RemoteTaskRunnerWorkItem (io.druid.indexing.overlord.RemoteTaskRunnerWorkItem)5 TestRemoteTaskRunnerConfig (io.druid.indexing.overlord.TestRemoteTaskRunnerConfig)5 Period (org.joda.time.Period)5 Task (io.druid.indexing.common.task.Task)4 WorkerBehaviorConfig (io.druid.indexing.overlord.setup.WorkerBehaviorConfig)4 Duration (org.joda.time.Duration)4 Function (com.google.common.base.Function)3 List (java.util.List)3 ZkWorker (io.druid.indexing.overlord.ZkWorker)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 WorkerSelectStrategy (io.druid.indexing.overlord.setup.WorkerSelectStrategy)1