Modified:
trunk/connector-mxj/CHANGES
trunk/connector-mxj/build.xml
trunk/connector-mxj/src/com/mysql/management/MysqldResource.java
trunk/connector-mxj/src/com/mysql/management/MysqldResourceTest.java
trunk/connector-mxj/src/com/mysql/management/util/Str.java
Log:
now we determine if server is "ready for connections" via JDBC, no longer parse output of
mysqld
Modified: trunk/connector-mxj/CHANGES
===================================================================
--- trunk/connector-mxj/CHANGES 2006-05-12 14:23:00 UTC (rev 48)
+++ trunk/connector-mxj/CHANGES 2006-05-16 02:43:57 UTC (rev 49)
@@ -1,6 +1,12 @@
# Changelog
# $Id: CHANGES,v 1.14 2005/10/25 19:11:16 eherman Exp $
+2006-05-15 - Replaced string parsing with JDBC connection attempt for
+ determining if a mysqld is "ready for connections"
+ NOTICE: Classpath will now need to include Connector/J jar.
+ - Extended timeout for help string parsing, to avoid cases where the
+ help text was getting prematurely flushed, and thus truncated.
+
2006-05-11 - Added trace level logging with Aspect/J. NOTICE: CLASSPATH will now
need to include "lib/aspectjrt.jar" in their for all users.
Modified: trunk/connector-mxj/build.xml
===================================================================
--- trunk/connector-mxj/build.xml 2006-05-12 14:23:00 UTC (rev 48)
+++ trunk/connector-mxj/build.xml 2006-05-16 02:43:57 UTC (rev 49)
@@ -167,14 +167,36 @@
<target name="-compile" unless="source.only">
<mkdir dir="${build}" />
- <echo> compiling MBean and supporting classes </echo>
+ <echo> compiling MysqldResource class and supporting classes </echo>
<javac srcdir="${src}" destdir="${build}" debug="true" verbose="false">
<classpath refid="project.build.classpath" />
- <exclude name="*Test*" />
+ <exclude name="**/*Test*" />
</javac>
+
<antcall target="-compile-tests" />
<antcall target="-skip-compile-tests" />
+ <antcall target="-instrument-logging" />
+ <antcall target="-skip-instrument-logging" />
+
+ <mkdir dir="${stage-cmxj}" />
+ <jar destfile="${stage-cmxj}/connector-mxj.jar">
+ <fileset dir="${build}" />
+ <fileset dir="${resources}">
+ <include name="5-0-21/**" />
+ <include name="kill.exe" />
+ <include name="*.txt" />
+ </fileset>
+ </jar>
+ </target>
+
+
+ <target name="-skip-instrument-logging" if="no.aspectj">
+ <echo> skip instrumenting classes for logging</echo>
+ </target>
+
+ <target name="-instrument-logging" unless="no.aspectj">
+ <echo> instrumenting classes for logging</echo>
<!-- <taskdef
resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties"/> -->
<taskdef resource="org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties">
<classpath>
@@ -192,18 +214,8 @@
<pathelement location="lib/aspectjtools.jar"/>
</classpath>
</iajc>
-
- <mkdir dir="${stage-cmxj}" />
- <jar destfile="${stage-cmxj}/connector-mxj.jar">
- <fileset dir="${build}" />
- <fileset dir="${resources}">
- <include name="5-0-21/**" />
- <include name="kill.exe" />
- <include name="*.txt" />
- </fileset>
- </jar>
</target>
-
+
<target name="-skip-compile-tests" if="no.test">
<echo> skipping compiling of Unit Tests and supporting classes </echo>
</target>
@@ -392,8 +404,11 @@
- <target name="instrument" description="runs the examples">
+ <target name="-emma-instrument" description="runs the examples">
<mkdir dir="${build}" />
+ <property name="no.aspectj" value="true" />
+ <antcall target="dist" />
+
<path id="emma.lib">
<pathelement location="${emma.dir}/emma.jar" />
<pathelement location="${emma.dir}/emma_ant.jar" />
@@ -406,7 +421,7 @@
</emma>
</target>
- <target name="test-emma" depends="instrument">
+ <target name="-test-emma" depends="-emma-instrument">
<mkdir dir="${junit.results}" />
<path id="test.classpath">
<path refid="project.build.classpath" />
@@ -420,7 +435,6 @@
<jvmarg value="-Demma.coverage.out.merge=true" />
<classpath refid="test.classpath" />
<formatter type="plain" />
- <formatter type="xml" />
<test name="com.mysql.management.AllTestsSuite" />
@@ -433,7 +447,7 @@
</junit>
</target>
- <target name="test-emma-report" depends="test-emma">
+ <target name="test-emma-report" depends="-test-emma">
<emma enabled="true">
<report sourcepath="${src}">
<fileset dir="${emma.coverage.dir}">
Modified: trunk/connector-mxj/src/com/mysql/management/MysqldResource.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/MysqldResource.java 2006-05-12 14:23:00
UTC (rev 48)
+++ trunk/connector-mxj/src/com/mysql/management/MysqldResource.java 2006-05-16 02:43:57
UTC (rev 49)
@@ -20,12 +20,17 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.PrintStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import com.mysql.jdbc.Driver;
+import com.mysql.jdbc.MysqlErrorNumbers;
import com.mysql.management.util.CommandLineOptionsParser;
import com.mysql.management.util.Files;
import com.mysql.management.util.ListToString;
@@ -152,10 +157,6 @@
// printMessage("mysqld : " +
// services.str().toString(mysqldArgs.entrySet()));
out.flush();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ByteArrayOutputStream baes = new ByteArrayOutputStream();
- TeeOutputStream teeOutStream = new TeeOutputStream(out, baos);
- TeeOutputStream teeErrStream = new TeeOutputStream(err, baes);
addCompletionListenser(new Runnable() {
public void run() {
setReadyForConnection(false);
@@ -163,28 +164,49 @@
completionListensers.remove(this);
}
});
- PrintStream psOut = new PrintStream(teeOutStream);
- PrintStream psErr = new PrintStream(teeErrStream);
- setShell(exec(threadName, mysqldArgs, psOut, psErr, true));
- long launchtime = System.currentTimeMillis();
+ setShell(exec(threadName, mysqldArgs, out, err, true));
reportPid();
- boolean ready = false;
- long giveUp = launchtime + killDelay;
- while (!ready && (System.currentTimeMillis() < giveUp)) {
- String lookFor = "ready for connections";
- String lookIn1 = baos.toString();
- String lookIn2 = baes.toString();
- ready = utils.str().containsIgnoreCase(lookIn1, lookFor);
- ready |= utils.str().containsIgnoreCase(lookIn2, lookFor);
- utils.threads().pause(100);
+ int port = 3306;
+ Object portArg = mysqldArgs.get(MysqldResourceI.PORT);
+ if (portArg != null) {
+ port = Integer.parseInt(portArg.toString());
}
- teeOutStream.nullStreamTwo();
- teeErrStream.nullStreamTwo();
+ int triesBeforeGivingUp = (killDelay / 1000) * 4;
+ boolean ready = canConnectToServer(port, triesBeforeGivingUp);
setReadyForConnection(ready);
}
+ boolean canConnectToServer(int port, int triesBeforeGivingUp) {
+ utils.str().classForName(Driver.class.getName());
+ Connection conn = null;
+ int timeoutMilis = 250;
+ String bogusUser = "Connector/MXJ";
+ String password = "Bogus Password";
+ String url = "jdbc:mysql://localhost:" + port + "/test"
+ + "?connectTimeout=" + timeoutMilis;
+ for (int i = 0; i < triesBeforeGivingUp; i++) {
+ try {
+ conn = DriverManager.getConnection(url, bogusUser, password);
+ return true; /* should never happen */
+ } catch (SQLException e) {
+ if (e.getErrorCode() == MysqlErrorNumbers.ER_ACCESS_DENIED_ERROR) {
+ return true;
+ }
+ } finally {
+ try {
+ if (conn != null) {
+ conn.close();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ return false;
+ }
+
private void setReadyForConnection(boolean ready) {
readyForConnections = ready;
}
@@ -195,8 +217,7 @@
private void reportPid() {
boolean printed = false;
- long giveUp = System.currentTimeMillis() + 3000;
- while (!printed && (System.currentTimeMillis() < giveUp)) {
+ for (int i = 0; !printed && i < 50; i++) {
if (pidFile().exists() && pidFile().length() > 0) {
utils.threads().pause(25);
printMessage("mysqld running as process: " + pid());
@@ -562,7 +583,7 @@
params.remove("help");
params.remove("verbose");
- utils.threads().pause(100);
+ utils.threads().pause(500);
capturedOut.flush();
capturedOut.close(); // should flush();
Modified: trunk/connector-mxj/src/com/mysql/management/MysqldResourceTest.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/MysqldResourceTest.java 2006-05-12
14:23:00 UTC (rev 48)
+++ trunk/connector-mxj/src/com/mysql/management/MysqldResourceTest.java 2006-05-16
02:43:57 UTC (rev 49)
@@ -347,6 +347,12 @@
setSytemPropertiesToLinux();
assertEquals("share_dir.jar", mysqldResource.shareJar());
}
+
+ public void testCanConnectToServer() {
+ assertFalse(mysqldResource.canConnectToServer(testUtil.testPort(), 1));
+ startMysql("testCanConnectToServer");
+ assertTrue(mysqldResource.canConnectToServer(testUtil.testPort(), 1));
+ }
// -------------------
private static class TestFileUtil extends Files {
Modified: trunk/connector-mxj/src/com/mysql/management/util/Str.java
===================================================================
--- trunk/connector-mxj/src/com/mysql/management/util/Str.java 2006-05-12 14:23:00 UTC
(rev 48)
+++ trunk/connector-mxj/src/com/mysql/management/util/Str.java 2006-05-16 02:43:57 UTC
(rev 49)
@@ -6,6 +6,8 @@
import java.util.ArrayList;
import java.util.List;
+import com.mysql.management.util.Exceptions.Block;
+
/*
Copyright (C) 2004 MySQL AB
@@ -76,6 +78,18 @@
}
/**
+ * wrapper method for Class.forName(string) which converts
+ * ClassNotFoundException to RuntimeException
+ */
+ public Class classForName(final String className) {
+ return (Class) new Exceptions.Block() {
+ protected Object inner() throws ClassNotFoundException {
+ return Class.forName(className);
+ }
+ }.exec();
+ }
+
+ /**
* returns an array of strings as read via a StringReader
*/
public String[] splitLines(String str) {
| Thread |
|---|
| • Connector/MXJ commit: r49 - in trunk/connector-mxj: . src/com/mysql/management src/com/mysql/management/util | eherman | 16 May |