This project has retired. For details please refer to its Attic page.
TestLongAggregators 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.aggregators;
19  
20  import static org.junit.Assert.assertEquals;
21  import static org.junit.Assert.assertNotNull;
22  
23  import org.apache.hadoop.io.LongWritable;
24  import org.junit.Test;
25  
26  public class TestLongAggregators {
27  
28    @Test
29    public void testMaxAggregator() {
30      LongMaxAggregator max = new LongMaxAggregator();
31      max.aggregate(new LongWritable(2L));
32      max.aggregate(new LongWritable(3L));
33      assertEquals(3L, max.getAggregatedValue().get());
34      max.setAggregatedValue(new LongWritable(1L));
35      assertEquals(1L, max.getAggregatedValue().get());
36      LongWritable lw = max.createInitialValue();
37      assertNotNull(lw);
38    }
39  
40    @Test
41    public void testMinAggregator() {
42      LongMinAggregator min = new LongMinAggregator();
43      min.aggregate(new LongWritable(3L));
44      min.aggregate(new LongWritable(2L));
45      assertEquals(2L, min.getAggregatedValue().get());
46      min.setAggregatedValue(new LongWritable(3L));
47      assertEquals(3L, min.getAggregatedValue().get());
48      LongWritable lw = min.createInitialValue();
49      assertNotNull(lw);
50    }
51  
52    @Test
53    public void testOverwriteAggregator() {
54      LongOverwriteAggregator overwrite = new LongOverwriteAggregator();
55      overwrite.aggregate(new LongWritable(1L));
56      assertEquals(1L, overwrite.getAggregatedValue().get());
57      overwrite.aggregate(new LongWritable(2L));
58      assertEquals(2L, overwrite.getAggregatedValue().get());
59      overwrite.setAggregatedValue(new LongWritable(3L));
60      assertEquals(3L, overwrite.getAggregatedValue().get());
61      LongWritable lw = overwrite.createInitialValue();
62      assertNotNull(lw);
63    }
64    
65    @Test
66    public void testProductAggregator() {
67      LongProductAggregator product = new LongProductAggregator();
68      product.aggregate(new LongWritable(6L));
69      product.aggregate(new LongWritable(7L));
70      assertEquals(42L, product.getAggregatedValue().get());
71      product.setAggregatedValue(new LongWritable(1L));
72      assertEquals(1L, product.getAggregatedValue().get());
73      LongWritable lw = product.createInitialValue();
74      assertNotNull(lw);
75    }
76  
77    @Test
78    public void testSumAggregator() {
79      LongSumAggregator sum = new LongSumAggregator();
80      sum.aggregate(new LongWritable(1L));
81      sum.aggregate(new LongWritable(2L));
82      assertEquals(3L, sum.getAggregatedValue().get());
83      sum.setAggregatedValue(new LongWritable(4L));
84      assertEquals(4L, sum.getAggregatedValue().get());
85      LongWritable lw = sum.createInitialValue();
86      assertNotNull(lw);
87    }
88  
89  }