From a24bb7ea72ef74aa4112edf5b664727df5c1e44d Mon Sep 17 00:00:00 2001 From: Pawel Piech Date: Wed, 20 Oct 2010 15:59:09 +0000 Subject: [PATCH] Bug 310345 - [concurrent] Asynchronous Cache Programming Model (ACPM) utilities for DSF - Removed the hidden handling of DataRequestMonitor in AbstractCache.update(). --- .../cdt/dsf/concurrent/AbstractCache.java | 5 - .../cdt/tests/dsf/concurrent/CacheTests.java | 121 +++++++----------- .../tests/dsf/concurrent/RangeCacheTests.java | 12 +- 3 files changed, 54 insertions(+), 84 deletions(-) diff --git a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/AbstractCache.java b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/AbstractCache.java index c3827309c68..21760c6ac5f 100644 --- a/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/AbstractCache.java +++ b/dsf/org.eclipse.cdt.dsf/src/org/eclipse/cdt/dsf/concurrent/AbstractCache.java @@ -156,11 +156,6 @@ public abstract class AbstractCache implements ICache { } private void completeWaitingRm(RequestMonitor rm) { - if (rm instanceof DataRequestMonitor) { - @SuppressWarnings("unchecked") - DataRequestMonitor drm = (DataRequestMonitor)rm; - drm.setData(fData); - } rm.setStatus(fStatus); rm.removeCancelListener(fRequestCanceledListener); rm.done(); diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/CacheTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/CacheTests.java index 939b3912b6a..5d269f89450 100644 --- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/CacheTests.java +++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/CacheTests.java @@ -25,6 +25,7 @@ import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ImmediateInDsfExecutor; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.concurrent.RequestCache; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.tests.dsf.TestDsfExecutor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; @@ -67,6 +68,19 @@ public class CacheTests { } + class TestQuery extends Query { + @Override + protected void execute(final DataRequestMonitor rm) { + fTestCache.update(new RequestMonitor(ImmediateExecutor.getInstance(), rm) { + @Override + protected void handleSuccess() { + rm.setData(fTestCache.getData()); + rm.done(); + } + }); + } + } + /** * There's no rule on how quickly the cache has to start data retrieval * after it has been requested. It could do it immediately, or it could @@ -158,12 +172,8 @@ public class CacheTests { @Test public void getWithCompletionInDsfThreadTest() throws InterruptedException, ExecutionException { // Request data from cache - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); + // Check initial state Assert.assertFalse(fTestCache.isValid()); @@ -200,12 +210,7 @@ public class CacheTests { Assert.assertFalse(fTestCache.isValid()); // Request data from cache - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); // Wait until the cache starts data retrieval. @@ -230,21 +235,11 @@ public class CacheTests { Assert.assertFalse(fTestCache.isValid()); // Request data from cache - Query q1 = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q1 = new TestQuery(); fExecutor.execute(q1); // Request data from cache again - Query q2 = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q2 = new TestQuery(); fExecutor.execute(q2); // Wait until the cache starts data retrieval. @@ -272,12 +267,7 @@ public class CacheTests { // Request data from cache List> qList = new ArrayList>(); for (int i = 0; i < 10; i++) { - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); qList.add(q); } @@ -413,12 +403,7 @@ public class CacheTests { @Test public void cancelWhilePendingTest() throws InterruptedException, ExecutionException { // Request data from cache - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); // Wait until the cache starts data retrieval. @@ -450,13 +435,20 @@ public class CacheTests { // Request data from cache Query q = new Query() { @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(new DataRequestMonitor(ImmediateExecutor.getInstance(), rm) { + protected void execute(final DataRequestMonitor rm) { + + fTestCache.update(new RequestMonitor(ImmediateExecutor.getInstance(), rm) { @Override public synchronized void addCancelListener(ICanceledListener listener) { // Do not add the cancel listener so that the cancel request is not // propagated to the cache. } + + @Override + protected void handleSuccess() { + rm.setData(fTestCache.getData()); + rm.done(); + } }); } }; @@ -498,12 +490,12 @@ public class CacheTests { // Create a client request with a badly behaved cancel implementation. @SuppressWarnings("unchecked") - final DataRequestMonitor[] rmBad = (DataRequestMonitor[])new DataRequestMonitor[1] ; + final RequestMonitor[] rmBad = new RequestMonitor[1] ; final boolean qBadCanceled[] = new boolean[] { false }; Query qBad = new Query() { @Override - protected void execute(DataRequestMonitor rm) { - rmBad[0] = new DataRequestMonitor(ImmediateExecutor.getInstance(), rm) { + protected void execute(final DataRequestMonitor rm) { + rmBad[0] = new RequestMonitor(ImmediateExecutor.getInstance(), rm) { @Override public synchronized void removeCancelListener(ICanceledListener listener) { // Do not add the cancel listener so that the cancel request is not @@ -526,6 +518,11 @@ public class CacheTests { public synchronized void done() { // Avoid clearing cancel listeners list }; + + protected void handleSuccess() { + rm.setData(fTestCache.getData()); + rm.done(); + }; }; fTestCache.update(rmBad[0]); @@ -545,12 +542,7 @@ public class CacheTests { } }).get(); - Query qGood = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query qGood = new TestQuery(); fExecutor.execute(qGood); // Wait until the cache starts data retrieval. @@ -577,21 +569,11 @@ public class CacheTests { @Test public void cancelWhilePendingWithTwoClientsTest() throws InterruptedException, ExecutionException { // Request data from cache - Query q1 = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q1 = new TestQuery(); fExecutor.execute(q1); // Request data from cache again - Query q2 = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q2 = new TestQuery(); fExecutor.execute(q2); @@ -632,12 +614,7 @@ public class CacheTests { // Request data from cache List> qList = new ArrayList>(); for (int i = 0; i < 10; i++) { - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); qList.add(q); } @@ -663,12 +640,7 @@ public class CacheTests { // Replace canceled requests with new ones for (int i = 0; i < toCancel.length; i++) { - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); qList.set(toCancel[i], q); assertCacheWaiting(); @@ -698,12 +670,7 @@ public class CacheTests { @Test public void resetWhileValidTest() throws InterruptedException, ExecutionException { // Request data from cache - Query q = new Query() { - @Override - protected void execute(DataRequestMonitor rm) { - fTestCache.update(rm); - } - }; + Query q = new TestQuery(); fExecutor.execute(q); // Wait until the cache starts data retrieval. diff --git a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java index e6701914a09..b9b2d46d8ff 100644 --- a/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java +++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java @@ -23,9 +23,11 @@ import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor; import org.eclipse.cdt.dsf.concurrent.DsfRunnable; import org.eclipse.cdt.dsf.concurrent.ICache; import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants; +import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor; import org.eclipse.cdt.dsf.concurrent.ImmediateInDsfExecutor; import org.eclipse.cdt.dsf.concurrent.Query; import org.eclipse.cdt.dsf.concurrent.RangeCache; +import org.eclipse.cdt.dsf.concurrent.RequestMonitor; import org.eclipse.cdt.tests.dsf.DsfTestPlugin; import org.eclipse.cdt.tests.dsf.TestDsfExecutor; import org.eclipse.core.runtime.IStatus; @@ -70,9 +72,15 @@ public class RangeCacheTests { } @Override - protected void execute(DataRequestMonitor> rm) { + protected void execute(final DataRequestMonitor> rm) { fRangeCache = fTestCache.getRange(fOffset, fCount); - fRangeCache.update(rm); + fRangeCache.update(new RequestMonitor(ImmediateExecutor.getInstance(), rm) { + @Override + protected void handleSuccess() { + rm.setData(fRangeCache.getData()); + rm.done(); + } + }); } }