1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
/****************************************************************************
* Copyright (c) 2008 Composent, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Composent, Inc. - initial API and implementation
*****************************************************************************/
package org.eclipse.ecf.tests.remoteservice.generic;
import java.util.Dictionary;
import java.util.Hashtable;
import org.eclipse.ecf.remoteservice.IRemoteService;
import org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter;
import org.eclipse.ecf.remoteservice.IRemoteServiceProxy;
import org.eclipse.ecf.remoteservice.IRemoteServiceReference;
import org.eclipse.ecf.remoteservice.RemoteServiceHelper;
import org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker;
import org.eclipse.ecf.tests.remoteservice.AbstractServiceTrackerTest;
import org.eclipse.ecf.tests.remoteservice.IConcatService;
/**
*
*/
public class RemoteServiceProxyTest extends AbstractServiceTrackerTest {
RemoteServiceTracker remoteServiceTracker;
/* (non-Javadoc)
* @see org.eclipse.ecf.tests.remoteservice.AbstractRemoteServiceTest#getClientContainerName()
*/
protected String getClientContainerName() {
return Generic.CONSUMER_CONTAINER_TYPE;
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
setClientCount(2);
createServerAndClients();
connectClients();
setupRemoteServiceAdapters();
addRemoteServiceListeners();
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
cleanUpServerAndClients();
if (remoteServiceTracker != null) {
remoteServiceTracker.close();
}
super.tearDown();
}
protected IRemoteService getRemoteService(IRemoteServiceContainerAdapter adapter, String clazz, String filter) {
remoteServiceTracker = new RemoteServiceTracker(adapter, null, clazz, null);
assertNotNull(remoteServiceTracker);
remoteServiceTracker.open();
return remoteServiceTracker.getRemoteService();
}
public void testRemoteServiceProxy() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
// client [0]/adapter[0] is the service 'server'
// client [1]/adapter[1] is the service target (client)
final Dictionary props = new Hashtable();
// Register
adapters[0].registerRemoteService(new String[] {IConcatService.class.getName()}, createService(), props);
// Give some time for propagation
sleep(3000);
final RemoteServiceTracker st = new RemoteServiceTracker(adapters[1], null, IConcatService.class.getName(), null);
assertNotNull(st);
st.open();
IRemoteService rs = st.getRemoteService();
final IConcatService concatService = (IConcatService) rs.getProxy();
assertNotNull(concatService);
// test for proxy implementing IRemoteServiceProxy
if (concatService instanceof IRemoteServiceProxy) {
IRemoteService remoteService = ((IRemoteServiceProxy) concatService).getRemoteService();
assertNotNull(remoteService);
IRemoteServiceReference remoteServiceReference = ((IRemoteServiceProxy) concatService).getRemoteServiceReference();
assertNotNull(remoteServiceReference);
System.out.println("remote service reference found from proxy="+remoteServiceReference);
System.out.println("remoteserviceproxy call start");
Object result = RemoteServiceHelper.syncExec(remoteService, "concat" , new Object[] { "IRemoteServiceProxy ","is very cool" }, 20000);
System.out.println("remoteserviceproxy call end. result=" + result);
} else {
System.out.println("proxy call start");
final String result = concatService.concat("OSGi ", "is cool");
System.out.println("proxy call end. result=" + result);
}
sleep(3000);
st.close();
sleep(3000);
}
}
|