Skip to content
Snippets Groups Projects
Commit 508a012b authored by Paul Hu's avatar Paul Hu
Browse files

Correct isLegacy metric data

The isLegacy field of Nsd metrics should indicate whether the
data was collected from the old backend or not. However, it is
currently only dependent on the ENABLE_PLATFORM_MDNS_BACKEND
compat change value, which is incorrect. This is because the
NsdService always uses the new backend since Android U,
regardless of the compat change value. Therefore, the isLegacy
data should be obtained from each transaction.

Bug: 287546772
Bug: 299880473
Test: atest FrameworksNetTestCases NsdManagerTest
Change-Id: I156abd656b90578d710696a69ccf7dfca97a2c9c
parent 3521a5ed
No related branches found
No related tags found
No related merge requests found
......@@ -34,20 +34,17 @@ public class NetworkNsdReportedMetrics {
// The upper bound for the random number used in metrics data sampling determines the possible
// sample rate.
private static final int RANDOM_NUMBER_UPPER_BOUND = 1000;
// Whether this client is using legacy backend.
private final boolean mIsLegacy;
// The client id.
private final int mClientId;
private final Dependencies mDependencies;
private final Random mRandom;
public NetworkNsdReportedMetrics(boolean isLegacy, int clientId) {
this(isLegacy, clientId, new Dependencies());
public NetworkNsdReportedMetrics(int clientId) {
this(clientId, new Dependencies());
}
@VisibleForTesting
NetworkNsdReportedMetrics(boolean isLegacy, int clientId, Dependencies dependencies) {
mIsLegacy = isLegacy;
NetworkNsdReportedMetrics(int clientId, Dependencies dependencies) {
mClientId = clientId;
mDependencies = dependencies;
mRandom = dependencies.makeRandomGenerator();
......@@ -89,23 +86,25 @@ public class NetworkNsdReportedMetrics {
}
}
private Builder makeReportedBuilder() {
private Builder makeReportedBuilder(boolean isLegacy, int transactionId) {
final Builder builder = NetworkNsdReported.newBuilder();
builder.setIsLegacy(mIsLegacy);
builder.setIsLegacy(isLegacy);
builder.setClientId(mClientId);
builder.setRandomNumber(mRandom.nextInt(RANDOM_NUMBER_UPPER_BOUND));
builder.setTransactionId(transactionId);
return builder;
}
/**
* Report service registration succeeded metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration.
* @param durationMs The duration of service registration success.
*/
public void reportServiceRegistrationSucceeded(int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceRegistrationSucceeded(boolean isLegacy, int transactionId,
long durationMs) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTERED);
builder.setEventDurationMillisec(durationMs);
......@@ -115,12 +114,13 @@ public class NetworkNsdReportedMetrics {
/**
* Report service registration failed metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration.
* @param durationMs The duration of service registration failed.
*/
public void reportServiceRegistrationFailed(int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceRegistrationFailed(boolean isLegacy, int transactionId,
long durationMs) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_REGISTRATION_FAILED);
builder.setEventDurationMillisec(durationMs);
......@@ -130,6 +130,7 @@ public class NetworkNsdReportedMetrics {
/**
* Report service unregistration success metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service registration.
* @param durationMs The duration of service stayed registered.
* @param repliedRequestsCount The replied request count of this service before unregistered it.
......@@ -137,11 +138,10 @@ public class NetworkNsdReportedMetrics {
* @param conflictDuringProbingCount The number of conflict during probing.
* @param conflictAfterProbingCount The number of conflict after probing.
*/
public void reportServiceUnregistration(int transactionId, long durationMs,
public void reportServiceUnregistration(boolean isLegacy, int transactionId, long durationMs,
int repliedRequestsCount, int sentPacketCount, int conflictDuringProbingCount,
int conflictAfterProbingCount) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_REGISTER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_UNREGISTERED);
builder.setEventDurationMillisec(durationMs);
......@@ -155,11 +155,11 @@ public class NetworkNsdReportedMetrics {
/**
* Report service discovery started metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery.
*/
public void reportServiceDiscoveryStarted(int transactionId) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceDiscoveryStarted(boolean isLegacy, int transactionId) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STARTED);
mDependencies.statsWrite(builder.build());
......@@ -168,12 +168,13 @@ public class NetworkNsdReportedMetrics {
/**
* Report service discovery failed metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery.
* @param durationMs The duration of service discovery failed.
*/
public void reportServiceDiscoveryFailed(int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceDiscoveryFailed(boolean isLegacy, int transactionId,
long durationMs) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_FAILED);
builder.setEventDurationMillisec(durationMs);
......@@ -183,6 +184,7 @@ public class NetworkNsdReportedMetrics {
/**
* Report service discovery stop metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service discovery.
* @param durationMs The duration of discovering services.
* @param foundCallbackCount The count of found service callbacks before stop discovery.
......@@ -190,10 +192,9 @@ public class NetworkNsdReportedMetrics {
* @param servicesCount The count of found services.
* @param sentQueryCount The count of sent queries before stop discovery.
*/
public void reportServiceDiscoveryStop(int transactionId, long durationMs,
public void reportServiceDiscoveryStop(boolean isLegacy, int transactionId, long durationMs,
int foundCallbackCount, int lostCallbackCount, int servicesCount, int sentQueryCount) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_DISCOVER);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_DISCOVERY_STOP);
builder.setEventDurationMillisec(durationMs);
......@@ -207,15 +208,15 @@ public class NetworkNsdReportedMetrics {
/**
* Report service resolution success metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution.
* @param durationMs The duration of resolving services.
* @param isServiceFromCache Whether the resolved service is from cache.
* @param sentQueryCount The count of sent queries during resolving.
*/
public void reportServiceResolved(int transactionId, long durationMs,
public void reportServiceResolved(boolean isLegacy, int transactionId, long durationMs,
boolean isServiceFromCache, int sentQueryCount) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLVED);
builder.setEventDurationMillisec(durationMs);
......@@ -227,12 +228,13 @@ public class NetworkNsdReportedMetrics {
/**
* Report service resolution failed metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution.
* @param durationMs The duration of service resolution failed.
*/
public void reportServiceResolutionFailed(int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceResolutionFailed(boolean isLegacy, int transactionId,
long durationMs) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_FAILED);
builder.setEventDurationMillisec(durationMs);
......@@ -242,12 +244,12 @@ public class NetworkNsdReportedMetrics {
/**
* Report service resolution stop metric data.
*
* @param isLegacy Whether this call is using legacy backend.
* @param transactionId The transaction id of service resolution.
* @param durationMs The duration before stop resolving the service.
*/
public void reportServiceResolutionStop(int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
public void reportServiceResolutionStop(boolean isLegacy, int transactionId, long durationMs) {
final Builder builder = makeReportedBuilder(isLegacy, transactionId);
builder.setType(NsdEventType.NET_RESOLVE);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_RESOLUTION_STOP);
builder.setEventDurationMillisec(durationMs);
......@@ -260,8 +262,8 @@ public class NetworkNsdReportedMetrics {
* @param transactionId The transaction id of service info callback registration.
*/
public void reportServiceInfoCallbackRegistered(int transactionId) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
// service info callback is always using new backend.
final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTERED);
mDependencies.statsWrite(builder.build());
......@@ -273,8 +275,8 @@ public class NetworkNsdReportedMetrics {
* @param transactionId The transaction id of service callback registration.
*/
public void reportServiceInfoCallbackRegistrationFailed(int transactionId) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
// service info callback is always using new backend.
final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_REGISTRATION_FAILED);
mDependencies.statsWrite(builder.build());
......@@ -293,8 +295,8 @@ public class NetworkNsdReportedMetrics {
public void reportServiceInfoCallbackUnregistered(int transactionId, long durationMs,
int updateCallbackCount, int lostCallbackCount, boolean isServiceFromCache,
int sentQueryCount) {
final Builder builder = makeReportedBuilder();
builder.setTransactionId(transactionId);
// service info callback is always using new backend.
final Builder builder = makeReportedBuilder(false /* isLegacy */, transactionId);
builder.setType(NsdEventType.NET_SERVICE_INFO_CALLBACK);
builder.setQueryResult(MdnsQueryResult.MQR_SERVICE_INFO_CALLBACK_UNREGISTERED);
builder.setEventDurationMillisec(durationMs);
......
This diff is collapsed.
......@@ -49,8 +49,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99
val transactionId = 100
val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceRegistrationSucceeded(transactionId, durationMs)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceRegistrationSucceeded(true /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -69,8 +69,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99
val transactionId = 100
val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
metrics.reportServiceRegistrationFailed(transactionId, durationMs)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceRegistrationFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -93,9 +93,10 @@ class NetworkNsdReportedMetricsTest {
val sentPacketCount = 50
val conflictDuringProbingCount = 2
val conflictAfterProbingCount = 1
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceUnregistration(transactionId, durationMs, repliedRequestsCount,
sentPacketCount, conflictDuringProbingCount, conflictAfterProbingCount)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceUnregistration(true /* isLegacy */, transactionId, durationMs,
repliedRequestsCount, sentPacketCount, conflictDuringProbingCount,
conflictAfterProbingCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -117,8 +118,8 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceDiscoveryStarted() {
val clientId = 99
val transactionId = 100
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceDiscoveryStarted(transactionId)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryStarted(true /* isLegacy */, transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -136,8 +137,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99
val transactionId = 100
val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
metrics.reportServiceDiscoveryFailed(transactionId, durationMs)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -160,9 +161,9 @@ class NetworkNsdReportedMetricsTest {
val lostCallbackCount = 49
val servicesCount = 75
val sentQueryCount = 150
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceDiscoveryStop(transactionId, durationMs, foundCallbackCount,
lostCallbackCount, servicesCount, sentQueryCount)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceDiscoveryStop(true /* isLegacy */, transactionId, durationMs,
foundCallbackCount, lostCallbackCount, servicesCount, sentQueryCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -187,9 +188,9 @@ class NetworkNsdReportedMetricsTest {
val transactionId = 100
val durationMs = 10L
val sentQueryCount = 0
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceResolved(transactionId, durationMs, true /* isServiceFromCache */,
sentQueryCount)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolved(true /* isLegacy */, transactionId, durationMs,
true /* isServiceFromCache */, sentQueryCount)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -210,8 +211,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99
val transactionId = 100
val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
metrics.reportServiceResolutionFailed(transactionId, durationMs)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolutionFailed(false /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -230,8 +231,8 @@ class NetworkNsdReportedMetricsTest {
val clientId = 99
val transactionId = 100
val durationMs = 10L
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
metrics.reportServiceResolutionStop(transactionId, durationMs)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceResolutionStop(true /* isLegacy */, transactionId, durationMs)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
......@@ -249,7 +250,7 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceInfoCallbackRegistered() {
val clientId = 99
val transactionId = 100
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackRegistered(transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
......@@ -267,13 +268,13 @@ class NetworkNsdReportedMetricsTest {
fun testReportServiceInfoCallbackRegistrationFailed() {
val clientId = 99
val transactionId = 100
val metrics = NetworkNsdReportedMetrics(true /* isLegacy */, clientId, deps)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackRegistrationFailed(transactionId)
val eventCaptor = ArgumentCaptor.forClass(NetworkNsdReported::class.java)
verify(deps).statsWrite(eventCaptor.capture())
eventCaptor.value.let {
assertTrue(it.isLegacy)
assertFalse(it.isLegacy)
assertEquals(clientId, it.clientId)
assertEquals(transactionId, it.transactionId)
assertEquals(NsdEventType.NET_SERVICE_INFO_CALLBACK, it.type)
......@@ -290,7 +291,7 @@ class NetworkNsdReportedMetricsTest {
val updateCallbackCount = 100
val lostCallbackCount = 10
val sentQueryCount = 150
val metrics = NetworkNsdReportedMetrics(false /* isLegacy */, clientId, deps)
val metrics = NetworkNsdReportedMetrics(clientId, deps)
metrics.reportServiceInfoCallbackUnregistered(transactionId, durationMs,
updateCallbackCount, lostCallbackCount, false /* isServiceFromCache */,
sentQueryCount)
......
......@@ -49,7 +49,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.argThat;
......@@ -227,7 +226,7 @@ public class NsdServiceTest {
doReturn(DEFAULT_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF).when(mDeps).getDeviceConfigInt(
eq(NsdService.MDNS_CONFIG_RUNNING_APP_ACTIVE_IMPORTANCE_CUTOFF), anyInt());
doReturn(mAdvertiser).when(mDeps).makeMdnsAdvertiser(any(), any(), any(), any(), any());
doReturn(mMetrics).when(mDeps).makeNetworkNsdReportedMetrics(anyBoolean(), anyInt());
doReturn(mMetrics).when(mDeps).makeNetworkNsdReportedMetrics(anyInt());
doReturn(mClock).when(mDeps).makeClock();
doReturn(TEST_TIME_MS).when(mClock).elapsedRealtime();
mService = makeService();
......@@ -412,7 +411,7 @@ public class NsdServiceTest {
// this needs to use a timeout
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId);
verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
final DiscoveryInfo discoveryInfo = new DiscoveryInfo(
discId,
......@@ -481,7 +480,7 @@ 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 */,
verify(mMetrics).reportServiceResolved(true /* isLegacy */, getAddrId, 10L /* durationMs */,
false /* isServiceFromCache */, 0 /* sentQueryCount */);
final NsdServiceInfo resolvedService = resInfoCaptor.getValue();
......@@ -509,7 +508,7 @@ public class NsdServiceTest {
// this needs to use a timeout
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId);
verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
final DiscoveryInfo discoveryInfo = new DiscoveryInfo(
discId,
......@@ -559,7 +558,8 @@ public class NsdServiceTest {
.onServiceRegistered(registeredInfoCaptor.capture());
final NsdServiceInfo registeredInfo = registeredInfoCaptor.getValue();
assertEquals(SERVICE_NAME, registeredInfo.getServiceName());
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */);
verify(mMetrics).reportServiceRegistrationSucceeded(
true /* isLegacy */, regId, 10L /* durationMs */);
// Fail to register service.
final RegistrationInfo registrationFailedInfo = new RegistrationInfo(
......@@ -574,7 +574,8 @@ public class NsdServiceTest {
eventListener.onServiceRegistrationStatus(registrationFailedInfo);
verify(regListener, timeout(TIMEOUT_MS))
.onRegistrationFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceRegistrationFailed(regId, 20L /* durationMs */);
verify(mMetrics).reportServiceRegistrationFailed(
true /* isLegacy */, regId, 20L /* durationMs */);
}
@Test
......@@ -590,7 +591,7 @@ public class NsdServiceTest {
verify(mMockMDnsM).discover(discIdCaptor.capture(), eq(SERVICE_TYPE), eq(IFACE_IDX_ANY));
verify(discListener, timeout(TIMEOUT_MS)).onDiscoveryStarted(SERVICE_TYPE);
final int discId = discIdCaptor.getValue();
verify(mMetrics).reportServiceDiscoveryStarted(discId);
verify(mMetrics).reportServiceDiscoveryStarted(true /* isLegacy */, discId);
// Fail to discover service.
final DiscoveryInfo discoveryFailedInfo = new DiscoveryInfo(
......@@ -605,7 +606,8 @@ public class NsdServiceTest {
eventListener.onServiceDiscoveryStatus(discoveryFailedInfo);
verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(SERVICE_TYPE, FAILURE_INTERNAL_ERROR);
verify(mMetrics).reportServiceDiscoveryFailed(discId, 10L /* durationMs */);
verify(mMetrics).reportServiceDiscoveryFailed(
true /* isLegacy */, discId, 10L /* durationMs */);
}
@Test
......@@ -639,7 +641,8 @@ public class NsdServiceTest {
eventListener.onServiceResolutionStatus(resolutionFailedInfo);
verify(resolveListener, timeout(TIMEOUT_MS))
.onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceResolutionFailed(resolvId, 10L /* durationMs */);
verify(mMetrics).reportServiceResolutionFailed(
true /* isLegacy */, resolvId, 10L /* durationMs */);
}
@Test
......@@ -689,7 +692,8 @@ public class NsdServiceTest {
eventListener.onGettingServiceAddressStatus(gettingAddrFailedInfo);
verify(resolveListener, timeout(TIMEOUT_MS))
.onResolveFailed(any(), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceResolutionFailed(getAddrId, 10L /* durationMs */);
verify(mMetrics).reportServiceResolutionFailed(
true /* isLegacy */, getAddrId, 10L /* durationMs */);
}
@Test
......@@ -734,7 +738,8 @@ public class NsdServiceTest {
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType())));
verify(mMetrics).reportServiceResolutionStop(resolveId, 10L /* durationMs */);
verify(mMetrics).reportServiceResolutionStop(
true /* isLegacy */, resolveId, 10L /* durationMs */);
}
@Test
......@@ -805,7 +810,8 @@ public class NsdServiceTest {
verify(resolveListener, timeout(TIMEOUT_MS)).onResolutionStopped(argThat(ns ->
request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType())));
verify(mMetrics).reportServiceResolutionStop(getAddrId, 10L /* durationMs */);
verify(mMetrics).reportServiceResolutionStop(
true /* isLegacy */, getAddrId, 10L /* durationMs */);
}
private void verifyUpdatedServiceInfo(NsdServiceInfo info, String serviceName,
......@@ -996,7 +1002,7 @@ public class NsdServiceTest {
final MdnsListener listener = listenerCaptor.getValue();
final int discId = listener.mTransactionId;
verify(mMetrics).reportServiceDiscoveryStarted(discId);
verify(mMetrics).reportServiceDiscoveryStarted(false /* isLegacy */, discId);
// Callbacks for query sent.
listener.onDiscoveryQuerySent(Collections.emptyList(), 1 /* transactionId */);
......@@ -1050,9 +1056,9 @@ public class NsdServiceTest {
verify(mDiscoveryManager).unregisterListener(eq(serviceTypeWithLocalDomain), any());
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 */,
3 /* sentQueryCount */);
verify(mMetrics).reportServiceDiscoveryStop(false /* isLegacy */, discId,
10L /* durationMs */, 1 /* foundCallbackCount */, 1 /* lostCallbackCount */,
1 /* servicesCount */, 3 /* sentQueryCount */);
}
@Test
......@@ -1068,8 +1074,8 @@ public class NsdServiceTest {
waitForIdle();
verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(invalidServiceType, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(1))
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */);
verify(mMetrics, times(1)).reportServiceDiscoveryFailed(
false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
final String serviceTypeWithLocalDomain = SERVICE_TYPE + ".local";
client.discoverServices(
......@@ -1077,8 +1083,8 @@ public class NsdServiceTest {
waitForIdle();
verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(serviceTypeWithLocalDomain, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(2))
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */);
verify(mMetrics, times(2)).reportServiceDiscoveryFailed(
false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
final String serviceTypeWithoutTcpOrUdpEnding = "_test._com";
client.discoverServices(
......@@ -1086,8 +1092,8 @@ public class NsdServiceTest {
waitForIdle();
verify(discListener, timeout(TIMEOUT_MS))
.onStartDiscoveryFailed(serviceTypeWithoutTcpOrUdpEnding, FAILURE_INTERNAL_ERROR);
verify(mMetrics, times(3))
.reportServiceDiscoveryFailed(NO_TRANSACTION, 0L /* durationMs */);
verify(mMetrics, times(3)).reportServiceDiscoveryFailed(
false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
}
@Test
......@@ -1164,8 +1170,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 */, 0 /* sendQueryCount */);
verify(mMetrics).reportServiceResolved(false /* isLegacy */, listener.mTransactionId,
10 /* durationMs */, true /* isServiceFromCache */, 0 /* sendQueryCount */);
final NsdServiceInfo info = infoCaptor.getValue();
assertEquals(SERVICE_NAME, info.getServiceName());
......@@ -1309,7 +1315,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered(argThat(info -> matches(info,
new NsdServiceInfo(regInfo.getServiceName(), null))));
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */);
verify(mMetrics).reportServiceRegistrationSucceeded(
false /* isLegacy */, regId, 10L /* durationMs */);
final MdnsAdvertiser.AdvertiserMetrics metrics = new MdnsAdvertiser.AdvertiserMetrics(
50 /* repliedRequestCount */, 100 /* sentPacketCount */,
......@@ -1322,8 +1329,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceUnregistered(
argThat(info -> matches(info, regInfo)));
verify(mSocketProvider, timeout(TIMEOUT_MS)).requestStopWhenInactive();
verify(mMetrics).reportServiceUnregistration(regId, 100L /* durationMs */,
50 /* repliedRequestCount */, 100 /* sentPacketCount */,
verify(mMetrics).reportServiceUnregistration(false /* isLegacy */, regId,
100L /* durationMs */, 50 /* repliedRequestCount */, 100 /* sentPacketCount */,
3 /* conflictDuringProbingCount */, 2 /* conflictAfterProbingCount */);
}
......@@ -1350,7 +1357,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onRegistrationFailed(
argThat(info -> matches(info, regInfo)), eq(FAILURE_INTERNAL_ERROR));
verify(mMetrics).reportServiceRegistrationFailed(NO_TRANSACTION, 0L /* durationMs */);
verify(mMetrics).reportServiceRegistrationFailed(
false /* isLegacy */, NO_TRANSACTION, 0L /* durationMs */);
}
@Test
......@@ -1386,7 +1394,8 @@ public class NsdServiceTest {
verify(regListener, timeout(TIMEOUT_MS)).onServiceRegistered(
argThat(info -> matches(info, new NsdServiceInfo(regInfo.getServiceName(), null))));
verify(mMetrics).reportServiceRegistrationSucceeded(regId, 10L /* durationMs */);
verify(mMetrics).reportServiceRegistrationSucceeded(
false /* isLegacy */, regId, 10L /* durationMs */);
}
@Test
......@@ -1426,7 +1435,8 @@ public class NsdServiceTest {
request.getServiceName().equals(ns.getServiceName())
&& request.getServiceType().equals(ns.getServiceType())));
verify(mSocketProvider, timeout(CLEANUP_DELAY_MS + TIMEOUT_MS)).requestStopWhenInactive();
verify(mMetrics).reportServiceResolutionStop(listener.mTransactionId, 10L /* durationMs */);
verify(mMetrics).reportServiceResolutionStop(
false /* isLegacy */, listener.mTransactionId, 10L /* durationMs */);
}
@Test
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment