@@ -164,20 +164,15 @@ void charPrimitive() {
164
164
165
165
@ Test
166
166
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 ();
181
176
182
177
Function <byte [], Blob > byteToBlob = (bytes ) -> new Blob () {
183
178
@@ -209,33 +204,25 @@ void circle() {
209
204
210
205
@ Test
211
206
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[][]" );
214
209
}
215
210
216
211
@ Test
217
212
void clob () {
218
- testCodec (Clob .class ,
219
- new Clob () {
213
+ testCodec (Clob .class , new Clob () {
220
214
221
- @ Override
222
- public Publisher <Void > discard () {
223
- return Mono .empty ();
224
- }
215
+ @ Override
216
+ public Publisher <Void > discard () {
217
+ return Mono .empty ();
218
+ }
225
219
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" );
239
226
}
240
227
241
228
@ Test
@@ -468,11 +455,22 @@ void localDateTime() {
468
455
}, "TIMESTAMPTZ" , "$1" , null );
469
456
}
470
457
458
+ @ Test
459
+ void localDateTimeArray () {
460
+ testCodec (LocalDateTime [].class , new LocalDateTime []{LocalDateTime .now ().truncatedTo (ChronoUnit .MICROS )}, "TIMESTAMP[]" );
461
+ testCodec (LocalDateTime [].class , new LocalDateTime []{LocalDateTime .now ().truncatedTo (ChronoUnit .MICROS )}, "TIMESTAMPTZ[]" );
462
+ }
463
+
471
464
@ Test
472
465
void localTime () {
473
466
testCodec (LocalTime .class , LocalTime .now ().truncatedTo (ChronoUnit .MICROS ), "TIME" );
474
467
}
475
468
469
+ @ Test
470
+ void localTimeArray () {
471
+ testCodec (LocalTime [].class , new LocalTime []{LocalTime .now ().truncatedTo (ChronoUnit .MICROS )}, "TIME[]" );
472
+ }
473
+
476
474
@ Test
477
475
void longArray () {
478
476
testCodec (Long [].class , new Long []{100L , 200L , 300L }, "INT8[]" );
@@ -672,8 +670,8 @@ void pathTwoDimensionalArray() {
672
670
673
671
@ Test
674
672
void polygonArray () {
675
- testCodec (Polygon [].class , new Polygon []{Polygon .of (Point .of (1.1 , 2.2 ), Point .of (10.10 , 10.10 ), Point .of (.42 , 5.3 )),
676
- 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[]" );
673
+ 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 ,
674
+ 5.3 ), Point .of (-3.5 , 0. ))}, "POLYGON[]" );
677
675
}
678
676
679
677
@ Test
@@ -689,9 +687,7 @@ void polygonTwoDimensionalArray() {
689
687
}
690
688
691
689
private static <T > Mono <T > close (Connection connection ) {
692
- return Mono .from (connection
693
- .close ())
694
- .then (Mono .empty ());
690
+ return Mono .from (connection .close ()).then (Mono .empty ());
695
691
}
696
692
697
693
private <T > void testCodec (Class <T > javaType , T value , String sqlType ) {
@@ -750,94 +746,64 @@ private <IN, OUT> void testCodec(Class<IN> javaType, IN value, Class<OUT> outTyp
750
746
751
747
if (parameterType == null ) {
752
748
753
- this .connectionFactory .create ()
754
- .flatMapMany (connection -> connection
749
+ this .connectionFactory .create ().flatMapMany (connection -> connection
755
750
756
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
757
- .bindNull ("$1" , javaType )
758
- .execute ()
751
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bindNull ("$1" , javaType ).execute ()
759
752
760
- .flatMap (PostgresqlResult ::getRowsUpdated )
753
+ .flatMap (PostgresqlResult ::getRowsUpdated )
761
754
762
- .concatWith (close (connection )))
763
- .as (StepVerifier ::create )
764
- .expectNext (1L )
765
- .verifyComplete ();
755
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1L ).verifyComplete ();
766
756
767
757
SERVER .getJdbcOperations ().execute ("DELETE FROM test" );
768
758
769
- this .connectionFactory .create ()
770
- .flatMapMany (connection -> connection
759
+ this .connectionFactory .create ().flatMapMany (connection -> connection
771
760
772
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
773
- .bind ("$1" , value )
774
- .execute ()
761
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bind ("$1" , value ).execute ()
775
762
776
- .flatMap (PostgresqlResult ::getRowsUpdated )
763
+ .flatMap (PostgresqlResult ::getRowsUpdated )
777
764
778
- .concatWith (close (connection )))
779
- .as (StepVerifier ::create )
780
- .expectNext (1L )
781
- .verifyComplete ();
765
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1L ).verifyComplete ();
782
766
} else {
783
767
784
- this .connectionFactory .create ()
785
- .flatMapMany (connection -> connection
768
+ this .connectionFactory .create ().flatMapMany (connection -> connection
786
769
787
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
788
- .bind ("$1" , Parameters .in (parameterType ))
789
- .execute ()
770
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bind ("$1" , Parameters .in (parameterType )).execute ()
790
771
791
- .flatMap (PostgresqlResult ::getRowsUpdated )
772
+ .flatMap (PostgresqlResult ::getRowsUpdated )
792
773
793
- .concatWith (close (connection )))
794
- .as (StepVerifier ::create )
795
- .expectNext (1L )
796
- .verifyComplete ();
774
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1L ).verifyComplete ();
797
775
798
776
SERVER .getJdbcOperations ().execute ("DELETE FROM test" );
799
777
800
- this .connectionFactory .create ()
801
- .flatMapMany (connection -> connection
778
+ this .connectionFactory .create ().flatMapMany (connection -> connection
802
779
803
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
804
- .bind ("$1" , Parameters .in (parameterType , value ))
805
- .execute ()
780
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bind ("$1" , Parameters .in (parameterType , value )).execute ()
806
781
807
- .flatMap (PostgresqlResult ::getRowsUpdated )
782
+ .flatMap (PostgresqlResult ::getRowsUpdated )
808
783
809
- .concatWith (close (connection )))
810
- .as (StepVerifier ::create )
811
- .expectNext (1L )
812
- .verifyComplete ();
784
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1L ).verifyComplete ();
813
785
}
814
786
815
787
if (value instanceof Buffer ) {
816
788
((Buffer ) value ).rewind ();
817
789
}
818
790
819
- this .connectionFactory .create ()
820
- .flatMapMany (connection -> {
821
-
822
- PostgresqlStatement statement ;
823
- if (insertPlaceholder .equals ("$1" )) {
824
- statement = connection
825
- // where clause added to force using extended query instead of simple query
826
- .createStatement ("SELECT value FROM test WHERE " + insertPlaceholder + " <> 1" )
827
- .bind ("$1" , 2 );
828
- } else {
829
- statement = connection .createStatement ("SELECT value FROM test" );
830
- }
831
- return statement .execute ()
832
-
833
- .map (result -> result .map ((row , metadata ) -> row .get ("value" , outType )))
834
- .flatMap (Function .identity ())
835
-
836
- .concatWith (close (connection ));
837
- })
838
- .as (StepVerifier ::create )
839
- .assertNext (r2dbc -> equality .accept (r2dbc , value ))
840
- .verifyComplete ();
791
+ this .connectionFactory .create ().flatMapMany (connection -> {
792
+
793
+ PostgresqlStatement statement ;
794
+ if (insertPlaceholder .equals ("$1" )) {
795
+ statement = connection
796
+ // where clause added to force using extended query instead of simple query
797
+ .createStatement ("SELECT value FROM test WHERE " + insertPlaceholder + " <> 1" ).bind ("$1" , 2 );
798
+ } else {
799
+ statement = connection .createStatement ("SELECT value FROM test" );
800
+ }
801
+ return statement .execute ()
802
+
803
+ .map (result -> result .map ((row , metadata ) -> row .get ("value" , outType ))).flatMap (Function .identity ())
804
+
805
+ .concatWith (close (connection ));
806
+ }).as (StepVerifier ::create ).assertNext (r2dbc -> equality .accept (r2dbc , value )).verifyComplete ();
841
807
} finally {
842
808
SERVER .getJdbcOperations ().execute ("DROP TABLE test" );
843
809
}
@@ -868,32 +834,21 @@ private <W, R> void testCodecReadAs(W toWrite, Class<R> javaTypeToRead, Consumer
868
834
SERVER .getJdbcOperations ().execute (String .format ("CREATE TABLE test (value %s)" , sqlType ));
869
835
870
836
try {
871
- this .connectionFactory .create ()
872
- .flatMapMany (connection -> connection
837
+ this .connectionFactory .create ().flatMapMany (connection -> connection
873
838
874
- .createStatement ("INSERT INTO test VALUES ($1)" )
875
- .bind ("$1" , toWrite )
876
- .execute ()
839
+ .createStatement ("INSERT INTO test VALUES ($1)" ).bind ("$1" , toWrite ).execute ()
877
840
878
- .flatMap (PostgresqlResult ::getRowsUpdated )
841
+ .flatMap (PostgresqlResult ::getRowsUpdated )
879
842
880
- .concatWith (close (connection )))
881
- .as (StepVerifier ::create )
882
- .expectNext (1L )
883
- .verifyComplete ();
843
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1L ).verifyComplete ();
884
844
885
- this .connectionFactory .create ()
886
- .flatMapMany (connection -> {
887
- return connection .createStatement ("SELECT value FROM test" ).execute ()
845
+ this .connectionFactory .create ().flatMapMany (connection -> {
846
+ return connection .createStatement ("SELECT value FROM test" ).execute ()
888
847
889
- .map (result -> result .map ((row , metadata ) -> row .get ("value" , javaTypeToRead )))
890
- .flatMap (Function .identity ())
848
+ .map (result -> result .map ((row , metadata ) -> row .get ("value" , javaTypeToRead ))).flatMap (Function .identity ())
891
849
892
- .concatWith (close (connection ));
893
- })
894
- .as (StepVerifier ::create )
895
- .assertNext (equality )
896
- .verifyComplete ();
850
+ .concatWith (close (connection ));
851
+ }).as (StepVerifier ::create ).assertNext (equality ).verifyComplete ();
897
852
} finally {
898
853
SERVER .getJdbcOperations ().execute ("DROP TABLE test" );
899
854
}
0 commit comments