source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestSortedRanges.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.9 KB
Line 
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 */
18package org.apache.hadoop.mapred;
19
20import java.util.Iterator;
21
22import junit.framework.TestCase;
23
24import org.apache.commons.logging.Log;
25import org.apache.commons.logging.LogFactory;
26import org.apache.hadoop.mapred.SortedRanges.Range;
27
28public class TestSortedRanges extends TestCase {
29  private static final Log LOG = 
30    LogFactory.getLog(TestSortedRanges.class);
31 
32  public void testAdd() {
33    SortedRanges sr = new SortedRanges();
34    sr.add(new Range(2,9));
35    assertEquals(9, sr.getIndicesCount());
36   
37    sr.add(new SortedRanges.Range(3,5));
38    assertEquals(9, sr.getIndicesCount());
39   
40    sr.add(new SortedRanges.Range(7,1));
41    assertEquals(9, sr.getIndicesCount());
42   
43    sr.add(new Range(1,12));
44    assertEquals(12, sr.getIndicesCount());
45   
46    sr.add(new Range(7,9));
47    assertEquals(15, sr.getIndicesCount());
48   
49    sr.add(new Range(31,10));
50    sr.add(new Range(51,10));
51    sr.add(new Range(66,10));
52    assertEquals(45, sr.getIndicesCount());
53   
54    sr.add(new Range(21,50));
55    assertEquals(70, sr.getIndicesCount());
56   
57    LOG.debug(sr);
58   
59    Iterator<Long> it = sr.skipRangeIterator();
60    int i = 0;
61    assertEquals(i, it.next().longValue());
62    for(i=16;i<21;i++) {
63      assertEquals(i, it.next().longValue());
64    }
65    assertEquals(76, it.next().longValue());
66    assertEquals(77, it.next().longValue());
67   
68  }
69 
70  public void testRemove() {
71    SortedRanges sr = new SortedRanges();
72    sr.add(new Range(2,19));
73    assertEquals(19, sr.getIndicesCount());
74   
75    sr.remove(new SortedRanges.Range(15,8));
76    assertEquals(13, sr.getIndicesCount());
77   
78    sr.remove(new SortedRanges.Range(6,5));
79    assertEquals(8, sr.getIndicesCount());
80   
81    sr.remove(new SortedRanges.Range(8,4));
82    assertEquals(7, sr.getIndicesCount());
83   
84    sr.add(new Range(18,5));
85    assertEquals(12, sr.getIndicesCount());
86   
87    sr.add(new Range(25,1));
88    assertEquals(13, sr.getIndicesCount());
89   
90    sr.remove(new SortedRanges.Range(7,24));
91    assertEquals(4, sr.getIndicesCount());
92   
93    sr.remove(new SortedRanges.Range(5,1));
94    assertEquals(3, sr.getIndicesCount());
95   
96    LOG.debug(sr);
97  }
98
99}
Note: See TracBrowser for help on using the repository browser.