@Test public void testParallelStrategyParallelSteps() throws Exception { Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); // Service should launch all of hello-0/1-first/second using the provided offers: ticks.add(Send.offerBuilder("hello").setCount(3).build()); // Launches will end up being split across two offers/agents: ticks.add(Expect.launchedTasks(2, "hello-0-first", "hello-0-second", "hello-1-first", "hello-1-second")); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.samePod("hello-0-first", "hello-0-second")); ticks.add(Expect.samePod("hello-1-first", "hello-1-second")); // No more hellos to launch: ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.allPlansComplete()); new ServiceTestRunner("custom_steps.yml") .setSchedulerEnv( "DEPLOY_STRATEGY", "parallel", "DEPLOY_STEPS", "[[first, second]]") .run(ticks); }
ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_FAILED).build()); ticks.add(Send.emptyOffers()); ticks.add(Send.replacePod("hello-0")); ticks.add(Send.emptyOffers()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.allPlansComplete());
LOGGER.info("SEND: {}", tick.getDescription()); try { ((Send) tick).send(clusterState, mockDriver, frameworkScheduler); } catch (Throwable e) { throw buildSimulationError(ticks, tick, e);
ticks.add(Send.register());
@Test public void testSwitchToInvalidPlacementConstraint() throws Exception { ServiceTestResult initial = new ServiceTestRunner() .setSchedulerEnv("HELLO_PLACEMENT", VALID_HOSTNAME_CONSTRAINT) .run(getDefaultDeploymentTicks()); Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.planStatus("deploy", Status.ERROR)); new ServiceTestRunner() .setState(initial) .setSchedulerEnv("HELLO_PLACEMENT", INVALID_HOSTNAME_CONSTRAINT) .run(ticks); }
/** * Checks that unexpected Tasks are killed. */ @Test public void testZombieTaskKilling() throws Exception { Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); // Verify that service launches 1 hello pod. ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-server")); // Running, no readiness check is applicable: ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); String taskId = CommonIdUtils.toTaskId("bogus", "taskid").getValue(); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING) .setTaskId(taskId) .build()); // Unknown task that we made up above was killed, but the launched task was not killed: ticks.add(Expect.taskIdKilled(taskId)); ticks.add(Expect.taskNameNotKilled("hello-0-server")); new ServiceTestRunner("simple.yml").run(ticks); }
ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_FAILED).build()); ticks.add(Send.emptyOffers()); ticks.add(Send.register()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_FAILED).build()); ticks.add(Send.emptyOffers()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_FAILED).build()); ticks.add(Send.emptyOffers()); ticks.add(Expect.revivedOffers(1)); ticks.add(Send.replacePod("world-0")); ticks.add(Send.emptyOffers()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.recoveryStepStatus("world-0:[server]", "world-0:[server]", Status.STARTING)); ticks.add(Expect.launchedTasks("world-0-server")); ticks.add(Expect.taskEnv(result.getPersister(), "world-0-server", "SLEEP_DURATION", oldEnv)); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setPodIndexToReoffer(0).build()); ticks.add(Expect.deployStepStatus("hello", "hello-0:[server]", Status.STARTING)); ticks.add(Expect.launchedTasks("hello-0-server"));
@Test public void testSerialStrategyParallelSteps() throws Exception { Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); // Service should launch hello-0-first and hello-0-second at the same time. ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-0-first", "hello-0-second")); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); // New offer declined since hello-0-second isn't RUNNING yet: ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.samePod("hello-0-first", "hello-0-second")); // Now hello-1 may be deployed: ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-1-first", "hello-1-second")); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.samePod("hello-1-first", "hello-1-second")); // No more hellos to launch: ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.allPlansComplete()); new ServiceTestRunner("custom_steps.yml") .setSchedulerEnv( "DEPLOY_STRATEGY", "serial", "DEPLOY_STEPS", "[[first, second]]") .run(ticks); }
ticks.add(Send.register()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.launchedTasks("world-0-server")); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING) .setReadinessCheckExitCode(readinessCheckStatusCode).build()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.register()); ticks.add(Expect.reconciledExplicitly(result.getPersister()));
ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.launchedTasks("world-0-server")); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.offerBuilder("world").setHostname("host-foo").build()); ticks.add(Expect.launchedTasks("world-1-server")); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.offerBuilder("world").setHostname("host-bar").build()); ticks.add(Expect.declinedLastOffer());
ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-essential", "hello-0-nonessential")); ticks.add(Send.taskStatus("hello-0-essential", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-0-nonessential", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setHostname("host-foo").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.allPlansComplete()); ticks.add(Send.taskStatus("hello-0-essential", Protos.TaskState.TASK_FAILED).build()); } else { ticks.add(Send.taskStatus("hello-0-nonessential", Protos.TaskState.TASK_FAILED).build()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.declinedLastOffer()); if (essential) { ticks.add(Send.offerBuilder("hello").setPodIndexToReoffer(0).build()); ticks.add(Send.taskStatus("hello-0-nonessential", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-0-essential", Protos.TaskState.TASK_RUNNING).build()); } else { ticks.add(Expect.launchedTasks("hello-0-nonessential")); ticks.add(Send.taskStatus("hello-0-nonessential", Protos.TaskState.TASK_RUNNING).build());
Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Expect.launchedTasks("hello-0-second", "hello-0-third")); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Expect.launchedTasks("hello-1-second", "hello-1-third")); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-0-third", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-third", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer());
ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-0-first")); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Expect.launchedTasks("hello-0-second", "hello-0-third")); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-0-third", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-1-first")); // hello-0 complete ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Expect.launchedTasks("hello-1-second", "hello-1-third"));
Collection<SimulationTick> ticks = new ArrayList<>(); ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Expect.launchedTasks("hello-0-second")); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Expect.launchedTasks("hello-1-second")); ticks.add(Expect.samePod("hello-1-first", "hello-1-second")); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("hello-1-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer());
ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-0-first")); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("hello-0-first", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(0).build()); ticks.add(Expect.launchedTasks("hello-0-second")); ticks.add(Send.taskStatus("hello-0-second", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.launchedTasks("hello-1-first")); ticks.add(Send.offerBuilder("hello").setCount(3).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.offerBuilder("hello").setCount(3).setPodIndexToReoffer(1).build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.taskStatus("hello-1-first", Protos.TaskState.TASK_RUNNING).build());
ticks.add(Send.register()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Expect.declinedLastOffer());
ticks.add(Send.register()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Expect.deployStepStatus("hello-deploy", "hello-0:[server]", Status.STARTING)); ticks.add(Send.register()); ticks.add(Expect.reconciledExplicitly(result.getPersister())); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.taskNameKilled("hello-0-server", 1)); ticks.add(Send.offerBuilder("hello").setPodIndexToReoffer(0).build()); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Expect.deployStepStatus("hello-deploy", "hello-0:[server]", Status.STARTING)); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.suppressedOffers(1)); ticks.add(Send.register()); ticks.add(Expect.reconciledExplicitly(result.getPersister())); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.reconciledImplicitly());
ticks.add(Send.register()); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).setReadinessCheckExitCode(0).build()); ticks.add(Send.offerBuilder("hello").build()); ticks.add(Expect.reconciledImplicitly()); ticks.add(Expect.declinedLastOffer()); ticks.add(Send.offerBuilder("world").setPodIndexToReoffer(0).build()); ticks.add(new ExpectDecommissionPlanProgress(Arrays.asList( new StepCount("world-1", stepCount - 2, 1, 1), new StepCount("world-0", stepCount, 0, 0)))); ticks.add(Send.offerBuilder("world").setPodIndexToReoffer(1).build()); ticks.add(Expect.unreservedTasks("world-1-server")); ticks.add(new ExpectDecommissionPlanProgress(Arrays.asList( ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server", "world-0-server")); ticks.add(Send.offerBuilder("world").setPodIndexToReoffer(0).build()); ticks.add(new ExpectDecommissionPlanProgress(Arrays.asList( new StepCount("world-1", 0, 0, stepCount), new StepCount("world-0", 1, 0, stepCount - 1)))); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server"));