85
85
import org .junit .jupiter .api .BeforeEach ;
86
86
import org .junit .jupiter .api .Disabled ;
87
87
import org .junit .jupiter .api .Test ;
88
+ import org .junit .jupiter .params .ParameterizedTest ;
89
+ import org .junit .jupiter .params .provider .MethodSource ;
88
90
import org .mockito .Mockito ;
89
91
import org .testcontainers .containers .MinIOContainer ;
90
92
import org .testcontainers .junit .jupiter .Container ;
@@ -443,99 +445,53 @@ public void testFileIOJsonSerialization() {
443
445
}
444
446
}
445
447
446
- @ Test
447
- public void testS3FileIOKryoSerialization () throws IOException {
448
+ @ ParameterizedTest
449
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
450
+ public void testS3FileIOSerialization (TestHelpers .RoundTripSerializer <FileIO > roundTripSerializer )
451
+ throws IOException , ClassNotFoundException {
448
452
FileIO testS3FileIO = new S3FileIO ();
449
453
450
454
// s3 fileIO should be serializable when properties are passed as immutable map
451
- testS3FileIO .initialize (ImmutableMap .of ("k1" , "v1" ));
452
- FileIO roundTripSerializedFileIO = TestHelpers . KryoHelpers . roundTripSerialize (testS3FileIO );
455
+ testS3FileIO .initialize (ImmutableMap .of ("k1" , "v1" , "k2" , "v2" ));
456
+ FileIO roundTripSerializedFileIO = roundTripSerializer . apply (testS3FileIO );
453
457
454
458
assertThat (roundTripSerializedFileIO .properties ()).isEqualTo (testS3FileIO .properties ());
455
459
}
456
460
457
- @ Test
458
- public void testS3FileIOWithEmptyPropsKryoSerialization () throws IOException {
461
+ @ ParameterizedTest
462
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
463
+ public void testS3FileIOWithEmptyPropsSerialization (
464
+ TestHelpers .RoundTripSerializer <FileIO > roundTripSerializer )
465
+ throws IOException , ClassNotFoundException {
459
466
FileIO testS3FileIO = new S3FileIO ();
460
467
461
468
// s3 fileIO should be serializable when properties passed as empty immutable map
462
469
testS3FileIO .initialize (ImmutableMap .of ());
463
- FileIO roundTripSerializedFileIO = TestHelpers . KryoHelpers . roundTripSerialize (testS3FileIO );
470
+ FileIO roundTripSerializedFileIO = roundTripSerializer . apply (testS3FileIO );
464
471
465
472
assertThat (roundTripSerializedFileIO .properties ()).isEqualTo (testS3FileIO .properties ());
466
473
}
467
474
468
- @ Test
469
- public void fileIOWithStorageCredentialsKryoSerialization () throws IOException {
470
- S3FileIO fileIO = new S3FileIO ();
471
- fileIO .setCredentials (
472
- ImmutableList .of (
473
- StorageCredential .create ("prefix" , Map .of ("key1" , "val1" , "key2" , "val2" ))));
474
- fileIO .initialize (Map .of ());
475
-
476
- assertThat (TestHelpers .KryoHelpers .roundTripSerialize (fileIO ).credentials ())
477
- .isEqualTo (fileIO .credentials ());
478
- }
479
-
480
- @ Test
481
- public void fileIOWithStorageCredentialsJavaSerialization ()
475
+ @ ParameterizedTest
476
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
477
+ public void fileIOWithStorageCredentialsSerialization (
478
+ TestHelpers .RoundTripSerializer <S3FileIO > roundTripSerializer )
482
479
throws IOException , ClassNotFoundException {
483
480
S3FileIO fileIO = new S3FileIO ();
484
481
fileIO .setCredentials (
485
482
ImmutableList .of (
486
483
StorageCredential .create ("prefix" , Map .of ("key1" , "val1" , "key2" , "val2" ))));
487
484
fileIO .initialize (Map .of ());
488
485
489
- assertThat (TestHelpers .roundTripSerialize (fileIO ).credentials ())
490
- .isEqualTo (fileIO .credentials ());
491
- }
492
-
493
- @ Test
494
- public void fileIOWithPrefixedS3ClientWithoutCredentialsKryoSerialization () throws IOException {
495
- S3FileIO io = new S3FileIO ();
496
- io .initialize (Map .of (AwsClientProperties .CLIENT_REGION , "us-east-1" ));
497
-
498
- assertThat (io .client ()).isInstanceOf (S3Client .class );
499
- assertThat (io .asyncClient ()).isInstanceOf (S3AsyncClient .class );
500
- assertThat (io .client ("s3a://my-bucket/my-path" )).isInstanceOf (S3Client .class );
501
- assertThat (io .asyncClient ("s3a://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
502
-
503
- S3FileIO fileIO = TestHelpers .KryoHelpers .roundTripSerialize (io );
504
- assertThat (fileIO .credentials ()).isEqualTo (io .credentials ()).isEmpty ();
505
-
506
- assertThat (fileIO .client ()).isInstanceOf (S3Client .class );
507
- assertThat (fileIO .asyncClient ()).isInstanceOf (S3AsyncClient .class );
508
- assertThat (fileIO .client ("s3a://my-bucket/my-path" )).isInstanceOf (S3Client .class );
509
- assertThat (fileIO .asyncClient ("s3a://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
486
+ assertThat (roundTripSerializer .apply (fileIO ).credentials ()).isEqualTo (fileIO .credentials ());
510
487
}
511
488
512
- @ Test
513
- public void fileIOWithPrefixedS3ClientKryoSerialization () throws IOException {
514
- S3FileIO io = new S3FileIO ();
515
- io .setCredentials (
516
- ImmutableList .of (
517
- StorageCredential .create ("s3://my-bucket/my-path/table1" , Map .of ("key1" , "val1" ))));
518
- io .initialize (Map .of (AwsClientProperties .CLIENT_REGION , "us-east-1" ));
519
-
520
- // there should be a client for the generic and specific storage prefix available
521
- assertThat (io .client ()).isInstanceOf (S3Client .class );
522
- assertThat (io .asyncClient ()).isInstanceOf (S3AsyncClient .class );
523
- assertThat (io .client ("s3://my-bucket/my-path" )).isInstanceOf (S3Client .class );
524
- assertThat (io .asyncClient ("s3://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
525
-
526
- S3FileIO fileIO = TestHelpers .KryoHelpers .roundTripSerialize (io );
527
- assertThat (fileIO .credentials ()).isEqualTo (io .credentials ());
528
-
529
- // make sure there's a client for the generic and specific storage prefix available after ser/de
530
- assertThat (fileIO .client ()).isInstanceOf (S3Client .class );
531
- assertThat (fileIO .asyncClient ()).isInstanceOf (S3AsyncClient .class );
532
- assertThat (fileIO .client ("s3://my-bucket/my-path" )).isInstanceOf (S3Client .class );
533
- assertThat (fileIO .asyncClient ("s3://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
534
- }
535
-
536
- @ Test
537
- public void fileIOWithPrefixedS3ClientWithoutCredentialsJavaSerialization ()
489
+ @ ParameterizedTest
490
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
491
+ public void fileIOWithPrefixedS3ClientWithoutCredentialsSerialization (
492
+ TestHelpers .RoundTripSerializer <S3FileIO > roundTripSerializer )
538
493
throws IOException , ClassNotFoundException {
494
+
539
495
S3FileIO io = new S3FileIO ();
540
496
io .initialize (Map .of (AwsClientProperties .CLIENT_REGION , "us-east-1" ));
541
497
@@ -544,7 +500,7 @@ public void fileIOWithPrefixedS3ClientWithoutCredentialsJavaSerialization()
544
500
assertThat (io .client ("s3a://my-bucket/my-path" )).isInstanceOf (S3Client .class );
545
501
assertThat (io .asyncClient ("s3a://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
546
502
547
- S3FileIO fileIO = TestHelpers . roundTripSerialize (io );
503
+ S3FileIO fileIO = roundTripSerializer . apply (io );
548
504
assertThat (fileIO .credentials ()).isEqualTo (io .credentials ()).isEmpty ();
549
505
550
506
assertThat (fileIO .client ()).isInstanceOf (S3Client .class );
@@ -553,8 +509,10 @@ public void fileIOWithPrefixedS3ClientWithoutCredentialsJavaSerialization()
553
509
assertThat (fileIO .asyncClient ("s3a://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
554
510
}
555
511
556
- @ Test
557
- public void fileIOWithPrefixedS3ClientJavaSerialization ()
512
+ @ ParameterizedTest
513
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
514
+ public void fileIOWithPrefixedS3ClientSerialization (
515
+ TestHelpers .RoundTripSerializer <S3FileIO > roundTripSerializer )
558
516
throws IOException , ClassNotFoundException {
559
517
S3FileIO io = new S3FileIO ();
560
518
io .setCredentials (
@@ -568,7 +526,7 @@ public void fileIOWithPrefixedS3ClientJavaSerialization()
568
526
assertThat (io .client ("s3://my-bucket/my-path" )).isInstanceOf (S3Client .class );
569
527
assertThat (io .asyncClient ("s3://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
570
528
571
- S3FileIO fileIO = TestHelpers . roundTripSerialize (io );
529
+ S3FileIO fileIO = roundTripSerializer . apply (io );
572
530
assertThat (fileIO .credentials ()).isEqualTo (io .credentials ());
573
531
574
532
// make sure there's a client for the generic and specific storage prefix available after ser/de
@@ -578,17 +536,6 @@ public void fileIOWithPrefixedS3ClientJavaSerialization()
578
536
assertThat (fileIO .asyncClient ("s3://my-bucket/my-path" )).isInstanceOf (S3AsyncClient .class );
579
537
}
580
538
581
- @ Test
582
- public void testS3FileIOJavaSerialization () throws IOException , ClassNotFoundException {
583
- FileIO testS3FileIO = new S3FileIO ();
584
-
585
- // s3 fileIO should be serializable when properties are passed as immutable map
586
- testS3FileIO .initialize (ImmutableMap .of ("k1" , "v1" ));
587
- FileIO roundTripSerializedFileIO = TestHelpers .roundTripSerialize (testS3FileIO );
588
-
589
- assertThat (roundTripSerializedFileIO .properties ()).isEqualTo (testS3FileIO .properties ());
590
- }
591
-
592
539
@ Test
593
540
public void testResolvingFileIOLoad () {
594
541
ResolvingFileIO resolvingFileIO = new ResolvingFileIO ();
@@ -662,8 +609,10 @@ public void testInputFileWithManifest() throws IOException {
662
609
verify (s3mock , never ()).headObject (any (HeadObjectRequest .class ));
663
610
}
664
611
665
- @ Test
666
- public void resolvingFileIOLoadWithoutStorageCredentials ()
612
+ @ ParameterizedTest
613
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
614
+ public void resolvingFileIOLoadWithoutStorageCredentials (
615
+ TestHelpers .RoundTripSerializer <ResolvingFileIO > roundTripSerializer )
667
616
throws IOException , ClassNotFoundException {
668
617
ResolvingFileIO resolvingFileIO = new ResolvingFileIO ();
669
618
resolvingFileIO .initialize (ImmutableMap .of (AwsClientProperties .CLIENT_REGION , "us-east-1" ));
@@ -686,8 +635,8 @@ public void resolvingFileIOLoadWithoutStorageCredentials()
686
635
.isInstanceOf (S3AsyncClient .class );
687
636
});
688
637
689
- // make sure credentials can be accessed after kryo serde
690
- ResolvingFileIO resolvingIO = TestHelpers . KryoHelpers . roundTripSerialize (resolvingFileIO );
638
+ // make sure credentials can be accessed after serde
639
+ ResolvingFileIO resolvingIO = roundTripSerializer . apply (resolvingFileIO );
691
640
assertThat (resolvingIO .credentials ()).isEmpty ();
692
641
result =
693
642
DynMethods .builder ("io" )
@@ -706,31 +655,12 @@ public void resolvingFileIOLoadWithoutStorageCredentials()
706
655
.isSameAs (fileIO .asyncClient ())
707
656
.isInstanceOf (S3AsyncClient .class );
708
657
});
709
-
710
- // make sure credentials can be accessed after java serde
711
- resolvingIO = TestHelpers .roundTripSerialize (resolvingFileIO );
712
- assertThat (resolvingIO .credentials ()).isEmpty ();
713
- result =
714
- DynMethods .builder ("io" )
715
- .hiddenImpl (ResolvingFileIO .class , String .class )
716
- .build (resolvingIO )
717
- .invoke ("s3://foo/bar" );
718
- assertThat (result )
719
- .isInstanceOf (S3FileIO .class )
720
- .asInstanceOf (InstanceOfAssertFactories .type (S3FileIO .class ))
721
- .satisfies (
722
- fileIO -> {
723
- assertThat (fileIO .client ("s3://foo/bar" ))
724
- .isSameAs (fileIO .client ())
725
- .isInstanceOf (S3Client .class );
726
- assertThat (fileIO .asyncClient ("s3://foo/bar" ))
727
- .isSameAs (fileIO .asyncClient ())
728
- .isInstanceOf (S3AsyncClient .class );
729
- });
730
658
}
731
659
732
- @ Test
733
- public void resolvingFileIOLoadWithStorageCredentials ()
660
+ @ ParameterizedTest
661
+ @ MethodSource ("org.apache.iceberg.TestHelpers#serializers" )
662
+ public void resolvingFileIOLoadWithStorageCredentials (
663
+ TestHelpers .RoundTripSerializer <ResolvingFileIO > roundTripSerializer )
734
664
throws IOException , ClassNotFoundException {
735
665
StorageCredential credential = StorageCredential .create ("s3://foo/bar" , Map .of ("key1" , "val1" ));
736
666
List <StorageCredential > storageCredentials = ImmutableList .of (credential );
@@ -760,33 +690,8 @@ public void resolvingFileIOLoadWithStorageCredentials()
760
690
.isInstanceOf (S3AsyncClient .class );
761
691
});
762
692
763
- // make sure credentials are still present after kryo serde
764
- ResolvingFileIO resolvingIO = TestHelpers .KryoHelpers .roundTripSerialize (resolvingFileIO );
765
- assertThat (resolvingIO .credentials ()).isEqualTo (storageCredentials );
766
- result =
767
- DynMethods .builder ("io" )
768
- .hiddenImpl (ResolvingFileIO .class , String .class )
769
- .build (resolvingIO )
770
- .invoke ("s3://foo/bar" );
771
- io =
772
- assertThat (result )
773
- .isInstanceOf (S3FileIO .class )
774
- .asInstanceOf (InstanceOfAssertFactories .type (S3FileIO .class ));
775
- io .extracting (S3FileIO ::credentials ).isEqualTo (storageCredentials );
776
- io .satisfies (
777
- fileIO -> {
778
- // make sure there are two separate S3 clients for different prefixes and that the
779
- // underlying sync/async client is set
780
- assertThat (fileIO .client ("s3://foo/bar" ))
781
- .isNotSameAs (fileIO .client ())
782
- .isInstanceOf (S3Client .class );
783
- assertThat (fileIO .asyncClient ("s3://foo/bar" ))
784
- .isNotSameAs (fileIO .asyncClient ())
785
- .isInstanceOf (S3AsyncClient .class );
786
- });
787
-
788
- // make sure credentials are still present after java serde
789
- resolvingIO = TestHelpers .roundTripSerialize (resolvingFileIO );
693
+ // make sure credentials are still present after serde
694
+ ResolvingFileIO resolvingIO = roundTripSerializer .apply (resolvingFileIO );
790
695
assertThat (resolvingIO .credentials ()).isEqualTo (storageCredentials );
791
696
result =
792
697
DynMethods .builder ("io" )
0 commit comments