11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 *
26 */
27
28 import java.io.*;
29 import java.rmi.*;
30 import java.rmi.activation.*;
31 import java.util.Properties;
32
33 /**
34 * Utility class that creates an instance of rmid with a policy
35 * file of name <code>TestParams.defaultPolicy</code>.
36 *
37 * Activation groups should run with the same security manager as the
38 * test.
39 */
40 public class RMID extends JavaVM {
41
42 public static String MANAGER_OPTION="-Djava.security.manager=";
43
44 /** Test port for rmid */
45 private final int port;
46
47 /** Initial log name */
48 protected static String log = "log";
49 /** rmid's logfile directory; currently must be "." */
50 protected static String LOGDIR = ".";
51
116 /**
117 * Routine that creates an rmid that will run with or without a
118 * policy file.
119 */
120 public static RMID createRMID() {
121 return createRMID(System.out, System.err, true);
122 }
123
124 public static RMID createRMID(boolean debugExec) {
125 return createRMID(System.out, System.err, debugExec);
126 }
127
128 public static RMID createRMID(OutputStream out, OutputStream err) {
129 return createRMID(out, err, true);
130 }
131
132 public static RMID createRMID(OutputStream out, OutputStream err,
133 boolean debugExec)
134 {
135 return createRMID(out, err, debugExec, true,
136 TestLibrary.RMID_PORT);
137 }
138
139 public static RMID createRMID(OutputStream out, OutputStream err,
140 boolean debugExec, boolean includePortArg,
141 int port)
142 {
143 String options = makeOptions(debugExec);
144 String args = makeArgs(includePortArg, port);
145 RMID rmid = new RMID("sun.rmi.server.Activation", options, args,
146 out, err, port);
147 rmid.setPolicyFile(TestParams.defaultRmidPolicy);
148
149 return rmid;
150 }
151
152
153 /**
154 * Test RMID should be created with the createRMID method.
155 */
156 protected RMID(String classname, String options, String args,
191 */
192 protected static String getCodeCoverageArgs() {
193 return TestLibrary.getExtraProperty("rmid.jcov.args","");
194 }
195
196 public void start() throws IOException {
197 start(10000);
198 }
199
200 public void slowStart() throws IOException {
201 start(60000);
202 }
203
204 public void start(long waitTime) throws IOException {
205
206 if (getVM() != null) return;
207
208 // if rmid is already running, then the test will fail with
209 // a well recognized exception (port already in use...).
210
211 mesg("starting rmid...");
212 super.start();
213
214 int slopFactor = 1;
215 try {
216 slopFactor = Integer.valueOf(
217 TestLibrary.getExtraProperty("jcov.sleep.multiplier","1"));
218 } catch (NumberFormatException ignore) {}
219 waitTime = waitTime * slopFactor;
220
221 // We check several times (as many as provides passed waitTime) to
222 // see if Rmid is currently running. Waiting steps last 100 msecs.
223 final long rmidStartSleepTime = 100;
224 do {
225 // Sleeping for another rmidStartSleepTime time slice.
226 try {
227 Thread.sleep(Math.min(waitTime, rmidStartSleepTime));
228 } catch (InterruptedException ie) {
229 Thread.currentThread().interrupt();
230 mesg("Thread interrupted while checking for start of Activation System. Giving up check.");
231 mesg("Activation System state unknown");
232 return;
233 }
234 waitTime -= rmidStartSleepTime;
235
236 // Checking if rmid is present
237 if (ActivationLibrary.rmidRunning(port)) {
238 mesg("finished starting rmid.");
239 return;
240 }
241 else {
242 mesg("rmid still not started");
243 }
244
245 } while (waitTime > 0);
246 TestLibrary.bomb("start rmid failed... giving up", null);
247 }
248
249 public void restart() throws IOException {
250 destroy();
251 start();
252 }
253
254 /**
255 * Ask rmid to shutdown gracefully using a remote method call.
256 * catch any errors that might occur from rmid not being present
257 * at time of shutdown invocation.
258 *
259 * Shutdown does not nullify possible references to the rmid
260 * process object (destroy does though).
261 */
262 public static void shutdown() {
263 shutdown(TestLibrary.RMID_PORT);
264 }
265
266 public static void shutdown(int port) {
267
268 try {
269 ActivationSystem system = null;
270
271 try {
272 mesg("getting a reference to the activation system");
273 system = (ActivationSystem) Naming.lookup("//:" +
274 port +
275 "/java.rmi.activation.ActivationSystem");
276 mesg("obtained a reference to the activation system");
277 } catch (RemoteException re) {
278 mesg("could not contact registry while trying to shutdown activation system");
279 } catch (java.net.MalformedURLException mue) {
280 }
281
282 if (system == null) {
283 TestLibrary.bomb("reference to the activation system was null");
284 }
285 system.shutdown();
286
287 } catch (RemoteException re) {
288 mesg("shutting down the activation daemon failed");
289 } catch (Exception e) {
290 mesg("caught exception trying to shutdown rmid");
291 mesg(e.getMessage());
292 e.printStackTrace();
293 }
294
295 mesg("testlibrary finished shutting down rmid");
296 }
297
298 /**
299 * Ask rmid to shutdown gracefully but then destroy the rmid
300 * process if it does not exit by itself. This method only works
301 * if rmid is a child process of the current VM.
302 */
303 public void destroy() {
304
305 // attempt graceful shutdown of the activation system on
306 // TestLibrary.RMID_PORT
307 shutdown(port);
308
309 if (vm != null) {
310 try {
311 /* Waiting for distant RMID process to shutdown.
312 * Waiting is bounded at a hardcoded max of 60 secs (1 min).
313 * Waiting by steps of 200 msecs, thus at most 300 such attempts
314 * for termination of distant RMID process. If process is not
315 * known to be terminated properly after that time,
316 * we give up for a gracefull termination, and thus go for
317 * forcibly destroying the process.
318 */
319 boolean vmEnded = false;
320 int waitingTrials = 0;
321 final int maxTrials = 300;
322 final long vmProcessEndWaitInterval = 200;
323 int vmExitValue;
324 do {
325 try {
326 Thread.sleep(vmProcessEndWaitInterval);
340 mesg("RMID's process still not terminated after more than " +
341 (waitingTrials * vmProcessEndWaitInterval) + " milliseconds." +
342 "Givinp up gracefull termination...");
343 mesg("destroying RMID's process using Process.destroy()");
344 super.destroy();
345 }
346
347 } catch (InterruptedException ie) {
348 Thread.currentThread().interrupt();
349 mesg("Thread interrupted while checking for termination of distant rmid vm. Giving up check.");
350 } catch (Exception e) {
351 mesg("caught unexpected exception trying to destroy rmid: " +
352 e.getMessage());
353 e.printStackTrace();
354 }
355
356 // rmid will not restart if its process is not null
357 vm = null;
358 }
359 }
360 }
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 *
26 */
27
28 import java.io.*;
29 import java.rmi.*;
30 import java.rmi.activation.*;
31
32 /**
33 * Utility class that creates an instance of rmid with a policy
34 * file of name <code>TestParams.defaultPolicy</code>.
35 *
36 * Activation groups should run with the same security manager as the
37 * test.
38 */
39 public class RMID extends JavaVM {
40
41 public static String MANAGER_OPTION="-Djava.security.manager=";
42
43 /** Test port for rmid */
44 private final int port;
45
46 /** Initial log name */
47 protected static String log = "log";
48 /** rmid's logfile directory; currently must be "." */
49 protected static String LOGDIR = ".";
50
115 /**
116 * Routine that creates an rmid that will run with or without a
117 * policy file.
118 */
119 public static RMID createRMID() {
120 return createRMID(System.out, System.err, true);
121 }
122
123 public static RMID createRMID(boolean debugExec) {
124 return createRMID(System.out, System.err, debugExec);
125 }
126
127 public static RMID createRMID(OutputStream out, OutputStream err) {
128 return createRMID(out, err, true);
129 }
130
131 public static RMID createRMID(OutputStream out, OutputStream err,
132 boolean debugExec)
133 {
134 return createRMID(out, err, debugExec, true,
135 TestLibrary.getUnusedRandomPort());
136 }
137
138 public static RMID createRMID(OutputStream out, OutputStream err,
139 boolean debugExec, boolean includePortArg,
140 int port)
141 {
142 String options = makeOptions(debugExec);
143 String args = makeArgs(includePortArg, port);
144 RMID rmid = new RMID("sun.rmi.server.Activation", options, args,
145 out, err, port);
146 rmid.setPolicyFile(TestParams.defaultRmidPolicy);
147
148 return rmid;
149 }
150
151
152 /**
153 * Test RMID should be created with the createRMID method.
154 */
155 protected RMID(String classname, String options, String args,
190 */
191 protected static String getCodeCoverageArgs() {
192 return TestLibrary.getExtraProperty("rmid.jcov.args","");
193 }
194
195 public void start() throws IOException {
196 start(10000);
197 }
198
199 public void slowStart() throws IOException {
200 start(60000);
201 }
202
203 public void start(long waitTime) throws IOException {
204
205 if (getVM() != null) return;
206
207 // if rmid is already running, then the test will fail with
208 // a well recognized exception (port already in use...).
209
210 mesg("starting rmid on port #" + port + "...");
211 super.start();
212
213 int slopFactor = 1;
214 try {
215 slopFactor = Integer.valueOf(
216 TestLibrary.getExtraProperty("jcov.sleep.multiplier","1"));
217 } catch (NumberFormatException ignore) {}
218 waitTime = waitTime * slopFactor;
219
220 // We check several times (as many as provides passed waitTime) to
221 // see if Rmid is currently running. Waiting steps last 100 msecs.
222 final long rmidStartSleepTime = 100;
223 do {
224 // Sleeping for another rmidStartSleepTime time slice.
225 try {
226 Thread.sleep(Math.min(waitTime, rmidStartSleepTime));
227 } catch (InterruptedException ie) {
228 Thread.currentThread().interrupt();
229 mesg("Thread interrupted while checking for start of Activation System. Giving up check.");
230 mesg("Activation System state unknown");
231 return;
232 }
233 waitTime -= rmidStartSleepTime;
234
235 // Checking if rmid is present
236 if (ActivationLibrary.rmidRunning(port)) {
237 /**
238 * We need to set the java.rmi.activation.port value as the
239 * activation system will use the property to determine the
240 * port #. The activation system will use this value if set.
241 * If it isn't set, the activation system will set it to an
242 * incorrect value.
243 */
244 System.setProperty("java.rmi.activation.port", Integer.toString(port));
245 mesg("finished starting rmid.");
246 return;
247 }
248 else {
249 mesg("rmid still not started");
250 }
251
252 } while (waitTime > 0);
253 TestLibrary.bomb("start rmid failed... giving up", null);
254 }
255
256 public void restart() throws IOException {
257 destroy();
258 start();
259 }
260
261 /**
262 * Ask rmid to shutdown gracefully using a remote method call.
263 * catch any errors that might occur from rmid not being present
264 * at time of shutdown invocation.
265 *
266 * Shutdown does not nullify possible references to the rmid
267 * process object (destroy does though).
268 */
269 public static void shutdown(int port) {
270
271 try {
272 ActivationSystem system = null;
273
274 try {
275 mesg("getting a reference to the activation system");
276 system = (ActivationSystem) Naming.lookup("//:" +
277 port +
278 "/java.rmi.activation.ActivationSystem");
279 mesg("obtained a reference to the activation system");
280 } catch (RemoteException re) {
281 mesg("could not contact registry while trying to shutdown activation system");
282 } catch (java.net.MalformedURLException mue) {
283 }
284
285 if (system == null) {
286 TestLibrary.bomb("reference to the activation system was null");
287 }
288 system.shutdown();
289
290 } catch (RemoteException re) {
291 mesg("shutting down the activation daemon failed");
292 } catch (Exception e) {
293 mesg("caught exception trying to shutdown rmid");
294 mesg(e.getMessage());
295 e.printStackTrace();
296 }
297
298 mesg("testlibrary finished shutting down rmid");
299 }
300
301 /**
302 * Ask rmid to shutdown gracefully but then destroy the rmid
303 * process if it does not exit by itself. This method only works
304 * if rmid is a child process of the current VM.
305 */
306 public void destroy() {
307 // attempt graceful shutdown of the activation system
308 shutdown(port);
309
310 if (vm != null) {
311 try {
312 /* Waiting for distant RMID process to shutdown.
313 * Waiting is bounded at a hardcoded max of 60 secs (1 min).
314 * Waiting by steps of 200 msecs, thus at most 300 such attempts
315 * for termination of distant RMID process. If process is not
316 * known to be terminated properly after that time,
317 * we give up for a gracefull termination, and thus go for
318 * forcibly destroying the process.
319 */
320 boolean vmEnded = false;
321 int waitingTrials = 0;
322 final int maxTrials = 300;
323 final long vmProcessEndWaitInterval = 200;
324 int vmExitValue;
325 do {
326 try {
327 Thread.sleep(vmProcessEndWaitInterval);
341 mesg("RMID's process still not terminated after more than " +
342 (waitingTrials * vmProcessEndWaitInterval) + " milliseconds." +
343 "Givinp up gracefull termination...");
344 mesg("destroying RMID's process using Process.destroy()");
345 super.destroy();
346 }
347
348 } catch (InterruptedException ie) {
349 Thread.currentThread().interrupt();
350 mesg("Thread interrupted while checking for termination of distant rmid vm. Giving up check.");
351 } catch (Exception e) {
352 mesg("caught unexpected exception trying to destroy rmid: " +
353 e.getMessage());
354 e.printStackTrace();
355 }
356
357 // rmid will not restart if its process is not null
358 vm = null;
359 }
360 }
361
362 public int getPort() {return port;}
363 }
|