@@ -759,338 +759,4 @@ public void testH1DirectReadFullySmallTempBufferWithPositionAndLimit() throws Ex
759759 ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
760760 }
761761
762- @ Test
763- public void testH2HeapReadFullySmallBuffer () throws Exception {
764- ByteBuffer readBuffer = ByteBuffer .allocate (8 );
765-
766- FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
767-
768- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
769- Assert .assertEquals (8 , readBuffer .position ());
770- Assert .assertEquals (8 , readBuffer .limit ());
771-
772- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
773- Assert .assertEquals (8 , readBuffer .position ());
774- Assert .assertEquals (8 , readBuffer .limit ());
775-
776- readBuffer .flip ();
777- Assert .assertEquals ("Buffer contents should match" ,
778- ByteBuffer .wrap (TEST_ARRAY , 0 , 8 ), readBuffer );
779- }
780-
781- @ Test
782- public void testH2HeapReadFullyLargeBuffer () throws Exception {
783- final ByteBuffer readBuffer = ByteBuffer .allocate (20 );
784-
785- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
786-
787- TestUtils .assertThrows ("Should throw EOFException" ,
788- EOFException .class , new Callable () {
789- @ Override
790- public Object call () throws Exception {
791- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
792- return null ;
793- }
794- });
795-
796- // NOTE: This behavior differs from readFullyHeapBuffer because direct uses
797- // several read operations that will read up to the end of the input. This
798- // is a correct value because the bytes in the buffer are valid. This
799- // behavior can't be implemented for the heap buffer without using the read
800- // method instead of the readFully method on the underlying
801- // FSDataInputStream.
802- Assert .assertEquals (10 , readBuffer .position ());
803- Assert .assertEquals (20 , readBuffer .limit ());
804- }
805-
806- @ Test
807- public void testH2HeapReadFullyJustRight () throws Exception {
808- final ByteBuffer readBuffer = ByteBuffer .allocate (10 );
809-
810- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
811-
812- // reads all of the bytes available without EOFException
813- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
814- Assert .assertEquals (10 , readBuffer .position ());
815- Assert .assertEquals (10 , readBuffer .limit ());
816-
817- // trying to read 0 more bytes doesn't result in EOFException
818- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
819- Assert .assertEquals (10 , readBuffer .position ());
820- Assert .assertEquals (10 , readBuffer .limit ());
821-
822- readBuffer .flip ();
823- Assert .assertEquals ("Buffer contents should match" ,
824- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
825- }
826-
827- @ Test
828- public void testH2HeapReadFullySmallReads () throws Exception {
829- final ByteBuffer readBuffer = ByteBuffer .allocate (10 );
830-
831- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
832-
833- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
834- Assert .assertEquals (10 , readBuffer .position ());
835- Assert .assertEquals (10 , readBuffer .limit ());
836-
837- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
838- Assert .assertEquals (10 , readBuffer .position ());
839- Assert .assertEquals (10 , readBuffer .limit ());
840-
841- readBuffer .flip ();
842- Assert .assertEquals ("Buffer contents should match" ,
843- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
844- }
845-
846- @ Test
847- public void testH2HeapReadFullyPosition () throws Exception {
848- final ByteBuffer readBuffer = ByteBuffer .allocate (10 );
849- readBuffer .position (3 );
850- readBuffer .mark ();
851-
852- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
853-
854- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
855- Assert .assertEquals (10 , readBuffer .position ());
856- Assert .assertEquals (10 , readBuffer .limit ());
857-
858- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
859- Assert .assertEquals (10 , readBuffer .position ());
860- Assert .assertEquals (10 , readBuffer .limit ());
861-
862- readBuffer .reset ();
863- Assert .assertEquals ("Buffer contents should match" ,
864- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
865- }
866-
867- @ Test
868- public void testH2HeapReadFullyLimit () throws Exception {
869- final ByteBuffer readBuffer = ByteBuffer .allocate (10 );
870- readBuffer .limit (7 );
871-
872- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
873-
874- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
875- Assert .assertEquals (7 , readBuffer .position ());
876- Assert .assertEquals (7 , readBuffer .limit ());
877-
878- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
879- Assert .assertEquals (7 , readBuffer .position ());
880- Assert .assertEquals (7 , readBuffer .limit ());
881-
882- readBuffer .flip ();
883- Assert .assertEquals ("Buffer contents should match" ,
884- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
885-
886- readBuffer .position (7 );
887- readBuffer .limit (10 );
888- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
889- Assert .assertEquals (10 , readBuffer .position ());
890- Assert .assertEquals (10 , readBuffer .limit ());
891-
892- readBuffer .flip ();
893- Assert .assertEquals ("Buffer contents should match" ,
894- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
895- }
896-
897- @ Test
898- public void testH2HeapReadFullyPositionAndLimit () throws Exception {
899- final ByteBuffer readBuffer = ByteBuffer .allocate (10 );
900- readBuffer .position (3 );
901- readBuffer .limit (7 );
902- readBuffer .mark ();
903-
904- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
905-
906- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
907- Assert .assertEquals (7 , readBuffer .position ());
908- Assert .assertEquals (7 , readBuffer .limit ());
909-
910- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
911- Assert .assertEquals (7 , readBuffer .position ());
912- Assert .assertEquals (7 , readBuffer .limit ());
913-
914- readBuffer .reset ();
915- Assert .assertEquals ("Buffer contents should match" ,
916- ByteBuffer .wrap (TEST_ARRAY , 0 , 4 ), readBuffer );
917-
918- readBuffer .position (7 );
919- readBuffer .limit (10 );
920- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
921- Assert .assertEquals (10 , readBuffer .position ());
922- Assert .assertEquals (10 , readBuffer .limit ());
923-
924- readBuffer .reset ();
925- Assert .assertEquals ("Buffer contents should match" ,
926- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
927- }
928-
929- @ Test
930- public void testH2DirectReadFullySmallBuffer () throws Exception {
931- ByteBuffer readBuffer = ByteBuffer .allocateDirect (8 );
932-
933- FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
934-
935- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
936- Assert .assertEquals (8 , readBuffer .position ());
937- Assert .assertEquals (8 , readBuffer .limit ());
938-
939- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
940- Assert .assertEquals (8 , readBuffer .position ());
941- Assert .assertEquals (8 , readBuffer .limit ());
942-
943- readBuffer .flip ();
944- Assert .assertEquals ("Buffer contents should match" ,
945- ByteBuffer .wrap (TEST_ARRAY , 0 , 8 ), readBuffer );
946- }
947-
948- @ Test
949- public void testH2DirectReadFullyLargeBuffer () throws Exception {
950- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (20 );
951-
952- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
953-
954- TestUtils .assertThrows ("Should throw EOFException" ,
955- EOFException .class , new Callable () {
956- @ Override
957- public Object call () throws Exception {
958- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
959- return null ;
960- }
961- });
962-
963- // NOTE: This behavior differs from readFullyHeapBuffer because direct uses
964- // several read operations that will read up to the end of the input. This
965- // is a correct value because the bytes in the buffer are valid. This
966- // behavior can't be implemented for the heap buffer without using the read
967- // method instead of the readFully method on the underlying
968- // FSDataInputStream.
969- Assert .assertEquals (10 , readBuffer .position ());
970- Assert .assertEquals (20 , readBuffer .limit ());
971- }
972-
973- @ Test
974- public void testH2DirectReadFullyJustRight () throws Exception {
975- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (10 );
976-
977- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream ());
978-
979- // reads all of the bytes available without EOFException
980- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
981- Assert .assertEquals (10 , readBuffer .position ());
982- Assert .assertEquals (10 , readBuffer .limit ());
983-
984- // trying to read 0 more bytes doesn't result in EOFException
985- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
986- Assert .assertEquals (10 , readBuffer .position ());
987- Assert .assertEquals (10 , readBuffer .limit ());
988-
989- readBuffer .flip ();
990- Assert .assertEquals ("Buffer contents should match" ,
991- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
992- }
993-
994- @ Test
995- public void testH2DirectReadFullySmallReads () throws Exception {
996- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (10 );
997-
998- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
999-
1000- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1001- Assert .assertEquals (10 , readBuffer .position ());
1002- Assert .assertEquals (10 , readBuffer .limit ());
1003-
1004- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1005- Assert .assertEquals (10 , readBuffer .position ());
1006- Assert .assertEquals (10 , readBuffer .limit ());
1007-
1008- readBuffer .flip ();
1009- Assert .assertEquals ("Buffer contents should match" ,
1010- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
1011- }
1012-
1013- @ Test
1014- public void testH2DirectReadFullyPosition () throws Exception {
1015- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (10 );
1016- readBuffer .position (3 );
1017- readBuffer .mark ();
1018-
1019- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
1020-
1021- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1022- Assert .assertEquals (10 , readBuffer .position ());
1023- Assert .assertEquals (10 , readBuffer .limit ());
1024-
1025- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1026- Assert .assertEquals (10 , readBuffer .position ());
1027- Assert .assertEquals (10 , readBuffer .limit ());
1028-
1029- readBuffer .reset ();
1030- Assert .assertEquals ("Buffer contents should match" ,
1031- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
1032- }
1033-
1034- @ Test
1035- public void testH2DirectReadFullyLimit () throws Exception {
1036- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (10 );
1037- readBuffer .limit (7 );
1038-
1039- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
1040-
1041- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1042- Assert .assertEquals (7 , readBuffer .position ());
1043- Assert .assertEquals (7 , readBuffer .limit ());
1044-
1045- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1046- Assert .assertEquals (7 , readBuffer .position ());
1047- Assert .assertEquals (7 , readBuffer .limit ());
1048-
1049- readBuffer .flip ();
1050- Assert .assertEquals ("Buffer contents should match" ,
1051- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
1052-
1053- readBuffer .position (7 );
1054- readBuffer .limit (10 );
1055- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1056- Assert .assertEquals (10 , readBuffer .position ());
1057- Assert .assertEquals (10 , readBuffer .limit ());
1058-
1059- readBuffer .flip ();
1060- Assert .assertEquals ("Buffer contents should match" ,
1061- ByteBuffer .wrap (TEST_ARRAY ), readBuffer );
1062- }
1063-
1064- @ Test
1065- public void testH2DirectReadFullyPositionAndLimit () throws Exception {
1066- final ByteBuffer readBuffer = ByteBuffer .allocateDirect (10 );
1067- readBuffer .position (3 );
1068- readBuffer .limit (7 );
1069- readBuffer .mark ();
1070-
1071- final FSDataInputStream hadoopStream = new FSDataInputStream (new H2MockInputStream (2 , 3 , 3 ));
1072-
1073- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1074- Assert .assertEquals (7 , readBuffer .position ());
1075- Assert .assertEquals (7 , readBuffer .limit ());
1076-
1077- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1078- Assert .assertEquals (7 , readBuffer .position ());
1079- Assert .assertEquals (7 , readBuffer .limit ());
1080-
1081- readBuffer .reset ();
1082- Assert .assertEquals ("Buffer contents should match" ,
1083- ByteBuffer .wrap (TEST_ARRAY , 0 , 4 ), readBuffer );
1084-
1085- readBuffer .position (7 );
1086- readBuffer .limit (10 );
1087- H2SeekableInputStream .readFully (hadoopStream , readBuffer );
1088- Assert .assertEquals (10 , readBuffer .position ());
1089- Assert .assertEquals (10 , readBuffer .limit ());
1090-
1091- readBuffer .reset ();
1092- Assert .assertEquals ("Buffer contents should match" ,
1093- ByteBuffer .wrap (TEST_ARRAY , 0 , 7 ), readBuffer );
1094- }
1095-
1096762}
0 commit comments