From d8d9d1128190c6f9d773eea7d4258391bd03bd56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20J=C4=99drzejczyk?= Date: Tue, 6 Jun 2023 15:20:31 +0200 Subject: [PATCH] Removed contextCapture package private method that uses predicate --- .../core/publisher/ContextPropagation.java | 30 ------------------- .../ContextPropagationNotThereSmokeTest.java | 6 ---- .../publisher/ContextPropagationTest.java | 29 ------------------ 3 files changed, 65 deletions(-) diff --git a/reactor-core/src/main/java/reactor/core/publisher/ContextPropagation.java b/reactor-core/src/main/java/reactor/core/publisher/ContextPropagation.java index 29d205e6ef..b040e110cb 100644 --- a/reactor-core/src/main/java/reactor/core/publisher/ContextPropagation.java +++ b/reactor-core/src/main/java/reactor/core/publisher/ContextPropagation.java @@ -93,36 +93,6 @@ static Context contextCaptureToEmpty() { return contextCapture().apply(Context.empty()); } - /** - * Create a support function that takes a snapshot of thread locals and merges them with the - * provided {@link Context}, resulting in a new {@link Context} which includes entries - * captured from threadLocals by the Context-Propagation API. - *

- * The provided {@link Predicate} is used on keys associated to said thread locals - * by the Context-Propagation API to filter which entries should be captured in the - * first place. - *

- * This variant uses the implicit global {@code ContextRegistry} and captures only from - * available {@code ThreadLocalAccessors} that match the {@link Predicate}. - * - * @param captureKeyPredicate a {@link Predicate} used on keys to determine if each entry - * should be injected into the new {@link Context} - * @return a {@link Function} augmenting {@link Context} with captured entries - */ - static Function contextCapture(Predicate captureKeyPredicate) { - if (!ContextPropagationSupport.isContextPropagationOnClasspath) { - return NO_OP; - } - // This method is actually used only in tests, so creating a new instance for - // each call is not an issue. If it's used in production code, a better - // strategy for configuring the Predicate needs to be chosen. - ContextSnapshotFactory factory = ContextSnapshotFactory - .builder() - .captureKeyPredicate(captureKeyPredicate) - .build(); - return target -> factory.captureAll().updateContext(target); - } - /** * When context-propagation library * is available on the classpath, the provided {@link BiConsumer handler} will be diff --git a/reactor-core/src/test/java/reactor/core/publisher/ContextPropagationNotThereSmokeTest.java b/reactor-core/src/test/java/reactor/core/publisher/ContextPropagationNotThereSmokeTest.java index 1632ad1590..17fcfd361b 100644 --- a/reactor-core/src/test/java/reactor/core/publisher/ContextPropagationNotThereSmokeTest.java +++ b/reactor-core/src/test/java/reactor/core/publisher/ContextPropagationNotThereSmokeTest.java @@ -32,12 +32,6 @@ void contextPropagationIsNotAvailable() { assertThat(ContextPropagationSupport.isContextPropagationAvailable()).isFalse(); } - @Test - void contextCaptureIsNoOp() { - assertThat(ContextPropagation.contextCapture()).as("without predicate").isSameAs(ContextPropagation.NO_OP); - assertThat(ContextPropagation.contextCapture(v -> true)).as("with predicate").isSameAs(ContextPropagation.NO_OP); - } - @Test void contextCaptureFluxApiIsNoOp() { Flux source = Flux.empty(); diff --git a/reactor-core/src/withMicrometerTest/java/reactor/core/publisher/ContextPropagationTest.java b/reactor-core/src/withMicrometerTest/java/reactor/core/publisher/ContextPropagationTest.java index 39d68e0d0e..1189517b4d 100644 --- a/reactor-core/src/withMicrometerTest/java/reactor/core/publisher/ContextPropagationTest.java +++ b/reactor-core/src/withMicrometerTest/java/reactor/core/publisher/ContextPropagationTest.java @@ -334,19 +334,6 @@ void contextCaptureWithNoPredicateReturnsTheConstantFunction() { .isSameAs(ContextPropagation.WITH_GLOBAL_REGISTRY_NO_PREDICATE); } - @Test - void contextCaptureWithPredicateReturnsNewFunctionWithGlobalRegistry() { - Function test = ContextPropagation.contextCapture(ContextPropagation.PREDICATE_TRUE); - - assertThat(test) - .as("predicate, no registry") - .isNotNull() - .isNotSameAs(ContextPropagation.WITH_GLOBAL_REGISTRY_NO_PREDICATE) - .isNotSameAs(ContextPropagation.NO_OP) - // as long as a predicate is supplied, the method creates new instances of the Function - .isNotSameAs(ContextPropagation.contextCapture(ContextPropagation.PREDICATE_TRUE)); - } - @Test void fluxApiUsesContextPropagationConstantFunction() { Flux source = Flux.empty(); @@ -411,22 +398,6 @@ void contextCaptureFunctionWithoutFiltering() { .containsEntry(KEY2, "expected2") .hasSize(2); } - - @Test - void captureWithFiltering() { - Function test = ContextPropagation.contextCapture(k -> k.toString().equals(KEY2)); - - REF1.set("not_expected"); - REF2.set("expected"); - - Context ctx = test.apply(Context.empty()); - Map asMap = new HashMap<>(); - ctx.forEach(asMap::put); //easier to assert - - assertThat(asMap) - .containsEntry(KEY2, "expected") - .hasSize(1); - } } @Nested