-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
sdk/metrics/src/test/java/io/opentelemetry/sdk/metrics/ViewRegistryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo; | ||
import io.opentelemetry.sdk.internal.TestClock; | ||
import io.opentelemetry.sdk.metrics.common.InstrumentType; | ||
import io.opentelemetry.sdk.metrics.common.InstrumentValueType; | ||
import io.opentelemetry.sdk.metrics.view.AggregationConfiguration; | ||
import io.opentelemetry.sdk.metrics.view.Aggregations; | ||
import io.opentelemetry.sdk.metrics.view.InstrumentSelector; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class ViewRegistryTest { | ||
|
||
@Test | ||
void registerView() { | ||
AggregationChooser chooser = mock(AggregationChooser.class); | ||
|
||
ViewRegistry viewRegistry = new ViewRegistry(chooser); | ||
InstrumentSelector selector = | ||
InstrumentSelector.newBuilder().instrumentType(InstrumentType.COUNTER).build(); | ||
AggregationConfiguration specification = | ||
AggregationConfiguration.create( | ||
Aggregations.count(), AggregationConfiguration.Temporality.CUMULATIVE); | ||
|
||
viewRegistry.registerView(selector, specification); | ||
|
||
verify(chooser).addView(selector, specification); | ||
} | ||
|
||
@Test | ||
void createBatcher_cumulative() { | ||
AggregationChooser chooser = mock(AggregationChooser.class); | ||
|
||
ViewRegistry viewRegistry = new ViewRegistry(chooser); | ||
|
||
InstrumentDescriptor descriptor = InstrumentDescriptor.create("name", "description", "unit", | ||
InstrumentType.COUNTER, InstrumentValueType.DOUBLE); | ||
MeterProviderSharedState providerSharedState = MeterProviderSharedState.create( | ||
TestClock.create(), | ||
Resource.getEmpty()); | ||
MeterSharedState meterSharedState = MeterSharedState | ||
.create(InstrumentationLibraryInfo.create("test", "1.0")); | ||
|
||
AggregationConfiguration specification = | ||
AggregationConfiguration.create( | ||
Aggregations.count(), AggregationConfiguration.Temporality.CUMULATIVE); | ||
Batcher expectedBatcher = Batchers | ||
.getCumulativeAllLabels(descriptor, providerSharedState, meterSharedState, | ||
Aggregations.count()); | ||
|
||
when(chooser.chooseAggregation(descriptor)).thenReturn(specification); | ||
|
||
Batcher result = viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor); | ||
|
||
assertThat(result.generatesDeltas()).isFalse(); | ||
assertThat(result).isEqualTo(expectedBatcher); | ||
|
||
assertThat(result).isNotNull(); | ||
} | ||
|
||
@Test | ||
void createBatcher_delta() { | ||
AggregationChooser chooser = mock(AggregationChooser.class); | ||
|
||
ViewRegistry viewRegistry = new ViewRegistry(chooser); | ||
|
||
InstrumentDescriptor descriptor = InstrumentDescriptor.create("name", "description", "unit", | ||
InstrumentType.COUNTER, InstrumentValueType.DOUBLE); | ||
MeterProviderSharedState providerSharedState = MeterProviderSharedState.create( | ||
TestClock.create(), | ||
Resource.getEmpty()); | ||
MeterSharedState meterSharedState = MeterSharedState | ||
.create(InstrumentationLibraryInfo.create("test", "1.0")); | ||
|
||
AggregationConfiguration specification = | ||
AggregationConfiguration.create( | ||
Aggregations.count(), AggregationConfiguration.Temporality.DELTA); | ||
Batcher expectedBatcher = Batchers | ||
.getDeltaAllLabels(descriptor, providerSharedState, meterSharedState, | ||
Aggregations.count()); | ||
|
||
when(chooser.chooseAggregation(descriptor)).thenReturn(specification); | ||
|
||
Batcher result = viewRegistry.createBatcher(providerSharedState, meterSharedState, descriptor); | ||
|
||
assertThat(result.generatesDeltas()).isTrue(); | ||
assertThat(result).isEqualTo(expectedBatcher); | ||
|
||
assertThat(result).isNotNull(); | ||
} | ||
} |