Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8c58677e authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Fix network stats and policy tests." into jb-dev

parents 9c982340 0cf6de0c
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_LIMIT_SNOOZED;
import static com.android.server.net.NetworkPolicyManagerService.TYPE_WARNING;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyLong;
import static org.easymock.EasyMock.aryEq;
import static org.easymock.EasyMock.capture;
import static org.easymock.EasyMock.createMock;
@@ -229,6 +230,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {

        // expect to answer screen status during systemReady()
        expect(mPowerManager.isScreenOn()).andReturn(true).atLeastOnce();
        expect(mNetworkManager.isBandwidthControlEnabled()).andReturn(true).atLeastOnce();
        expectCurrentTime();

        replay();
@@ -613,6 +615,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        expect(mConnManager.getAllNetworkState()).andReturn(state).atLeastOnce();
        expectCurrentTime();
        expectClearNotifications();
        expectAdvisePersistThreshold();
        future = expectMeteredIfacesChanged();

        replay();
@@ -637,6 +640,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        expectSetInterfaceQuota(TEST_IFACE, (2 * MB_IN_BYTES) - 512);

        expectClearNotifications();
        expectAdvisePersistThreshold();
        future = expectMeteredIfacesChanged(TEST_IFACE);

        replay();
@@ -704,6 +708,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectPolicyDataEnable(TYPE_WIFI, true);

            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged();

            replay();
@@ -730,6 +735,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectSetInterfaceQuota(TEST_IFACE, 2 * MB_IN_BYTES);

            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged(TEST_IFACE);

            replay();
@@ -794,6 +800,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            // still restricted.
            expectRemoveInterfaceQuota(TEST_IFACE);
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);
            expectAdvisePersistThreshold();
            expectMeteredIfacesChanged(TEST_IFACE);

            future = expectClearNotifications();
@@ -835,6 +842,7 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
            expectSetInterfaceQuota(TEST_IFACE, Long.MAX_VALUE);

            expectClearNotifications();
            expectAdvisePersistThreshold();
            future = expectMeteredIfacesChanged(TEST_IFACE);

            replay();
@@ -943,6 +951,11 @@ public class NetworkPolicyManagerServiceTest extends AndroidTestCase {
        return future;
    }

    private void expectAdvisePersistThreshold() throws Exception {
        mStatsService.advisePersistThreshold(anyLong());
        expectLastCall().anyTimes();
    }

    private static class TestAbstractFuture<T> extends AbstractFuture<T> {
        @Override
        public T get() throws InterruptedException, ExecutionException {
+6 −6
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {

        // verify that history read correctly
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                636014522L, 709291L, 88037144L, 518820L);
                636016770L, 709306L, 88038768L, 518836L);

        // now export into a unified format
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -70,7 +70,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {
        // and read back into structure, verifying that totals are same
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                636014522L, 709291L, 88037144L, 518820L);
                636016770L, 709306L, 88038768L, 518836L);
    }

    public void testReadLegacyUid() throws Exception {
@@ -82,7 +82,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {

        // verify that history read correctly
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                637073904L, 711398L, 88342093L, 521006L);
                637076152L, 711413L, 88343717L, 521022L);

        // now export into a unified format
        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -96,7 +96,7 @@ public class NetworkStatsCollectionTest extends AndroidTestCase {
        // and read back into structure, verifying that totals are same
        collection.read(new ByteArrayInputStream(bos.toByteArray()));
        assertSummaryTotal(collection, buildTemplateMobileAll(TEST_IMSI),
                637073904L, 711398L, 88342093L, 521006L);
                637076152L, 711413L, 88343717L, 521022L);
    }

    public void testReadLegacyUidTags() throws Exception {