Loading packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java +14 −13 Original line number Original line Diff line number Diff line Loading @@ -181,29 +181,30 @@ public class PluginInstanceTest extends SysuiTestCase { String ACTION = "testAction"; String ACTION = "testAction"; } } public void assertInstances(Integer allocated, Integer created) { private void assertInstances(int allocated, int created) { // Run the garbage collector to finalize and deallocate outstanding // If there are more than the expected number of allocated instances, then we run the // instances. Since the GC doesn't always appear to want to run // garbage collector to finalize and deallocate any outstanding non-referenced instances. // completely when we ask, we ask it 10 times in a short loop. // Since the GC doesn't always appear to want to run completely when we ask, we do this up for (int i = 0; i < 10; i++) { // to 10 times before failing the test. for (int i = 0; mCounter.getAllocatedInstances() > allocated && i < 10; i++) { System.runFinalization(); System.runFinalization(); System.gc(); System.gc(); } } mCounter.assertInstances(allocated, created); assertEquals(allocated, mCounter.getAllocatedInstances()); assertEquals(created, mCounter.getCreatedInstances()); } } public static class RefCounter { public static class RefCounter { public final AtomicInteger mAllocatedInstances = new AtomicInteger(); public final AtomicInteger mAllocatedInstances = new AtomicInteger(); public final AtomicInteger mCreatedInstances = new AtomicInteger(); public final AtomicInteger mCreatedInstances = new AtomicInteger(); public void assertInstances(Integer allocated, Integer created) { public int getAllocatedInstances() { if (allocated != null) { return mAllocatedInstances.get(); assertEquals(allocated.intValue(), mAllocatedInstances.get()); } if (created != null) { assertEquals(created.intValue(), mCreatedInstances.get()); } } public int getCreatedInstances() { return mCreatedInstances.get(); } } } } Loading Loading
packages/SystemUI/tests/src/com/android/systemui/shared/plugins/PluginInstanceTest.java +14 −13 Original line number Original line Diff line number Diff line Loading @@ -181,29 +181,30 @@ public class PluginInstanceTest extends SysuiTestCase { String ACTION = "testAction"; String ACTION = "testAction"; } } public void assertInstances(Integer allocated, Integer created) { private void assertInstances(int allocated, int created) { // Run the garbage collector to finalize and deallocate outstanding // If there are more than the expected number of allocated instances, then we run the // instances. Since the GC doesn't always appear to want to run // garbage collector to finalize and deallocate any outstanding non-referenced instances. // completely when we ask, we ask it 10 times in a short loop. // Since the GC doesn't always appear to want to run completely when we ask, we do this up for (int i = 0; i < 10; i++) { // to 10 times before failing the test. for (int i = 0; mCounter.getAllocatedInstances() > allocated && i < 10; i++) { System.runFinalization(); System.runFinalization(); System.gc(); System.gc(); } } mCounter.assertInstances(allocated, created); assertEquals(allocated, mCounter.getAllocatedInstances()); assertEquals(created, mCounter.getCreatedInstances()); } } public static class RefCounter { public static class RefCounter { public final AtomicInteger mAllocatedInstances = new AtomicInteger(); public final AtomicInteger mAllocatedInstances = new AtomicInteger(); public final AtomicInteger mCreatedInstances = new AtomicInteger(); public final AtomicInteger mCreatedInstances = new AtomicInteger(); public void assertInstances(Integer allocated, Integer created) { public int getAllocatedInstances() { if (allocated != null) { return mAllocatedInstances.get(); assertEquals(allocated.intValue(), mAllocatedInstances.get()); } if (created != null) { assertEquals(created.intValue(), mCreatedInstances.get()); } } public int getCreatedInstances() { return mCreatedInstances.get(); } } } } Loading