Permalink
Browse files

refactor: remove useless checks in the tests

remove useless checks for protocol version in the tests.
  • Loading branch information...
AlexElin authored and vlsi committed Jul 23, 2017
1 parent e960f23 commit 0221f930b35a6f24e539ac4740886fafaebcaeac
@@ -664,18 +664,6 @@ public static boolean haveMinimumJVMVersion(String version) {
return (jvm.compareTo(version) >= 0);
}

@Deprecated
public static boolean isProtocolVersion(Connection con, int version) {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return (version == ((PgConnection) con).getProtocolVersion());

}
return false;
}

/**
* Print a ResultSet to System.out. This is useful for debugging tests.
*/
@@ -159,13 +159,11 @@ public void testGetInt() throws Throwable {
@Test
public void testGetShort() throws Throwable {
assumeCallableStatementsSupported();
if (TestUtil.isProtocolVersion(con, 3)) {
CallableStatement call = con.prepareCall(func + pkgName + "getShort (?) }");
call.setShort(2, (short) 4);
call.registerOutParameter(1, Types.SMALLINT);
call.execute();
assertEquals(42, call.getShort(1));
}
CallableStatement call = con.prepareCall(func + pkgName + "getShort (?) }");
call.setShort(2, (short) 4);
call.registerOutParameter(1, Types.SMALLINT);
call.execute();
assertEquals(42, call.getShort(1));
}

@Test
@@ -125,10 +125,8 @@ public static TestSuite suite() throws Exception {
suite.addTest(new JUnit4TestAdapter(V3ParameterListTests.class));

Connection conn = TestUtil.openDB();
if (TestUtil.isProtocolVersion(conn, 3)) {
suite.addTest(new JUnit4TestAdapter(CopyTest.class));
suite.addTest(new JUnit4TestAdapter(CopyLargeFileTest.class));
}
suite.addTest(new JUnit4TestAdapter(CopyTest.class));
suite.addTest(new JUnit4TestAdapter(CopyLargeFileTest.class));

if (TestUtil.haveMinimumServerVersion(conn, ServerVersion.v9_3)) {
suite.addTest(new JUnit4TestAdapter(ServerErrorTest.class));
@@ -52,7 +52,7 @@ public void testNotify() throws SQLException {

@Test(timeout = 60000)
public void testNotifyArgument() throws Exception {
if (!TestUtil.haveMinimumServerVersion(conn, ServerVersion.v9_0) || TestUtil.isProtocolVersion(conn, 2)) {
if (!TestUtil.haveMinimumServerVersion(conn, ServerVersion.v9_0)) {
return;
}

@@ -143,15 +143,6 @@ public void testExecuteStringOnPreparedStatement() throws Exception {

@Test
public void testBinaryStreamErrorsRestartable() throws SQLException {
// The V2 protocol does not have the ability to recover when
// streaming data to the server. We could potentially try
// introducing a syntax error to force the query to fail, but
// that seems dangerous.
//
if (!TestUtil.isProtocolVersion(con, 3)) {
return;
}

byte buf[] = new byte[10];
for (int i = 0; i < buf.length; i++) {
buf[i] = (byte) i;
@@ -1169,15 +1160,13 @@ public void testSetObjectNumberFallbackWithAtomicLong() throws SQLException {
public void testUnknownSetObject() throws SQLException {
PreparedStatement pstmt = con.prepareStatement("INSERT INTO intervaltable(i) VALUES (?)");

if (TestUtil.isProtocolVersion(con, 3)) {
pstmt.setString(1, "1 week");
try {
pstmt.executeUpdate();
assertTrue("When using extended protocol, interval vs character varying type mismatch error is expected",
preferQueryMode == PreferQueryMode.SIMPLE);
} catch (SQLException sqle) {
// ERROR: column "i" is of type interval but expression is of type character varying
}
pstmt.setString(1, "1 week");
try {
pstmt.executeUpdate();
assertTrue("When using extended protocol, interval vs character varying type mismatch error is expected",
preferQueryMode == PreferQueryMode.SIMPLE);
} catch (SQLException sqle) {
// ERROR: column "i" is of type interval but expression is of type character varying
}

pstmt.setObject(1, "1 week", Types.OTHER);
@@ -88,10 +88,8 @@ private void runStandardTests(ResultSetMetaData rsmd) throws SQLException {

assertEquals("a", rsmd.getColumnName(1));
assertEquals("oid", rsmd.getColumnName(5));
if (TestUtil.isProtocolVersion(conn, 3)) {
assertEquals("", pgrsmd.getBaseColumnName(4));
assertEquals("b", pgrsmd.getBaseColumnName(6));
}
assertEquals("", pgrsmd.getBaseColumnName(4));
assertEquals("b", pgrsmd.getBaseColumnName(6));

assertEquals(Types.INTEGER, rsmd.getColumnType(1));
assertEquals(Types.VARCHAR, rsmd.getColumnType(2));
@@ -105,25 +103,17 @@ private void runStandardTests(ResultSetMetaData rsmd) throws SQLException {

assertEquals("", rsmd.getSchemaName(1));
assertEquals("", rsmd.getSchemaName(4));
if (TestUtil.isProtocolVersion(conn, 3)) {
assertEquals("public", pgrsmd.getBaseSchemaName(1));
assertEquals("", pgrsmd.getBaseSchemaName(4));
}
assertEquals("public", pgrsmd.getBaseSchemaName(1));
assertEquals("", pgrsmd.getBaseSchemaName(4));

assertEquals("rsmd1", rsmd.getTableName(1));
assertEquals("", rsmd.getTableName(4));
if (TestUtil.isProtocolVersion(conn, 3)) {
assertEquals("rsmd1", pgrsmd.getBaseTableName(1));
assertEquals("", pgrsmd.getBaseTableName(4));
}
assertEquals("rsmd1", pgrsmd.getBaseTableName(1));
assertEquals("", pgrsmd.getBaseTableName(4));

if (TestUtil.isProtocolVersion(conn, 3)) {
assertEquals(ResultSetMetaData.columnNoNulls, rsmd.isNullable(1));
assertEquals(ResultSetMetaData.columnNullable, rsmd.isNullable(2));
assertEquals(ResultSetMetaData.columnNullableUnknown, rsmd.isNullable(4));
} else {
assertEquals(ResultSetMetaData.columnNullableUnknown, rsmd.isNullable(1));
}
assertEquals(ResultSetMetaData.columnNoNulls, rsmd.isNullable(1));
assertEquals(ResultSetMetaData.columnNullable, rsmd.isNullable(2));
assertEquals(ResultSetMetaData.columnNullableUnknown, rsmd.isNullable(4));
}

// verify that a prepared update statement returns no metadata and doesn't execute.
@@ -205,12 +195,10 @@ public void testIsAutoIncrement() throws SQLException {
ResultSetMetaData rsmd = rs.getMetaData();

assertTrue(!rsmd.isAutoIncrement(1));
if (TestUtil.isProtocolVersion(conn, 3)) {
assertTrue(rsmd.isAutoIncrement(2));
assertTrue(rsmd.isAutoIncrement(3));
assertEquals("bigserial", rsmd.getColumnTypeName(2));
assertEquals("serial", rsmd.getColumnTypeName(3));
}
assertTrue(rsmd.isAutoIncrement(2));
assertTrue(rsmd.isAutoIncrement(3));
assertEquals("bigserial", rsmd.getColumnTypeName(2));
assertEquals("serial", rsmd.getColumnTypeName(3));

rs.close();
stmt.close();
@@ -41,10 +41,6 @@ public void tearDown() throws SQLException {

@Test
public void testParameterMD() throws SQLException {
if (!TestUtil.isProtocolVersion(con, 3)) {
return;
}

PreparedStatement pstmt =
con.prepareStatement("SELECT a FROM parametertest WHERE b = ? AND c = ? AND d >^ ? ");
ParameterMetaData pmd = pstmt.getParameterMetaData();
@@ -65,10 +61,6 @@ public void testParameterMD() throws SQLException {

@Test
public void testFailsOnBadIndex() throws SQLException {
if (!TestUtil.isProtocolVersion(con, 3)) {
return;
}

PreparedStatement pstmt =
con.prepareStatement("SELECT a FROM parametertest WHERE b = ? AND c = ?");
ParameterMetaData pmd = pstmt.getParameterMetaData();
@@ -87,10 +79,6 @@ public void testFailsOnBadIndex() throws SQLException {
// Make sure we work when mashing two queries into a single statement.
@Test
public void testMultiStatement() throws SQLException {
if (!TestUtil.isProtocolVersion(con, 3)) {
return;
}

PreparedStatement pstmt = con.prepareStatement(
"SELECT a FROM parametertest WHERE b = ? AND c = ? ; SELECT b FROM parametertest WHERE a = ?");
ParameterMetaData pmd = pstmt.getParameterMetaData();
@@ -113,10 +101,6 @@ public void testMultiStatement() throws SQLException {
//
@Test
public void testTypeChangeWithUnknown() throws SQLException {
if (!TestUtil.isProtocolVersion(con, 3)) {
return;
}

PreparedStatement pstmt =
con.prepareStatement("SELECT a FROM parametertest WHERE c = ? AND e = ?");
ParameterMetaData pmd = pstmt.getParameterMetaData();

0 comments on commit 0221f93

Please sign in to comment.