1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.giraph.utils.io;
20
21 import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22 import org.apache.hadoop.conf.Configuration;
23 import org.junit.Assert;
24 import org.junit.Test;
25
26 import java.io.IOException;
27
28 public class TestBigDataIO {
29 @Test
30 public void testLargeByteArrays() throws IOException {
31 ImmutableClassesGiraphConfiguration conf =
32 new ImmutableClassesGiraphConfiguration(new Configuration());
33 BigDataOutput output = new BigDataOutput(conf);
34 byte[] byteArray1 = new byte[(1 << 28) + 3];
35 int pos1 = (1 << 27) + 2;
36 byteArray1[pos1] = 17;
37 output.write(byteArray1);
38 Assert.assertEquals(9, output.getNumberOfDataOutputs());
39 byte[] byteArray2 = new byte[(1 << 27) - 1];
40 int pos2 = (1 << 26) + 5;
41 byteArray2[pos2] = 13;
42 output.write(byteArray2);
43 Assert.assertEquals(13, output.getNumberOfDataOutputs());
44
45 BigDataInput in = new BigDataInput(output);
46 byte[] byteArray3 = new byte[byteArray1.length];
47 in.readFully(byteArray3);
48 Assert.assertEquals(byteArray1[pos1], byteArray3[pos1]);
49 byte[] byteArray4 = new byte[byteArray2.length];
50 in.readFully(byteArray4);
51 Assert.assertEquals(byteArray2[pos2], byteArray4[pos2]);
52 }
53 }