aboutsummaryrefslogtreecommitdiff
path: root/api/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'api/src/test')
-rw-r--r--api/src/test/java/io/opencensus/metrics/DistributionTest.java226
-rw-r--r--api/src/test/java/io/opencensus/metrics/LabelKeyTest.java86
-rw-r--r--api/src/test/java/io/opencensus/metrics/LabelValueTest.java74
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricDescriptorTest.java102
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricRegistryTest.java185
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricTest.java116
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricsComponentTest.java40
-rw-r--r--api/src/test/java/io/opencensus/metrics/MetricsTest.java71
-rw-r--r--api/src/test/java/io/opencensus/metrics/PointTest.java68
-rw-r--r--api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java116
-rw-r--r--api/src/test/java/io/opencensus/metrics/ValueTest.java128
-rw-r--r--api/src/test/java/io/opencensus/metrics/export/ExportComponentTest.java33
-rw-r--r--api/src/test/java/io/opencensus/metrics/export/MetricProducerManagerTest.java81
13 files changed, 0 insertions, 1326 deletions
diff --git a/api/src/test/java/io/opencensus/metrics/DistributionTest.java b/api/src/test/java/io/opencensus/metrics/DistributionTest.java
deleted file mode 100644
index d511e317..00000000
--- a/api/src/test/java/io/opencensus/metrics/DistributionTest.java
+++ /dev/null
@@ -1,226 +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 io.opencensus.metrics.Distribution.Bucket;
-import io.opencensus.metrics.Distribution.Exemplar;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-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 Value}. */
-@RunWith(JUnit4.class)
-public class DistributionTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
-
- private static final Timestamp TIMESTAMP = Timestamp.create(1, 0);
- private static final Map<String, String> ATTACHMENTS = Collections.singletonMap("key", "value");
-
- @Test
- public void createAndGet_Bucket() {
- Bucket bucket = Bucket.create(98);
- assertThat(bucket.getCount()).isEqualTo(98);
- assertThat(bucket.getExemplar()).isNull();
- }
-
- @Test
- public void createAndGet_BucketWithExemplar() {
- Exemplar exemplar = Exemplar.create(12.2, TIMESTAMP, ATTACHMENTS);
- Bucket bucket = Bucket.create(7, exemplar);
- assertThat(bucket.getCount()).isEqualTo(7);
- assertThat(bucket.getExemplar()).isEqualTo(exemplar);
- }
-
- @Test
- public void createBucket_preventNullExemplar() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("exemplar");
- Bucket.create(1, null);
- }
-
- @Test
- public void createAndGet_Exemplar() {
- Exemplar exemplar = Exemplar.create(-9.9, TIMESTAMP, ATTACHMENTS);
- assertThat(exemplar.getValue()).isEqualTo(-9.9);
- assertThat(exemplar.getTimestamp()).isEqualTo(TIMESTAMP);
- assertThat(exemplar.getAttachments()).isEqualTo(ATTACHMENTS);
- }
-
- @Test
- public void createAndGet_Distribution() {
- Exemplar exemplar = Exemplar.create(15.0, TIMESTAMP, ATTACHMENTS);
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4, exemplar));
- Distribution distribution = Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
- assertThat(distribution.getMean()).isEqualTo(6.6);
- assertThat(distribution.getCount()).isEqualTo(10);
- assertThat(distribution.getSumOfSquaredDeviations()).isEqualTo(678.54);
- assertThat(distribution.getBucketBoundaries())
- .containsExactlyElementsIn(bucketBounds)
- .inOrder();
- assertThat(distribution.getBuckets()).containsExactlyElementsIn(buckets).inOrder();
- }
-
- @Test
- public void createBucket_NegativeCount() {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("bucket count should be non-negative.");
- Bucket.create(-5);
- }
-
- @Test
- public void createExemplar_PreventNullAttachments() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("attachments");
- Exemplar.create(15, TIMESTAMP, null);
- }
-
- @Test
- public void createExemplar_PreventNullAttachmentKey() {
- Map<String, String> attachments = Collections.singletonMap(null, "value");
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("key of attachment");
- Exemplar.create(15, TIMESTAMP, attachments);
- }
-
- @Test
- public void createExemplar_PreventNullAttachmentValue() {
- Map<String, String> attachments = Collections.singletonMap("key", null);
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("value of attachment");
- Exemplar.create(15, TIMESTAMP, attachments);
- }
-
- @Test
- public void createDistribution_NegativeCount() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("count should be non-negative.");
- Distribution.create(6.6, -10, 678.54, bucketBounds, buckets);
- }
-
- @Test
- public void createDistribution_NegativeSumOfSquaredDeviations() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("sum of squared deviations should be non-negative.");
- Distribution.create(6.6, 0, -678.54, bucketBounds, buckets);
- }
-
- @Test
- public void createDistribution_ZeroCountAndPositiveMean() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("mean should be 0 if count is 0.");
- Distribution.create(6.6, 0, 0, bucketBounds, buckets);
- }
-
- @Test
- public void createDistribution_ZeroCountAndSumOfSquaredDeviations() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(0), Bucket.create(0), Bucket.create(0), Bucket.create(0));
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("sum of squared deviations should be 0 if count is 0.");
- Distribution.create(0, 0, 678.54, bucketBounds, buckets);
- }
-
- @Test
- public void createDistribution_NullBucketBounds() {
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("bucketBoundaries list should not be null.");
- Distribution.create(6.6, 10, 678.54, null, buckets);
- }
-
- @Test
- public void createDistribution_UnorderedBucketBounds() {
- List<Double> bucketBounds = Arrays.asList(0.0, -1.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4));
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("bucket boundaries not sorted.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
- }
-
- @Test
- public void createDistribution_NullBucketList() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("bucket list should not be null.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, null);
- }
-
- @Test
- public void createDistribution_NullBucket() {
- List<Double> bucketBounds = Arrays.asList(-1.0, 0.0, 1.0);
- List<Bucket> buckets =
- Arrays.asList(Bucket.create(3), Bucket.create(1), null, Bucket.create(4));
- thrown.expect(NullPointerException.class);
- thrown.expectMessage("bucket should not be null.");
- Distribution.create(6.6, 10, 678.54, bucketBounds, buckets);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(
- Distribution.create(
- 10,
- 10,
- 1,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))),
- Distribution.create(
- 10,
- 10,
- 1,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))))
- .addEqualityGroup(
- Distribution.create(
- -7,
- 10,
- 23.456,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/LabelKeyTest.java b/api/src/test/java/io/opencensus/metrics/LabelKeyTest.java
deleted file mode 100644
index 83f2b59a..00000000
--- a/api/src/test/java/io/opencensus/metrics/LabelKeyTest.java
+++ /dev/null
@@ -1,86 +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 java.util.Arrays;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link LabelKey}. */
-@RunWith(JUnit4.class)
-public class LabelKeyTest {
-
- private static final LabelKey KEY = LabelKey.create("key", "description");
-
- @Test
- public void testGetKey() {
- assertThat(KEY.getKey()).isEqualTo("key");
- }
-
- @Test
- public void testGetDescription() {
- assertThat(KEY.getDescription()).isEqualTo("description");
- }
-
- @Test
- public void create_NoLengthConstraint() {
- // We have a length constraint of 256-characters for TagKey. That constraint doesn't apply to
- // LabelKey.
- char[] chars = new char[300];
- Arrays.fill(chars, 'k');
- String key = new String(chars);
- assertThat(LabelKey.create(key, "").getKey()).isEqualTo(key);
- }
-
- @Test
- public void create_WithUnprintableChars() {
- String key = "\2ab\3cd";
- String description = "\4ef\5gh";
- LabelKey labelKey = LabelKey.create(key, description);
- assertThat(labelKey.getKey()).isEqualTo(key);
- assertThat(labelKey.getDescription()).isEqualTo(description);
- }
-
- @Test
- public void create_WithNonAsciiChars() {
- String key = "键";
- String description = "测试用键";
- LabelKey nonAsciiKey = LabelKey.create(key, description);
- assertThat(nonAsciiKey.getKey()).isEqualTo(key);
- assertThat(nonAsciiKey.getDescription()).isEqualTo(description);
- }
-
- @Test
- public void create_Empty() {
- LabelKey emptyKey = LabelKey.create("", "");
- assertThat(emptyKey.getKey()).isEmpty();
- assertThat(emptyKey.getDescription()).isEmpty();
- }
-
- @Test
- public void testLabelKeyEquals() {
- new EqualsTester()
- .addEqualityGroup(LabelKey.create("foo", ""), LabelKey.create("foo", ""))
- .addEqualityGroup(LabelKey.create("foo", "description"))
- .addEqualityGroup(LabelKey.create("bar", ""))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/LabelValueTest.java b/api/src/test/java/io/opencensus/metrics/LabelValueTest.java
deleted file mode 100644
index e5526b2f..00000000
--- a/api/src/test/java/io/opencensus/metrics/LabelValueTest.java
+++ /dev/null
@@ -1,74 +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 java.util.Arrays;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link LabelValue}. */
-@RunWith(JUnit4.class)
-public class LabelValueTest {
-
- private static final LabelValue VALUE = LabelValue.create("value");
- private static final LabelValue UNSET = LabelValue.create(null);
- private static final LabelValue EMPTY = LabelValue.create("");
-
- @Test
- public void testGetValue() {
- assertThat(VALUE.getValue()).isEqualTo("value");
- assertThat(UNSET.getValue()).isNull();
- assertThat(EMPTY.getValue()).isEmpty();
- }
-
- @Test
- public void create_NoLengthConstraint() {
- // We have a length constraint of 256-characters for TagValue. That constraint doesn't apply to
- // LabelValue.
- char[] chars = new char[300];
- Arrays.fill(chars, 'v');
- String value = new String(chars);
- assertThat(LabelValue.create(value).getValue()).isEqualTo(value);
- }
-
- @Test
- public void create_WithUnprintableChars() {
- String value = "\2ab\3cd";
- assertThat(LabelValue.create(value).getValue()).isEqualTo(value);
- }
-
- @Test
- public void create_WithNonAsciiChars() {
- String value = "值";
- LabelValue nonAsciiValue = LabelValue.create(value);
- assertThat(nonAsciiValue.getValue()).isEqualTo(value);
- }
-
- @Test
- public void testLabelValueEquals() {
- new EqualsTester()
- .addEqualityGroup(LabelValue.create("foo"), LabelValue.create("foo"))
- .addEqualityGroup(UNSET)
- .addEqualityGroup(EMPTY)
- .addEqualityGroup(LabelValue.create("bar"))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/MetricDescriptorTest.java b/api/src/test/java/io/opencensus/metrics/MetricDescriptorTest.java
deleted file mode 100644
index 9c0a42fc..00000000
--- a/api/src/test/java/io/opencensus/metrics/MetricDescriptorTest.java
+++ /dev/null
@@ -1,102 +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.metrics.MetricDescriptor.Type;
-import java.util.Arrays;
-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 MetricDescriptor}. */
-@RunWith(JUnit4.class)
-public class MetricDescriptorTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
-
- private static final String METRIC_NAME_1 = "metric1";
- private static final String METRIC_NAME_2 = "metric2";
- private static final String DESCRIPTION = "Metric description.";
- private static final String UNIT = "kb/s";
- private static final LabelKey KEY_1 = LabelKey.create("key1", "some key");
- private static final LabelKey KEY_2 = LabelKey.create("key2", "some other key");
-
- @Test
- public void testGet() {
- MetricDescriptor metricDescriptor =
- MetricDescriptor.create(
- METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, Arrays.asList(KEY_1, KEY_2));
- assertThat(metricDescriptor.getName()).isEqualTo(METRIC_NAME_1);
- assertThat(metricDescriptor.getDescription()).isEqualTo(DESCRIPTION);
- assertThat(metricDescriptor.getUnit()).isEqualTo(UNIT);
- assertThat(metricDescriptor.getType()).isEqualTo(Type.GAUGE_DOUBLE);
- assertThat(metricDescriptor.getLabelKeys()).containsExactly(KEY_1, KEY_2).inOrder();
- }
-
- @Test
- public void preventNullLabelKeyList() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("labelKeys"));
- MetricDescriptor.create(METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, null);
- }
-
- @Test
- public void preventNullLabelKey() {
- List<LabelKey> keys = Arrays.asList(KEY_1, null);
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("labelKey"));
- MetricDescriptor.create(METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, keys);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(
- MetricDescriptor.create(
- METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, Arrays.asList(KEY_1, KEY_2)),
- MetricDescriptor.create(
- METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, Arrays.asList(KEY_1, KEY_2)))
- .addEqualityGroup(
- MetricDescriptor.create(
- METRIC_NAME_2, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, Arrays.asList(KEY_1, KEY_2)))
- .addEqualityGroup(
- MetricDescriptor.create(
- METRIC_NAME_2, DESCRIPTION, UNIT, Type.GAUGE_INT64, Arrays.asList(KEY_1, KEY_2)))
- .addEqualityGroup(
- MetricDescriptor.create(
- METRIC_NAME_1,
- DESCRIPTION,
- UNIT,
- Type.CUMULATIVE_DISTRIBUTION,
- Arrays.asList(KEY_1, KEY_2)))
- .addEqualityGroup(
- MetricDescriptor.create(
- METRIC_NAME_1,
- DESCRIPTION,
- UNIT,
- Type.CUMULATIVE_DISTRIBUTION,
- Arrays.asList(KEY_1)))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/MetricRegistryTest.java b/api/src/test/java/io/opencensus/metrics/MetricRegistryTest.java
deleted file mode 100644
index 49e8ce02..00000000
--- a/api/src/test/java/io/opencensus/metrics/MetricRegistryTest.java
+++ /dev/null
@@ -1,185 +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 io.opencensus.common.ToDoubleFunction;
-import io.opencensus.common.ToLongFunction;
-import java.util.LinkedHashMap;
-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 MetricRegistry}. */
-@RunWith(JUnit4.class)
-public class MetricRegistryTest {
- @Rule public ExpectedException thrown = ExpectedException.none();
-
- private final MetricRegistry metricRegistry =
- MetricsComponent.newNoopMetricsComponent().getMetricRegistry();
-
- @Test
- public void addDoubleGauge_NullName() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addDoubleGauge(
- null,
- "description",
- "1",
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToDoubleFunction<Object>() {
- @Override
- public double applyAsDouble(Object value) {
- return 5.0;
- }
- });
- }
-
- @Test
- public void addDoubleGauge_NullDescription() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addDoubleGauge(
- "name",
- null,
- "1",
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToDoubleFunction<Object>() {
- @Override
- public double applyAsDouble(Object value) {
- return 5.0;
- }
- });
- }
-
- @Test
- public void addDoubleGauge_NullUnit() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addDoubleGauge(
- "name",
- "description",
- null,
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToDoubleFunction<Object>() {
- @Override
- public double applyAsDouble(Object value) {
- return 5.0;
- }
- });
- }
-
- @Test
- public void addDoubleGauge_NullLabels() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addDoubleGauge(
- "name",
- "description",
- "1",
- null,
- null,
- new ToDoubleFunction<Object>() {
- @Override
- public double applyAsDouble(Object value) {
- return 5.0;
- }
- });
- }
-
- @Test
- public void addDoubleGauge_NullFunction() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addDoubleGauge(
- "name", "description", "1", new LinkedHashMap<LabelKey, LabelValue>(), null, null);
- }
-
- @Test
- public void addLongGauge_NullName() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addLongGauge(
- null,
- "description",
- "1",
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToLongFunction<Object>() {
- @Override
- public long applyAsLong(Object value) {
- return 5;
- }
- });
- }
-
- @Test
- public void addLongGauge_NullDescription() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addLongGauge(
- "name",
- null,
- "1",
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToLongFunction<Object>() {
- @Override
- public long applyAsLong(Object value) {
- return 5;
- }
- });
- }
-
- @Test
- public void addLongGauge_NullUnit() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addLongGauge(
- "name",
- "description",
- null,
- new LinkedHashMap<LabelKey, LabelValue>(),
- null,
- new ToLongFunction<Object>() {
- @Override
- public long applyAsLong(Object value) {
- return 5;
- }
- });
- }
-
- @Test
- public void addLongGauge_NullLabels() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addLongGauge(
- "name",
- "description",
- "1",
- null,
- null,
- new ToLongFunction<Object>() {
- @Override
- public long applyAsLong(Object value) {
- return 5;
- }
- });
- }
-
- @Test
- public void addLongGauge_NullFunction() {
- thrown.expect(NullPointerException.class);
- metricRegistry.addLongGauge(
- "name", "description", "1", new LinkedHashMap<LabelKey, LabelValue>(), null, null);
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/MetricTest.java b/api/src/test/java/io/opencensus/metrics/MetricTest.java
deleted file mode 100644
index 37deed4b..00000000
--- a/api/src/test/java/io/opencensus/metrics/MetricTest.java
+++ /dev/null
@@ -1,116 +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 io.opencensus.metrics.MetricDescriptor.Type;
-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;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link Metric}. */
-@RunWith(JUnit4.class)
-public class MetricTest {
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
-
- private static final String METRIC_NAME_1 = "metric1";
- private static final String METRIC_NAME_2 = "metric2";
- private static final String DESCRIPTION = "Metric description.";
- private static final String UNIT = "kb/s";
- private static final LabelKey KEY_1 = LabelKey.create("key1", "some key");
- private static final LabelKey KEY_2 = LabelKey.create("key1", "some other key");
- private static final MetricDescriptor METRIC_DESCRIPTOR_1 =
- MetricDescriptor.create(
- METRIC_NAME_1, DESCRIPTION, UNIT, Type.GAUGE_DOUBLE, Arrays.asList(KEY_1, KEY_2));
- private static final MetricDescriptor METRIC_DESCRIPTOR_2 =
- MetricDescriptor.create(
- METRIC_NAME_2, DESCRIPTION, UNIT, Type.CUMULATIVE_INT64, Arrays.asList(KEY_1));
- private static final LabelValue LABEL_VALUE_1 = LabelValue.create("value1");
- private static final LabelValue LABEL_VALUE_2 = LabelValue.create("value1");
- private static final LabelValue LABEL_VALUE_EMPTY = LabelValue.create("");
- private static final Value VALUE_LONG = Value.longValue(12345678);
- private static final Value VALUE_DOUBLE_1 = Value.doubleValue(-345.77);
- private static final Value VALUE_DOUBLE_2 = Value.doubleValue(133.79);
- 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_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 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, Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2));
- assertThat(metric.getMetricDescriptor()).isEqualTo(METRIC_DESCRIPTOR_1);
- assertThat(metric.getTimeSeriesList())
- .containsExactly(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2)
- .inOrder();
- }
-
- @Test
- public void typeMismatch_GaugeDouble_Long() {
- typeMismatch(
- METRIC_DESCRIPTOR_1,
- Arrays.asList(CUMULATIVE_TIME_SERIES),
- String.format("Type mismatch: %s, %s.", Type.GAUGE_DOUBLE, "ValueLong"));
- }
-
- @Test
- public void typeMismatch_CumulativeInt64_Double() {
- typeMismatch(
- METRIC_DESCRIPTOR_2,
- Arrays.asList(GAUGE_TIME_SERIES_1),
- String.format("Type mismatch: %s, %s.", Type.CUMULATIVE_INT64, "ValueDouble"));
- }
-
- private void typeMismatch(
- MetricDescriptor metricDescriptor, List<TimeSeries> timeSeriesList, String errorMessage) {
- thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage(errorMessage);
- Metric.create(metricDescriptor, timeSeriesList);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(
- Metric.create(
- METRIC_DESCRIPTOR_1, Arrays.asList(GAUGE_TIME_SERIES_1, GAUGE_TIME_SERIES_2)),
- Metric.create(
- 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/MetricsComponentTest.java b/api/src/test/java/io/opencensus/metrics/MetricsComponentTest.java
deleted file mode 100644
index 1c4e70f7..00000000
--- a/api/src/test/java/io/opencensus/metrics/MetricsComponentTest.java
+++ /dev/null
@@ -1,40 +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 io.opencensus.metrics.export.ExportComponent;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link MetricsComponent}. */
-@RunWith(JUnit4.class)
-public class MetricsComponentTest {
- @Test
- public void defaultExportComponent() {
- assertThat(MetricsComponent.newNoopMetricsComponent().getExportComponent())
- .isInstanceOf(ExportComponent.newNoopExportComponent().getClass());
- }
-
- @Test
- public void defaultMetricRegistry() {
- assertThat(MetricsComponent.newNoopMetricsComponent().getMetricRegistry())
- .isInstanceOf(MetricRegistry.newNoopMetricRegistry().getClass());
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/MetricsTest.java b/api/src/test/java/io/opencensus/metrics/MetricsTest.java
deleted file mode 100644
index 9e0eee1f..00000000
--- a/api/src/test/java/io/opencensus/metrics/MetricsTest.java
+++ /dev/null
@@ -1,71 +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 io.opencensus.metrics.export.ExportComponent;
-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 Metrics}. */
-@RunWith(JUnit4.class)
-public class MetricsTest {
- @Rule public ExpectedException thrown = ExpectedException.none();
-
- @Test
- public void loadMetricsComponent_UsesProvidedClassLoader() {
- final RuntimeException toThrow = new RuntimeException("UseClassLoader");
- thrown.expect(RuntimeException.class);
- thrown.expectMessage("UseClassLoader");
- Metrics.loadMetricsComponent(
- new ClassLoader() {
- @Override
- public Class<?> loadClass(String name) {
- throw toThrow;
- }
- });
- }
-
- @Test
- public void loadMetricsComponent_IgnoresMissingClasses() {
- ClassLoader classLoader =
- new ClassLoader() {
- @Override
- public Class<?> loadClass(String name) throws ClassNotFoundException {
- throw new ClassNotFoundException();
- }
- };
- assertThat(Metrics.loadMetricsComponent(classLoader).getClass().getName())
- .isEqualTo("io.opencensus.metrics.MetricsComponent$NoopMetricsComponent");
- }
-
- @Test
- public void defaultExportComponent() {
- assertThat(Metrics.getExportComponent())
- .isInstanceOf(ExportComponent.newNoopExportComponent().getClass());
- }
-
- @Test
- public void defaultMetricRegistry() {
- assertThat(Metrics.getMetricRegistry())
- .isInstanceOf(MetricRegistry.newNoopMetricRegistry().getClass());
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/PointTest.java b/api/src/test/java/io/opencensus/metrics/PointTest.java
deleted file mode 100644
index cb6175c1..00000000
--- a/api/src/test/java/io/opencensus/metrics/PointTest.java
+++ /dev/null
@@ -1,68 +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 io.opencensus.metrics.Distribution.Bucket;
-import java.util.Arrays;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link Point}. */
-@RunWith(JUnit4.class)
-public class PointTest {
-
- private static final Value DOUBLE_VALUE = Value.doubleValue(55.5);
- private static final Value LONG_VALUE = Value.longValue(9876543210L);
- private static final Value DISTRIBUTION_VALUE =
- Value.distributionValue(
- Distribution.create(
- 6.6,
- 10,
- 678.54,
- Arrays.asList(-1.0, 0.0, 1.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4))));
- private static final Timestamp TIMESTAMP_1 = Timestamp.create(1, 2);
- private static final Timestamp TIMESTAMP_2 = Timestamp.create(3, 4);
- private static final Timestamp TIMESTAMP_3 = Timestamp.create(5, 6);
-
- @Test
- public void testGet() {
- Point point = Point.create(DOUBLE_VALUE, TIMESTAMP_1);
- assertThat(point.getValue()).isEqualTo(DOUBLE_VALUE);
- assertThat(point.getTimestamp()).isEqualTo(TIMESTAMP_1);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(
- Point.create(DOUBLE_VALUE, TIMESTAMP_1), Point.create(DOUBLE_VALUE, TIMESTAMP_1))
- .addEqualityGroup(Point.create(LONG_VALUE, TIMESTAMP_1))
- .addEqualityGroup(Point.create(LONG_VALUE, TIMESTAMP_2))
- .addEqualityGroup(
- Point.create(DISTRIBUTION_VALUE, TIMESTAMP_2),
- Point.create(DISTRIBUTION_VALUE, TIMESTAMP_2))
- .addEqualityGroup(Point.create(DISTRIBUTION_VALUE, TIMESTAMP_3))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java b/api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java
deleted file mode 100644
index 07dff97d..00000000
--- a/api/src/test/java/io/opencensus/metrics/TimeSeriesTest.java
+++ /dev/null
@@ -1,116 +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 TimeSeries}. */
-@RunWith(JUnit4.class)
-public class TimeSeriesTest {
-
- @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 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);
-
- @Test
- 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())
- .containsExactly(LABEL_VALUE_1, LABEL_VALUE_2)
- .inOrder();
- assertThat(cumulativeTimeSeries.getPoints()).containsExactly(POINT_1).inOrder();
- }
-
- @Test
- public void create_WithNullLabelValueList() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("labelValues"));
- TimeSeries.create(null, Collections.<Point>emptyList(), TIMESTAMP_1);
- }
-
- @Test
- public void create_WithNullLabelValue() {
- List<LabelValue> labelValues = Arrays.asList(LABEL_VALUE_1, null);
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("labelValue"));
- TimeSeries.create(labelValues, Collections.<Point>emptyList(), TIMESTAMP_1);
- }
-
- @Test
- public void create_WithNullPointList() {
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("points"));
- TimeSeries.create(Collections.<LabelValue>emptyList(), null, TIMESTAMP_1);
- }
-
- @Test
- public void create_WithNullPoint() {
- List<Point> points = Arrays.asList(POINT_1, null);
- thrown.expect(NullPointerException.class);
- thrown.expectMessage(CoreMatchers.equalTo("point"));
- TimeSeries.create(Collections.<LabelValue>emptyList(), points, TIMESTAMP_1);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(
- TimeSeries.create(
- Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_1),
- TimeSeries.create(
- Arrays.asList(LABEL_VALUE_1, LABEL_VALUE_2), Arrays.asList(POINT_1), TIMESTAMP_1))
- .addEqualityGroup(
- 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(
- TimeSeries.create(Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1), TIMESTAMP_2))
- .addEqualityGroup(
- TimeSeries.create(Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_2), TIMESTAMP_2))
- .addEqualityGroup(
- TimeSeries.create(
- Arrays.asList(LABEL_VALUE_1), Arrays.asList(POINT_1, POINT_2), TIMESTAMP_2))
- .testEquals();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/ValueTest.java b/api/src/test/java/io/opencensus/metrics/ValueTest.java
deleted file mode 100644
index 63430b28..00000000
--- a/api/src/test/java/io/opencensus/metrics/ValueTest.java
+++ /dev/null
@@ -1,128 +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.Function;
-import io.opencensus.common.Functions;
-import io.opencensus.metrics.Distribution.Bucket;
-import io.opencensus.metrics.Value.ValueDistribution;
-import io.opencensus.metrics.Value.ValueDouble;
-import io.opencensus.metrics.Value.ValueLong;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link Value}. */
-@RunWith(JUnit4.class)
-public class ValueTest {
-
- private static final Distribution DISTRIBUTION =
- Distribution.create(
- 10,
- 10,
- 1,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)));
-
- @Test
- public void createAndGet_ValueDouble() {
- Value value = Value.doubleValue(-34.56);
- assertThat(value).isInstanceOf(ValueDouble.class);
- assertThat(((ValueDouble) value).getValue()).isEqualTo(-34.56);
- }
-
- @Test
- public void createAndGet_ValueLong() {
- Value value = Value.longValue(123456789);
- assertThat(value).isInstanceOf(ValueLong.class);
- assertThat(((ValueLong) value).getValue()).isEqualTo(123456789);
- }
-
- @Test
- public void createAndGet_ValueDistribution() {
- Value value = Value.distributionValue(DISTRIBUTION);
- assertThat(value).isInstanceOf(ValueDistribution.class);
- assertThat(((ValueDistribution) value).getValue()).isEqualTo(DISTRIBUTION);
- }
-
- @Test
- public void testEquals() {
- new EqualsTester()
- .addEqualityGroup(Value.doubleValue(1.0), Value.doubleValue(1.0))
- .addEqualityGroup(Value.doubleValue(2.0))
- .addEqualityGroup(Value.longValue(1L))
- .addEqualityGroup(Value.longValue(2L))
- .addEqualityGroup(
- Value.distributionValue(
- Distribution.create(
- -7,
- 10,
- 23.456,
- Arrays.asList(-5.0, 0.0, 5.0),
- Arrays.asList(
- Bucket.create(3), Bucket.create(1), Bucket.create(2), Bucket.create(4)))))
- .testEquals();
- }
-
- @Test
- public void testMatch() {
- List<Value> values =
- Arrays.asList(
- ValueDouble.create(1.0), ValueLong.create(-1), ValueDistribution.create(DISTRIBUTION));
- List<Number> expected =
- Arrays.<Number>asList(1.0, -1L, 10.0, 10L, 1.0, -5.0, 0.0, 5.0, 3L, 1L, 2L, 4L);
- final List<Number> actual = new ArrayList<Number>();
- for (Value value : values) {
- value.match(
- new Function<Double, Object>() {
- @Override
- public Object apply(Double arg) {
- actual.add(arg);
- return null;
- }
- },
- new Function<Long, Object>() {
- @Override
- public Object apply(Long arg) {
- actual.add(arg);
- return null;
- }
- },
- new Function<Distribution, Object>() {
- @Override
- public Object apply(Distribution arg) {
- actual.add(arg.getMean());
- actual.add(arg.getCount());
- actual.add(arg.getSumOfSquaredDeviations());
- actual.addAll(arg.getBucketBoundaries());
- for (Bucket bucket : arg.getBuckets()) {
- actual.add(bucket.getCount());
- }
- return null;
- }
- },
- Functions.throwAssertionError());
- }
- assertThat(actual).containsExactlyElementsIn(expected).inOrder();
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/export/ExportComponentTest.java b/api/src/test/java/io/opencensus/metrics/export/ExportComponentTest.java
deleted file mode 100644
index 15c6e883..00000000
--- a/api/src/test/java/io/opencensus/metrics/export/ExportComponentTest.java
+++ /dev/null
@@ -1,33 +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.export;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-
-/** Unit tests for {@link ExportComponent}. */
-@RunWith(JUnit4.class)
-public class ExportComponentTest {
- @Test
- public void defaultMetricExporter() {
- assertThat(ExportComponent.newNoopExportComponent().getMetricProducerManager())
- .isInstanceOf(MetricProducerManager.class);
- }
-}
diff --git a/api/src/test/java/io/opencensus/metrics/export/MetricProducerManagerTest.java b/api/src/test/java/io/opencensus/metrics/export/MetricProducerManagerTest.java
deleted file mode 100644
index 07854927..00000000
--- a/api/src/test/java/io/opencensus/metrics/export/MetricProducerManagerTest.java
+++ /dev/null
@@ -1,81 +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.export;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import io.opencensus.metrics.MetricProducer;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.runner.RunWith;
-import org.junit.runners.JUnit4;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-/** Unit tests for {@link MetricProducerManager}. */
-@RunWith(JUnit4.class)
-public class MetricProducerManagerTest {
- private final MetricProducerManager metricProducerManager =
- MetricProducerManager.newNoopMetricProducerManager();
- @Mock private MetricProducer metricProducer;
-
- @Rule public final ExpectedException thrown = ExpectedException.none();
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- }
-
- @Test
- public void add_DisallowsNull() {
- thrown.expect(NullPointerException.class);
- metricProducerManager.add(null);
- }
-
- @Test
- public void add() {
- metricProducerManager.add(metricProducer);
- assertThat(metricProducerManager.getAllMetricProducer()).isEmpty();
- }
-
- @Test
- public void addAndRemove() {
- metricProducerManager.add(metricProducer);
- assertThat(metricProducerManager.getAllMetricProducer()).isEmpty();
- metricProducerManager.remove(metricProducer);
- assertThat(metricProducerManager.getAllMetricProducer()).isEmpty();
- }
-
- @Test
- public void remove_DisallowsNull() {
- thrown.expect(NullPointerException.class);
- metricProducerManager.remove(null);
- }
-
- @Test
- public void remove_FromEmpty() {
- metricProducerManager.remove(metricProducer);
- assertThat(metricProducerManager.getAllMetricProducer()).isEmpty();
- }
-
- @Test
- public void getAllMetricProducer_empty() {
- assertThat(metricProducerManager.getAllMetricProducer()).isEmpty();
- }
-}