Skip to content

Commit

Permalink
Add the means to extract the contextual underlying channel from HttpC…
Browse files Browse the repository at this point in the history
…hannel without excessive typecasting

Signed-off-by: Andriy Redko <andriy.redko@aiven.io>
  • Loading branch information
reta committed Jan 4, 2024
1 parent 178a7a0 commit dd95708
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Changed
- Mute the query profile IT with concurrent execution ([#9840](https://github.com/opensearch-project/OpenSearch/pull/9840))
- Force merge with `only_expunge_deletes` honors max segment size ([#10036](https://github.com/opensearch-project/OpenSearch/pull/10036))
- Add the means to extract the contextual properties from HttpChannel, TcpCChannel and TrasportChannel without excessive typecasting ([#10562](https://github.com/opensearch-project/OpenSearch/pull/10562))
- Add the means to extract the contextual properties from HttpChannel, TcpCChannel and TrasportChannel without excessive typecasting ([#10562](https://github.com/opensearch-project/OpenSearch/pull/10562)), ([#11748](https://github.com/opensearch-project/OpenSearch/pull/11748))
- Introduce new dynamic cluster setting to control slice computation for concurrent segment search ([#9107](https://github.com/opensearch-project/OpenSearch/pull/9107))
- Search pipelines now support asynchronous request and response processors to avoid blocking on a transport thread ([#10598](https://github.com/opensearch-project/OpenSearch/pull/10598))
- [Remote Store] Add Remote Store backpressure rejection stats to `_nodes/stats` ([#10524](https://github.com/opensearch-project/OpenSearch/pull/10524))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import io.netty.channel.ChannelPipeline;

public class Netty4HttpChannel implements HttpChannel {
private static final String CHANNEL_PROPERTY = "channel";

private final Channel channel;
private final CompletableContext<Void> closeContext = new CompletableContext<>();
Expand Down Expand Up @@ -102,6 +103,10 @@ public Channel getNettyChannel() {
@SuppressWarnings("unchecked")
@Override
public <T> Optional<T> get(String name, Class<T> clazz) {
if (CHANNEL_PROPERTY.equalsIgnoreCase(name) && clazz.isAssignableFrom(Channel.class)) {
return (Optional<T>) Optional.of(getNettyChannel());
}

Object handler = getNettyChannel().pipeline().get(name);

if (handler == null && inboundPipeline() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.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 testChannelAttributeMatchesNettyChannel() {
final Optional<Channel> channelOpt = netty4HttpChannel.get("channel", Channel.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));
}
}

0 comments on commit dd95708

Please sign in to comment.