-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-27194 Add test coverage for SimpleRpcServer (#4616)
Add test coverage for SimpleRpcServer. Improve the way we test both SimpleRpcServer and NettyRpcServer. Use LoadTestKVGenerator to generate random values with varying sizes between 1000 bytes and 1M bytes, and also to verify them when reading the values back. Add secure test coverage for both SimpleRpcServer and NettyRpcServer. Signed-off-by: Duo Zhang <[email protected]> Signed-off-by: Viraj Jasani <[email protected]>
- Loading branch information
Showing
4 changed files
with
351 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestSecureNettyRpcServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.ipc; | ||
|
||
import java.io.File; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.CommonConfigurationKeys; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
import org.apache.hadoop.hbase.TableNameTestRule; | ||
import org.apache.hadoop.hbase.security.HBaseKerberosUtils; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.testclassification.RPCTests; | ||
import org.apache.hadoop.minikdc.MiniKdc; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category({ RPCTests.class, MediumTests.class }) | ||
public class TestSecureNettyRpcServer extends TestNettyRpcServer { | ||
|
||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestSecureNettyRpcServer.class); | ||
|
||
private static File KEYTAB_FILE; | ||
private static MiniKdc KDC; | ||
private static String HOST = "localhost"; | ||
private static String PRINCIPAL; | ||
private static UserGroupInformation UGI; | ||
|
||
@Rule | ||
public TableNameTestRule name = new TableNameTestRule(); | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
TEST_UTIL = new HBaseTestingUtil(); | ||
KEYTAB_FILE = new File(TEST_UTIL.getDataTestDir("keytab").toUri().getPath()); | ||
KDC = TEST_UTIL.setupMiniKdc(KEYTAB_FILE); | ||
PRINCIPAL = "hbase/" + HOST; | ||
KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL); | ||
String principalName = PRINCIPAL + "@" + KDC.getRealm(); | ||
HBaseKerberosUtils.setPrincipalForTesting(principalName); | ||
Configuration conf = TEST_UTIL.getConfiguration(); | ||
HBaseKerberosUtils.setSecuredConfiguration(conf, principalName, principalName); | ||
UGI = login(KEYTAB_FILE.toString(), principalName); | ||
super.setup(); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
super.tearDown(); | ||
if (KDC != null) { | ||
KDC.stop(); | ||
} | ||
KEYTAB_FILE.delete(); | ||
TEST_UTIL.cleanupTestDir(); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void testNettyRpcServer() throws Exception { | ||
UGI.doAs(new PrivilegedExceptionAction<Void>() { | ||
@Override | ||
public Void run() throws Exception { | ||
doTest(name.getTableName()); | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
static UserGroupInformation login(String krbKeytab, String krbPrincipal) throws Exception { | ||
Configuration conf = new Configuration(); | ||
conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); | ||
UserGroupInformation.setConfiguration(conf); | ||
UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab); | ||
return UserGroupInformation.getLoginUser(); | ||
} | ||
|
||
} |
101 changes: 101 additions & 0 deletions
101
hbase-server/src/test/java/org/apache/hadoop/hbase/ipc/TestSecureSimpleRpcServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.hadoop.hbase.ipc; | ||
|
||
import java.io.File; | ||
import java.security.PrivilegedExceptionAction; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.fs.CommonConfigurationKeys; | ||
import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
import org.apache.hadoop.hbase.TableNameTestRule; | ||
import org.apache.hadoop.hbase.security.HBaseKerberosUtils; | ||
import org.apache.hadoop.hbase.testclassification.MediumTests; | ||
import org.apache.hadoop.hbase.testclassification.RPCTests; | ||
import org.apache.hadoop.minikdc.MiniKdc; | ||
import org.apache.hadoop.security.UserGroupInformation; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.experimental.categories.Category; | ||
|
||
@Category({ RPCTests.class, MediumTests.class }) | ||
public class TestSecureSimpleRpcServer extends TestSimpleRpcServer { | ||
|
||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestSecureSimpleRpcServer.class); | ||
|
||
private static File KEYTAB_FILE; | ||
private static MiniKdc KDC; | ||
private static String HOST = "localhost"; | ||
private static String PRINCIPAL; | ||
private static UserGroupInformation UGI; | ||
|
||
@Rule | ||
public TableNameTestRule name = new TableNameTestRule(); | ||
|
||
@BeforeClass | ||
public static void setupClass() throws Exception { | ||
TEST_UTIL = new HBaseTestingUtil(); | ||
KEYTAB_FILE = new File(TEST_UTIL.getDataTestDir("keytab").toUri().getPath()); | ||
KDC = TEST_UTIL.setupMiniKdc(KEYTAB_FILE); | ||
PRINCIPAL = "hbase/" + HOST; | ||
KDC.createPrincipal(KEYTAB_FILE, PRINCIPAL); | ||
String principalName = PRINCIPAL + "@" + KDC.getRealm(); | ||
HBaseKerberosUtils.setPrincipalForTesting(principalName); | ||
Configuration conf = TEST_UTIL.getConfiguration(); | ||
HBaseKerberosUtils.setSecuredConfiguration(conf, principalName, principalName); | ||
UGI = login(KEYTAB_FILE.toString(), principalName); | ||
TestSimpleRpcServer.setupClass(); | ||
|
||
} | ||
|
||
@AfterClass | ||
public static void tearDownClass() throws Exception { | ||
TestSimpleRpcServer.tearDownClass(); | ||
if (KDC != null) { | ||
KDC.stop(); | ||
} | ||
KEYTAB_FILE.delete(); | ||
TEST_UTIL.cleanupTestDir(); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void testSimpleRpcServer() throws Exception { | ||
UGI.doAs(new PrivilegedExceptionAction<Void>() { | ||
@Override | ||
public Void run() throws Exception { | ||
doTest(name.getTableName()); | ||
return null; | ||
} | ||
}); | ||
} | ||
|
||
static UserGroupInformation login(String krbKeytab, String krbPrincipal) throws Exception { | ||
Configuration conf = new Configuration(); | ||
conf.set(CommonConfigurationKeys.HADOOP_SECURITY_AUTHENTICATION, "kerberos"); | ||
UserGroupInformation.setConfiguration(conf); | ||
UserGroupInformation.loginUserFromKeytab(krbPrincipal, krbKeytab); | ||
return UserGroupInformation.getLoginUser(); | ||
} | ||
|
||
} |
Oops, something went wrong.