Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2010-03-02 18:15:20 -0500
committerThomas Watson2010-03-02 18:15:20 -0500
commit2823d9e5edf97ea81143d99d4524dcc769416f74 (patch)
treeb03229b2792adc55fd7b9cee8f2608d4fe8aea67
parenteefb9243cd59e20504d42e5313821821776c126a (diff)
downloadrt.equinox.framework-2823d9e5edf97ea81143d99d4524dcc769416f74.tar.gz
rt.equinox.framework-2823d9e5edf97ea81143d99d4524dcc769416f74.tar.xz
rt.equinox.framework-2823d9e5edf97ea81143d99d4524dcc769416f74.zip
Bug 304361 - [app] enhance the eclipse application container to allow for async application results
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java173
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ExitValueApp.java81
2 files changed, 236 insertions, 18 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java
index 19b12920f..0209d8c75 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ApplicationAdminTest.java
@@ -11,12 +11,10 @@
package org.eclipse.osgi.tests.appadmin;
import java.util.*;
-import java.util.Map.Entry;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.tests.session.ConfigurationSessionTestSuite;
import org.eclipse.core.tests.session.SetupManager.SetupException;
-import org.eclipse.equinox.app.IApplicationContext;
import org.eclipse.osgi.tests.OSGiTest;
import org.eclipse.osgi.tests.OSGiTestsActivator;
import org.eclipse.osgi.tests.bundles.BundleInstaller;
@@ -34,7 +32,7 @@ public class ApplicationAdminTest extends OSGiTest {
public static final String REMOVED = "removed"; //$NON-NLS-1$
public static final String simpleResults = "test.simpleResults"; //$NON-NLS-1$
public static final String[] tests = new String[] {
- "testSimpleApp", "testInvalidArgs", "testExitValue01", "testExitValue02", "testExitValue03", "testExitValue04", "testExitValue05", "testExitValue06", "testExitValue07", "testExitValue08", "testExitValue09", "testExitValue10", "testGlobalSingleton", "testCardinality01", "testCardinality02", "testMainThreaded01", "testMainThreaded02", "testHandleEvents01", "testDescriptorEvents01", "testPersistentLock01", "testPersistentLock02", "testPersistentLock03", "testPersistentSchedule01", "testPersistentSchedule02", "testPersistentSchedule03", "testPersistentSchedule04", "testPersistentSchedule05", "testPersistentSchedule06", "testPersistentSchedule07", "testPersistentSchedule08", "testFailedApplication01", "testDestroyBeforeStart01", "testDestroyBeforeStart02"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ //$NON-NLS-15$ //$NON-NLS-16$ //$NON-NLS-17$ //$NON-NLS-18$ //$NON-NLS-19$ //$NON-NLS-20$ //$NON-NLS-21$ //$NON-NLS-22$ //$NON-NLS-23$ //$NON-NLS-24$ //$NON-NLS-25$ //$NON-NLS-26$ //$NON-NLS-27$ //$NON-NLS-28$ //$NON-NLS-29$
+ "testSimpleApp", "testInvalidArgs", "testAsyncValue01", "testAsyncValue02", "testAsyncValue03", "testAsyncValue04", "testAsyncValue05", "testAsyncValue06", "testExitValue01", "testExitValue02", "testExitValue03", "testExitValue04", "testExitValue05", "testExitValue06", "testExitValue07", "testExitValue08", "testExitValue09", "testExitValue10", "testGlobalSingleton", "testCardinality01", "testCardinality02", "testMainThreaded01", "testMainThreaded02", "testHandleEvents01", "testDescriptorEvents01", "testPersistentLock01", "testPersistentLock02", "testPersistentLock03", "testPersistentSchedule01", "testPersistentSchedule02", "testPersistentSchedule03", "testPersistentSchedule04", "testPersistentSchedule05", "testPersistentSchedule06", "testPersistentSchedule07", "testPersistentSchedule08", "testFailedApplication01", "testDestroyBeforeStart01", "testDestroyBeforeStart02"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ //$NON-NLS-11$ //$NON-NLS-12$ //$NON-NLS-13$ //$NON-NLS-14$ //$NON-NLS-15$ //$NON-NLS-16$ //$NON-NLS-17$ //$NON-NLS-18$ //$NON-NLS-19$ //$NON-NLS-20$ //$NON-NLS-21$ //$NON-NLS-22$ //$NON-NLS-23$ //$NON-NLS-24$ //$NON-NLS-25$ //$NON-NLS-26$ //$NON-NLS-27$ //$NON-NLS-28$ //$NON-NLS-29$
private static final String PI_OSGI_SERVICES = "org.eclipse.osgi.services"; //$NON-NLS-1$
public static Test suite() {
@@ -438,7 +436,7 @@ public class ApplicationAdminTest extends OSGiTest {
ApplicationHandle handle = null;
HashMap args = getArguments();
- args.put(IApplicationContext.APPLICATION_ARGS, new String[] {ExitValueApp.returnNullResult});
+ args.put(ExitValueApp.returnNullResult, Boolean.TRUE);
try {
handle = app.launch(args);
@@ -487,6 +485,169 @@ public class ApplicationAdminTest extends OSGiTest {
assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
}
+ public void testAsyncValue01() {
+ //setValue test; called with timeout 0 after the result is available
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ Map args = new HashMap();
+ args.put(ExitValueApp.returnAsyncResult, Boolean.TRUE);
+ ApplicationHandle handle = null;
+ try {
+ handle = app.launch(args);
+ } catch (ApplicationException e) {
+ fail("failed to launch simpleApp", e); //$NON-NLS-1$
+ }
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+ String value = null;
+ try {
+ // waiting for app to exit
+ handle.getExitValue(10000);
+ // app exited now get the result with 0 timeout
+ value = (String) handle.getExitValue(0);
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ assertNotNull("value is null", value); //$NON-NLS-1$
+ assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
+
+ try {
+ // app exited now get the result with -1 timeout; we know the value is ready from above
+ value = (String) handle.getExitValue(-1);
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ assertNotNull("value is null", value); //$NON-NLS-1$
+ assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
+ }
+
+ public void testAsyncValue02() {
+ //setValue test; called with timeout -1
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ ApplicationHandle handle = null;
+ Map args = new HashMap();
+ args.put(ExitValueApp.returnAsyncResult, Boolean.TRUE);
+ try {
+ handle = app.launch(args);
+ } catch (ApplicationException e) {
+ fail("failed to launcher simpleApp", e); //$NON-NLS-1$
+ }
+
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+
+ try {
+ handle.getExitValue(-1);
+ fail("Expected an ApplicationException for exit value not available"); //$NON-NLS-1$
+ } catch (ApplicationException e) {
+ assertEquals("Unexpected error type", ApplicationException.APPLICATION_EXITVALUE_NOT_AVAILABLE, e.getErrorCode()); //$NON-NLS-1$
+ } catch (InterruptedException e) {
+ fail("Unexpected interrupted exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ }
+
+ public void testAsyncValue03() {
+ //setValue test; application returns null
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ ApplicationHandle handle = null;
+
+ HashMap args = getArguments();
+ args.put(ExitValueApp.returnNullResult, Boolean.TRUE);
+ args.put(ExitValueApp.returnAsyncResult, Boolean.TRUE);
+
+ try {
+ handle = app.launch(args);
+ } catch (ApplicationException e) {
+ fail("failed to launcher simpleApp", e); //$NON-NLS-1$
+ }
+
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+
+ try {
+ assertNull("expected null return value", handle.getExitValue(0));
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ }
+
+ public void testAsyncValue04() {
+ // setValue test with destroy called while waiting for an exit value
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ HashMap args = getArguments();
+ args.put(ExitValueApp.returnAsyncResult, Boolean.TRUE);
+ ApplicationHandle handle = null;
+ try {
+ handle = app.launch(null);
+ } catch (ApplicationException e) {
+ fail("failed to launch simpleApp", e); //$NON-NLS-1$
+ }
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+ final ApplicationHandle destroyHandle = handle;
+ new Thread(new Runnable() {
+ public void run() {
+ try {
+ Thread.sleep(1000);
+ destroyHandle.destroy();
+ } catch (InterruptedException e) {
+ // nothing
+ }
+
+ }
+ }).start();
+ String value = null;
+ try {
+ value = (String) handle.getExitValue(10000);
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ assertNotNull("value is null", value); //$NON-NLS-1$
+ assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
+ }
+
+ public void testAsyncValue05() {
+ // test calling setValue to early
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ Map args = new HashMap();
+ args.put(ExitValueApp.setAsyncEarly, Boolean.TRUE);
+ ApplicationHandle handle = null;
+ try {
+ handle = app.launch(args);
+ } catch (ApplicationException e) {
+ fail("failed to launch simpleApp", e); //$NON-NLS-1$
+ }
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+ String value = null;
+ try {
+ // waiting for app to exit
+ value = (String) handle.getExitValue(10000);
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ assertNotNull("value is null", value); //$NON-NLS-1$
+ assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
+ }
+
+ public void testAsyncValue06() {
+ // test calling setValue with wrong application instance
+ ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".exitValueApp"); //$NON-NLS-1$
+ Map args = new HashMap();
+ args.put(ExitValueApp.returnAsyncResult, Boolean.TRUE);
+ args.put(ExitValueApp.setAsyncWrongApp, Boolean.TRUE);
+ ApplicationHandle handle = null;
+ try {
+ handle = app.launch(args);
+ } catch (ApplicationException e) {
+ fail("failed to launch simpleApp", e); //$NON-NLS-1$
+ }
+ assertNotNull("app handle is null", handle); //$NON-NLS-1$
+ String value = null;
+ try {
+ // waiting for app to exit
+ value = (String) handle.getExitValue(10000);
+ } catch (Exception e) {
+ fail("unexpected exception waiting for exit value", e); //$NON-NLS-1$
+ }
+ assertNotNull("value is null", value); //$NON-NLS-1$
+ assertEquals("exit value is incorrect", ExitValueApp.exitValue, value); //$NON-NLS-1$
+ }
+
public void testGlobalSingleton() {
ApplicationDescriptor app = getApplication(PI_OSGI_TESTS + ".globalSingletonApp"); //$NON-NLS-1$
HashMap args = getArguments();
@@ -686,7 +847,7 @@ public class ApplicationAdminTest extends OSGiTest {
args.put("test.arg2", new Integer(34)); //$NON-NLS-1$
args.put("test.arg3", new Long(34)); //$NON-NLS-1$
for (Iterator iEntries = args.entrySet().iterator(); iEntries.hasNext();) {
- Entry entry = (Entry) iEntries.next();
+ Map.Entry entry = (Map.Entry) iEntries.next();
assertEquals("key: " + entry.getKey(), entry.getValue(), results.get(entry.getKey())); //$NON-NLS-1$
}
} catch (InterruptedException e) {
@@ -751,7 +912,7 @@ public class ApplicationAdminTest extends OSGiTest {
args.put("test.arg2", new Integer(34)); //$NON-NLS-1$
args.put("test.arg3", new Long(34)); //$NON-NLS-1$
for (Iterator iEntries = args.entrySet().iterator(); iEntries.hasNext();) {
- Entry entry = (Entry) iEntries.next();
+ Map.Entry entry = (Map.Entry) iEntries.next();
assertEquals("key: " + entry.getKey(), entry.getValue(), results.get(entry.getKey())); //$NON-NLS-1$
}
// should not find the scheduled app anymore
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ExitValueApp.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ExitValueApp.java
index b82c68359..809fcbfce 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ExitValueApp.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/appadmin/ExitValueApp.java
@@ -13,27 +13,48 @@ package org.eclipse.osgi.tests.appadmin;
import org.eclipse.equinox.app.IApplication;
import org.eclipse.equinox.app.IApplicationContext;
-public class ExitValueApp implements IApplication {
- public static final String returnNullResult = "return null"; //$NON-NLS-1$
+public class ExitValueApp implements IApplication, Runnable {
+ public static final String returnNullResult = "return.null"; //$NON-NLS-1$
+ public static final String returnAsyncResult = "return.async";
+ public static final String setAsyncEarly = "set.async.early";
+ public static final String setAsyncWrongApp = "set.async.wrongApp";
public static final String exitValue = "Exit Value"; //$NON-NLS-1$
+
private boolean active = true;
private boolean stopped = false;
+ private boolean useAsync = false;
+ private boolean returnNull = false;
+ private boolean setWrongApp = false;
+ private IApplicationContext appContext;
+ final Object guardObj = new Object();
public synchronized Object start(IApplicationContext context) {
- boolean returnNull = false;
+ appContext = context;
context.applicationRunning();
- if (active) {
- String[] args = (String[]) context.getArguments().get(IApplicationContext.APPLICATION_ARGS);
- if (args != null && args.length > 0)
- returnNull = returnNullResult.equals(args[0]);
+ Boolean nullValue = (Boolean) context.getArguments().get(returnNullResult);
+ returnNull = nullValue == null ? false : nullValue.booleanValue();
+ Boolean asyncValue = (Boolean) context.getArguments().get(returnAsyncResult);
+ useAsync = asyncValue == null ? false : asyncValue.booleanValue();
+
+ Boolean asyncEarlyValue = (Boolean) context.getArguments().get(setAsyncEarly);
+ boolean setEarly = asyncEarlyValue == null ? false : asyncEarlyValue.booleanValue();
+ Boolean wrongAppValue = (Boolean) context.getArguments().get(setAsyncWrongApp);
+ setWrongApp = wrongAppValue == null ? false : wrongAppValue.booleanValue();
+ if (setEarly) {
try {
- wait(5000); // only run for 5 seconds at most
- } catch (InterruptedException e) {
- // do nothing
+ context.setResult("failed", this);
+ // failed
+ } catch (IllegalStateException e) {
+ // passed
+ return exitValue;
}
}
- stopped = true;
- notifyAll();
+ if (useAsync) {
+ System.out.println("async result");
+ new Thread(this, "ExitValueApp Test").start();
+ return IApplicationContext.EXIT_ASYNC_RESULT;
+ }
+ run();
return returnNull ? null : exitValue;
}
@@ -48,4 +69,40 @@ public class ExitValueApp implements IApplication {
}
}
+ public synchronized void run() {
+ if (active) {
+ try {
+ wait(5000); // only run for 5 seconds at most
+ } catch (InterruptedException e) {
+ // do nothing
+ }
+ }
+ stopped = true;
+ if (useAsync) {
+ IApplication app = this;
+ Object result = returnNull ? null : exitValue;
+ if (setWrongApp) {
+ result = "failed";
+ app = new IApplication() {
+
+ public void stop() {
+ // nothing
+ }
+
+ public Object start(IApplicationContext context) throws Exception {
+ return null;
+ }
+ };
+ }
+ try {
+ appContext.setResult(result, app);
+ // failed
+ } catch (IllegalArgumentException e) {
+ // passed
+ appContext.setResult(returnNull ? null : exitValue, this);
+ }
+ }
+ notifyAll();
+ }
+
}

Back to the top