author | alanb |
Thu, 17 Mar 2016 19:04:16 +0000 | |
changeset 36511 | 9d0388c6b336 |
parent 32835 | 8bfe2ea5617d |
child 40261 | 86a49ba76f52 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
31247
6423385b99fe
8129499: Structure of java/rmi/activation/rmidViaInheritedChannel tests masks exception
bpb
parents:
30820
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
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 |
* |
|
5506 | 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. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* @test |
|
2443
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
25 |
* @bug 6261402 6824141 |
2 | 26 |
* @summary If rmid has an inherited channel that is not a server |
27 |
* socket (such as it if was started using rsh/rcmd), then it should |
|
28 |
* function normally. |
|
29 |
* @author Peter Jones |
|
30 |
* |
|
31 |
* @library ../../testlibrary |
|
30820 | 32 |
* @modules java.base/sun.nio.ch |
33 |
* java.rmi/sun.rmi.registry |
|
34 |
* java.rmi/sun.rmi.server |
|
35 |
* java.rmi/sun.rmi.transport |
|
36 |
* java.rmi/sun.rmi.transport.tcp |
|
14778 | 37 |
* @build TestLibrary RMID ActivationLibrary |
13256 | 38 |
* @run main/othervm/timeout=240 InheritedChannelNotServerSocket |
32835
8bfe2ea5617d
8137232: Mark 3 more core-libs tests as intermittently failing
amlu
parents:
31247
diff
changeset
|
39 |
* @key intermittent |
2 | 40 |
*/ |
41 |
||
42 |
import java.io.IOException; |
|
43 |
import java.net.Socket; |
|
2443
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
44 |
import java.net.ProtocolFamily; |
2 | 45 |
import java.nio.channels.Channel; |
46 |
import java.nio.channels.DatagramChannel; |
|
47 |
import java.nio.channels.Pipe; |
|
48 |
import java.nio.channels.ServerSocketChannel; |
|
49 |
import java.nio.channels.SocketChannel; |
|
50 |
import java.nio.channels.spi.AbstractSelector; |
|
51 |
import java.nio.channels.spi.SelectorProvider; |
|
52 |
import java.rmi.NotBoundException; |
|
53 |
import java.rmi.Remote; |
|
54 |
import java.rmi.RemoteException; |
|
55 |
import java.rmi.activation.ActivationGroup; |
|
56 |
import java.rmi.activation.ActivationSystem; |
|
57 |
import java.rmi.registry.LocateRegistry; |
|
58 |
import java.rmi.registry.Registry; |
|
59 |
import java.rmi.server.UnicastRemoteObject; |
|
60 |
||
61 |
public class InheritedChannelNotServerSocket { |
|
62 |
private static final Object lock = new Object(); |
|
63 |
private static boolean notified = false; |
|
64 |
||
65 |
private InheritedChannelNotServerSocket() { } |
|
66 |
||
67 |
public interface Callback extends Remote { |
|
68 |
void notifyTest() throws RemoteException; |
|
69 |
} |
|
70 |
||
71 |
public static class CallbackImpl implements Callback { |
|
72 |
CallbackImpl() { } |
|
73 |
public void notifyTest() { |
|
74 |
synchronized (lock) { |
|
75 |
notified = true; |
|
76 |
System.err.println("notification received."); |
|
77 |
lock.notifyAll(); |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
||
82 |
public static void main(String[] args) throws Exception { |
|
83 |
System.err.println("\nRegression test for bug 6261402\n"); |
|
13256 | 84 |
System.setProperty("java.rmi.activation.port", |
85 |
Integer.toString(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT)); |
|
2 | 86 |
RMID rmid = null; |
87 |
Callback obj = null; |
|
88 |
try { |
|
89 |
/* |
|
90 |
* Export callback object and bind in registry. |
|
91 |
*/ |
|
92 |
System.err.println("export callback object and bind in registry"); |
|
93 |
obj = new CallbackImpl(); |
|
94 |
Callback proxy = |
|
95 |
(Callback) UnicastRemoteObject.exportObject(obj, 0); |
|
96 |
Registry registry = |
|
13256 | 97 |
LocateRegistry.createRegistry( |
98 |
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); |
|
2 | 99 |
registry.bind("Callback", proxy); |
100 |
||
101 |
/* |
|
102 |
* Start rmid. |
|
103 |
*/ |
|
104 |
System.err.println("start rmid with inherited channel"); |
|
105 |
RMID.removeLog(); |
|
13256 | 106 |
rmid = RMID.createRMID(System.out, System.err, true, true, |
107 |
TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_ACTIVATION_PORT); |
|
36511 | 108 |
rmid.addOptions( |
109 |
"-XaddExports:java.base/sun.nio.ch=ALL-UNNAMED", |
|
110 |
"-Djava.nio.channels.spi.SelectorProvider=InheritedChannelNotServerSocket$SP"); |
|
2 | 111 |
rmid.start(); |
112 |
||
113 |
/* |
|
114 |
* Get activation system and wait to be notified via callback |
|
115 |
* from rmid's selector provider. |
|
116 |
*/ |
|
117 |
System.err.println("get activation system"); |
|
118 |
ActivationSystem system = ActivationGroup.getSystem(); |
|
119 |
System.err.println("ActivationSystem = " + system); |
|
120 |
synchronized (lock) { |
|
121 |
while (!notified) { |
|
122 |
lock.wait(); |
|
123 |
} |
|
124 |
} |
|
125 |
System.err.println("TEST PASSED"); |
|
126 |
} finally { |
|
127 |
if (obj != null) { |
|
128 |
UnicastRemoteObject.unexportObject(obj, true); |
|
129 |
} |
|
31247
6423385b99fe
8129499: Structure of java/rmi/activation/rmidViaInheritedChannel tests masks exception
bpb
parents:
30820
diff
changeset
|
130 |
if (rmid != null) { |
6423385b99fe
8129499: Structure of java/rmi/activation/rmidViaInheritedChannel tests masks exception
bpb
parents:
30820
diff
changeset
|
131 |
rmid.cleanup(); |
6423385b99fe
8129499: Structure of java/rmi/activation/rmidViaInheritedChannel tests masks exception
bpb
parents:
30820
diff
changeset
|
132 |
} |
2 | 133 |
} |
134 |
} |
|
135 |
||
136 |
public static class SP extends SelectorProvider { |
|
137 |
private final SelectorProvider provider; |
|
138 |
private volatile SocketChannel channel = null; |
|
139 |
||
140 |
public SP() { |
|
141 |
provider = sun.nio.ch.DefaultSelectorProvider.create(); |
|
142 |
} |
|
143 |
||
144 |
public DatagramChannel openDatagramChannel() throws IOException { |
|
145 |
return provider.openDatagramChannel(); |
|
146 |
} |
|
147 |
||
2443
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
148 |
public DatagramChannel openDatagramChannel(ProtocolFamily family) |
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
149 |
throws IOException |
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
150 |
{ |
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
151 |
return provider.openDatagramChannel(family); |
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
152 |
} |
4bcc75ed04c0
6824141: test/java/rmi/activation/rmidViaInheritedChannel tests fail
alanb
parents:
2
diff
changeset
|
153 |
|
2 | 154 |
public Pipe openPipe() throws IOException { |
155 |
return provider.openPipe(); |
|
156 |
} |
|
157 |
||
158 |
public AbstractSelector openSelector() throws IOException { |
|
159 |
return provider.openSelector(); |
|
160 |
} |
|
161 |
||
162 |
public ServerSocketChannel openServerSocketChannel() |
|
163 |
throws IOException |
|
164 |
{ |
|
165 |
return provider.openServerSocketChannel(); |
|
166 |
} |
|
167 |
||
168 |
public SocketChannel openSocketChannel() throws IOException { |
|
169 |
return provider.openSocketChannel(); |
|
170 |
} |
|
171 |
||
172 |
public synchronized Channel inheritedChannel() throws IOException { |
|
173 |
System.err.println("SP.inheritedChannel"); |
|
174 |
if (channel == null) { |
|
175 |
channel = SocketChannel.open(); |
|
176 |
Socket socket = channel.socket(); |
|
177 |
System.err.println("socket = " + socket); |
|
178 |
||
179 |
/* |
|
180 |
* Notify test that inherited channel was created. |
|
181 |
*/ |
|
182 |
try { |
|
183 |
System.err.println("notify test..."); |
|
184 |
Registry registry = |
|
13256 | 185 |
LocateRegistry.getRegistry(TestLibrary.INHERITEDCHANNELNOTSERVERSOCKET_REGISTRY_PORT); |
2 | 186 |
Callback obj = (Callback) registry.lookup("Callback"); |
187 |
obj.notifyTest(); |
|
188 |
} catch (NotBoundException nbe) { |
|
189 |
throw (IOException) |
|
190 |
new IOException("callback object not bound"). |
|
191 |
initCause(nbe); |
|
192 |
} |
|
193 |
} |
|
194 |
return channel; |
|
195 |
} |
|
196 |
} |
|
197 |
} |