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
This commit is contained in:
parent
f236274482
commit
394164ac05
7 changed files with 281 additions and 214 deletions
|
@ -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
|
||||
--------
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue