Skip to content

Commit f1d85d2

Browse files
committed
[#noissue] Fix testRecordNotChainedException test failure
1 parent 5598e76 commit f1d85d2

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

agent-module/profiler/src/test/java/com/navercorp/pinpoint/profiler/metadata/DefaultExceptionRecorderTest.java

+13-16
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@
4040
public class DefaultExceptionRecorderTest {
4141

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

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

47-
long START_TIME = 1;
4848

49-
50-
class TestExceptionStorage implements ExceptionStorage {
49+
static class TestExceptionStorage implements ExceptionStorage {
5150

5251
List<ExceptionWrapper> wrappers;
5352
public List<ExceptionWrapper> outputStream;
@@ -59,7 +58,7 @@ public TestExceptionStorage() {
5958

6059
@Override
6160
public void store(List<ExceptionWrapper> wrappers) {
62-
logger.error(wrappers);
61+
logger.info(wrappers);
6362
this.wrappers.addAll(wrappers);
6463
}
6564

@@ -85,7 +84,7 @@ public List<ExceptionWrapper> getOutputStream() {
8584
}
8685
}
8786

88-
private Function<Throwable, Throwable> getThrowableFunction(
87+
private static Function<Throwable, Throwable> getThrowableFunction(
8988
DefaultExceptionRecorder recorder,
9089
List<Throwable> throwable
9190
) {
@@ -112,11 +111,11 @@ public void testRecordNothing() {
112111
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
113112
exceptionChainSampler, exceptionWrapperFactory, context
114113
);
115-
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
114+
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
116115
exceptionRecorder, exceptions
117116
);
118117

119-
exceptionRecorder.recordException(null, 0);
118+
recordThrowable.apply(null);
120119
exceptionRecorder.close();
121120

122121
List<ExceptionWrapper> expected = new ArrayList<>();
@@ -133,18 +132,18 @@ public void testRecordException() {
133132
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
134133
exceptionChainSampler, exceptionWrapperFactory, context
135134
);
136-
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
135+
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
137136
exceptionRecorder, exceptions
138137
);
139138

140139
List<ExceptionWrapper> expected = null;
141140
List<ExceptionWrapper> actual = null;
142141

143142
try {
144-
level3Error(throwableFunction);
143+
level3Error(recordThrowable);
145144
} catch (Throwable e) {
146145
expected = newExceptionWrappers(e, START_TIME, 1);
147-
exceptionRecorder.recordException(e, START_TIME);
146+
recordThrowable.apply(e);
148147
actual = exceptionStorage.getWrappers();
149148
Assertions.assertTrue(actual.isEmpty());
150149
}
@@ -161,7 +160,7 @@ public void testRecordNotChainedException() {
161160
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
162161
exceptionChainSampler, exceptionWrapperFactory, context
163162
);
164-
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
163+
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
165164
exceptionRecorder, exceptions
166165
);
167166

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

175174
try {
176-
notChainedException(throwableFunction);
175+
notChainedException(recordThrowable);
177176
} catch (Throwable e) {
178177
expected1 = newExceptionWrappers(exceptions.get(exceptions.size() - 2), START_TIME, 1);
179-
exceptionRecorder.recordException(e, START_TIME);
180178
logger.warn(exceptionStorage.getWrappers());
181179
actual1 = new ArrayList<>(exceptionStorage.getWrappers());
182180
throwable = e;
@@ -204,18 +202,17 @@ public void testRecordRethrowGivenException() {
204202
DefaultExceptionRecorder exceptionRecorder = new DefaultExceptionRecorder(
205203
exceptionChainSampler, exceptionWrapperFactory, context
206204
);
207-
Function<Throwable, Throwable> throwableFunction = getThrowableFunction(
205+
Function<Throwable, Throwable> recordThrowable = getThrowableFunction(
208206
exceptionRecorder, exceptions
209207
);
210208

211209
List<ExceptionWrapper> expected = null;
212210
List<ExceptionWrapper> actual = null;
213211

214212
try {
215-
rethrowGivenException(throwableFunction);
213+
rethrowGivenException(recordThrowable);
216214
} catch (Throwable e) {
217215
expected = newExceptionWrappers(e, START_TIME, 1);
218-
exceptionRecorder.recordException(e, START_TIME);
219216
actual = exceptionStorage.getWrappers();
220217
Assertions.assertTrue(actual.isEmpty());
221218
}

0 commit comments

Comments
 (0)