Author: jmarino
Date: Fri May 5 11:55:12 2006
New Revision: 400143
URL: http://svn.apache.org/viewcvs?rev=400143&view=rev
Log:
fix for TUSCANY-298
Added:
incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
Added:
incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java?rev=400143&view=auto
==============================================================================
---
incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java
(added)
+++
incubator/tuscany/java/sca/containers/container.java/src/test/java/org/apache/tuscany/container/java/integration/StartStopTestCase.java
Fri May 5 11:55:12 2006
@@ -0,0 +1,52 @@
+package org.apache.tuscany.container.java.integration;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.TestCase;
+import org.apache.tuscany.core.client.TuscanyRuntime;
+import org.osoa.sca.ModuleContext;
+import org.osoa.sca.CurrentModuleContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StartStopTestCase extends TestCase {
+ private ClassLoader oldCL;
+
+ public void testHelloWorld() throws Exception {
+ TuscanyRuntime tuscany = new TuscanyRuntime("test", null);
+ tuscany.start();
+ ModuleContext moduleContext = CurrentModuleContext.getContext();
+ assertNotNull(moduleContext);
+
+ HelloWorldService helloworldService = (HelloWorldService)
moduleContext.locateService("HelloWorld");
+ assertNotNull(helloworldService);
+
+ String value = helloworldService .getGreetings("World");
+ assertEquals("Hello World", value);
+ tuscany.stop();
+ tuscany = new TuscanyRuntime("test", null);
+ tuscany.start();
+ moduleContext = CurrentModuleContext.getContext();
+ assertNotNull(moduleContext);
+ helloworldService = (HelloWorldService)
moduleContext.locateService("HelloWorld");
+ assertNotNull(helloworldService);
+ value = helloworldService .getGreetings("World");
+ assertEquals("Hello World", value);
+ tuscany.stop();
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ URL url = getClass().getResource("/helloworldmc/");
+ ClassLoader cl = new URLClassLoader(new URL[]{url},
getClass().getClassLoader());
+ oldCL = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(cl);
+ }
+
+ protected void tearDown() throws Exception {
+ Thread.currentThread().setContextClassLoader(oldCL);
+ super.tearDown();
+ }
+}
Modified:
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java?rev=400143&r1=400142&r2=400143&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
(original)
+++
incubator/tuscany/java/sca/core/src/main/java/org/apache/tuscany/core/context/impl/AbstractCompositeContext.java
Fri May 5 11:55:12 2006
@@ -150,9 +150,12 @@
public void start() {
synchronized (lock) {
try {
- if (lifecycleState != UNINITIALIZED && lifecycleState !=
STOPPED) {
- throw new IllegalStateException("Context not in
UNINITIALIZED state");
+ if (lifecycleState == STOPPED){
+ throw new IllegalStateException("Context cannot be
restarted - create a new one");
+ }else if (lifecycleState != UNINITIALIZED) {
+ throw new IllegalStateException("Context not in
UNINITIALIZED state");
}
+
lifecycleState = INITIALIZING;
initializeScopes();
@@ -219,7 +222,7 @@
return;
}
// need to block a start until reset is complete
- initializeLatch = new CountDownLatch(2);
+ initializeLatch = new CountDownLatch(1); //xcv
lifecycleState = STOPPING;
initialized = false;
if (scopeContexts != null) {
@@ -234,6 +237,7 @@
// allow initialized to be called
initializeLatch.countDown();
lifecycleState = STOPPED;
+
}
public void setModule(Module module) {
@@ -540,6 +544,9 @@
* Blocks until the module context has been initialized
*/
protected void checkInit() {
+ if (lifecycleState == STOPPED){
+ throw new IllegalStateException("Context cannot be restarted -
create a new one");
+ }
if (!initialized) {
try {
/* block until the module has initialized */
Modified:
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java?rev=400143&r1=400142&r2=400143&view=diff
==============================================================================
---
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
(original)
+++
incubator/tuscany/java/sca/core/src/test/java/org/apache/tuscany/core/runtime/RuntimeBootTestCase.java
Fri May 5 11:55:12 2006
@@ -56,9 +56,6 @@
runtime.stop();
assertEquals(Lifecycle.STOPPED, runtime.getLifecycleState());
-
- runtime.start();
- assertEquals(Lifecycle.RUNNING, runtime.getLifecycleState());
}
public void testIncrementalBoot() throws Exception{