/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4940957
* @summary Tests behaviour when connections break
* @author Eamonn McManus
* @run clean BrokenConnectionTest
* @run build BrokenConnectionTest
* @run main BrokenConnectionTest
*/
import javax.management.*;
// resolve ambiguity
public class BrokenConnectionTest {
new ObjectName("JMImplementation:type=MBeanServerDelegate");
try {
} catch (Exception e) {
}
}
}
}
return rmiTest();
return jmxmpTest();
else
throw new AssertionError(proto);
}
private static interface Breakable {
throws IOException;
}
private static interface TestAction {
throws Exception;
}
}
throws Exception {
try {
" should fail!");
return false;
} catch (IOException e) {
}
return true;
}
}
new Operation() {
return "getDefaultDomain";
}
}
},
new Operation() {
return "addNotificationListener(NL)";
}
}
},
new Operation() {
return "addNotificationListener(MB)";
}
}
}
},
new Operation() {
return "removeNotificationListener(NL)";
}
for (int i = 0; i < NLISTENERS; i++) {
NotificationListener l = new CountListener();
}
}
}
static final int NLISTENERS = 2;
},
new Operation() {
return "removeNotificationListener(MB)";
}
}
try {
throw new IllegalArgumentException("removeNL should not " +
"have worked!");
} catch (ListenerNotFoundException e) {
// normal - there isn't one!
}
}
},
new Operation() {
return "createMBean(className, objectName)";
}
}
private synchronized int nextInstance() {
return ++instance;
}
private int instance;
},
new Operation() {
return "getAttribute";
}
}
},
new Operation() {
return "getAttributes";
}
}
},
new Operation() {
return "getDomains";
}
mbsc.getDomains();
}
},
new Operation() {
return "getMBeanCount";
}
}
},
new Operation() {
return "getMBeanInfo";
}
}
},
new Operation() {
return "getObjectInstance";
}
}
},
new Operation() {
return "invoke";
}
new String[0]);
}
},
new Operation() {
return "isInstanceOf";
}
}
},
new Operation() {
return "isRegistered";
}
}
},
new Operation() {
return "queryMBeans";
}
}
},
new Operation() {
return "queryNames";
}
}
},
new Operation() {
return "setAttribute";
}
}
},
new Operation() {
return "setAttributes";
}
}
},
new Operation() {
return "unregisterMBean";
}
for (int i = 0; i < NBEANS; i++) {
}
}
}
private static final int NBEANS = 2;
},
new TestAction() {
return "break during send for setAttribute";
}
try {
"BreakWhenSerializable did not fail!");
return false;
} catch (IOException e) {
return true;
}
}
},
new TestAction() {
return "break during receive for getAttribute";
}
try {
"BreakWhenSerializable did not fail!");
return false;
} catch (IOException e) {
return true;
}
}
},
};
public static interface BreakMBean {
// public void breakOnNotify();
public void doNothing();
}
public static class Break
extends NotificationBroadcasterSupport implements BreakMBean {
}
return new BreakWhenSerialized(breakable);
}
throw new IllegalArgumentException("setBreak worked but " +
"should not!");
}
// public void breakOnNotify() {
// Notification broken = new Notification("type", "source", 0L);
// broken.setUserData(new BreakWhenSerialized(breakable));
// sendNotification(broken);
// }
public void doNothing() {}
}
}
}
}
private static class FailureNotificationFilter
implements NotificationFilter {
return (n instanceof JMXConnectionNotification
}
}
public static interface CountListenerMBean {}
public static class CountListener
implements CountListenerMBean, NotificationListener {
count++;
}
int count;
}
throws Exception {
boolean alreadyMissedFailureNotif = false;
null);
try {
} catch (IOException e) {
}
if (thisok) {
thisok = false;
thisok = false;
}
}
if (!thisok)
}
return true;
else {
return false;
}
}
throws IOException {
brssf);
return cs;
}
}
}
}
private static class BreakableRMIServerSocketFactory
implements RMIServerSocketFactory {
throws IOException {
if (broken)
throw new IOException("ServerSocket has been broken");
return bss;
}
// System.out.println("BRSSF.setBroken(" + broken + ")");
// System.out.println((broken ? "" : "un") + "break " + bss);
}
}
new ArrayList();
private boolean broken = false;
}
}
throws IOException {
try {
"javax.management.remote.generic.MessageConnectionServer";
scsih);
"javax.management.remote.generic.GenericConnectorServer";
final Constructor constr =
return cs;
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
}
try {
} catch (ClassNotFoundException e) {
return true;
}
}
super();
}
// System.out.println("BSS.setBroken(" + broken + ")");
if (!broken)
return;
try {
// System.out.println("Break: " + s);
s.close();
} catch (IOException e) {
", ignoring (" + e + ")");
}
}
}
}
throws IOException {
}
return ss.getInetAddress();
}
public int getLocalPort() {
return ss.getLocalPort();
}
return ss.getLocalSocketAddress();
}
// System.out.println("BSS.accept");
// System.out.println("BSS.accept returned: " + s);
if (broken)
s.close();
else
return s;
}
}
return ss.getChannel();
}
public boolean isBound() {
}
public boolean isClosed() {
}
}
return ss.getSoTimeout();
}
}
return ss.getReuseAddress();
}
}
}
return ss.getReceiveBufferSize();
}
private boolean broken = false;
}
/* We do a lot of messy reflection stuff here because we don't
want to reference the optional parts of the JMX Remote API in
an environment (J2SE) where they won't be present. */
/* This class implements the logic that allows us to pretend that
we have a class that looks like this:
class SocketConnectionServer implements MessageConnectionServer {
public MessageConnection accept() throws IOException {...}
public JMXServiceURL getAddress() {...}
public void start(Map env) throws IOException {...}
public void stop() throws IOException {...}
}
*/
private static class SocketConnectionServerInvocationHandler
implements InvocationHandler {
}
throws Exception {
try {
return accept();
return getAddress();
stop();
else // probably a method inherited from Object
} catch (InvocationTargetException ite) {
if (t instanceof IOException) {
throw (IOException)t;
} else if (t instanceof RuntimeException) {
throw (RuntimeException)t;
} else {
throw ite;
}
}
return null;
}
// InvocationHandler scih = new SocketConnectionInvocationHandler(s);
// Class messageConnectionClass =
// Class.forName("javax.management.generic.MessageConnection");
// return Proxy.newProxyInstance(this.getClass().getClassLoader(),
// new Class[] {messageConnectionClass},
// scih);
}
}
}
}
}
}