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 46f602d commit 3e1a9fb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 35 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
<version>3.8.0</version>
<configuration>
<source>${java.version}</source>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,23 +151,22 @@ void testWrapInCopyRunable() throws Throwable {
final String value2 = UUID.randomUUID().toString();

MDC.put("mdc", value);
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();
}
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();
}
}

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

MDC.put("mdc", value);
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();
}
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();
}
}

Expand Down

0 comments on commit 3e1a9fb

Please sign in to comment.