DBZ-280 Expanding test

This commit is contained in:
Gunnar Morling 2017-06-08 22:17:29 +02:00
parent 616ba945bf
commit aa4f102ff0
3 changed files with 68 additions and 58 deletions

View File

@ -79,8 +79,8 @@ public abstract class AbstractRecordsProducerTest {
protected static final String INSERT_NUMERIC_TYPES_STMT = "INSERT INTO numeric_table (si, i, bi, d, n, r, db, ss, bs, b) " +
"VALUES (1, 123456, 1234567890123, 1.1, 22.22, 3.3, 4.44, 1, 123, true)";
protected static final String INSERT_TSTZRANGE_TYPES_STMT = "INSERT INTO tstzrange_table (t) " +
"VALUES ('[2017-06-05 11:29:12.549426+00,)')";
protected static final String INSERT_TSTZRANGE_TYPES_STMT = "INSERT INTO tstzrange_table (unbounded_exclusive_range, bounded_inclusive_range) " +
"VALUES ('[2017-06-05 11:29:12.549426+00,)', '[2017-06-05 11:29:12.549426+00, 2017-06-05 12:34:56.789012+00]')";
protected static final Set<String> ALL_STMTS = new HashSet<>(Arrays.asList(INSERT_NUMERIC_TYPES_STMT, INSERT_DATE_TIME_TYPES_STMT,
INSERT_BIN_TYPES_STMT, INSERT_GEOM_TYPES_STMT, INSERT_TEXT_TYPES_STMT,
@ -121,13 +121,21 @@ protected List<SchemaAndValueField> schemaAndValuesForGeomTypes() {
protected List<SchemaAndValueField> schemaAndValuesForTstzRangeTypes() {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSSSSSx");
Instant instant = dateTimeFormatter.parse("2017-06-05 11:29:12.549426+00", Instant::from);
// Acknowledge timezone expectation of the system running the test
String systemTime = dateTimeFormatter.withZone(ZoneId.systemDefault()).format(instant);
String expectedField = String.format("[\"%s\",)",systemTime);
return Collections.singletonList(new SchemaAndValueField("t", Schema.OPTIONAL_STRING_SCHEMA, expectedField));
}
Instant begin = dateTimeFormatter.parse("2017-06-05 11:29:12.549426+00", Instant::from);
Instant end = dateTimeFormatter.parse("2017-06-05 12:34:56.789012+00", Instant::from);
// Acknowledge timezone expectation of the system running the test
String beginSystemTime = dateTimeFormatter.withZone(ZoneId.systemDefault()).format(begin);
String endSystemTime = dateTimeFormatter.withZone(ZoneId.systemDefault()).format(end);
String expectedField1 = String.format("[\"%s\",)", beginSystemTime);
String expectedField2 = String.format("[\"%s\",\"%s\"]", beginSystemTime, endSystemTime);
return Arrays.asList(
new SchemaAndValueField("unbounded_exclusive_range", Schema.OPTIONAL_STRING_SCHEMA, expectedField1),
new SchemaAndValueField("bounded_inclusive_range", Schema.OPTIONAL_STRING_SCHEMA, expectedField2)
);
}
protected List<SchemaAndValueField> schemaAndValuesForBinTypes() {
return Arrays.asList(new SchemaAndValueField("ba", Schema.OPTIONAL_BYTES_SCHEMA, ByteBuffer.wrap(new byte[]{ 1, 2, 3})),

View File

@ -15,6 +15,7 @@
import java.sql.SQLException;
import java.util.Arrays;
import java.util.stream.IntStream;
import org.apache.kafka.connect.data.Decimal;
import org.apache.kafka.connect.data.Field;
import org.apache.kafka.connect.data.Schema;
@ -82,7 +83,8 @@ public void shouldLoadSchemaForBuiltinPostgresTypes() throws Exception {
Json.builder().optional().build(), Json.builder().optional().build(), Xml.builder().optional().build(),
Uuid.builder().optional().build());
assertTableSchema("public.geom_table", "p", Point.builder().optional().build());
assertTableSchema("public.tstzrange_table", "t", Schema.OPTIONAL_STRING_SCHEMA);
assertTableSchema("public.tstzrange_table", "unbounded_exclusive_range, bounded_inclusive_range",
Schema.OPTIONAL_STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA);
}
}

View File

@ -8,4 +8,4 @@ CREATE TABLE bitbin_table (pk SERIAL, ba BYTEA, bol BIT(1), bs BIT(2), bv BIT VA
CREATE TABLE time_table (pk SERIAL, ts TIMESTAMP, tz TIMESTAMPTZ, date DATE, ti TIME, ttz TIME WITH TIME ZONE, it INTERVAL, PRIMARY KEY(pk));
CREATE TABLE text_table (pk SERIAL, j JSON, jb JSONB, x XML, u Uuid, PRIMARY KEY(pk));
CREATE TABLE geom_table (pk SERIAL, p POINT, PRIMARY KEY(pk));
CREATE TABLE tstzrange_table (pk serial, t tstzrange, PRIMARY KEY(pk));
CREATE TABLE tstzrange_table (pk serial, unbounded_exclusive_range tstzrange, bounded_inclusive_range tstzrange, PRIMARY KEY(pk));