Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPawel Piech2010-10-19 21:20:56 +0000
committerPawel Piech2010-10-19 21:20:56 +0000
commita56f1006bda417474544e566a577a1778fba41a4 (patch)
tree6418c5b63ef7be010d4bd2b6f5d36d0572165a13 /dsf/org.eclipse.cdt.tests.dsf
parent432a6010a8551166483e3975dc9d70950ea4cc45 (diff)
downloadorg.eclipse.cdt-a56f1006bda417474544e566a577a1778fba41a4.tar.gz
org.eclipse.cdt-a56f1006bda417474544e566a577a1778fba41a4.tar.xz
org.eclipse.cdt-a56f1006bda417474544e566a577a1778fba41a4.zip
Bug 310345 - [concurrent] Asynchronous Cache Programming Model (ACPM) utilities for DSF
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.java304
-rw-r--r--dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java407
2 files changed, 617 insertions, 94 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 6923e5b1e3e..939b3912b6a 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
@@ -61,11 +61,6 @@ public class CacheTests {
}
@Override
- public void reset(Integer data, IStatus status) {
- super.reset(data, status);
- }
-
- @Override
public void set(Integer data, IStatus status) {
super.set(data, status);
}
@@ -117,6 +112,18 @@ public class CacheTests {
private void assertCacheResetWithoutData() {
Assert.assertFalse(fTestCache.isValid());
+ try {
+ fTestCache.getData();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ try {
+ fTestCache.getStatus();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ }
+
+ private void assertCacheDisabledWithoutData() {
+ Assert.assertTrue(fTestCache.isValid());
Assert.assertEquals(null, fTestCache.getData());
Assert.assertFalse(fTestCache.getStatus().isOK());
Assert.assertEquals(fTestCache.getStatus().getCode(), IDsfStatusConstants.INVALID_STATE);
@@ -124,17 +131,27 @@ public class CacheTests {
private void assertCacheWaiting() {
Assert.assertFalse(fTestCache.isValid());
- Assert.assertEquals(null, fTestCache.getData());
- Assert.assertFalse(fTestCache.getStatus().isOK());
- Assert.assertEquals(fTestCache.getStatus().getCode(), IDsfStatusConstants.INVALID_STATE);
+ try {
+ fTestCache.getData();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ try {
+ fTestCache.getStatus();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
Assert.assertFalse(fRetrieveRm.isCanceled());
}
private void assertCacheCanceled() {
Assert.assertFalse(fTestCache.isValid());
- Assert.assertEquals(null, fTestCache.getData());
- Assert.assertFalse(fTestCache.getStatus().isOK());
- Assert.assertEquals(fTestCache.getStatus().getCode(), IDsfStatusConstants.INVALID_STATE);
+ try {
+ fTestCache.getData();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ try {
+ fTestCache.getStatus();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
Assert.assertTrue(fRetrieveRm.isCanceled());
}
@@ -149,8 +166,6 @@ public class CacheTests {
};
// Check initial state
Assert.assertFalse(fTestCache.isValid());
- Assert.assertFalse(fTestCache.getStatus().isOK());
- Assert.assertEquals(fTestCache.getStatus().getCode(), IDsfStatusConstants.INVALID_STATE);
fExecutor.execute(q);
@@ -284,6 +299,103 @@ public class CacheTests {
assertCacheValidWithData(1);
}
+// @Test
+// public void disableBeforeRequestTest() throws InterruptedException, ExecutionException {
+// // Disable the cache with a given value
+// fExecutor.submit(new DsfRunnable() {
+// public void run() {
+// fTestCache.disable();
+// }
+// }).get();
+//
+// assertCacheDisabledWithoutData();
+//
+// // Try to request data from cache
+// Query<Integer> q = new Query<Integer>() {
+// @Override
+// protected void execute(DataRequestMonitor<Integer> rm) {
+// fTestCache.request(rm);
+// }
+// };
+// fExecutor.execute(q);
+//
+// Thread.sleep(100);
+//
+// // Retrieval should never have been made.
+// Assert.assertEquals(null, fRetrieveRm);
+//
+// try {
+// Assert.assertEquals(null, q.get());
+// } catch (ExecutionException e) {
+// // expected the exception
+// return;
+// }
+// Assert.fail("expected an exeption");
+// }
+//
+// @Test
+// public void disableWhilePendingTest() throws InterruptedException, ExecutionException {
+// // Request data from cache
+// Query<Integer> q = new Query<Integer>() {
+// @Override
+// protected void execute(DataRequestMonitor<Integer> rm) {
+// fTestCache.request(rm);
+// }
+// };
+// fExecutor.execute(q);
+//
+// // Disable the cache with a given value
+// fExecutor.submit(new DsfRunnable() {
+// public void run() {
+// fTestCache.disable();
+// }
+// }).get();
+//
+// assertCacheDisabledWithoutData();
+//
+// // Completed the retrieve RM
+// fExecutor.submit(new DsfRunnable() {
+// public void run() {
+// fRetrieveRm.setData(1);
+// fRetrieveRm.done();
+// }
+// }).get();
+//
+// // Validate that cache is still disabled without data.
+// assertCacheDisabledWithoutData();
+// }
+//
+// @Test
+// public void disableWhileValidTest() throws InterruptedException, ExecutionException {
+// // Request data from cache
+// Query<Integer> q = new Query<Integer>() {
+// @Override
+// protected void execute(DataRequestMonitor<Integer> rm) {
+// fTestCache.request(rm);
+// }
+// };
+// fExecutor.execute(q);
+//
+// // Wait until the cache starts data retrieval.
+// waitForRetrieveRm();
+//
+// // Complete the request
+// fRetrieveRm.setData(1);
+// fRetrieveRm.done();
+//
+// q.get();
+//
+// // Disable cache
+// fExecutor.submit(new DsfRunnable() {
+// public void run() {
+// fTestCache.disable();
+// }
+// }).get();
+//
+// // Check final state
+// assertCacheValidWithData(1);
+// }
+
@Test
public void disableWithValueTest() throws InterruptedException, ExecutionException {
// Disable the cache with a given value
@@ -297,42 +409,9 @@ public class CacheTests {
assertCacheValidWithData(2);
}
-
- @Test
- public void resetBeforeRequestTest() throws InterruptedException, ExecutionException {
- // Disable the cache with a given value
- fExecutor.submit(new DsfRunnable() {
- public void run() {
- fTestCache.reset();
- }
- }).get();
-
- assertCacheResetWithoutData();
-
- // Try to request data from cache (check that cache still works normally)
- Query<Integer> q = new Query<Integer>() {
- @Override
- protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
- }
- };
- fExecutor.execute(q);
-
- // Wait until the cache starts data retrieval.
- waitForRetrieveRm();
-
- // Complete the request
- fRetrieveRm.setData(1);
- fRetrieveRm.done();
-
- // Check result
- Assert.assertEquals(1, (int)q.get());
-
- assertCacheValidWithData(1);
- }
@Test
- public void resetWhilePendingTest() throws InterruptedException, ExecutionException {
+ public void cancelWhilePendingTest() throws InterruptedException, ExecutionException {
// Request data from cache
Query<Integer> q = new Query<Integer>() {
@Override
@@ -344,16 +423,16 @@ public class CacheTests {
// Wait until the cache starts data retrieval.
waitForRetrieveRm();
+
+ // Cancel the client request
+ q.cancel(true);
+ try {
+ q.get();
+ Assert.fail("Expected a cancellation exception");
+ } catch (CancellationException e) {} // Expected exception;
- // Disable the cache with a given value
- fExecutor.submit(new DsfRunnable() {
- public void run() {
- fTestCache.reset();
- }
- }).get();
-
- assertCacheResetWithoutData();
-
+ assertCacheCanceled();
+
// Completed the retrieve RM
fExecutor.submit(new DsfRunnable() {
public void run() {
@@ -361,18 +440,24 @@ public class CacheTests {
fRetrieveRm.done();
}
}).get();
-
- // Validate that cache is still disabled without data.
- assertCacheResetWithoutData();
+
+ // Validate that cache accepts the canceled request data
+ assertCacheValidWithData(1);
}
@Test
- public void cancelWhilePendingTest() throws InterruptedException, ExecutionException {
+ public void cancelWhilePendingWithoutClientNotificationTest() throws InterruptedException, ExecutionException {
// Request data from cache
Query<Integer> q = new Query<Integer>() {
@Override
protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(rm);
+ fTestCache.update(new DataRequestMonitor<Integer>(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.
+ }
+ });
}
};
fExecutor.execute(q);
@@ -382,12 +467,13 @@ public class CacheTests {
// Cancel the client request
q.cancel(true);
+
+ assertCacheCanceled();
+
try {
q.get();
Assert.fail("Expected a cancellation exception");
} catch (CancellationException e) {} // Expected exception;
-
- assertCacheCanceled();
// Completed the retrieve RM
fExecutor.submit(new DsfRunnable() {
@@ -401,36 +487,80 @@ public class CacheTests {
assertCacheValidWithData(1);
}
+ /**
+ * This test forces a race condition where a client that requested data
+ * cancels. While shortly after a second client starts a new request.
+ * The first request's cancel should not interfere with the second
+ * request.
+ */
@Test
- public void cancelWhilePendingWithoutClientNotificationTest() throws InterruptedException, ExecutionException {
- // Request data from cache
- Query<Integer> q = new Query<Integer>() {
+ public void cancelAfterCompletedRaceCondition() throws InterruptedException, ExecutionException {
+
+ // Create a client request with a badly behaved cancel implementation.
+ @SuppressWarnings("unchecked")
+ final DataRequestMonitor<Integer>[] rmBad = (DataRequestMonitor<Integer>[])new DataRequestMonitor<?>[1] ;
+ final boolean qBadCanceled[] = new boolean[] { false };
+ Query<Integer> qBad = new Query<Integer>() {
@Override
protected void execute(DataRequestMonitor<Integer> rm) {
- fTestCache.update(new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), rm) {
+ rmBad[0] = new DataRequestMonitor<Integer>(ImmediateExecutor.getInstance(), rm) {
@Override
- public synchronized void addCancelListener(ICanceledListener listener) {
+ public synchronized void removeCancelListener(ICanceledListener listener) {
// Do not add the cancel listener so that the cancel request is not
// propagated to the cache.
}
- });
+
+ @Override
+ public void cancel() {
+ if (qBadCanceled[0]) {
+ super.cancel();
+ }
+ }
+
+ @Override
+ public synchronized boolean isCanceled() {
+ return qBadCanceled[0];
+ }
+
+ @Override
+ public synchronized void done() {
+ // Avoid clearing cancel listeners list
+ };
+ };
+
+ fTestCache.update(rmBad[0]);
}
};
- fExecutor.execute(q);
+ fExecutor.execute(qBad);
// Wait until the cache starts data retrieval.
waitForRetrieveRm();
- // Cancel the client request
- q.cancel(true);
+ // Reset the cache
+ fExecutor.submit(new DsfRunnable() {
+ public void run() {
+ fRetrieveRm = null;
+ fTestCache.set(null, Status.OK_STATUS);
+ fTestCache.reset();
+ }
+ }).get();
- assertCacheCanceled();
+ Query<Integer> qGood = new Query<Integer>() {
+ @Override
+ protected void execute(DataRequestMonitor<Integer> rm) {
+ fTestCache.update(rm);
+ }
+ };
+ fExecutor.execute(qGood);
- try {
- q.get();
- Assert.fail("Expected a cancellation exception");
- } catch (CancellationException e) {} // Expected exception;
+ // Wait until the cache starts data retrieval.
+ waitForRetrieveRm();
+
+ qBadCanceled[0] = true;
+ rmBad[0].cancel();
+ Assert.assertFalse(fRetrieveRm.isCanceled());
+
// Completed the retrieve RM
fExecutor.submit(new DsfRunnable() {
public void run() {
@@ -439,7 +569,8 @@ public class CacheTests {
}
}).get();
- // Validate that cache accepts the canceled request data
+ qGood.get();
+
assertCacheValidWithData(1);
}
@@ -594,19 +725,4 @@ public class CacheTests {
// Check final state
assertCacheResetWithoutData();
}
-
- @Test
- public void resetWithValueTest() throws InterruptedException, ExecutionException {
- // Disable the cache with a given value
- fExecutor.submit(new DsfRunnable() {
- public void run() {
- fTestCache.reset(2, Status.OK_STATUS);
- }
- }).get();
-
- // Validate that cache is disabled without data.
- Assert.assertFalse(fTestCache.isValid());
- Assert.assertEquals(2, (int)fTestCache.getData());
- Assert.assertTrue(fTestCache.getStatus().isOK());
- }
-}
+} \ No newline at end of file
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
new file mode 100644
index 00000000000..e6701914a09
--- /dev/null
+++ b/dsf/org.eclipse.cdt.tests.dsf/src/org/eclipse/cdt/tests/dsf/concurrent/RangeCacheTests.java
@@ -0,0 +1,407 @@
+/*******************************************************************************
+ * Copyright (c) 2006 Wind River Systems and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Wind River Systems - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.tests.dsf.concurrent;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+
+import junit.framework.Assert;
+
+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.ImmediateInDsfExecutor;
+import org.eclipse.cdt.dsf.concurrent.Query;
+import org.eclipse.cdt.dsf.concurrent.RangeCache;
+import org.eclipse.cdt.tests.dsf.DsfTestPlugin;
+import org.eclipse.cdt.tests.dsf.TestDsfExecutor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Tests that exercise the DataCache object.
+ */
+public class RangeCacheTests {
+
+ class TestRangeCache extends RangeCache<Integer> {
+
+ public TestRangeCache() {
+ super(new ImmediateInDsfExecutor(fExecutor));
+ }
+
+ @Override
+ protected void retrieve(long offset, int count, DataRequestMonitor<List<Integer>> rm) {
+ fRetrieveInfos.add(new RetrieveInfo(offset, count, rm));
+ }
+
+ @Override
+ public void reset() {
+ super.reset();
+ }
+
+ @Override
+ public void set(long offset, int count, List<Integer> data, IStatus status) {
+ super.set(offset, count, data, status);
+ }
+ }
+
+ class TestQuery extends Query<List<Integer>> {
+ long fOffset;
+ int fCount;
+ TestQuery(long offset, int count) {
+ fOffset = offset;
+ fCount = count;
+ }
+
+ @Override
+ protected void execute(DataRequestMonitor<List<Integer>> rm) {
+ fRangeCache = fTestCache.getRange(fOffset, fCount);
+ fRangeCache.update(rm);
+ }
+ }
+
+ class RetrieveInfo implements Comparable<RetrieveInfo> {
+ long fOffset;
+ int fCount;
+ DataRequestMonitor<List<Integer>> fRm;
+ RetrieveInfo(long offset, int count, DataRequestMonitor<List<Integer>> rm) {
+ fOffset = offset;
+ fCount = count;
+ fRm = rm;
+ }
+
+ public int compareTo(RetrieveInfo o) {
+ if (fOffset > o.fOffset) {
+ return 1;
+ } else if (fOffset == o.fOffset) {
+ return 0;
+ } else /*if (fOffset < o.fOffset)*/ {
+ return -1;
+ }
+ }
+ }
+
+ TestDsfExecutor fExecutor;
+ TestRangeCache fTestCache;
+ SortedSet<RetrieveInfo> fRetrieveInfos;
+ ICache<List<Integer>> fRangeCache;
+
+ private List<Integer> makeList(long offset, int count) {
+ List<Integer> list = new ArrayList<Integer>(count);
+ for (int i = 0; i < count; i++) {
+ list.add((int)(i + offset));
+ }
+ return list;
+ }
+
+ /**
+ * 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
+ * wait a dispatch cycle, etc..
+ */
+ private void waitForRetrieveRm(int size) {
+ synchronized(this) {
+ while (fRetrieveInfos.size() < size) {
+ try {
+ wait(100);
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ }
+ }
+
+ @Before
+ public void startExecutor() throws ExecutionException, InterruptedException {
+ fExecutor = new TestDsfExecutor();
+ fTestCache = new TestRangeCache();
+ fRetrieveInfos = new TreeSet<RetrieveInfo>();
+ fRangeCache = null;
+ }
+
+ @After
+ public void shutdownExecutor() throws ExecutionException, InterruptedException {
+ fExecutor.submit(new DsfRunnable() { public void run() {
+ fExecutor.shutdown();
+ }}).get();
+ if (fExecutor.exceptionsCaught()) {
+ Throwable[] exceptions = fExecutor.getExceptions();
+ throw new ExecutionException(exceptions[0]);
+ }
+ fTestCache = null;
+ fExecutor = null;
+ }
+
+ private void assertCacheValidWithData(ICache<List<Integer>> cache, long offset, int count) {
+ Assert.assertTrue(cache.isValid());
+ Assert.assertEquals(makeList(offset, count), cache.getData());
+ Assert.assertTrue(cache.getStatus().isOK());
+ }
+
+ private void assertCacheWaiting(ICache<List<Integer>> cache) {
+ Assert.assertFalse(cache.isValid());
+ try {
+ cache.getData();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ try {
+ cache.getStatus();
+ Assert.fail("Expected an IllegalStateException");
+ } catch (IllegalStateException e) {}
+ }
+
+ private void completeInfo(RetrieveInfo info, long offset, int count) {
+ Assert.assertEquals(offset, info.fOffset);
+ Assert.assertEquals(count, info.fCount);
+ info.fRm.setData(makeList(offset, count));
+ info.fRm.done();
+ }
+
+ private void getRange(long queryOffset, int queryCount, long[] retrieveOffsets, int retrieveCounts[]) throws InterruptedException, ExecutionException {
+ assert retrieveOffsets.length == retrieveCounts.length;
+ int retrieveCount = retrieveOffsets.length;
+
+ // Request data from cache
+ TestQuery q = new TestQuery(queryOffset, queryCount);
+
+ fRangeCache = null;
+ fRetrieveInfos.clear();
+
+ fExecutor.execute(q);
+
+ // Wait until the cache requests the data.
+ waitForRetrieveRm(retrieveOffsets.length);
+
+ if (retrieveCount != 0) {
+ assertCacheWaiting(fRangeCache);
+
+ // Set the data without using an executor.
+ Assert.assertEquals(retrieveCount, fRetrieveInfos.size());
+ int i = 0;
+ for (RetrieveInfo info : fRetrieveInfos) {
+ completeInfo(info, retrieveOffsets[i], retrieveCounts[i]);
+ i++;
+ }
+ }
+
+ // Wait for data.
+ Assert.assertEquals(makeList(queryOffset, queryCount), q.get());
+
+ // Check state while waiting for data
+ assertCacheValidWithData(fRangeCache, queryOffset, queryCount);
+ }
+
+ @Test
+ public void getOneRangeTest() throws InterruptedException, ExecutionException {
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ }
+
+ @Test
+ public void getMultipleRangesTest() throws InterruptedException, ExecutionException {
+ // Retrieve a range in-between two cached ranges
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ getRange(200, 100, new long[] { 200 }, new int[] { 100 });
+ getRange(0, 300, new long[] { 100 }, new int[] { 100 });
+
+ // Retrieve a range overlapping two cached ranges
+ getRange(1000, 100, new long[] { 1000 }, new int[] { 100 });
+ getRange(1200, 100, new long[] { 1200 }, new int[] { 100 });
+ getRange(900, 500, new long[] { 900, 1100, 1300 }, new int[] { 100, 100, 100 });
+
+ // Retrieve a range that's a subset of a cached range.
+ getRange(2000, 100, new long[] { 2000 }, new int[] { 100 });
+ getRange(2000, 50, new long[] {}, new int[] {});
+ getRange(2025, 50, new long[] {}, new int[] {});
+ getRange(2050, 50, new long[] {}, new int[] {});
+ }
+
+ private void cancelRange(long queryOffset, int queryCount, long[] retrieveOffsets, int retrieveCounts[]) throws Exception {
+ int retrieveCount = retrieveOffsets.length;
+
+ // Request data from cache
+ TestQuery q = new TestQuery(queryOffset, queryCount);
+
+ fRangeCache = null;
+ fRetrieveInfos.clear();
+
+ fExecutor.execute(q);
+
+ // Wait until the cache requests the data.
+ waitForRetrieveRm(retrieveCount);
+
+ assertCacheWaiting(fRangeCache);
+
+ // Set the data without using an executor.
+ Assert.assertEquals(retrieveCount, fRetrieveInfos.size());
+ int i = 0;
+ for (RetrieveInfo info : fRetrieveInfos) {
+ Assert.assertEquals(retrieveOffsets[i], info.fOffset);
+ Assert.assertEquals(retrieveCounts[i], info.fCount);
+ Assert.assertFalse(info.fRm.isCanceled());
+ i++;
+ }
+
+ q.cancel(true);
+ try {
+ q.get();
+ Assert.fail("Expected a cancellation exception");
+ } catch (CancellationException e) {} // Expected exception;
+
+ for (RetrieveInfo info : fRetrieveInfos) {
+ Assert.assertTrue(info.fRm.isCanceled());
+ }
+ }
+
+ @Test
+ public void cancelOneRangeTest() throws Exception {
+ cancelRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ }
+
+ @Test
+ public void cancelMultipleRangesTest() throws Exception {
+ // Cancel a couple of ranges.
+ cancelRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ cancelRange(200, 100, new long[] { 200 }, new int[] { 100 });
+
+ // Cancel a range overlapping two previously canceled ranges.
+ cancelRange(0, 300, new long[] { 0 }, new int[] { 300 });
+ }
+
+ @Test
+ public void getAndCancelMultipleRangesTest() throws Exception {
+ // Cancel a range, then retrieve the same range
+ cancelRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+
+ // Cancel a range overlapping a cached range.
+ cancelRange(0, 200, new long[] { 100 }, new int[] { 100 });
+ }
+
+ @Test
+ public void resetOneRangeTest() throws InterruptedException, ExecutionException {
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+
+ fExecutor.submit(new DsfRunnable() {
+ public void run() {
+ fTestCache.reset();
+ };
+ }).get();
+
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ }
+
+ @Test
+ public void resetMultipleRangesTest() throws InterruptedException, ExecutionException {
+ // Retrieve a range in-between two cached ranges
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ getRange(200, 100, new long[] { 200 }, new int[] { 100 });
+ getRange(0, 300, new long[] { 100 }, new int[] { 100 });
+
+ // Retrieve a range overlapping two cached ranges
+ getRange(1000, 100, new long[] { 1000 }, new int[] { 100 });
+ getRange(1200, 100, new long[] { 1200 }, new int[] { 100 });
+ getRange(900, 500, new long[] { 900, 1100, 1300 }, new int[] { 100, 100, 100 });
+
+ // Retrieve a range that's a subset of a cached range.
+ getRange(2000, 100, new long[] { 2000 }, new int[] { 100 });
+ getRange(2000, 50, new long[] {}, new int[] {});
+ getRange(2025, 50, new long[] {}, new int[] {});
+ getRange(2050, 50, new long[] {}, new int[] {});
+
+ fExecutor.submit(new DsfRunnable() {
+ public void run() {
+ fTestCache.reset();
+ };
+ }).get();
+
+ // Retrieve a range in-between two cached ranges
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+ getRange(200, 100, new long[] { 200 }, new int[] { 100 });
+ getRange(0, 300, new long[] { 100 }, new int[] { 100 });
+
+ // Retrieve a range overlapping two cached ranges
+ getRange(1000, 100, new long[] { 1000 }, new int[] { 100 });
+ getRange(1200, 100, new long[] { 1200 }, new int[] { 100 });
+ getRange(900, 500, new long[] { 900, 1100, 1300 }, new int[] { 100, 100, 100 });
+
+ // Retrieve a range that's a subset of a cached range.
+ getRange(2000, 100, new long[] { 2000 }, new int[] { 100 });
+ getRange(2000, 50, new long[] {}, new int[] {});
+ getRange(2025, 50, new long[] {}, new int[] {});
+ getRange(2050, 50, new long[] {}, new int[] {});
+ }
+
+ @Test
+ public void resetWhileInvalidTest() throws InterruptedException, ExecutionException {
+ // Request data from cache
+ TestQuery q = new TestQuery(10, 100);
+
+ fRangeCache = null;
+ fRetrieveInfos.clear();
+
+ fExecutor.execute(q);
+
+ // Wait until the cache requests the data.
+ waitForRetrieveRm(1);
+
+ assertCacheWaiting(fRangeCache);
+
+ fExecutor.submit(new DsfRunnable() {
+ public void run() {
+ fTestCache.reset();
+ };
+ }).get();
+
+ // Set the data without using an executor.
+ Assert.assertEquals(1, fRetrieveInfos.size());
+ completeInfo(fRetrieveInfos.first(), 10, 100);
+
+ // Wait for data.
+ Assert.assertEquals(makeList(10, 100), q.get());
+
+ // Check state while waiting for data
+ assertCacheValidWithData(fRangeCache, 10, 100);
+ }
+
+ @Test
+ public void setOneRangeTest() throws InterruptedException, ExecutionException {
+ getRange(0, 100, new long[] { 0 }, new int[] { 100 });
+
+ fExecutor.submit(new DsfRunnable() {
+ public void run() {
+ fTestCache.set(0, 100, null, new Status(IStatus.ERROR, DsfTestPlugin.PLUGIN_ID, IDsfStatusConstants.INVALID_STATE, "Cache invalid", null));
+ };
+ }).get();
+
+ // Request data from cache
+ TestQuery q = new TestQuery(10, 100);
+
+ fRangeCache = null;
+ fRetrieveInfos.clear();
+
+ fExecutor.execute(q);
+
+ try {
+ q.get();
+ Assert.fail("Expected an ExecutionException");
+ } catch (ExecutionException e) {}
+ }
+
+
+}

Back to the top