Merge pull request #1336 from metamx/fix-1330

fixes #1330
This commit is contained in:
Fangjin Yang 2015-05-04 09:06:32 -07:00
commit 6be596c45e
2 changed files with 24 additions and 1 deletions

View File

@ -17,12 +17,16 @@
package io.druid.common.utils;
import org.joda.time.DateTimeConstants;
import org.joda.time.Duration;
import org.joda.time.Interval;
import org.joda.time.Period;
import org.junit.Assert;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
/**
@ -124,4 +128,23 @@ public class JodaUtilsTest
final Interval interval = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT);
Assert.assertEquals(Long.MAX_VALUE, interval.toDuration().getMillis());
}
@Test
public void testMinMaxDuration()
{
final Interval interval = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT);
final Duration duration = interval.toDuration();
Assert.assertEquals(Long.MAX_VALUE, duration.getMillis());
Assert.assertEquals("PT9223372036854775.807S", duration.toString());
}
// new Period(Long.MAX_VALUE) throws ArithmeticException
@Test(expected = ArithmeticException.class)
public void testMinMaxPeriod()
{
final Interval interval = new Interval(JodaUtils.MIN_INSTANT, JodaUtils.MAX_INSTANT);
final Period period = interval.toDuration().toPeriod();
Assert.assertEquals(Long.MAX_VALUE, period.getMinutes());
}
}

View File

@ -76,7 +76,7 @@ public class DruidMetrics
).toArray(new String[query.getIntervals().size()])
)
.setDimension("hasFilters", String.valueOf(query.hasFilters()))
.setDimension("duration", query.getDuration().toPeriod().toStandardMinutes().toString());
.setDimension("duration", query.getDuration().toString());
}
public static <T> ServiceMetricEvent.Builder makeQueryTimeMetric(