Skip to content

Commit 569d303

Browse files
committed
Add codec integration tests for temporal arrays.
[#555] Signed-off-by: Mark Paluch <[email protected]>
1 parent cda70a6 commit 569d303

File tree

1 file changed

+76
-122
lines changed

1 file changed

+76
-122
lines changed

src/test/java/io/r2dbc/postgresql/AbstractCodecIntegrationTests.java

+76-122
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,15 @@ void charPrimitive() {
164164

165165
@Test
166166
void blob() {
167-
BiConsumer<Blob, Blob> equality = (actual, expected) -> Flux.zip(
168-
Flux.from(actual.stream()).reduce(TEST.heapBuffer(), ByteBuf::writeBytes),
169-
Flux.from(expected.stream()).reduce(TEST.heapBuffer(), ByteBuf::writeBytes)
170-
)
171-
.as(StepVerifier::create)
172-
.assertNext(t -> {
173-
try {
174-
assertThat(t.getT1()).isEqualTo(t.getT2());
175-
} finally {
176-
t.getT1().release();
177-
t.getT2().release();
178-
}
179-
})
180-
.verifyComplete();
167+
BiConsumer<Blob, Blob> equality = (actual, expected) -> Flux.zip(Flux.from(actual.stream()).reduce(TEST.heapBuffer(), ByteBuf::writeBytes),
168+
Flux.from(expected.stream()).reduce(TEST.heapBuffer(), ByteBuf::writeBytes)).as(StepVerifier::create).assertNext(t -> {
169+
try {
170+
assertThat(t.getT1()).isEqualTo(t.getT2());
171+
} finally {
172+
t.getT1().release();
173+
t.getT2().release();
174+
}
175+
}).verifyComplete();
181176

182177
Function<byte[], Blob> byteToBlob = (bytes) -> new Blob() {
183178

@@ -209,33 +204,25 @@ void circle() {
209204

210205
@Test
211206
void circleTwoDimensionalArray() {
212-
testCodec(Circle[][].class, new Circle[][]{{Circle.of(Point.of(1.12, 2.12), 3.12), Circle.of(Point.of(Double.MIN_VALUE, Double.MIN_VALUE), Double.MAX_VALUE)},
213-
{Circle.of(Point.of(-2.4, -456.2), 20), null}}, "CIRCLE[][]");
207+
testCodec(Circle[][].class, new Circle[][]{{Circle.of(Point.of(1.12, 2.12), 3.12), Circle.of(Point.of(Double.MIN_VALUE, Double.MIN_VALUE), Double.MAX_VALUE)}, {Circle.of(Point.of(-2.4,
208+
-456.2), 20), null}}, "CIRCLE[][]");
214209
}
215210

216211
@Test
217212
void clob() {
218-
testCodec(Clob.class,
219-
new Clob() {
213+
testCodec(Clob.class, new Clob() {
220214

221-
@Override
222-
public Publisher<Void> discard() {
223-
return Mono.empty();
224-
}
215+
@Override
216+
public Publisher<Void> discard() {
217+
return Mono.empty();
218+
}
225219

226-
@Override
227-
public Publisher<CharSequence> stream() {
228-
return Mono.just("test-value");
229-
}
230-
},
231-
(actual, expected) -> Flux.zip(
232-
Flux.from(actual.stream()).reduce(new StringBuilder(), StringBuilder::append).map(StringBuilder::toString),
233-
Flux.from(expected.stream()).reduce(new StringBuilder(), StringBuilder::append).map(StringBuilder::toString)
234-
)
235-
.as(StepVerifier::create)
236-
.assertNext(t -> assertThat(t.getT1()).isEqualToIgnoringWhitespace(t.getT2()))
237-
.verifyComplete()
238-
, "TEXT");
220+
@Override
221+
public Publisher<CharSequence> stream() {
222+
return Mono.just("test-value");
223+
}
224+
}, (actual, expected) -> Flux.zip(Flux.from(actual.stream()).reduce(new StringBuilder(), StringBuilder::append).map(StringBuilder::toString),
225+
Flux.from(expected.stream()).reduce(new StringBuilder(), StringBuilder::append).map(StringBuilder::toString)).as(StepVerifier::create).assertNext(t -> assertThat(t.getT1()).isEqualToIgnoringWhitespace(t.getT2())).verifyComplete(), "TEXT");
239226
}
240227

241228
@Test
@@ -445,11 +432,21 @@ void localDateTime() {
445432
testCodec(LocalDateTime.class, LocalDateTime.now().truncatedTo(ChronoUnit.MICROS), "TIMESTAMP");
446433
}
447434

435+
@Test
436+
void localDateTimeArray() {
437+
testCodec(LocalDateTime[].class, new LocalDateTime[]{LocalDateTime.now().truncatedTo(ChronoUnit.MICROS)}, "TIMESTAMP[]");
438+
}
439+
448440
@Test
449441
void localTime() {
450442
testCodec(LocalTime.class, LocalTime.now().truncatedTo(ChronoUnit.MICROS), "TIME");
451443
}
452444

445+
@Test
446+
void localTimeArray() {
447+
testCodec(LocalTime[].class, new LocalTime[]{LocalTime.now().truncatedTo(ChronoUnit.MICROS)}, "TIME[]");
448+
}
449+
453450
@Test
454451
void longArray() {
455452
testCodec(Long[].class, new Long[]{100L, 200L, 300L}, "INT8[]");
@@ -649,8 +646,8 @@ void pathTwoDimensionalArray() {
649646

650647
@Test
651648
void polygonArray() {
652-
testCodec(Polygon[].class, new Polygon[]{Polygon.of(Point.of(1.1, 2.2), Point.of(10.10, 10.10), Point.of(.42, 5.3)),
653-
Polygon.of(Point.of(1.1, 2.2), Point.of(10.10, 10.10), Point.of(.42, 5.3), Point.of(-3.5, 0.))}, "POLYGON[]");
649+
testCodec(Polygon[].class, new Polygon[]{Polygon.of(Point.of(1.1, 2.2), Point.of(10.10, 10.10), Point.of(.42, 5.3)), Polygon.of(Point.of(1.1, 2.2), Point.of(10.10, 10.10), Point.of(.42,
650+
5.3), Point.of(-3.5, 0.))}, "POLYGON[]");
654651
}
655652

656653
@Test
@@ -666,9 +663,7 @@ void polygonTwoDimensionalArray() {
666663
}
667664

668665
private static <T> Mono<T> close(Connection connection) {
669-
return Mono.from(connection
670-
.close())
671-
.then(Mono.empty());
666+
return Mono.from(connection.close()).then(Mono.empty());
672667
}
673668

674669
private <T> void testCodec(Class<T> javaType, T value, String sqlType) {
@@ -727,94 +722,64 @@ private <IN, OUT> void testCodec(Class<IN> javaType, IN value, Class<OUT> outTyp
727722

728723
if (parameterType == null) {
729724

730-
this.connectionFactory.create()
731-
.flatMapMany(connection -> connection
725+
this.connectionFactory.create().flatMapMany(connection -> connection
732726

733-
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")")
734-
.bindNull("$1", javaType)
735-
.execute()
727+
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")").bindNull("$1", javaType).execute()
736728

737-
.flatMap(PostgresqlResult::getRowsUpdated)
729+
.flatMap(PostgresqlResult::getRowsUpdated)
738730

739-
.concatWith(close(connection)))
740-
.as(StepVerifier::create)
741-
.expectNext(1)
742-
.verifyComplete();
731+
.concatWith(close(connection))).as(StepVerifier::create).expectNext(1).verifyComplete();
743732

744733
SERVER.getJdbcOperations().execute("DELETE FROM test");
745734

746-
this.connectionFactory.create()
747-
.flatMapMany(connection -> connection
735+
this.connectionFactory.create().flatMapMany(connection -> connection
748736

749-
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")")
750-
.bind("$1", value)
751-
.execute()
737+
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")").bind("$1", value).execute()
752738

753-
.flatMap(PostgresqlResult::getRowsUpdated)
739+
.flatMap(PostgresqlResult::getRowsUpdated)
754740

755-
.concatWith(close(connection)))
756-
.as(StepVerifier::create)
757-
.expectNext(1)
758-
.verifyComplete();
741+
.concatWith(close(connection))).as(StepVerifier::create).expectNext(1).verifyComplete();
759742
} else {
760743

761-
this.connectionFactory.create()
762-
.flatMapMany(connection -> connection
744+
this.connectionFactory.create().flatMapMany(connection -> connection
763745

764-
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")")
765-
.bind("$1", Parameters.in(parameterType))
766-
.execute()
746+
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")").bind("$1", Parameters.in(parameterType)).execute()
767747

768-
.flatMap(PostgresqlResult::getRowsUpdated)
748+
.flatMap(PostgresqlResult::getRowsUpdated)
769749

770-
.concatWith(close(connection)))
771-
.as(StepVerifier::create)
772-
.expectNext(1)
773-
.verifyComplete();
750+
.concatWith(close(connection))).as(StepVerifier::create).expectNext(1).verifyComplete();
774751

775752
SERVER.getJdbcOperations().execute("DELETE FROM test");
776753

777-
this.connectionFactory.create()
778-
.flatMapMany(connection -> connection
754+
this.connectionFactory.create().flatMapMany(connection -> connection
779755

780-
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")")
781-
.bind("$1", Parameters.in(parameterType, value))
782-
.execute()
756+
.createStatement("INSERT INTO test VALUES (" + insertPlaceholder + ")").bind("$1", Parameters.in(parameterType, value)).execute()
783757

784-
.flatMap(PostgresqlResult::getRowsUpdated)
758+
.flatMap(PostgresqlResult::getRowsUpdated)
785759

786-
.concatWith(close(connection)))
787-
.as(StepVerifier::create)
788-
.expectNext(1)
789-
.verifyComplete();
760+
.concatWith(close(connection))).as(StepVerifier::create).expectNext(1).verifyComplete();
790761
}
791762

792763
if (value instanceof Buffer) {
793764
((Buffer) value).rewind();
794765
}
795766

796-
this.connectionFactory.create()
797-
.flatMapMany(connection -> {
798-
799-
PostgresqlStatement statement;
800-
if (insertPlaceholder.equals("$1")) {
801-
statement = connection
802-
// where clause added to force using extended query instead of simple query
803-
.createStatement("SELECT value FROM test WHERE " + insertPlaceholder + " <> 1")
804-
.bind("$1", 2);
805-
} else {
806-
statement = connection.createStatement("SELECT value FROM test");
807-
}
808-
return statement.execute()
809-
810-
.map(result -> result.map((row, metadata) -> row.get("value", outType)))
811-
.flatMap(Function.identity())
812-
813-
.concatWith(close(connection));
814-
})
815-
.as(StepVerifier::create)
816-
.assertNext(r2dbc -> equality.accept(r2dbc, value))
817-
.verifyComplete();
767+
this.connectionFactory.create().flatMapMany(connection -> {
768+
769+
PostgresqlStatement statement;
770+
if (insertPlaceholder.equals("$1")) {
771+
statement = connection
772+
// where clause added to force using extended query instead of simple query
773+
.createStatement("SELECT value FROM test WHERE " + insertPlaceholder + " <> 1").bind("$1", 2);
774+
} else {
775+
statement = connection.createStatement("SELECT value FROM test");
776+
}
777+
return statement.execute()
778+
779+
.map(result -> result.map((row, metadata) -> row.get("value", outType))).flatMap(Function.identity())
780+
781+
.concatWith(close(connection));
782+
}).as(StepVerifier::create).assertNext(r2dbc -> equality.accept(r2dbc, value)).verifyComplete();
818783
} finally {
819784
SERVER.getJdbcOperations().execute("DROP TABLE test");
820785
}
@@ -845,32 +810,21 @@ private <W, R> void testCodecReadAs(W toWrite, Class<R> javaTypeToRead, Consumer
845810
SERVER.getJdbcOperations().execute(String.format("CREATE TABLE test (value %s)", sqlType));
846811

847812
try {
848-
this.connectionFactory.create()
849-
.flatMapMany(connection -> connection
813+
this.connectionFactory.create().flatMapMany(connection -> connection
850814

851-
.createStatement("INSERT INTO test VALUES ($1)")
852-
.bind("$1", toWrite)
853-
.execute()
815+
.createStatement("INSERT INTO test VALUES ($1)").bind("$1", toWrite).execute()
854816

855-
.flatMap(PostgresqlResult::getRowsUpdated)
817+
.flatMap(PostgresqlResult::getRowsUpdated)
856818

857-
.concatWith(close(connection)))
858-
.as(StepVerifier::create)
859-
.expectNext(1)
860-
.verifyComplete();
819+
.concatWith(close(connection))).as(StepVerifier::create).expectNext(1).verifyComplete();
861820

862-
this.connectionFactory.create()
863-
.flatMapMany(connection -> {
864-
return connection.createStatement("SELECT value FROM test").execute()
821+
this.connectionFactory.create().flatMapMany(connection -> {
822+
return connection.createStatement("SELECT value FROM test").execute()
865823

866-
.map(result -> result.map((row, metadata) -> row.get("value", javaTypeToRead)))
867-
.flatMap(Function.identity())
824+
.map(result -> result.map((row, metadata) -> row.get("value", javaTypeToRead))).flatMap(Function.identity())
868825

869-
.concatWith(close(connection));
870-
})
871-
.as(StepVerifier::create)
872-
.assertNext(equality)
873-
.verifyComplete();
826+
.concatWith(close(connection));
827+
}).as(StepVerifier::create).assertNext(equality).verifyComplete();
874828
} finally {
875829
SERVER.getJdbcOperations().execute("DROP TABLE test");
876830
}

0 commit comments

Comments
 (0)