From fcc065b22a21e117c0a9636bea5292a4fb2d2822 Mon Sep 17 00:00:00 2001 From: slaws Date: Fri, 27 May 2011 15:13:50 +0000 Subject: TUSCANY-3867 - Update the status reporting so that I can see what components the events are related to git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1128352 13f79535-47bb-0310-9956-ffa450edef68 --- .../LifecycleReferenceBindingProvider.java | 8 +- .../lifecycle/LifecycleServiceBindingProvider.java | 8 +- .../main/java/helloworld/HelloworldClientImpl.java | 8 +- .../src/main/java/helloworld/StatusImpl.java | 4 + .../lifecycle/LifecycleProvider.java | 4 +- .../src/main/resources/lifecycle.composite | 2 +- .../sca/itest/lifecycle/LifecycleTestCase.java | 151 +++++++++++++++------ 7 files changed, 129 insertions(+), 56 deletions(-) diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java index 5709de7747..5c2ca0bf77 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleReferenceBindingProvider.java @@ -22,6 +22,8 @@ package binding.lifecycle; import helloworld.StatusImpl; import org.apache.tuscany.sca.assembly.EndpointReference; +import org.apache.tuscany.sca.assembly.impl.EndpointImpl; +import org.apache.tuscany.sca.assembly.impl.EndpointReferenceImpl; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; import org.apache.tuscany.sca.invocation.Invoker; @@ -41,11 +43,13 @@ public class LifecycleReferenceBindingProvider implements ReferenceBindingProvid } public void start() { - StatusImpl.statusString += "Reference binding start "; + StatusImpl.appendStatus("Reference binding start", + ((EndpointReferenceImpl)endpoint).toStringWithoutHash()); } public void stop() { - StatusImpl.statusString += "Reference binding stop "; + StatusImpl.appendStatus("Reference binding stop", + ((EndpointReferenceImpl)endpoint).toStringWithoutHash()); } public InterfaceContract getBindingInterfaceContract() { diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java index 0f62e13aed..158aa27201 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/binding/lifecycle/LifecycleServiceBindingProvider.java @@ -20,6 +20,8 @@ package binding.lifecycle; import helloworld.StatusImpl; + +import org.apache.tuscany.sca.assembly.impl.EndpointImpl; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.provider.ServiceBindingProvider; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; @@ -34,11 +36,13 @@ public class LifecycleServiceBindingProvider implements ServiceBindingProvider { } public void start() { - StatusImpl.statusString += "Service binding start "; + StatusImpl.appendStatus("Service binding start", + ((EndpointImpl)endpoint).toStringWithoutHash()); } public void stop() { - StatusImpl.statusString += "Service binding stop "; + StatusImpl.appendStatus("Service binding stop", + ((EndpointImpl)endpoint).toStringWithoutHash()); } public InterfaceContract getBindingInterfaceContract() { diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java index 9328b53bac..d8a56eacde 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/HelloworldClientImpl.java @@ -39,22 +39,22 @@ public class HelloworldClientImpl implements Helloworld { @Init public void initialize() throws Exception{ if (throwTestExceptionOnInit) { - StatusImpl.statusString += "Exception on init "; + StatusImpl.appendStatus("Exception on init", "HelloworldClientImpl"); throw new Exception("Exception on init"); } - StatusImpl.statusString += "HelloworldClientImpl init "; + StatusImpl.appendStatus("Init", "HelloworldClientImpl"); System.out.println(">>>>>> " + sayHello("init")); } @Destroy public void destroy() throws Exception{ if (throwTestExceptionOnDestroy) { - StatusImpl.statusString += "Exception on destroy "; + StatusImpl.appendStatus("Exception on destroy", "HelloworldClientImpl"); throw new Exception("Exception on destroy"); } - StatusImpl.statusString += "HelloworldClientImpl destroy "; + StatusImpl.appendStatus("Destroy", "HelloworldClientImpl"); } public String sayHello(String name) throws Exception { diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java index a18633ca74..2932da1554 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/helloworld/StatusImpl.java @@ -22,5 +22,9 @@ package helloworld; public class StatusImpl { public static String statusString = ""; + + public static void appendStatus(String event, String location){ + statusString += event + " - " + location + "\n"; + } } diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java index c06346d8d3..f1e303882f 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/java/implementation/lifecycle/LifecycleProvider.java @@ -56,11 +56,11 @@ class LifecycleProvider implements ImplementationProvider { } public void start() { - StatusImpl.statusString += "Implementation start "; + StatusImpl.appendStatus("Implementation start", comp.getName()); } public void stop() { - StatusImpl.statusString += "Implementation stop "; + StatusImpl.appendStatus("Implementation stop", comp.getName()); } public boolean supportsOneWayInvocation() { diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite index 2c48cc4bf9..c959749c03 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/main/resources/lifecycle.composite @@ -20,7 +20,7 @@ + name="lifecycle"> diff --git a/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java b/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java index dbffc8ce8c..01180b86bb 100644 --- a/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java +++ b/sca-java-2.x/trunk/testing/itest/lifecycle/src/test/java/org/apache/tuscany/sca/itest/lifecycle/LifecycleTestCase.java @@ -39,7 +39,7 @@ public class LifecycleTestCase { @Before public void setUp() throws Exception { - + StatusImpl.statusString = ""; } @After @@ -48,7 +48,9 @@ public class LifecycleTestCase { } @Test - public void testNormalShutdown() throws Exception{ + public void testNormalShutdownNoMessage() throws Exception{ + + StatusImpl.statusString = ""; TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); @@ -75,19 +77,67 @@ public class LifecycleTestCase { // see what happened System.out.println(StatusImpl.statusString); - Assert.assertEquals("Service binding start " + - "Implementation start " + - "Service binding start " + - "HelloworldClientImpl init " + - "Reference binding start " + - "Service binding stop " + - "Service binding stop " + - "Implementation stop " + - "Reference binding stop " + - "HelloworldClientImpl destroy ", + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldService2\n" + + "Service binding start - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImpl\n" + + "Reference binding start - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldService2\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImpl\n", StatusImpl.statusString); } + @Test + public void testNormalShutdownAfterMessage() throws Exception{ + + TuscanyRuntime tuscanyRuntime = TuscanyRuntime.newInstance(); + + // create a Tuscany node + node = tuscanyRuntime.createNode(); + + // install a contribution + node.installContribution("HelloworldContrib", "target/classes", null, null); + + // start a composite + node.startComposite("HelloworldContrib", "lifecycle.composite"); + + // send a message + Helloworld hw = node.getService(Helloworld.class, "HelloworldService1"); + System.out.println(hw.sayHello("name")); + + // stop a composite + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + + // uninstall a constribution + node.uninstallContribution("HelloworldContrib"); + + // stop a Tuscany node + node.stop(); + + // stop the runtime + tuscanyRuntime.stop(); + + // see what happened + System.out.println(StatusImpl.statusString); + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldService2\n" + + "Service binding start - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImpl\n" + + "Reference binding start - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + /*extra ref start for getService reference*/ + "Reference binding start - EndpointReference: URI = HelloworldService1#reference-binding($self$.Helloworld/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldService2\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + /*$self$ reference is not stopped */ + "Destroy - HelloworldClientImpl\n", + StatusImpl.statusString); + } + @Test public void testInitExceptionShutdown() throws Exception{ @@ -109,7 +159,11 @@ public class LifecycleTestCase { } // stop a composite - node.stopComposite("HelloworldContrib", "lifecycle.composite"); + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + } // uninstall a constribution node.uninstallContribution("HelloworldContrib"); @@ -122,16 +176,15 @@ public class LifecycleTestCase { // see what happened System.out.println(StatusImpl.statusString); - Assert.assertEquals("Service binding start " + - "Implementation start " + - "Service binding start " + - "HelloworldClientImpl init " + - "Reference binding start " + - "Service binding stop " + - "Service binding stop " + - "Implementation stop " + - "Reference binding stop " + - "HelloworldClientImpl destroy ", + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldService2\n" + + "Service binding start - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Exception on init - HelloworldClientImpl\n" + + /* is it right that the destroy happens directly?*/ + "Destroy - HelloworldClientImpl\n" + + "Service binding stop - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldService2\n", StatusImpl.statusString); HelloworldClientImpl.throwTestExceptionOnInit = false; @@ -151,10 +204,18 @@ public class LifecycleTestCase { node.installContribution("HelloworldContrib", "target/classes", null, null); // start a composite - node.startComposite("HelloworldContrib", "lifecycle.composite"); + try { + node.startComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it's thrown from the HelloworldClientImpl @Destroy method + } // stop a composite - node.stopComposite("HelloworldContrib", "lifecycle.composite"); + try { + node.stopComposite("HelloworldContrib", "lifecycle.composite"); + } catch (Exception exception) { + // it will complain about the composite not being started + } // uninstall a constribution node.uninstallContribution("HelloworldContrib"); @@ -167,16 +228,16 @@ public class LifecycleTestCase { // see what happened System.out.println(StatusImpl.statusString); - Assert.assertEquals("Service binding start " + - "Implementation start " + - "Service binding start " + - "HelloworldClientImpl init " + - "Reference binding start " + - "Service binding stop " + - "Service binding stop " + - "Implementation stop " + - "Reference binding stop " + - "HelloworldClientImpl destroy ", + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldService2\n" + + "Service binding start - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImpl\n" + + "Reference binding start - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldService2\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Exception on destroy - HelloworldClientImpl\n", StatusImpl.statusString); HelloworldClientImpl.throwTestExceptionOnDestroy = false; @@ -217,16 +278,16 @@ public class LifecycleTestCase { // see what happened System.out.println(StatusImpl.statusString); - Assert.assertEquals("Service binding start " + - "Implementation start " + - "Service binding start " + - "HelloworldClientImpl init " + - "Reference binding start " + - "Service binding stop " + - "Service binding stop " + - "Implementation stop " + - "Reference binding stop " + - "HelloworldClientImpl destroy ", + Assert.assertEquals("Service binding start - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Implementation start - HelloworldService2\n" + + "Service binding start - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Init - HelloworldClientImpl\n" + + "Reference binding start - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Service binding stop - Endpoint: URI = HelloworldService2#service-binding(Helloworld/lifecycle)\n" + + "Implementation stop - HelloworldService2\n" + + "Reference binding stop - EndpointReference: URI = HelloworldClient#reference-binding(service/lifecycle) WIRED_TARGET_FOUND_AND_MATCHED Target = Endpoint: URI = HelloworldService1#service-binding(Helloworld/lifecycle)\n" + + "Destroy - HelloworldClientImpl\n", StatusImpl.statusString); } -- cgit v1.2.3