58 public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; |
58 public static int TEST_FAIL_TIME = HOLD_TARGET_TIME + 30000; |
59 public static boolean finished = false; |
59 public static boolean finished = false; |
60 static DGCDeadLock test = new DGCDeadLock(); |
60 static DGCDeadLock test = new DGCDeadLock(); |
61 |
61 |
62 static { |
62 static { |
63 System.setProperty("sun.rmi.transport.cleanInterval", "50"); |
63 System.setProperty("sun.rmi.transport.cleanInterval", "50"); |
64 } |
64 } |
65 |
65 |
66 static public void main(String[] args) { |
66 static public void main(String[] args) { |
67 |
67 |
68 JavaVM testImplVM = null; |
68 JavaVM testImplVM = null; |
69 |
69 |
70 System.err.println("\nregression test for 4118056\n"); |
70 System.err.println("\nregression test for 4118056\n"); |
71 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
71 TestLibrary.suggestSecurityManager("java.rmi.RMISecurityManager"); |
72 |
72 |
73 try { |
73 try { |
74 String options = " -Djava.security.policy=" + |
74 String options = " -Djava.security.policy=" + |
75 TestParams.defaultPolicy + |
75 TestParams.defaultPolicy + |
76 " -Djava.rmi.dgc.leaseValue=500000" + |
76 " -Djava.rmi.dgc.leaseValue=500000" + |
77 " -Dsun.rmi.dgc.checkInterval=" + |
77 " -Dsun.rmi.dgc.checkInterval=" + |
78 (HOLD_TARGET_TIME - 5000) + ""; |
78 (HOLD_TARGET_TIME - 5000) + ""; |
79 |
79 |
80 testImplVM = new JavaVM("TestImpl", options, ""); |
80 testImplVM = new JavaVM("TestImpl", options, ""); |
81 testImplVM.start(); |
81 testImplVM.start(); |
82 |
82 |
83 synchronized (test) { |
83 synchronized (test) { |
84 Thread t = new Thread(test); |
84 Thread t = new Thread(test); |
85 t.setDaemon(true); |
85 t.setDaemon(true); |
86 t.start(); |
86 t.start(); |
87 |
87 |
88 // wait for the remote calls to take place |
88 // wait for the remote calls to take place |
89 test.wait(TEST_FAIL_TIME); |
89 test.wait(TEST_FAIL_TIME); |
90 } |
90 } |
91 |
91 |
92 if (!finished) { |
92 if (!finished) { |
93 TestLibrary.bomb("Test failed, had exception or exercise" + |
93 TestLibrary.bomb("Test failed, had exception or exercise" + |
94 " routines took too long to " + |
94 " routines took too long to " + |
95 "execute"); |
95 "execute"); |
96 } |
96 } |
97 System.err.println("Test passed, exercises " + |
97 System.err.println("Test passed, exercises " + |
98 "finished in time."); |
98 "finished in time."); |
99 |
99 |
100 } catch (Exception e) { |
100 } catch (Exception e) { |
101 testImplVM = null; |
101 testImplVM = null; |
102 TestLibrary.bomb("test failed", e); |
102 TestLibrary.bomb("test failed", e); |
103 } |
103 } |
104 } |
104 } |
105 |
105 |
106 public void run() { |
106 public void run() { |
107 try { |
107 try { |
108 String echo = null; |
108 String echo = null; |
109 |
109 |
110 // give the test remote object time to initialize. |
110 // give the test remote object time to initialize. |
111 Thread.currentThread().sleep(8000); |
111 Thread.currentThread().sleep(8000); |
112 |
112 |
113 // create a test client |
113 // create a test client |
114 Test foo = (Test) Naming.lookup("rmi://:" + |
114 Test foo = (Test) Naming.lookup("rmi://:" + |
115 TestLibrary.REGISTRY_PORT + |
115 TestLibrary.REGISTRY_PORT + |
116 "/Foo"); |
116 "/Foo"); |
117 echo = foo.echo("Hello world"); |
117 echo = foo.echo("Hello world"); |
118 System.err.println("Test object created."); |
118 System.err.println("Test object created."); |
119 |
119 |
120 /* give TestImpl time to lock the target in the |
120 /* give TestImpl time to lock the target in the |
121 * object table and any dirtys finish. |
121 * object table and any dirtys finish. |
122 */ |
122 */ |
123 Thread.currentThread().sleep(5000); |
123 Thread.currentThread().sleep(5000); |
124 |
124 |
125 //unreference "Foo" |
125 //unreference "Foo" |
126 foo = null; |
126 foo = null; |
127 |
127 |
128 //garbage collect and finalize foo |
128 //garbage collect and finalize foo |
129 Runtime.getRuntime().gc(); |
129 Runtime.getRuntime().gc(); |
130 Runtime.getRuntime().runFinalization(); |
130 Runtime.getRuntime().runFinalization(); |
131 |
|
132 //import "Bar" |
|
133 Test bar = (Test) Naming.lookup("rmi://:" + |
|
134 TestLibrary.REGISTRY_PORT + |
|
135 "/Bar"); |
|
136 |
|
137 /* infinite loop to show the liveness of Client, |
|
138 * if we have deadlock remote call will not return |
|
139 */ |
|
140 try { |
|
141 for (int i = 0; i < 500; i++) { |
|
142 echo = bar.echo("Remote call" + i); |
|
143 Thread.sleep(10); |
|
144 } |
|
145 |
131 |
146 // flag exercises finished |
132 //import "Bar" |
147 finished = true; |
133 Test bar = (Test) Naming.lookup("rmi://:" + |
|
134 TestLibrary.REGISTRY_PORT + |
|
135 "/Bar"); |
148 |
136 |
149 } catch (RemoteException e) { |
137 /* infinite loop to show the liveness of Client, |
150 } |
138 * if we have deadlock remote call will not return |
151 |
139 */ |
152 } catch (Exception e) { |
140 try { |
153 TestLibrary.bomb("test failed", e); |
141 for (int i = 0; i < 500; i++) { |
154 } finally { |
142 echo = bar.echo("Remote call" + i); |
155 } |
143 Thread.sleep(10); |
|
144 } |
|
145 |
|
146 // flag exercises finished |
|
147 finished = true; |
|
148 |
|
149 } catch (RemoteException e) { |
|
150 } |
|
151 |
|
152 } catch (Exception e) { |
|
153 TestLibrary.bomb("test failed", e); |
|
154 } finally { |
|
155 } |
156 } |
156 } |
157 } |
157 } |