Search in sources :

Example 1 with Instant

use of org.joda.time.Instant in project joda-time-android by dlew.

the class TestDateTimeZone method testGetOffsetFixed_RI.

public void testGetOffsetFixed_RI() {
    DateTimeZone zone = DateTimeZone.forID("+01:00");
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_SUMMER)));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_WINTER)));
    assertEquals(zone.getOffset(DateTimeUtils.currentTimeMillis()), zone.getOffset(null));
}
Also used : Instant(org.joda.time.Instant) DateTimeZone(org.joda.time.DateTimeZone)

Example 2 with Instant

use of org.joda.time.Instant in project joda-time-android by dlew.

the class TestDateTimeZone method testGetOffset_RI.

public void testGetOffset_RI() {
    DateTimeZone zone = DateTimeZone.forID("Europe/Paris");
    assertEquals(2L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_SUMMER)));
    assertEquals(1L * DateTimeConstants.MILLIS_PER_HOUR, zone.getOffset(new Instant(TEST_TIME_WINTER)));
    assertEquals(zone.getOffset(DateTimeUtils.currentTimeMillis()), zone.getOffset(null));
}
Also used : Instant(org.joda.time.Instant) DateTimeZone(org.joda.time.DateTimeZone)

Example 3 with Instant

use of org.joda.time.Instant in project elasticsearch by elastic.

the class ExtendedBoundsTests method unparsed.

/**
     * Convert an extended bounds in parsed for into one in unparsed form.
     */
public static ExtendedBounds unparsed(ExtendedBounds template) {
    // It'd probably be better to randomize the formatter
    FormatDateTimeFormatter formatter = Joda.forPattern("dateOptionalTime");
    String minAsStr = template.getMin() == null ? null : formatter.printer().print(new Instant(template.getMin()));
    String maxAsStr = template.getMax() == null ? null : formatter.printer().print(new Instant(template.getMax()));
    return new ExtendedBounds(minAsStr, maxAsStr);
}
Also used : FormatDateTimeFormatter(org.elasticsearch.common.joda.FormatDateTimeFormatter) Instant(org.joda.time.Instant)

Example 4 with Instant

use of org.joda.time.Instant in project elasticsearch by elastic.

the class BaseXContentTestCase method testReadableInstant.

public void testReadableInstant() throws Exception {
    assertResult("{'instant':null}", () -> builder().startObject().field("instant", (ReadableInstant) null).endObject());
    assertResult("{'instant':null}", () -> builder().startObject().field("instant").value((ReadableInstant) null).endObject());
    final DateTime t1 = new DateTime(2016, 1, 1, 0, 0, DateTimeZone.UTC);
    String expected = "{'t1':'2016-01-01T00:00:00.000Z'}";
    assertResult(expected, () -> builder().startObject().field("t1", t1).endObject());
    assertResult(expected, () -> builder().startObject().field("t1").value(t1).endObject());
    final DateTime t2 = new DateTime(2016, 12, 25, 7, 59, 42, 213, DateTimeZone.UTC);
    expected = "{'t2':'2016-12-25T07:59:42.213Z'}";
    assertResult(expected, () -> builder().startObject().field("t2", t2).endObject());
    assertResult(expected, () -> builder().startObject().field("t2").value(t2).endObject());
    final DateTimeFormatter formatter = randomFrom(ISODateTimeFormat.basicDate(), ISODateTimeFormat.dateTimeNoMillis());
    final DateTime t3 = DateTime.now();
    expected = "{'t3':'" + formatter.print(t3) + "'}";
    assertResult(expected, () -> builder().startObject().field("t3", t3, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t3").value(t3, formatter).endObject());
    final DateTime t4 = new DateTime(randomDateTimeZone());
    expected = "{'t4':'" + formatter.print(t4) + "'}";
    assertResult(expected, () -> builder().startObject().field("t4", t4, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t4").value(t4, formatter).endObject());
    // 1970-01-01T00:00:00Z - 2033-05-18T05:33:20.000+02:00
    long date = Math.abs(randomLong() % (2 * (long) 10e11));
    final DateTime t5 = new DateTime(date, randomDateTimeZone());
    expected = "{'t5':'" + XContentBuilder.DEFAULT_DATE_PRINTER.print(t5) + "'}";
    assertResult(expected, () -> builder().startObject().field("t5", t5).endObject());
    assertResult(expected, () -> builder().startObject().field("t5").value(t5).endObject());
    expected = "{'t5':'" + formatter.print(t5) + "'}";
    assertResult(expected, () -> builder().startObject().field("t5", t5, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("t5").value(t5, formatter).endObject());
    // 2016-01-01T00:00:00.000Z
    Instant i1 = new Instant(1451606400000L);
    expected = "{'i1':'2016-01-01T00:00:00.000Z'}";
    assertResult(expected, () -> builder().startObject().field("i1", i1).endObject());
    assertResult(expected, () -> builder().startObject().field("i1").value(i1).endObject());
    // 2016-12-25T07:59:42.213Z
    Instant i2 = new Instant(1482652782213L);
    expected = "{'i2':'" + formatter.print(i2) + "'}";
    assertResult(expected, () -> builder().startObject().field("i2", i2, formatter).endObject());
    assertResult(expected, () -> builder().startObject().field("i2").value(i2, formatter).endObject());
    expectNonNullFormatterException(() -> builder().startObject().field("t3", t3, null).endObject());
    expectNonNullFormatterException(() -> builder().startObject().field("t3").value(t3, null).endObject());
}
Also used : ReadableInstant(org.joda.time.ReadableInstant) Instant(org.joda.time.Instant) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime)

Example 5 with Instant

use of org.joda.time.Instant in project cassandra-mesos-deprecated by mesosphere.

the class HealthReportServiceTest method brandNewClusterIsUnhealthy.

@Test
public void brandNewClusterIsUnhealthy() throws Exception {
    final int numberOfNodes = 3;
    final int numberOfSeeds = 1;
    final CassandraClusterState.Builder clusterState = CassandraClusterState.newBuilder();
    final CassandraFrameworkConfiguration.Builder config = CassandraFrameworkConfiguration.newBuilder().setFrameworkName("cassandra.testing").setTargetNumberOfNodes(numberOfNodes).setTargetNumberOfSeeds(numberOfSeeds);
    final CassandraClusterHealthCheckHistory.Builder healthCheckHistory = CassandraClusterHealthCheckHistory.newBuilder().setMaxEntriesPerNode(5);
    final Instant now = Instant.now();
    final Long healthCheckExpiration = now.minus(Duration.standardMinutes(5)).getMillis();
    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(0);
    assertThat(nodeCount.isOk()).isFalse();
    final ClusterHealthEvaluationResult<?> seedCount = index.get("seedCount").get(0);
    assertThat(seedCount.getExpected()).isEqualTo(1);
    assertThat(seedCount.getActual()).isEqualTo(0);
    assertThat(seedCount.isOk()).isFalse();
    final ClusterHealthEvaluationResult<?> allHealthy = index.get("allHealthy").get(0);
    assertThat(allHealthy.getExpected()).isEqualTo(newArrayList(true, true, true));
    assertThat(allHealthy.getActual()).isEqualTo(newArrayList());
    assertThat(allHealthy.isOk()).isFalse();
    final ClusterHealthEvaluationResult<?> operatingModeNormal = index.get("operatingModeNormal").get(0);
    assertThat(operatingModeNormal.getExpected()).isEqualTo(newArrayList(normal(), normal(), normal()));
    assertThat(operatingModeNormal.getActual()).isEqualTo(newArrayList());
    assertThat(operatingModeNormal.isOk()).isFalse();
    final ClusterHealthEvaluationResult<?> lastHealthCheckNewerThan = index.get("lastHealthCheckNewerThan").get(0);
    assertThat(lastHealthCheckNewerThan.getExpected()).isEqualTo(newArrayList(healthCheckExpiration, healthCheckExpiration, healthCheckExpiration));
    assertThat(lastHealthCheckNewerThan.getActual()).isEqualTo(newArrayList());
    assertThat(lastHealthCheckNewerThan.isOk()).isFalse();
}
Also used : Instant(org.joda.time.Instant) HealthReportService.getClusterHealthReport(io.mesosphere.mesos.frameworks.cassandra.scheduler.health.HealthReportService.getClusterHealthReport) Test(org.junit.Test)

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