mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Bug 310345: [concurrent] Asynchronous Cache Programming Model (ACPM) utilities for DSF (reintroduced the "disabled" tests)
This commit is contained in:
parent
de6703334b
commit
c53ab94055
1 changed files with 120 additions and 101 deletions
|
@ -20,12 +20,12 @@ import junit.framework.Assert;
|
||||||
|
|
||||||
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
import org.eclipse.cdt.dsf.concurrent.DataRequestMonitor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
||||||
import org.eclipse.cdt.dsf.concurrent.IDsfStatusConstants;
|
|
||||||
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
|
import org.eclipse.cdt.dsf.concurrent.ImmediateExecutor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.ImmediateInDsfExecutor;
|
import org.eclipse.cdt.dsf.concurrent.ImmediateInDsfExecutor;
|
||||||
import org.eclipse.cdt.dsf.concurrent.Query;
|
import org.eclipse.cdt.dsf.concurrent.Query;
|
||||||
import org.eclipse.cdt.dsf.concurrent.RequestCache;
|
import org.eclipse.cdt.dsf.concurrent.RequestCache;
|
||||||
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
import org.eclipse.cdt.dsf.concurrent.RequestMonitor;
|
||||||
|
import org.eclipse.cdt.tests.dsf.DsfTestPlugin;
|
||||||
import org.eclipse.cdt.tests.dsf.TestDsfExecutor;
|
import org.eclipse.cdt.tests.dsf.TestDsfExecutor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
@ -136,11 +136,11 @@ public class CacheTests {
|
||||||
} catch (IllegalStateException e) {}
|
} catch (IllegalStateException e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCacheDisabledWithoutData() {
|
private void assertCacheValidWithoutData() {
|
||||||
Assert.assertTrue(fTestCache.isValid());
|
Assert.assertTrue(fTestCache.isValid());
|
||||||
Assert.assertEquals(null, fTestCache.getData());
|
Assert.assertEquals(null, fTestCache.getData());
|
||||||
Assert.assertFalse(fTestCache.getStatus().isOK());
|
Assert.assertFalse(fTestCache.getStatus().isOK());
|
||||||
Assert.assertEquals(fTestCache.getStatus().getCode(), IDsfStatusConstants.INVALID_STATE);
|
Assert.assertEquals(fTestCache.getStatus().getCode(), ERRCODE_TARGET_RUNNING);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertCacheWaiting() {
|
private void assertCacheWaiting() {
|
||||||
|
@ -289,106 +289,125 @@ public class CacheTests {
|
||||||
assertCacheValidWithData(1);
|
assertCacheValidWithData(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
private static final int ERRCODE_TARGET_RUNNING = 1234;
|
||||||
// public void disableBeforeRequestTest() throws InterruptedException, ExecutionException {
|
private static final Status STATUS_TARGET_RUNNING = new Status(Status.ERROR, DsfTestPlugin.PLUGIN_ID, ERRCODE_TARGET_RUNNING, "Target is running", null);
|
||||||
// // Disable the cache with a given value
|
|
||||||
// fExecutor.submit(new DsfRunnable() {
|
// DISABLE TESTS
|
||||||
// public void run() {
|
//
|
||||||
// fTestCache.disable();
|
// We say a cache is "disabled" when its most recent attempt to update from
|
||||||
// }
|
// the source failed. Also, a cache may make itself disabled as a reaction
|
||||||
// }).get();
|
// to a state change notification from its source (e.g., the target
|
||||||
//
|
// resumed). In either case, the cache is in the valid state but it has no
|
||||||
// assertCacheDisabledWithoutData();
|
// data and the status reflects an error. Keep in mind that the 'valid'
|
||||||
//
|
// state is not a reflection of the quality of the data, but merely whether
|
||||||
// // Try to request data from cache
|
// the cache object's representation of the data is stale or
|
||||||
// Query<Integer> q = new Query<Integer>() {
|
// not. A transaction that uses a "disabled" cache object will simply fail;
|
||||||
// @Override
|
// it will not ask the cache to update its data from the source. Only a
|
||||||
// protected void execute(DataRequestMonitor<Integer> rm) {
|
// change in the source's state would cause the cache to put itself back in
|
||||||
// fTestCache.request(rm);
|
// the invalid state, thus opening the door to another update.
|
||||||
// }
|
|
||||||
// };
|
/**
|
||||||
// fExecutor.execute(q);
|
* Test behavior when a cache object is asked to update itself after it has
|
||||||
//
|
* become "disabled". Since a "disabled" cache is in the valid state, a
|
||||||
// Thread.sleep(100);
|
* request for it to update from the source should be ignored.
|
||||||
//
|
*/
|
||||||
// // Retrieval should never have been made.
|
@Test
|
||||||
// Assert.assertEquals(null, fRetrieveRm);
|
public void disableBeforeRequestTest() throws InterruptedException, ExecutionException {
|
||||||
//
|
// Disable the cache
|
||||||
// try {
|
fExecutor.submit(new DsfRunnable() {
|
||||||
// Assert.assertEquals(null, q.get());
|
public void run() {
|
||||||
// } catch (ExecutionException e) {
|
fTestCache.set(null, STATUS_TARGET_RUNNING);
|
||||||
// // expected the exception
|
}
|
||||||
// return;
|
}).get();
|
||||||
// }
|
|
||||||
// Assert.fail("expected an exeption");
|
assertCacheValidWithoutData();
|
||||||
// }
|
|
||||||
//
|
// Try to request data from cache
|
||||||
// @Test
|
Query<Integer> q = new TestQuery();
|
||||||
// public void disableWhilePendingTest() throws InterruptedException, ExecutionException {
|
fExecutor.execute(q);
|
||||||
// // Request data from cache
|
|
||||||
// Query<Integer> q = new Query<Integer>() {
|
Thread.sleep(100);
|
||||||
// @Override
|
|
||||||
// protected void execute(DataRequestMonitor<Integer> rm) {
|
// Retrieval should never have been made.
|
||||||
// fTestCache.request(rm);
|
Assert.assertEquals(null, fRetrieveRm);
|
||||||
// }
|
|
||||||
// };
|
// The cache has no data so the query should have failed
|
||||||
// fExecutor.execute(q);
|
try {
|
||||||
//
|
q.get();
|
||||||
// // Disable the cache with a given value
|
Assert.fail("expected an exeption");
|
||||||
// fExecutor.submit(new DsfRunnable() {
|
} catch (ExecutionException e) {
|
||||||
// public void run() {
|
// expected the exception
|
||||||
// fTestCache.disable();
|
}
|
||||||
// }
|
}
|
||||||
// }).get();
|
|
||||||
//
|
/**
|
||||||
// assertCacheDisabledWithoutData();
|
* Test behavior when a cache object goes into the "disabled" state while an
|
||||||
//
|
* update request is ongoing. The subsequent completion of the request should
|
||||||
// // Completed the retrieve RM
|
* have no effect on the cache
|
||||||
// fExecutor.submit(new DsfRunnable() {
|
*/
|
||||||
// public void run() {
|
@Test
|
||||||
// fRetrieveRm.setData(1);
|
public void disableWhilePendingTest() throws InterruptedException, ExecutionException {
|
||||||
// fRetrieveRm.done();
|
// Request data from cache
|
||||||
// }
|
Query<Integer> q = new TestQuery();
|
||||||
// }).get();
|
fExecutor.execute(q);
|
||||||
//
|
|
||||||
// // Validate that cache is still disabled without data.
|
// Disable the cache
|
||||||
// assertCacheDisabledWithoutData();
|
fExecutor.submit(new DsfRunnable() {
|
||||||
// }
|
public void run() {
|
||||||
//
|
fTestCache.set(null, STATUS_TARGET_RUNNING);
|
||||||
// @Test
|
}
|
||||||
// public void disableWhileValidTest() throws InterruptedException, ExecutionException {
|
}).get();
|
||||||
// // Request data from cache
|
|
||||||
// Query<Integer> q = new Query<Integer>() {
|
assertCacheValidWithoutData();
|
||||||
// @Override
|
|
||||||
// protected void execute(DataRequestMonitor<Integer> rm) {
|
// Complete the retrieve RM. Note that the disabling of the cache above
|
||||||
// fTestCache.request(rm);
|
// disassociates it from its retrieval RM. Thus regardless of how that
|
||||||
// }
|
// request completes, it does not affect the cache.
|
||||||
// };
|
fExecutor.submit(new DsfRunnable() {
|
||||||
// fExecutor.execute(q);
|
public void run() {
|
||||||
//
|
fRetrieveRm.setData(1);
|
||||||
// // Wait until the cache starts data retrieval.
|
fRetrieveRm.done();
|
||||||
// waitForRetrieveRm();
|
}
|
||||||
//
|
}).get();
|
||||||
// // Complete the request
|
|
||||||
// fRetrieveRm.setData(1);
|
// Validate that cache is still disabled without data.
|
||||||
// fRetrieveRm.done();
|
assertCacheValidWithoutData();
|
||||||
//
|
}
|
||||||
// q.get();
|
|
||||||
//
|
/**
|
||||||
// // Disable cache
|
* Test behavior when a cache object goes into the "disabled" state while
|
||||||
// fExecutor.submit(new DsfRunnable() {
|
* it's in the valid state. The cache remains in the valid state but it
|
||||||
// public void run() {
|
* loses its data and obtains an error status.
|
||||||
// fTestCache.disable();
|
*/
|
||||||
// }
|
@Test
|
||||||
// }).get();
|
public void disableWhileValidTest() throws InterruptedException, ExecutionException {
|
||||||
//
|
// Request data from cache
|
||||||
// // Check final state
|
Query<Integer> q = new TestQuery();
|
||||||
// assertCacheValidWithData(1);
|
fExecutor.execute(q);
|
||||||
// }
|
|
||||||
|
// Wait until the cache starts data retrieval.
|
||||||
|
waitForRetrieveRm();
|
||||||
|
|
||||||
|
// Complete the request
|
||||||
|
fRetrieveRm.setData(1);
|
||||||
|
fRetrieveRm.done();
|
||||||
|
|
||||||
|
Assert.assertEquals(Integer.valueOf(1), q.get());
|
||||||
|
|
||||||
|
// Disable the cache
|
||||||
|
fExecutor.submit(new DsfRunnable() {
|
||||||
|
public void run() {
|
||||||
|
fTestCache.set(null, STATUS_TARGET_RUNNING);
|
||||||
|
}
|
||||||
|
}).get();
|
||||||
|
|
||||||
|
// Check final state
|
||||||
|
assertCacheValidWithoutData();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void disableWithValueTest() throws InterruptedException, ExecutionException {
|
public void setWithValueTest() throws InterruptedException, ExecutionException {
|
||||||
// Disable the cache with a given value
|
// Disable the cache
|
||||||
fExecutor.submit(new DsfRunnable() {
|
fExecutor.submit(new DsfRunnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
fTestCache.set(2, Status.OK_STATUS);
|
fTestCache.set(2, Status.OK_STATUS);
|
||||||
|
|
Loading…
Add table
Reference in a new issue