use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class ViewDataTest method testCumulativeViewData.
@Test
public void testCumulativeViewData() {
View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, CUMULATIVE);
Timestamp start = Timestamp.fromMillis(1000);
Timestamp end = Timestamp.fromMillis(2000);
AggregationWindowData windowData = CumulativeData.create(start, end);
ViewData viewData = ViewData.create(view, ENTRIES, windowData);
assertThat(viewData.getView()).isEqualTo(view);
assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class ViewDataTest method testAggregationWindowDataMatch.
@Test
public void testAggregationWindowDataMatch() {
final Timestamp start = Timestamp.fromMillis(1000);
final Timestamp end = Timestamp.fromMillis(2000);
final AggregationWindowData windowData1 = CumulativeData.create(start, end);
final AggregationWindowData windowData2 = IntervalData.create(end);
windowData1.match(new Function<CumulativeData, Void>() {
@Override
public Void apply(CumulativeData windowData) {
assertThat(windowData.getStart()).isEqualTo(start);
assertThat(windowData.getEnd()).isEqualTo(end);
return null;
}
}, new Function<IntervalData, Void>() {
@Override
public Void apply(IntervalData windowData) {
fail("CumulativeData expected.");
return null;
}
}, Functions.<Void>throwIllegalArgumentException());
windowData2.match(new Function<CumulativeData, Void>() {
@Override
public Void apply(CumulativeData windowData) {
fail("IntervalData expected.");
return null;
}
}, new Function<IntervalData, Void>() {
@Override
public Void apply(IntervalData windowData) {
assertThat(windowData.getEnd()).isEqualTo(end);
return null;
}
}, Functions.<Void>throwIllegalArgumentException());
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class ViewDataTest method testIntervalViewData.
@Test
public void testIntervalViewData() {
View view = View.create(NAME, DESCRIPTION, MEASURE_DOUBLE, DISTRIBUTION, TAG_KEYS, INTERVAL_HOUR);
Timestamp end = Timestamp.fromMillis(2000);
AggregationWindowData windowData = IntervalData.create(end);
ViewData viewData = ViewData.create(view, ENTRIES, windowData);
assertThat(viewData.getView()).isEqualTo(view);
assertThat(viewData.getAggregationMap()).isEqualTo(ENTRIES);
assertThat(viewData.getWindowData()).isEqualTo(windowData);
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class OcAgentNodeUtils method getNodeInfo.
// Creates a Node with information from the OpenCensus library and environment variables.
static Node getNodeInfo(String serviceName) {
String jvmName = ManagementFactory.getRuntimeMXBean().getName();
Timestamp censusTimestamp = Timestamp.fromMillis(System.currentTimeMillis());
return Node.newBuilder().setIdentifier(getProcessIdentifier(jvmName, censusTimestamp)).setLibraryInfo(getLibraryInfo(OpenCensusLibraryInformation.VERSION)).setServiceInfo(getServiceInfo(serviceName)).build();
}
use of io.opencensus.common.Timestamp in project instrumentation-java by census-instrumentation.
the class MutableAggregationTest method testAdd_DistributionWithExemplarAttachments.
@Test
public void testAdd_DistributionWithExemplarAttachments() {
MutableDistribution mutableDistribution = MutableDistribution.create(BUCKET_BOUNDARIES);
MutableDistribution mutableDistributionNoHistogram = MutableDistribution.create(BUCKET_BOUNDARIES_EMPTY);
List<Double> values = Arrays.asList(-1.0, 1.0, -5.0, 20.0, 5.0);
List<Map<String, AttachmentValue>> attachmentsList = ImmutableList.<Map<String, AttachmentValue>>of(Collections.<String, AttachmentValue>singletonMap("k1", ATTACHMENT_VALUE_1), Collections.<String, AttachmentValue>singletonMap("k2", ATTACHMENT_VALUE_2), Collections.<String, AttachmentValue>singletonMap("k3", ATTACHMENT_VALUE_3), Collections.<String, AttachmentValue>singletonMap("k4", ATTACHMENT_VALUE_4), Collections.<String, AttachmentValue>singletonMap("k5", ATTACHMENT_VALUE_5));
List<Timestamp> timestamps = Arrays.asList(Timestamp.fromMillis(500), Timestamp.fromMillis(1000), Timestamp.fromMillis(2000), Timestamp.fromMillis(3000), Timestamp.fromMillis(4000));
for (int i = 0; i < values.size(); i++) {
mutableDistribution.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
mutableDistributionNoHistogram.add(values.get(i), attachmentsList.get(i), timestamps.get(i));
}
// Each bucket can only have up to one exemplar. If there are more than one exemplars in a
// bucket, only the last one will be kept.
List<Exemplar> expected = Arrays.<Exemplar>asList(Exemplar.create(values.get(4), timestamps.get(4), attachmentsList.get(4)), Exemplar.create(values.get(3), timestamps.get(3), attachmentsList.get(3)));
assertThat(mutableDistribution.getExemplars()).asList().containsExactlyElementsIn(expected).inOrder();
assertThat(mutableDistributionNoHistogram.getExemplars()).isNull();
}
Aggregations