use of com.mesosphere.sdk.state.StateStore in project dcos-commons by mesosphere.
the class DefaultStepFactoryTest method getPodInstanceWithGoalState.
private PodInstance getPodInstanceWithGoalState(GoalState goalState) throws Exception {
TaskSpec taskSpec = TestPodFactory.getTaskSpecWithGoalState(TestConstants.TASK_NAME, TestConstants.RESOURCE_SET_ID, goalState);
PodSpec podSpec = DefaultPodSpec.newBuilder(SCHEDULER_CONFIG.getExecutorURI()).type(TestConstants.POD_TYPE).count(1).tasks(Arrays.asList(taskSpec)).build();
ServiceSpec serviceSpec = DefaultServiceSpec.newBuilder().name(TestConstants.SERVICE_NAME).role(TestConstants.ROLE).principal(TestConstants.PRINCIPAL).zookeeperConnection("foo.bar.com").pods(Arrays.asList(podSpec)).build();
Persister persister = new MemPersister();
stateStore = new StateStore(persister);
configStore = new ConfigStore<>(DefaultServiceSpec.getConfigurationFactory(serviceSpec), persister);
UUID configId = configStore.store(serviceSpec);
configStore.setTargetConfig(configId);
stepFactory = new DefaultStepFactory(configStore, stateStore);
return new DefaultPodInstance(podSpec, 0);
}
use of com.mesosphere.sdk.state.StateStore in project dcos-commons by mesosphere.
the class Expect method knownTasks.
/**
* Verifies that the scheduler's list of tasks in the state store matches the provided set.
*/
public static Expect knownTasks(Persister persisterWithTasks, String... taskNames) {
return new Expect() {
@Override
public void expect(ClusterState state, SchedulerDriver mockDriver) {
Set<String> expectedTasks = new HashSet<>(Arrays.asList(taskNames));
Set<String> tasks = new StateStore(persisterWithTasks).fetchTasks().stream().map(Protos.TaskInfo::getName).collect(Collectors.toSet());
Assert.assertEquals(expectedTasks, tasks);
}
@Override
public String getDescription() {
return String.format("State store task names: %s", new StateStore(persisterWithTasks).fetchTasks().stream().map(Protos.TaskInfo::getName).collect(Collectors.toList()));
}
};
}
use of com.mesosphere.sdk.state.StateStore in project dcos-commons by mesosphere.
the class Expect method reconciledExplicitly.
/**
* Verifies that an explicit task reconciliation for the task statuses in the provided persister was invoked.
*/
public static Expect reconciledExplicitly(Persister persisterWithStatuses) {
// Use a custom comparator for sorting: Protos don't implement Comparable
final Comparator<Protos.TaskStatus> statusComparator = new Comparator<Protos.TaskStatus>() {
@Override
public int compare(TaskStatus o1, TaskStatus o2) {
return o1.getTaskId().getValue().compareTo(o2.getTaskId().getValue());
}
};
return new Expect() {
// Use this form instead of using ArgumentCaptor.forClass() to avoid problems with typecasting generics:
@Captor
private ArgumentCaptor<Collection<Protos.TaskStatus>> statusCaptor;
@Override
public void expect(ClusterState state, SchedulerDriver mockDriver) {
MockitoAnnotations.initMocks(this);
verify(mockDriver, atLeastOnce()).reconcileTasks(statusCaptor.capture());
Set<Protos.TaskStatus> expected = new TreeSet<>(statusComparator);
expected.addAll(new StateStore(persisterWithStatuses).fetchStatuses());
// We do this arg ourselves, since the in-mock comparison never matches.
for (Collection<Protos.TaskStatus> reconcileArgs : statusCaptor.getAllValues()) {
Set<Protos.TaskStatus> got = new TreeSet<>(statusComparator);
got.addAll(reconcileArgs);
if (expected.equals(got)) {
// Found matching call
return;
}
}
Assert.fail(String.format("Expected a task reconcile with arguments: %s, but actual calls were: %s", expected, statusCaptor.getAllValues()));
}
@Override
public String getDescription() {
return String.format("Explicit task reconcile call for statuses: %s", new StateStore(persisterWithStatuses).fetchStatuses().stream().map(status -> String.format("%s=%s", status.getTaskId().getValue(), status.getState())).collect(Collectors.toList()));
}
};
}
use of com.mesosphere.sdk.state.StateStore in project dcos-commons by mesosphere.
the class OfferEvaluatorTestBase method beforeEach.
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
Persister persister = new MemPersister();
frameworkStore = new FrameworkStore(persister);
frameworkStore.storeFrameworkId(Protos.FrameworkID.newBuilder().setValue("framework-id").build());
stateStore = new StateStore(persister);
targetConfig = UUID.randomUUID();
evaluator = new OfferEvaluator(frameworkStore, stateStore, new OfferOutcomeTracker(), TestConstants.SERVICE_NAME, targetConfig, ArtifactResource.getUrlFactory(TestConstants.SERVICE_NAME), SCHEDULER_CONFIG, Optional.empty(), true);
}
use of com.mesosphere.sdk.state.StateStore in project dcos-commons by mesosphere.
the class UninstallSchedulerTest method beforeEach.
@Before
public void beforeEach() throws Exception {
MockitoAnnotations.initMocks(this);
Persister persister = new MemPersister();
frameworkStore = new FrameworkStore(persister);
frameworkStore.storeFrameworkId(TestConstants.FRAMEWORK_ID);
stateStore = new StateStore(persister);
stateStore.storeTasks(Collections.singletonList(TASK_A));
// Have the mock plan customizer default to returning the plan unchanged.
when(mockPlanCustomizer.updateUninstallPlan(any())).thenAnswer(invocation -> invocation.getArguments()[0]);
}
Aggregations