Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.regionserver.DisabledRegionSplitPolicy;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.LoadTestKVGenerator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;

public abstract class AbstractTestRpcServer {

private static final byte[] FAMILY = Bytes.toBytes("f");
private static final byte[] QUALIFIER = Bytes.toBytes("q");
private static final int NUM_ROWS = 100;
private static final int MIN_LEN = 1000;
private static final int MAX_LEN = 1000000;
protected static final LoadTestKVGenerator GENERATOR = new LoadTestKVGenerator(MIN_LEN, MAX_LEN);
protected static HBaseTestingUtil TEST_UTIL;
protected TableName tableName;

@BeforeEach
public void setUpTest(TestInfo testInfo) {
tableName = TableName.valueOf(testInfo.getTestMethod().get().getName());
}

protected void doTest(TableName tableName) throws Exception {
// Splitting just complicates the test scenario, disable it
final TableDescriptor desc = TableDescriptorBuilder.newBuilder(tableName)
.setRegionSplitPolicyClassName(DisabledRegionSplitPolicy.class.getName()).build();
try (Table table =
TEST_UTIL.createTable(desc, new byte[][] { FAMILY }, TEST_UTIL.getConfiguration())) {
// put some test data
for (int i = 0; i < NUM_ROWS; i++) {
final byte[] rowKey = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
final byte[] v = GENERATOR.generateRandomSizeValue(rowKey, QUALIFIER);
table.put(new Put(rowKey).addColumn(FAMILY, QUALIFIER, v));
}
// read to verify it.
for (int i = 0; i < NUM_ROWS; i++) {
final byte[] rowKey = Bytes.toBytes(LoadTestKVGenerator.md5PrefixedKey(i));
final Result r = table.get(new Get(rowKey).addColumn(FAMILY, QUALIFIER));
assertNotNull(r, "Result was empty");
final byte[] v = r.getValue(FAMILY, QUALIFIER);
assertNotNull(v, "Result did not contain expected value");
assertTrue(LoadTestKVGenerator.verify(v, rowKey, QUALIFIER), "Value was not verified");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,42 @@
*/
package org.apache.hadoop.hbase.ipc;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.apache.hbase.thirdparty.com.google.common.base.Charsets;
import org.apache.hbase.thirdparty.com.google.common.io.Files;

@Category({ RPCTests.class, SmallTests.class })
@Tag(RPCTests.TAG)
@Tag(SmallTests.TAG)
public class TestBufferChain {

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

private File tmpFile;

private static final byte[][] HELLO_WORLD_CHUNKS =
new byte[][] { "hello".getBytes(Charsets.UTF_8), " ".getBytes(Charsets.UTF_8),
"world".getBytes(Charsets.UTF_8) };

@Before
@BeforeEach
public void setup() throws IOException {
tmpFile = File.createTempFile("TestBufferChain", "txt");
}

@After
@AfterEach
public void teardown() {
tmpFile.delete();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
import static org.hamcrest.Matchers.hasItem;

import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.sdk.testing.junit4.OpenTelemetryRule;
import io.opentelemetry.sdk.testing.junit5.OpenTelemetryExtension;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.CallDroppedException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.MatcherPredicate;
import org.apache.hadoop.hbase.Waiter;
Expand All @@ -41,31 +40,26 @@
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.trace.TraceUtil;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.mockito.Mockito;

@Category({ RPCTests.class, SmallTests.class })
@Tag(RPCTests.TAG)
@Tag(SmallTests.TAG)
public class TestCallRunner {

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

@Rule
public TestName testName = new TestName();

@Rule
public OpenTelemetryRule otelRule = OpenTelemetryRule.create();
@RegisterExtension
public static final OpenTelemetryExtension otelRule = OpenTelemetryExtension.create();

private Configuration conf = null;
private String testMethodName;

@Before
public void before() {
@BeforeEach
public void before(TestInfo testInfo) {
testMethodName = testInfo.getTestMethod().get().getName();
final HBaseTestingUtil util = new HBaseTestingUtil();
conf = util.getConfiguration();
}
Expand All @@ -83,13 +77,13 @@ public void testSimpleCall() {
CallRunner cr = new CallRunner(mockRpcServer, mockCall);
cr.setStatus(new MonitoredRPCHandlerImpl("test"));
cr.run();
}, testName.getMethodName());
}, testMethodName);

Waiter.waitFor(conf, TimeUnit.SECONDS.toMillis(5), new MatcherPredicate<>(otelRule::getSpans,
hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
hasItem(allOf(hasName(testMethodName), hasEnded()))));

assertThat(otelRule.getSpans(), hasItem(
allOf(hasName(testName.getMethodName()), hasStatusWithCode(StatusCode.OK), hasEnded())));
assertThat(otelRule.getSpans(),
hasItem(allOf(hasName(testMethodName), hasStatusWithCode(StatusCode.OK), hasEnded())));
}

@Test
Expand All @@ -103,7 +97,7 @@ public void testCallCleanup() {
CallRunner cr = new CallRunner(mockRpcServer, mockCall);
cr.setStatus(new MonitoredRPCHandlerImpl("test"));
cr.run();
}, testName.getMethodName());
}, testMethodName);
Mockito.verify(mockCall, Mockito.times(1)).cleanup();
}

Expand All @@ -118,14 +112,14 @@ public void testCallRunnerDropDisconnected() {
CallRunner cr = new CallRunner(mockRpcServer, mockCall);
cr.setStatus(new MonitoredRPCHandlerImpl("test"));
cr.drop();
}, testName.getMethodName());
}, testMethodName);
Mockito.verify(mockCall, Mockito.times(1)).cleanup();

Waiter.waitFor(conf, TimeUnit.SECONDS.toMillis(5), new MatcherPredicate<>(otelRule::getSpans,
hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
hasItem(allOf(hasName(testMethodName), hasEnded()))));

assertThat(otelRule.getSpans(),
hasItem(allOf(hasName(testName.getMethodName()), hasStatusWithCode(StatusCode.OK),
hasItem(allOf(hasName(testMethodName), hasStatusWithCode(StatusCode.OK),
hasEvents(hasItem(EventMatchers.hasName("Client disconnect detected"))), hasEnded())));
}

Expand All @@ -144,15 +138,15 @@ public void testCallRunnerDropConnected() {
CallRunner cr = new CallRunner(mockRpcServer, mockCall);
cr.setStatus(new MonitoredRPCHandlerImpl("test"));
cr.drop();
}, testName.getMethodName());
}, testMethodName);
Mockito.verify(mockCall, Mockito.times(1)).cleanup();
Mockito.verify(mockMetrics).exception(Mockito.any(CallDroppedException.class));

Waiter.waitFor(conf, TimeUnit.SECONDS.toMillis(5), new MatcherPredicate<>(otelRule::getSpans,
hasItem(allOf(hasName(testName.getMethodName()), hasEnded()))));
hasItem(allOf(hasName(testMethodName), hasEnded()))));

assertThat(otelRule.getSpans(),
hasItem(allOf(hasName(testName.getMethodName()), hasStatusWithCode(StatusCode.ERROR),
hasItem(allOf(hasName(testMethodName), hasStatusWithCode(StatusCode.ERROR),
hasEvents(hasItem(allOf(EventMatchers.hasName("exception"),
EventMatchers.hasAttributes(
containsEntry("exception.type", CallDroppedException.class.getName()))))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.ipc;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand All @@ -29,27 +29,22 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.monitoring.MonitoredRPCHandlerImpl;
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Category({ RPCTests.class, SmallTests.class })
@Tag(RPCTests.TAG)
@Tag(SmallTests.TAG)
public class TestFifoRpcScheduler {

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

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

private AtomicInteger callExecutionCount;
Expand All @@ -62,7 +57,7 @@ public InetSocketAddress getListenerAddress() {
};
private Configuration conf;

@Before
@BeforeEach
public void setUp() {
conf = HBaseConfiguration.create();
callExecutionCount = new AtomicInteger(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@
*/
package org.apache.hadoop.hbase.ipc;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.net.Address;
import org.apache.hadoop.hbase.testclassification.RPCTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge;
import org.junit.Assert;
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({ RPCTests.class, SmallTests.class })
@Tag(RPCTests.TAG)
@Tag(SmallTests.TAG)
public class TestHBaseClient {
@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestHBaseClient.class);

@Test
public void testFailedServer() {
ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
Expand All @@ -48,36 +45,36 @@ public void testFailedServer() {
Address ia3 = Address.fromParts("badtoo", 12);
Address ia4 = Address.fromParts("badtoo", 13);

Assert.assertFalse(fs.isFailedServer(ia));
assertFalse(fs.isFailedServer(ia));

fs.addToFailedServers(ia, testThrowable);
Assert.assertTrue(fs.isFailedServer(ia));
Assert.assertTrue(fs.isFailedServer(ia2));
assertTrue(fs.isFailedServer(ia));
assertTrue(fs.isFailedServer(ia2));

ee.incValue(1);
Assert.assertTrue(fs.isFailedServer(ia));
Assert.assertTrue(fs.isFailedServer(ia2));
assertTrue(fs.isFailedServer(ia));
assertTrue(fs.isFailedServer(ia2));

ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
Assert.assertFalse(fs.isFailedServer(ia));
Assert.assertFalse(fs.isFailedServer(ia2));
assertFalse(fs.isFailedServer(ia));
assertFalse(fs.isFailedServer(ia2));

fs.addToFailedServers(ia, testThrowable);
fs.addToFailedServers(ia3, testThrowable);
fs.addToFailedServers(ia4, testThrowable);

Assert.assertTrue(fs.isFailedServer(ia));
Assert.assertTrue(fs.isFailedServer(ia2));
Assert.assertTrue(fs.isFailedServer(ia3));
Assert.assertTrue(fs.isFailedServer(ia4));
assertTrue(fs.isFailedServer(ia));
assertTrue(fs.isFailedServer(ia2));
assertTrue(fs.isFailedServer(ia3));
assertTrue(fs.isFailedServer(ia4));

ee.incValue(RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1);
Assert.assertFalse(fs.isFailedServer(ia));
Assert.assertFalse(fs.isFailedServer(ia2));
Assert.assertFalse(fs.isFailedServer(ia3));
Assert.assertFalse(fs.isFailedServer(ia4));
assertFalse(fs.isFailedServer(ia));
assertFalse(fs.isFailedServer(ia2));
assertFalse(fs.isFailedServer(ia3));
assertFalse(fs.isFailedServer(ia4));

fs.addToFailedServers(ia3, testThrowable);
Assert.assertFalse(fs.isFailedServer(ia4));
assertFalse(fs.isFailedServer(ia4));
}
}
Loading