Search in sources :

Example 6 with DnsEvent

use of android.net.metrics.DnsEvent in project android_frameworks_base by ResurrectionRemix.

the class NetdEventListenerServiceTest method verifyLoggedDnsEvents.

void verifyLoggedDnsEvents(int wait, DnsEvent... expectedEvents) {
    verify(mLog, timeout(wait).times(expectedEvents.length)).log(mDnsEvCaptor.capture());
    for (DnsEvent got : mDnsEvCaptor.getAllValues()) {
        OptionalInt index = IntStream.range(0, expectedEvents.length).filter(i -> dnsEventsEqual(expectedEvents[i], got)).findFirst();
        // Don't match same expected event more than once.
        index.ifPresent(i -> expectedEvents[i] = null);
        assertTrue(index.isPresent());
    }
}
Also used : IntStream(java.util.stream.IntStream) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) Arrays(java.util.Arrays) IpConnectivityEvent(com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) DnsEvent(android.net.metrics.DnsEvent) RemoteException(android.os.RemoteException) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.timeout(org.mockito.Mockito.timeout) IpConnectivityLog(android.net.metrics.IpConnectivityLog) ArgumentCaptor(org.mockito.ArgumentCaptor) INetdEventListener(android.net.metrics.INetdEventListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestCase(junit.framework.TestCase) Before(org.junit.Before) ConnectivityManager(android.net.ConnectivityManager) PrintWriter(java.io.PrintWriter) OsConstants(android.system.OsConstants) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Network(android.net.Network) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.anyInt(org.mockito.Mockito.anyInt) Comparator(java.util.Comparator) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) OptionalInt(java.util.OptionalInt) DnsEvent(android.net.metrics.DnsEvent)

Example 7 with DnsEvent

use of android.net.metrics.DnsEvent in project android_frameworks_base by DirtyUnicorns.

the class NetdEventListenerServiceTest method testConcurrentDnsBatchesAndDumps.

@SmallTest
public void testConcurrentDnsBatchesAndDumps() throws Exception {
    final long stop = System.currentTimeMillis() + 100;
    final PrintWriter pw = new PrintWriter(new FileOutputStream("/dev/null"));
    new Thread() {

        public void run() {
            while (System.currentTimeMillis() < stop) {
                mNetdEventListenerService.dump(pw);
            }
        }
    }.start();
    logDnsAsync(105, LATENCIES);
    logDnsAsync(106, LATENCIES);
    logDnsAsync(107, LATENCIES);
    verifyLoggedDnsEvents(500, new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(106, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(107, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
Also used : FileOutputStream(java.io.FileOutputStream) PrintWriter(java.io.PrintWriter) DnsEvent(android.net.metrics.DnsEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 8 with DnsEvent

use of android.net.metrics.DnsEvent in project android_frameworks_base by DirtyUnicorns.

the class NetdEventListenerServiceTest method testDnsBatchAndNetworkLost.

@SmallTest
public void testDnsBatchAndNetworkLost() throws Exception {
    byte[] eventTypes = Arrays.copyOf(EVENT_TYPES, 20);
    byte[] returnCodes = Arrays.copyOf(RETURN_CODES, 20);
    int[] latencies = Arrays.copyOf(LATENCIES, 20);
    log(105, LATENCIES);
    log(105, latencies);
    mCallbackCaptor.getValue().onLost(new Network(105));
    log(105, LATENCIES);
    verifyLoggedDnsEvents(new DnsEvent(105, eventTypes, returnCodes, latencies), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
Also used : Network(android.net.Network) DnsEvent(android.net.metrics.DnsEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 9 with DnsEvent

use of android.net.metrics.DnsEvent in project android_frameworks_base by DirtyUnicorns.

the class NetdEventListenerServiceTest method testOneDnsBatch.

@SmallTest
public void testOneDnsBatch() throws Exception {
    log(105, LATENCIES);
    // one lookup short of a batch event
    log(106, Arrays.copyOf(LATENCIES, BATCH_SIZE - 1));
    verifyLoggedDnsEvents(new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES));
    log(106, Arrays.copyOfRange(LATENCIES, BATCH_SIZE - 1, BATCH_SIZE));
    // reset argument captor
    mDnsEvCaptor = ArgumentCaptor.forClass(DnsEvent.class);
    verifyLoggedDnsEvents(new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(106, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
Also used : DnsEvent(android.net.metrics.DnsEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 10 with DnsEvent

use of android.net.metrics.DnsEvent in project android_frameworks_base by DirtyUnicorns.

the class NetdEventListenerServiceTest method verifyLoggedDnsEvents.

void verifyLoggedDnsEvents(int wait, DnsEvent... expectedEvents) {
    verify(mLog, timeout(wait).times(expectedEvents.length)).log(mDnsEvCaptor.capture());
    for (DnsEvent got : mDnsEvCaptor.getAllValues()) {
        OptionalInt index = IntStream.range(0, expectedEvents.length).filter(i -> dnsEventsEqual(expectedEvents[i], got)).findFirst();
        // Don't match same expected event more than once.
        index.ifPresent(i -> expectedEvents[i] = null);
        assertTrue(index.isPresent());
    }
}
Also used : IntStream(java.util.stream.IntStream) NetworkCallback(android.net.ConnectivityManager.NetworkCallback) Arrays(java.util.Arrays) IpConnectivityEvent(com.android.server.connectivity.metrics.IpConnectivityLogClass.IpConnectivityEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) DnsEvent(android.net.metrics.DnsEvent) RemoteException(android.os.RemoteException) OptionalInt(java.util.OptionalInt) ArrayList(java.util.ArrayList) MockitoAnnotations(org.mockito.MockitoAnnotations) Mockito.timeout(org.mockito.Mockito.timeout) IpConnectivityLog(android.net.metrics.IpConnectivityLog) ArgumentCaptor(org.mockito.ArgumentCaptor) INetdEventListener(android.net.metrics.INetdEventListener) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) TestCase(junit.framework.TestCase) Before(org.junit.Before) ConnectivityManager(android.net.ConnectivityManager) PrintWriter(java.io.PrintWriter) OsConstants(android.system.OsConstants) FileOutputStream(java.io.FileOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Network(android.net.Network) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) List(java.util.List) Mockito.anyInt(org.mockito.Mockito.anyInt) Comparator(java.util.Comparator) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) OptionalInt(java.util.OptionalInt) DnsEvent(android.net.metrics.DnsEvent)

Aggregations

DnsEvent (android.net.metrics.DnsEvent)20 SmallTest (android.test.suitebuilder.annotation.SmallTest)20 Network (android.net.Network)8 FileOutputStream (java.io.FileOutputStream)8 PrintWriter (java.io.PrintWriter)8 ConnectivityManager (android.net.ConnectivityManager)4 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)4 INetdEventListener (android.net.metrics.INetdEventListener)4 IpConnectivityLog (android.net.metrics.IpConnectivityLog)4 RemoteException (android.os.RemoteException)4 Arrays (java.util.Arrays)4 List (java.util.List)4 OptionalInt (java.util.OptionalInt)4 IntStream (java.util.stream.IntStream)4 TestCase (junit.framework.TestCase)4 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Before (org.junit.Before)4 Test (org.junit.Test)4 ArgumentCaptor (org.mockito.ArgumentCaptor)4