Skip to content

Commit

Permalink
chore: #sonarlint
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-fra committed Sep 10, 2024
1 parent 2894819 commit 46f602d
Showing 1 changed file with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,23 @@ void testWrapInCopyRunable() throws Throwable {
final String value2 = UUID.randomUUID().toString();

MDC.put("mdc", value);
final ExecutorService executor = Executors.newSingleThreadExecutor();
try (LoggingContext ctx = LoggingContext.create()) {
MDC.put("mdc", value2);

final Future<?> future = executor.submit(
ctx.wrapInCopy(() -> {
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
MDC.put("mdc", UUID.randomUUID().toString());
}));
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
future.get();
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
} catch (ExecutionException e) {
throw e.getCause();
} finally {
executor.shutdownNow();
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
try (LoggingContext ctx = LoggingContext.create()) {
MDC.put("mdc", value2);

final Future<?> future = executor.submit(
ctx.wrapInCopy(() -> {
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
MDC.put("mdc", UUID.randomUUID().toString());
}));
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
future.get();
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
} catch (ExecutionException e) {
throw e.getCause();
} finally {
executor.shutdownNow();
}
}
}

Expand All @@ -176,23 +177,24 @@ void testWrapInCopyCallable() throws Throwable {
final String value2 = UUID.randomUUID().toString();

MDC.put("mdc", value);
final ExecutorService executor = Executors.newSingleThreadExecutor();
try (LoggingContext ctx = LoggingContext.create()) {
MDC.put("mdc", value2);

final Future<?> future = executor.submit(
ctx.wrapInCopy((Callable<String>) () -> {
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
MDC.put("mdc", UUID.randomUUID().toString());
return "hello";
}));
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
future.get();
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
} catch (ExecutionException e) {
throw e.getCause();
} finally {
executor.shutdownNow();
try (ExecutorService executor = Executors.newSingleThreadExecutor()) {
try (LoggingContext ctx = LoggingContext.create()) {
MDC.put("mdc", value2);

final Future<?> future = executor.submit(
ctx.wrapInCopy((Callable<String>) () -> {
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
MDC.put("mdc", UUID.randomUUID().toString());
return "hello";
}));
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
future.get();
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
} catch (ExecutionException e) {
throw e.getCause();
} finally {
executor.shutdownNow();
}
}
}

Expand All @@ -205,7 +207,7 @@ void testWrapInCopyFunction() {
MDC.put("mdc", value);
try (LoggingContext ctx = LoggingContext.create()) {
MDC.put("mdc", value2);
final Function<String, String> function = ctx.wrapInCopy((name) -> {
final Function<String, String> function = ctx.wrapInCopy((String name) -> {
assertThat(MDC.get("mdc"), CoreMatchers.is(value2));
MDC.put("mdc", UUID.randomUUID().toString());
return "hello " + name;
Expand Down

0 comments on commit 46f602d

Please sign in to comment.