diff options
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta1/itest/oneway/src')
6 files changed, 0 insertions, 511 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayClient.java b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayClient.java deleted file mode 100644 index ecd239d5fb..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayClient.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 org.apache.tuscany.sca.itest.oneway; - -/** - * The client for the oneway itest. - * - * @version $Rev$ $Date$ - */ -public interface OneWayClient { - - /** - * This method will invoke the doSomething() @OneWay method on the OneWayService - * the specified number of times. - * - * @param count The number of times to invoke doSomething() on the OneWayService - */ - void doSomething(int count); - - /** - * This method will invoke a @OneWay method that throws an exception. - */ - void doSomethingWhichThrowsException(); -} diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayService.java b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayService.java deleted file mode 100644 index ba74b67d31..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/OneWayService.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 org.apache.tuscany.sca.itest.oneway; - - -import org.oasisopen.sca.annotation.OneWay; -import org.oasisopen.sca.annotation.Remotable; - - -/** - * The service interface used when testing @OneWay interactions. - * - * @version $Rev$ $Date$ - */ -@Remotable -public interface OneWayService { - - /** - * This OneWay method will increment the callCount by 1. - * - * @param count Not used - */ - @OneWay - void doSomething(int count); - - /** - * This one way method will throw a NullPointerException. - */ - @OneWay - void doSomethingWhichThrowsException(); -} diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayClientImpl.java b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayClientImpl.java deleted file mode 100644 index 8ed3c3d638..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayClientImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * 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 org.apache.tuscany.sca.itest.oneway.impl; - -import org.apache.tuscany.sca.itest.oneway.OneWayClient; -import org.apache.tuscany.sca.itest.oneway.OneWayService; -import org.junit.Assert; -import org.oasisopen.sca.annotation.Reference; - - -/** - * The client for the oneway itest. - * - * @version $Rev$ $Date$ - */ -public class OneWayClientImpl implements OneWayClient { - /** - * Injected reference to the OneWayService. - */ - @Reference - protected OneWayService oneWayService; - - /** - * Tracks the number of calls of the doSomething() method on the OneWayService. - */ - public static int callCount = 0; - - /** - * {@inheritDoc} - */ - public void doSomething(int count) { - callCount = callCount + count; - - for (int loopCount = 0; loopCount < count; loopCount++) { - //System.out.println("Client: doSomething " + loopCount); - //System.out.flush(); - oneWayService.doSomething(loopCount); - } - } - - /** - * {@inheritDoc} - */ - public void doSomethingWhichThrowsException() { - Assert.assertNotNull(oneWayService); - oneWayService.doSomethingWhichThrowsException(); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java deleted file mode 100644 index ef88c22baa..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/java/org/apache/tuscany/sca/itest/oneway/impl/OneWayServiceImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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 org.apache.tuscany.sca.itest.oneway.impl; - -import org.apache.tuscany.sca.itest.oneway.OneWayService; - -import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicInteger; - -/** - * The service for the oneway itest. - * - * @version $Rev$ $Date$ - */ - - -public class OneWayServiceImpl implements OneWayService { - - /** - * This is the error message that will be in the Exception thrown by - * the doSomethingWhichThrowsException() method. - */ - public static final String EXCEPTION_MESSAGE = "Sample RuntimeException from a @OneWay method"; - - /** - * Counts the number of invocations to doSomething(). - */ - public static final AtomicInteger CALL_COUNT = new AtomicInteger(); - - /** - * Counts the number of invocations of the doSomethingWhichThrowsException() method. - */ - public static final AtomicInteger CALL_COUNT_FOR_THROWS_EXCEPTION_METHOD = new AtomicInteger(); - - /** - * {@inheritDoc} - */ - public void doSomething(int count) { - CALL_COUNT.incrementAndGet(); - - // System.out.println("Service: doSomething " + count + " callCount = " + callCount); - // System.out.flush(); - } - - /** - * {@inheritDoc} - */ - public void doSomethingWhichThrowsException() { - System.out.println("OneWay invoked. About to throw an Exception"); - CALL_COUNT_FOR_THROWS_EXCEPTION_METHOD.incrementAndGet(); - throw new NullPointerException(EXCEPTION_MESSAGE); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/resources/OneWayContribution/META-INF/sca-deployables/oneWay.composite b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/resources/OneWayContribution/META-INF/sca-deployables/oneWay.composite deleted file mode 100644 index b375944bbd..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/main/resources/OneWayContribution/META-INF/sca-deployables/oneWay.composite +++ /dev/null @@ -1,57 +0,0 @@ -<?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"
- targetNamespace="http://oneway"
- name="OneWayITest">
-
- <component name="OneWayClientComponent">
- <implementation.java class="org.apache.tuscany.sca.itest.oneway.impl.OneWayClientImpl"/>
- <reference name="oneWayService" target="OneWayServiceComponent">
- <interface.java interface="org.apache.tuscany.sca.itest.oneway.OneWayService" />
- </reference>
- </component>
-
- <component name="OneWayServiceComponent">
- <implementation.java class="org.apache.tuscany.sca.itest.oneway.impl.OneWayServiceImpl"/>
- <service name="OneWayService">
- <interface.java interface="org.apache.tuscany.sca.itest.oneway.OneWayService" />
- <binding.ws uri="http://localhost:8085/OneWayServiceComponent"/>
- </service>
- </component>
-
-
- <!-- OneWay Client and Server Components that use the standard SCA Binding so we can validate -->
- <!-- that the NonBlockingInterceptor logs an message when an Exception is thrown by the code -->
- <!-- that is called. See TUSCANY-2225 -->
- <component name="OneWayClientComponentSCABinding">
- <implementation.java class="org.apache.tuscany.sca.itest.oneway.impl.OneWayClientImpl"/>
- <reference name="oneWayService" target="OneWayServiceComponentSCABinding">
- <interface.java interface="org.apache.tuscany.sca.itest.oneway.OneWayService" />
- </reference>
- </component>
-
- <component name="OneWayServiceComponentSCABinding">
- <implementation.java class="org.apache.tuscany.sca.itest.oneway.impl.OneWayServiceImpl"/>
- <service name="OneWayService">
- <interface.java interface="org.apache.tuscany.sca.itest.oneway.OneWayService" />
- </service>
- </component>
-
-</composite>
diff --git a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java b/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java deleted file mode 100644 index 1f771ea4ce..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/itest/oneway/src/test/java/org/apache/tuscany/sca/itest/oneway/OneWayTestCase.java +++ /dev/null @@ -1,235 +0,0 @@ -/* - * 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 org.apache.tuscany.sca.itest.oneway; - -import java.io.File; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Handler; -import java.util.logging.Level; -import java.util.logging.LogRecord; -import java.util.logging.Logger; - -import junit.framework.Assert; - -import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; -import org.apache.tuscany.sca.itest.oneway.impl.OneWayClientImpl; -import org.apache.tuscany.sca.itest.oneway.impl.OneWayServiceImpl; -import org.apache.tuscany.sca.node.Contribution; -import org.apache.tuscany.sca.node.Node; -import org.apache.tuscany.sca.node.NodeFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -/** - * This test case will test invoking @OneWay operations. - * - * @version $Date$ $Revision$ - */ -public class OneWayTestCase { - /** - * Maximum period of time that we are prepared to wait for all the @OneWay - * method calls to complete in milliseconds. - */ - private static final int MAX_SLEEP_TIME = 10000; - - private Node node; - - /** - * Initialise the SCADomain. - * - * @throws Exception Failed to initialise the SCADomain - */ - @Before - public void setUp() throws Exception { - - NodeFactory factory = NodeFactory.newInstance(); - node = factory.createNode(new File("src/main/resources/OneWayContribution/META-INF/sca-deployables/oneWay.composite").toURI().toURL().toString(), - new Contribution("TestContribution", new File("src/main/resources/OneWayContribution/META-INF/sca-deployables/").toURI().toURL().toString())); - node.start(); - - } - - /** - * This method will ensure that the SCADomain is shutdown. - * - * @throws Exception Failed to shutdown the SCADomain - */ - @After - public void tearDown() throws Exception { - node.stop(); - } - - /** - * This test will test repeatedly calling a @OneWay operation and ensure that the correct - * number of @OneWay operations are run. - * - * @throws Exception Test failed - */ - @Test - public void testOneWay() throws Exception { - OneWayClient client = - node.getService(OneWayClient.class, "OneWayClientComponent"); - - int count = 100; - - for (int i = 0; i < 10; i++) { - // System.out.println("Test: doSomething " + count); - // System.out.flush(); - client.doSomething(count); - - // TUSCANY-2192 - We need to sleep to allow the @OneWay method calls to complete. - // Note: This can take different periods depending on the speed and load - // on the computer where the test is being run. - // This loop will wait for the required number of @OneWay method calls to - // have taken place or MAX_SLEEP_TIME to have passed. - long startSleep = System.currentTimeMillis(); - while (OneWayClientImpl.callCount != OneWayServiceImpl.CALL_COUNT.get() - && System.currentTimeMillis() - startSleep < MAX_SLEEP_TIME) { - Thread.sleep(100); - // System.out.println("" + OneWayClientImpl.callCount + "," + OneWayServiceImpl.callCount); - } - - System.out.println("Finished callCount = " + OneWayServiceImpl.CALL_COUNT); - - Assert.assertEquals(OneWayClientImpl.callCount, OneWayServiceImpl.CALL_COUNT.get()); - } - } - - /** - * This method will invoke a @OneWay method that throws an exception - * when invoked over a SCA Binding which uses the NonBlockingInterceptor and - * ensure that the Exception is logged. - * See TUSCANY-2225 - */ - @Test - public void testOneWayUsingNonBlockingInterceptorThrowsAnException() { - OneWayClient client = - node.getService(OneWayClient.class, "OneWayClientComponentSCABinding"); - - // We need to modify the JDK Logger for the NonBlockingInterceptor so we - // can check that it logs a message for the @OneWay invocation that throws - // an Exception - Logger nbiLogger = Logger.getLogger(NonBlockingInterceptor.class.getName()); - DummyJDKHandler handler = new DummyJDKHandler(); - nbiLogger.addHandler(handler); - - // Add a message on the console to explain the stack dump that is going to be - // displayed and state that this is not a problem but expected behaviour - System.out.println(); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - System.out.println("IMPORTANT: The error message that appears on the console"); - System.out.println("below is an expected error if it is a NullPointerException"); - System.out.println(" with the message of:"); - System.out.println(" \"" + OneWayServiceImpl.EXCEPTION_MESSAGE + "\""); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - System.out.println(); - System.out.flush(); - - // Invoke the @OneWay method that throws an exception - client.doSomethingWhichThrowsException(); - - // The logging is done asynchronously so we will need to wait a bit before - // the log message appears. - long start = System.currentTimeMillis(); - boolean logged = false; - while (System.currentTimeMillis() - start < MAX_SLEEP_TIME && !logged) { - // Has the log message been logged? - if (handler.exceptionLogged.get()) { - logged = true; - } else { - try { - Thread.sleep(25); - } catch (InterruptedException ex) { - Assert.fail("Unexpected exception " + ex); - } - } - } - - // Add a message explaining that errors beyond this point should be reported - System.out.println(); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - System.out.println("End of expected exceptions. Any errors beyond this point are errors!"); - System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-"); - System.out.println(); - System.out.flush(); - - // Remove the handler - nbiLogger.removeHandler(handler); - - // Make sure that the exception was logged - Assert.assertTrue(handler.exceptionLogged.get()); - } - - /** - * A handler that is added to the JDK Logging system to examine the log messages - * generated to ensure that a @OneWay method that throws an Exception will - * generate a log message. - */ - private class DummyJDKHandler extends Handler { - - /** - * Used to track whether the exception has been logged. - */ - private AtomicBoolean exceptionLogged = new AtomicBoolean(false); - - /** - * Constructor. - */ - private DummyJDKHandler() { - super.setLevel(Level.ALL); - } - - /** - * {@inheritDoc} - */ - @Override - public void close() throws SecurityException { - // Nothing to do - } - - /** - * {@inheritDoc} - */ - @Override - public void flush() { - // Nothing to do - } - - /** - * Examines the LogRecord and checks whether it matches the one we are looking for. - * If it matches, it will set exceptionLogged to True. - * - * @param record The Log Record that is being published - */ - @Override - public void publish(LogRecord record) { - // The log message we are looking for is Severe - if (record.getLevel() == Level.SEVERE) { - if (record.getThrown() != null - && record.getThrown().toString().indexOf( - OneWayServiceImpl.EXCEPTION_MESSAGE) != -1) { - // We have found our Exception. - exceptionLogged.set(true); - } - } - } - } -} |