Merge changes I47b91c0c,I630c0e49 into main
* changes: Report sent query count Report service info callback metrics data
This commit is contained in:
@@ -141,9 +141,10 @@ class NetworkNsdReportedMetricsTest {
|
||||
val foundCallbackCount = 100
|
||||
val lostCallbackCount = 49
|
||||
val servicesCount = 75
|
||||
val sentQueryCount = 150
|
||||
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
|
||||
metrics.reportServiceDiscoveryStop(
|
||||
transactionId, durationMs, foundCallbackCount, lostCallbackCount, servicesCount)
|
||||
metrics.reportServiceDiscoveryStop(transactionId, durationMs, foundCallbackCount,
|
||||
lostCallbackCount, servicesCount, sentQueryCount)
|
||||
|
||||
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||
verify(deps).statsWrite(eventCaptor.capture())
|
||||
@@ -158,6 +159,7 @@ class NetworkNsdReportedMetricsTest {
|
||||
assertEquals(lostCallbackCount, it.lostCallbackCount)
|
||||
assertEquals(servicesCount, it.foundServiceCount)
|
||||
assertEquals(durationMs, it.eventDurationMillisec)
|
||||
assertEquals(sentQueryCount, it.sentQueryCount)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,8 +168,10 @@ class NetworkNsdReportedMetricsTest {
|
||||
val clientId = 99
|
||||
val transactionId = 100
|
||||
val durationMs = 10L
|
||||
val sentQueryCount = 0
|
||||
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
|
||||
metrics.reportServiceResolved(transactionId, durationMs, true /* isServiceFromCache */)
|
||||
metrics.reportServiceResolved(transactionId, durationMs, true /* isServiceFromCache */,
|
||||
sentQueryCount)
|
||||
|
||||
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||
verify(deps).statsWrite(eventCaptor.capture())
|
||||
@@ -179,6 +183,7 @@ class NetworkNsdReportedMetricsTest {
|
||||
assertEquals(MdnsQueryResult.MQR_SERVICE_RESOLVED, it.queryResult)
|
||||
assertTrue(it.isKnownService)
|
||||
assertEquals(durationMs, it.eventDurationMillisec)
|
||||
assertEquals(sentQueryCount, it.sentQueryCount)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,4 +226,70 @@ class NetworkNsdReportedMetricsTest {
|
||||
assertEquals(durationMs, it.eventDurationMillisec)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReportServiceInfoCallbackRegistered() {
|
||||
val clientId = 99
|
||||
val transactionId = 100
|
||||
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
|
||||
metrics.reportServiceInfoCallbackRegistered(transactionId)
|
||||
|
||||
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||
verify(deps).statsWrite(eventCaptor.capture())
|
||||
eventCaptor.value.let {
|
||||
assertFalse(it.isLegacy)
|
||||
assertEquals(clientId, it.clientId)
|
||||
assertEquals(transactionId, it.transactionId)
|
||||
assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type)
|
||||
assertEquals(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTERED, it.queryResult)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReportServiceInfoCallbackRegistrationFailed() {
|
||||
val clientId = 99
|
||||
val transactionId = 100
|
||||
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
|
||||
metrics.reportServiceInfoCallbackRegistrationFailed(transactionId)
|
||||
|
||||
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||
verify(deps).statsWrite(eventCaptor.capture())
|
||||
eventCaptor.value.let {
|
||||
assertTrue(it.isLegacy)
|
||||
assertEquals(clientId, it.clientId)
|
||||
assertEquals(transactionId, it.transactionId)
|
||||
assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type)
|
||||
assertEquals(
|
||||
MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTRATION_FAILED, it.queryResult)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testReportServiceInfoCallbackUnregistered() {
|
||||
val clientId = 99
|
||||
val transactionId = 100
|
||||
val durationMs = 10L
|
||||
val updateCallbackCount = 100
|
||||
val lostCallbackCount = 10
|
||||
val sentQueryCount = 150
|
||||
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
|
||||
metrics.reportServiceInfoCallbackUnregistered(transactionId, durationMs,
|
||||
updateCallbackCount, lostCallbackCount, false /* isServiceFromCache */,
|
||||
sentQueryCount)
|
||||
|
||||
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
|
||||
verify(deps).statsWrite(eventCaptor.capture())
|
||||
eventCaptor.value.let {
|
||||
assertFalse(it.isLegacy)
|
||||
assertEquals(clientId, it.clientId)
|
||||
assertEquals(transactionId, it.transactionId)
|
||||
assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type)
|
||||
assertEquals(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_UNREGISTERED, it.queryResult)
|
||||
assertEquals(durationMs, it.eventDurationMillisec)
|
||||
assertEquals(updateCallbackCount, it.foundCallbackCount)
|
||||
assertEquals(lostCallbackCount, it.lostCallbackCount)
|
||||
assertFalse(it.isKnownService)
|
||||
assertEquals(sentQueryCount, it.sentQueryCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -472,8 +472,8 @@ public class NsdServiceTest {
|
||||
final ArgumentCaptor<NsdServiceInfo> resInfoCaptor =
|
||||
ArgumentCaptor.forClass(NsdServiceInfo.class);
|
||||
verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(resInfoCaptor.capture());
|
||||
verify(mMetrics).reportServiceResolved(
|
||||
getAddrId, 10L /* durationMs */, false /* isServiceFromCache */);
|
||||
verify(mMetrics).reportServiceResolved(getAddrId, 10L /* durationMs */,
|
||||
false /* isServiceFromCache */, 0 /* sentQueryCount */);
|
||||
|
||||
final NsdServiceInfo resolvedService = resInfoCaptor.getValue();
|
||||
assertEquals(SERVICE_NAME, resolvedService.getServiceName());
|
||||
@@ -822,13 +822,17 @@ public class NsdServiceTest {
|
||||
client.registerServiceInfoCallback(request, Runnable::run, serviceInfoCallback);
|
||||
waitForIdle();
|
||||
// Verify the registration callback start.
|
||||
final ArgumentCaptor<MdnsServiceBrowserListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(MdnsServiceBrowserListener.class);
|
||||
final ArgumentCaptor<MdnsListener> listenerCaptor =
|
||||
ArgumentCaptor.forClass(MdnsListener.class);
|
||||
verify(mSocketProvider).startMonitoringSockets();
|
||||
verify(mDiscoveryManager).registerListener(eq(serviceTypeWithLocalDomain),
|
||||
listenerCaptor.capture(), argThat(options -> network.equals(options.getNetwork())));
|
||||
|
||||
final MdnsServiceBrowserListener listener = listenerCaptor.getValue();
|
||||
final MdnsListener listener = listenerCaptor.getValue();
|
||||
final int servInfoId = listener.mTransactionId;
|
||||
// Verify the service info callback registered.
|
||||
verify(mMetrics).reportServiceInfoCallbackRegistered(servInfoId);
|
||||
|
||||
final MdnsServiceInfo mdnsServiceInfo = new MdnsServiceInfo(
|
||||
SERVICE_NAME,
|
||||
serviceTypeWithLocalDomain.split("\\."),
|
||||
@@ -842,8 +846,11 @@ public class NsdServiceTest {
|
||||
1234,
|
||||
network);
|
||||
|
||||
// Callbacks for query sent.
|
||||
listener.onDiscoveryQuerySent(Collections.emptyList(), 1 /* transactionId */);
|
||||
|
||||
// Verify onServiceFound callback
|
||||
listener.onServiceFound(mdnsServiceInfo, false /* isServiceFromCache */);
|
||||
listener.onServiceFound(mdnsServiceInfo, true /* isServiceFromCache */);
|
||||
final ArgumentCaptor<NsdServiceInfo> updateInfoCaptor =
|
||||
ArgumentCaptor.forClass(NsdServiceInfo.class);
|
||||
verify(serviceInfoCallback, timeout(TIMEOUT_MS).times(1))
|
||||
@@ -878,10 +885,18 @@ public class NsdServiceTest {
|
||||
List.of(parseNumericAddress(v4Address), parseNumericAddress(v6Address)),
|
||||
PORT, IFACE_IDX_ANY, new Network(999));
|
||||
|
||||
// Service lost then recovered.
|
||||
listener.onServiceRemoved(updatedServiceInfo);
|
||||
listener.onServiceFound(updatedServiceInfo, false /* isServiceFromCache */);
|
||||
|
||||
// Verify service callback unregistration.
|
||||
doReturn(TEST_TIME_MS + 10L).when(mClock).elapsedRealtime();
|
||||
client.unregisterServiceInfoCallback(serviceInfoCallback);
|
||||
waitForIdle();
|
||||
verify(serviceInfoCallback, timeout(TIMEOUT_MS)).onServiceInfoCallbackUnregistered();
|
||||
verify(mMetrics).reportServiceInfoCallbackUnregistered(servInfoId, 10L /* durationMs */,
|
||||
3 /* updateCallbackCount */, 1 /* lostCallbackCount */,
|
||||
true /* isServiceFromCache */, 1 /* sentQueryCount */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -897,6 +912,7 @@ public class NsdServiceTest {
|
||||
// Fail to register service callback.
|
||||
verify(serviceInfoCallback, timeout(TIMEOUT_MS))
|
||||
.onServiceInfoCallbackRegistrationFailed(eq(FAILURE_BAD_PARAMETERS));
|
||||
verify(mMetrics).reportServiceInfoCallbackRegistrationFailed(NO_TRANSACTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -973,6 +989,11 @@ public class NsdServiceTest {
|
||||
final int discId = listener.mTransactionId;
|
||||
verify(mMetrics).reportServiceDiscoveryStarted(discId);
|
||||
|
||||
// Callbacks for query sent.
|
||||
listener.onDiscoveryQuerySent(Collections.emptyList(), 1 /* transactionId */);
|
||||
listener.onDiscoveryQuerySent(Collections.emptyList(), 2 /* transactionId */);
|
||||
listener.onDiscoveryQuerySent(Collections.emptyList(), 3 /* transactionId */);
|
||||
|
||||
final MdnsServiceInfo foundInfo = new MdnsServiceInfo(
|
||||
SERVICE_NAME, /* serviceInstanceName */
|
||||
serviceTypeWithLocalDomain.split("\\."), /* serviceType */
|
||||
@@ -1021,7 +1042,8 @@ public class NsdServiceTest {
|
||||
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStopped(SERVICE_TYPE);
|
||||
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
|
||||
verify(mMetrics).reportServiceDiscoveryStop(discId, 10L /* durationMs */,
|
||||
1 /* foundCallbackCount */, 1 /* lostCallbackCount */, 1 /* servicesCount */);
|
||||
1 /* foundCallbackCount */, 1 /* lostCallbackCount */, 1 /* servicesCount */,
|
||||
3 /* sentQueryCount */);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1133,8 +1155,8 @@ public class NsdServiceTest {
|
||||
final ArgumentCaptor<NsdServiceInfo> infoCaptor =
|
||||
ArgumentCaptor.forClass(NsdServiceInfo.class);
|
||||
verify(resolveListener, timeout(TIMEOUT_MS)).onServiceResolved(infoCaptor.capture());
|
||||
verify(mMetrics).reportServiceResolved(
|
||||
listener.mTransactionId, 10 /* durationMs */, true /* isServiceFromCache */);
|
||||
verify(mMetrics).reportServiceResolved(listener.mTransactionId, 10 /* durationMs */,
|
||||
true /* isServiceFromCache */, 0 /* sendQueryCount */);
|
||||
|
||||
final NsdServiceInfo info = infoCaptor.getValue();
|
||||
assertEquals(SERVICE_NAME, info.getServiceName());
|
||||
|
||||
Reference in New Issue
Block a user