use of org.apache.druid.indexing.overlord.RemoteTaskRunner in project druid by druid-io.
the class PendingTaskBasedProvisioningStrategyTest method testNullWorkerConfig.
@Test
public void testNullWorkerConfig() {
workerConfig.set(null);
EasyMock.replay(autoScaler);
RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(Collections.singletonList(NoopTask.create())).times(1);
EasyMock.expect(runner.getWorkers()).andReturn(Collections.singletonList(new TestZkWorker(null).toImmutable())).times(2);
EasyMock.replay(runner);
Provisioner provisioner = strategy.makeProvisioner(runner);
boolean terminatedSomething = provisioner.doTerminate();
boolean provisionedSomething = provisioner.doProvision();
Assert.assertFalse(terminatedSomething);
Assert.assertFalse(provisionedSomething);
EasyMock.verify(autoScaler);
EasyMock.verify(runner);
}
use of org.apache.druid.indexing.overlord.RemoteTaskRunner in project druid by druid-io.
the class PendingTaskBasedProvisioningStrategyTest method testMinCountIncrease.
@Test
public void testMinCountIncrease() {
// Don't terminate anything
EasyMock.reset(autoScaler);
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(2);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(Collections.singletonList("ip"));
EasyMock.replay(autoScaler);
RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(Collections.emptyList()).times(2);
EasyMock.expect(runner.getWorkers()).andReturn(Collections.singletonList(new TestZkWorker(NoopTask.create(), "http", "h1", "i1", MIN_VERSION).toImmutable())).times(3);
EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig()).times(2);
EasyMock.expect(runner.getLazyWorkers()).andReturn(new ArrayList<>());
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())).andReturn(Collections.emptyList());
EasyMock.replay(runner);
Provisioner provisioner = strategy.makeProvisioner(runner);
boolean terminatedSomething = provisioner.doTerminate();
Assert.assertFalse(terminatedSomething);
EasyMock.verify(autoScaler);
// Don't provision anything
EasyMock.reset(autoScaler);
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(2);
EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(2);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(Collections.singletonList("ip"));
EasyMock.replay(autoScaler);
boolean provisionedSomething = provisioner.doProvision();
Assert.assertFalse(provisionedSomething);
EasyMock.verify(autoScaler);
EasyMock.reset(autoScaler);
// Increase minNumWorkers
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(3).times(2);
EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(5);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(Collections.singletonList("ip"));
EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("h3")));
// Should provision two new workers
EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("h4")));
EasyMock.replay(autoScaler);
provisionedSomething = provisioner.doProvision();
Assert.assertTrue(provisionedSomething);
EasyMock.verify(autoScaler);
EasyMock.verify(runner);
}
use of org.apache.druid.indexing.overlord.RemoteTaskRunner in project druid by druid-io.
the class PendingTaskBasedProvisioningStrategyTest method testNoActionNeeded.
@Test
public void testNoActionNeeded() {
EasyMock.reset(autoScaler);
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(2);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(Collections.singletonList("ip"));
EasyMock.replay(autoScaler);
RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(Collections.singletonList((Task) NoopTask.create())).times(1);
EasyMock.expect(runner.getWorkers()).andReturn(Arrays.asList(new TestZkWorker(NoopTask.create()).toImmutable(), new TestZkWorker(NoopTask.create()).toImmutable())).times(2);
EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
EasyMock.expect(runner.getLazyWorkers()).andReturn(new ArrayList<>());
EasyMock.expect(runner.markWorkersLazy(EasyMock.anyObject(), EasyMock.anyInt())).andReturn(Collections.emptyList());
EasyMock.replay(runner);
Provisioner provisioner = strategy.makeProvisioner(runner);
boolean terminatedSomething = provisioner.doTerminate();
Assert.assertFalse(terminatedSomething);
EasyMock.verify(autoScaler);
EasyMock.reset(autoScaler);
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(1).times(2);
EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(2);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(Collections.singletonList("ip"));
EasyMock.replay(autoScaler);
boolean provisionedSomething = provisioner.doProvision();
Assert.assertFalse(provisionedSomething);
EasyMock.verify(autoScaler);
EasyMock.verify(runner);
}
use of org.apache.druid.indexing.overlord.RemoteTaskRunner in project druid by druid-io.
the class PendingTaskBasedProvisioningStrategyTest method testProvisionNoCurrentlyRunningWorkerWithCapacityHintSetAndNoPendingTaskShouldProvisionMinimumAsCurrentIsBelowMinimum.
@Test
public void testProvisionNoCurrentlyRunningWorkerWithCapacityHintSetAndNoPendingTaskShouldProvisionMinimumAsCurrentIsBelowMinimum() {
PendingTaskBasedWorkerProvisioningConfig config = new PendingTaskBasedWorkerProvisioningConfig().setMaxScalingDuration(new Period(1000)).setNumEventsToTrack(10).setPendingTaskTimeout(new Period(0)).setWorkerVersion(MIN_VERSION).setMaxScalingStep(2).setWorkerCapacityHint(30);
strategy = new PendingTaskBasedWorkerProvisioningStrategy(config, DSuppliers.of(workerConfig), new ProvisioningSchedulerConfig(), new Supplier<ScheduledExecutorService>() {
@Override
public ScheduledExecutorService get() {
return executorService;
}
});
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(3).times(2);
EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(5);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>());
RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
// No pending tasks
EasyMock.expect(runner.getPendingTaskPayloads()).andReturn(new ArrayList<>());
EasyMock.expect(runner.getWorkers()).andReturn(Collections.emptyList());
EasyMock.expect(runner.getConfig()).andReturn(new RemoteTaskRunnerConfig());
EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("aNode"))).times(3);
EasyMock.replay(runner, autoScaler);
Provisioner provisioner = strategy.makeProvisioner(runner);
boolean provisionedSomething = provisioner.doProvision();
Assert.assertTrue(provisionedSomething);
Assert.assertTrue(provisioner.getStats().toList().size() == 3);
for (ScalingStats.ScalingEvent event : provisioner.getStats().toList()) {
Assert.assertTrue(event.getEvent() == ScalingStats.EVENT.PROVISION);
}
}
use of org.apache.druid.indexing.overlord.RemoteTaskRunner in project druid by druid-io.
the class SimpleProvisioningStrategyTest method testProvisionAlert.
@Test
public void testProvisionAlert() throws Exception {
ServiceEmitter emitter = EasyMock.createMock(ServiceEmitter.class);
EmittingLogger.registerEmitter(emitter);
emitter.emit(EasyMock.<ServiceEventBuilder>anyObject());
EasyMock.expectLastCall().atLeastOnce();
EasyMock.replay(emitter);
EasyMock.expect(autoScaler.getMinNumWorkers()).andReturn(0).times(2);
EasyMock.expect(autoScaler.getMaxNumWorkers()).andReturn(2).times(2);
EasyMock.expect(autoScaler.ipToIdLookup(EasyMock.anyObject())).andReturn(new ArrayList<String>()).times(2);
EasyMock.expect(autoScaler.terminateWithIds(EasyMock.anyObject())).andReturn(null);
EasyMock.expect(autoScaler.provision()).andReturn(new AutoScalingData(Collections.singletonList("fake")));
EasyMock.replay(autoScaler);
RemoteTaskRunner runner = EasyMock.createMock(RemoteTaskRunner.class);
EasyMock.expect(runner.getPendingTasks()).andReturn(Collections.singletonList(new RemoteTaskRunnerWorkItem(testTask.getId(), testTask.getType(), null, null, testTask.getDataSource()).withQueueInsertionTime(DateTimes.nowUtc()))).times(2);
EasyMock.expect(runner.getWorkers()).andReturn(Collections.singletonList(new TestZkWorker(testTask).toImmutable())).times(2);
EasyMock.replay(runner);
Provisioner provisioner = strategy.makeProvisioner(runner);
boolean provisionedSomething = provisioner.doProvision();
Assert.assertTrue(provisionedSomething);
Assert.assertTrue(provisioner.getStats().toList().size() == 1);
DateTime createdTime = provisioner.getStats().toList().get(0).getTimestamp();
Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
Thread.sleep(2000);
provisionedSomething = provisioner.doProvision();
Assert.assertFalse(provisionedSomething);
Assert.assertTrue(provisioner.getStats().toList().get(0).getEvent() == ScalingStats.EVENT.PROVISION);
DateTime anotherCreatedTime = provisioner.getStats().toList().get(0).getTimestamp();
Assert.assertTrue(createdTime.equals(anotherCreatedTime));
EasyMock.verify(autoScaler);
EasyMock.verify(emitter);
EasyMock.verify(runner);
}
Aggregations