core,netty,okhttp,alts,inprocess: deprecate usePlaintext(boolean)

This commit is contained in:
Carl Mastrangelo 2018-02-28 08:53:14 -08:00 committed by GitHub
parent 1b5aadf068
commit 7af2373a03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 86 additions and 20 deletions

View File

@ -58,7 +58,7 @@ final class HandshakerServiceChannel {
NettyChannelBuilder.forTarget(handshakerAddress) NettyChannelBuilder.forTarget(handshakerAddress)
.directExecutor() .directExecutor()
.eventLoopGroup(new NioEventLoopGroup(1, clientThreadFactory)) .eventLoopGroup(new NioEventLoopGroup(1, clientThreadFactory))
.usePlaintext(true) .usePlaintext()
.build(); .build();
return channel; return channel;
} }

View File

@ -57,7 +57,7 @@ public class LoadWorkerTest {
int port = Utils.pickUnusedPort(); int port = Utils.pickUnusedPort();
worker = new LoadWorker(port, 0); worker = new LoadWorker(port, 0);
worker.start(); worker.start();
channel = NettyChannelBuilder.forAddress("localhost", port).usePlaintext(true).build(); channel = NettyChannelBuilder.forAddress("localhost", port).usePlaintext().build();
workerServiceStub = WorkerServiceGrpc.newStub(channel); workerServiceStub = WorkerServiceGrpc.newStub(channel);
marksQueue = new LinkedBlockingQueue<Stats.ClientStats>(); marksQueue = new LinkedBlockingQueue<Stats.ClientStats>();
} }

View File

@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/3363") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/3363")
public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>> public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilder<T>>
extends ManagedChannelBuilder<T> { extends ManagedChannelBuilder<T> {
/** /**
* The default constructor. * The default constructor.
*/ */
@ -91,9 +92,19 @@ public abstract class ForwardingChannelBuilder<T extends ForwardingChannelBuilde
return thisT(); return thisT();
} }
/**
* @deprecated use {@link #usePlaintext()} instead.
*/
@Override @Override
@Deprecated
public T usePlaintext(boolean skipNegotiation) { public T usePlaintext(boolean skipNegotiation) {
delegate().usePlaintext(skipNegotiation); ManagedChannelBuilder<?> o = delegate().usePlaintext(skipNegotiation);
return thisT();
}
@Override
public T usePlaintext() {
delegate().usePlaintext();
return thisT(); return thisT();
} }

View File

@ -152,13 +152,38 @@ public abstract class ManagedChannelBuilder<T extends ManagedChannelBuilder<T>>
* *
* @param skipNegotiation @{code true} if there is a priori knowledge that the endpoint supports * @param skipNegotiation @{code true} if there is a priori knowledge that the endpoint supports
* plaintext, {@code false} if plaintext use must be negotiated. * plaintext, {@code false} if plaintext use must be negotiated.
* @deprecated Use {@link #usePlaintext()} instead.
* *
* @throws UnsupportedOperationException if plaintext mode is not supported. * @throws UnsupportedOperationException if plaintext mode is not supported.
* @return this * @return this
* @since 1.0.0 * @since 1.0.0
*/ */
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772") @ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772")
public abstract T usePlaintext(boolean skipNegotiation); @Deprecated
public T usePlaintext(boolean skipNegotiation) {
throw new UnsupportedOperationException();
}
/**
* Use of a plaintext connection to the server. By default a secure connection mechanism
* such as TLS will be used.
*
* <p>Should only be used for testing or for APIs where the use of such API or the data
* exchanged is not sensitive.
*
* <p>This assumes prior knowledge that the target of this channel is using plaintext. It will
* not perform HTTP/1.1 upgrades.
*
*
* @throws UnsupportedOperationException if plaintext mode is not supported.
* @return this
* @since 1.11.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1772")
@SuppressWarnings("deprecation")
public T usePlaintext() {
return usePlaintext(true);
}
/** /**
* Makes the client use TLS. * Makes the client use TLS.

View File

@ -94,12 +94,23 @@ public final class InProcessChannelBuilder extends
/** /**
* Does nothing. * Does nothing.
*
* @deprecated use {@link #usePlaintext()} instead.
*/ */
@Override @Override
@Deprecated
public InProcessChannelBuilder usePlaintext(boolean skipNegotiation) { public InProcessChannelBuilder usePlaintext(boolean skipNegotiation) {
return this; return this;
} }
/**
* Does nothing.
*/
@Override
public InProcessChannelBuilder usePlaintext() {
return this;
}
/** Does nothing. */ /** Does nothing. */
@Override @Override
public InProcessChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) { public InProcessChannelBuilder keepAliveTime(long keepAliveTime, TimeUnit timeUnit) {

View File

@ -422,10 +422,5 @@ public class AbstractManagedChannelImplBuilderTest {
protected ClientTransportFactory buildTransportFactory() { protected ClientTransportFactory buildTransportFactory() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override
public Builder usePlaintext(boolean value) {
throw new UnsupportedOperationException();
}
} }
} }

View File

@ -128,7 +128,7 @@ public class ManagedChannelImplIdlenessTest {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override public Builder usePlaintext(boolean b) { @Override public Builder usePlaintext() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

View File

@ -218,7 +218,7 @@ public class ManagedChannelImplTest {
return NAME_RESOLVER_PARAMS; return NAME_RESOLVER_PARAMS;
} }
@Override public Builder usePlaintext(boolean b) { @Override public Builder usePlaintext() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
} }

View File

@ -370,7 +370,7 @@ public class TestServiceClient {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} else { } else {
okBuilder.usePlaintext(true); okBuilder.usePlaintext();
} }
if (fullStreamDecompression) { if (fullStreamDecompression) {
okBuilder.enableFullStreamDecompression(); okBuilder.enableFullStreamDecompression();

View File

@ -193,7 +193,7 @@ public class CompressionTest {
.decompressorRegistry(clientDecompressors) .decompressorRegistry(clientDecompressors)
.compressorRegistry(clientCompressors) .compressorRegistry(clientCompressors)
.intercept(new ClientCompressorInterceptor()) .intercept(new ClientCompressorInterceptor())
.usePlaintext(true) .usePlaintext()
.build(); .build();
stub = TestServiceGrpc.newBlockingStub(channel); stub = TestServiceGrpc.newBlockingStub(channel);

View File

@ -129,7 +129,7 @@ public class StressTestClientTest {
// Connect to the metrics service // Connect to the metrics service
ManagedChannel ch = ManagedChannelBuilder.forAddress("localhost", client.getMetricServerPort()) ManagedChannel ch = ManagedChannelBuilder.forAddress("localhost", client.getMetricServerPort())
.usePlaintext(true) .usePlaintext()
.build(); .build();
MetricsServiceGrpc.MetricsServiceBlockingStub stub = MetricsServiceGrpc.newBlockingStub(ch); MetricsServiceGrpc.MetricsServiceBlockingStub stub = MetricsServiceGrpc.newBlockingStub(ch);

View File

@ -167,7 +167,7 @@ public class TransportCompressionTest extends AbstractInteropTest {
}; };
} }
}) })
.usePlaintext(true); .usePlaintext();
io.grpc.internal.TestingAccessor.setStatsImplementation( io.grpc.internal.TestingAccessor.setStatsImplementation(
builder, createClientCensusStatsModule()); builder, createClientCensusStatsModule());
return builder.build(); return builder.build();

View File

@ -78,7 +78,7 @@ public final class ShadingTest {
.build().start(); .build().start();
channel = ManagedChannelBuilder channel = ManagedChannelBuilder
.forAddress("localhost", server.getPort()) .forAddress("localhost", server.getPort())
.usePlaintext(true) .usePlaintext()
.build(); .build();
SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel); SimpleServiceBlockingStub stub = SimpleServiceGrpc.newBlockingStub(channel);
assertThat(SimpleResponse.getDefaultInstance()) assertThat(SimpleResponse.getDefaultInstance())

View File

@ -226,8 +226,11 @@ public final class NettyChannelBuilder
/** /**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT} or * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT} or
* {@code PLAINTEXT_UPGRADE}. * {@code PLAINTEXT_UPGRADE}.
*
* @deprecated use {@link #usePlaintext()} instead.
*/ */
@Override @Override
@Deprecated
public NettyChannelBuilder usePlaintext(boolean skipNegotiation) { public NettyChannelBuilder usePlaintext(boolean skipNegotiation) {
if (skipNegotiation) { if (skipNegotiation) {
negotiationType(NegotiationType.PLAINTEXT); negotiationType(NegotiationType.PLAINTEXT);
@ -237,6 +240,15 @@ public final class NettyChannelBuilder
return this; return this;
} }
/**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}.
*/
@Override
public NettyChannelBuilder usePlaintext() {
negotiationType(NegotiationType.PLAINTEXT);
return this;
}
/** /**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}.
*/ */

View File

@ -273,7 +273,7 @@ public class OkHttpChannelBuilder extends
* <p>By default {@link #DEFAULT_CONNECTION_SPEC} will be used. * <p>By default {@link #DEFAULT_CONNECTION_SPEC} will be used.
* *
* <p>This method is only used when building a secure connection. For plaintext * <p>This method is only used when building a secure connection. For plaintext
* connection, use {@link #usePlaintext} instead. * connection, use {@link #usePlaintext()} instead.
* *
* @throws IllegalArgumentException * @throws IllegalArgumentException
* If {@code connectionSpec} is not with TLS * If {@code connectionSpec} is not with TLS
@ -286,8 +286,11 @@ public class OkHttpChannelBuilder extends
/** /**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}. * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}.
*
* @deprecated use {@link #usePlaintext()} instead.
*/ */
@Override @Override
@Deprecated
public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation) { public final OkHttpChannelBuilder usePlaintext(boolean skipNegotiation) {
if (skipNegotiation) { if (skipNegotiation) {
negotiationType(NegotiationType.PLAINTEXT); negotiationType(NegotiationType.PLAINTEXT);
@ -297,6 +300,15 @@ public class OkHttpChannelBuilder extends
return this; return this;
} }
/**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code PLAINTEXT}.
*/
@Override
public final OkHttpChannelBuilder usePlaintext() {
negotiationType(NegotiationType.PLAINTEXT);
return this;
}
/** /**
* Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}. * Equivalent to using {@link #negotiationType(NegotiationType)} with {@code TLS}.
*/ */

View File

@ -108,14 +108,14 @@ public class OkHttpChannelBuilderTest {
@Test @Test
public void usePlaintext_newClientTransportAllowed() { public void usePlaintext_newClientTransportAllowed() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(true); OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext();
builder.buildTransportFactory().newClientTransport(new InetSocketAddress(5678), builder.buildTransportFactory().newClientTransport(new InetSocketAddress(5678),
"dummy_authority", "dummy_userAgent", null /* proxy */); "dummy_authority", "dummy_userAgent", null /* proxy */);
} }
@Test @Test
public void usePlaintextDefaultPort() { public void usePlaintextDefaultPort() {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext(true); OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234).usePlaintext();
assertEquals(GrpcUtil.DEFAULT_PORT_PLAINTEXT, assertEquals(GrpcUtil.DEFAULT_PORT_PLAINTEXT,
builder.getNameResolverParams().get(NameResolver.Factory.PARAMS_DEFAULT_PORT).intValue()); builder.getNameResolverParams().get(NameResolver.Factory.PARAMS_DEFAULT_PORT).intValue());
} }
@ -125,7 +125,7 @@ public class OkHttpChannelBuilderTest {
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234); OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234);
assertNotNull(builder.createSocketFactory()); assertNotNull(builder.createSocketFactory());
builder.usePlaintext(true); builder.usePlaintext();
assertNull(builder.createSocketFactory()); assertNull(builder.createSocketFactory());
} }
} }