This project has retired. For details please refer to its Attic page.
TestCollections 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  package org.apache.giraph.types;
19  
20  import org.apache.giraph.types.ops.LongTypeOps;
21  import org.apache.giraph.types.ops.collections.BasicSet;
22  import org.apache.giraph.types.ops.collections.array.WArrayList;
23  import org.apache.hadoop.io.LongWritable;
24  import org.junit.Assert;
25  import org.junit.Ignore;
26  import org.junit.Test;
27  
28  /**
29   * Test basic collections
30   */
31  public class TestCollections {
32    @Test
33    public void testBasicSet() {
34      BasicSet<LongWritable> longSet = LongTypeOps.INSTANCE.createOpenHashSet();
35      long count = 13;
36      for (long i = 1, j = 0; j < count; i *= 10, j++) {
37        longSet.add(new LongWritable(i));
38      }
39      Assert.assertEquals(count, longSet.size());
40  
41      longSet.clear();
42      Assert.assertEquals(0, longSet.size());
43    }
44  
45    @Test
46    @Ignore("this test requires 32G to run")
47    public void testLargeBasicSet() {
48      long capacity = 1234567890;
49      BasicSet<LongWritable> longSet = LongTypeOps.INSTANCE.createOpenHashSet(capacity);
50      longSet.add(new LongWritable(capacity));
51      longSet.add(new LongWritable(capacity));
52      Assert.assertEquals(1, longSet.size());
53    }
54  
55    @Test
56    @Ignore("this test requires 1G to run")
57    public void testLargeBasicList() {
58      int capacity = 123456789;
59      WArrayList<LongWritable> longSet = LongTypeOps.INSTANCE.createArrayList(capacity);
60      longSet.addW(new LongWritable(capacity));
61      longSet.addW(new LongWritable(capacity));
62      Assert.assertEquals(2, longSet.size());
63    }
64  }