Skip to content
Permalink
Browse files

test: assume integer datetimes for timestamp tests (#873)

Float timestamp equality comparisons like comparisons with any float
are problematic if they don't take into account their imprecise
nature. Some timestamp tests produce false negative failures for
servers compiled with float timestamps. Use JUnit assumptions to skip
these tests if the server doesn't have integer datetimes.

This addresses #12 in part in
that it omits (most of) the failing tests, though it leaves these
timestamp behaviors untested under float timestamps, which was the
default prior to PostgreSQL 8.4.
  • Loading branch information
grzm authored and vlsi committed Jul 24, 2017
1 parent ed0014c commit 8287e7f92f890a41f8d2b51980157a92e1cd57e8
@@ -664,6 +664,16 @@ public static boolean haveMinimumJVMVersion(String version) {
return (jvm.compareTo(version) >= 0);
}

public static boolean haveIntegerDateTimes(Connection con) {
if (con == null) {
throw new NullPointerException("Connection is null");
}
if (con instanceof PgConnection) {
return ((PgConnection) con).getQueryExecutor().getIntegerDateTimes();
}
return false;
}

/**
* Print a ResultSet to System.out. This is useful for debugging tests.
*/
@@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.postgresql.test.TestUtil;
import org.postgresql.util.PGInterval;
@@ -54,6 +55,8 @@ public void tearDown() throws SQLException {
*/
@Test
public void testTimeWithInterval() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

Calendar cal = Calendar.getInstance();
cal.set(1970, 0, 1);

@@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.postgresql.test.TestUtil;
import org.postgresql.util.PGInterval;
@@ -58,6 +59,7 @@ public void tearDown() throws Exception {
*/
@Test
public void testTimestampWithInterval() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));
PGTimestamp timestamp = new PGTimestamp(System.currentTimeMillis());
PGInterval interval = new PGInterval(0, 0, 0, 1, 2, 3.14);
verifyTimestampWithInterval(timestamp, interval, true);
@@ -9,6 +9,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;

import org.postgresql.PGStatement;
import org.postgresql.core.BaseConnection;
@@ -174,6 +175,8 @@ private void runInfinityTests(String table, long value) throws SQLException {
*/
@Test
public void testGetTimestampWTZ() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

Statement stmt = con.createStatement();
TimestampUtils tsu = ((BaseConnection) con).getTimestampUtils();

@@ -235,6 +238,8 @@ public void testGetTimestampWTZ() throws SQLException {
*/
@Test
public void testSetTimestampWTZ() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

Statement stmt = con.createStatement();
PreparedStatement pstmt = con.prepareStatement(TestUtil.insertSQL(TSWTZ_TABLE, "?"));

@@ -305,6 +310,8 @@ public void testSetTimestampWTZ() throws SQLException {
*/
@Test
public void testGetTimestampWOTZ() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

Statement stmt = con.createStatement();
TimestampUtils tsu = ((BaseConnection) con).getTimestampUtils();

@@ -385,6 +392,8 @@ public void testGetTimestampWOTZ() throws SQLException {
*/
@Test
public void testSetTimestampWOTZ() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

Statement stmt = con.createStatement();
PreparedStatement pstmt = con.prepareStatement(TestUtil.insertSQL(TSWOTZ_TABLE, "?"));

@@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.postgresql.test.TestUtil;
import org.postgresql.test.jdbc2.BaseTest4;
@@ -164,6 +165,8 @@ public void testGetLocalTimeInvalidType() throws SQLException {
*/
@Test
public void testGetLocalDateTime() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

List<String> zoneIdsToTest = new ArrayList<String>();
zoneIdsToTest.add("Africa/Casablanca"); // It is something like GMT+0..GMT+1
zoneIdsToTest.add("America/Adak"); // It is something like GMT-10..GMT-9
@@ -8,6 +8,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.postgresql.test.TestUtil;

@@ -279,6 +280,8 @@ private void offsetTimestamps(ZoneId dataZone, LocalDateTime localDateTime, Stri
*/
@Test
public void testSetLocalDateTimeBc() throws SQLException {
assumeTrue(TestUtil.haveIntegerDateTimes(con));

// use BC for funsies
List<LocalDateTime> bcDates = new ArrayList<LocalDateTime>();
bcDates.add(LocalDateTime.parse("1997-06-30T23:59:59.999999").with(ChronoField.ERA, IsoEra.BCE.getValue()));

0 comments on commit 8287e7f

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