Skip to content
Permalink
Browse files
test: PostgreSQL 8.4 and 9.5 databases, XA configuration
closes #499
  • Loading branch information
vlsi committed Jan 28, 2016
1 parent 61384ec commit 8c9898af9d6ab21f2a727cc2f673519d2c4352c7
@@ -2,9 +2,12 @@ sudo: false
language: java

before_script:
- test "x$XA" == 'x' || ./travis_install_dependencies.sh
- psql -U postgres -c "create user test with password 'test';"
- psql -c 'create database test owner test;' -U postgres
- echo "MAVEN_OPTS='-Xmx1g -Dgpg.skip=true'" > ~/.mavenrc
- test "x$PG_VERSION" == 'x' || test $PG_VERSION == '8.4' || test $PG_VERSION == '9.0' || psql test -c 'CREATE EXTENSION hstore;' -U postgres
- test "x$PG_VERSION" == 'x' || test $PG_VERSION != '8.4' || createlang -U postgres plpgsql test

env:
global:
@@ -38,6 +41,20 @@ cache:
matrix:
fast_finish: true
include:
- jdk: oraclejdk8
sudo: required
dist: trusty
env:
- PG_VERSION=9.5
- XA=true
- COVERAGE=Y
- jdk: oraclejdk8
sudo: required
dist: trusty
env:
- PG_VERSION=8.4
- XA=true
- COVERAGE=Y
- jdk: oraclejdk8
env: RUN_CHECKSTYLE=true
script: cd pgjdbc && mvn checkstyle:check
@@ -71,6 +71,7 @@ protected void setUp() throws Exception {
} finally {
st.close();
}
TestUtil.closeDB(privilegedCon);

con.setAutoCommit(false);
con2.setAutoCommit(false);
@@ -13,6 +13,7 @@
import org.postgresql.copy.CopyManager;
import org.postgresql.copy.CopyOut;
import org.postgresql.copy.PGCopyOutputStream;
import org.postgresql.core.ServerVersion;
import org.postgresql.test.TestUtil;
import org.postgresql.util.PSQLState;

@@ -38,6 +39,7 @@

private Connection con;
private CopyManager copyAPI;
private String copyParams;
// 0's required to match DB output for numeric(5,2)
private String[] origData =
{"First Row\t1\t1.10\n",
@@ -67,6 +69,11 @@ protected void setUp() throws Exception {
TestUtil.createTable(con, "copytest", "stringvalue text, intvalue int, numvalue numeric(5,2)");

copyAPI = ((PGConnection) con).getCopyAPI();
if (TestUtil.haveMinimumServerVersion(con, ServerVersion.v9_0)) {
copyParams = "(FORMAT CSV, HEADER false)";
} else {
copyParams = "CSV";
}
}

protected void tearDown() throws Exception {
@@ -312,7 +319,7 @@ public void testChangeDateStyle() throws SQLException {


// I expect an SQLException
String sql = "COPY copytest FROM STDIN with xxx (format 'csv')";
String sql = "COPY copytest FROM STDIN with xxx " + copyParams;
CopyIn cp = manager.copyIn(sql);
for (int i = 0; i < origData.length; i++) {
byte[] buf = origData[i].getBytes();
@@ -348,7 +355,7 @@ public void testLockReleaseOnCancelFailure() throws SQLException, InterruptedExc
stmt.close();

CopyManager manager = con.unwrap(PGConnection.class).getCopyAPI();
CopyIn copyIn = manager.copyIn("COPY copytest FROM STDIN with (format 'csv')");
CopyIn copyIn = manager.copyIn("COPY copytest FROM STDIN with " + copyParams);
try {
killConnection(pid);
byte[] bunchOfNulls = ",,\n".getBytes();
@@ -66,12 +66,14 @@ public void tearDown() throws SQLException {
*/
public void testDataSourceDisabledSanitiserPropertySucceeds() throws SQLException {
String label = "FOO";
Connection conn = getDataSourceConnection();
PreparedStatement query =
getDataSourceConnection().prepareStatement("select * from allmixedup");
conn.prepareStatement("select * from allmixedup");
if (0 < TestUtil.findColumn(query, label)) {
fail(String.format("Did not expect to find the column with the label [%1$s].", label));
}
query.close();
conn.close();
}

/**
@@ -2,6 +2,7 @@

import org.postgresql.PGConnection;
import org.postgresql.copy.PGCopyInputStream;
import org.postgresql.core.ServerVersion;
import org.postgresql.test.TestUtil;

import junit.framework.TestCase;
@@ -14,6 +15,7 @@
public class PGCopyInputStreamTest extends TestCase {
private Connection _conn;
private PGCopyInputStream sut;
private String copyParams;

public PGCopyInputStreamTest(String name) {
super(name);
@@ -22,6 +24,11 @@ public PGCopyInputStreamTest(String name) {
protected void setUp() throws Exception {
_conn = TestUtil.openDB();
TestUtil.createTable(_conn, "cpinstreamtest", "i int");
if (TestUtil.haveMinimumServerVersion(_conn, ServerVersion.v9_0)) {
copyParams = "(FORMAT CSV, HEADER false)";
} else {
copyParams = "CSV";
}
}

protected void tearDown() throws SQLException {
@@ -34,7 +41,7 @@ public void testReadBytesCorrectlyHandlesEof() throws SQLException, IOException
insertSomeData();

sut = new PGCopyInputStream((PGConnection) _conn,
"COPY cpinstreamtest (i) TO STDOUT WITH (FORMAT CSV, HEADER false)");
"COPY cpinstreamtest (i) TO STDOUT WITH " + copyParams);

byte[] buf = new byte[100]; // large enough to read everything on the next step
assertTrue(sut.read(buf) > 0);
@@ -46,7 +53,7 @@ public void testReadBytesCorrectlyReadsDataInChunks() throws SQLException, IOExc
insertSomeData();

sut = new PGCopyInputStream((PGConnection) _conn,
"COPY (select i from cpinstreamtest order by i asc) TO STDOUT WITH (FORMAT CSV, HEADER false)");
"COPY (select i from cpinstreamtest order by i asc) TO STDOUT WITH " + copyParams);

byte[] buf = new byte[2]; // small enough to read in multiple chunks
StringBuilder result = new StringBuilder(100);
@@ -64,7 +71,7 @@ public void testStreamCanBeClosedAfterReadUp() throws SQLException, IOException
insertSomeData();

sut = new PGCopyInputStream((PGConnection) _conn,
"COPY (select i from cpinstreamtest order by i asc) TO STDOUT WITH (FORMAT CSV, HEADER false)");
"COPY (select i from cpinstreamtest order by i asc) TO STDOUT WITH " + copyParams);

byte[] buff = new byte[100];
while (sut.read(buff) > 0) {
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
# Adapted from https://github.com/dockyard/reefpoints/blob/master/source/posts/2013-03-29-running-postgresql-9-2-on-travis-ci.md
set -x -e

sudo service postgresql stop
sudo cp /etc/postgresql/9.1/main/pg_hba.conf ./
sudo apt-get remove postgresql libpq-dev libpq5 postgresql-client-common postgresql-common -qq --purge
source /etc/lsb-release
echo "deb http://apt.postgresql.org/pub/repos/apt/ $DISTRIB_CODENAME-pgdg main" > pgdg.list
sudo mv pgdg.list /etc/apt/sources.list.d/
wget --quiet -O - https://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confnew" install postgresql-${PG_VERSION} postgresql-contrib-${PG_VERSION} -qq

if [ ${PG_VERSION} = '8.4' ]
then
sudo sed -i -e 's/port = 5433/port = 5432/g' /etc/postgresql/8.4/main/postgresql.conf
fi

sudo sed -i -e 's/#max_prepared_transactions = 0/max_prepared_transactions = 64/g' /etc/postgresql/${PG_VERSION}/main/postgresql.conf

sudo cp ./pg_hba.conf /etc/postgresql/${PG_VERSION}/main

sudo service postgresql restart ${PG_VERSION}

sudo tail /var/log/postgresql/postgresql-${PG_VERSION}-main.log

0 comments on commit 8c9898a

Please sign in to comment.