Search in sources :

Example 51 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class QueryGranularityTest method testPeriodDaylightSaving.

@Test
public void testPeriodDaylightSaving() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
    final DateTime baseTime = new DateTime("2012-11-04T00:00:00", tz);
    assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-05T00:00:00.000-08:00"), new DateTime("2012-11-06T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1D"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Days.days(3)).getMillis())));
    assertSameInterval(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), new PeriodGranularity(new Period("PT1H"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Hours.hours(5)).getMillis())));
    final PeriodGranularity hour = new PeriodGranularity(new Period("PT1H"), null, tz);
    assertSameDateTime(Lists.newArrayList(new DateTime("2012-11-04T00:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-07:00"), new DateTime("2012-11-04T01:00:00.000-08:00"), new DateTime("2012-11-04T02:00:00.000-08:00"), new DateTime("2012-11-04T03:00:00.000-08:00")), Lists.newArrayList(hour.bucketStart(new DateTime("2012-11-04T00:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-07:00")), hour.bucketStart(new DateTime("2012-11-04T01:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T02:30:00-08:00")), hour.bucketStart(new DateTime("2012-11-04T03:30:00-08:00"))));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 52 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class QueryGranularityTest method testIterableHourSimple.

@Test
public void testIterableHourSimple() throws Exception {
    final DateTime baseTime = new DateTime("2011-01-01T09:00:00.000Z");
    assertSameInterval(Lists.newArrayList(new DateTime("2011-01-01T09:00:00.000Z"), new DateTime("2011-01-01T10:00:00.000Z"), new DateTime("2011-01-01T11:00:00.000Z")), Granularities.HOUR.getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Hours.hours(3)).getMillis())));
}
Also used : DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 53 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class DefaultObjectMapperTest method testDateTime.

@Test
public void testDateTime() throws Exception {
    final DateTime time = new DateTime();
    Assert.assertEquals(String.format("\"%s\"", time), mapper.writeValueAsString(time));
}
Also used : DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 54 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class CombiningIterableTest method testMerge.

@Test
public void testMerge() {
    List<Result<Object>> resultsBefore = Arrays.asList(new Result<Object>(new DateTime("2011-01-01"), 1L), new Result<Object>(new DateTime("2011-01-01"), 2L));
    Iterable<Result<Object>> expectedResults = Arrays.<Result<Object>>asList(new Result<Object>(new DateTime("2011-01-01"), 3L));
    Iterable<Result<Object>> resultsAfter = CombiningIterable.create(resultsBefore, new Comparator<Result<Object>>() {

        @Override
        public int compare(Result<Object> r1, Result<Object> r2) {
            return r1.getTimestamp().compareTo(r2.getTimestamp());
        }
    }, new BinaryFn<Result<Object>, Result<Object>, Result<Object>>() {

        @Override
        public Result<Object> apply(final Result<Object> arg1, final Result<Object> arg2) {
            if (arg1 == null) {
                return arg2;
            }
            if (arg2 == null) {
                return arg1;
            }
            return new Result<Object>(arg1.getTimestamp(), ((Long) arg1.getValue()).longValue() + ((Long) arg2.getValue()).longValue());
        }
    });
    Iterator<Result<Object>> it1 = expectedResults.iterator();
    Iterator<Result<Object>> it2 = resultsAfter.iterator();
    while (it1.hasNext() && it2.hasNext()) {
        Result r1 = it1.next();
        Result r2 = it2.next();
        Assert.assertEquals(r1.getTimestamp(), r2.getTimestamp());
        Assert.assertEquals(r1.getValue(), r2.getValue());
    }
}
Also used : DateTime(org.joda.time.DateTime) Result(io.druid.query.Result) Test(org.junit.Test)

Example 55 with DateTime

use of org.joda.time.DateTime in project druid by druid-io.

the class QueryGranularityTest method testIterableMonth.

@Test
public void testIterableMonth() throws Exception {
    final DateTimeZone tz = DateTimeZone.forID("America/Los_Angeles");
    final DateTime baseTime = new DateTime("2012-11-03T10:00:00", tz);
    assertSameInterval(Lists.newArrayList(new DateTime("2012-11-01T00:00:00.000-07:00"), new DateTime("2012-12-01T00:00:00.000-08:00"), new DateTime("2013-01-01T00:00:00.000-08:00"), new DateTime("2013-02-01T00:00:00.000-08:00")), new PeriodGranularity(new Period("P1M"), null, tz).getIterable(new Interval(baseTime.getMillis(), baseTime.plus(Months.months(3)).getMillis())));
}
Also used : PeriodGranularity(io.druid.java.util.common.granularity.PeriodGranularity) Period(org.joda.time.Period) DateTimeZone(org.joda.time.DateTimeZone) DateTime(org.joda.time.DateTime) Interval(org.joda.time.Interval) Test(org.junit.Test)

Aggregations

DateTime (org.joda.time.DateTime)5683 Test (org.junit.Test)1667 Test (org.testng.annotations.Test)774 ArrayList (java.util.ArrayList)545 Date (java.util.Date)389 LocalDate (org.joda.time.LocalDate)374 DateTimeRfc1123 (com.microsoft.rest.DateTimeRfc1123)353 ResponseBody (okhttp3.ResponseBody)335 Interval (org.joda.time.Interval)307 Test (org.junit.jupiter.api.Test)281 HashMap (java.util.HashMap)272 BigDecimal (java.math.BigDecimal)234 DateTimeZone (org.joda.time.DateTimeZone)220 UUID (java.util.UUID)195 List (java.util.List)194 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)178 Map (java.util.Map)171 IOException (java.io.IOException)158 Result (io.druid.query.Result)153 ServiceCall (com.microsoft.rest.ServiceCall)148