aboutsummaryrefslogtreecommitdiff
path: root/api/src/test/java/io/opencensus/metrics/ValueTest.java
diff options
context:
space:
mode:
authorsebright <sebright@google.com>2018-09-12 12:13:14 -0700
committerGitHub <noreply@github.com>2018-09-12 12:13:14 -0700
commitd3fa0e5c60903f95c184d7c7bafae8fdd12156ad (patch)
treef88e8fb0ebd0fa60c603285363acfcb6b7cee33e /api/src/test/java/io/opencensus/metrics/ValueTest.java
parentc0e0b225a5230036b3dc09134f94eece81d3f96d (diff)
downloadopencensus-java-d3fa0e5c60903f95c184d7c7bafae8fdd12156ad.tar.gz
Temporarily move "metrics" package into impl_core/ for release. (#1426)
The "metrics" package isn't ready to be released yet, so this commit moves it out of the API artifact. The package can still be accessed by the stats implementation in impl_core/. This commit can be reverted once the package is ready to be exposed. The moved package names also contain "temporary" so that there is no possibility of class name conflicts between different versions of opencensus-api and opencensus-impl-core. For example, io.opencensus.metrics.export is renamed to io.opencensus.implcore.temporary.metrics.export.
Diffstat (limited to 'api/src/test/java/io/opencensus/metrics/ValueTest.java')
-rw-r--r--api/src/test/java/io/opencensus/metrics/ValueTest.java128
1 files changed, 0 insertions, 128 deletions
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();
- }
-}