From 394164ac05f97d71feae0d9aa43d67bdf5d695d4 Mon Sep 17 00:00:00 2001 From: nash Date: Fri, 29 Oct 2010 09:22:02 +0000 Subject: TUSCANY-3759: Add code to read stdin and stderr from spawned epmd process and reverse changes made by commit r1028371 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1028655 13f79535-47bb-0310-9956-ffa450edef68 --- .../distribution/src/main/release/src/BUILDING | 8 -- .../erlang/testing/ReferenceServiceTestCase.java | 23 ++- .../samples/helloworld-erlang-reference/README | 3 - .../helloworld/HelloWorldErlangClientTestCase.java | 154 +++++++++++--------- .../samples/helloworld-erlang-service/README | 3 - .../src/main/java/helloworld/HelloWorldServer.java | 149 +++++++++++--------- .../helloworld/HelloWorldErlangServerTestCase.java | 155 ++++++++++++--------- 7 files changed, 281 insertions(+), 214 deletions(-) (limited to 'sca-java-1.x/branches') diff --git a/sca-java-1.x/branches/sca-java-1.6.1/distribution/src/main/release/src/BUILDING b/sca-java-1.x/branches/sca-java-1.6.1/distribution/src/main/release/src/BUILDING index 40e95fa63f..926c8b397d 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/distribution/src/main/release/src/BUILDING +++ b/sca-java-1.x/branches/sca-java-1.6.1/distribution/src/main/release/src/BUILDING @@ -26,14 +26,6 @@ Initial Setup Unix users: export MAVEN_OPTS=-Xmx256m -XX:MaxPermSize=256m -5) You don't need any other software installed to run the Apache Tuscany SCA - build. However, if you have Erlang/OTP installed and in your path, you could - experience build problems if the version of Erlang/OTP in your path isn't - compatible with the Apache Tuscany SCA Erlang binding. To ensure that the - Apache Tuscany SCA build runs cleanly, you should either put the R12B version - of Erlang/OTP in your path or completely remove Erlang/OTP from your path - when running the Apache Tuscany SCA build. See TUSCANY-3759 for details. - Building -------- diff --git a/sca-java-1.x/branches/sca-java-1.6.1/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java b/sca-java-1.x/branches/sca-java-1.6.1/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java index 2073e4b154..4b829dfd0f 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java +++ b/sca-java-1.x/branches/sca-java-1.6.1/modules/binding-erlang-runtime/src/test/java/org/apache/tuscany/sca/binding/erlang/testing/ReferenceServiceTestCase.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.binding.erlang.testing; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; +import java.io.InputStream; import java.io.IOException; import org.apache.tuscany.sca.binding.erlang.impl.TypeMismatchException; @@ -76,9 +77,11 @@ public class ReferenceServiceTestCase { private static Process epmdProcess; @BeforeClass - public static void init() throws IOException { + public static void init() { try { epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + startReaderThread(epmdProcess.getInputStream()); + startReaderThread(epmdProcess.getErrorStream()); SCADomain domain = SCADomain .newInstance("ErlangReference.composite"); SCADomain.newInstance("ErlangService.composite"); @@ -103,6 +106,22 @@ public class ReferenceServiceTestCase { } } + private static void startReaderThread(final InputStream stream) { + Thread readerThread = new Thread() { + public void run() { + try { + byte[] buf = new byte[100]; + while (true) { + stream.read(buf); + } + } catch (Exception e) { + return; + } + } + }; + readerThread.start(); + } + @AfterClass public static void clean() { if (epmdProcess != null) { @@ -737,6 +756,8 @@ public class ReferenceServiceTestCase { args[0] = new OtpErlangString("world"); args[1] = new OtpErlangString("!"); refMbox.send("sayHello", "RPCServerMbox", new OtpErlangTuple(args)); + // FIXME: this seems to help avoid occasional hangs + Thread.sleep(100); OtpErlangString result = (OtpErlangString) refMbox.receiveMsg() .getMsg(); assertEquals("Hello world !", result.stringValue()); diff --git a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/README b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/README index ced99d6d10..e0c1a5c89f 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/README +++ b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/README @@ -8,9 +8,6 @@ first. In order to run Erlang samples you need to have Erlang/OTP distribution installed - epmd binary is required in your system path. See http://erlang.org for downloads. -The Tuscany SCA Erlang binding is compatible with Erlang/OTP version R12B but -doesn't work correctly with some later versions including R14B. See TUSCANY-3759 -for details. If you just want to run it to see what happens you need to run the server first so open a command prompt, navigate to the helloworld-erlang-service sample directory diff --git a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/src/test/java/helloworld/HelloWorldErlangClientTestCase.java b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/src/test/java/helloworld/HelloWorldErlangClientTestCase.java index 03d98f817f..0776892414 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/src/test/java/helloworld/HelloWorldErlangClientTestCase.java +++ b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-reference/src/test/java/helloworld/HelloWorldErlangClientTestCase.java @@ -1,66 +1,88 @@ -/* - * 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 helloworld; - -import helloworld.dynaignore.IgnorableRunner; -import helloworld.dynaignore.IgnoreTest; -import junit.framework.Assert; - -import org.apache.tuscany.sca.host.embedded.SCADomain; -import org.junit.Test; -import org.junit.runner.RunWith; - -/** - * Test case for helloworld Erlang client - */ -@RunWith(IgnorableRunner.class) -public class HelloWorldErlangClientTestCase { - - private static final String EPMD_COMMAND = "epmd"; - - @Test - public void testClient() throws Exception { - Process epmdProcess = null; - try { - epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); - } catch (Exception e) { - System.out - .println("Cannot proceed - exception while executing " - + EPMD_COMMAND - + ": " - + e.getMessage() - + ". Valid and working Erlang/OTP distribution is required."); - throw new IgnoreTest(); - } - SCADomain scaServiceDomain = SCADomain - .newInstance("helloworlderlangservice.composite"); - SCADomain scaClientDomain = SCADomain - .newInstance("helloworlderlangreference.composite"); - HelloWorldService helloWorldService = scaClientDomain.getService( - HelloWorldService.class, "HelloWorldServiceComponent"); - String msg = helloWorldService.getGreetings("Smith"); - Assert.assertEquals("Hello Smith", msg); - scaClientDomain.close(); - scaServiceDomain.close(); - epmdProcess.destroy(); - - } - -} +/* + * 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 helloworld; + +import java.io.InputStream; +import java.io.IOException; + +import helloworld.dynaignore.IgnorableRunner; +import helloworld.dynaignore.IgnoreTest; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Test case for helloworld Erlang client + */ +@RunWith(IgnorableRunner.class) +public class HelloWorldErlangClientTestCase { + + private static final String EPMD_COMMAND = "epmd"; + + @Test + public void testClient() { + Process epmdProcess = null; + try { + epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + } catch (IOException e) { + System.out + .println("Cannot proceed - exception while executing " + + EPMD_COMMAND + + ": " + + e.getMessage() + + ". Valid and working Erlang/OTP distribution is required."); + throw new IgnoreTest(); + } + startReaderThread(epmdProcess.getInputStream()); + startReaderThread(epmdProcess.getErrorStream()); + + SCADomain scaServiceDomain = SCADomain + .newInstance("helloworlderlangservice.composite"); + SCADomain scaClientDomain = SCADomain + .newInstance("helloworlderlangreference.composite"); + HelloWorldService helloWorldService = scaClientDomain.getService( + HelloWorldService.class, "HelloWorldServiceComponent"); + String msg = helloWorldService.getGreetings("Smith"); + Assert.assertEquals("Hello Smith", msg); + scaClientDomain.close(); + scaServiceDomain.close(); + + epmdProcess.destroy(); + } + + private static void startReaderThread(final InputStream stream) { + Thread readerThread = new Thread() { + public void run() { + try { + byte[] buf = new byte[100]; + while (true) { + stream.read(buf); + } + } catch (Exception e) { + return; + } + } + }; + readerThread.start(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/README b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/README index a702f5df89..ed21c91098 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/README +++ b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/README @@ -8,9 +8,6 @@ first. In order to run Erlang samples you need to have Erlang/OTP distribution installed - epmd binary is required in your system path. See http://erlang.org for downloads. -The Tuscany SCA Erlang binding is compatible with Erlang/OTP version R12B but -doesn't work correctly with some later versions including R14B. See TUSCANY-3759 -for details. If you just want to run it to see what happens open a command prompt, navigate to this sample directory and do: diff --git a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/main/java/helloworld/HelloWorldServer.java b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/main/java/helloworld/HelloWorldServer.java index 83dbfe03ff..2e632c00fc 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/main/java/helloworld/HelloWorldServer.java +++ b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/main/java/helloworld/HelloWorldServer.java @@ -1,65 +1,84 @@ -/* - * 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 helloworld; - -import java.io.IOException; - -import org.apache.tuscany.sca.host.embedded.SCADomain; - -/** - * This server program shows how to create an SCA runtime, and start it which - * activates the helloworld Web service endpoint. - */ -public class HelloWorldServer { - - private static final String EPMD_COMMAND = "epmd"; - - public static void main(String[] args) { - try { - Process process = null; - try { - process = Runtime.getRuntime().exec(EPMD_COMMAND); - } catch (Exception e) { - System.out - .println("Cannot proceed - exception while executing " - + EPMD_COMMAND - + ": " - + e.getMessage() - + ". Valid and working Erlang/OTP distribution is required."); - } - if (process != null) { - System.out.println("EPMD server started"); - SCADomain scaDomain = SCADomain - .newInstance("helloworlderlangservice.composite"); - System.out - .println("HelloWorld server started (press enter to shutdown)"); - System.in.read(); - process.destroy(); - scaDomain.close(); - System.out.println("EPMD server stopped"); - System.out.println("HelloWorld server stopped"); - } - } catch (IOException e) { - e.printStackTrace(); - } catch (Exception e) { - e.printStackTrace(); - } - } - -} +/* + * 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 helloworld; + +import java.io.InputStream; +import java.io.IOException; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This server program shows how to create an SCA runtime, and start it which + * activates the helloworld Web service endpoint. + */ +public class HelloWorldServer { + + private static final String EPMD_COMMAND = "epmd"; + + public static void main(String[] args) { + try { + Process process = null; + try { + process = Runtime.getRuntime().exec(EPMD_COMMAND); + } catch (IOException e) { + System.out + .println("Cannot proceed - exception while executing " + + EPMD_COMMAND + + ": " + + e.getMessage() + + ". Valid and working Erlang/OTP distribution is required."); + } + if (process != null) { + startReaderThread(process.getInputStream()); + startReaderThread(process.getErrorStream()); + System.out.println("EPMD server started"); + + SCADomain scaDomain = SCADomain + .newInstance("helloworlderlangservice.composite"); + System.out + .println("HelloWorld server started (press enter to shutdown)"); + System.in.read(); + scaDomain.close(); + System.out.println("HelloWorld server stopped"); + + process.destroy(); + System.out.println("EPMD server stopped"); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + private static void startReaderThread(final InputStream stream) { + Thread readerThread = new Thread() { + public void run() { + try { + byte[] buf = new byte[100]; + while (true) { + stream.read(buf); + } + } catch (Exception e) { + return; + } + } + }; + readerThread.start(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/test/java/helloworld/HelloWorldErlangServerTestCase.java b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/test/java/helloworld/HelloWorldErlangServerTestCase.java index 7f7d78c50d..a071e153d2 100644 --- a/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/test/java/helloworld/HelloWorldErlangServerTestCase.java +++ b/sca-java-1.x/branches/sca-java-1.6.1/samples/helloworld-erlang-service/src/test/java/helloworld/HelloWorldErlangServerTestCase.java @@ -1,68 +1,87 @@ -/* - * 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 helloworld; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertNotNull; - -import helloworld.dynaignore.IgnorableRunner; -import helloworld.dynaignore.IgnoreTest; - -import java.io.IOException; - -import org.apache.tuscany.sca.host.embedded.SCADomain; -import org.junit.Test; -import org.junit.runner.RunWith; - - - -/** - * Tests that the helloworld server is available - */ -@RunWith(IgnorableRunner.class) -public class HelloWorldErlangServerTestCase { - - private static final String EPMD_COMMAND = "epmd"; - - @Test - public void testServiceCall() throws IOException { - Process epmdProcess = null; - try { - epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); - } catch (Exception e) { - System.out - .println("Cannot proceed - exception while executing " - + EPMD_COMMAND - + ": " - + e.getMessage() - + ". Valid and working Erlang/OTP distribution is required."); - throw new IgnoreTest(); - } - SCADomain scaDomain = SCADomain - .newInstance("helloworlderlangservice.composite"); - HelloWorldService helloWorldService = scaDomain.getService( - HelloWorldService.class, - "HelloWorldServiceComponent/HelloWorldService"); - assertNotNull(helloWorldService); - assertEquals("Hello Smith", helloWorldService.getGreetings("Smith")); - scaDomain.close(); - epmdProcess.destroy(); - } - -} +/* + * 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 helloworld; + +import java.io.InputStream; +import java.io.IOException; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +import helloworld.dynaignore.IgnorableRunner; +import helloworld.dynaignore.IgnoreTest; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * Tests that the helloworld server is available + */ +@RunWith(IgnorableRunner.class) +public class HelloWorldErlangServerTestCase { + + private static final String EPMD_COMMAND = "epmd"; + + @Test + public void testServiceCall() { + Process epmdProcess = null; + try { + epmdProcess = Runtime.getRuntime().exec(EPMD_COMMAND); + } catch (IOException e) { + System.out + .println("Cannot proceed - exception while executing " + + EPMD_COMMAND + + ": " + + e.getMessage() + + ". Valid and working Erlang/OTP distribution is required."); + throw new IgnoreTest(); + } + startReaderThread(epmdProcess.getInputStream()); + startReaderThread(epmdProcess.getErrorStream()); + + SCADomain scaDomain = SCADomain + .newInstance("helloworlderlangservice.composite"); + HelloWorldService helloWorldService = scaDomain.getService( + HelloWorldService.class, + "HelloWorldServiceComponent/HelloWorldService"); + assertNotNull(helloWorldService); + assertEquals("Hello Smith", helloWorldService.getGreetings("Smith")); + scaDomain.close(); + + epmdProcess.destroy(); + } + + private static void startReaderThread(final InputStream stream) { + Thread readerThread = new Thread() { + public void run() { + try { + byte[] buf = new byte[100]; + while (true) { + stream.read(buf); + } + } catch (Exception e) { + return; + } + } + }; + readerThread.start(); + } + +} -- cgit v1.2.3