Skip to content

Commit

Permalink
interop-testing: Avoid Netty-specific APIs to creating channels
Browse files Browse the repository at this point in the history
We prefer to test using the stable APIs, as they are what our users
should be using. Http2Client continues using NettyChannelBuilder because
it is intended to test grpc-netty.
  • Loading branch information
ejona86 committed Feb 12, 2024
1 parent 372a535 commit 92463f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@
import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.protobuf.ByteString;
import io.grpc.ChannelCredentials;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannel;
import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import io.grpc.netty.NegotiationType;
import io.grpc.netty.NettyChannelBuilder;
import io.grpc.stub.StreamObserver;
import io.grpc.testing.integration.Messages.Payload;
import io.grpc.testing.integration.Messages.SimpleRequest;
import io.grpc.testing.integration.Messages.SimpleResponse;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -353,15 +351,8 @@ private void assertResponseEquals(SimpleResponse response, SimpleResponse golden
}

private ManagedChannel createChannel() {
InetAddress address;
try {
address = InetAddress.getByName(serverHost);
} catch (UnknownHostException ex) {
throw new RuntimeException(ex);
}
return NettyChannelBuilder.forAddress(new InetSocketAddress(address, serverPort))
.negotiationType(NegotiationType.PLAINTEXT)
.build();
ChannelCredentials creds = InsecureChannelCredentials.create();
return NettyChannelBuilder.forAddress(serverHost, serverPort, creds).build();
}

private static String validTestCasesHelpText() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import static org.junit.Assert.assertTrue;

import io.grpc.ChannelCredentials;
import io.grpc.Grpc;
import io.grpc.InsecureChannelCredentials;
import io.grpc.ManagedChannelBuilder;
import io.grpc.alts.ComputeEngineChannelCredentials;
import io.grpc.netty.NettyChannelBuilder;
import java.util.ArrayList;
import java.util.logging.Logger;

Expand Down Expand Up @@ -289,7 +289,7 @@ protected ManagedChannelBuilder<?> createChannelBuilder() {
default:
throw new IllegalArgumentException("Unknown custom credentials: " + credentialsType);
}
return NettyChannelBuilder.forTarget(serverUri, channelCredentials)
return Grpc.newChannelBuilder(serverUri, channelCredentials)
.keepAliveTime(3600, SECONDS)
.keepAliveTimeout(20, SECONDS);
}
Expand Down

0 comments on commit 92463f6

Please sign in to comment.