diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/ContextManagers.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/ContextManagers.java index 1b79cbe5..8ae4cdae 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/ContextManagers.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/ContextManagers.java @@ -59,7 +59,7 @@ private ContextManagers() { * within a try-with-resources construct. */ @SuppressWarnings("rawtypes") - public static nl.talsmasoftware.context.api.ContextSnapshot createContextSnapshot() { + public static ContextSnapshot createContextSnapshot() { final long start = System.nanoTime(); final List managers = ServiceCache.cached(ContextManager.class); // Cached list is immutable final Object[] values = new Object[managers.size()]; @@ -188,7 +188,7 @@ public Reactivation reactivate() { } ReactivationImpl reactivation = new ReactivationImpl(reactivatedContexts); - Timers.timed(System.nanoTime() - start, nl.talsmasoftware.context.api.ContextSnapshot.class, "reactivate"); + Timers.timed(System.nanoTime() - start, ContextSnapshot.class, "reactivate"); return reactivation; } catch (RuntimeException reactivationException) { // TODO think about simplifying by catching & handling in reactivate(manager, value) method diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiConsumerWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiConsumerWithContext.java index f446c85e..790b3d8f 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiConsumerWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiConsumerWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Supplier; @@ -51,7 +49,7 @@ protected BiConsumerWithContext(Supplier supplier, BiConsumer andThen(BiConsumer after) { requireNonNull(after, "Cannot post-process with after bi-consumer ."); return (l, r) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating andThen method with {0} to {1}.", new Object[]{context, delegate()}); delegate().accept(l, r); @@ -83,8 +79,6 @@ public BiConsumer andThen(BiConsumer after) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiFunctionWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiFunctionWithContext.java index b5e8cc78..66384f94 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiFunctionWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiFunctionWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; @@ -52,7 +50,7 @@ protected BiFunctionWithContext(Supplier supplier, BiFunction BiFunction andThen(Function after) { requireNonNull(after, "Cannot post-process bi-function with after function ."); return (IN1 in1, IN2 in2) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating andThen method with {0} to {1}.", new Object[]{context, delegate()}); return after.apply(delegate().apply(in1, in2)); @@ -83,8 +79,6 @@ public BiFunction andThen(Function af contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiPredicateWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiPredicateWithContext.java index 508c0858..050e61c9 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiPredicateWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BiPredicateWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.BiPredicate; import java.util.function.Consumer; import java.util.function.Supplier; @@ -51,7 +49,7 @@ protected BiPredicateWithContext(Supplier supplier, BiPredicate @Override public boolean test(IN1 in1, IN2 in2) { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating test method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(in1, in2); @@ -62,8 +60,6 @@ public boolean test(IN1 in1, IN2 in2) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } } @@ -71,7 +67,7 @@ public boolean test(IN1 in1, IN2 in2) { public BiPredicate and(BiPredicate other) { requireNonNull(other, "Cannot combine bi-predicate with 'and' ."); return (IN1 in1, IN2 in2) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating 'and' method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(in1, in2) && other.test(in1, in2); @@ -82,8 +78,6 @@ public BiPredicate and(BiPredicate other) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } @@ -92,7 +86,7 @@ public BiPredicate and(BiPredicate other) { public BiPredicate or(BiPredicate other) { requireNonNull(other, "Cannot combine bi-predicate with 'or' ."); return (IN1 in1, IN2 in2) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating 'or' method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(in1, in2) || other.test(in1, in2); @@ -103,8 +97,6 @@ public BiPredicate or(BiPredicate other) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContext.java index 88bedf5f..a6e405aa 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.BooleanSupplier; import java.util.function.Consumer; import java.util.function.Supplier; @@ -49,7 +47,7 @@ protected BooleanSupplierWithContext(Supplier supplier, Boolean @Override public boolean getAsBoolean() { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating getAsBoolean method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().getAsBoolean(); @@ -60,8 +58,6 @@ public boolean getAsBoolean() { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/ConsumerWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/ConsumerWithContext.java index c9ca7392..fc483b2c 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/ConsumerWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/ConsumerWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.logging.Level; @@ -50,7 +48,7 @@ protected ConsumerWithContext(Supplier supplier, Consumer de @Override public void accept(T t) { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating accept method with {0} to {1}.", new Object[]{context, delegate()}); delegate().accept(t); @@ -61,8 +59,6 @@ public void accept(T t) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new IllegalStateException("Error closing snapshot reactivation: " + e.getMessage(), e); } } @@ -70,7 +66,7 @@ public void accept(T t) { public Consumer andThen(Consumer after) { requireNonNull(after, "Cannot follow ConsumerWithContext with after consumer ."); return (T t) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating andThen method with {0} to {1}.", new Object[]{context, delegate()}); delegate().accept(t); @@ -82,8 +78,6 @@ public Consumer andThen(Consumer after) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/FunctionWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/FunctionWithContext.java index b4d250c8..6b9d4bf8 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/FunctionWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/FunctionWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -50,7 +48,7 @@ protected FunctionWithContext(Supplier supplier, Function Function compose(Function before) { requireNonNull(before, "Cannot compose with before function ."); return (V v) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating compose method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().apply(before.apply(v)); @@ -80,8 +76,6 @@ public Function compose(Function before) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } @@ -89,7 +83,7 @@ public Function compose(Function before) { public Function andThen(Function after) { requireNonNull(after, "Cannot transform with after function ."); return (IN in) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating andThen method with {0} to {1}.", new Object[]{context, delegate()}); return after.apply(delegate().apply(in)); @@ -100,8 +94,6 @@ public Function andThen(Function after) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/PredicateWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/PredicateWithContext.java index 285fb320..4aea7403 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/PredicateWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/PredicateWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Predicate; import java.util.function.Supplier; @@ -51,7 +49,7 @@ protected PredicateWithContext(Supplier supplier, Predicate @Override public boolean test(T t) { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating test method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(t); @@ -62,8 +60,6 @@ public boolean test(T t) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } } @@ -71,7 +67,7 @@ public boolean test(T t) { public Predicate and(Predicate other) { requireNonNull(other, "Cannot combine predicate with 'and' ."); return (t) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating 'and' method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(t) && other.test(t); @@ -82,8 +78,6 @@ public Predicate and(Predicate other) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } @@ -92,7 +86,7 @@ public Predicate and(Predicate other) { public Predicate or(Predicate other) { requireNonNull(other, "Cannot combine predicate with 'or' ."); return (t) -> { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating 'or' method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().test(t) || other.test(t); @@ -103,8 +97,6 @@ public Predicate or(Predicate other) { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }; } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/RunnableWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/RunnableWithContext.java index ac552c7e..497fe570 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/RunnableWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/RunnableWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.logging.Level; @@ -72,7 +70,7 @@ protected RunnableWithContext(Supplier supplier, Runnable deleg @Override public void run() { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating run method with {0} to {1}.", new Object[]{context, delegate()}); delegate().run(); @@ -83,8 +81,6 @@ public void run() { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } } diff --git a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/SupplierWithContext.java b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/SupplierWithContext.java index 9a2bcfab..86d0034f 100644 --- a/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/SupplierWithContext.java +++ b/context-propagation-core/src/main/java/nl/talsmasoftware/context/core/function/SupplierWithContext.java @@ -18,8 +18,6 @@ import nl.talsmasoftware.context.api.ContextSnapshot; import nl.talsmasoftware.context.core.ContextManagers; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Consumer; import java.util.function.Supplier; import java.util.logging.Level; @@ -48,7 +46,7 @@ protected SupplierWithContext(Supplier snapshotSupplier, Suppli @Override public T get() { - try (Closeable context = snapshot().reactivate()) { + try (ContextSnapshot.Reactivation context = snapshot().reactivate()) { try { // inner 'try' is needed: https://github.com/talsma-ict/context-propagation/pull/56#discussion_r201590623 LOGGER.log(Level.FINEST, "Delegating get method with {0} to {1}.", new Object[]{context, delegate()}); return delegate().get(); @@ -59,8 +57,6 @@ public T get() { contextSnapshotConsumer.accept(resultSnapshot); } } - } catch (IOException e) { - throw new IllegalStateException(e.getMessage(), e); } } } diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextManagersTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextManagersTest.java index 9380df80..fb3d5295 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextManagersTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextManagersTest.java @@ -26,8 +26,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; @@ -82,7 +80,7 @@ public void testUnsupportedConstructor() { } @Test - public void testSnapshot_inSameThread() throws IOException { + public void testSnapshot_inSameThread() { dummyManager.clear(); MatcherAssert.assertThat(DummyContext.currentValue(), is(nullValue())); @@ -99,7 +97,7 @@ public void testSnapshot_inSameThread() throws IOException { MatcherAssert.assertThat(DummyContext.currentValue(), is("third value")); // Reactivate snapshot: ctx1 -> ctx2 -> ctx3 -> ctx2' - Closeable reactivation = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivation = snapshot.reactivate(); MatcherAssert.assertThat(DummyContext.currentValue(), is("second value")); reactivation.close(); @@ -173,14 +171,14 @@ public ContextSnapshot call() throws Exception { } @Test - public void testCreateSnapshot_ExceptionHandling() throws IOException { + public void testCreateSnapshot_ExceptionHandling() { ThrowingContextManager.onGet = new IllegalStateException("No active context!"); Context ctx = new DummyContext("blah"); ContextSnapshot snapshot = ContextManagers.createContextSnapshot(); ctx.close(); MatcherAssert.assertThat(DummyContext.currentValue(), is(nullValue())); - Closeable reactivation = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivation = snapshot.reactivate(); MatcherAssert.assertThat(DummyContext.currentValue(), is("blah")); reactivation.close(); MatcherAssert.assertThat(DummyContext.currentValue(), is(nullValue())); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextSnapshotTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextSnapshotTest.java index 637c522f..002948aa 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextSnapshotTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/ContextSnapshotTest.java @@ -20,8 +20,6 @@ import nl.talsmasoftware.context.dummy.DummyContextManager; import org.junit.jupiter.api.Test; -import java.io.IOException; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasToString; import static org.hamcrest.Matchers.is; @@ -39,7 +37,7 @@ public void testSnapshotToString() { } @Test - public void testSnapshotReactivate() throws IOException { + public void testSnapshotReactivate() { try (Context ctx = MGR.initializeNewContext("Old value")) { ContextSnapshot snapshot = ContextManagers.createContextSnapshot(); try (Context ctx2 = MGR.initializeNewContext("New value")) { diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/NoContextManagersTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/NoContextManagersTest.java index 6ae54665..c7ede91b 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/NoContextManagersTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/NoContextManagersTest.java @@ -23,9 +23,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; import java.io.File; -import java.io.IOException; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -50,21 +48,21 @@ public void resetDefaultClassLoader() { } @Test - public void testReactivate_withoutContextManagers() throws IOException { + public void testReactivate_withoutContextManagers() { Context ctx1 = new DummyContext("foo"); ContextSnapshot snapshot = ContextManagers.createContextSnapshot(); ctx1.close(); - Closeable reactivated = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivated = snapshot.reactivate(); reactivated.close(); } @Test - public void testCreateSnapshot_withoutContextManagers() throws IOException { + public void testCreateSnapshot_withoutContextManagers() { ContextSnapshot snapshot = ContextManagers.createContextSnapshot(); assertThat(snapshot, is(notNullValue())); - Closeable reactivated = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivated = snapshot.reactivate(); assertThat(reactivated, is(notNullValue())); reactivated.close(); } diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiFunctionWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiFunctionWithContextTest.java index 6705f3b0..a29bab46 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiFunctionWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiFunctionWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; import java.util.function.Function; @@ -96,7 +94,7 @@ public void testApplyWithoutSnapshotSupplier() { } @Test - public void testApplyWithSnapshotConsumer() throws InterruptedException, IOException { + public void testApplyWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -110,7 +108,7 @@ public void testApplyWithSnapshotConsumer() throws InterruptedException, IOExcep t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiPredicateWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiPredicateWithContextTest.java index 2c403b22..378e2889 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiPredicateWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BiPredicateWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiPredicate; import java.util.function.Supplier; @@ -95,7 +93,7 @@ public void testTestWithoutSnapshotSupplier() { } @Test - public void testTestWithSnapshotConsumer() throws InterruptedException, IOException { + public void testTestWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -109,7 +107,7 @@ public void testTestWithSnapshotConsumer() throws InterruptedException, IOExcept t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BinaryOperatorWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BinaryOperatorWithContextTest.java index 4da0d8e7..82a0f8bc 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BinaryOperatorWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BinaryOperatorWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; import java.util.function.BinaryOperator; @@ -98,7 +96,7 @@ public void testApplyWithoutSnapshotSupplier() { } @Test - public void testApplyWithSnapshotConsumer() throws InterruptedException, IOException { + public void testApplyWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -111,7 +109,7 @@ public void testApplyWithSnapshotConsumer() throws InterruptedException, IOExcep t.start(); t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContextTest.java index 9b3b150b..b6310428 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/BooleanSupplierWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -85,7 +83,7 @@ public void testConstructWithoutSnapshotSupplier() { } @Test - public void testGetAsBooleanWithSnapshotConsumer() throws ExecutionException, InterruptedException, IOException { + public void testGetAsBooleanWithSnapshotConsumer() throws ExecutionException, InterruptedException { DummyContext.setCurrentValue("true"); final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; @@ -101,7 +99,7 @@ public void testGetAsBooleanWithSnapshotConsumer() throws ExecutionException, In assertThat(future.get(), is(true)); assertThat(DummyContext.currentValue(), is("true")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("false")); } assertThat(DummyContext.currentValue(), is("true")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/ConsumerWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/ConsumerWithContextTest.java index 46874bfd..fac9a614 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/ConsumerWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/ConsumerWithContextTest.java @@ -24,8 +24,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.Optional; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -103,10 +101,8 @@ public void testAcceptWithSnapshotConsumer() throws InterruptedException { assertThat("Snapshot consumer must be called", snapshotHolder[0], is(notNullValue())); t = new Thread(() -> { - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat("Thread context must propagate", currentValue(), is("New value")); - } catch (IOException e) { - throw new RuntimeException(e.getMessage(), e); } }); t.start(); @@ -114,7 +110,7 @@ public void testAcceptWithSnapshotConsumer() throws InterruptedException { } @Test - public void testAndThen() throws InterruptedException, IOException { + public void testAndThen() throws InterruptedException { setCurrentValue("Old value"); final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; @@ -129,7 +125,7 @@ public void testAndThen() throws InterruptedException, IOException { t.join(); assertThat(currentValue(), is("Old value")); - try (Closeable reactivated = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivated = snapshotHolder[0].reactivate()) { assertThat(currentValue(), is("NEW VALUE, New value, Old value")); } } diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/FunctionWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/FunctionWithContextTest.java index a18848f5..53c34239 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/FunctionWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/FunctionWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Function; import java.util.function.Supplier; @@ -95,7 +93,7 @@ public void testApplyWithoutSnapshotSupplier() { } @Test - public void testApplyWithSnapshotConsumer() throws InterruptedException, IOException { + public void testApplyWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -109,7 +107,7 @@ public void testApplyWithSnapshotConsumer() throws InterruptedException, IOExcep t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/PredicateWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/PredicateWithContextTest.java index 4c761bc3..3420fc4a 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/PredicateWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/PredicateWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; @@ -96,7 +94,7 @@ public void testTestWithoutSnapshotSupplier() { } @Test - public void testTestWithSnapshotConsumer() throws InterruptedException, IOException { + public void testTestWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -110,7 +108,7 @@ public void testTestWithSnapshotConsumer() throws InterruptedException, IOExcept t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/RunnableWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/RunnableWithContextTest.java index f2adff7d..016f93b0 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/RunnableWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/RunnableWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Supplier; import static org.hamcrest.MatcherAssert.assertThat; @@ -94,7 +92,7 @@ public void testRunWithoutSnapshotSupplier() { } @Test - public void testRunWithSnapshotConsumer() throws InterruptedException, IOException { + public void testRunWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -105,7 +103,7 @@ public void testRunWithSnapshotConsumer() throws InterruptedException, IOExcepti t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/SupplierWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/SupplierWithContextTest.java index 9b1fb443..ac4d71cf 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/SupplierWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/SupplierWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -76,7 +74,7 @@ public void testGetNull() { } @Test - public void testGetWithSnapshotConsumer() throws ExecutionException, InterruptedException, IOException { + public void testGetWithSnapshotConsumer() throws ExecutionException, InterruptedException { DummyContext.setCurrentValue("Old value"); final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; @@ -93,7 +91,7 @@ public void testGetWithSnapshotConsumer() throws ExecutionException, Interrupted verify(snapshot).reactivate(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } } diff --git a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/UnaryOperatorWithContextTest.java b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/UnaryOperatorWithContextTest.java index 48005a91..ecb6ad14 100644 --- a/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/UnaryOperatorWithContextTest.java +++ b/context-propagation-core/src/test/java/nl/talsmasoftware/context/core/function/UnaryOperatorWithContextTest.java @@ -23,8 +23,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.function.Supplier; import java.util.function.UnaryOperator; @@ -93,7 +91,7 @@ public void testApplyWithoutSnapshotSupplier() { } @Test - public void testApplyWithSnapshotConsumer() throws InterruptedException, IOException { + public void testApplyWithSnapshotConsumer() throws InterruptedException { final ContextSnapshot[] snapshotHolder = new ContextSnapshot[1]; DummyContext.setCurrentValue("Old value"); @@ -107,7 +105,7 @@ public void testApplyWithSnapshotConsumer() throws InterruptedException, IOExcep t.join(); assertThat(DummyContext.currentValue(), is("Old value")); - try (Closeable reactivation = snapshotHolder[0].reactivate()) { + try (ContextSnapshot.Reactivation reactivation = snapshotHolder[0].reactivate()) { assertThat(DummyContext.currentValue(), is("New value")); } assertThat(DummyContext.currentValue(), is("Old value")); diff --git a/managers/context-manager-log4j2/src/test/java/nl/talsmasoftware/context/managers/log4j2/threadcontext/Log4j2ThreadContextManagerTest.java b/managers/context-manager-log4j2/src/test/java/nl/talsmasoftware/context/managers/log4j2/threadcontext/Log4j2ThreadContextManagerTest.java index 73556c3f..d5962b00 100644 --- a/managers/context-manager-log4j2/src/test/java/nl/talsmasoftware/context/managers/log4j2/threadcontext/Log4j2ThreadContextManagerTest.java +++ b/managers/context-manager-log4j2/src/test/java/nl/talsmasoftware/context/managers/log4j2/threadcontext/Log4j2ThreadContextManagerTest.java @@ -24,8 +24,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; @@ -173,7 +171,7 @@ public Integer call() { } @Test - void testSnapshotRestorationAfterClosingReactivatedSnapshot() throws IOException { + void testSnapshotRestorationAfterClosingReactivatedSnapshot() { String mapKey1 = "map1"; ThreadContext.put(mapKey1, "value1"); ThreadContext.push("stack1"); @@ -192,7 +190,7 @@ void testSnapshotRestorationAfterClosingReactivatedSnapshot() throws IOException String mapKey2 = "map2"; ThreadContext.put(mapKey2, "value2"); - Closeable reactivation = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivation = snapshot.reactivate(); assertThat("ThreadContext changed by reactivation", ThreadContext.get(mapKey1), equalTo("value1")); assertThat("Existing ThreadContext data should not have been cleared", ThreadContext.get(mapKey2), equalTo("value2")); assertThat(ThreadContext.getContext().size(), is(2)); diff --git a/managers/context-manager-opentracing/src/test/java/nl/talsmasoftware/context/managers/opentracing/Issue30Test.java b/managers/context-manager-opentracing/src/test/java/nl/talsmasoftware/context/managers/opentracing/Issue30Test.java index 623e8981..982ef344 100644 --- a/managers/context-manager-opentracing/src/test/java/nl/talsmasoftware/context/managers/opentracing/Issue30Test.java +++ b/managers/context-manager-opentracing/src/test/java/nl/talsmasoftware/context/managers/opentracing/Issue30Test.java @@ -26,9 +26,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.io.Closeable; -import java.io.IOException; - import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; @@ -71,9 +68,9 @@ public void cleanup() { } @Test - public void testIssue30NullPointerException() throws IOException { + public void testIssue30NullPointerException() { ContextSnapshot snapshot = ContextManagers.createContextSnapshot(); - Closeable reactivation = snapshot.reactivate(); + ContextSnapshot.Reactivation reactivation = snapshot.reactivate(); reactivation.close(); // This throws NPE in issue 30 }