001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.mapred; 019 020import static org.junit.jupiter.api.Assertions.assertEquals; 021import static org.junit.jupiter.api.Assertions.assertNotEquals; 022import static org.junit.jupiter.api.Assertions.assertTrue; 023 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.testclassification.MapReduceTests; 026import org.apache.hadoop.hbase.testclassification.SmallTests; 027import org.apache.hadoop.hbase.util.Bytes; 028import org.junit.jupiter.api.Tag; 029import org.junit.jupiter.api.Test; 030import org.junit.jupiter.api.TestInfo; 031 032@Tag(MapReduceTests.TAG) 033@Tag(SmallTests.TAG) 034public class TestSplitTable { 035 036 @Test 037 @SuppressWarnings({ "deprecation", "SelfComparison" }) 038 public void testSplitTableCompareTo() { 039 TableSplit aTableSplit = new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("aaa"), 040 Bytes.toBytes("ddd"), "locationA"); 041 042 TableSplit bTableSplit = new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("iii"), 043 Bytes.toBytes("kkk"), "locationA"); 044 045 TableSplit cTableSplit = new TableSplit(Bytes.toBytes("tableA"), Bytes.toBytes("lll"), 046 Bytes.toBytes("zzz"), "locationA"); 047 048 assertEquals(0, aTableSplit.compareTo(aTableSplit)); 049 assertEquals(0, bTableSplit.compareTo(bTableSplit)); 050 assertEquals(0, cTableSplit.compareTo(cTableSplit)); 051 052 assertTrue(aTableSplit.compareTo(bTableSplit) < 0); 053 assertTrue(bTableSplit.compareTo(aTableSplit) > 0); 054 055 assertTrue(aTableSplit.compareTo(cTableSplit) < 0); 056 assertTrue(cTableSplit.compareTo(aTableSplit) > 0); 057 058 assertTrue(bTableSplit.compareTo(cTableSplit) < 0); 059 assertTrue(cTableSplit.compareTo(bTableSplit) > 0); 060 061 assertTrue(cTableSplit.compareTo(aTableSplit) > 0); 062 } 063 064 @Test 065 @SuppressWarnings("deprecation") 066 public void testSplitTableEquals() { 067 byte[] tableA = Bytes.toBytes("tableA"); 068 byte[] aaa = Bytes.toBytes("aaa"); 069 byte[] ddd = Bytes.toBytes("ddd"); 070 String locationA = "locationA"; 071 072 TableSplit tablesplit = new TableSplit(tableA, aaa, ddd, locationA); 073 074 TableSplit tableB = new TableSplit(Bytes.toBytes("tableB"), aaa, ddd, locationA); 075 assertNotEquals(tablesplit.hashCode(), tableB.hashCode()); 076 assertNotEquals(tablesplit, tableB); 077 078 TableSplit startBbb = new TableSplit(tableA, Bytes.toBytes("bbb"), ddd, locationA); 079 assertNotEquals(tablesplit.hashCode(), startBbb.hashCode()); 080 assertNotEquals(tablesplit, startBbb); 081 082 TableSplit endEee = new TableSplit(tableA, aaa, Bytes.toBytes("eee"), locationA); 083 assertNotEquals(tablesplit.hashCode(), endEee.hashCode()); 084 assertNotEquals(tablesplit, endEee); 085 086 TableSplit locationB = new TableSplit(tableA, aaa, ddd, "locationB"); 087 assertNotEquals(tablesplit.hashCode(), locationB.hashCode()); 088 assertNotEquals(tablesplit, locationB); 089 090 TableSplit same = new TableSplit(tableA, aaa, ddd, locationA); 091 assertEquals(tablesplit.hashCode(), same.hashCode()); 092 assertEquals(tablesplit, same); 093 } 094 095 @Test 096 @SuppressWarnings("deprecation") 097 public void testToString(TestInfo testInfo) { 098 TableSplit split = new TableSplit(TableName.valueOf(testInfo.getTestMethod().get().getName()), 099 Bytes.toBytes("row-start"), Bytes.toBytes("row-end"), "location"); 100 String str = "HBase table split(table name: " + testInfo.getTestMethod().get().getName() 101 + ", start row: row-start, " + "end row: row-end, region location: location)"; 102 assertEquals(str, split.toString()); 103 104 split = new TableSplit((TableName) null, null, null, null); 105 str = "HBase table split(table name: null, start row: null, " 106 + "end row: null, region location: null)"; 107 assertEquals(str, split.toString()); 108 } 109}