1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.utils.io;
2021import org.apache.giraph.conf.ImmutableClassesGiraphConfiguration;
22import org.apache.hadoop.conf.Configuration;
23import org.junit.Assert;
24import org.junit.Test;
2526import java.io.IOException;
2728publicclassTestBigDataIO {
29 @Test
30publicvoid testLargeByteArrays() throws IOException {
31 ImmutableClassesGiraphConfiguration conf =
32new ImmutableClassesGiraphConfiguration(new Configuration());
33 BigDataOutput output = new BigDataOutput(conf);
34 byte[] byteArray1 = new byte[(1 << 28) + 3];
35int 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];
40int pos2 = (1 << 26) + 5;
41 byteArray2[pos2] = 13;
42 output.write(byteArray2);
43 Assert.assertEquals(13, output.getNumberOfDataOutputs());
4445 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 }