-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,339 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...etty5-core/src/contextPropagationTest/java/reactor/netty5/ChannelContextAccessorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package reactor.netty5; | ||
|
||
import io.micrometer.context.ContextRegistry; | ||
import io.micrometer.context.ContextSnapshot; | ||
import io.netty5.channel.Channel; | ||
import io.netty5.channel.embedded.EmbeddedChannel; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import reactor.util.context.Context; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static reactor.netty5.ReactorNetty.setChannelContext; | ||
|
||
class ChannelContextAccessorTest { | ||
static final ContextRegistry registry = ContextRegistry.getInstance(); | ||
|
||
static Object[][] data() { | ||
return new Object[][]{ | ||
{null, "test1"}, | ||
{Context.empty(), "test1"}, | ||
{Context.of("test", "test"), "test1"} | ||
}; | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("data") | ||
@SuppressWarnings("FutureReturnValueIgnored") | ||
void test(Context context, String expectation) { | ||
registry.registerThreadLocalAccessor(new TestThreadLocalAccessor()); | ||
|
||
TestThreadLocalHolder.value("test1"); | ||
|
||
Channel channel = new EmbeddedChannel(); | ||
setChannelContext(channel, context); | ||
|
||
ContextSnapshot.captureAll(registry).updateContext(channel); | ||
|
||
TestThreadLocalHolder.value("test2"); | ||
|
||
try (ContextSnapshot.Scope scope = ContextSnapshot.captureFrom(channel).setThreadLocals()) { | ||
assertThat(TestThreadLocalHolder.value()).isEqualTo(expectation); | ||
} | ||
finally { | ||
//"FutureReturnValueIgnored" this is deliberate | ||
channel.close(); | ||
registry.removeThreadLocalAccessor(TestThreadLocalAccessor.KEY); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...r-netty5-core/src/contextPropagationTest/java/reactor/netty5/TestThreadLocalAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package reactor.netty5; | ||
|
||
import io.micrometer.context.ThreadLocalAccessor; | ||
|
||
final class TestThreadLocalAccessor implements ThreadLocalAccessor<String> { | ||
|
||
static final String KEY = "testContextPropagation"; | ||
|
||
@Override | ||
public Object key() { | ||
return KEY; | ||
} | ||
|
||
@Override | ||
public String getValue() { | ||
return TestThreadLocalHolder.value(); | ||
} | ||
|
||
@Override | ||
public void setValue(String value) { | ||
TestThreadLocalHolder.value(value); | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
TestThreadLocalHolder.reset(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...tor-netty5-core/src/contextPropagationTest/java/reactor/netty5/TestThreadLocalHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (c) 2022 VMware, Inc. or its affiliates, All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package reactor.netty5; | ||
|
||
final class TestThreadLocalHolder { | ||
|
||
static final ThreadLocal<String> holder = new ThreadLocal<>(); | ||
|
||
static void reset() { | ||
holder.remove(); | ||
} | ||
|
||
static String value() { | ||
return holder.get(); | ||
} | ||
|
||
static void value(String value) { | ||
holder.set(value); | ||
} | ||
} |
Oops, something went wrong.