Search in sources :

Example 1 with DnsEvent

use of android.net.metrics.DnsEvent in project platform_frameworks_base by android.

the class NetdEventListenerServiceTest method testConcurrentBatchesAndDumps.

@SmallTest
public void testConcurrentBatchesAndDumps() 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();
    logAsync(105, LATENCIES);
    logAsync(106, LATENCIES);
    logAsync(107, LATENCIES);
    verifyLoggedEvents(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 2 with DnsEvent

use of android.net.metrics.DnsEvent in project platform_frameworks_base by android.

the class NetdEventListenerServiceTest method testSeveralBatches.

@SmallTest
public void testSeveralBatches() throws Exception {
    log(105, LATENCIES);
    log(106, LATENCIES);
    log(105, LATENCIES);
    log(107, LATENCIES);
    verifyLoggedEvents(new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(106, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(105, EVENT_TYPES, RETURN_CODES, LATENCIES), new DnsEvent(107, EVENT_TYPES, RETURN_CODES, LATENCIES));
}
Also used : DnsEvent(android.net.metrics.DnsEvent) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 3 with DnsEvent

use of android.net.metrics.DnsEvent in project platform_frameworks_base by android.

the class NetdEventListenerServiceTest method verifyLoggedEvents.

void verifyLoggedEvents(int wait, DnsEvent... expectedEvents) {
    verify(mLog, timeout(wait).times(expectedEvents.length)).log(mEvCaptor.capture());
    for (DnsEvent got : mEvCaptor.getAllValues()) {
        OptionalInt index = IntStream.range(0, expectedEvents.length).filter(i -> eventsEqual(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) SmallTest(android.test.suitebuilder.annotation.SmallTest) Mock(org.mockito.Mock) DnsEvent(android.net.metrics.DnsEvent) RemoteException(android.os.RemoteException) OptionalInt(java.util.OptionalInt) 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) Assert.assertTrue(org.junit.Assert.assertTrue) FileOutputStream(java.io.FileOutputStream) 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) Mockito.any(org.mockito.Mockito.any) Mockito.eq(org.mockito.Mockito.eq) OptionalInt(java.util.OptionalInt) DnsEvent(android.net.metrics.DnsEvent)

Example 4 with DnsEvent

use of android.net.metrics.DnsEvent in project platform_frameworks_base by android.

the class NetdEventListenerServiceTest method testBatchAndNetworkLost.

@SmallTest
public void testBatchAndNetworkLost() 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);
    verifyLoggedEvents(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 5 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)

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