60 |
60 |
61 private static final int PORT = 2020; |
61 private static final int PORT = 2020; |
62 private static final String NAME = "WMM"; |
62 private static final String NAME = "WMM"; |
63 |
63 |
64 public static void main(String[] args) throws Exception { |
64 public static void main(String[] args) throws Exception { |
65 System.err.println("\nRegression test for bug 4472769"); |
65 System.err.println("\nRegression test for bug 4472769"); |
66 |
66 |
67 System.err.println( |
67 System.err.println( |
68 "\n=== verifying that J2SE registry's skeleton uses" + |
68 "\n=== verifying that J2SE registry's skeleton uses" + |
69 "\ncorrect interface hash and operation numbers:"); |
69 "\ncorrect interface hash and operation numbers:"); |
70 |
70 |
71 Registry testImpl = LocateRegistry.createRegistry(PORT); |
71 Registry testImpl = LocateRegistry.createRegistry(PORT); |
72 System.err.println("created test registry on port " + PORT); |
72 System.err.println("created test registry on port " + PORT); |
73 |
73 |
74 RemoteRef ref = new UnicastRef( |
74 RemoteRef ref = new UnicastRef( |
75 new LiveRef(new ObjID(ObjID.REGISTRY_ID), |
75 new LiveRef(new ObjID(ObjID.REGISTRY_ID), |
76 new TCPEndpoint("", PORT), false)); |
76 new TCPEndpoint("", PORT), false)); |
77 Registry referenceStub = new ReferenceRegistryStub(ref); |
77 Registry referenceStub = new ReferenceRegistryStub(ref); |
78 System.err.println("created reference registry stub: " + |
78 System.err.println("created reference registry stub: " + |
79 referenceStub); |
79 referenceStub); |
80 |
80 |
81 referenceStub.bind(NAME, referenceStub); |
81 referenceStub.bind(NAME, referenceStub); |
82 System.err.println("bound name \"" + NAME + "\" in registry"); |
82 System.err.println("bound name \"" + NAME + "\" in registry"); |
83 |
83 |
84 String[] list = referenceStub.list(); |
84 String[] list = referenceStub.list(); |
85 System.err.println("list of registry contents: " + |
85 System.err.println("list of registry contents: " + |
86 Arrays.asList(list)); |
86 Arrays.asList(list)); |
87 if (list.length != 1 || !list[0].equals(NAME)) { |
87 if (list.length != 1 || !list[0].equals(NAME)) { |
88 throw new RuntimeException( |
88 throw new RuntimeException( |
89 "TEST FAILED: unexpected list contents"); |
89 "TEST FAILED: unexpected list contents"); |
90 } |
90 } |
91 |
91 |
92 Registry result = (Registry) referenceStub.lookup(NAME); |
92 Registry result = (Registry) referenceStub.lookup(NAME); |
93 System.err.println("lookup of name \"" + NAME + "\" returned: " + |
93 System.err.println("lookup of name \"" + NAME + "\" returned: " + |
94 result); |
94 result); |
95 if (!result.equals(referenceStub)) { |
95 if (!result.equals(referenceStub)) { |
96 throw new RuntimeException( |
96 throw new RuntimeException( |
97 "TEST FAILED: unexpected lookup result"); |
97 "TEST FAILED: unexpected lookup result"); |
98 } |
98 } |
99 |
99 |
100 referenceStub.rebind(NAME, referenceStub); |
100 referenceStub.rebind(NAME, referenceStub); |
101 referenceStub.unbind(NAME); |
101 referenceStub.unbind(NAME); |
102 System.err.println("unbound name \"" + NAME + "\""); |
102 System.err.println("unbound name \"" + NAME + "\""); |
103 |
103 |
104 list = referenceStub.list(); |
104 list = referenceStub.list(); |
105 System.err.println("list of registry contents: " + |
105 System.err.println("list of registry contents: " + |
106 Arrays.asList(list)); |
106 Arrays.asList(list)); |
107 if (list.length != 0) { |
107 if (list.length != 0) { |
108 throw new RuntimeException("TEST FAILED: list not empty"); |
108 throw new RuntimeException("TEST FAILED: list not empty"); |
109 } |
109 } |
110 |
110 |
111 System.err.println("\n=== verifying that J2SE registry's stub uses" + |
111 System.err.println("\n=== verifying that J2SE registry's stub uses" + |
112 "correct interface hash:"); |
112 "correct interface hash:"); |
113 |
113 |
114 class FakeRemoteRef implements RemoteRef { |
114 class FakeRemoteRef implements RemoteRef { |
115 long hash; |
115 long hash; |
116 int opnum; |
116 int opnum; |
117 public RemoteCall newCall(RemoteObject obj, Operation[] op, |
117 public RemoteCall newCall(RemoteObject obj, Operation[] op, |
118 int opnum, long hash) |
118 int opnum, long hash) |
119 { |
119 { |
120 this.hash = hash; |
120 this.hash = hash; |
121 this.opnum = opnum; |
121 this.opnum = opnum; |
122 throw new UnsupportedOperationException(); |
122 throw new UnsupportedOperationException(); |
123 } |
123 } |
124 public void invoke(RemoteCall call) { } |
124 public void invoke(RemoteCall call) { } |
125 public void done(RemoteCall call) { } |
125 public void done(RemoteCall call) { } |
126 public Object invoke(Remote obj, Method method, |
126 public Object invoke(Remote obj, Method method, |
127 Object[] args, long hash) |
127 Object[] args, long hash) |
128 { |
128 { |
129 throw new UnsupportedOperationException(); |
129 throw new UnsupportedOperationException(); |
130 } |
130 } |
131 public String getRefClass(java.io.ObjectOutput out) { |
131 public String getRefClass(java.io.ObjectOutput out) { |
132 return "FakeRemoteRef"; |
132 return "FakeRemoteRef"; |
133 } |
133 } |
134 public int remoteHashCode() { return 1013; } |
134 public int remoteHashCode() { return 1013; } |
135 public boolean remoteEquals(RemoteRef obj) { return false; } |
135 public boolean remoteEquals(RemoteRef obj) { return false; } |
136 public String remoteToString() { return "FakeRemoteRef"; } |
136 public String remoteToString() { return "FakeRemoteRef"; } |
137 public void writeExternal(java.io.ObjectOutput out) { } |
137 public void writeExternal(java.io.ObjectOutput out) { } |
138 public void readExternal(java.io.ObjectInput in) { } |
138 public void readExternal(java.io.ObjectInput in) { } |
139 } |
139 } |
140 FakeRemoteRef f = new FakeRemoteRef(); |
140 FakeRemoteRef f = new FakeRemoteRef(); |
141 |
141 |
142 Registry testRegistry = LocateRegistry.getRegistry(PORT); |
142 Registry testRegistry = LocateRegistry.getRegistry(PORT); |
143 System.err.println("created original test registry stub: " + |
143 System.err.println("created original test registry stub: " + |
144 testRegistry); |
144 testRegistry); |
145 |
145 |
146 Class stubClass = testRegistry.getClass(); |
146 Class stubClass = testRegistry.getClass(); |
147 System.err.println("test registry stub class: " + stubClass); |
147 System.err.println("test registry stub class: " + stubClass); |
148 |
148 |
149 Constructor cons = stubClass.getConstructor( |
149 Constructor cons = stubClass.getConstructor( |
150 new Class[] { RemoteRef.class }); |
150 new Class[] { RemoteRef.class }); |
151 Registry testStub = (Registry) cons.newInstance( |
151 Registry testStub = (Registry) cons.newInstance( |
152 new Object[] { f }); |
152 new Object[] { f }); |
153 System.err.println("created new instrumented test registry stub: " + |
153 System.err.println("created new instrumented test registry stub: " + |
154 testStub); |
154 testStub); |
155 |
155 |
156 System.err.println("invoking bind:"); |
156 System.err.println("invoking bind:"); |
157 try { |
157 try { |
158 testStub.bind(NAME, referenceStub); |
158 testStub.bind(NAME, referenceStub); |
159 } catch (UnsupportedOperationException e) { |
159 } catch (UnsupportedOperationException e) { |
160 } |
160 } |
161 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
161 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
162 if (f.hash != 4905912898345647071L) { |
162 if (f.hash != 4905912898345647071L) { |
163 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
163 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
164 } else if (f.opnum != 0) { |
164 } else if (f.opnum != 0) { |
165 throw new RuntimeException("TEST FAILED: wrong operation number"); |
165 throw new RuntimeException("TEST FAILED: wrong operation number"); |
166 } |
166 } |
167 |
167 |
168 System.err.println("invoking list:"); |
168 System.err.println("invoking list:"); |
169 try { |
169 try { |
170 testStub.list(); |
170 testStub.list(); |
171 } catch (UnsupportedOperationException e) { |
171 } catch (UnsupportedOperationException e) { |
172 } |
172 } |
173 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
173 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
174 if (f.hash != 4905912898345647071L) { |
174 if (f.hash != 4905912898345647071L) { |
175 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
175 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
176 } else if (f.opnum != 1) { |
176 } else if (f.opnum != 1) { |
177 throw new RuntimeException("TEST FAILED: wrong operation number"); |
177 throw new RuntimeException("TEST FAILED: wrong operation number"); |
178 } |
178 } |
179 |
179 |
180 System.err.println("invoking lookup:"); |
180 System.err.println("invoking lookup:"); |
181 try { |
181 try { |
182 testStub.lookup(NAME); |
182 testStub.lookup(NAME); |
183 } catch (UnsupportedOperationException e) { |
183 } catch (UnsupportedOperationException e) { |
184 } |
184 } |
185 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
185 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
186 if (f.hash != 4905912898345647071L) { |
186 if (f.hash != 4905912898345647071L) { |
187 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
187 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
188 } else if (f.opnum != 2) { |
188 } else if (f.opnum != 2) { |
189 throw new RuntimeException("TEST FAILED: wrong operation number"); |
189 throw new RuntimeException("TEST FAILED: wrong operation number"); |
190 } |
190 } |
191 |
191 |
192 System.err.println("invoking rebind:"); |
192 System.err.println("invoking rebind:"); |
193 try { |
193 try { |
194 testStub.rebind(NAME, referenceStub); |
194 testStub.rebind(NAME, referenceStub); |
195 } catch (UnsupportedOperationException e) { |
195 } catch (UnsupportedOperationException e) { |
196 } |
196 } |
197 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
197 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
198 if (f.hash != 4905912898345647071L) { |
198 if (f.hash != 4905912898345647071L) { |
199 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
199 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
200 } else if (f.opnum != 3) { |
200 } else if (f.opnum != 3) { |
201 throw new RuntimeException("TEST FAILED: wrong operation number"); |
201 throw new RuntimeException("TEST FAILED: wrong operation number"); |
202 } |
202 } |
203 |
203 |
204 System.err.println("invoking unbind:"); |
204 System.err.println("invoking unbind:"); |
205 try { |
205 try { |
206 testStub.unbind(NAME); |
206 testStub.unbind(NAME); |
207 } catch (UnsupportedOperationException e) { |
207 } catch (UnsupportedOperationException e) { |
208 } |
208 } |
209 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
209 System.err.println("hash == " + f.hash + ", opnum == " + f.opnum); |
210 if (f.hash != 4905912898345647071L) { |
210 if (f.hash != 4905912898345647071L) { |
211 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
211 throw new RuntimeException("TEST FAILED: wrong interface hash"); |
212 } else if (f.opnum != 4) { |
212 } else if (f.opnum != 4) { |
213 throw new RuntimeException("TEST FAILED: wrong operation number"); |
213 throw new RuntimeException("TEST FAILED: wrong operation number"); |
214 } |
214 } |
215 |
215 |
216 System.err.println("TEST PASSED"); |
216 System.err.println("TEST PASSED"); |
217 } |
217 } |
218 } |
218 } |