use of org.joda.time.Instant in project cassandra-mesos-deprecated by mesosphere.
the class HealthReportServiceTest method terminatedSeed_clusterUnhealthy.
@Test
public void terminatedSeed_clusterUnhealthy() throws Exception {
final int numberOfNodes = 3;
final int numberOfSeeds = 2;
final Instant now = Instant.now();
final Long healthCheckExpiration = now.minus(Duration.standardMinutes(5)).getMillis();
final CassandraClusterState.Builder clusterState = CassandraClusterState.newBuilder().addNodes(CassandraNode.newBuilder().setHostname("host1").setSeed(false).setTargetRunState(CassandraNode.TargetRunState.TERMINATE)).addNodes(CassandraNode.newBuilder().setHostname("host2").setSeed(true).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec2").setSource("source").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.METADATA).setTaskId("host2-metadata").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.SERVER).setTaskId("host2-server").setResources(TaskResources.getDefaultInstance()))).addNodes(CassandraNode.newBuilder().setHostname("host3").setSeed(false).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec3").setSource("source").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.METADATA).setTaskId("host3-metadata").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.SERVER).setTaskId("host3-server").setResources(TaskResources.getDefaultInstance())));
final CassandraFrameworkConfiguration.Builder config = CassandraFrameworkConfiguration.newBuilder().setFrameworkName("cassandra.testing").setHealthCheckIntervalSeconds(60).setBootstrapGraceTimeSeconds(120).setTargetNumberOfNodes(numberOfNodes).setTargetNumberOfSeeds(numberOfSeeds);
final CassandraClusterHealthCheckHistory.Builder healthCheckHistory = CassandraClusterHealthCheckHistory.newBuilder().setMaxEntriesPerNode(5).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec1").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec2").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration + 1).setExecutorId("exec3").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL"))));
when(clock.now()).thenReturn(now);
final ClusterHealthReport report = getClusterHealthReport(clock, new ClusterHealthEvaluationContext(clusterState.build(), config.build(), healthCheckHistory.build()));
assertThat(report.isHealthy()).isFalse();
final ListMultimap<String, ClusterHealthEvaluationResult<?>> index = from(report.getResults()).index(new Function<ClusterHealthEvaluationResult<?>, String>() {
@Override
public String apply(final ClusterHealthEvaluationResult<?> input) {
return input.getName();
}
});
final ClusterHealthEvaluationResult<?> nodeCount = index.get("nodeCount").get(0);
assertThat(nodeCount.getExpected()).isEqualTo(3);
assertThat(nodeCount.getActual()).isEqualTo(2);
assertThat(nodeCount.isOk()).isFalse();
final ClusterHealthEvaluationResult<?> seedCount = index.get("seedCount").get(0);
assertThat(seedCount.getExpected()).isEqualTo(2);
assertThat(seedCount.getActual()).isEqualTo(1);
assertThat(seedCount.isOk()).isFalse();
}
use of org.joda.time.Instant in project cassandra-mesos-deprecated by mesosphere.
the class HealthReportServiceTest method terminatedNodeReplaced_clusterHealthy.
@Test
public void terminatedNodeReplaced_clusterHealthy() throws Exception {
final int numberOfNodes = 3;
final int numberOfSeeds = 2;
final Instant now = Instant.now();
final Long healthCheckExpiration = now.minus(Duration.standardMinutes(5)).getMillis();
final CassandraClusterState.Builder clusterState = CassandraClusterState.newBuilder().addNodes(CassandraNode.newBuilder().setHostname("host1").setSeed(false).setTargetRunState(CassandraNode.TargetRunState.TERMINATE)).addNodes(CassandraNode.newBuilder().setHostname("host2").setSeed(true).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec2").setSource("source").setResources(TaskResources.getDefaultInstance())).setTargetRunState(CassandraNode.TargetRunState.RUN).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.METADATA).setTaskId("host2-metadata").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.SERVER).setTaskId("host2-server").setResources(TaskResources.getDefaultInstance()))).addNodes(CassandraNode.newBuilder().setHostname("host3").setSeed(false).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec3").setSource("source").setResources(TaskResources.getDefaultInstance())).setTargetRunState(CassandraNode.TargetRunState.RUN).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.METADATA).setTaskId("host3-metadata").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.SERVER).setTaskId("host3-server").setResources(TaskResources.getDefaultInstance()))).addNodes(CassandraNode.newBuilder().setHostname("host4").setSeed(true).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec4").setSource("source").setResources(TaskResources.getDefaultInstance())).setTargetRunState(CassandraNode.TargetRunState.RUN).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.METADATA).setTaskId("host4-metadata").setResources(TaskResources.getDefaultInstance())).addTasks(CassandraNodeTask.newBuilder().setType(CassandraNodeTask.NodeTaskType.SERVER).setTaskId("host4-server").setResources(TaskResources.getDefaultInstance()))).addNodes(CassandraNode.newBuilder().setHostname("host5").setSeed(false).setTargetRunState(CassandraNode.TargetRunState.TERMINATE).setCassandraNodeExecutor(CassandraNodeExecutor.newBuilder().setExecutorId("exec5").setSource("source").setResources(TaskResources.getDefaultInstance())));
final CassandraFrameworkConfiguration.Builder config = CassandraFrameworkConfiguration.newBuilder().setFrameworkName("cassandra.testing").setHealthCheckIntervalSeconds(60).setBootstrapGraceTimeSeconds(120).setTargetNumberOfNodes(numberOfNodes).setTargetNumberOfSeeds(numberOfSeeds);
final CassandraClusterHealthCheckHistory.Builder healthCheckHistory = CassandraClusterHealthCheckHistory.newBuilder().setMaxEntriesPerNode(5).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec1").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec2").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec3").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec4").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL")))).addEntries(HealthCheckHistoryEntry.newBuilder().setTimestampStart(1).setTimestampEnd(healthCheckExpiration).setExecutorId("exec5").setDetails(HealthCheckDetails.newBuilder().setHealthy(true).setInfo(NodeInfo.newBuilder().setOperationMode("NORMAL"))));
when(clock.now()).thenReturn(now);
final ClusterHealthReport report = getClusterHealthReport(clock, new ClusterHealthEvaluationContext(clusterState.build(), config.build(), healthCheckHistory.build()));
final ListMultimap<String, ClusterHealthEvaluationResult<?>> index = from(report.getResults()).index(new Function<ClusterHealthEvaluationResult<?>, String>() {
@Override
public String apply(final ClusterHealthEvaluationResult<?> input) {
return input.getName();
}
});
final ClusterHealthEvaluationResult<?> nodeCount = index.get("nodeCount").get(0);
assertThat(nodeCount.getExpected()).isEqualTo(3);
assertThat(nodeCount.getActual()).isEqualTo(3);
assertThat(nodeCount.isOk()).isTrue();
final ClusterHealthEvaluationResult<?> seedCount = index.get("seedCount").get(0);
assertThat(seedCount.getExpected()).isEqualTo(2);
assertThat(seedCount.getActual()).isEqualTo(2);
assertThat(seedCount.isOk()).isTrue();
final ClusterHealthEvaluationResult<?> allHealthy = index.get("allHealthy").get(0);
assertThat(allHealthy.getExpected()).isEqualTo(newArrayList(true, true, true));
assertThat(allHealthy.getActual()).isEqualTo(newArrayList(true, true, true));
assertThat(allHealthy.isOk()).isTrue();
final ClusterHealthEvaluationResult<?> operatingModeNormal = index.get("operatingModeNormal").get(0);
assertThat(operatingModeNormal.getExpected()).isEqualTo(newArrayList(normal(), normal(), normal()));
assertThat(operatingModeNormal.getActual()).isEqualTo(newArrayList(normal(), normal(), normal()));
assertThat(operatingModeNormal.isOk()).isTrue();
final ClusterHealthEvaluationResult<?> lastHealthCheckNewerThan = index.get("lastHealthCheckNewerThan").get(0);
assertThat(lastHealthCheckNewerThan.getExpected()).isEqualTo(newArrayList(healthCheckExpiration, healthCheckExpiration, healthCheckExpiration));
assertThat(lastHealthCheckNewerThan.getActual()).isEqualTo(newArrayList(healthCheckExpiration, healthCheckExpiration, healthCheckExpiration));
assertThat(lastHealthCheckNewerThan.isOk()).isTrue();
assertThat(report.isHealthy()).isTrue();
}
use of org.joda.time.Instant in project helios by spotify.
the class RetryingRequestDispatcherTest method testSuccessOnRetry.
@Test
public void testSuccessOnRetry() throws Exception {
when(delegate.request(any(URI.class), anyString(), any(byte[].class), Matchers.<Map<String, List<String>>>any())).thenReturn(Futures.<Response>immediateFailedFuture(new IOException())).thenReturn(Futures.<Response>immediateFuture(null));
when(clock.now()).thenReturn(new Instant(0));
dispatcher.request(new URI("http://example.com"), "GET", null, Collections.<String, List<String>>emptyMap());
// Verify the delegate was called twice if it returns successfully on the second try before the
// deadline
verify(delegate, times(2)).request(any(URI.class), anyString(), any(byte[].class), Matchers.<Map<String, List<String>>>any());
}
use of org.joda.time.Instant in project helios by spotify.
the class ExpiredJobReaperTest method testExpiredJobReaper.
@Test
public void testExpiredJobReaper() throws Exception {
when(mockClock.now()).thenReturn(new Instant(CURRENT_TS));
when(masterModel.getJobs()).thenReturn(JOBS);
when(masterModel.getJobStatus(any(JobId.class))).then(new Answer<JobStatus>() {
@Override
public JobStatus answer(final InvocationOnMock invocation) throws Throwable {
final JobId jobId = (JobId) invocation.getArguments()[0];
final Map<String, Deployment> deployments = ImmutableMap.of("hostA", Deployment.of(jobId, Goal.START), "hostB", Deployment.of(jobId, Goal.START));
return JobStatus.newBuilder().setJob(JOBS.get(jobId)).setDeployments(deployments).build();
}
});
ExpiredJobReaper.newBuilder().setClock(mockClock).setMasterModel(masterModel).build().runOneIteration();
// Make sure that the expiring job was removed, but that the non-expiring job
// and the job that expires far in the future were not.
verify(masterModel).undeployJob(eq("hostA"), eq(EXPIRING_JOB_ID), eq(""));
verify(masterModel).undeployJob(eq("hostB"), eq(EXPIRING_JOB_ID), eq(""));
verify(masterModel).removeJob(eq(EXPIRING_JOB_ID), eq(""));
verifyNoMoreInteractions(ignoreStubs(masterModel));
}
use of org.joda.time.Instant in project joda-time by JodaOrg.
the class TestGJChronology method testFactory_Zone_RI.
public void testFactory_Zone_RI() {
GJChronology chrono = GJChronology.getInstance(TOKYO, new Instant(0L));
assertEquals(TOKYO, chrono.getZone());
assertEquals(new Instant(0L), chrono.getGregorianCutover());
assertSame(GJChronology.class, GJChronology.getInstance(TOKYO, new Instant(0L)).getClass());
DateTime cutover = new DateTime(1582, 10, 15, 0, 0, 0, 0, DateTimeZone.UTC);
chrono = GJChronology.getInstance(TOKYO, null);
assertEquals(TOKYO, chrono.getZone());
assertEquals(cutover.toInstant(), chrono.getGregorianCutover());
}
Aggregations