Skip to content

Commit

Permalink
Fix check for rte response from pmux
Browse files Browse the repository at this point in the history
Signed-off-by: Rivers Zhang <[email protected]>
  • Loading branch information
riverszhang89 committed Dec 23, 2024
1 parent c962f15 commit 615253f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 23 deletions.
5 changes: 4 additions & 1 deletion cdb2jdbc/src/main/java/com/bloomberg/comdb2/jdbc/SockIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ public boolean open() {
/* Errors are handled by the catch block below. */
out.write(rtepacket.getBytes());
out.flush();
readLine(32);
/* empty string: success */
String ret = readLine(32);
if (!ret.equals("0"))
throw new IOException("could not route connection");
}
} catch (IOException e) {
opened = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ public void testPmuxDown() throws IOException, SQLException {

String db = System.getProperty("cdb2jdbc.test.database");
String cluster = System.getProperty("cdb2jdbc.test.cluster");
Connection conn = DriverManager.getConnection(
String.format("jdbc:comdb2://%s/%s?portmuxport=8888", cluster, db));
/* This line would succeed, because the driver would use the pmuxport for single-port */
Connection conn1 = DriverManager.getConnection(
String.format("jdbc:comdb2://%s/%s?portmuxport=8888&allow_pmux_route=1", cluster, db));
conn1.close();
/* This line would fail, because the driver would attempt to query port 8888 for db port */
Connection conn2 = DriverManager.getConnection(
String.format("jdbc:comdb2://%s/%s?portmuxport=8888&allow_pmux_route=0", cluster, db));
Assert.assertTrue("Should not reach here", false);
} catch (SQLException sqle) {
Assert.assertTrue("Should see correct error message.",
Expand Down Expand Up @@ -69,21 +74,28 @@ public void testComdb2dbMachineOffline() throws IOException, SQLException {

@Test
public void testComdb2dbNodeDown() throws IOException, SQLException {
LogManager.getLogManager().reset();
String fname = "/tmp/comdb2db.jdbc.mvn.test.cfg." + System.currentTimeMillis();
String cluster = System.getProperty("cdb2jdbc.test.cluster");
BufferedWriter writer = new BufferedWriter(new FileWriter(fname));
writer.write("does_not_exist 0 ");
writer.write(cluster);
writer.close();
System.setProperty("comdb2db.cfg", fname);
try {
LogManager.getLogManager().reset();
String fname = "/tmp/comdb2db.jdbc.mvn.test.cfg." + System.currentTimeMillis();
String cluster = System.getProperty("cdb2jdbc.test.cluster");
BufferedWriter writer = new BufferedWriter(new FileWriter(fname));
writer.write("does_not_exist 0 ");
writer.write(cluster);
writer.close();
System.setProperty("comdb2db.cfg", fname);
Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/db?comdb2dbname=does_not_exist");
Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/db?comdb2dbname=does_not_exist&allow_pmux_route=0");
Assert.assertTrue("Should not reach here", false);
} catch (SQLException sqle) {
Assert.assertTrue("Should see correct error message.",
sqle.getMessage().contains("Received invalid port from pmux"));
}
try {
Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/db?comdb2dbname=does_not_exist&allow_pmux_route=1");
Assert.assertTrue("Should not reach here", false);
} catch (SQLException sqle) {
Assert.assertTrue("Should see correct error message.",
sqle.getMessage().contains("A network I/O error occurred"));
}
}

@Test
Expand Down Expand Up @@ -128,24 +140,32 @@ public void testMalformedComdb2db() throws IOException, SQLException {

@Test
public void testDbDown() throws IOException, SQLException {
try {
LogManager.getLogManager().reset();
LogManager.getLogManager().reset();

String cluster = System.getProperty("cdb2jdbc.test.cluster");
String fname = "/tmp/comdb2db.jdbc.mvn.test.cfg." + System.currentTimeMillis();
BufferedWriter writer = new BufferedWriter(new FileWriter(fname));
writer.write("does_not_exist");
writer.write(" 0 ");
writer.write(cluster);
writer.close();
System.setProperty("comdb2db.cfg", fname);
String cluster = System.getProperty("cdb2jdbc.test.cluster");
String fname = "/tmp/comdb2db.jdbc.mvn.test.cfg." + System.currentTimeMillis();
BufferedWriter writer = new BufferedWriter(new FileWriter(fname));
writer.write("does_not_exist");
writer.write(" 0 ");
writer.write(cluster);
writer.close();
System.setProperty("comdb2db.cfg", fname);

Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/does_not_exist?max_retries=1");
try {
Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/does_not_exist?max_retries=1&allow_pmux_route=0");
Assert.assertTrue("Should not reach here", false);
} catch (SQLException sqle) {
Assert.assertTrue("Should see correct error message.",
sqle.getMessage().contains("Received invalid port from pmux."));
}

try {
Connection conn = DriverManager.getConnection("jdbc:comdb2://dev/does_not_exist?max_retries=1&allow_pmux_route=1");
Assert.assertTrue("Should not reach here", false);
} catch (SQLException sqle) {
Assert.assertTrue("Should see correct error message.",
sqle.getMessage().contains("A network I/O error occurred"));
}
}

@Test
Expand Down

0 comments on commit 615253f

Please sign in to comment.