22
22
import java .io .DataOutputStream ;
23
23
import java .io .IOException ;
24
24
25
- import org .apache .hadoop .io .Text ;
26
25
import org .testng .Assert ;
27
26
import org .testng .annotations .Test ;
28
27
@@ -35,9 +34,7 @@ public class TextSerializerTest {
35
34
private static final String [] textsToSerialize = new String []{"abracadabra" , Strings .repeat ("longString" , 128000 )};
36
35
37
36
@ Test
38
- public void testSerialize ()
39
- throws IOException {
40
-
37
+ public void testWriteAndRead () throws IOException {
41
38
// Use our serializer, verify Hadoop deserializer can read it back
42
39
for (String textToSerialize : textsToSerialize ) {
43
40
ByteArrayOutputStream bOs = new ByteArrayOutputStream ();
@@ -49,31 +46,8 @@ public void testSerialize()
49
46
ByteArrayInputStream bIn = new ByteArrayInputStream (bOs .toByteArray ());
50
47
DataInputStream dataInputStream = new DataInputStream (bIn );
51
48
52
- Text hadoopText = new Text ();
53
- hadoopText .readFields (dataInputStream );
54
-
55
- Assert .assertEquals (hadoopText .toString (), textToSerialize );
56
- }
57
- }
58
-
59
- @ Test
60
- public void testDeserialize () throws IOException {
61
- // Use Hadoop's serializer, verify our deserializer can read the string back
62
- for (String textToSerialize : textsToSerialize ) {
63
- ByteArrayOutputStream bOs = new ByteArrayOutputStream ();
64
- DataOutputStream dataOutputStream = new DataOutputStream (bOs );
65
-
66
- Text hadoopText = new Text ();
67
- hadoopText .set (textToSerialize );
68
- hadoopText .write (dataOutputStream );
69
- dataOutputStream .close ();
70
-
71
- ByteArrayInputStream bIn = new ByteArrayInputStream (bOs .toByteArray ());
72
- DataInputStream dataInputStream = new DataInputStream (bIn );
73
-
74
- String deserializedString = TextSerializer .readTextAsString (dataInputStream );
75
-
76
- Assert .assertEquals (deserializedString , textToSerialize );
49
+ String deserializedText = TextSerializer .readTextAsString (dataInputStream );
50
+ Assert .assertEquals (deserializedText , textToSerialize );
77
51
}
78
52
}
79
53
}
0 commit comments