Add a test for remote invocations between nodes created from two different node factories
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@916838 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
736d9f9484
commit
8c8aca83d8
7 changed files with 38 additions and 15 deletions
|
|
@ -88,18 +88,24 @@ public class BindingSCATestCase {
|
|||
* Two node factories and two nodes
|
||||
*/
|
||||
@Test
|
||||
public void testTwoFactoriesTwoNodes() {
|
||||
public void testTwoFactoriesTwoNodes() throws Exception {
|
||||
NodeFactory factory1 = NodeFactory.newInstance();
|
||||
Node node1 = createClientNode(factory1);
|
||||
NodeFactory factory2 = NodeFactory.newInstance();
|
||||
Node node2 = createServiceNode(factory2);
|
||||
node1.start();
|
||||
node2.start();
|
||||
Thread.sleep(1000);
|
||||
try {
|
||||
runClient(node1);
|
||||
Assert.fail("ServiceRuntimeException should have been thrown.");
|
||||
} catch (ServiceRuntimeException e) {
|
||||
// ignore
|
||||
// This call doesn't require the Local service, it should be successful
|
||||
createCustomer(node1);
|
||||
try {
|
||||
runClient(node1);
|
||||
// We cannot make local call to remote endpoints
|
||||
Assert.fail("ServiceRuntimeException should have been thrown.");
|
||||
} catch (ServiceRuntimeException e) {
|
||||
// ignore
|
||||
}
|
||||
} finally {
|
||||
node2.stop();
|
||||
node1.stop();
|
||||
|
|
@ -122,6 +128,13 @@ public class BindingSCATestCase {
|
|||
Assert.assertEquals("Ray", client.getName(id));
|
||||
}
|
||||
|
||||
static String createCustomer(Node node) {
|
||||
Client client = node.getService(Client.class, "ClientComponent/Client");
|
||||
String id = client.create("John");
|
||||
Assert.assertNotNull(id);
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* One node factory and one node for both composites
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class DefaultExtensionPointRegistry implements ExtensionPointRegistry {
|
|||
this.discovery = ServiceDiscovery.getInstance();
|
||||
}
|
||||
|
||||
protected DefaultExtensionPointRegistry(ServiceDiscovery discovery) {
|
||||
public DefaultExtensionPointRegistry(ServiceDiscovery discovery) {
|
||||
this.discovery = discovery;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -115,17 +115,25 @@ public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer {
|
|||
this.classLoaderReference = new WeakReference<ClassLoader>(classLoader);
|
||||
}
|
||||
|
||||
public ContextClassLoaderServiceDiscoverer(ClassLoader classLoader) {
|
||||
if (classLoader == null) {
|
||||
classLoader = Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
this.classLoaderReference = new WeakReference<ClassLoader>(classLoader);
|
||||
}
|
||||
|
||||
public ClassLoader getContextClassLoader() {
|
||||
//return classLoaderReference.get();
|
||||
return Thread.currentThread().getContextClassLoader();
|
||||
}
|
||||
|
||||
private List<URL> getResources(final String name) throws IOException {
|
||||
private Collection<URL> getResources(final String name) throws IOException {
|
||||
try {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<List<URL>>() {
|
||||
public List<URL> run() throws IOException {
|
||||
return AccessController.doPrivileged(new PrivilegedExceptionAction<Collection<URL>>() {
|
||||
public Collection<URL> run() throws IOException {
|
||||
List<URL> urls = Collections.list(classLoaderReference.get().getResources(name));
|
||||
return urls;
|
||||
// Eliminate the duplicate URLs (which can be found from child/parent classloaders)
|
||||
return new HashSet<URL>(urls);
|
||||
}
|
||||
});
|
||||
} catch (PrivilegedActionException e) {
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ public final class ServiceDiscovery implements ServiceDiscoverer {
|
|||
}
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
discoverer = new ContextClassLoaderServiceDiscoverer();
|
||||
discoverer = new ContextClassLoaderServiceDiscoverer(getClass().getClassLoader());
|
||||
return discoverer;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -472,6 +472,8 @@ public abstract class NodeFactory extends DefaultNodeConfigurationFactory {
|
|||
}
|
||||
|
||||
public void destroy() {
|
||||
count = 0;
|
||||
instance = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import javax.xml.namespace.QName;
|
|||
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
|
||||
import org.apache.tuscany.sca.core.UtilityExtensionPoint;
|
||||
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
|
||||
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
|
||||
import org.apache.tuscany.sca.monitor.Monitor;
|
||||
import org.apache.tuscany.sca.monitor.MonitorFactory;
|
||||
|
||||
|
|
@ -127,7 +126,7 @@ public class DefaultComponentJavaScriptGeneratorExtensionPoint implements Compon
|
|||
// Get the proxy factories declarations
|
||||
Collection<ServiceDeclaration> factoryDeclarations = null;
|
||||
try {
|
||||
factoryDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ComponentJavaScriptGenerator.class);
|
||||
factoryDeclarations = extensionPoints.getServiceDiscovery().getServiceDeclarations(ComponentJavaScriptGenerator.class);
|
||||
} catch (IOException e) {
|
||||
IllegalStateException ie = new IllegalStateException(e);
|
||||
error("IllegalStateException", factoryDeclarations, ie);
|
||||
|
|
|
|||
|
|
@ -45,10 +45,11 @@ public class DefaultJavascriptProxyFactoryExtensionPoint implements JavascriptPr
|
|||
private final Map<Class<?>, JavascriptProxyFactory> factoriesByType = new HashMap<Class<?>, JavascriptProxyFactory>();
|
||||
|
||||
private Monitor monitor = null;
|
||||
|
||||
private ExtensionPointRegistry registry;
|
||||
private boolean loaded = false;
|
||||
|
||||
public DefaultJavascriptProxyFactoryExtensionPoint(ExtensionPointRegistry extensionPoints) {
|
||||
this.registry = extensionPoints;
|
||||
UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
|
||||
MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
|
||||
if (monitorFactory != null) {
|
||||
|
|
@ -116,7 +117,7 @@ public class DefaultJavascriptProxyFactoryExtensionPoint implements JavascriptPr
|
|||
if (bindingType.isInterface()) {
|
||||
// Dynamically load a factory class declared under META-INF/services
|
||||
try {
|
||||
Class<?> factoryClass = ServiceDiscovery.getInstance().getServiceDeclaration(bindingType).getClass();
|
||||
Class<?> factoryClass = registry.getServiceDiscovery().getServiceDeclaration(bindingType).getClass();
|
||||
if (factoryClass != null) {
|
||||
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue