/** * Configures the test with the provided state from a prior run. This may be used to initialize a second simulation * with the state of a first simulation. Otherwise the simulation will be performed with empty state, simulating * an initial install. * * @param serviceTestResult the result from a previous simulation, from which state will be retrieved * @return {@code this} */ public ServiceTestRunner setState(ServiceTestResult serviceTestResult) { this.persister = serviceTestResult.getPersister(); this.oldClusterState = serviceTestResult.getClusterState(); return this; }
.run(getDefaultDeploymentTicks()); checkNotFound(result.getPersister(), "/Tasks"); checkNotFound(result.getPersister(), "/Configurations"); byte[] frameworkId = result.getPersister().get("/FrameworkID"); checkNamespace(result, "path.to.namespace", "/path/to/namespace", "/Services/path__to__namespace"); .run(getDefaultDeploymentTicks()); checkNotFound(result.getPersister(), "/Tasks"); checkNotFound(result.getPersister(), "/Configurations"); Assert.assertEquals(3, result.getPersister().getChildren("/Services/path__to__namespace/Tasks").size()); Assert.assertEquals(1, result.getPersister().getChildren("/Services/path__to__namespace/Configurations").size()); Assert.assertArrayEquals(frameworkId, result.getPersister().get("/FrameworkID")); checkNamespace(result, "test-namespace", "test-namespace", "/Services/test-namespace"); Assert.assertEquals(3, result.getPersister().getChildren("/Services/path__to__namespace/Tasks").size()); Assert.assertEquals(1, result.getPersister().getChildren("/Services/path__to__namespace/Configurations").size()); Assert.assertEquals(3, result.getPersister().getChildren("/Services/test-namespace/Tasks").size()); Assert.assertEquals(1, result.getPersister().getChildren("/Services/test-namespace/Configurations").size()); Assert.assertArrayEquals(frameworkId, result.getPersister().get("/FrameworkID")); checkNamespace(result, "hello-world", null, "");
ticks.add(Expect.reconciledExplicitly(result.getPersister()));
Assert.assertEquals( new TreeSet<>(Arrays.asList("hello-0-server", "world-0-server", "world-1-server")), result.getPersister().getChildren("/Tasks")); ticks.add(Expect.reconciledExplicitly(result.getPersister())); 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());
Assert.assertFalse(StateStoreUtils.getDeploymentWasCompleted(new StateStore(result.getPersister()))); ticks.add(Expect.reconciledExplicitly(result.getPersister())); Assert.assertTrue(StateStoreUtils.getDeploymentWasCompleted(new StateStore(result.getPersister()))); ticks.add(Expect.reconciledExplicitly(result.getPersister())); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.reconciledImplicitly()); Assert.assertTrue(StateStoreUtils.getDeploymentWasCompleted(new StateStore(result.getPersister())));
private static void checkNamespace( ServiceTestResult result, String sanitizedServiceName, String resourceNamespace, String persisterPrefix) throws Exception { Collection<String> taskNames = Arrays.asList("hello-0-server", "world-0-server", "world-1-server"); // Persister: everything under a specified prefix (or no prefix). Assert.assertEquals(new TreeSet<>(taskNames), result.getPersister().getChildren(persisterPrefix + "/Tasks")); Assert.assertEquals(1, result.getPersister().getChildren(persisterPrefix + "/Configurations").size()); for (String taskName : taskNames) { LaunchedTask launchedTask = result.getClusterState().getLastLaunchedTask(taskName); // Each task should have a taskId and executorId containing the service name, regardless of namespacing: Assert.assertEquals(sanitizedServiceName, CommonIdUtils.toSanitizedServiceName(launchedTask.getExecutor().getExecutorId()).get()); Assert.assertEquals(sanitizedServiceName, CommonIdUtils.toSanitizedServiceName(launchedTask.getTask().getTaskId()).get()); if (resourceNamespace != null) { // All task+executor resources should have a 'namespace' label for (Protos.Resource resource : ResourceUtils.getAllResources(launchedTask.getTask())) { Assert.assertEquals(resourceNamespace, ResourceUtils.getNamespace(resource).get()); } } else { // All task+executor resources should NOT have a 'namespace' label for (Protos.Resource resource : ResourceUtils.getAllResources(launchedTask.getTask())) { Assert.assertFalse(ResourceUtils.getNamespace(resource).isPresent()); } } } }
/** * Validates service deployment in the default configuration case. */ @Test public void testDefaultDeployment() throws Exception { ServiceTestResult result = new ServiceTestRunner().run(getDefaultDeploymentTicks()); // After deployment completed, service should have stored that fact to ZK: Assert.assertTrue(StateStoreUtils.getDeploymentWasCompleted(new StateStore(result.getPersister()))); }
Assert.assertEquals( new TreeSet<>(Arrays.asList("hello-0-server", "world-0-server", "world-1-server")), result.getPersister().getChildren("/Tasks")); ticks.add(Expect.reconciledExplicitly(result.getPersister())); 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(new ExpectDecommissionPlanProgress(Arrays.asList( new StepCount("world-1", 1, 0, stepCount - 1), new StepCount("world-0", stepCount, 0, 0)))); // FAIL ticks.add(new ExpectEmptyResources(result.getPersister(), "world-1-server")); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server", "world-0-server", "world-1-server")); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server", "world-0-server")); ticks.add(new ExpectDecommissionPlanProgress(Arrays.asList( new StepCount("world-1", 0, 0, stepCount), new StepCount("world-0", stepCount, 0, 0)))); new StepCount("world-1", 0, 0, stepCount), new StepCount("world-0", 1, 0, stepCount - 1)))); ticks.add(Expect.taskNameKilled("world-0-server", 1)); ticks.add(new ExpectEmptyResources(result.getPersister(), "world-0-server")); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server", "world-0-server")); ticks.add(Send.offerBuilder("world").build()); ticks.add(Expect.declinedLastOffer()); ticks.add(Expect.knownTasks(result.getPersister(), "hello-0-server")); ticks.add(new ExpectDecommissionPlanProgress(Arrays.asList( new StepCount("world-1", 0, 0, stepCount), new StepCount("world-0", 0, 0, stepCount))));
ticks.add(Expect.reconciledExplicitly(result.getPersister())); 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(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(Expect.deployStepStatus("hello", "hello-0:[server]", Status.STARTING)); ticks.add(Expect.launchedTasks("hello-0-server")); ticks.add(Expect.taskEnv(result.getPersister(), "hello-0-server", "SLEEP_DURATION", newEnv)); ticks.add(Send.taskStatus("hello-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.deployStepStatus("world", "world-0:[server]", Status.STARTING)); ticks.add(Expect.launchedTasks("world-0-server")); ticks.add(Expect.taskEnv(result.getPersister(), "world-0-server", "SLEEP_DURATION", newEnv)); ticks.add(Send.taskStatus("world-0-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.launchedTasks("world-1-server")); ticks.add(Expect.taskEnv(result.getPersister(), "world-1-server", "SLEEP_DURATION", oldEnv)); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).build()); ticks.add(Expect.launchedTasks("world-1-server")); ticks.add(Expect.taskEnv(result.getPersister(), "world-1-server", "SLEEP_DURATION", newEnv)); ticks.add(Send.taskStatus("world-1-server", Protos.TaskState.TASK_RUNNING).build());