Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions hbase-thrift/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,17 @@
*/
package org.apache.hadoop.hbase.thrift;

import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ ClientTests.class, MediumTests.class })
@Tag(ClientTests.TAG)
@Tag(MediumTests.TAG)
public class TestBindExceptionHandling {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBindExceptionHandling.class);

private static final HBaseTestingUtil HTU = new HBaseTestingUtil();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,30 @@
package org.apache.hadoop.hbase.thrift;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Stream;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CompatibilitySingletonFactory;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseParameterizedTestTemplate;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.test.MetricsAssertHelper;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestTemplate;
import org.junit.jupiter.params.provider.Arguments;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Unit testing for CallQueue, a part of the org.apache.hadoop.hbase.thrift package.
*/
@Category({ ClientTests.class, SmallTests.class })
@RunWith(Parameterized.class)
@Tag(ClientTests.TAG)
@Tag(SmallTests.TAG)
@HBaseParameterizedTestTemplate
public class TestCallQueue {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestCallQueue.class);

private static final Logger LOG = LoggerFactory.getLogger(TestCallQueue.class);
private static final HBaseTestingUtil UTIL = new HBaseTestingUtil();

Expand All @@ -56,15 +51,14 @@ public class TestCallQueue {
private int elementsAdded;
private int elementsRemoved;

@Parameters
public static Collection<Object[]> getParameters() {
Collection<Object[]> parameters = new ArrayList<>();
public static Stream<Arguments> parameters() {
List<Arguments> params = new ArrayList<>();
for (int elementsAdded : new int[] { 100, 200, 300 }) {
for (int elementsRemoved : new int[] { 0, 20, 100 }) {
parameters.add(new Object[] { elementsAdded, elementsRemoved });
params.add(Arguments.of(elementsAdded, elementsRemoved));
}
}
return parameters;
return params.stream();
}

public TestCallQueue(int elementsAdded, int elementsRemoved) {
Expand All @@ -74,7 +68,7 @@ public TestCallQueue(int elementsAdded, int elementsRemoved) {

}

@Test
@TestTemplate
public void testPutTake() throws Exception {
ThriftMetrics metrics = createMetrics();
CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics);
Expand All @@ -87,7 +81,7 @@ public void testPutTake() throws Exception {
verifyMetrics(metrics, "timeInQueue_num_ops", elementsRemoved);
}

@Test
@TestTemplate
public void testOfferPoll() throws Exception {
ThriftMetrics metrics = createMetrics();
CallQueue callQueue = new CallQueue(new LinkedBlockingQueue<>(), metrics);
Expand Down Expand Up @@ -119,5 +113,4 @@ public void run() {
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,184 +17,27 @@
*/
package org.apache.hadoop.hbase.thrift;

import static org.apache.hadoop.hbase.thrift.TestThriftServerCmdLine.createBoundServer;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.function.Supplier;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.testclassification.ClientTests;
import org.apache.hadoop.hbase.testclassification.LargeTests;
import org.apache.hadoop.hbase.thrift.generated.Hbase;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManagerTestHelper;
import org.apache.hadoop.hbase.util.IncrementingEnvironmentEdge;
import org.apache.hadoop.hbase.util.TableDescriptorChecker;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.THttpClient;
import org.apache.thrift.transport.TTransportException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;

/**
* Start the HBase Thrift HTTP server on a random port through the command-line interface and talk
* to it from client side.
*/
@Category({ ClientTests.class, LargeTests.class })
public class TestThriftHttpServer {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestThriftHttpServer.class);

private static final Logger LOG = LoggerFactory.getLogger(TestThriftHttpServer.class);

protected static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

@BeforeClass
public static void setUpBeforeClass() throws Exception {
TEST_UTIL.getConfiguration().setBoolean(Constants.USE_HTTP_CONF_KEY, true);
TEST_UTIL.getConfiguration().setBoolean(TableDescriptorChecker.TABLE_SANITY_CHECKS, false);
TEST_UTIL.startMiniCluster();
// ensure that server time increments every time we do an operation, otherwise
// successive puts having the same timestamp will override each other
EnvironmentEdgeManagerTestHelper.injectEdge(new IncrementingEnvironmentEdge());
}

@AfterClass
public static void tearDownAfterClass() throws Exception {
TEST_UTIL.shutdownMiniCluster();
EnvironmentEdgeManager.reset();
}

@Test
public void testExceptionThrownWhenMisConfigured() throws IOException {
Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
conf.set("hbase.thrift.security.qop", "privacy");
conf.setBoolean("hbase.thrift.ssl.enabled", false);
ExpectedException thrown = ExpectedException.none();
ThriftServerRunner tsr = null;
try {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage(
"Thrift HTTP Server's QoP is privacy, " + "but hbase.thrift.ssl.enabled is false");
tsr = TestThriftServerCmdLine.createBoundServer(() -> new ThriftServer(conf));
fail("Thrift HTTP Server starts up even with wrong security configurations.");
} catch (Exception e) {
LOG.info("Expected!", e);
} finally {
if (tsr != null) {
tsr.close();
}
}
}
@Tag(ClientTests.TAG)
@Tag(LargeTests.TAG)
public class TestThriftHttpServer extends TestThriftHttpServerBase {

@Rule
public ExpectedException exception = ExpectedException.none();

@Test
public void testRunThriftServerWithHeaderBufferLength() throws Exception {
// Test thrift server with HTTP header length less than 64k
try {
runThriftServer(1024 * 63);
} catch (TTransportException tex) {
assertFalse(tex.getMessage().equals("HTTP Response code: 431"));
}

// Test thrift server with HTTP header length more than 64k, expect an exception
exception.expect(TTransportException.class);
exception.expectMessage("HTTP Response code: 431");
runThriftServer(1024 * 64);
@BeforeAll
public static void beforeAll() throws Exception {
setUpBeforeClass();
}

protected Supplier<ThriftServer> getThriftServerSupplier() {
return () -> new ThriftServer(TEST_UTIL.getConfiguration());
}

@Test
public void testRunThriftServer() throws Exception {
runThriftServer(0);
}

void runThriftServer(int customHeaderSize) throws Exception {
// Add retries in case we see stuff like connection reset
Exception clientSideException = null;
for (int i = 0; i < 10; i++) {
clientSideException = null;
ThriftServerRunner tsr = createBoundServer(getThriftServerSupplier());
String url = "http://" + HConstants.LOCALHOST + ":" + tsr.getThriftServer().listenPort;
try {
checkHttpMethods(url);
talkToThriftServer(url, customHeaderSize);
break;
} catch (Exception ex) {
clientSideException = ex;
LOG.info("Client-side Exception", ex);
} finally {
tsr.close();
tsr.join();
if (tsr.getRunException() != null) {
LOG.error("Invocation of HBase Thrift server threw exception", tsr.getRunException());
throw tsr.getRunException();
}
}
}

if (clientSideException != null) {
LOG.error("Thrift Client", clientSideException);
throw clientSideException;
}
}

private void checkHttpMethods(String url) throws Exception {
// HTTP TRACE method should be disabled for security
// See https://www.owasp.org/index.php/Cross_Site_Tracing
HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
conn.setRequestMethod("TRACE");
conn.connect();
Assert.assertEquals(conn.getResponseMessage(), HttpURLConnection.HTTP_FORBIDDEN,
conn.getResponseCode());
}

protected static volatile boolean tableCreated = false;

protected void talkToThriftServer(String url, int customHeaderSize) throws Exception {
THttpClient httpClient = new THttpClient(url);
httpClient.open();

if (customHeaderSize > 0) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customHeaderSize; i++) {
sb.append("a");
}
httpClient.setCustomHeader("User-Agent", sb.toString());
}

try {
TProtocol prot;
prot = new TBinaryProtocol(httpClient);
Hbase.Client client = new Hbase.Client(prot);
if (!tableCreated) {
TestThriftServer.createTestTables(client);
tableCreated = true;
}
TestThriftServer.checkTableList(client);
} finally {
httpClient.close();
}
@AfterAll
public static void afterAll() throws Exception {
tearDownAfterClass();
}
}
Loading