-
Notifications
You must be signed in to change notification settings - Fork 3.9k
netty server sockets shall be configurable #3755
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -23,9 +23,18 @@ | |
| import io.grpc.internal.ServerTransport; | ||
| import io.grpc.internal.ServerTransportListener; | ||
| import io.grpc.internal.TransportTracer; | ||
| import io.netty.channel.Channel; | ||
| import io.netty.channel.ChannelOption; | ||
| import io.netty.channel.WriteBufferWaterMark; | ||
| import io.netty.channel.socket.nio.NioServerSocketChannel; | ||
| import java.net.InetSocketAddress; | ||
| import java.net.Socket; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CountDownLatch; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
|
|
||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
|
|
@@ -39,6 +48,7 @@ public void getPort() throws Exception { | |
| NettyServer ns = new NettyServer( | ||
| addr, | ||
| NioServerSocketChannel.class, | ||
| new HashMap<ChannelOption<?>, Object>(), | ||
| null, // no boss group | ||
| null, // no event group | ||
| new ProtocolNegotiators.PlaintextNegotiator(), | ||
|
|
@@ -75,6 +85,7 @@ public void getPort_notStarted() throws Exception { | |
| NettyServer ns = new NettyServer( | ||
| addr, | ||
| NioServerSocketChannel.class, | ||
| new HashMap<ChannelOption<?>, Object>(), | ||
| null, // no boss group | ||
| null, // no event group | ||
| new ProtocolNegotiators.PlaintextNegotiator(), | ||
|
|
@@ -91,4 +102,65 @@ public void getPort_notStarted() throws Exception { | |
|
|
||
| assertThat(ns.getPort()).isEqualTo(-1); | ||
| } | ||
|
|
||
| @Test(timeout = 60000) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should not use timeout here, and instead use a JUnit4 timeout rule:
The reason is that the timeout rule works correctly when debugging / stepping through code. |
||
| public void childChannelOptions() throws Exception { | ||
| final int originalLowWaterMark = 2097169; | ||
| final int originalHighWaterMark = 2097211; | ||
|
|
||
| Map<ChannelOption<?>, Object> channelOptions = new HashMap<ChannelOption<?>, Object>(); | ||
|
|
||
| channelOptions.put(ChannelOption.WRITE_BUFFER_WATER_MARK, | ||
| new WriteBufferWaterMark(originalLowWaterMark, originalHighWaterMark)); | ||
|
|
||
| final AtomicInteger lowWaterMark = new AtomicInteger(0); | ||
| final AtomicInteger highWaterMark = new AtomicInteger(0); | ||
|
|
||
| final CountDownLatch countDownLatch = new CountDownLatch(1); | ||
|
|
||
| NettyServer ns = new NettyServer( | ||
| new InetSocketAddress(9999), | ||
| NioServerSocketChannel.class, | ||
| channelOptions, | ||
| null, // no boss group | ||
| null, // no event group | ||
| new ProtocolNegotiators.PlaintextNegotiator(), | ||
| Collections.<ServerStreamTracer.Factory>emptyList(), | ||
| TransportTracer.getDefaultFactory(), | ||
| 1, // ignore | ||
| 1, // ignore | ||
| 1, // ignore | ||
| 1, // ignore | ||
| 1, // ignore | ||
| 1, 1, // ignore | ||
| 1, 1, // ignore | ||
| true, 0); // ignore | ||
| ns.start(new ServerListener() { | ||
| @Override | ||
| public ServerTransportListener transportCreated(ServerTransport transport) { | ||
| Channel channel = ((NettyServerTransport)transport).channel(); | ||
| WriteBufferWaterMark writeBufferWaterMark = channel.config() | ||
| .getOption(ChannelOption.WRITE_BUFFER_WATER_MARK); | ||
| lowWaterMark.set(writeBufferWaterMark.low()); | ||
| highWaterMark.set(writeBufferWaterMark.high()); | ||
|
|
||
| countDownLatch.countDown(); | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void serverShutdown() {} | ||
| }); | ||
|
|
||
| Socket socket = new Socket(); | ||
| socket.connect(new InetSocketAddress("localhost", 9999), 8000); | ||
| countDownLatch.await(); | ||
| socket.close(); | ||
|
|
||
| assertThat(lowWaterMark.get()).isEqualTo(originalLowWaterMark); | ||
| assertThat(highWaterMark.get()).isEqualTo(originalHighWaterMark); | ||
|
|
||
| ns.shutdown(); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be a copy of the map. If someone modifies the map later, existing servers would accidentally see the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. How about coping the map in NettyServer constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems fine to me.