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));
}
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));
}
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);
}
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());
}
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();
}
Aggregations