diff options
Diffstat (limited to 'sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test')
10 files changed, 418 insertions, 1 deletions
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<String> upperAsync(String s); + + // Async Callback + public Future<String> upperAsync(String s, AsyncHandler<String> 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<String> 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<String> 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<String> 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(); + } +} diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/test.composite b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/test.composite index 43a75f50a7..1f5b98c00b 100644 --- a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/test.composite +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/test.composite @@ -55,6 +55,7 @@ <!-- Test component converts a string to uppercase --> <component name="upper-test"> <t:implementation.sample class="sample.UpperTest"/> - </component> + </component> + </composite> diff --git a/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/testasync.composite b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/testasync.composite new file mode 100644 index 0000000000..c289a1ab32 --- /dev/null +++ b/sca-java-2.x/trunk/unreleased/samples/implementation-sample-async/src/test/resources/testasync.composite @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * 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. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1" + targetNamespace="http://test" + name="testasync"> + + <!-- SampleAsync implementation at reference with Java async at service --> + <component name="SampleAsyncReference"> + <t:implementation.sampleasync class="sampleasync.impl.UpperSampleAsyncReferenceImpl"/> + <reference name="upper" target="JavaAsyncService"/> + </component> + + <component name="JavaAsyncService"> + <implementation.java class="sampleasync.impl.UpperJavaAsyncServiceImpl"/> + </component> + + <!-- SampleAsync implementation at service with Java async at reference --> + <component name="JavaAsyncReference"> + <implementation.java class="sampleasync.impl.UpperJavaAsyncReferenceImpl"/> + <reference name="upper" target="SampleAsyncService"/> + </component> + + <component name="SampleAsyncService"> + <t:implementation.sampleasync class="sampleasync.impl.UpperSampleAsyncServiceImpl"/> + </component> + +</composite> |