summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
authoredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2011-01-20 17:09:19 +0000
committeredwardsmj <edwardsmj@13f79535-47bb-0310-9956-ffa450edef68>2011-01-20 17:09:19 +0000
commit9cc1048cec667bab9e31c3d97759372730917556 (patch)
tree8b3e75d614f4faa62d0221108db644818356ed79 /sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca
parentdec8d4b54c3df67becf018552ca3c2d9d091218d (diff)
Adding new group of Itests for Async Services
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1061396 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca')
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java77
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java34
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java34
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java26
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java38
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java168
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java27
-rw-r--r--sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java32
8 files changed, 436 insertions, 0 deletions
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java
new file mode 100644
index 0000000000..880fd3cb9e
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/ASM_0002_Client.java
@@ -0,0 +1,77 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.annotation.Service;
+import org.oasisopen.sca.annotation.Reference;
+import org.oasisopen.sca.annotation.Property;
+import org.apache.tuscany.sca.itest.Service1;
+import org.apache.tuscany.sca.itest.TestException;
+import org.apache.tuscany.sca.itest.TestInvocation;
+
+
+/**
+ * Test initiation class with a single reference of multiplicity 1..1
+ * @author MikeEdwards
+ *
+ */
+@Service(TestInvocation.class)
+public class ASM_0002_Client implements org.apache.tuscany.sca.itest.TestInvocation {
+
+ @Property
+ public String testName = "ASM_xxxx";
+
+ // required=false implies a multiplicity of 0..1 so that this component need not be wired
+ @Reference(required=false)
+ public Service1 reference1;
+
+ /**
+ * This method is offered as a service and is
+ * invoked by the test client to run the test
+ */
+ public String invokeTest( String input ) throws TestException {
+ String response = null;
+
+ try {
+ response = runTest( input );
+ } catch( Exception e ) {
+ System.out.println("TestInvocation: Test service got an exception during execution:" + e.getClass().getName()+ " " + e.getMessage() );
+ e.printStackTrace();
+ throw new TestException("Test service got an exception during execution: " + e.getClass().getName()+ " " + e.getMessage() );
+ } // end try
+ return response;
+ } // end method invokeTest
+
+ /**
+ * This method actually runs the test - and is subclassed by classes that run other tests.
+ * @param input - an input string
+ * @return - a response string = "ASM_0001 inputString xxxxx" where xxxxx depends on the invoked service
+ *
+ */
+ public String runTest( String input ){
+ String response = null;
+ // Deals with cases where this component reference is not wired
+ if( reference1 != null ) {
+ String response1 = reference1.operation1(input);
+
+ response = testName + " " + input + " " + response1;
+ } else {
+ response = testName + " " + input + " no invocation";
+ } // end if
+
+ return response;
+ } // end method runTest
+
+ /**
+ * Sets the name of the test
+ * @param name - the test name
+ */
+ protected void setTestName( String name ) {
+ testName = name;
+ }
+
+} //
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java
new file mode 100644
index 0000000000..b2fea7a4dd
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault1.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+ package org.apache.tuscany.sca.itest;
+
+/**
+ * A business exception
+ *
+ */
+public class BusinessFault1 extends Exception {
+
+ // Serialization UID
+ private static final long serialVersionUID = 44240525335368929L;
+
+ public BusinessFault1() {
+ super();
+ }
+
+ public BusinessFault1(String arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault1(Throwable arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault1(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+} // end class BusinessFault1
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java
new file mode 100644
index 0000000000..fac4f58c75
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/BusinessFault2.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+ package org.apache.tuscany.sca.itest;
+
+/**
+ * A business exception
+ *
+ */
+public class BusinessFault2 extends Exception {
+
+ // Serialization UID
+ private static final long serialVersionUID = 44240525335368929L;
+
+ public BusinessFault2() {
+ super();
+ }
+
+ public BusinessFault2(String arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault2(Throwable arg0) {
+ super(arg0);
+ }
+
+ public BusinessFault2(String arg0, Throwable arg1) {
+ super(arg0, arg1);
+ }
+
+} // end class BusinessFault1
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java
new file mode 100644
index 0000000000..6c45fa3c03
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1.java
@@ -0,0 +1,26 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * A test service interface
+ * @author MikeEdwards
+ *
+ */
+@Remotable
+public interface Service1 {
+
+ /**
+ * Method for invoking testcase service
+ * @param input - input parameter(s) as a String
+ * @return - output data as a String
+ */
+ public String operation1( String input );
+
+}
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java
new file mode 100644
index 0000000000..80bdba955e
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServer.java
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+import org.oasisopen.sca.ResponseDispatch;
+import org.oasisopen.sca.annotation.AsyncFault;
+import org.oasisopen.sca.annotation.AsyncInvocation;
+import org.oasisopen.sca.annotation.Remotable;
+
+/**
+ * Service1 service interface
+ * - Asynchronous server version
+ */
+@AsyncInvocation
+@Remotable
+public interface Service1AsyncServer {
+
+ /**
+ * Synchronous method for invoking testcase service
+ * @param input - input parameter as a String
+ * @return - output data as a String
+ * Listed here for documentation purposes - this is the operation that the async server operation maps to
+ */
+ // public String operation1( String input );
+
+ /**
+ * Async server version of the synchronous operation1 method
+ * @param input - input parameter as a String
+ * @param handler - the ResponseDispatch<String> handler used to send the response message (a String in this case)
+ */
+ @AsyncFault( {BusinessFault1.class, BusinessFault2.class} )
+ public void operation1Async( String input, ResponseDispatch<String> handler );
+
+} // end interface Service1AsyncServer
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java
new file mode 100644
index 0000000000..16c513bbf3
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/Service1AsyncServerImpl.java
@@ -0,0 +1,168 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.oasisopen.sca.ResponseDispatch;
+import org.oasisopen.sca.ServiceUnavailableException;
+import org.oasisopen.sca.annotation.*;
+
+
+/**
+ * Java component implementation
+ * 1 service with interface Service1AsyncServer
+ * 0 references
+ *
+ * Async server implementation of the Service1 service
+ *
+ */
+@Service(Service1AsyncServer.class)
+public class Service1AsyncServerImpl implements Service1AsyncServer {
+
+ private volatile ResponseDispatch<String> responseHandler = null;
+
+ private volatile String tmpFilePath = null;
+
+ @Property(required=true)
+ public volatile String serviceName = "service1";
+
+ /*
+ public String operation1(String input) {
+ return serviceName + " operation1 invoked";
+ }
+ */
+
+ public void operation1Async(String input, ResponseDispatch<String> handler) {
+ // Store the ResponseDispatch object
+ responseHandler = handler;
+
+ serializeResponseHandler(responseHandler);
+
+ // Now kick off processing on a separate thread that will dispatch the response some time after this
+ // initial method returns...
+ runResponseThread( input );
+
+ // return
+ return;
+ } // end method operation1Async
+
+ /**
+ * Serialize the response handler to a file
+ * @param responseHandler2
+ */
+ private void serializeResponseHandler(
+ ResponseDispatch<String> responseHandler2) {
+ if( responseHandler2 instanceof Serializable ) {
+ Serializable obj = (Serializable)responseHandler2;
+ FileOutputStream fos;
+ try {
+ File tmpFile = File.createTempFile("Async_Server", null);
+ tmpFilePath = tmpFile.getCanonicalPath();
+ fos = new FileOutputStream(tmpFile);
+ ObjectOutputStream oos = new ObjectOutputStream(fos);
+
+ oos.writeObject(obj);
+
+ oos.close();
+ } catch (FileNotFoundException e) {
+ } catch (IOException e) {
+ e.printStackTrace();
+ } // end try
+
+ } // end if
+ } // end method serializeResponseHandler
+
+ @SuppressWarnings("unchecked")
+ public ResponseDispatch<String> deserializeResponseHandler() {
+ try {
+ if( tmpFilePath == null ) return null;
+ FileInputStream fis = new FileInputStream( tmpFilePath );
+ ObjectInputStream ois = new ObjectInputStream(fis);
+
+ ResponseDispatch<String> responseDispatch = (ResponseDispatch<String>) ois.readObject();
+
+ ois.close();
+ return responseDispatch;
+ } catch (Exception e) {
+ e.printStackTrace();
+ } // end try
+
+ return null;
+ } // end method deserializeResponseHandler
+
+ /**
+ * Method used to run a separate thread, to invoke the ResponseDispatch
+ */
+ private void runResponseThread( String input ) {
+
+ int invocationCount = 2; // # of threads to use
+ long maxWaitTime = 5000; // Max wait time for completion = 5sec
+
+ // Run the tests using a ThreadPoolExecutor
+ ThreadPoolExecutor theExecutor = new ThreadPoolExecutor( invocationCount, invocationCount,
+ maxWaitTime, TimeUnit.MILLISECONDS,
+ new ArrayBlockingQueue<Runnable>( invocationCount ) );
+
+
+
+ // Perform the invocations on separate thread...
+ theExecutor.execute( new separateThreadInvoker( input ) );
+
+ } // end method runResponseThread
+
+ /**
+ * An inner class which acts as a runnable task for invoking APIs on threads that are not processing
+ * either a service operation or a callback operation
+ */
+ private class separateThreadInvoker implements Runnable {
+
+ private long pauseTime = 1000; // Pause interval to allow initiating thread to complete
+ private String input; // Input parameter
+
+ public separateThreadInvoker( String input ) {
+ super();
+ this.input = input;
+ } // end constructor
+
+ public void run() {
+
+ // Wait for a short time to ensure that the invoking thread has time to return
+ try {
+ Thread.sleep(pauseTime);
+ } catch (InterruptedException e) {
+ // Nothing to do here...
+ } // end try
+
+ ResponseDispatch<String> responseHandler2 = deserializeResponseHandler();
+ if( responseHandler2 != null ) {
+ responseHandler = responseHandler2;
+ } // end if
+
+ if( "exception".equals(input) ) {
+ // Invoke the response dispatch object to return a an exception
+ responseHandler.sendFault( new BusinessFault1(serviceName + " operation1 invoked asynchronously"));
+
+ } else {
+ // Invoke the response dispatch object to return a response
+ responseHandler.sendResponse( serviceName + " operation1 invoked asynchronously");
+ } // end if
+ } // end method run
+
+ } // end class separateThreadInvoker
+
+}
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java
new file mode 100644
index 0000000000..456ed2ba02
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestException.java
@@ -0,0 +1,27 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+/*
+ * Exception thrown by SCA Test services
+ */
+public class TestException extends Exception {
+
+ /**
+ * Required serialVersionUID field
+ */
+ private static final long serialVersionUID = -6978058912756564824L;
+
+ public TestException() { super(); };
+
+ public TestException( String msg ) { super( msg ); };
+
+ public TestException( String msg, Throwable cause ) { super( msg, cause); };
+
+ public TestException( Throwable cause ) { super( cause ); };
+
+}
diff --git a/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java
new file mode 100644
index 0000000000..a0233946b5
--- /dev/null
+++ b/sca-java-2.x/trunk/testing/itest/async-services/src/main/java/org/apache/tuscany/sca/itest/TestInvocation.java
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright(C) OASIS(R) 2009,2010. All Rights Reserved.
+ * OASIS trademark, IPR and other policies apply.
+ *
+ */
+package org.apache.tuscany.sca.itest;
+
+import javax.jws.WebMethod;
+import org.oasisopen.sca.annotation.Remotable;
+import org.apache.tuscany.sca.itest.TestException;
+
+
+/**
+ * Basic interface to invoke testcases
+ * 1 operation
+ * - "invokeTest", string input, string output
+ *
+ */
+@Remotable
+public interface TestInvocation {
+
+ /**
+ * Method for invoking testcase
+ * @param input - input parameter(s) as a String
+ * @return - output data as a String
+ * @throws - a TestException is thrown in cases where the test service fails internally
+ */
+ @WebMethod
+ public String invokeTest( String input ) throws TestException ;
+
+}