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.hadoop.hbase;
20  
21  import org.apache.hadoop.hbase.util.Bytes;
22  import org.junit.Assert;
23  import org.junit.Test;
24  import org.junit.experimental.categories.Category;
25  
26  @Category(SmallTests.class)
27  public class TestCellUtil {
28  
29    @Test
30    public void testOverlappingKeys() {
31      byte[] empty = HConstants.EMPTY_BYTE_ARRAY;
32      byte[] a = Bytes.toBytes("a");
33      byte[] b = Bytes.toBytes("b");
34      byte[] c = Bytes.toBytes("c");
35      byte[] d = Bytes.toBytes("d");
36  
37      // overlaps
38      Assert.assertTrue(CellUtil.overlappingKeys(a, b, a, b));
39      Assert.assertTrue(CellUtil.overlappingKeys(a, c, a, b));
40      Assert.assertTrue(CellUtil.overlappingKeys(a, b, a, c));
41      Assert.assertTrue(CellUtil.overlappingKeys(b, c, a, c));
42      Assert.assertTrue(CellUtil.overlappingKeys(a, c, b, c));
43      Assert.assertTrue(CellUtil.overlappingKeys(a, d, b, c));
44      Assert.assertTrue(CellUtil.overlappingKeys(b, c, a, d));
45  
46      Assert.assertTrue(CellUtil.overlappingKeys(empty, b, a, b));
47      Assert.assertTrue(CellUtil.overlappingKeys(empty, b, a, c));
48  
49      Assert.assertTrue(CellUtil.overlappingKeys(a, b, empty, b));
50      Assert.assertTrue(CellUtil.overlappingKeys(a, b, empty, c));
51  
52      Assert.assertTrue(CellUtil.overlappingKeys(a, empty, a, b));
53      Assert.assertTrue(CellUtil.overlappingKeys(a, empty, a, c));
54  
55      Assert.assertTrue(CellUtil.overlappingKeys(a, b, empty, empty));
56      Assert.assertTrue(CellUtil.overlappingKeys(empty, empty, a, b));
57  
58      // non overlaps
59      Assert.assertFalse(CellUtil.overlappingKeys(a, b, c, d));
60      Assert.assertFalse(CellUtil.overlappingKeys(c, d, a, b));
61  
62      Assert.assertFalse(CellUtil.overlappingKeys(b, c, c, d));
63      Assert.assertFalse(CellUtil.overlappingKeys(b, c, c, empty));
64      Assert.assertFalse(CellUtil.overlappingKeys(b, c, d, empty));
65      Assert.assertFalse(CellUtil.overlappingKeys(c, d, b, c));
66      Assert.assertFalse(CellUtil.overlappingKeys(c, empty, b, c));
67      Assert.assertFalse(CellUtil.overlappingKeys(d, empty, b, c));
68  
69      Assert.assertFalse(CellUtil.overlappingKeys(b, c, a, b));
70      Assert.assertFalse(CellUtil.overlappingKeys(b, c, empty, b));
71      Assert.assertFalse(CellUtil.overlappingKeys(b, c, empty, a));
72      Assert.assertFalse(CellUtil.overlappingKeys(a,b, b, c));
73      Assert.assertFalse(CellUtil.overlappingKeys(empty, b, b, c));
74      Assert.assertFalse(CellUtil.overlappingKeys(empty, a, b, c));
75    }
76  }