forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the means to extract the contextual underlying channel from HttpC…
…hannel without excessive typecasting (opensearch-project#11751) Signed-off-by: Andriy Redko <[email protected]>
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
...les/transport-netty4/src/test/java/org/opensearch/http/netty4/Netty4HttpChannelTests.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,52 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.http.netty4; | ||
|
||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.transport.Netty4NioSocketChannel; | ||
import org.junit.Before; | ||
|
||
import java.util.Optional; | ||
|
||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelOutboundInvoker; | ||
import io.netty.channel.ServerChannel; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.sameInstance; | ||
|
||
public class Netty4HttpChannelTests extends OpenSearchTestCase { | ||
private Netty4HttpChannel netty4HttpChannel; | ||
private Channel channel; | ||
|
||
@Before | ||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
channel = new Netty4NioSocketChannel(); | ||
netty4HttpChannel = new Netty4HttpChannel(channel); | ||
} | ||
|
||
public void testChannelAttributeMatchesChannel() { | ||
final Optional<Channel> channelOpt = netty4HttpChannel.get("channel", Channel.class); | ||
assertThat(channelOpt.isPresent(), is(true)); | ||
assertThat(channelOpt.get(), sameInstance(channel)); | ||
} | ||
|
||
public void testChannelAttributeMatchesChannelOutboundInvoker() { | ||
final Optional<ChannelOutboundInvoker> channelOpt = netty4HttpChannel.get("channel", ChannelOutboundInvoker.class); | ||
assertThat(channelOpt.isPresent(), is(true)); | ||
assertThat(channelOpt.get(), sameInstance(channel)); | ||
} | ||
|
||
public void testChannelAttributeIsEmpty() { | ||
final Optional<ServerChannel> channelOpt = netty4HttpChannel.get("channel", ServerChannel.class); | ||
assertThat(channelOpt.isEmpty(), is(true)); | ||
} | ||
} |