Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#noissue] Fix testRecordNotChainedException test failure #11748

Merged
merged 1 commit into from
Nov 21, 2024
Merged
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
Expand Up @@ -40,14 +40,13 @@
public class DefaultExceptionRecorderTest {

private final static Logger logger = LogManager.getLogger(DefaultExceptionRecorderTest.class);
private final static long START_TIME = 1;

ExceptionChainSampler exceptionChainSampler = new ExceptionChainSampler(1000);
ExceptionWrapperFactory exceptionWrapperFactory = new ExceptionWrapperFactory(10, 1048);

long START_TIME = 1;


class TestExceptionStorage implements ExceptionStorage {
static class TestExceptionStorage implements ExceptionStorage {

List<ExceptionWrapper> wrappers;
public List<ExceptionWrapper> outputStream;
Expand All @@ -59,7 +58,7 @@ public TestExceptionStorage() {

@Override
public void store(List<ExceptionWrapper> wrappers) {
logger.error(wrappers);
logger.info(wrappers);
this.wrappers.addAll(wrappers);
}

Expand All @@ -85,7 +84,7 @@ public List<ExceptionWrapper> getOutputStream() {
}
}

private Function<Throwable, Throwable> getThrowableFunction(
private static Function<Throwable, Throwable> getThrowableFunction(
DefaultExceptionRecorder recorder,
List<Throwable> throwable
) {
Expand All @@ -112,11 +111,11 @@ public void testRecordNothing() {
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
exceptionChainSampler, exceptionWrapperFactory, context
);
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
exceptionRecorder, exceptions
);

exceptionRecorder.recordException(null, 0);
recordThrowable.apply(null);
exceptionRecorder.close();

List<ExceptionWrapper> expected = new ArrayList<>();
Expand All @@ -133,18 +132,18 @@ public void testRecordException() {
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
exceptionChainSampler, exceptionWrapperFactory, context
);
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
exceptionRecorder, exceptions
);

List<ExceptionWrapper> expected = null;
List<ExceptionWrapper> actual = null;

try {
level3Error(throwableFunction);
level3Error(recordThrowable);
} catch (Throwable e) {
expected = newExceptionWrappers(e, START_TIME, 1);
exceptionRecorder.recordException(e, START_TIME);
recordThrowable.apply(e);
actual = exceptionStorage.getWrappers();
Assertions.assertTrue(actual.isEmpty());
}
Expand All @@ -161,7 +160,7 @@ public void testRecordNotChainedException() {
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
exceptionChainSampler, exceptionWrapperFactory, context
);
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
exceptionRecorder, exceptions
);

Expand All @@ -173,10 +172,9 @@ public void testRecordNotChainedException() {
Throwable throwable = null;

try {
notChainedException(throwableFunction);
notChainedException(recordThrowable);
} catch (Throwable e) {
expected1 = newExceptionWrappers(exceptions.get(exceptions.size() - 2), START_TIME, 1);
exceptionRecorder.recordException(e, START_TIME);
logger.warn(exceptionStorage.getWrappers());
actual1 = new ArrayList<>(exceptionStorage.getWrappers());
throwable = e;
Expand Down Expand Up @@ -204,18 +202,17 @@ public void testRecordRethrowGivenException() {
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
exceptionChainSampler, exceptionWrapperFactory, context
);
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
exceptionRecorder, exceptions
);

List<ExceptionWrapper> expected = null;
List<ExceptionWrapper> actual = null;

try {
rethrowGivenException(throwableFunction);
rethrowGivenException(recordThrowable);
} catch (Throwable e) {
expected = newExceptionWrappers(e, START_TIME, 1);
exceptionRecorder.recordException(e, START_TIME);
actual = exceptionStorage.getWrappers();
Assertions.assertTrue(actual.isEmpty());
}
Expand Down