Skip to content

Commit

Permalink
HBASE-27052 TestAsyncTableScanner.testScanWrongColumnFamily is flaky (#…
Browse files Browse the repository at this point in the history
…4456)

Signed-off-by: Andrew Purtell <[email protected]>
  • Loading branch information
ndimiduk authored May 20, 2022
1 parent f982e6d commit 8bbba73
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@
*/
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.trace.hamcrest.AttributesMatchers.containsEntry;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.isA;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.fail;

import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Arrays;
Expand All @@ -46,6 +51,7 @@
import org.apache.hadoop.hbase.StartMiniClusterOption;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Waiter;
import org.apache.hadoop.hbase.ipc.RemoteWithExtrasException;
import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException;
import org.apache.hadoop.hbase.trace.OpenTelemetryClassRule;
import org.apache.hadoop.hbase.trace.OpenTelemetryTestRule;
Expand Down Expand Up @@ -176,7 +182,8 @@ protected static List<Object[]> getTableAndScanCreatorParams() {
/**
* Used by implementation classes to assert the correctness of spans having errors.
*/
protected abstract void assertTraceError(final Matcher<String> exceptionTypeNameMatcher);
protected abstract void
assertTraceError(final Matcher<io.opentelemetry.api.common.Attributes> exceptionMatcher);

protected final List<Result> convertFromBatchResult(List<Result> results) {
assertEquals(0, results.size() % 2);
Expand Down Expand Up @@ -269,7 +276,14 @@ public void testScanWrongColumnFamily() {
} else {
fail("Found unexpected Exception " + e);
}
assertTraceError(endsWith(NoSuchColumnFamilyException.class.getName()));
assertTraceError(anyOf(
containsEntry(is(SemanticAttributes.EXCEPTION_TYPE),
endsWith(NoSuchColumnFamilyException.class.getName())),
allOf(
containsEntry(is(SemanticAttributes.EXCEPTION_TYPE),
endsWith(RemoteWithExtrasException.class.getName())),
containsEntry(is(SemanticAttributes.EXCEPTION_MESSAGE),
containsString(NoSuchColumnFamilyException.class.getName())))));
}

private void testScan(int start, boolean startInclusive, int stop, boolean stopInclusive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasEnded;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasExceptionWithType;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasException;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasName;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasParentSpanId;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasStatusWithCode;
Expand Down Expand Up @@ -145,7 +145,8 @@ protected void assertTraceContinuity() {
}

@Override
protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
protected void
assertTraceError(Matcher<io.opentelemetry.api.common.Attributes> exceptionMatcher) {
final String parentSpanName = testName.getMethodName();
final Matcher<SpanData> parentSpanMatcher = allOf(hasName(parentSpanName), hasEnded());
waitForSpan(parentSpanMatcher);
Expand All @@ -163,7 +164,7 @@ protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
final Matcher<SpanData> scanOperationSpanMatcher =
allOf(hasName(startsWith("SCAN " + TABLE_NAME.getNameWithNamespaceInclAsString())),
hasParentSpanId(parentSpanId), hasStatusWithCode(StatusCode.ERROR),
hasExceptionWithType(exceptionTypeNameMatcher), hasEnded());
hasException(exceptionMatcher), hasEnded());
assertThat(spans, hasItem(scanOperationSpanMatcher));
final String scanOperationSpanId = spans.stream().filter(scanOperationSpanMatcher::matches)
.map(SpanData::getSpanId).findAny().orElseThrow(AssertionError::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasEnded;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasExceptionWithType;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasException;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasName;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasParentSpanId;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasStatusWithCode;
Expand Down Expand Up @@ -116,7 +116,8 @@ protected void assertTraceContinuity() {
}

@Override
protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
protected void
assertTraceError(Matcher<io.opentelemetry.api.common.Attributes> exceptionMatcher) {
final String parentSpanName = testName.getMethodName();
final Matcher<SpanData> parentSpanMatcher = allOf(hasName(parentSpanName), hasEnded());
waitForSpan(parentSpanMatcher);
Expand All @@ -134,7 +135,7 @@ protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
final Matcher<SpanData> scanOperationSpanMatcher =
allOf(hasName(startsWith("SCAN " + TABLE_NAME.getNameWithNamespaceInclAsString())),
hasParentSpanId(parentSpanId), hasStatusWithCode(StatusCode.ERROR),
hasExceptionWithType(exceptionTypeNameMatcher), hasEnded());
hasException(exceptionMatcher), hasEnded());
assertThat(spans, hasItem(scanOperationSpanMatcher));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasEnded;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasExceptionWithType;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasException;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasName;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasParentSpanId;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasStatusWithCode;
Expand Down Expand Up @@ -128,7 +128,8 @@ protected void assertTraceContinuity() {
}

@Override
protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
protected void
assertTraceError(Matcher<io.opentelemetry.api.common.Attributes> exceptionMatcher) {
final String parentSpanName = testName.getMethodName();
final Matcher<SpanData> parentSpanMatcher = allOf(hasName(parentSpanName), hasEnded());
waitForSpan(parentSpanMatcher);
Expand All @@ -146,7 +147,7 @@ protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
final Matcher<SpanData> scanOperationSpanMatcher =
allOf(hasName(startsWith("SCAN " + TABLE_NAME.getNameWithNamespaceInclAsString())),
hasParentSpanId(parentSpanId), hasStatusWithCode(StatusCode.ERROR),
hasExceptionWithType(exceptionTypeNameMatcher), hasEnded());
hasException(exceptionMatcher), hasEnded());
assertThat(spans, hasItem(scanOperationSpanMatcher));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.hadoop.hbase.client;

import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasEnded;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasExceptionWithType;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasException;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasName;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasParentSpanId;
import static org.apache.hadoop.hbase.client.trace.hamcrest.SpanDataMatchers.hasStatusWithCode;
Expand Down Expand Up @@ -142,7 +142,8 @@ protected void assertTraceContinuity() {
}

@Override
protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
protected void
assertTraceError(Matcher<io.opentelemetry.api.common.Attributes> exceptionMatcher) {
final String parentSpanName = testName.getMethodName();
final Matcher<SpanData> parentSpanMatcher = allOf(hasName(parentSpanName), hasEnded());
waitForSpan(parentSpanMatcher);
Expand All @@ -160,7 +161,7 @@ protected void assertTraceError(Matcher<String> exceptionTypeNameMatcher) {
final Matcher<SpanData> scanOperationSpanMatcher =
allOf(hasName(startsWith("SCAN " + TABLE_NAME.getNameWithNamespaceInclAsString())),
hasParentSpanId(parentSpanId), hasStatusWithCode(StatusCode.ERROR),
hasExceptionWithType(exceptionTypeNameMatcher), hasEnded());
hasException(exceptionMatcher), hasEnded());
assertThat(spans, hasItem(scanOperationSpanMatcher));
final String scanOperationSpanId = spans.stream().filter(scanOperationSpanMatcher::matches)
.map(SpanData::getSpanId).findAny().orElseThrow(AssertionError::new);
Expand Down

0 comments on commit 8bbba73

Please sign in to comment.