@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()); }
/** * Configures the test with custom options as would be provided via an {@code options.json} file. If this is not * invoked then the service defaults from {@code config.json} are used for the test. * * @param optionKeyVals an even number of strings which will be unpacked as (key, value, key, value, ...), where the * keys should be in {@code section1.section2.section3.name} form as an {@code options.json} file would have * @return {@code this} */ public ServiceTestRunner setOptions(String... optionKeyVals) { return setOptions(toMap(optionKeyVals)); }
public CassandraRecoveryPlanOverriderTest() throws Exception { ServiceTestResult result = new ServiceTestRunner() .setPodEnv("node", "LOCAL_SEEDS", "foo,bar") .run(); rawSpec = result.getRawServiceSpec(); serviceSpec = result.getServiceSpec(); }
/** * Configures the test with additional environment variables in the specified Pod, beyond those which would be * included by the Scheduler or by Mesos. This may be useful for services whose tasks configure environment * variables before rendering config files via execution of {@code bootstrap}. * * @param podType the pod to set the environment against * @param podEnvKeyVals an even number of strings which will be unpacked as (key, value, key, value, ...) * @return {@code this} */ public ServiceTestRunner setPodEnv(String podType, String... podEnvKeyVals) { return setPodEnv(podType, toMap(podEnvKeyVals)); }
/** * Configures the test with custom template parameters to be applied against the Universe packaging, as would be * provided via {@code TEMPLATE_X} envvars when building the service. These are applied onto {@code config.json} * and {@code resource.json} for the test * * @param paramKeyVals an even number of strings which will be unpacked as (key, value, key, value, ...) * @return {@code this} */ public ServiceTestRunner setBuildTemplateParams(String... paramKeyVals) { return setBuildTemplateParams(toMap(paramKeyVals)); }
@Test public void testRegionAwareness() throws Exception { ServiceTestResult result = new ServiceTestRunner() .setOptions("service.region", "Europe") .setPodEnv("node", getDefaultNodeEnv()) .run(); Assert.assertEquals(result.getSchedulerEnvironment().get("SERVICE_REGION"), "Europe"); }
public void testHelloDecommissionNotAllowed() throws Exception { ServiceTestResult result = new ServiceTestRunner().run(getDefaultDeploymentTicks()); Assert.assertEquals( new TreeSet<>(Arrays.asList("hello-0-server", "world-0-server", "world-1-server")), new ServiceTestRunner() .setOptions("hello.count", "0") .setState(result) .run(ticks);
/** * Validates the default service spec. */ @Test public void testDefaultSpec() throws Exception { new ServiceTestRunner().run(); }
ticks.add(Expect.declinedLastOffer()); ServiceTestRunner runner = new ServiceTestRunner(); ServiceTestResult result = runner.run(ticks); new ServiceTestRunner().setState(result).run(ticks);
@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 public void testRegionAwareness() throws Exception { ServiceTestResult result = getDefaultRunner() .setOptions("service.region", "Europe") .run(); Assert.assertEquals(result.getSchedulerEnvironment().get("SERVICE_REGION"), "Europe"); }
File[] exampleFiles = ServiceTestRunner.getDistDir().listFiles(); Assert.assertNotNull(exampleFiles); Assert.assertTrue(exampleFiles.length != 0); for (File examplesFile : exampleFiles) { ServiceTestRunner serviceTestRunner = new ServiceTestRunner(examplesFile); Map<String, String> schedulerEnv = schedulerEnvForExamples.get(examplesFile.getName()); if (schedulerEnv != null) { serviceTestRunner.setSchedulerEnv(schedulerEnv); serviceTestRunner.run(); } catch (Exception e) { throw new Exception(String.format(
.setSchedulerEnv(placementEnvKey, originalPlacement) .run(); .setSchedulerEnv(placementEnvKey, newPlacement) .addCustomValidator(configValidator) .setState(result) .run(ticks);
return new ServiceTestRunner() .setPodEnv( "master", "CLUSTER_NAME", "cluster-foo", "CUSTOM_YAML_BLOCK", "some.thing=true", "ZONE", "us-east-1a") .setPodEnv( "data", "CLUSTER_NAME", "cluster-foo", "CUSTOM_YAML_BLOCK", "some.thing=true", "ZONE", "us-east-1a") .setPodEnv( "ingest", "CLUSTER_NAME", "cluster-foo", "CUSTOM_YAML_BLOCK", "some.thing=true", "ZONE", "us-east-1a") .setPodEnv( "coordinator", "CLUSTER_NAME", "cluster-foo", "CUSTOM_YAML_BLOCK", "some.thing=true", "ZONE", "us-east-1a") .setBuildTemplateParams( "elastic-version", "1.2.3", "elastic-statsd-version", "1.2.3.0", // NOPMD
private ServiceTestRunner getDefaultRunner() throws Exception { // Our Main.java only defines SERVICE_ZK_ROOT in our name nodes. // However, the test utilities are strict about missing template params so we set something for all pods: return new ServiceTestRunner() .setPodEnv("journal", "SERVICE_ZK_ROOT", "") .setPodEnv("data", "SERVICE_ZK_ROOT", "") .setPodEnv("name", "SERVICE_ZK_ROOT", "/path/to/zk"); } }
ticks.add(Expect.allPlansComplete()); ServiceTestRunner runner = new ServiceTestRunner(); if (overrider.isPresent()) { runner.setRecoveryManagerFactory(overrider.get()); runner.run(ticks);
/** * Exercises the service's packaging and resulting Service Specification YAML file without running any simulation * afterwards. * * @return a {@link ServiceTestResult} containing the resulting scheduler environment and spec information * @throws Exception if the test failed */ public ServiceTestResult run() throws Exception { return run(Collections.emptyList()); }
/** * 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; }
/** * Creates a new instance against the provided Service Specification YAML filename within the service's * {@code src/main/dist} directory. * * <p>WARNING: If you do not invoke the {@link #run()} method, your test will not run! * * @param specDistFilename path to the Service Specification YAML file, relative to the {@code src/main/dist} * directory */ public ServiceTestRunner(String specDistFilename) { this(getDistFile(specDistFilename)); }
/** * Returns a {@link File} object for a provided filename or relative path within the service's {@code src/main/dist} * directory. Does not check if the specified path actually exists. */ public static File getDistFile(String specFilePath) { return new File(getDistDir(), specFilePath); }