/** * 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; }
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()); } } } }