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

Commit 7d98941c authored by William Escande's avatar William Escande Committed by Android (Google) Code Review
Browse files

Revert "Refactor PropertyInvalidatedCache"

This reverts commit 75f17d4f.

Reason for revert: b/373955044 test breakage. Will be verified with abtd prior to submission

Bug: 373955044
Change-Id: I75ab080acc3f11703f84c6cefb6816cc1f2a3ce9
Test: atest ServiceBluetoothTests
parent 75f17d4f
Loading
Loading
Loading
Loading
+330 −395

File changed.

Preview size limit exceeded, changes collapsed.

+12 −18
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package android.app;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;

import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;
@@ -27,7 +26,6 @@ import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

@@ -92,10 +90,11 @@ public class PropertyInvalidatedCacheTests {
        }
    }

    // Ensure all test nonces are cleared after the test ends.
    // Clear the test mode after every test, in case this process is used for other
    // tests. This also resets the test property map.
    @After
    public void tearDown() throws Exception {
        PropertyInvalidatedCache.resetAfterTest();
        PropertyInvalidatedCache.setTestMode(false);
    }

    // This test is disabled pending an sepolicy change that allows any app to set the
@@ -112,6 +111,9 @@ public class PropertyInvalidatedCacheTests {
                new PropertyInvalidatedCache<>(4, MODULE, API, "cache1",
                        new ServerQuery(tester));

        PropertyInvalidatedCache.setTestMode(true);
        testCache.testPropertyName();

        tester.verify(0);
        assertEquals(tester.value(3), testCache.query(3));
        tester.verify(1);
@@ -221,16 +223,22 @@ public class PropertyInvalidatedCacheTests {

        TestCache(String module, String api) {
            this(module, api, new TestQuery());
            setTestMode(true);
            testPropertyName();
        }

        TestCache(String module, String api, TestQuery query) {
            super(4, module, api, api, query);
            mQuery = query;
            setTestMode(true);
            testPropertyName();
        }

        public int getRecomputeCount() {
            return mQuery.getRecomputeCount();
        }


    }

    @Test
@@ -367,18 +375,4 @@ public class PropertyInvalidatedCacheTests {
            PropertyInvalidatedCache.MODULE_BLUETOOTH, "getState");
        assertEquals(n1, "cache_key.bluetooth.get_state");
    }

    // It is illegal to continue to use a cache with a test key after calling setTestMode(false).
    // This test verifies the code detects errors in calling setTestMode().
    @Test
    public void testTestMode() {
        TestCache cache = new TestCache();
        cache.invalidateCache();
        PropertyInvalidatedCache.resetAfterTest();
        try {
            cache.invalidateCache();
            fail("expected an IllegalStateException");
        } catch (IllegalStateException expected) {
        }
    }
}
+16 −19
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.os;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;

import android.multiuser.Flags;
import android.platform.test.annotations.IgnoreUnderRavenwood;
@@ -27,7 +26,6 @@ import android.platform.test.ravenwood.RavenwoodRule;
import androidx.test.filters.SmallTest;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

@@ -94,17 +92,17 @@ public class IpcDataCacheTest {
        public Boolean apply(Integer x) {
            return mServer.query(x);
        }

        @Override
        public boolean shouldBypassCache(Integer x) {
            return x % 13 == 0;
        }
    }

    // Ensure all test nonces are cleared after the test ends.
    // Clear the test mode after every test, in case this process is used for other
    // tests. This also resets the test property map.
    @After
    public void tearDown() throws Exception {
        IpcDataCache.resetAfterTest();
        IpcDataCache.setTestMode(false);
    }

    // This test is disabled pending an sepolicy change that allows any app to set the
@@ -121,6 +119,9 @@ public class IpcDataCacheTest {
                new IpcDataCache<>(4, MODULE, API, "testCache1",
                        new ServerQuery(tester));

        IpcDataCache.setTestMode(true);
        testCache.testPropertyName();

        tester.verify(0);
        assertEquals(tester.value(3), testCache.query(3));
        tester.verify(1);
@@ -164,6 +165,9 @@ public class IpcDataCacheTest {
        IpcDataCache<Integer, Boolean> testCache =
                new IpcDataCache<>(config, (x) -> tester.query(x, x % 10 == 9));

        IpcDataCache.setTestMode(true);
        testCache.testPropertyName();

        tester.verify(0);
        assertEquals(tester.value(3), testCache.query(3));
        tester.verify(1);
@@ -201,6 +205,9 @@ public class IpcDataCacheTest {
        IpcDataCache<Integer, Boolean> testCache =
                new IpcDataCache<>(config, (x) -> tester.query(x), (x) -> x % 9 == 0);

        IpcDataCache.setTestMode(true);
        testCache.testPropertyName();

        tester.verify(0);
        assertEquals(tester.value(3), testCache.query(3));
        tester.verify(1);
@@ -306,6 +313,8 @@ public class IpcDataCacheTest {
        TestCache(String module, String api, TestQuery query) {
            super(4, module, api, "testCache7", query);
            mQuery = query;
            setTestMode(true);
            testPropertyName();
        }

        TestCache(IpcDataCache.Config c) {
@@ -315,6 +324,8 @@ public class IpcDataCacheTest {
        TestCache(IpcDataCache.Config c, TestQuery query) {
            super(c, query);
            mQuery = query;
            setTestMode(true);
            testPropertyName();
        }

        int getRecomputeCount() {
@@ -445,18 +456,4 @@ public class IpcDataCacheTest {
        TestCache ec = new TestCache(e);
        assertEquals(ec.isDisabled(), true);
    }

    // It is illegal to continue to use a cache with a test key after calling setTestMode(false).
    // This test verifies the code detects errors in calling setTestMode().
    @Test
    public void testTestMode() {
        TestCache cache = new TestCache();
        cache.invalidateCache();
        IpcDataCache.resetAfterTest();
        try {
            cache.invalidateCache();
            fail("expected an IllegalStateException");
        } catch (IllegalStateException expected) {
        }
    }
}