/** * Configures the test with additional environment variables in the Scheduler beyond those which would be included * by the service's {@code marathon.json.mustache}. This may be useful for tests against custom Service * Specification YAML files which reference envvars that aren't also present in the packaging's Marathon definition. * These values will override any produced by the service's packaging. * * @param schedulerEnvKeyVals an even number of strings which will be unpacked as (key, value, key, value, ...) * @return {@code this} */ public ServiceTestRunner setSchedulerEnv(String... schedulerEnvKeyVals) { setSchedulerEnv(toMap(schedulerEnvKeyVals)); return this; }
.setSchedulerEnv(placementEnvKey, originalPlacement) .run(); .setSchedulerEnv(placementEnvKey, newPlacement) .addCustomValidator(configValidator) .setState(result)
@Test(expected = IllegalStateException.class) public void testInvalidStep() throws Exception { new ServiceTestRunner("custom_steps.yml") .setSchedulerEnv( "DEPLOY_STRATEGY", "serial", "DEPLOY_STEPS", "[[foo, bar]]") .run(Collections.emptyList()); }
@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); }
@Test(expected = IllegalStateException.class) public void testInvalidPlacementConstraint() throws Exception { new ServiceTestRunner() .setSchedulerEnv("HELLO_PLACEMENT", INVALID_HOSTNAME_CONSTRAINT) .run(getDefaultDeploymentTicks()); }
@Test public void testValidPlacementConstraint() throws Exception { new ServiceTestRunner() .setSchedulerEnv("HELLO_PLACEMENT", VALID_HOSTNAME_CONSTRAINT) .run(getDefaultDeploymentTicks()); }
Map<String, String> schedulerEnv = schedulerEnvForExamples.get(examplesFile.getName()); if (schedulerEnv != null) { serviceTestRunner.setSchedulerEnv(schedulerEnv);
@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); }
@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); }
.setSchedulerEnv( "DEPLOY_STRATEGY", "parallel", "DEPLOY_STEPS", "[[first], [second]]")
.setSchedulerEnv( "DEPLOY_STRATEGY", "serial", "DEPLOY_STEPS", "[[first], [second]]")
.setSchedulerEnv( "DEPLOY_STRATEGY", "serial", "DEPLOY_STEPS", "[[first], [second, third]]")
.setSchedulerEnv( "DEPLOY_STRATEGY", "parallel", "DEPLOY_STEPS", "[[first], [second, third]]")