Skip to content
Permalink
Browse files

test: ignore tests that don't apply to Pg8.2 and Pg8.3 (#703)

  • Loading branch information
jorsol authored and davecramer committed Dec 22, 2016
1 parent 7881e41 commit 3bc0951e84ad3b7af746e2dece04b4ea816605e2
@@ -60,12 +60,6 @@ matrix:
- COVERAGE=Y
- NO_HSTORE=Y
- CREATE_PLPGSQL=Y
- env: # this has to match the environment for 8.3 below
- PG_VERSION=8.3
- XA=true
- COVERAGE=Y
- NO_HSTORE=Y
- CREATE_PLPGSQL=Y
include:
- env:
- FEDORA_CI=Y
@@ -327,6 +327,11 @@ public void testChangeDateStyle() throws SQLException {
}

public void testLockReleaseOnCancelFailure() throws SQLException, InterruptedException {
if (!TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_4)) {
// pg_backend_pid() requires PostgreSQL 8.4+
return;
}

// This is a fairly complex test because it is testing a
// deadlock that only occurs when the connection to postgres
// is broken during a copy operation. We'll start a copy
@@ -26,9 +26,8 @@
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/*
* TestCase to test the internal functionality of org.postgresql.jdbc2.DatabaseMetaData
@@ -52,9 +51,9 @@ public void setUp() throws Exception {
TestUtil.createCompositeType(con, "custom", "i int");
TestUtil.createCompositeType(con, "_custom", "f float");

// 8.2 does not support _custom[]. ERROR: type "_custom[]" does not exist
TestUtil.createTable(con, "customtable", "c1 custom, c2 _custom, c3 custom[]"
+ (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3) ? ", c4 _custom[]" : ""));
// 8.2 does not support arrays of composite types
TestUtil.createTable(con, "customtable", "c1 custom, c2 _custom"
+ (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3) ? ", c3 custom[], c4 _custom[]" : ""));

Statement stmt = con.createStatement();
// we add the following comments to ensure the joins to the comments
@@ -143,21 +142,21 @@ public void testCustomArrayTypeInfo() throws SQLException {
assertEquals("custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("_custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3)) {
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("___custom", res.getString("TYPE_NAME"));
}
con.createArrayOf("custom", new Object[] {});
res = dbmd.getColumns(null, null, "customtable", null);
assertTrue(res.next());
assertEquals("custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("_custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3)) {
con.createArrayOf("custom", new Object[]{});
res = dbmd.getColumns(null, null, "customtable", null);
assertTrue(res.next());
assertEquals("custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("_custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("__custom", res.getString("TYPE_NAME"));
assertTrue(res.next());
assertEquals("___custom", res.getString("TYPE_NAME"));
}
@@ -1103,73 +1102,66 @@ public void testGetUDT4() throws Exception {
}
}

// these all work from 9.1 on. Not meant to be exhaustive, but it's better than nothing.
private String[] typeArray = new String[]{
"bool",
"bytea",
"char",
"name",
"int8",
"int2",
"int2vector",
"int4",
"text",
"oid",
"tid",
"xid",
"cid",
"oidvector",
"xml",
"point",
"lseg",
"path",
"box",
"polygon",
"line",
"float4",
"float8",
"abstime",
"reltime",
"tinterval",
"unknown",
"circle",
"money",
"macaddr",
"inet",
"cidr",
"aclitem",
"bpchar",
"varchar",
"date",
"time",
"timestamp",
"timestamptz",
"interval",
"timetz",
"bit",
"varbit",
"numeric",
"refcursor",
"uuid",
"tsvector",
"gtsvector",
"tsquery",
"any",
"anyarray",
"void",
};

@Test
public void testTypes() throws SQLException {
// https://www.postgresql.org/docs/8.2/static/datatype.html
List<String> stringTypeList = new ArrayList<String>();
stringTypeList.addAll(Arrays.asList(new String[]{
"bit",
"bool",
"box",
"bytea",
"char",
"cidr",
"circle",
"date",
"float4",
"float8",
"inet",
"int2",
"int4",
"int8",
"interval",
"line",
"lseg",
"macaddr",
"money",
"numeric",
"path",
"point",
"polygon",
"text",
"time",
"timestamp",
"timestamptz",
"timetz",
"varbit",
"varchar"
}));
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_3)) {
stringTypeList.add("tsquery");
stringTypeList.add("tsvector");
stringTypeList.add("txid_snapshot");
stringTypeList.add("uuid");
stringTypeList.add("xml");
}
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_2)) {
stringTypeList.add("json");
}
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_4)) {
stringTypeList.add("jsonb");
stringTypeList.add("pg_lsn");
}

DatabaseMetaData dbmd = con.getMetaData();
ResultSet rs = dbmd.getTypeInfo();
Map<String, Boolean> types = new HashMap<String, Boolean>();
List<String> types = new ArrayList<String>();

while (rs.next()) {
types.put(rs.getString("TYPE_NAME"), true);
types.add(rs.getString("TYPE_NAME"));
}
for (String typeName : typeArray) {
assertTrue(types.containsKey(typeName));
for (String typeName : stringTypeList) {
assertTrue(types.contains(typeName));
}

}
@@ -10,10 +10,12 @@
import static org.junit.Assert.fail;

import org.postgresql.PGConnection;
import org.postgresql.core.ServerVersion;
import org.postgresql.ds.PGConnectionPoolDataSource;
import org.postgresql.jdbc2.optional.ConnectionPool;
import org.postgresql.test.TestUtil;

import org.junit.Assume;
import org.junit.Test;

import java.io.ByteArrayInputStream;
@@ -323,6 +325,10 @@ public void testBackendIsClosed() throws Exception {
PooledConnection pc = getPooledConnection();
con = pc.getConnection();
assertTrue(!con.isClosed());

Assume.assumeTrue("pg_terminate_backend requires PostgreSQL 8.4+",
TestUtil.haveMinimumServerVersion(con, ServerVersion.v8_4));

int pid = ((PGConnection) con).getBackendPID();

Connection adminCon = TestUtil.openPrivilegedDB();
@@ -31,7 +31,7 @@ protected boolean setUp(String stringType) throws Exception {
props.put("stringtype", stringType);
}
_conn = TestUtil.openDB(props);
if (TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v8_3)) {
if (!TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v8_3)) {
return false;
}
TestUtil.createEnumType(_conn, "mood", "'happy', 'sad'");
@@ -327,6 +327,9 @@ public void testSetObjectFromJavaArray() throws SQLException {

@Test
public void testGetArrayOfComposites() throws SQLException {
Assume.assumeTrue("array_agg(expression) requires PostgreSQL 8.4+",
TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v8_4));

PreparedStatement insert_parent_pstmt =
_conn.prepareStatement("INSERT INTO arrcompprnttest (name) "
+ "VALUES ('aParent');");
@@ -392,6 +395,9 @@ public void testGetArrayOfComposites() throws SQLException {

@Test
public void testCasingComposite() throws SQLException {
Assume.assumeTrue("Arrays of composite types requires PostgreSQL 8.3+",
TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v8_3));

PGobject cc = new PGobject();
cc.setType("\"CorrectCasing\"");
cc.setValue("(1)");
@@ -439,6 +445,9 @@ public void testCasingBuiltinNonAlias() throws SQLException {

@Test
public void testEvilCasing() throws SQLException {
Assume.assumeTrue("Arrays of composite types requires PostgreSQL 8.3+",
TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v8_3));

PGobject cc = new PGobject();
cc.setType("\"Evil.Table\"");
cc.setValue("(1)");

0 comments on commit 3bc0951

Please sign in to comment.
You can’t perform that action at this time.