1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 02:06:01 +02:00

Bug 310345: [concurrent] Asynchronous Cache Programming Model (ACPM) utilities for DSF (reintroduced the "disabled" tests)

This commit is contained in:
John Cortell 2010-10-20 20:44:43 +00:00
parent de6703334b
commit c53ab94055

View file

@ -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();
// }
// }).get();
// //
// assertCacheDisabledWithoutData(); // 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
// // Try to request data from cache // to a state change notification from its source (e.g., the target
// Query<Integer> q = new Query<Integer>() { // resumed). In either case, the cache is in the valid state but it has no
// @Override // data and the status reflects an error. Keep in mind that the 'valid'
// protected void execute(DataRequestMonitor<Integer> rm) { // state is not a reflection of the quality of the data, but merely whether
// fTestCache.request(rm); // the cache object's representation of the data is stale or
// } // not. A transaction that uses a "disabled" cache object will simply fail;
// }; // it will not ask the cache to update its data from the source. Only a
// fExecutor.execute(q); // change in the source's state would cause the cache to put itself back in
// // the invalid state, thus opening the door to another update.
// Thread.sleep(100);
// /**
// // Retrieval should never have been made. * Test behavior when a cache object is asked to update itself after it has
// Assert.assertEquals(null, fRetrieveRm); * become "disabled". Since a "disabled" cache is in the valid state, a
// * request for it to update from the source should be ignored.
// try { */
// Assert.assertEquals(null, q.get()); @Test
// } catch (ExecutionException e) { public void disableBeforeRequestTest() throws InterruptedException, ExecutionException {
// // expected the exception // Disable the cache
// return; fExecutor.submit(new DsfRunnable() {
// } public void run() {
// Assert.fail("expected an exeption"); fTestCache.set(null, STATUS_TARGET_RUNNING);
// } }
// }).get();
// @Test
// public void disableWhilePendingTest() throws InterruptedException, ExecutionException { assertCacheValidWithoutData();
// // Request data from cache
// Query<Integer> q = new Query<Integer>() { // Try to request data from cache
// @Override Query<Integer> q = new TestQuery();
// protected void execute(DataRequestMonitor<Integer> rm) { fExecutor.execute(q);
// fTestCache.request(rm);
// } Thread.sleep(100);
// };
// fExecutor.execute(q); // Retrieval should never have been made.
// Assert.assertEquals(null, fRetrieveRm);
// // Disable the cache with a given value
// fExecutor.submit(new DsfRunnable() { // The cache has no data so the query should have failed
// public void run() { try {
// fTestCache.disable(); q.get();
// } Assert.fail("expected an exeption");
// }).get(); } catch (ExecutionException e) {
// // expected the exception
// assertCacheDisabledWithoutData(); }
// }
// // Completed the retrieve RM
// fExecutor.submit(new DsfRunnable() { /**
// public void run() { * Test behavior when a cache object goes into the "disabled" state while an
// fRetrieveRm.setData(1); * update request is ongoing. The subsequent completion of the request should
// fRetrieveRm.done(); * have no effect on the cache
// } */
// }).get(); @Test
// public void disableWhilePendingTest() throws InterruptedException, ExecutionException {
// // Validate that cache is still disabled without data. // Request data from cache
// assertCacheDisabledWithoutData(); Query<Integer> q = new TestQuery();
// } fExecutor.execute(q);
//
// @Test // Disable the cache
// public void disableWhileValidTest() throws InterruptedException, ExecutionException { fExecutor.submit(new DsfRunnable() {
// // Request data from cache public void run() {
// Query<Integer> q = new Query<Integer>() { fTestCache.set(null, STATUS_TARGET_RUNNING);
// @Override }
// protected void execute(DataRequestMonitor<Integer> rm) { }).get();
// fTestCache.request(rm);
// } assertCacheValidWithoutData();
// };
// fExecutor.execute(q); // Complete the retrieve RM. Note that the disabling of the cache above
// // disassociates it from its retrieval RM. Thus regardless of how that
// // Wait until the cache starts data retrieval. // request completes, it does not affect the cache.
// waitForRetrieveRm(); fExecutor.submit(new DsfRunnable() {
// public void run() {
// // Complete the request fRetrieveRm.setData(1);
// fRetrieveRm.setData(1); fRetrieveRm.done();
// fRetrieveRm.done(); }
// }).get();
// q.get();
// // Validate that cache is still disabled without data.
// // Disable cache assertCacheValidWithoutData();
// fExecutor.submit(new DsfRunnable() { }
// public void run() {
// fTestCache.disable(); /**
// } * Test behavior when a cache object goes into the "disabled" state while
// }).get(); * it's in the valid state. The cache remains in the valid state but it
// * loses its data and obtains an error status.
// // Check final state */
// assertCacheValidWithData(1); @Test
// } public void disableWhileValidTest() throws InterruptedException, ExecutionException {
// Request data from cache
Query<Integer> q = new TestQuery();
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);