Merge changes I47b91c0c,I630c0e49 into main

* changes:
  Report sent query count
  Report service info callback metrics data
This commit is contained in:
Paul Hu
2023-08-25 14:46:39 +00:00
committed by Gerrit Code Review
4 changed files with 258 additions and 33 deletions

View File

@@ -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());