use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.
the class DefaultPlanGeneratorTest method testCustomPhases.
@Test
public void testCustomPhases() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("custom-phases.yml").getFile());
RawServiceSpec rawServiceSpec = RawServiceSpec.newBuilder(file).build();
DefaultServiceSpec serviceSpec = DefaultServiceSpec.newGenerator(rawServiceSpec, SCHEDULER_CONFIG, file.getParentFile()).build();
Persister persister = new MemPersister();
stateStore = new StateStore(persister);
configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
Assert.assertNotNull(serviceSpec);
DefaultPlanGenerator generator = new DefaultPlanGenerator(configStore, stateStore);
for (Map.Entry<String, RawPlan> entry : rawServiceSpec.getPlans().entrySet()) {
Plan plan = generator.generate(entry.getValue(), entry.getKey(), serviceSpec.getPods());
Assert.assertNotNull(plan);
Assert.assertEquals(6, plan.getChildren().size());
Phase serverPhase = plan.getChildren().get(0);
Phase oncePhase = plan.getChildren().get(1);
Phase interleavePhase = plan.getChildren().get(2);
Phase fullCustomPhase = plan.getChildren().get(3);
Phase partialCustomPhase = plan.getChildren().get(4);
Phase omitStepPhase = plan.getChildren().get(5);
validatePhase(serverPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("server")));
validatePhase(oncePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("once")));
validatePhase(interleavePhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
validatePhase(fullCustomPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("server")));
validatePhase(partialCustomPhase, Arrays.asList(Arrays.asList("server"), Arrays.asList("once"), Arrays.asList("once"), Arrays.asList("server"), Arrays.asList("server"), Arrays.asList("once")));
validatePhase(omitStepPhase, Arrays.asList(Arrays.asList("once"), Arrays.asList("server")));
Assert.assertEquals("hello-1:[once]", omitStepPhase.getChildren().get(0).getName());
Assert.assertEquals("hello-1:[server]", omitStepPhase.getChildren().get(1).getName());
}
}
use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.
the class DefaultServiceSpecTest method invalidPlanSteps.
@Test(expected = IllegalStateException.class)
public void invalidPlanSteps() throws Exception {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("invalid-plan-steps.yml").getFile());
RawServiceSpec rawSpec = RawServiceSpec.newBuilder(file).build();
DefaultScheduler.newBuilder(DefaultServiceSpec.newGenerator(rawSpec, SCHEDULER_CONFIG, file.getParentFile()).build(), SCHEDULER_CONFIG, new MemPersister()).setPlansFrom(rawSpec).build();
}
use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.
the class SchedulerBuilderTest method testRegionAwarenessDisabledWithSchedulerRegion.
@Test
public void testRegionAwarenessDisabledWithSchedulerRegion() throws PersisterException {
when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of(TestConstants.REMOTE_REGION));
ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
// Pod updated with local region rule:
Assert.assertTrue(rule.isPresent());
Assert.assertTrue(rule.get() instanceof IsLocalRegionRule);
}
use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.
the class SchedulerBuilderTest method testDomainsNotSupportedByCluster.
@Test
public void testDomainsNotSupportedByCluster() throws Exception {
when(mockCapabilities.supportsDomains()).thenReturn(false);
ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
// No rule changes:
Assert.assertFalse(updatedServiceSpec.getPods().get(0).getPlacementRule().isPresent());
// Not hit since unsupported by cluster:
verify(mockCapabilities, atLeastOnce()).supportsDomains();
verify(mockSchedulerConfig, never()).isRegionAwarenessEnabled();
verify(mockSchedulerConfig, never()).getSchedulerRegion();
}
use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.
the class SchedulerBuilderTest method testRegionAwarenessDisabledWithoutSchedulerRegion.
@Test
public void testRegionAwarenessDisabledWithoutSchedulerRegion() throws PersisterException {
ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).build().getServiceSpec();
Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
// Pod updated with local region rule:
Assert.assertTrue(rule.isPresent());
Assert.assertTrue(rule.get() instanceof IsLocalRegionRule);
}
Aggregations