use of com.spotify.helios.servicescommon.coordination.Delete in project helios by spotify.
the class RollingUpdateOpFactoryTest method testStartManualNoHostsTasksAlreadyExist.
@Test
public void testStartManualNoHostsTasksAlreadyExist() throws Exception {
// Create a DeploymentGroupTasks object with no rolloutTasks (defaults to empty list).
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final ZooKeeperClient client = mock(ZooKeeperClient.class);
when(client.exists(anyString())).thenReturn(mock(Stat.class));
final RollingUpdateOp op = opFactory.start(MANUAL_DEPLOYMENT_GROUP, client);
// Two ZK operations should return:
// * delete the tasks
// * set the status to DONE
assertEquals(ImmutableSet.of(new Delete("/status/deployment-group-tasks/my_group"), new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
// Two events should return: rollingUpdateStarted and rollingUpdateDone
assertEquals(2, op.events().size());
verify(eventFactory).rollingUpdateStarted(MANUAL_DEPLOYMENT_GROUP);
verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP);
}
use of com.spotify.helios.servicescommon.coordination.Delete in project helios by spotify.
the class RollingUpdateOpFactoryTest method testStartManualNoHosts.
@Test
public void testStartManualNoHosts() throws Exception {
// Create a DeploymentGroupTasks object with no rolloutTasks (defaults to empty list).
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final ZooKeeperClient client = mock(ZooKeeperClient.class);
when(client.exists(anyString())).thenReturn(null);
final RollingUpdateOp op = opFactory.start(MANUAL_DEPLOYMENT_GROUP, client);
// Three ZK operations should return:
// * create tasks node
// * delete the tasks
// * set the status to DONE
assertEquals(ImmutableSet.of(new CreateEmpty("/status/deployment-group-tasks/my_group"), new Delete("/status/deployment-group-tasks/my_group"), new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes())), ImmutableSet.copyOf(op.operations()));
// Two events should return: rollingUpdateStarted and rollingUpdateDone
assertEquals(2, op.events().size());
verify(eventFactory).rollingUpdateStarted(MANUAL_DEPLOYMENT_GROUP);
verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP);
}
use of com.spotify.helios.servicescommon.coordination.Delete in project helios by spotify.
the class RollingUpdateOpFactoryTest method testTransitionToDone.
@Test
public void testTransitionToDone() {
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(2).setRolloutTasks(Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"))).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final RollingUpdateOp op = opFactory.nextTask();
// When state -> DONE we expected
// * deployment group tasks are deleted
// * deployment group status is updated (to DONE)
assertEquals(ImmutableSet.of(new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.DONE).setError(null).build().toJsonBytes()), new Delete("/status/deployment-group-tasks/my_group")), ImmutableSet.copyOf(op.operations()));
// ...and that an event is emitted
assertEquals(1, op.events().size());
verify(eventFactory).rollingUpdateDone(MANUAL_DEPLOYMENT_GROUP);
}
use of com.spotify.helios.servicescommon.coordination.Delete in project helios by spotify.
the class RollingUpdateOpFactoryTest method testTransitionToFailed.
@Test
public void testTransitionToFailed() {
final DeploymentGroupTasks deploymentGroupTasks = DeploymentGroupTasks.newBuilder().setTaskIndex(0).setRolloutTasks(Lists.newArrayList(RolloutTask.of(RolloutTask.Action.UNDEPLOY_OLD_JOBS, "host1"), RolloutTask.of(RolloutTask.Action.AWAIT_RUNNING, "host1"), RolloutTask.of(RolloutTask.Action.DEPLOY_NEW_JOB, "host1"))).setDeploymentGroup(MANUAL_DEPLOYMENT_GROUP).build();
final RollingUpdateOpFactory opFactory = new RollingUpdateOpFactory(deploymentGroupTasks, eventFactory);
final RollingUpdateOp op = opFactory.error("foo", "host1", RollingUpdateError.HOST_NOT_FOUND);
final Map<String, Object> failEvent = Maps.newHashMap();
when(eventFactory.rollingUpdateTaskFailed(any(DeploymentGroup.class), any(RolloutTask.class), anyString(), any(RollingUpdateError.class))).thenReturn(failEvent);
// When state -> FAILED we expected
// * deployment group tasks are deleted
// * deployment group status is updated (to FAILED)
assertEquals(ImmutableSet.of(new SetData("/status/deployment-groups/my_group", DeploymentGroupStatus.newBuilder().setState(DeploymentGroupStatus.State.FAILED).setError("host1: foo").build().toJsonBytes()), new Delete("/status/deployment-group-tasks/my_group")), ImmutableSet.copyOf(op.operations()));
// ...and that a failed-task event and a rolling-update failed event are emitted
assertEquals(2, op.events().size());
verify(eventFactory).rollingUpdateTaskFailed(eq(MANUAL_DEPLOYMENT_GROUP), eq(deploymentGroupTasks.getRolloutTasks().get(deploymentGroupTasks.getTaskIndex())), anyString(), eq(RollingUpdateError.HOST_NOT_FOUND), eq(Collections.<String, Object>emptyMap()));
verify(eventFactory).rollingUpdateFailed(eq(MANUAL_DEPLOYMENT_GROUP), eq(failEvent));
}
Aggregations