View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.mapred;
20  
21  import static org.junit.Assert.assertFalse;
22  import static org.junit.Assert.assertTrue;
23  
24  import org.apache.hadoop.hbase.SmallTests;
25  import org.apache.hadoop.hbase.util.Bytes;
26  import org.junit.Test;
27  import org.junit.experimental.categories.Category;
28  
29  @Category(SmallTests.class)
30  public class TestSplitTable {
31  
32    @Test
33    @SuppressWarnings("deprecation")
34    public void testSplitTableCompareTo() {
35      TableSplit aTableSplit = new TableSplit(Bytes.toBytes("tableA"),
36          Bytes.toBytes("aaa"), Bytes.toBytes("ddd"), "locationA");
37  
38      TableSplit bTableSplit = new TableSplit(Bytes.toBytes("tableA"),
39          Bytes.toBytes("iii"), Bytes.toBytes("kkk"), "locationA");
40  
41      TableSplit cTableSplit = new TableSplit(Bytes.toBytes("tableA"),
42          Bytes.toBytes("lll"), Bytes.toBytes("zzz"), "locationA");
43  
44      assertTrue(aTableSplit.compareTo(aTableSplit) == 0);
45      assertTrue(bTableSplit.compareTo(bTableSplit) == 0);
46      assertTrue(cTableSplit.compareTo(cTableSplit) == 0);
47  
48      assertTrue(aTableSplit.compareTo(bTableSplit) < 0);
49      assertTrue(bTableSplit.compareTo(aTableSplit) > 0);
50  
51      assertTrue(aTableSplit.compareTo(cTableSplit) < 0);
52      assertTrue(cTableSplit.compareTo(aTableSplit) > 0);
53  
54      assertTrue(bTableSplit.compareTo(cTableSplit) < 0);
55      assertTrue(cTableSplit.compareTo(bTableSplit) > 0);
56  
57      assertTrue(cTableSplit.compareTo(aTableSplit) > 0);
58    }
59  
60    @Test
61    @SuppressWarnings("deprecation")
62    public void testSplitTableEquals() {
63      assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
64          Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
65          .toBytes("tableB"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
66          "locationA")));
67  
68      assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
69          Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
70          .toBytes("tableA"), Bytes.toBytes("bbb"), Bytes.toBytes("ddd"),
71          "locationA")));
72  
73      assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
74          Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
75          .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("eee"),
76          "locationA")));
77  
78      assertFalse(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
79          Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
80          .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
81          "locationB")));
82  
83      assertTrue(new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"),
84          Bytes.toBytes("ddd"), "locationA").equals(new TableSplit(Bytes
85          .toBytes("tableA"), Bytes.toBytes("aaa"), Bytes.toBytes("ddd"),
86          "locationA")));
87    }
88  }