Search in sources :

Example 6 with Instant

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();
}
Also used : Instant(org.joda.time.Instant) HealthReportService.getClusterHealthReport(io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService.getClusterHealthReport) Test(org.junit.Test)

Example 7 with Instant

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();
}
Also used : Instant(org.joda.time.Instant) HealthReportService.getClusterHealthReport(io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService.getClusterHealthReport) Test(org.junit.Test)

Example 8 with Instant

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());
}
Also used : Instant(org.joda.time.Instant) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IOException(java.io.IOException) Map(java.util.Map) URI(java.net.URI) Test(org.junit.Test)

Example 9 with Instant

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));
}
Also used : JobStatus(com.spotify.helios.common.descriptors.JobStatus) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Instant(org.joda.time.Instant) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) JobId(com.spotify.helios.common.descriptors.JobId) Test(org.junit.Test)

Example 10 with Instant

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());
}
Also used : Instant(org.joda.time.Instant) DateTime(org.joda.time.DateTime)

Aggregations

Instant (org.joda.time.Instant)410 Test (org.junit.Test)326 IntervalWindow (org.apache.beam.sdk.transforms.windowing.IntervalWindow)135 KV (org.apache.beam.sdk.values.KV)64 Category (org.junit.experimental.categories.Category)60 WindowedValue (org.apache.beam.sdk.util.WindowedValue)47 Duration (org.joda.time.Duration)44 ReadableInstant (org.joda.time.ReadableInstant)36 BoundedWindow (org.apache.beam.sdk.transforms.windowing.BoundedWindow)30 WatermarkHoldState (org.apache.beam.sdk.state.WatermarkHoldState)24 TimerData (org.apache.beam.runners.core.TimerInternals.TimerData)22 Matchers.emptyIterable (org.hamcrest.Matchers.emptyIterable)22 HashMap (java.util.HashMap)19 TransformWatermarks (org.apache.beam.runners.direct.WatermarkManager.TransformWatermarks)18 StateNamespaceForTest (org.apache.beam.runners.core.StateNamespaceForTest)17 WindowMatchers.isSingleWindowedValue (org.apache.beam.runners.core.WindowMatchers.isSingleWindowedValue)17 WindowMatchers.isWindowedValue (org.apache.beam.runners.core.WindowMatchers.isWindowedValue)17 TupleTag (org.apache.beam.sdk.values.TupleTag)14 ArrayList (java.util.ArrayList)13 Map (java.util.Map)12