This project has retired. For details please refer to its Attic page.
TestBigDataIO xref
View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * 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 and
16   * limitations under the License.
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  }