Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2010-10-20 15:59:09 +0000
committerPawel Piech2010-10-20 15:59:09 +0000
commita24bb7ea72ef74aa4112edf5b664727df5c1e44d (patch)
tree36ac1cb880ec08aa3b55a6224d80327a44fe85de /dsf/org.eclipse.cdt.tests.dsf
parentea02d217d54e03c5258d9bece171d5d6d360906b (diff)
downloadorg.eclipse.cdt-a24bb7ea72ef74aa4112edf5b664727df5c1e44d.tar.gz
org.eclipse.cdt-a24bb7ea72ef74aa4112edf5b664727df5c1e44d.tar.xz
org.eclipse.cdt-a24bb7ea72ef74aa4112edf5b664727df5c1e44d.zip
Bug 310345 - [concurrent] Asynchronous Cache Programming Model (ACPM) utilities for DSF
- Removed the hidden handling of DataRequestMonitor in AbstractCache.update().
Diffstat (limited to 'dsf/org.eclipse.cdt.tests.dsf')
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/CacheTests.java121
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java12
2 files changed, 54 insertions, 79 deletions
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 939b3912b6..5d269f8945 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<Integer> {
+ @Override
+ protected void execute(final DataRequestMonitor<Integer> 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<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q1 = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> q1 = new TestQuery();
fExecutor.execute(q1);
// Request data from cache again
- Query<Integer> q2 = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Query<Integer>> qList = new ArrayList<Query<Integer>>();
for (int i = 0; i < 10; i++) {
- Query<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q = new Query<Integer>() {
@Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), rm) {
+ protected void execute(final DataRequestMonitor<Integer> 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<Integer>[] rmBad = (DataRequestMonitor<Integer>[])new DataRequestMonitor<?>[1] ;
+ final RequestMonitor[] rmBad = new RequestMonitor[1] ;
final boolean qBadCanceled[] = new boolean[] { false };
Query<Integer> qBad = new Query<Integer>() {
@Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- rmBad[0] = new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), rm) {
+ protected void execute(final DataRequestMonitor<Integer> 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<Integer> qGood = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q1 = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> q1 = new TestQuery();
fExecutor.execute(q1);
// Request data from cache again
- Query<Integer> q2 = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> q2 = new TestQuery();
fExecutor.execute(q2);
@@ -632,12 +614,7 @@ public class CacheTests {
// Request data from cache
List<Query<Integer>> qList = new ArrayList<Query<Integer>>();
for (int i = 0; i < 10; i++) {
- Query<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
+ Query<Integer> 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 e6701914a0..b9b2d46d8f 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<List<Integer>> rm) {
+ protected void execute(final DataRequestMonitor<List<Integer>> 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();
+ }
+ });
}
}

Back to the top