Search in sources :

Example 26 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testExistingRegionRuleUnmodified.

@Test
public void testExistingRegionRuleUnmodified() throws PersisterException {
    PlacementRule remoteRegionRule = RegionRuleFactory.getInstance().require(ExactMatcher.create(TestConstants.REMOTE_REGION));
    PlacementRule localRegionRule = new IsLocalRegionRule();
    ServiceSpec serviceSpec = DefaultServiceSpec.newBuilder(minimalServiceSpec).addPod(DefaultPodSpec.newBuilder(getPodSpec("foo")).placementRule(remoteRegionRule).build()).addPod(DefaultPodSpec.newBuilder(getPodSpec("bar")).placementRule(localRegionRule).build()).build();
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(serviceSpec, mockSchedulerConfig, new MemPersister()).withSingleRegionConstraint().build().getServiceSpec();
    // Pod without placement rules from valid-minimal.yml had a rule added:
    Assert.assertTrue(updatedServiceSpec.getPods().get(0).getPlacementRule().get() instanceof IsLocalRegionRule);
    // Pods with region placement rules were left as-is:
    Assert.assertSame(remoteRegionRule, updatedServiceSpec.getPods().get(1).getPlacementRule().get());
    Assert.assertSame(localRegionRule, updatedServiceSpec.getPods().get(2).getPlacementRule().get());
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 27 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerBuilderTest method testRegionAwarenessEnabledJavaWithSchedulerRegion.

@Test
public void testRegionAwarenessEnabledJavaWithSchedulerRegion() throws PersisterException {
    when(mockSchedulerConfig.getSchedulerRegion()).thenReturn(Optional.of(TestConstants.REMOTE_REGION));
    ServiceSpec updatedServiceSpec = DefaultScheduler.newBuilder(minimalServiceSpec, mockSchedulerConfig, new MemPersister()).withSingleRegionConstraint().build().getServiceSpec();
    Optional<PlacementRule> rule = updatedServiceSpec.getPods().get(0).getPlacementRule();
    // Pod updated with exact region rule:
    Assert.assertTrue(rule.isPresent());
    Assert.assertTrue(rule.get() instanceof RegionRule);
    // Not hit since enabled directly in java:
    verify(mockSchedulerConfig, never()).isRegionAwarenessEnabled();
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) DefaultServiceSpec(com.mesosphere.sdk.specification.DefaultServiceSpec) ServiceSpec(com.mesosphere.sdk.specification.ServiceSpec) Test(org.junit.Test)

Example 28 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchedulerRunnerTest method checkSchemaVersion.

@Test
public void checkSchemaVersion() throws Exception {
    // Set up a schema version which shouldn't work, to verify that the schema version is being checked:
    Persister persister = new MemPersister();
    persister.set("SchemaVersion", "123".getBytes(StandardCharsets.UTF_8));
    when(mockSchedulerBuilder.getPersister()).thenReturn(persister);
    when(mockSchedulerBuilder.getSchedulerConfig()).thenReturn(mockSchedulerConfig);
    when(mockSchedulerBuilder.getServiceSpec()).thenReturn(mockServiceSpec);
    SchedulerRunner runner = SchedulerRunner.fromSchedulerBuilder(mockSchedulerBuilder);
    try {
        runner.run();
        Assert.fail("Expected exception due to bad schema version");
    } catch (IllegalStateException e) {
        Assert.assertEquals("Storage schema version 123 is not supported by this software (expected: 1)", e.getMessage());
    }
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) MemPersister(com.mesosphere.sdk.storage.MemPersister) Persister(com.mesosphere.sdk.storage.Persister) Test(org.junit.Test)

Example 29 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class SchemaVersionStoreTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    MockitoAnnotations.initMocks(this);
    persister = new MemPersister();
    store = new SchemaVersionStore(persister);
    store2 = new SchemaVersionStore(persister);
    storeWithMock = new SchemaVersionStore(mockPersister);
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) Before(org.junit.Before)

Example 30 with MemPersister

use of com.mesosphere.sdk.storage.MemPersister in project dcos-commons by mesosphere.

the class StateStoreUtilsTest method beforeEach.

@Before
public void beforeEach() throws Exception {
    this.persister = new MemPersister();
    this.stateStore = new StateStore(this.persister);
}
Also used : MemPersister(com.mesosphere.sdk.storage.MemPersister) Before(org.junit.Before)

Aggregations

MemPersister (com.mesosphere.sdk.storage.MemPersister)31 Persister (com.mesosphere.sdk.storage.Persister)14 Test (org.junit.Test)13 StateStore (com.mesosphere.sdk.state.StateStore)12 Before (org.junit.Before)9 DefaultServiceSpec (com.mesosphere.sdk.specification.DefaultServiceSpec)7 ServiceSpec (com.mesosphere.sdk.specification.ServiceSpec)7 FrameworkStore (com.mesosphere.sdk.state.FrameworkStore)5 UUID (java.util.UUID)5 File (java.io.File)4 OfferOutcomeTracker (com.mesosphere.sdk.offer.history.OfferOutcomeTracker)3 Plan (com.mesosphere.sdk.scheduler.plan.Plan)3 RawServiceSpec (com.mesosphere.sdk.specification.yaml.RawServiceSpec)3 OfferAccepter (com.mesosphere.sdk.offer.OfferAccepter)2 OfferEvaluator (com.mesosphere.sdk.offer.evaluate.OfferEvaluator)2 DefaultPlan (com.mesosphere.sdk.scheduler.plan.DefaultPlan)2 ConfigStore (com.mesosphere.sdk.state.ConfigStore)2 StringConfiguration (com.mesosphere.sdk.config.StringConfiguration)1 Capabilities (com.mesosphere.sdk.dcos.Capabilities)1 TaskLabelWriter (com.mesosphere.sdk.offer.taskdata.TaskLabelWriter)1