From 931daedb4ffd8c1e57f54ee324c5c7d284004607 Mon Sep 17 00:00:00 2001 From: slaws Date: Mon, 22 Nov 2010 12:38:34 +0000 Subject: TUSCANY-3783 - Start working up a test case to drive the async infrastructure improvements git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1037692 13f79535-47bb-0310-9956-ffa450edef68 --- .../src/test/java/sampleasync/Upper.java | 33 ++++++++++ .../test/java/sampleasync/UpperAsyncReference.java | 47 +++++++++++++++ .../test/java/sampleasync/UpperAsyncService.java | 36 +++++++++++ .../impl/SampleAsyncReferenceTestCase.java | 63 +++++++++++++++++++ .../impl/UpperJavaAsyncReferenceImpl.java | 70 ++++++++++++++++++++++ .../impl/UpperJavaAsyncServiceImpl.java | 39 ++++++++++++ .../impl/UpperSampleAsyncReferenceImpl.java | 41 +++++++++++++ .../impl/UpperSampleAsyncServiceImpl.java | 42 +++++++++++++ 8 files changed, 371 insertions(+) create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleAsyncReferenceTestCase.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java create mode 100644 sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java (limited to 'sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java') diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java new file mode 100644 index 0000000000..0c29cea1dc --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/Upper.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Upper { + + String upper(String s); +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java new file mode 100644 index 0000000000..ad2e62f85d --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncReference.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync; + +import java.util.concurrent.Future; + +import javax.xml.ws.AsyncHandler; +import javax.xml.ws.Response; + +import org.oasisopen.sca.annotation.AsyncInvocation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +@AsyncInvocation +public interface UpperAsyncReference { + + // Sync + String upper(String s); + + // Aysnc Poll + public Response upperAsync(String s); + + // Async Callback + public Future upperAsync(String s, AsyncHandler handler); +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java new file mode 100644 index 0000000000..019b0c2f12 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/UpperAsyncService.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync; + +import org.oasisopen.sca.ResponseDispatch; +import org.oasisopen.sca.annotation.AsyncInvocation; +import org.oasisopen.sca.annotation.Remotable; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +@Remotable +@AsyncInvocation +public interface UpperAsyncService { + + void upper(String s,ResponseDispatch response); +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleAsyncReferenceTestCase.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleAsyncReferenceTestCase.java new file mode 100644 index 0000000000..6511f3ddf3 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/SampleAsyncReferenceTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static org.junit.Assert.assertEquals; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import sampleasync.Upper; + +/** + * Test how to run an SCA contribution containing a test composite on a + * Tuscany runtime node. + * + * @version $Rev$ $Date$ + */ +public class SampleAsyncReferenceTestCase { + static Node node; + + @BeforeClass + public static void setUp() throws Exception { + final NodeFactory nf = NodeFactory.newInstance(); + String here = SampleAsyncReferenceTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString(); + node = nf.createNode(new Contribution("test", here)); + node.start(); + } + + @AfterClass + public static void tearDown() throws Exception { + node.stop(); + } + + @Test + public void testReference() { + System.out.println("SampleAsyncReferenceTestCase.testReference"); + Upper upper = node.getService(Upper.class, "SampleAsyncReference"); + final String r = upper.upper("async"); + System.out.println(r); + assertEquals("ASYNC", r); + } +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java new file mode 100644 index 0000000000..9cf7ff9883 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncReferenceImpl.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static java.lang.System.out; + +import java.util.concurrent.ExecutionException; + +import javax.xml.ws.Response; + +import org.oasisopen.sca.annotation.Reference; + +import sampleasync.Upper; +import sampleasync.UpperAsyncReference; + +/** + * Sample service interface. + * + * @version $Rev$ $Date$ + */ +public class UpperJavaAsyncReferenceImpl implements Upper { + + @Reference + UpperAsyncReference upper; + + public String upper(String s) { + out.println("UpperAsyncReferenceImpl.upper(" + s + ")"); + + // async poll + Response response = upper.upperAsync(s); + + while (!response.isDone()){ + System.out.println("Waiting for poll"); + try { + Thread.sleep(500); + } catch (Exception ex) { + // do nothing + } + } + + String result = null; + + try { + result = response.get(); + System.out.println("Async client poll patern: result = " + result); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + return result; + } +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java new file mode 100644 index 0000000000..33eb668e59 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperJavaAsyncServiceImpl.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static java.lang.System.out; + +import org.oasisopen.sca.ResponseDispatch; + +import sampleasync.UpperAsyncService; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +public class UpperJavaAsyncServiceImpl implements UpperAsyncService { + + public void upper(String s,ResponseDispatch response) { + out.println("UpperServiceImple.upper(" + s + ")"); + response.sendResponse(s.toUpperCase()); + } +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java new file mode 100644 index 0000000000..e4ac64c37c --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncReferenceImpl.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static java.lang.System.out; +import sample.api.Java; +import sampleasync.Upper; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Upper.class) +public class UpperSampleAsyncReferenceImpl { + + @Java(Upper.class) + Upper upper; + + public String upper(String s) { + out.println("UpperReferenceImpl.upper(" + s + ")"); + return upper.upper(s); + } +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java new file mode 100644 index 0000000000..c71c3ca2b9 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/java/sampleasync/impl/UpperSampleAsyncServiceImpl.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package sampleasync.impl; + +import static java.lang.System.out; + +import org.oasisopen.sca.ResponseDispatch; + +import sample.api.Java; +import sampleasync.Upper; +import sampleasync.UpperAsyncService; + +/** + * Sample component implementation that uses Java interfaces. + * + * @version $Rev$ $Date$ + */ +@Java(Upper.class) +public class UpperSampleAsyncServiceImpl { + + public String upper(String s) { + out.println("UpperServiceImple.upper(" + s + ")"); + return s.toUpperCase(); + } +} -- cgit v1.2.3