List:Commits« Previous MessageNext Message »
From:eherman Date:November 22 2006 10:16pm
Subject:Connector/MXJ commit: r58 - in trunk/connector-mxj/src/com/mysql/management: . driverlaunched jmx util
View as plain text  
Modified:
   trunk/connector-mxj/src/com/mysql/management/MysqldResource.java
   trunk/connector-mxj/src/com/mysql/management/MysqldResourceI.java
   trunk/connector-mxj/src/com/mysql/management/MysqldResourceTestImpl.java
   trunk/connector-mxj/src/com/mysql/management/driverlaunched/AcceptanceTest.java
   trunk/connector-mxj/src/com/mysql/management/driverlaunched/ServerLauncherSocketFactory.java
   trunk/connector-mxj/src/com/mysql/management/jmx/SimpleMysqldDynamicMBean.java
   trunk/connector-mxj/src/com/mysql/management/util/Files.java
Log:
Fix for BUG#24004; plust some code performance and test robustness

Modified: trunk/connector-mxj/src/com/mysql/management/MysqldResource.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/MysqldResource.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/MysqldResource.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -145,14 +145,34 @@
      * No effect if MySQL is already running
      */
     public void start(String threadName, Map mysqldArgs) {
+        start(threadName, mysqldArgs, false);
+    }
+
+    public void start(String threadName, Map mysqldArgs,
+            boolean populateAllOptions) {
         if ((getShell() != null) || processRunning()) {
             printMessage("mysqld already running (process: " + pid() + ")");
             return;
         }
 
+        mysqldArgs = new HashMap(mysqldArgs);
+
+        int port = 3306;
+        Object portArg = mysqldArgs.get(MysqldResourceI.PORT);
+        if (portArg != null) {
+            port = Integer.parseInt(portArg.toString());
+        }
+        String portStr = "" + port;
+        mysqldArgs.put(MysqldResourceI.PORT, portStr);
         mysqldArgs.remove(MysqldResourceI.MYSQLD_VERSION);
-        options = optionParser.getOptionsFromHelp(getHelp(mysqldArgs));
 
+        if (populateAllOptions) {
+            options = optionParser.getOptionsFromHelp(getHelp(mysqldArgs));
+        } else {
+            options = new HashMap();
+            options.putAll(mysqldArgs);
+        }
+
         // printMessage("mysqld : " +
         // services.str().toString(mysqldArgs.entrySet()));
         out.flush();
@@ -166,17 +186,17 @@
         setShell(exec(threadName, mysqldArgs, out, err, true));
 
         reportPid();
+        utils.files().writeString(portFile(), portStr);
 
-        int port = 3306;
-        Object portArg = mysqldArgs.get(MysqldResourceI.PORT);
-        if (portArg != null) {
-            port = Integer.parseInt(portArg.toString());
-        }
         int triesBeforeGivingUp = (killDelay / 1000) * 4;
         boolean ready = canConnectToServer(port, triesBeforeGivingUp);
         setReadyForConnection(ready);
     }
 
+    private File portFile() {
+        return new File(dataDir, "port");
+    }
+
     boolean canConnectToServer(int port, int triesBeforeGivingUp) {
         utils.str().classForName(Driver.class.getName());
         Connection conn = null;
@@ -648,4 +668,13 @@
 
         mysqld.start(new Threads().newName(), clop.asMap());
     }
+
+    public int getPort() {
+        if (isRunning()) {
+            String portStr = utils.files().asString(portFile())
+                    .trim();
+            return Integer.parseInt(portStr);
+        }
+        return 0;
+    }
 }
\ No newline at end of file

Modified: trunk/connector-mxj/src/com/mysql/management/MysqldResourceI.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/MysqldResourceI.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/MysqldResourceI.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -45,6 +45,8 @@
 
     void start(String threadName, Map mysqldArgs);
 
+    void start(String threadName, Map mysqldArgs, boolean populateAllOptions);
+
     void shutdown();
 
     Map getServerOptions();
@@ -58,4 +60,6 @@
     void addCompletionListenser(Runnable listener);
 
     File getBaseDir();
+    
+    int getPort();
 }
\ No newline at end of file

Modified: trunk/connector-mxj/src/com/mysql/management/MysqldResourceTestImpl.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/MysqldResourceTestImpl.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/MysqldResourceTestImpl.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -64,6 +64,11 @@
     }
 
     public void start(String threadName, Map mysqldArgs) {
+        start(threadName, mysqldArgs, false);
+    }
+
+    public void start(String threadName, Map mysqldArgs,
+            boolean populateAllOptions) {
         if (running != null) {
             String msg = "already running " + running + " mysqldArgs: "
                     + new ListToString().toString(mysqldArgs);
@@ -115,4 +120,8 @@
     public File getBaseDir() {
         return baseDir;
     }
+
+    public int getPort() {
+        return 0;
+    }
 }
\ No newline at end of file

Modified: trunk/connector-mxj/src/com/mysql/management/driverlaunched/AcceptanceTest.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/driverlaunched/AcceptanceTest.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/driverlaunched/AcceptanceTest.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -69,5 +69,7 @@
         ;
 
         new TestUtil().assertConnectViaJDBC(url);
+        new TestUtil().assertConnectViaJDBC(url);
+        new TestUtil().assertConnectViaJDBC(url);
     }
 }

Modified: trunk/connector-mxj/src/com/mysql/management/driverlaunched/ServerLauncherSocketFactory.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/driverlaunched/ServerLauncherSocketFactory.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/driverlaunched/ServerLauncherSocketFactory.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -85,11 +85,14 @@
                 dataDir);
 
         if (mysqld.isRunning()) {
-            Object runningPort = mysqld.getServerOptions().get(
-                    MysqldResourceI.PORT);
-            if (!runningPort.equals(Integer.toString(port))) {
-                String msg = "Mysqld at " + mysqld.getBaseDir()
-                        + " is running on port " + runningPort + " not " + port;
+            int runningPort = mysqld.getPort();
+            if (port != runningPort) {
+                String location = mysqld.getBaseDir().getPath();
+                if (dataDir != null) {
+                    location += " with data at " + dataDir;
+                }
+                String msg = "Mysqld at " + location + " is running on port "
+                        + runningPort + " not " + port;
                 throw new RuntimeException(msg);
             }
             return;

Modified: trunk/connector-mxj/src/com/mysql/management/jmx/SimpleMysqldDynamicMBean.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/jmx/SimpleMysqldDynamicMBean.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/jmx/SimpleMysqldDynamicMBean.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -208,7 +208,7 @@
         clearMBeanInfo();
 
         if (methodName.equals(START_METHOD)) {
-            mysqldResource.start("MysqldMBean", attributesToOpionMap());
+            mysqldResource.start("MysqldMBean", attributesToOpionMap(), true);
             getMBeanOperationInfoList().remove(startMysqldOp);
             getMBeanOperationInfoList().add(stopOp);
             freezeAttributes();

Modified: trunk/connector-mxj/src/com/mysql/management/util/Files.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/util/Files.java	2006-11-22 17:30:31 UTC (rev 57)
+++ trunk/connector-mxj/src/com/mysql/management/util/Files.java	2006-11-22 22:16:11 UTC (rev 58)
@@ -19,8 +19,10 @@
 
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.PrintStream;
+import java.io.PrintWriter;
 
 /**
  * @author Eric Herman <eric@stripped>
@@ -112,6 +114,31 @@
         }.exec();
     }
 
+    public void writeString(final File file, final String str) {
+        new Exceptions.VoidBlock() {
+            public void inner() throws IOException {
+                FileWriter fw = null;
+                PrintWriter pw = null;
+                try {
+                    fw = new FileWriter(file);
+                    pw = new PrintWriter(fw);
+                    pw.print(str);
+                    pw.flush();
+                } finally {
+                    try {
+                        if (pw != null) {
+                            pw.close();
+                        }
+                    } finally {
+                        if (fw != null) {
+                            fw.close();
+                        }
+                    }
+                }
+            }
+        }.exec();
+    }
+
     public File nullFile() {
         return new File("");
     }

Thread
Connector/MXJ commit: r58 - in trunk/connector-mxj/src/com/mysql/management: . driverlaunched jmx utileherman22 Nov