use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method validTraceMetric_knownApplicationProcessState_getLogged.
// endregion
// region ApplicationProcessState Behaviour
@Test
public void validTraceMetric_knownApplicationProcessState_getLogged() {
TraceMetric validTrace = createValidTraceMetric();
testTransportManager.log(validTrace, ApplicationProcessState.BACKGROUND);
fakeExecutorService.runAll();
PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
assertThat(loggedPerfMetric.getTraceMetric()).isEqualTo(validTrace);
validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.BACKGROUND);
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method logMultipleGauges_transportNotInitialized_gaugesAfterMaxCapAreNotQueued.
@Test
public void logMultipleGauges_transportNotInitialized_gaugesAfterMaxCapAreNotQueued() {
// 1. Transport is not initialized in the beginning
initializeTransport(false);
// 2. Log multiple Gauges such that they are capped
// only 50 GaugeMetric events are allowed to cache
int maxGaugesCacheSize = 50;
int totalGaugeEvents = maxGaugesCacheSize + 10;
GaugeMetric[] validGauges = new GaugeMetric[totalGaugeEvents];
for (int i = 0; i < totalGaugeEvents; i++) {
validGauges[i] = createValidGaugeMetric().toBuilder().setSessionId("Session - " + (i + 1)).build();
testTransportManager.log(validGauges[i], ApplicationProcessState.FOREGROUND);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
}
// 3. Even though we recorded "totalGaugeEvents", events up-to "maxGaugesCacheSize" are only
// queued
assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(maxGaugesCacheSize);
// 4. Initialize Transport
initializeTransport(true);
// 5. Consume all queued Gauges and validate them
for (int i = 0; i < maxGaugesCacheSize; i++) {
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedValidGauge = getLastLoggedEvent(times(1));
assertThat(loggedValidGauge.getGaugeMetric()).isEqualTo(validGauges[i]);
validateApplicationInfo(loggedValidGauge, ApplicationProcessState.FOREGROUND);
}
// 6. Queue is all consumed after iterating "maxGaugesCacheSize" events
assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
// 7. No pending events
clearLastLoggedEvents();
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method validGaugeMetric_withMetadata_isLogged.
@Test
public void validGaugeMetric_withMetadata_isLogged() {
ApplicationProcessState expectedAppState = ApplicationProcessState.FOREGROUND;
GaugeMetadata gaugeMetadata = GaugeMetadata.newBuilder().setDeviceRamSizeKb(2000).setMaxAppJavaHeapMemoryKb(1000).setMaxEncouragedAppJavaHeapMemoryKb(800).build();
GaugeMetric validGauge = GaugeMetric.newBuilder().setSessionId("sessionId").setGaugeMetadata(gaugeMetadata).build();
testTransportManager.log(validGauge, expectedAppState);
fakeExecutorService.runAll();
PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
assertThat(loggedPerfMetric.getGaugeMetric().getSessionId()).isEqualTo("sessionId");
assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getDeviceRamSizeKb()).isEqualTo(2000);
assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxAppJavaHeapMemoryKb()).isEqualTo(1000);
assertThat(loggedPerfMetric.getGaugeMetric().getGaugeMetadata().getMaxEncouragedAppJavaHeapMemoryKb()).isEqualTo(800);
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method logMultipleEvents_transportNotInitialized_validEventsGetLoggedInOrderAfterInitialization.
@Test
public void logMultipleEvents_transportNotInitialized_validEventsGetLoggedInOrderAfterInitialization() {
initializeTransport(false);
TraceMetric validTrace = createValidTraceMetric();
testTransportManager.log(validTrace, ApplicationProcessState.BACKGROUND);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
TraceMetric invalidTrace = createInvalidTraceMetric();
testTransportManager.log(invalidTrace, ApplicationProcessState.BACKGROUND);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
testTransportManager.log(validNetworkRequest, ApplicationProcessState.FOREGROUND);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
NetworkRequestMetric invalidNetworkRequest = createInvalidNetworkRequestMetric();
testTransportManager.log(invalidNetworkRequest, ApplicationProcessState.FOREGROUND);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
GaugeMetric validGauge = createValidGaugeMetric();
testTransportManager.log(validGauge);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
GaugeMetric invalidGauge = createInValidGaugeMetric();
testTransportManager.log(invalidGauge);
fakeExecutorService.runAll();
assertThat(getLastLoggedEvent(never())).isNull();
assertThat(testTransportManager.getPendingEventsQueue().size()).isEqualTo(6);
initializeTransport(true);
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedValidTrace = getLastLoggedEvent(times(1));
assertThat(loggedValidTrace.getTraceMetric()).isEqualTo(validTrace);
validateApplicationInfo(loggedValidTrace, ApplicationProcessState.BACKGROUND);
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedInvalidTrace = getLastLoggedEvent(never());
assertThat(loggedInvalidTrace).isNull();
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedValidNetworkRequest = getLastLoggedEvent(times(1));
assertThat(loggedValidNetworkRequest.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
validateApplicationInfo(loggedValidNetworkRequest, ApplicationProcessState.FOREGROUND);
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedInValidNetworkRequest = getLastLoggedEvent(never());
assertThat(loggedInValidNetworkRequest).isNull();
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedValidGauge = getLastLoggedEvent(times(1));
assertThat(loggedValidGauge.getGaugeMetric()).isEqualTo(validGauge);
validateApplicationInfo(loggedValidGauge, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
clearLastLoggedEvents();
fakeExecutorService.runNext();
PerfMetric loggedInValidGauge = getLastLoggedEvent(never());
assertThat(loggedInValidGauge).isNull();
assertThat(testTransportManager.getPendingEventsQueue().isEmpty()).isTrue();
}
use of com.google.firebase.perf.v1.PerfMetric in project firebase-android-sdk by firebase.
the class TransportManagerTest method logNetworkMetric_globalCustomAttributesAreAdded.
@Test
public void logNetworkMetric_globalCustomAttributesAreAdded() {
FirebasePerformance.getInstance().putAttribute("test_key1", "test_value1");
FirebasePerformance.getInstance().putAttribute("test_key2", "test_value2");
NetworkRequestMetric validNetworkRequest = createValidNetworkRequestMetric();
testTransportManager.log(validNetworkRequest);
fakeExecutorService.runAll();
PerfMetric loggedPerfMetric = getLastLoggedEvent(times(1));
assertThat(loggedPerfMetric.getNetworkRequestMetric()).isEqualTo(validNetworkRequest);
validateApplicationInfo(loggedPerfMetric, ApplicationProcessState.APPLICATION_PROCESS_STATE_UNKNOWN);
Map<String, String> globalCustomAttributes = loggedPerfMetric.getApplicationInfo().getCustomAttributesMap();
assertThat(globalCustomAttributes).hasSize(2);
assertThat(globalCustomAttributes).containsEntry("test_key1", "test_value1");
assertThat(globalCustomAttributes).containsEntry("test_key2", "test_value2");
}
Aggregations