Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoberto E. Escobar2011-10-28 02:21:25 -0400
committerRoberto E. Escobar2011-10-28 02:21:25 -0400
commitfe8d78ae9ccae47388e5e8709ed11f8e1e53d9cf (patch)
treee60bd4bc088a759c8375850a32d794edc67ed5f9 /plugins/org.eclipse.osee.executor.admin.test
parent5058815083f24a16e3aeac999b0f9a0f8d9bb730 (diff)
downloadorg.eclipse.osee-fe8d78ae9ccae47388e5e8709ed11f8e1e53d9cf.tar.gz
org.eclipse.osee-fe8d78ae9ccae47388e5e8709ed11f8e1e53d9cf.tar.xz
org.eclipse.osee-fe8d78ae9ccae47388e5e8709ed11f8e1e53d9cf.zip
feature[ats_18K4T]: Add cancel to searches
Diffstat (limited to 'plugins/org.eclipse.osee.executor.admin.test')
-rw-r--r--plugins/org.eclipse.osee.executor.admin.test/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.osee.executor.admin.test/build.properties3
-rw-r--r--plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutionCallbackTest.java146
-rw-r--r--plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminIternalTestSuite.java2
-rw-r--r--plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/mock/MockExecutionCallback.java63
5 files changed, 214 insertions, 3 deletions
diff --git a/plugins/org.eclipse.osee.executor.admin.test/META-INF/MANIFEST.MF b/plugins/org.eclipse.osee.executor.admin.test/META-INF/MANIFEST.MF
index 7abc66e61b..2ae48a2f77 100644
--- a/plugins/org.eclipse.osee.executor.admin.test/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.osee.executor.admin.test/META-INF/MANIFEST.MF
@@ -6,6 +6,7 @@ Bundle-Version: 0.9.9.qualifier
Bundle-Vendor: Eclipse Open System Engineering Environment
Fragment-Host: org.eclipse.osee.executor.admin
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
-Import-Package: org.junit;version="4.8.2",
+Import-Package: org.eclipse.osee.framework.jdk.core.type,
+ org.junit;version="4.8.2",
org.junit.runner;version="4.8.2",
org.junit.runners;version="4.8.2"
diff --git a/plugins/org.eclipse.osee.executor.admin.test/build.properties b/plugins/org.eclipse.osee.executor.admin.test/build.properties
index 5b9d2918ff..edf08e91d3 100644
--- a/plugins/org.eclipse.osee.executor.admin.test/build.properties
+++ b/plugins/org.eclipse.osee.executor.admin.test/build.properties
@@ -2,4 +2,5 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
-additional.bundles = org.junit
+additional.bundles = org.junit,\
+ org.eclipse.osee.framework.jdk.core
diff --git a/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutionCallbackTest.java b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutionCallbackTest.java
new file mode 100644
index 0000000000..9299923f0c
--- /dev/null
+++ b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutionCallbackTest.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.executor.admin.internal;
+
+import java.util.HashMap;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CancellationException;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import org.eclipse.osee.executor.admin.CancellableCallable;
+import org.eclipse.osee.executor.admin.mock.MockEventService;
+import org.eclipse.osee.executor.admin.mock.MockExecutionCallback;
+import org.eclipse.osee.executor.admin.mock.MockLog;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class ExecutionCallbackTest {
+
+ @Test
+ public void testCallbackOnSuccess() throws Exception {
+ ExecutorAdminImpl admin = new ExecutorAdminImpl();
+ admin.setLogger(new MockLog());
+ admin.setEventService(new MockEventService());
+ admin.start(new HashMap<String, Object>());
+
+ final String expected = "Was Called";
+
+ MockExecutionCallback<String> callback = new MockExecutionCallback<String>();
+ Callable<String> callable = new Callable<String>() {
+
+ @Override
+ public String call() throws Exception {
+ return expected;
+ }
+
+ };
+ Future<String> future = admin.schedule(callable, callback);
+ String actual = future.get();
+
+ Assert.assertEquals(expected, actual);
+
+ Assert.assertTrue(callback.wasOnSuccess());
+ Assert.assertFalse(callback.wasOnCancelled());
+ Assert.assertFalse(callback.wasOnFailure());
+
+ Assert.assertEquals(expected, callback.getResult());
+ Assert.assertNull(callback.getThrowable());
+ }
+
+ @Test
+ public void testCallbackOnFailure() throws Exception {
+ ExecutorAdminImpl admin = new ExecutorAdminImpl();
+ admin.setLogger(new MockLog());
+ admin.setEventService(new MockEventService());
+ admin.start(new HashMap<String, Object>());
+
+ final Exception expectedException = new IllegalStateException();
+ MockExecutionCallback<String> callback = new MockExecutionCallback<String>();
+ Callable<String> callable = new Callable<String>() {
+
+ @Override
+ public String call() throws Exception {
+ throw expectedException;
+ }
+
+ };
+ Future<String> future = admin.schedule(callable, callback);
+
+ try {
+ future.get();
+ Assert.assertTrue("An exception should have been thrown", false);
+ } catch (Exception ex) {
+ Assert.assertEquals(ExecutionException.class, ex.getClass());
+ Assert.assertEquals(expectedException, ex.getCause());
+ }
+
+ Assert.assertFalse(callback.wasOnSuccess());
+ Assert.assertFalse(callback.wasOnCancelled());
+ Assert.assertTrue(callback.wasOnFailure());
+
+ Assert.assertNull(callback.getResult());
+ Assert.assertEquals(IllegalStateException.class, callback.getThrowable().getClass());
+ }
+
+ @Test
+ public void testCallbackOnCancel() throws Exception {
+ ExecutorAdminImpl admin = new ExecutorAdminImpl();
+ admin.setLogger(new MockLog());
+ admin.setEventService(new MockEventService());
+ admin.start(new HashMap<String, Object>());
+
+ final String results = "results";
+
+ MockExecutionCallback<String> callback = new MockExecutionCallback<String>();
+
+ TestCancellableCallable callable = new TestCancellableCallable(results);
+ Future<String> future = admin.schedule(callable, callback);
+ future.cancel(true);
+
+ Assert.assertFalse(callback.wasOnSuccess());
+ Assert.assertTrue(callback.wasOnCancelled());
+ Assert.assertFalse(callback.wasOnFailure());
+
+ Assert.assertNull(callback.getResult());
+ Assert.assertNull(callback.getThrowable());
+
+ Assert.assertEquals(true, callable.isCancelled());
+ Assert.assertEquals(true, future.isCancelled());
+
+ try {
+ future.get();
+ Assert.assertTrue("An exception should have been thrown", false);
+ } catch (Exception ex) {
+ Assert.assertEquals(CancellationException.class, ex.getClass());
+ }
+ }
+
+ private class TestCancellableCallable extends CancellableCallable<String> {
+
+ private final String results;
+
+ public TestCancellableCallable(String results) {
+ this.results = results;
+ }
+
+ @Override
+ public String call() throws Exception {
+ while (!isCancelled()) {
+ checkForCancelled();
+ // System.out.println("working...");
+ }
+ return results;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminIternalTestSuite.java b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminIternalTestSuite.java
index 5569d96927..08f68af304 100644
--- a/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminIternalTestSuite.java
+++ b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/internal/ExecutorAdminIternalTestSuite.java
@@ -14,7 +14,7 @@ import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@RunWith(Suite.class)
-@Suite.SuiteClasses({ExecutorAdminTest.class})
+@Suite.SuiteClasses({ExecutorAdminTest.class, ExecutionCallbackTest.class})
public class ExecutorAdminIternalTestSuite {
//
}
diff --git a/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/mock/MockExecutionCallback.java b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/mock/MockExecutionCallback.java
new file mode 100644
index 0000000000..165c165cf7
--- /dev/null
+++ b/plugins/org.eclipse.osee.executor.admin.test/src/org/eclipse/osee/executor/admin/mock/MockExecutionCallback.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2007 Boeing.
+ * 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:
+ * Boeing - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.osee.executor.admin.mock;
+
+import org.eclipse.osee.executor.admin.ExecutionCallback;
+
+/**
+ * @author Roberto E. Escobar
+ */
+public class MockExecutionCallback<T> implements ExecutionCallback<T> {
+
+ private boolean wasOnCancelled;
+ private boolean wasOnSuccess;
+ private boolean wasOnFailure;
+ private Throwable throwable;
+ private T result;
+
+ @Override
+ public void onCancelled() {
+ this.wasOnCancelled = true;
+ }
+
+ @Override
+ public void onSuccess(T result) {
+ this.result = result;
+ this.wasOnSuccess = true;
+ }
+
+ @Override
+ public void onFailure(Throwable throwable) {
+ this.wasOnFailure = true;
+ this.throwable = throwable;
+ }
+
+ public boolean wasOnCancelled() {
+ return wasOnCancelled;
+ }
+
+ public boolean wasOnSuccess() {
+ return wasOnSuccess;
+ }
+
+ public boolean wasOnFailure() {
+ return wasOnFailure;
+ }
+
+ public Throwable getThrowable() {
+ return throwable;
+ }
+
+ public T getResult() {
+ return result;
+ }
+
+} \ No newline at end of file

Back to the top