Skip to content

Commit

Permalink
DBZ-494 Making tests more lenient towards specific List implementations;
Browse files Browse the repository at this point in the history
also fixing a few typos.
  • Loading branch information
gunnarmorling committed Jan 15, 2018
1 parent 5756f6d commit 5c88431
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.time.Month;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -231,30 +230,24 @@ protected List<SchemaAndValueField> schemaAndValuesForMoneyTypes() {

protected List<SchemaAndValueField> schemasAndValuesForArrayTypes() {
return Arrays.asList(new SchemaAndValueField("int_array", SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build(),
expectedArray(1, 2, 3)),
Arrays.asList(1, 2, 3)),
new SchemaAndValueField("bigint_array", SchemaBuilder.array(Schema.OPTIONAL_INT64_SCHEMA).optional().build(),
expectedArray(1550166368505037572L)),
Arrays.asList(1550166368505037572L)),
new SchemaAndValueField("text_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(),
expectedArray("one", "two", "three")),
Arrays.asList("one", "two", "three")),
new SchemaAndValueField("char_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(),
expectedArray("cone ", "ctwo ", "cthree ")),
Arrays.asList("cone ", "ctwo ", "cthree ")),
new SchemaAndValueField("varchar_array", SchemaBuilder.array(Schema.OPTIONAL_STRING_SCHEMA).optional().build(),
expectedArray("vcone", "vctwo", "vcthree")),
Arrays.asList("vcone", "vctwo", "vcthree")),
new SchemaAndValueField("date_array", SchemaBuilder.array(Date.builder().optional().schema()).optional().build(),
expectedArray(
Arrays.asList(
(int)LocalDate.of(2016, Month.NOVEMBER, 4).toEpochDay(),
(int)LocalDate.of(2016, Month.NOVEMBER, 5).toEpochDay(),
(int)LocalDate.of(2016, Month.NOVEMBER, 6).toEpochDay()
))
);
}

private List<?> expectedArray(Object... elements) {
final ArrayList<Object> list = new ArrayList<>();
list.addAll(Arrays.asList(elements));
return list;
}

protected List<SchemaAndValueField> schemasAndValuesForArrayTypesWithNullValues() {
return Arrays.asList(
new SchemaAndValueField("int_array", SchemaBuilder.array(Schema.OPTIONAL_INT32_SCHEMA).optional().build(), null),
Expand Down Expand Up @@ -396,8 +389,15 @@ private void assertValue(Struct content) {
return;
}
Object actualValue = content.get(fieldName);
assertNotNull("No value found for " + fieldName, actualValue);
assertEquals("Incorrect value type for " + fieldName, value.getClass(), actualValue.getClass());

// assert the value type; for List all implementation types (e.g. immutable ones) are acceptable
if(actualValue instanceof List) {
assertTrue("Incorrect value type for " + fieldName, value instanceof List);
}
else {
assertEquals("Incorrect value type for " + fieldName, value.getClass(), actualValue.getClass());
}

if (actualValue instanceof byte[]) {
assertArrayEquals("Values don't match for " + fieldName, (byte[]) value, (byte[]) actualValue);
} else if (actualValue instanceof Struct) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import io.debezium.doc.FixFor;
import io.debezium.jdbc.TemporalPrecisionMode;
import org.apache.kafka.connect.source.SourceRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import io.debezium.data.Envelope;
import io.debezium.data.VerifyRecord;
import io.debezium.doc.FixFor;
import io.debezium.jdbc.TemporalPrecisionMode;

/**
* Integration test for {@link RecordsSnapshotProducerIT}
Expand Down Expand Up @@ -157,7 +157,7 @@ private void assertReadRecord(SourceRecord record, Map<String, List<SchemaAndVal

@Test
@FixFor("DBZ-342")
public void shouldGenerateSnapshotsForDefaultDatatypesAdpativeMicroseconds() throws Exception {
public void shouldGenerateSnapshotsForDefaultDatatypesAdaptiveMicroseconds() throws Exception {
PostgresConnectorConfig config = new PostgresConnectorConfig(
TestHelper.defaultConfig()
.with(PostgresConnectorConfig.TIME_PRECISION_MODE, TemporalPrecisionMode.ADAPTIVE_TIME_MICROSECONDS)
Expand Down
12 changes: 6 additions & 6 deletions debezium-core/src/main/java/io/debezium/time/Date.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import org.apache.kafka.connect.data.SchemaBuilder;

/**
* A utility for converting various Java temporal object representations into the signed {@link SchemaBuilder#int64() INT64}
* A utility for converting various Java temporal object representations into the signed {@link SchemaBuilder#int32() INT32}
* number of <em>days</em> since January 1, 1970, at 00:00:00UTC, and for defining a Kafka Connect {@link Schema} for date values
* with no time or timezone information.
*
*
* @author Randall Hauch
* @see Timestamp
* @see ZonedTimestamp
Expand All @@ -31,7 +31,7 @@ public class Date {
* <p>
* You can use the resulting SchemaBuilder to set or override additional schema settings such as required/optional, default
* value, and documentation.
*
*
* @return the schema builder
*/
public static SchemaBuilder builder() {
Expand All @@ -44,19 +44,19 @@ public static SchemaBuilder builder() {
* Returns a Schema for a {@link Date} but with all other default Schema settings. The schema describes a field
* with the {@value #SCHEMA_NAME} as the {@link Schema#name() name} and {@link SchemaBuilder#int32() INT32} for the literal
* type storing the number of <em>days</em> since January 1, 1970, at 00:00:00Z.
*
*
* @return the schema
* @see #builder()
*/
public static Schema schema() {
return builder().build();
}

/**
* Get the number of epoch days of the given {@link java.time.LocalDateTime}, {@link java.time.LocalDate},
* {@link java.time.LocalTime}, {@link java.util.Date}, {@link java.sql.Date}, {@link java.sql.Time}, or
* {@link java.sql.Timestamp}, ignoring any time portions of the supplied value.
*
*
* @param value the local or SQL date, time, or timestamp value; may not be null
* @param adjuster the optional component that adjusts the local date value before obtaining the epoch day; may be null if no
* adjustment is necessary
Expand Down

0 comments on commit 5c88431

Please sign in to comment.