diff options
author | Yang Song <songy23@users.noreply.github.com> | 2018-08-21 13:14:31 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-21 13:14:31 -0700 |
commit | 8d75c101ab0ae0efd5faea9906ce399f00fb4394 (patch) | |
tree | fe63865bbb7fbd7b6e86dd88dfe4825331d6b5b6 /api/src/test/java/io | |
parent | 07ede4e46f2256917b4d4fb0968c09817b33b10a (diff) | |
download | opencensus-java-8d75c101ab0ae0efd5faea9906ce399f00fb4394.tar.gz |
Metrics: Combine TimeSeriesCumulative and TimeSeriesGauge. (#1380)
Diffstat (limited to 'api/src/test/java/io')
-rw-r--r-- | api/src/test/java/io/opencensus/metrics/MetricTest.java | 59 | ||||
-rw-r--r-- | api/src/test/java/io/opencensus/metrics/TimeSeriesGaugeTest.java | 104 | ||||
-rw-r--r-- | api/src/test/java/io/opencensus/metrics/TimeSeriesListTest.java | 135 | ||||
-rw-r--r-- | api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java (renamed from api/src/test/java/io/opencensus/metrics/TimeSeriesCumulativeTest.java) | 37 |
4 files changed, 44 insertions, 291 deletions
diff --git a/api/src/test/java/io/opencensus/metrics/MetricTest.java b/api/src/test/java/io/opencensus/metrics/MetricTest.java index 59838ef4..37deed4b 100644 --- a/api/src/test/java/io/opencensus/metrics/MetricTest.java +++ b/api/src/test/java/io/opencensus/metrics/MetricTest.java @@ -21,10 +21,9 @@ import static com.google.common.truth.Truth.assertThat; import com.google.common.testing.EqualsTester; import io.opencensus.common.Timestamp; import io.opencensus.metrics.MetricDescriptor.Type; -import io.opencensus.metrics.TimeSeriesList.TimeSeriesCumulativeList; -import io.opencensus.metrics.TimeSeriesList.TimeSeriesGaugeList; import java.util.Arrays; import java.util.Collections; +import java.util.List; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -61,47 +60,41 @@ public class MetricTest { private static final Point POINT_1 = Point.create(VALUE_DOUBLE_1, TIMESTAMP_2); private static final Point POINT_2 = Point.create(VALUE_DOUBLE_2, TIMESTAMP_3); private static final Point POINT_3 = Point.create(VALUE_LONG, TIMESTAMP_3); - private static final TimeSeriesGauge GAUGE_TIME_SERIES_1 = - TimeSeriesGauge.create(Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1)); - private static final TimeSeriesGauge GAUGE_TIME_SERIES_2 = - TimeSeriesGauge.create(Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_2)); - private static final TimeSeriesCumulative CUMULATIVE_TIME_SERIES = - TimeSeriesCumulative.create( - Arrays.asList(LABEL_VALUE_EMPTY), Arrays.asList(POINT_3), TIMESTAMP_1); - private static final TimeSeriesGaugeList TIME_SERIES_GAUGE_LIST = - TimeSeriesGaugeList.create(Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2)); - private static final TimeSeriesCumulativeList TIME_SERIES_CUMULATIVE_LIST = - TimeSeriesCumulativeList.create(Arrays.asList(CUMULATIVE_TIME_SERIES)); + private static final TimeSeries GAUGE_TIME_SERIES_1 = + TimeSeries.create(Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), null); + private static final TimeSeries GAUGE_TIME_SERIES_2 = + TimeSeries.create(Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_2), null); + private static final TimeSeries CUMULATIVE_TIME_SERIES = + TimeSeries.create(Arrays.asList(LABEL_VALUE_EMPTY), Arrays.asList(POINT_3), TIMESTAMP_1); @Test public void testGet() { - Metric metric = Metric.create(METRIC_DESCRIPTOR_1, TIME_SERIES_GAUGE_LIST); + Metric metric = + Metric.create(METRIC_DESCRIPTOR_1, Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2)); assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR_1); - assertThat(metric.getTimeSeriesList()).isEqualTo(TIME_SERIES_GAUGE_LIST); + assertThat(metric.getTimeSeriesList()) + .containsExactly(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2) + .inOrder(); } @Test - public void typeMismatch_GaugeDouble_TimeSeriesCumulative() { + public void typeMismatch_GaugeDouble_Long() { typeMismatch( METRIC_DESCRIPTOR_1, - TIME_SERIES_CUMULATIVE_LIST, - String.format( - "Type mismatch: %s, %s.", - Type.GAUGE_DOUBLE, TIME_SERIES_CUMULATIVE_LIST.getClass().getSimpleName())); + Arrays.asList(CUMULATIVE_TIME_SERIES), + String.format("Type mismatch: %s, %s.", Type.GAUGE_DOUBLE, "ValueLong")); } @Test - public void typeMismatch_CumulativeInt64_TimeSeriesGauge() { + public void typeMismatch_CumulativeInt64_Double() { typeMismatch( METRIC_DESCRIPTOR_2, - TIME_SERIES_GAUGE_LIST, - String.format( - "Type mismatch: %s, %s.", - Type.CUMULATIVE_INT64, TIME_SERIES_GAUGE_LIST.getClass().getSimpleName())); + Arrays.asList(GAUGE_TIME_SERIES_1), + String.format("Type mismatch: %s, %s.", Type.CUMULATIVE_INT64, "ValueDouble")); } private void typeMismatch( - MetricDescriptor metricDescriptor, TimeSeriesList timeSeriesList, String errorMessage) { + MetricDescriptor metricDescriptor, List<TimeSeries> timeSeriesList, String errorMessage) { thrown.expect(IllegalArgumentException.class); thrown.expectMessage(errorMessage); Metric.create(metricDescriptor, timeSeriesList); @@ -111,17 +104,13 @@ public class MetricTest { public void testEquals() { new EqualsTester() .addEqualityGroup( - Metric.create(METRIC_DESCRIPTOR_1, TIME_SERIES_GAUGE_LIST), - Metric.create(METRIC_DESCRIPTOR_1, TIME_SERIES_GAUGE_LIST)) - .addEqualityGroup( Metric.create( - METRIC_DESCRIPTOR_1, - TimeSeriesGaugeList.create(Collections.<TimeSeriesGauge>emptyList()))) - .addEqualityGroup(Metric.create(METRIC_DESCRIPTOR_2, TIME_SERIES_CUMULATIVE_LIST)) - .addEqualityGroup( + METRIC_DESCRIPTOR_1, Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2)), Metric.create( - METRIC_DESCRIPTOR_2, - TimeSeriesCumulativeList.create(Collections.<TimeSeriesCumulative>emptyList()))) + METRIC_DESCRIPTOR_1, Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2))) + .addEqualityGroup(Metric.create(METRIC_DESCRIPTOR_1, Collections.<TimeSeries>emptyList())) + .addEqualityGroup(Metric.create(METRIC_DESCRIPTOR_2, Arrays.asList(CUMULATIVE_TIME_SERIES))) + .addEqualityGroup(Metric.create(METRIC_DESCRIPTOR_2, Collections.<TimeSeries>emptyList())) .testEquals(); } } diff --git a/api/src/test/java/io/opencensus/metrics/TimeSeriesGaugeTest.java b/api/src/test/java/io/opencensus/metrics/TimeSeriesGaugeTest.java deleted file mode 100644 index 83f7c267..00000000 --- a/api/src/test/java/io/opencensus/metrics/TimeSeriesGaugeTest.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2018, OpenCensus Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opencensus.metrics; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.testing.EqualsTester; -import io.opencensus.common.Timestamp; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.hamcrest.CoreMatchers; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link TimeSeriesGauge}. */ -@RunWith(JUnit4.class) -public class TimeSeriesGaugeTest { - - @Rule public ExpectedException thrown = ExpectedException.none(); - - private static final LabelValue LABEL_VALUE_1 = LabelValue.create("value1"); - private static final LabelValue LABEL_VALUE_2 = LabelValue.create("value2"); - private static final Value VALUE_LONG = Value.longValue(12345678); - private static final Value VALUE_DOUBLE = Value.doubleValue(-345.77); - private static final Timestamp TIMESTAMP_1 = Timestamp.fromMillis(1000); - private static final Timestamp TIMESTAMP_2 = Timestamp.fromMillis(2000); - private static final Point POINT_1 = Point.create(VALUE_DOUBLE, TIMESTAMP_1); - private static final Point POINT_2 = Point.create(VALUE_LONG, TIMESTAMP_2); - - @Test - public void testGet_TimeSeriesGauge() { - TimeSeriesGauge gaugeTimeSeries = - TimeSeriesGauge.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1, POINT_2)); - assertThat(gaugeTimeSeries.getLabelValues()) - .containsExactly(LABEL_VALUE_1, LABEL_VALUE_2) - .inOrder(); - assertThat(gaugeTimeSeries.getPoints()).containsExactly(POINT_1, POINT_2).inOrder(); - } - - @Test - public void create_WithNullLabelValueList() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("labelValues")); - TimeSeriesGauge.create(null, Collections.<Point>emptyList()); - } - - @Test - public void create_WithNullLabelValue() { - List<LabelValue> labelValues = Arrays.asList(LABEL_VALUE_1, null); - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("labelValue")); - TimeSeriesGauge.create(labelValues, Collections.<Point>emptyList()); - } - - @Test - public void create_WithNullPointList() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("points")); - TimeSeriesGauge.create(Collections.<LabelValue>emptyList(), null); - } - - @Test - public void create_WithNullPoint() { - List<Point> points = Arrays.asList(POINT_1, null); - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("point")); - TimeSeriesGauge.create(Collections.<LabelValue>emptyList(), points); - } - - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup( - TimeSeriesGauge.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1, POINT_2)), - TimeSeriesGauge.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1, POINT_2))) - .addEqualityGroup( - TimeSeriesGauge.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1))) - .addEqualityGroup( - TimeSeriesGauge.create(Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1))) - .testEquals(); - } -} diff --git a/api/src/test/java/io/opencensus/metrics/TimeSeriesListTest.java b/api/src/test/java/io/opencensus/metrics/TimeSeriesListTest.java deleted file mode 100644 index 46ace50f..00000000 --- a/api/src/test/java/io/opencensus/metrics/TimeSeriesListTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2018, OpenCensus Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.opencensus.metrics; - -import static com.google.common.truth.Truth.assertThat; - -import com.google.common.testing.EqualsTester; -import io.opencensus.common.Functions; -import io.opencensus.common.Timestamp; -import io.opencensus.metrics.TimeSeriesList.TimeSeriesCumulativeList; -import io.opencensus.metrics.TimeSeriesList.TimeSeriesGaugeList; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.hamcrest.CoreMatchers; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; - -/** Unit tests for {@link TimeSeries}. */ -@RunWith(JUnit4.class) -public class TimeSeriesListTest { - - @Rule public ExpectedException thrown = ExpectedException.none(); - - private static final LabelValue LABEL_VALUE_1 = LabelValue.create("value1"); - private static final LabelValue LABEL_VALUE_2 = LabelValue.create("value2"); - private static final LabelValue LABEL_VALUE_EMPTY = LabelValue.create(""); - private static final Value VALUE_LONG = Value.longValue(12345678); - private static final Value VALUE_DOUBLE = Value.doubleValue(-345.77); - private static final Timestamp TIMESTAMP_1 = Timestamp.fromMillis(1000); - private static final Timestamp TIMESTAMP_2 = Timestamp.fromMillis(2000); - private static final Timestamp TIMESTAMP_3 = Timestamp.fromMillis(3000); - private static final Point POINT_1 = Point.create(VALUE_DOUBLE, TIMESTAMP_2); - private static final Point POINT_2 = Point.create(VALUE_LONG, TIMESTAMP_3); - private static final TimeSeriesGauge TIME_SERIES_GAUGE = - TimeSeriesGauge.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1, POINT_2)); - private static final TimeSeriesCumulative TIME_SERIES_CUMULATIVE = - TimeSeriesCumulative.create( - Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_EMPTY), Arrays.asList(POINT_1), TIMESTAMP_1); - - @Test - public void testGet_TimeSeriesGaugeList() { - TimeSeriesGaugeList gaugeTimeSeriesList = - TimeSeriesGaugeList.create(Collections.singletonList(TIME_SERIES_GAUGE)); - assertThat(gaugeTimeSeriesList.getList()).containsExactly(TIME_SERIES_GAUGE); - } - - @Test - public void testGet_TimeSeriesCumulativeList() { - TimeSeriesCumulativeList cumulativeTimeSeriesList = - TimeSeriesCumulativeList.create(Collections.singletonList(TIME_SERIES_CUMULATIVE)); - assertThat(cumulativeTimeSeriesList.getList()).containsExactly(TIME_SERIES_CUMULATIVE); - } - - @Test - public void createGaugeList_WithNullList() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("list")); - TimeSeriesGaugeList.create(null); - } - - @Test - public void createGaugeList_WithNullTimeSeries() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("timeSeriesGauge")); - TimeSeriesGaugeList.create(Arrays.asList(TIME_SERIES_GAUGE, null)); - } - - @Test - public void createCumulativeList_WithNullList() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("list")); - TimeSeriesCumulativeList.create(null); - } - - @Test - public void createCumulativeList_WithNullTimeSeries() { - thrown.expect(NullPointerException.class); - thrown.expectMessage(CoreMatchers.equalTo("timeSeriesCumulative")); - TimeSeriesCumulativeList.create(Arrays.asList(TIME_SERIES_CUMULATIVE, null)); - } - - @Test - public void testEquals() { - new EqualsTester() - .addEqualityGroup( - TimeSeriesGaugeList.create(Collections.singletonList(TIME_SERIES_GAUGE)), - TimeSeriesGaugeList.create(Collections.singletonList(TIME_SERIES_GAUGE))) - .addEqualityGroup( - TimeSeriesCumulativeList.create(Collections.singletonList(TIME_SERIES_CUMULATIVE)), - TimeSeriesCumulativeList.create(Collections.singletonList(TIME_SERIES_CUMULATIVE))) - .addEqualityGroup(TimeSeriesGaugeList.create(Collections.<TimeSeriesGauge>emptyList())) - .addEqualityGroup( - TimeSeriesCumulativeList.create(Collections.<TimeSeriesCumulative>emptyList())) - .testEquals(); - } - - @Test - public void testMatch() { - TimeSeriesList gaugeTimeSeriesList = - TimeSeriesGaugeList.create(Collections.singletonList(TIME_SERIES_GAUGE)); - TimeSeriesList cumulativeTimeSeriesList = - TimeSeriesCumulativeList.create(Collections.singletonList(TIME_SERIES_CUMULATIVE)); - - final List<String> actual = new ArrayList<String>(); - for (TimeSeriesList timeSeriesList : - Arrays.asList(cumulativeTimeSeriesList, gaugeTimeSeriesList)) { - actual.add( - timeSeriesList.match( - Functions.returnConstant("TimeSeriesGaugeList"), - Functions.returnConstant("TimeSeriesCumulativeList"), - Functions.<String>throwAssertionError())); - } - assertThat(actual).containsExactly("TimeSeriesCumulativeList", "TimeSeriesGaugeList").inOrder(); - } -} diff --git a/api/src/test/java/io/opencensus/metrics/TimeSeriesCumulativeTest.java b/api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java index 3532a5a5..07dff97d 100644 --- a/api/src/test/java/io/opencensus/metrics/TimeSeriesCumulativeTest.java +++ b/api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java @@ -30,9 +30,9 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -/** Unit tests for {@link TimeSeriesCumulative}. */ +/** Unit tests for {@link TimeSeries}. */ @RunWith(JUnit4.class) -public class TimeSeriesCumulativeTest { +public class TimeSeriesTest { @Rule public ExpectedException thrown = ExpectedException.none(); @@ -47,9 +47,9 @@ public class TimeSeriesCumulativeTest { private static final Point POINT_2 = Point.create(VALUE_LONG, TIMESTAMP_3); @Test - public void testGet_TimeSeriesCumulative() { - TimeSeriesCumulative cumulativeTimeSeries = - TimeSeriesCumulative.create( + public void testGet_TimeSeries() { + TimeSeries cumulativeTimeSeries = + TimeSeries.create( Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_1); assertThat(cumulativeTimeSeries.getStartTimestamp()).isEqualTo(TIMESTAMP_1); assertThat(cumulativeTimeSeries.getLabelValues()) @@ -62,7 +62,7 @@ public class TimeSeriesCumulativeTest { public void create_WithNullLabelValueList() { thrown.expect(NullPointerException.class); thrown.expectMessage(CoreMatchers.equalTo("labelValues")); - TimeSeriesCumulative.create(null, Collections.<Point>emptyList(), TIMESTAMP_1); + TimeSeries.create(null, Collections.<Point>emptyList(), TIMESTAMP_1); } @Test @@ -70,14 +70,14 @@ public class TimeSeriesCumulativeTest { List<LabelValue> labelValues = Arrays.asList(LABEL_VALUE_1, null); thrown.expect(NullPointerException.class); thrown.expectMessage(CoreMatchers.equalTo("labelValue")); - TimeSeriesCumulative.create(labelValues, Collections.<Point>emptyList(), TIMESTAMP_1); + TimeSeries.create(labelValues, Collections.<Point>emptyList(), TIMESTAMP_1); } @Test public void create_WithNullPointList() { thrown.expect(NullPointerException.class); thrown.expectMessage(CoreMatchers.equalTo("points")); - TimeSeriesCumulative.create(Collections.<LabelValue>emptyList(), null, TIMESTAMP_1); + TimeSeries.create(Collections.<LabelValue>emptyList(), null, TIMESTAMP_1); } @Test @@ -85,28 +85,31 @@ public class TimeSeriesCumulativeTest { List<Point> points = Arrays.asList(POINT_1, null); thrown.expect(NullPointerException.class); thrown.expectMessage(CoreMatchers.equalTo("point")); - TimeSeriesCumulative.create(Collections.<LabelValue>emptyList(), points, TIMESTAMP_1); + TimeSeries.create(Collections.<LabelValue>emptyList(), points, TIMESTAMP_1); } @Test public void testEquals() { new EqualsTester() .addEqualityGroup( - TimeSeriesCumulative.create( + TimeSeries.create( Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_1), - TimeSeriesCumulative.create( + TimeSeries.create( Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_1)) .addEqualityGroup( - TimeSeriesCumulative.create( + TimeSeries.create( + Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), null), + TimeSeries.create( + Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), null)) + .addEqualityGroup( + TimeSeries.create( Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_2)) .addEqualityGroup( - TimeSeriesCumulative.create( - Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1), TIMESTAMP_2)) + TimeSeries.create(Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1), TIMESTAMP_2)) .addEqualityGroup( - TimeSeriesCumulative.create( - Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_2), TIMESTAMP_2)) + TimeSeries.create(Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_2), TIMESTAMP_2)) .addEqualityGroup( - TimeSeriesCumulative.create( + TimeSeries.create( Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1, POINT_2), TIMESTAMP_2)) .testEquals(); } |