This project has retired. For details please refer to its
Attic page.
UDDI_090_RMIIntegrationTest xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.juddi.v3.tck;
17
18 import java.net.InetAddress;
19 import java.net.URI;
20 import java.rmi.registry.LocateRegistry;
21 import java.rmi.registry.Registry;
22 import java.util.Iterator;
23 import java.util.Random;
24 import org.apache.commons.configuration.ConfigurationException;
25 import static org.apache.juddi.v3.tck.UDDI_090_SubscriptionListenerIntegrationBase.logger;
26 import static org.apache.juddi.v3.tck.UDDI_090_SubscriptionListenerIntegrationBase.startManager;
27 import static org.apache.juddi.v3.tck.UDDI_090_SubscriptionListenerIntegrationBase.stopManager;
28 import org.junit.AfterClass;
29 import org.junit.Assert;
30 import org.junit.BeforeClass;
31
32
33
34
35
36 public class UDDI_090_RMIIntegrationTest extends UDDI_090_SubscriptionListenerIntegrationBase {
37
38 private static UDDISubscriptionListenerImpl rmiSubscriptionListenerService = null;
39 private static TckSubscriptionListenerRMI rmiSubscriptionListener = null;
40 private static Registry registry;
41 private static Integer randomPort = null;
42 private static String hostname = null;
43
44 @AfterClass
45 public static void stop() throws ConfigurationException {
46 if (!TckPublisher.isEnabled()) {
47 return;
48 }
49 stopManager();
50
51 }
52
53 @BeforeClass
54 public static void startup() throws Exception {
55
56 if (!TckPublisher.isEnabled()) {
57 return;
58 }
59 startManager();
60 int count = 0;
61 rmiSubscriptionListenerService = new UDDISubscriptionListenerImpl(0);
62 UDDISubscriptionListenerImpl.notifcationMap.clear();
63 UDDISubscriptionListenerImpl.notificationCount=0;
64 while (true && count < 5) {
65 try {
66 count++;
67 randomPort = 19800 + new Random().nextInt(99);
68 logger.info("RMI Random port=" + randomPort);
69
70 URI rmiEndPoint = new URI("rmi://localhost:" + randomPort + "/tck/rmisubscriptionlistener");
71 registry = LocateRegistry.createRegistry(rmiEndPoint.getPort());
72
73 String path = rmiEndPoint.getPath();
74 hostname = InetAddress.getLocalHost().getHostName();
75
76
77
78 registry.bind(path, rmiSubscriptionListenerService);
79
80
81 Registry registry2 = LocateRegistry.getRegistry(rmiEndPoint.getHost(), rmiEndPoint.getPort());
82 registry2.lookup(rmiEndPoint.getPath());
83 break;
84 } catch (Exception ex) {
85 logger.warn("trouble starting rmi endpoint " + ex.getMessage());
86 }
87 }
88 Assert.assertNotNull(registry);
89 Assert.assertNotNull(hostname);
90 }
91
92 @Override
93 public boolean verifyDelivery(String findMe) {
94 for (int i = 0; i < TckPublisher.getSubscriptionTimeout(); i++) {
95 try {
96 Thread.sleep(1000);
97 } catch (InterruptedException ex) {
98 }
99 logger.info(".");
100
101 }
102 logger.info("RX " + UDDISubscriptionListenerImpl.notificationCount + " notifications");
103 Iterator<String> it = UDDISubscriptionListenerImpl.notifcationMap.values().iterator();
104 boolean found = false;
105
106 while (it.hasNext()) {
107 String test = it.next();
108 if (TckCommon.isDebug()) {
109 logger.info("Notification: " + test);
110 }
111 if (test.toLowerCase().contains(findMe.toLowerCase())) {
112 found = true;
113 }
114 }
115
116 if (!found) {
117 it = UDDISubscriptionListenerImpl.notifcationMap.values().iterator();
118 Thread.dumpStack();
119 while (it.hasNext()) {
120 logger.info("Notification: " + it.next());
121 }
122 }
123 return found;
124 }
125
126 @Override
127 public void reset() {
128 UDDISubscriptionListenerImpl.notifcationMap.clear();
129 UDDISubscriptionListenerImpl.notificationCount = 0;
130
131 }
132
133 @Override
134 public String getXMLLocationOfServiceForDelivery() {
135 return TckSubscriptionListener.LISTENER_RMI_SERVICE_XML;
136 }
137
138 @Override
139 public String getTransport() {
140 return "RMI";
141 }
142
143 @Override
144 public int getPort() {
145 return randomPort;
146 }
147
148 @Override
149 public String getHostame() {
150 return hostname;
151 }
152
153 @Override
154 public String getSubscription1XML() {
155 return TckSubscriptionListenerRMI.SUBSCRIPTION_XML_RMI;
156 }
157
158 @Override
159 public String getSubscription2XML() {
160 return TckSubscriptionListenerRMI.SUBSCRIPTION_XML2_RMI;
161 }
162
163 @Override
164 public String getSubscription3XML() {
165 return TckSubscriptionListenerRMI.SUBSCRIPTION_XML3_RMI;
166 }
167
168 @Override
169 public String getSubscriptionKey1() {
170 return TckSubscriptionListenerRMI.SUBSCRIPTION_KEY_RMI;
171 }
172
173 @Override
174 public String getSubscriptionKey2() {
175 return TckSubscriptionListenerRMI.SUBSCRIPTION_KEY_RMI;
176 }
177
178 @Override
179 public String getSubscriptionKey3() {
180 return TckSubscriptionListenerRMI.SUBSCRIPTION_KEY_RMI;
181 }
182
183 @Override
184 public boolean IsEnabled() {
185 return TckPublisher.isRMI();
186 }
187
188 }