Skip to content

Commit 9d4fae0

Browse files
committed
HBASE-23665: Split unit tests from TestTableName into a separate test-only class.
1 parent 0bf933b commit 9d4fae0

File tree

10 files changed

+112
-101
lines changed

10 files changed

+112
-101
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.hadoop.hbase;
19+
20+
import org.junit.rules.TestWatcher;
21+
import org.junit.runner.Description;
22+
23+
/**
24+
* Returns a {@code byte[]} containing the name of the currently running test method.
25+
*/
26+
public class TableNameTestRule extends TestWatcher {
27+
28+
private TableName tableName;
29+
30+
/**
31+
* Invoked when a test is about to start
32+
*/
33+
@Override
34+
protected void starting(Description description) {
35+
tableName = TableName.valueOf(description.getMethodName());
36+
}
37+
38+
public TableName getTableName() {
39+
return tableName;
40+
}
41+
}
Lines changed: 55 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one
33
* or more contributor license agreements. See the NOTICE file
44
* distributed with this work for additional information
@@ -21,98 +21,35 @@
2121
import static org.junit.Assert.assertEquals;
2222
import static org.junit.Assert.assertSame;
2323
import static org.junit.Assert.fail;
24-
2524
import java.nio.ByteBuffer;
2625
import java.util.HashMap;
2726
import java.util.Map;
28-
import org.apache.hadoop.hbase.testclassification.MediumTests;
2927
import org.apache.hadoop.hbase.testclassification.MiscTests;
28+
import org.apache.hadoop.hbase.testclassification.SmallTests;
3029
import org.apache.hadoop.hbase.util.Bytes;
3130
import org.junit.ClassRule;
3231
import org.junit.Test;
3332
import org.junit.experimental.categories.Category;
34-
import org.junit.rules.TestWatcher;
35-
import org.junit.runner.Description;
3633

3734
/**
38-
* Returns a {@code byte[]} containing the name of the currently running test method.
35+
* Tests for various kinds of TableNames.
3936
*/
40-
@Category({MiscTests.class, MediumTests.class})
41-
public class TestTableName extends TestWatcher {
42-
37+
@Category({MiscTests.class, SmallTests.class})
38+
public class TestTableName {
4339
@ClassRule
4440
public static final HBaseClassTestRule CLASS_RULE =
4541
HBaseClassTestRule.forClass(TestTableName.class);
4642

47-
private TableName tableName;
48-
49-
/**
50-
* Invoked when a test is about to start
51-
*/
52-
@Override
53-
protected void starting(Description description) {
54-
tableName = TableName.valueOf(description.getMethodName());
55-
}
56-
57-
public TableName getTableName() {
58-
return tableName;
59-
}
60-
61-
String[] emptyNames = {"", " "};
62-
String[] invalidNamespace = {":a", "%:a"};
63-
String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
43+
private static String[] emptyNames = {"", " "};
44+
private static String[] invalidNamespace = {":a", "%:a"};
45+
private static String[] legalTableNames = {"foo", "with-dash_under.dot", "_under_start_ok",
6446
"with-dash.with_underscore", "02-01-2012.my_table_01-02", "xyz._mytable_", "9_9_0.table_02",
6547
"dot1.dot2.table", "new.-mytable", "with-dash.with.dot", "legal..t2", "legal..legal.t2",
6648
"trailingdots..", "trailing.dots...", "ns:mytable", "ns:_mytable_", "ns:my_table_01-02"};
67-
String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal", "spaces not ok",
68-
"-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
49+
private static String[] illegalTableNames = {".dot_start_illegal", "-dash_start_illegal",
50+
"spaces not ok", "-dash-.start_illegal", "new.table with space", "01 .table", "ns:-illegaldash",
6951
"new:.illegaldot", "new:illegalcolon1:", "new:illegalcolon1:2"};
7052

71-
72-
@Test(expected = IllegalArgumentException.class)
73-
public void testInvalidNamespace() {
74-
for (String tn : invalidNamespace) {
75-
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
76-
fail("invalid namespace " + tn
77-
+ " should have failed with IllegalArgumentException for namespace");
78-
}
79-
}
80-
81-
@Test(expected = IllegalArgumentException.class)
82-
public void testEmptyNamespaceName() {
83-
for (String nn : emptyNames) {
84-
TableName.isLegalNamespaceName(Bytes.toBytes(nn));
85-
fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
86-
}
87-
}
88-
89-
@Test(expected = IllegalArgumentException.class)
90-
public void testEmptyTableName() {
91-
for (String tn : emptyNames) {
92-
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
93-
fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
94-
}
95-
}
96-
97-
@Test
98-
public void testLegalHTableNames() {
99-
for (String tn : legalTableNames) {
100-
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
101-
}
102-
}
103-
104-
@Test
105-
public void testIllegalHTableNames() {
106-
for (String tn : illegalTableNames) {
107-
try {
108-
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
109-
fail("invalid tablename " + tn + " should have failed");
110-
} catch (Exception e) {
111-
// expected
112-
}
113-
}
114-
}
115-
11653
static class Names {
11754
String ns;
11855
byte[] nsb;
@@ -147,7 +84,6 @@ public boolean equals(Object o) {
14784
if (!tn.equals(names.tn)) {
14885
return false;
14986
}
150-
15187
return true;
15288
}
15389

@@ -159,7 +95,7 @@ public int hashCode() {
15995
}
16096
}
16197

162-
Names[] names = new Names[] {
98+
private static Names[] names = new Names[] {
16399
new Names("n1", "n1"),
164100
new Names("n2", "n2"),
165101
new Names("table1", "table1"),
@@ -172,9 +108,52 @@ public int hashCode() {
172108
new Names("n2", "table2")
173109
};
174110

111+
@Test(expected = IllegalArgumentException.class)
112+
public void testInvalidNamespace() {
113+
for (String tn : invalidNamespace) {
114+
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
115+
fail("invalid namespace " + tn
116+
+ " should have failed with IllegalArgumentException for namespace");
117+
}
118+
}
119+
120+
@Test(expected = IllegalArgumentException.class)
121+
public void testEmptyNamespaceName() {
122+
for (String nn : emptyNames) {
123+
TableName.isLegalNamespaceName(Bytes.toBytes(nn));
124+
fail("invalid Namespace name " + nn + " should have failed with IllegalArgumentException");
125+
}
126+
}
127+
128+
@Test(expected = IllegalArgumentException.class)
129+
public void testEmptyTableName() {
130+
for (String tn : emptyNames) {
131+
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
132+
fail("invalid tablename " + tn + " should have failed with IllegalArgumentException");
133+
}
134+
}
135+
175136
@Test
176-
public void testValueOf() {
137+
public void testLegalHTableNames() {
138+
for (String tn : legalTableNames) {
139+
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
140+
}
141+
}
177142

143+
@Test
144+
public void testIllegalHTableNames() {
145+
for (String tn : illegalTableNames) {
146+
try {
147+
TableName.isLegalFullyQualifiedTableName(Bytes.toBytes(tn));
148+
fail("invalid tablename " + tn + " should have failed");
149+
} catch (Exception e) {
150+
// expected
151+
}
152+
}
153+
}
154+
155+
@Test
156+
public void testValueOf() {
178157
Map<String, TableName> inCache = new HashMap<>();
179158
// fill cache
180159
for (Names name : names) {
@@ -188,7 +167,6 @@ public void testValueOf() {
188167
assertSame(inCache.get(name.nn), validateNames(TableName.valueOf(
189168
ByteBuffer.wrap(name.nsb), ByteBuffer.wrap(name.tnb)), name));
190169
}
191-
192170
}
193171

194172
private TableName validateNames(TableName expected, Names names) {
@@ -200,5 +178,4 @@ private TableName validateNames(TableName expected, Names names) {
200178
assertArrayEquals(expected.getNamespace(), names.nsb);
201179
return expected;
202180
}
203-
204181
}

hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestScannerRetriableFailure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.apache.hadoop.hbase.HBaseClassTestRule;
3131
import org.apache.hadoop.hbase.HBaseTestingUtility;
3232
import org.apache.hadoop.hbase.TableName;
33-
import org.apache.hadoop.hbase.TestTableName;
33+
import org.apache.hadoop.hbase.TableNameTestRule;
3434
import org.apache.hadoop.hbase.client.Durability;
3535
import org.apache.hadoop.hbase.client.Put;
3636
import org.apache.hadoop.hbase.client.Result;
@@ -68,7 +68,7 @@ public class TestScannerRetriableFailure {
6868
private static final String FAMILY_NAME_STR = "f";
6969
private static final byte[] FAMILY_NAME = Bytes.toBytes(FAMILY_NAME_STR);
7070

71-
@Rule public TestTableName TEST_TABLE = new TestTableName();
71+
@Rule public TableNameTestRule TEST_TABLE = new TableNameTestRule();
7272

7373
public static class FaultyScannerObserver implements RegionCoprocessor, RegionObserver {
7474
private int faults = 0;

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestAccessController2.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.junit.Assert.assertFalse;
2323
import static org.junit.Assert.assertNotNull;
2424
import static org.junit.Assert.assertTrue;
25-
2625
import java.util.Arrays;
2726
import java.util.List;
2827
import org.apache.hadoop.conf.Configuration;
@@ -34,8 +33,8 @@
3433
import org.apache.hadoop.hbase.HTableDescriptor;
3534
import org.apache.hadoop.hbase.NamespaceDescriptor;
3635
import org.apache.hadoop.hbase.TableName;
36+
import org.apache.hadoop.hbase.TableNameTestRule;
3737
import org.apache.hadoop.hbase.TableNotFoundException;
38-
import org.apache.hadoop.hbase.TestTableName;
3938
import org.apache.hadoop.hbase.client.Admin;
4039
import org.apache.hadoop.hbase.client.Connection;
4140
import org.apache.hadoop.hbase.client.ConnectionFactory;
@@ -105,7 +104,7 @@ public class TestAccessController2 extends SecureTestUtil {
105104
private static User TESTGROUP2_USER1;
106105

107106
@Rule
108-
public TestTableName TEST_TABLE = new TestTableName();
107+
public TableNameTestRule TEST_TABLE = new TableNameTestRule();
109108
private String namespace = "testNamespace";
110109
private String tname = namespace + ":testtable1";
111110
private TableName tableName = TableName.valueOf(tname);

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLWithMultipleVersions.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.fail;
22-
2322
import java.io.IOException;
2423
import java.security.PrivilegedExceptionAction;
2524
import java.util.HashMap;
@@ -31,8 +30,8 @@
3130
import org.apache.hadoop.hbase.HBaseTestingUtility;
3231
import org.apache.hadoop.hbase.HColumnDescriptor;
3332
import org.apache.hadoop.hbase.HTableDescriptor;
33+
import org.apache.hadoop.hbase.TableNameTestRule;
3434
import org.apache.hadoop.hbase.TableNotFoundException;
35-
import org.apache.hadoop.hbase.TestTableName;
3635
import org.apache.hadoop.hbase.client.Admin;
3736
import org.apache.hadoop.hbase.client.Connection;
3837
import org.apache.hadoop.hbase.client.ConnectionFactory;
@@ -71,7 +70,7 @@ public class TestCellACLWithMultipleVersions extends SecureTestUtil {
7170
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLWithMultipleVersions.class);
7271

7372
@Rule
74-
public TestTableName TEST_TABLE = new TestTableName();
73+
public TableNameTestRule TEST_TABLE = new TableNameTestRule();
7574
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
7675
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
7776
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestCellACLs.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.hadoop.hbase.security.access;
1919

2020
import static org.junit.Assert.assertEquals;
21-
2221
import java.util.HashMap;
2322
import java.util.List;
2423
import java.util.Map;
@@ -31,8 +30,8 @@
3130
import org.apache.hadoop.hbase.HColumnDescriptor;
3231
import org.apache.hadoop.hbase.HConstants;
3332
import org.apache.hadoop.hbase.HTableDescriptor;
33+
import org.apache.hadoop.hbase.TableNameTestRule;
3434
import org.apache.hadoop.hbase.TableNotFoundException;
35-
import org.apache.hadoop.hbase.TestTableName;
3635
import org.apache.hadoop.hbase.client.Admin;
3736
import org.apache.hadoop.hbase.client.Connection;
3837
import org.apache.hadoop.hbase.client.ConnectionFactory;
@@ -62,7 +61,6 @@
6261
import org.junit.experimental.categories.Category;
6362
import org.slf4j.Logger;
6463
import org.slf4j.LoggerFactory;
65-
6664
import org.apache.hbase.thirdparty.com.google.common.collect.Lists;
6765

6866
@Category({SecurityTests.class, LargeTests.class})
@@ -75,7 +73,7 @@ public class TestCellACLs extends SecureTestUtil {
7573
private static final Logger LOG = LoggerFactory.getLogger(TestCellACLs.class);
7674

7775
@Rule
78-
public TestTableName TEST_TABLE = new TestTableName();
76+
public TableNameTestRule TEST_TABLE = new TableNameTestRule();
7977
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
8078
private static final byte[] TEST_FAMILY = Bytes.toBytes("f1");
8179
private static final byte[] TEST_ROW = Bytes.toBytes("cellpermtest");

hbase-server/src/test/java/org/apache/hadoop/hbase/security/access/TestScanEarlyTermination.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@
2020
import static org.junit.Assert.assertEquals;
2121
import static org.junit.Assert.assertFalse;
2222
import static org.junit.Assert.assertTrue;
23-
2423
import org.apache.hadoop.conf.Configuration;
2524
import org.apache.hadoop.hbase.Coprocessor;
2625
import org.apache.hadoop.hbase.HBaseClassTestRule;
2726
import org.apache.hadoop.hbase.HBaseTestingUtility;
2827
import org.apache.hadoop.hbase.HColumnDescriptor;
2928
import org.apache.hadoop.hbase.HConstants;
3029
import org.apache.hadoop.hbase.HTableDescriptor;
30+
import org.apache.hadoop.hbase.TableNameTestRule;
3131
import org.apache.hadoop.hbase.TableNotFoundException;
32-
import org.apache.hadoop.hbase.TestTableName;
3332
import org.apache.hadoop.hbase.client.Admin;
3433
import org.apache.hadoop.hbase.client.Connection;
3534
import org.apache.hadoop.hbase.client.ConnectionFactory;
@@ -65,7 +64,7 @@ public class TestScanEarlyTermination extends SecureTestUtil {
6564
private static final Logger LOG = LoggerFactory.getLogger(TestScanEarlyTermination.class);
6665

6766
@Rule
68-
public TestTableName TEST_TABLE = new TestTableName();
67+
public TableNameTestRule TEST_TABLE = new TableNameTestRule();
6968
private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
7069
private static final byte[] TEST_FAMILY1 = Bytes.toBytes("f1");
7170
private static final byte[] TEST_FAMILY2 = Bytes.toBytes("f2");

0 commit comments

Comments
 (0)