use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.
the class TraceMetricBuilderTest method testRemovingNonExistingCustomAttributes.
@Test
public void testRemovingNonExistingCustomAttributes() {
Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
currentTime = 1;
trace.start();
currentTime = 2;
trace.startStage(TRACE_2);
trace.putAttribute(TRACE_ATTRIBUTE_KEY, TRACE_ATTRIBUTE_VALUE);
currentTime = 3;
trace.removeAttribute(TRACE_ATTRIBUTE_KEY + "NonExisting");
trace.stop();
TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
Assert.assertEquals(TRACE_ATTRIBUTE_VALUE, trace.getAttribute(TRACE_ATTRIBUTE_KEY));
Assert.assertEquals(TRACE_1, traceMetric.getName());
Assert.assertEquals(1, traceMetric.getCustomAttributesCount());
}
use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.
the class TraceMetricBuilderTest method testAddingCountersWithStartAndStop.
@Test
public void testAddingCountersWithStartAndStop() {
Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
currentTime = 1;
trace.start();
trace.incrementMetric(METRIC_1, 1);
trace.incrementMetric(METRIC_1, 1);
trace.incrementMetric(METRIC_2, 1);
trace.incrementMetric(METRIC_2, 1);
trace.incrementMetric(METRIC_2, 1);
currentTime = 2;
trace.stop();
TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
Assert.assertEquals(TRACE_1, traceMetric.getName());
Assert.assertEquals(1, traceMetric.getClientStartTimeUs());
Assert.assertEquals(1, traceMetric.getDurationUs());
Map<String, Long> counterMap = traceMetric.getCountersMap();
Assert.assertEquals(2, counterMap.size());
Assert.assertEquals(Long.valueOf(2), counterMap.get(METRIC_1));
Assert.assertEquals(Long.valueOf(3), counterMap.get(METRIC_2));
Assert.assertEquals(0, traceMetric.getSubtracesCount());
}
use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.
the class TraceMetricBuilderTest method testIncrementingCounterByX.
@Test
public void testIncrementingCounterByX() {
Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
currentTime = 1;
trace.start();
trace.incrementMetric(METRIC_1, 5);
trace.incrementMetric(METRIC_2, 1);
trace.incrementMetric(METRIC_2, 10);
currentTime = 2;
trace.stop();
TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
Assert.assertEquals(TRACE_1, traceMetric.getName());
Assert.assertEquals(1, traceMetric.getClientStartTimeUs());
Assert.assertEquals(1, traceMetric.getDurationUs());
Map<String, Long> counterMap = traceMetric.getCountersMap();
Assert.assertEquals(2, counterMap.size());
Assert.assertEquals(Long.valueOf(5), counterMap.get(METRIC_1));
Assert.assertEquals(Long.valueOf(11), counterMap.get(METRIC_2));
Assert.assertEquals(0, traceMetric.getSubtracesCount());
}
use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.
the class TraceMetricBuilderTest method testAddingSubtraceWithStartAndStop.
@Test
public void testAddingSubtraceWithStartAndStop() {
Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
currentTime = 1;
trace.start();
currentTime = 2;
trace.startStage(TRACE_2);
currentTime = 3;
trace.stop();
TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
Assert.assertEquals(TRACE_1, traceMetric.getName());
Assert.assertEquals(1, traceMetric.getClientStartTimeUs());
Assert.assertEquals(2, traceMetric.getDurationUs());
Assert.assertEquals(0, traceMetric.getCountersCount());
TraceMetric subtrace = traceMetric.getSubtraces(0);
Assert.assertEquals(TRACE_2, subtrace.getName());
Assert.assertEquals(2, subtrace.getClientStartTimeUs());
Assert.assertEquals(1, subtrace.getDurationUs());
Assert.assertEquals(0, subtrace.getCountersCount());
Assert.assertEquals(0, subtrace.getSubtracesCount());
}
use of com.google.firebase.perf.v1.TraceMetric in project firebase-android-sdk by firebase.
the class TraceMetricBuilderTest method testAddingAttributeWithNullKey.
@Test
public void testAddingAttributeWithNullKey() {
Trace trace = new Trace(TRACE_1, transportManager, clock, appStateMonitor);
currentTime = 1;
trace.start();
currentTime = 2;
trace.putAttribute(null, TRACE_ATTRIBUTE_VALUE);
currentTime = 3;
trace.stop();
TraceMetric traceMetric = new TraceMetricBuilder(trace).build();
Assert.assertEquals(TRACE_1, traceMetric.getName());
Assert.assertEquals(0, traceMetric.getCustomAttributesCount());
}
Aggregations