changeset 6302:c1a55ee9618e

8005309: Missed tests for 6783290,6937053,7009998 Summary: Missed tests for 6783290,6937053,7009998 Reviewed-by: sjiang, emcmanus Contributed-by: jaroslav.bachorik@oracle.com
author dsamersoff
date Thu, 20 Dec 2012 20:12:32 +0400
parents 31d2f9995d6c
children edb71a37fcb7
files test/com/sun/jmx/remote/CCAdminReconnectTest.java test/com/sun/jmx/remote/NotificationMarshalVersions/Client/Client.java test/com/sun/jmx/remote/NotificationMarshalVersions/Client/ConfigKey.java test/com/sun/jmx/remote/NotificationMarshalVersions/Client/TestNotification.java test/com/sun/jmx/remote/NotificationMarshalVersions/Server/ConfigKey.java test/com/sun/jmx/remote/NotificationMarshalVersions/Server/Server.java test/com/sun/jmx/remote/NotificationMarshalVersions/Server/Ste.java test/com/sun/jmx/remote/NotificationMarshalVersions/Server/SteMBean.java test/com/sun/jmx/remote/NotificationMarshalVersions/Server/TestNotification.java test/com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh test/javax/management/MBeanInfo/SerializationTest1.java
diffstat 11 files changed, 449 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/CCAdminReconnectTest.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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 7009998
+ * @summary Tests the correct processing of concurrent ClientComunicatorAdmin reconnect requests.
+ * @author Jaroslav Bachorik
+ * @run clean CCAdminReconnectTest
+ * @run build CCAdminReconnectTest
+ * @run main CCAdminReconnectTest
+ */
+
+import com.sun.jmx.remote.internal.ClientCommunicatorAdmin;
+import java.io.*;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class CCAdminReconnectTest {
+    final private static int THREAD_COUNT = 3;
+
+    public static void main(String ... args) throws Exception {
+        final ExecutorService e = Executors.newFixedThreadPool(THREAD_COUNT);
+        final AtomicBoolean beingReconnected = new AtomicBoolean();
+        final Collection<Exception> thrownExceptions = new LinkedList<>();
+
+        System.out.println(": Testing concurrent restart of ClientCommunicatorAdmin");
+
+        final ClientCommunicatorAdmin cca = new ClientCommunicatorAdmin(50) {
+
+            @Override
+            protected void checkConnection() throws IOException {
+                // empty
+            }
+
+            @Override
+            protected void doStart() throws IOException {
+                if (!beingReconnected.compareAndSet(false, true)) {
+                    IOException e = new IOException("Detected overlayed reconnect requests");
+                    thrownExceptions.add(e);
+                    throw e;
+                }
+                try {
+                    Thread.sleep(800); // simulating a workload
+                    beingReconnected.set(false);
+                } catch (InterruptedException e) {
+                }
+            }
+
+            @Override
+            protected void doStop() {
+                // empty
+            }
+        };
+
+        Runnable r = new Runnable() {
+            final private IOException e = new IOException("Forced reconnect");
+            @Override
+            public void run() {
+                try {
+                    // forcing the reconnect request
+                    cca.gotIOException(e);
+                } catch (Exception ex) {
+                    ex.printStackTrace();
+                }
+            }
+        };
+
+        System.out.println(": Spawning " + THREAD_COUNT + " concurrent reconnect requests");
+
+        for(int i=0;i<THREAD_COUNT;i++) {
+            e.execute(r);
+        }
+
+        Thread.sleep(THREAD_COUNT * 1000);
+        e.shutdown();
+        e.awaitTermination(10, TimeUnit.SECONDS);
+
+        cca.terminate();
+
+        for(Exception thrown : thrownExceptions) {
+            throw thrown;
+        }
+        System.out.println(": Requests processed successfully");
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Client/Client.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,47 @@
+
+import java.nio.charset.Charset;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardWatchEventKinds;
+import java.nio.file.WatchEvent;
+import java.nio.file.WatchService;
+import javax.management.MBeanServerConnection;
+import javax.management.Notification;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnector;
+import javax.management.remote.JMXConnectorFactory;
+import javax.management.remote.JMXServiceURL;
+
+public class Client {
+    public static void main(String[] argv) throws Exception {
+        if (argv.length != 1) throw new IllegalArgumentException("Expecting exactly one jmx url argument");
+
+        JMXServiceURL serverUrl = new JMXServiceURL(argv[0]);
+
+        ObjectName name = new ObjectName("test", "foo", "bar");
+        JMXConnector jmxConnector = JMXConnectorFactory.connect(serverUrl);
+        System.out.println("client connected");
+        jmxConnector.addConnectionNotificationListener(new NotificationListener() {
+            public void handleNotification(Notification notification, Object handback) {
+                System.err.println("no!" + notification);
+            }
+        }, null, null);
+        MBeanServerConnection jmxServer = jmxConnector.getMBeanServerConnection();
+
+        jmxServer.addNotificationListener(name, new NotificationListener() {
+            public void handleNotification(Notification notification, Object handback) {
+                System.out.println("client got:" + notification);
+            }
+        }, null, null);
+
+        for(int i=0;i<10;i++) {
+            System.out.println("client invoking foo");
+            jmxServer.invoke(name, "foo", new Object[]{}, new String[]{});
+            Thread.sleep(50);
+        }
+
+        System.err.println("happy!");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Client/ConfigKey.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,3 @@
+public enum ConfigKey {
+    CONSTANT3, CONSTANT2;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Client/TestNotification.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,25 @@
+
+import javax.management.Notification;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author Jaroslav Bachorik <jaroslav.bachorik at oracle.com>
+ */
+public class TestNotification extends Notification {
+    private ConfigKey key;
+
+    public TestNotification(String type, Object source, long sequenceNumber) {
+        super(type, source, sequenceNumber);
+        key = ConfigKey.CONSTANT3;
+    }
+
+    @Override
+    public String toString() {
+        return "TestNotification{" + "key=" + key + '}';
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Server/ConfigKey.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,3 @@
+public enum ConfigKey {
+    CONSTANT1, CONSTANT2;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Server/Server.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,46 @@
+import java.lang.management.ManagementFactory;
+import java.net.BindException;
+import java.nio.charset.Charset;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardOpenOption;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.server.ExportException;
+import java.util.Random;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXConnectorServerFactory;
+import javax.management.remote.JMXServiceURL;
+
+public class Server {
+    public static void main(String[] argv) throws Exception {
+        int serverPort = 12345;
+        ObjectName name = new ObjectName("test", "foo", "bar");
+        MBeanServer jmxServer = ManagementFactory.getPlatformMBeanServer();
+        SteMBean bean = new Ste();
+        jmxServer.registerMBean(bean, name);
+        boolean exported = false;
+        Random rnd = new Random(System.currentTimeMillis());
+        do {
+            try {
+                LocateRegistry.createRegistry(serverPort);
+                exported = true;
+            } catch (ExportException ee) {
+                if (ee.getCause() instanceof BindException) {
+                    serverPort = rnd.nextInt(10000) + 4096;
+                } else {
+                    throw ee;
+                }
+            }
+
+        } while (!exported);
+        JMXServiceURL serverUrl = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + serverPort + "/test");
+        JMXConnectorServer jmxConnector = JMXConnectorServerFactory.newJMXConnectorServer(serverUrl, null, jmxServer);
+        jmxConnector.start();
+        System.out.println(serverUrl);
+        System.err.println("server listening on " + serverUrl);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Server/Ste.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,10 @@
+
+import javax.management.NotificationBroadcasterSupport;
+
+public class Ste extends NotificationBroadcasterSupport implements SteMBean {
+    private long count = 0;
+
+    public void foo() {
+        sendNotification(new TestNotification("test", this, count++));
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Server/SteMBean.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,3 @@
+public interface SteMBean {
+    public void foo();
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/Server/TestNotification.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,25 @@
+
+import javax.management.Notification;
+
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+/**
+ *
+ * @author Jaroslav Bachorik <jaroslav.bachorik at oracle.com>
+ */
+public class TestNotification extends Notification {
+    private ConfigKey key;
+
+    public TestNotification(String type, Object source, long sequenceNumber) {
+        super(type, source, sequenceNumber);
+        key = ConfigKey.CONSTANT1;
+    }
+
+    @Override
+    public String toString() {
+        return "TestNotification{" + "key=" + key + '}';
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/com/sun/jmx/remote/NotificationMarshalVersions/TestSerializationMismatch.sh	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,93 @@
+#
+# Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# This code is free software; you can redistribute it and/or modify it
+# 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
+# @summary  Tests for the RMI unmarshalling errors not to cause silent failure.
+# @author   Jaroslav Bachorik
+# @bug      6937053
+#
+# @run shell TestSerializationMismatch.sh
+#
+
+#set -x
+
+#Set appropriate jdk
+#
+
+if [ ! -z "${TESTJAVA}" ] ; then
+     jdk="$TESTJAVA"
+else
+     echo "--Error: TESTJAVA must be defined as the pathname of a jdk to test."
+     exit 1
+fi
+
+SERVER_TESTCLASSES=$TESTCLASSES/Server
+CLIENT_TESTCLASSES=$TESTCLASSES/Client
+
+URL_PATH=$SERVER_TESTCLASSES/jmxurl
+
+rm $URL_PATH
+
+mkdir -p $SERVER_TESTCLASSES
+mkdir -p $CLIENT_TESTCLASSES
+
+$TESTJAVA/bin/javac -d $CLIENT_TESTCLASSES $TESTSRC/Client/ConfigKey.java $TESTSRC/Client/TestNotification.java $TESTSRC/Client/Client.java
+$TESTJAVA/bin/javac -d $SERVER_TESTCLASSES $TESTSRC/Server/ConfigKey.java $TESTSRC/Server/TestNotification.java $TESTSRC/Server/SteMBean.java $TESTSRC/Server/Ste.java $TESTSRC/Server/Server.java
+
+startServer()
+{
+   ($TESTJAVA/bin/java -classpath $SERVER_TESTCLASSES Server) 1>$URL_PATH &
+   SERVER_PID=$!
+}
+
+runClient() 
+{
+   while true
+   do
+      [ -f $URL_PATH ] && break
+      sleep 2
+   done
+   read JMXURL < $URL_PATH
+   
+   HAS_ERRORS=`($TESTJAVA/bin/java -classpath $CLIENT_TESTCLASSES Client $JMXURL) 2>&1 | grep -i "SEVERE: Failed to fetch notification, stopping thread. Error is: java.rmi.UnmarshalException"`
+}
+
+startServer
+
+runClient
+
+sleep 1 # wait for notifications to arrive
+
+kill "$SERVER_PID"
+
+if [ -z "$HAS_ERRORS" ]
+then
+  echo "Test PASSED"
+  exit 0
+fi
+
+echo "Test FAILED"
+echo $HAS_ERRORS 1>&2
+exit 1
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/management/MBeanInfo/SerializationTest1.java	Thu Dec 20 20:12:32 2012 +0400
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * 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 6783290
+ * @summary Test correct reading of an empty Descriptor.
+ * @author Jaroslav Bachorik
+ * @run clean SerializationTest1
+ * @run build SerializationTest1
+ * @run main SerializationTest1
+ */
+
+import java.io.*;
+import javax.management.*;
+
+public class SerializationTest1 {
+    public static void main(String[] args) throws Exception {
+        MBeanInfo mi1 = new MBeanInfo("",
+                                      "",
+                                      new MBeanAttributeInfo[]{},
+                                      new MBeanConstructorInfo[]{},
+                                      new MBeanOperationInfo[]{},
+                                      new MBeanNotificationInfo[]{},
+                                      ImmutableDescriptor.EMPTY_DESCRIPTOR);
+
+        test(mi1);
+
+        MBeanFeatureInfo mfi2 = new MBeanFeatureInfo("",
+                                                     "",
+                                                     ImmutableDescriptor.EMPTY_DESCRIPTOR);
+
+        test(mfi2);
+    }
+
+    public static void test(Object obj) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream oos = new ObjectOutputStream(baos);
+        oos.writeObject(obj);
+
+        final boolean[] failed = new boolean[]{false};
+        ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+        final ObjectInputStream ois = new ObjectInputStream(bais) {
+            protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+                System.out.println("*** " + desc.getName());
+                if (desc.getName().equals("[Ljava.lang.Object;")) { // javax.management.Descriptor fields
+                    Thread.dumpStack();
+                    for(StackTraceElement e : Thread.currentThread().getStackTrace()) { // checking for the deserialization location
+                        if (e.getMethodName().equals("skipCustomData")) { // indicates the presence of unread values from the custom object serialization
+                            failed[0] = true;
+                        }
+                    }
+                }
+                return super.resolveClass(desc); //To change body of generated methods, choose Tools | Templates.
+            }
+        };
+        Object newObj = ois.readObject();
+
+        if (failed[0]) {
+            throw new RuntimeException("Zero-length descriptor not read back");
+        }
+    }
+}