@@ -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
@@ -445,11 +432,21 @@ void localDateTime() {
445
432
testCodec (LocalDateTime .class , LocalDateTime .now ().truncatedTo (ChronoUnit .MICROS ), "TIMESTAMP" );
446
433
}
447
434
435
+ @ Test
436
+ void localDateTimeArray () {
437
+ testCodec (LocalDateTime [].class , new LocalDateTime []{LocalDateTime .now ().truncatedTo (ChronoUnit .MICROS )}, "TIMESTAMP[]" );
438
+ }
439
+
448
440
@ Test
449
441
void localTime () {
450
442
testCodec (LocalTime .class , LocalTime .now ().truncatedTo (ChronoUnit .MICROS ), "TIME" );
451
443
}
452
444
445
+ @ Test
446
+ void localTimeArray () {
447
+ testCodec (LocalTime [].class , new LocalTime []{LocalTime .now ().truncatedTo (ChronoUnit .MICROS )}, "TIME[]" );
448
+ }
449
+
453
450
@ Test
454
451
void longArray () {
455
452
testCodec (Long [].class , new Long []{100L , 200L , 300L }, "INT8[]" );
@@ -649,8 +646,8 @@ void pathTwoDimensionalArray() {
649
646
650
647
@ Test
651
648
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[]" );
654
651
}
655
652
656
653
@ Test
@@ -666,9 +663,7 @@ void polygonTwoDimensionalArray() {
666
663
}
667
664
668
665
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 ());
672
667
}
673
668
674
669
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
727
722
728
723
if (parameterType == null ) {
729
724
730
- this .connectionFactory .create ()
731
- .flatMapMany (connection -> connection
725
+ this .connectionFactory .create ().flatMapMany (connection -> connection
732
726
733
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
734
- .bindNull ("$1" , javaType )
735
- .execute ()
727
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bindNull ("$1" , javaType ).execute ()
736
728
737
- .flatMap (PostgresqlResult ::getRowsUpdated )
729
+ .flatMap (PostgresqlResult ::getRowsUpdated )
738
730
739
- .concatWith (close (connection )))
740
- .as (StepVerifier ::create )
741
- .expectNext (1 )
742
- .verifyComplete ();
731
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1 ).verifyComplete ();
743
732
744
733
SERVER .getJdbcOperations ().execute ("DELETE FROM test" );
745
734
746
- this .connectionFactory .create ()
747
- .flatMapMany (connection -> connection
735
+ this .connectionFactory .create ().flatMapMany (connection -> connection
748
736
749
- .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" )
750
- .bind ("$1" , value )
751
- .execute ()
737
+ .createStatement ("INSERT INTO test VALUES (" + insertPlaceholder + ")" ).bind ("$1" , value ).execute ()
752
738
753
- .flatMap (PostgresqlResult ::getRowsUpdated )
739
+ .flatMap (PostgresqlResult ::getRowsUpdated )
754
740
755
- .concatWith (close (connection )))
756
- .as (StepVerifier ::create )
757
- .expectNext (1 )
758
- .verifyComplete ();
741
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1 ).verifyComplete ();
759
742
} else {
760
743
761
- this .connectionFactory .create ()
762
- .flatMapMany (connection -> connection
744
+ this .connectionFactory .create ().flatMapMany (connection -> connection
763
745
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 ()
767
747
768
- .flatMap (PostgresqlResult ::getRowsUpdated )
748
+ .flatMap (PostgresqlResult ::getRowsUpdated )
769
749
770
- .concatWith (close (connection )))
771
- .as (StepVerifier ::create )
772
- .expectNext (1 )
773
- .verifyComplete ();
750
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1 ).verifyComplete ();
774
751
775
752
SERVER .getJdbcOperations ().execute ("DELETE FROM test" );
776
753
777
- this .connectionFactory .create ()
778
- .flatMapMany (connection -> connection
754
+ this .connectionFactory .create ().flatMapMany (connection -> connection
779
755
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 ()
783
757
784
- .flatMap (PostgresqlResult ::getRowsUpdated )
758
+ .flatMap (PostgresqlResult ::getRowsUpdated )
785
759
786
- .concatWith (close (connection )))
787
- .as (StepVerifier ::create )
788
- .expectNext (1 )
789
- .verifyComplete ();
760
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1 ).verifyComplete ();
790
761
}
791
762
792
763
if (value instanceof Buffer ) {
793
764
((Buffer ) value ).rewind ();
794
765
}
795
766
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 ();
818
783
} finally {
819
784
SERVER .getJdbcOperations ().execute ("DROP TABLE test" );
820
785
}
@@ -845,32 +810,21 @@ private <W, R> void testCodecReadAs(W toWrite, Class<R> javaTypeToRead, Consumer
845
810
SERVER .getJdbcOperations ().execute (String .format ("CREATE TABLE test (value %s)" , sqlType ));
846
811
847
812
try {
848
- this .connectionFactory .create ()
849
- .flatMapMany (connection -> connection
813
+ this .connectionFactory .create ().flatMapMany (connection -> connection
850
814
851
- .createStatement ("INSERT INTO test VALUES ($1)" )
852
- .bind ("$1" , toWrite )
853
- .execute ()
815
+ .createStatement ("INSERT INTO test VALUES ($1)" ).bind ("$1" , toWrite ).execute ()
854
816
855
- .flatMap (PostgresqlResult ::getRowsUpdated )
817
+ .flatMap (PostgresqlResult ::getRowsUpdated )
856
818
857
- .concatWith (close (connection )))
858
- .as (StepVerifier ::create )
859
- .expectNext (1 )
860
- .verifyComplete ();
819
+ .concatWith (close (connection ))).as (StepVerifier ::create ).expectNext (1 ).verifyComplete ();
861
820
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 ()
865
823
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 ())
868
825
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 ();
874
828
} finally {
875
829
SERVER .getJdbcOperations ().execute ("DROP TABLE test" );
876
830
}
0 commit comments