mirror of https://github.com/grpc/grpc-java.git
tests: Replace usages of deprecated junit ExpectedException with assertThrows (#12103)
This commit is contained in:
parent
83538cdae3
commit
22cf7cf2ac
|
@ -19,6 +19,7 @@ package io.grpc.netty;
|
|||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
|
@ -39,17 +40,13 @@ import java.net.InetSocketAddress;
|
|||
import java.net.SocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import javax.net.ssl.SSLException;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
public class NettyChannelBuilderTest {
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
private final SslContext noSslContext = null;
|
||||
|
||||
private void shutdown(ManagedChannel mc) throws Exception {
|
||||
|
@ -107,10 +104,9 @@ public class NettyChannelBuilderTest {
|
|||
public void failOverrideInvalidAuthority() {
|
||||
NettyChannelBuilder builder = new NettyChannelBuilder(getTestSocketAddress());
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid authority:");
|
||||
|
||||
builder.overrideAuthority("[invalidauthority");
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.overrideAuthority("[invalidauthority"));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid authority: [invalidauthority");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -128,20 +124,18 @@ public class NettyChannelBuilderTest {
|
|||
NettyChannelBuilder builder = new NettyChannelBuilder(getTestSocketAddress())
|
||||
.disableCheckAuthority()
|
||||
.enableCheckAuthority();
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid authority:");
|
||||
builder.overrideAuthority("[invalidauthority");
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.overrideAuthority("[invalidauthority"));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid authority: [invalidauthority");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failInvalidAuthority() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid host or port");
|
||||
|
||||
@SuppressWarnings("AddressSelection") // We actually expect zero addresses!
|
||||
Object unused =
|
||||
NettyChannelBuilder.forAddress(new InetSocketAddress("invalid_authority", 1234));
|
||||
InetSocketAddress address = new InetSocketAddress("invalid_authority", 1234);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> NettyChannelBuilder.forAddress(address));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid host or port: invalid_authority 1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -155,10 +149,10 @@ public class NettyChannelBuilderTest {
|
|||
SslContext sslContext = mock(SslContext.class);
|
||||
NettyChannelBuilder builder = new NettyChannelBuilder(getTestSocketAddress());
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Server SSL context can not be used for client channel");
|
||||
|
||||
builder.sslContext(sslContext);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.sslContext(sslContext));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Server SSL context can not be used for client channel");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -166,10 +160,10 @@ public class NettyChannelBuilderTest {
|
|||
NettyChannelBuilder builder = NettyChannelBuilder.forTarget(
|
||||
"fakeTarget", InsecureChannelCredentials.create());
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Cannot change security when using ChannelCredentials");
|
||||
|
||||
builder.negotiationType(NegotiationType.TLS);
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
() -> builder.negotiationType(NegotiationType.TLS));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Cannot change security when using ChannelCredentials");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -177,10 +171,10 @@ public class NettyChannelBuilderTest {
|
|||
NettyChannelBuilder builder = NettyChannelBuilder.forAddress(
|
||||
getTestSocketAddress(), InsecureChannelCredentials.create());
|
||||
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Cannot change security when using ChannelCredentials");
|
||||
|
||||
builder.negotiationType(NegotiationType.TLS);
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
() -> builder.negotiationType(NegotiationType.TLS));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Cannot change security when using ChannelCredentials");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -205,10 +199,9 @@ public class NettyChannelBuilderTest {
|
|||
|
||||
@Test
|
||||
public void createProtocolNegotiatorByType_tlsWithNoContext() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
NettyChannelBuilder.createProtocolNegotiatorByType(
|
||||
NegotiationType.TLS,
|
||||
noSslContext, null);
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> NettyChannelBuilder.createProtocolNegotiatorByType(
|
||||
NegotiationType.TLS, noSslContext, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -245,38 +238,40 @@ public class NettyChannelBuilderTest {
|
|||
public void negativeKeepAliveTime() {
|
||||
NettyChannelBuilder builder = NettyChannelBuilder.forTarget("fakeTarget");
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("keepalive time must be positive");
|
||||
builder.keepAliveTime(-1L, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.keepAliveTime(-1L, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("keepalive time must be positive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeKeepAliveTimeout() {
|
||||
NettyChannelBuilder builder = NettyChannelBuilder.forTarget("fakeTarget");
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("keepalive timeout must be positive");
|
||||
builder.keepAliveTimeout(-1L, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.keepAliveTimeout(-1L, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("keepalive timeout must be positive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEventLoopAndChannelType_onlyGroupProvided() {
|
||||
NettyChannelBuilder builder = NettyChannelBuilder.forTarget("fakeTarget");
|
||||
builder.eventLoopGroup(mock(EventLoopGroup.class));
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Both EventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopAndChannelType);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Both EventLoopGroup and ChannelType should be provided or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEventLoopAndChannelType_onlyTypeProvided() {
|
||||
NettyChannelBuilder builder = NettyChannelBuilder.forTarget("fakeTarget");
|
||||
builder.channelType(LocalChannel.class, LocalAddress.class);
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Both EventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopAndChannelType);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Both EventLoopGroup and ChannelType should be provided or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -288,10 +283,11 @@ public class NettyChannelBuilderTest {
|
|||
return null;
|
||||
}
|
||||
});
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage("Both EventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopAndChannelType);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Both EventLoopGroup and ChannelType should be provided or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,20 +16,19 @@
|
|||
|
||||
package io.grpc.netty;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.truth.Truth;
|
||||
import io.grpc.ServerStreamTracer;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.local.LocalServerChannel;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -39,9 +38,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class NettyServerBuilderTest {
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private NettyServerBuilder builder = NettyServerBuilder.forPort(8080);
|
||||
|
||||
@Test
|
||||
|
@ -50,7 +46,7 @@ public class NettyServerBuilderTest {
|
|||
NettyServer server =
|
||||
builder.buildTransportServers(ImmutableList.<ServerStreamTracer.Factory>of());
|
||||
|
||||
Truth.assertThat(server.getListenSocketAddresses()).hasSize(2);
|
||||
assertThat(server.getListenSocketAddresses()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -63,121 +59,112 @@ public class NettyServerBuilderTest {
|
|||
SslContext sslContext = mock(SslContext.class);
|
||||
when(sslContext.isClient()).thenReturn(true);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Client SSL context can not be used for server");
|
||||
builder.sslContext(sslContext);
|
||||
IllegalArgumentException e = assertThrows(
|
||||
IllegalArgumentException.class, () -> builder.sslContext(sslContext));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Client SSL context can not be used for server");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfKeepAliveTimeNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("keepalive time must be positive");
|
||||
|
||||
builder.keepAliveTime(-10L, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.keepAliveTime(-10L, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("keepalive time must be positive:-10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfKeepAliveTimeoutNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("keepalive timeout must be positive");
|
||||
|
||||
builder.keepAliveTimeout(-10L, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.keepAliveTimeout(-10L, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("keepalive timeout must be positive: -10");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxConcurrentCallsPerConnectionNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("max must be positive");
|
||||
|
||||
builder.maxConcurrentCallsPerConnection(0);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxConcurrentCallsPerConnection(0));
|
||||
assertThat(e).hasMessageThat().isEqualTo("max must be positive: 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxInboundMetadataSizeNonPositive() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("maxInboundMetadataSize must be positive");
|
||||
|
||||
builder.maxInboundMetadataSize(0);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxInboundMetadataSize(0));
|
||||
assertThat(e).hasMessageThat().isEqualTo("maxInboundMetadataSize must be positive: 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfSoftInboundMetadataSizeNonPositive() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("softLimitHeaderListSize must be positive");
|
||||
|
||||
builder.maxInboundMetadataSize(0, 100);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxInboundMetadataSize(0, 100));
|
||||
assertThat(e).hasMessageThat().isEqualTo("softLimitHeaderListSize must be positive: 0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxInboundMetadataSizeSmallerThanSoft() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("must be greater than softLimitHeaderListSize");
|
||||
|
||||
builder.maxInboundMetadataSize(100, 80);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxInboundMetadataSize(100, 80));
|
||||
assertThat(e).hasMessageThat().isEqualTo("maxInboundMetadataSize: 80 "
|
||||
+ "must be greater than softLimitHeaderListSize: 100");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxConnectionIdleNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("max connection idle must be positive");
|
||||
|
||||
builder.maxConnectionIdle(-1, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxConnectionIdle(-1, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("max connection idle must be positive: -1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxConnectionAgeNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("max connection age must be positive");
|
||||
|
||||
builder.maxConnectionAge(-1, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxConnectionAge(-1, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("max connection age must be positive: -1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfMaxConnectionAgeGraceNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("max connection age grace must be non-negative");
|
||||
|
||||
builder.maxConnectionAgeGrace(-1, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.maxConnectionAgeGrace(-1, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("max connection age grace must be non-negative: -1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failIfPermitKeepAliveTimeNegative() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("permit keepalive time must be non-negative");
|
||||
|
||||
builder.permitKeepAliveTime(-1, TimeUnit.HOURS);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.permitKeepAliveTime(-1, TimeUnit.HOURS));
|
||||
assertThat(e).hasMessageThat().isEqualTo("permit keepalive time must be non-negative: -1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEventLoopsAndChannelType_onlyBossGroupProvided() {
|
||||
EventLoopGroup mockEventLoopGroup = mock(EventLoopGroup.class);
|
||||
builder.bossEventLoopGroup(mockEventLoopGroup);
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopsAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopsAndChannelType);
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided "
|
||||
+ "or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEventLoopsAndChannelType_onlyWorkerGroupProvided() {
|
||||
EventLoopGroup mockEventLoopGroup = mock(EventLoopGroup.class);
|
||||
builder.workerEventLoopGroup(mockEventLoopGroup);
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopsAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopsAndChannelType);
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided "
|
||||
+ "or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void assertEventLoopsAndChannelType_onlyTypeProvided() {
|
||||
builder.channelType(LocalServerChannel.class);
|
||||
thrown.expect(IllegalStateException.class);
|
||||
thrown.expectMessage(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided");
|
||||
|
||||
builder.assertEventLoopsAndChannelType();
|
||||
IllegalStateException e = assertThrows(IllegalStateException.class,
|
||||
builder::assertEventLoopsAndChannelType);
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"All of BossEventLoopGroup, WorkerEventLoopGroup and ChannelType should be provided "
|
||||
+ "or neither should be");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -146,7 +147,6 @@ import org.junit.BeforeClass;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.DisableOnDebug;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.junit.rules.Timeout;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -174,8 +174,6 @@ public class ProtocolNegotiatorsTest {
|
|||
|
||||
private static final int TIMEOUT_SECONDS = 60;
|
||||
@Rule public final TestRule globalTimeout = new DisableOnDebug(Timeout.seconds(TIMEOUT_SECONDS));
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final EventLoopGroup group = new DefaultEventLoop();
|
||||
private Channel chan;
|
||||
|
@ -714,11 +712,10 @@ public class ProtocolNegotiatorsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void tlsHandler_failsOnNullEngine() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("ssl");
|
||||
|
||||
Object unused = ProtocolNegotiators.serverTls(null);
|
||||
public void tlsHandler_failsOnNullEngine() {
|
||||
NullPointerException e = assertThrows(NullPointerException.class,
|
||||
() -> ProtocolNegotiators.serverTls(null));
|
||||
assertThat(e).hasMessageThat().isEqualTo("sslContext");
|
||||
}
|
||||
|
||||
|
||||
|
@ -1058,9 +1055,8 @@ public class ProtocolNegotiatorsTest {
|
|||
|
||||
@Test
|
||||
public void tls_failsOnNullSslContext() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
|
||||
Object unused = ProtocolNegotiators.tls(null, null);
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ProtocolNegotiators.tls(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1090,17 +1086,16 @@ public class ProtocolNegotiatorsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void httpProxy_nullAddressNpe() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
Object unused =
|
||||
ProtocolNegotiators.httpProxy(null, "user", "pass", ProtocolNegotiators.plaintext());
|
||||
public void httpProxy_nullAddressNpe() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ProtocolNegotiators.httpProxy(null, "user", "pass", ProtocolNegotiators.plaintext()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpProxy_nullNegotiatorNpe() throws Exception {
|
||||
thrown.expect(NullPointerException.class);
|
||||
Object unused = ProtocolNegotiators.httpProxy(
|
||||
InetSocketAddress.createUnresolved("localhost", 80), "user", "pass", null);
|
||||
public void httpProxy_nullNegotiatorNpe() {
|
||||
assertThrows(NullPointerException.class,
|
||||
() -> ProtocolNegotiators.httpProxy(
|
||||
InetSocketAddress.createUnresolved("localhost", 80), "user", "pass", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1218,9 +1213,8 @@ public class ProtocolNegotiatorsTest {
|
|||
assertFalse(negotiationFuture.isDone());
|
||||
String response = "HTTP/1.1 500 OMG\r\nContent-Length: 4\r\n\r\noops";
|
||||
serverContext.writeAndFlush(bb(response, serverContext.channel())).sync();
|
||||
thrown.expect(ProxyConnectException.class);
|
||||
try {
|
||||
negotiationFuture.sync();
|
||||
assertThrows(ProxyConnectException.class, negotiationFuture::sync);
|
||||
} finally {
|
||||
channel.close();
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import static org.junit.Assert.assertEquals;
|
|||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
|
@ -57,7 +58,6 @@ import javax.net.ssl.TrustManager;
|
|||
import javax.security.auth.x500.X500Principal;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -67,8 +67,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class OkHttpChannelBuilderTest {
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
@Rule public final GrpcCleanupRule grpcCleanupRule = new GrpcCleanupRule();
|
||||
|
||||
@Test
|
||||
|
@ -100,10 +98,9 @@ public class OkHttpChannelBuilderTest {
|
|||
@Test
|
||||
public void failOverrideInvalidAuthority() {
|
||||
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("good", 1234);
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid authority:");
|
||||
builder.overrideAuthority("[invalidauthority");
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.overrideAuthority("[invalidauthority"));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid authority: [invalidauthority");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -119,17 +116,16 @@ public class OkHttpChannelBuilderTest {
|
|||
.disableCheckAuthority()
|
||||
.enableCheckAuthority();
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid authority:");
|
||||
builder.overrideAuthority("[invalidauthority");
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.overrideAuthority("[invalidauthority"));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid authority: [invalidauthority");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failInvalidAuthority() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid host or port");
|
||||
|
||||
OkHttpChannelBuilder.forAddress("invalid_authority", 1234);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> OkHttpChannelBuilder.forAddress("invalid_authority", 1234));
|
||||
assertThat(e.getMessage()).isEqualTo("Invalid host or port: invalid_authority 1234");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -396,10 +392,10 @@ public class OkHttpChannelBuilderTest {
|
|||
|
||||
@Test
|
||||
public void failForUsingClearTextSpecDirectly() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("plaintext ConnectionSpec is not accepted");
|
||||
|
||||
OkHttpChannelBuilder.forAddress("host", 1234).connectionSpec(ConnectionSpec.CLEARTEXT);
|
||||
OkHttpChannelBuilder builder = OkHttpChannelBuilder.forAddress("host", 1234);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> builder.connectionSpec(ConnectionSpec.CLEARTEXT));
|
||||
assertThat(e).hasMessageThat().isEqualTo("plaintext ConnectionSpec is not accepted");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
package io.grpc.okhttp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -37,9 +39,7 @@ import javax.net.ssl.HandshakeCompletedListener;
|
|||
import javax.net.ssl.SSLParameters;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocket;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
|
@ -49,9 +49,6 @@ import org.mockito.ArgumentMatchers;
|
|||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class OkHttpProtocolNegotiatorTest {
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final SSLSocket sock = mock(SSLSocket.class);
|
||||
private final Platform platform = mock(Platform.class);
|
||||
|
||||
|
@ -118,21 +115,19 @@ public class OkHttpProtocolNegotiatorTest {
|
|||
OkHttpProtocolNegotiator negotiator = OkHttpProtocolNegotiator.get();
|
||||
doReturn(parameters).when(sock).getSSLParameters();
|
||||
doThrow(new IOException()).when(sock).startHandshake();
|
||||
thrown.expect(IOException.class);
|
||||
|
||||
negotiator.negotiate(sock, "hostname", ImmutableList.of(Protocol.HTTP_2));
|
||||
assertThrows(IOException.class,
|
||||
() -> negotiator.negotiate(sock, "hostname", ImmutableList.of(Protocol.HTTP_2)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negotiate_noSelectedProtocol() throws Exception {
|
||||
public void negotiate_noSelectedProtocol() {
|
||||
Platform platform = mock(Platform.class);
|
||||
|
||||
OkHttpProtocolNegotiator negotiator = new OkHttpProtocolNegotiator(platform);
|
||||
|
||||
thrown.expect(RuntimeException.class);
|
||||
thrown.expectMessage("TLS ALPN negotiation failed");
|
||||
|
||||
negotiator.negotiate(sock, "hostname", ImmutableList.of(Protocol.HTTP_2));
|
||||
RuntimeException e = assertThrows(RuntimeException.class,
|
||||
() -> negotiator.negotiate(sock, "hostname", ImmutableList.of(Protocol.HTTP_2)));
|
||||
assertThat(e).hasMessageThat().isEqualTo("TLS ALPN negotiation failed with protocols: [h2]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -150,7 +145,7 @@ public class OkHttpProtocolNegotiatorTest {
|
|||
|
||||
// Checks that the super class is properly invoked.
|
||||
@Test
|
||||
public void negotiate_android_handshakeFails() throws Exception {
|
||||
public void negotiate_android_handshakeFails() {
|
||||
when(platform.getTlsExtensionType()).thenReturn(TlsExtensionType.ALPN_AND_NPN);
|
||||
AndroidNegotiator negotiator = new AndroidNegotiator(platform);
|
||||
|
||||
|
@ -161,10 +156,9 @@ public class OkHttpProtocolNegotiatorTest {
|
|||
}
|
||||
};
|
||||
|
||||
thrown.expect(IOException.class);
|
||||
thrown.expectMessage("expected");
|
||||
|
||||
negotiator.negotiate(androidSock, "hostname", ImmutableList.of(Protocol.HTTP_2));
|
||||
IOException e = assertThrows(IOException.class,
|
||||
() -> negotiator.negotiate(androidSock, "hostname", ImmutableList.of(Protocol.HTTP_2)));
|
||||
assertThat(e).hasMessageThat().isEqualTo("expected");
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
|
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
package io.grpc.okhttp;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import io.grpc.InternalChannelz.SocketOptions;
|
||||
|
@ -26,9 +28,7 @@ import io.grpc.okhttp.internal.TlsVersion;
|
|||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -38,16 +38,12 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class UtilsTest {
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void convertSpecRejectsPlaintext() {
|
||||
com.squareup.okhttp.ConnectionSpec plaintext = com.squareup.okhttp.ConnectionSpec.CLEARTEXT;
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("plaintext ConnectionSpec is not accepted");
|
||||
Utils.convertSpec(plaintext);
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> Utils.convertSpec(plaintext));
|
||||
assertThat(e).hasMessageThat().isEqualTo("plaintext ConnectionSpec is not accepted");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.protobuf.lite;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
@ -43,9 +44,7 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Arrays;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -53,9 +52,6 @@ import org.junit.runners.JUnit4;
|
|||
@RunWith(JUnit4.class)
|
||||
public class ProtoLiteUtilsTest {
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final Marshaller<Type> marshaller = ProtoLiteUtils.marshaller(Type.getDefaultInstance());
|
||||
private Type proto = Type.newBuilder().setName("name").build();
|
||||
|
||||
|
@ -214,10 +210,9 @@ public class ProtoLiteUtilsTest {
|
|||
|
||||
@Test
|
||||
public void extensionRegistry_notNull() {
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("newRegistry");
|
||||
|
||||
ProtoLiteUtils.setExtensionRegistry(null);
|
||||
NullPointerException e = assertThrows(NullPointerException.class,
|
||||
() -> ProtoLiteUtils.setExtensionRegistry(null));
|
||||
assertThat(e).hasMessageThat().isEqualTo("newRegistry");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,6 +18,7 @@ package io.grpc.testing;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.AdditionalAnswers.delegatesTo;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
@ -35,9 +36,7 @@ import io.grpc.Server;
|
|||
import io.grpc.internal.FakeClock;
|
||||
import io.grpc.testing.GrpcCleanupRule.Resource;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.junit.runners.model.MultipleFailureException;
|
||||
|
@ -51,10 +50,6 @@ import org.mockito.InOrder;
|
|||
public class GrpcCleanupRuleTest {
|
||||
public static final FakeClock fakeClock = new FakeClock();
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void registerChannelReturnSameChannel() {
|
||||
ManagedChannel channel = mock(ManagedChannel.class);
|
||||
|
@ -72,10 +67,9 @@ public class GrpcCleanupRuleTest {
|
|||
ManagedChannel channel = null;
|
||||
GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
|
||||
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("channel");
|
||||
|
||||
grpcCleanup.register(channel);
|
||||
NullPointerException e = assertThrows(NullPointerException.class,
|
||||
() -> grpcCleanup.register(channel));
|
||||
assertThat(e).hasMessageThat().isEqualTo("channel");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -83,10 +77,9 @@ public class GrpcCleanupRuleTest {
|
|||
Server server = null;
|
||||
GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
|
||||
|
||||
thrown.expect(NullPointerException.class);
|
||||
thrown.expectMessage("server");
|
||||
|
||||
grpcCleanup.register(server);
|
||||
NullPointerException e = assertThrows(NullPointerException.class,
|
||||
() -> grpcCleanup.register(server));
|
||||
assertThat(e).hasMessageThat().isEqualTo("server");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -21,6 +21,7 @@ import static io.grpc.ConnectivityState.CONNECTING;
|
|||
import static io.grpc.ConnectivityState.IDLE;
|
||||
import static io.grpc.ConnectivityState.READY;
|
||||
import static io.grpc.ConnectivityState.TRANSIENT_FAILURE;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
|
@ -53,9 +54,7 @@ import java.util.Collections;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
@ -68,10 +67,6 @@ import org.mockito.InOrder;
|
|||
public class GracefulSwitchLoadBalancerTest {
|
||||
private static final Object FAKE_CONFIG = new Object();
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final Map<LoadBalancerProvider, LoadBalancer> balancers = new HashMap<>();
|
||||
private final Map<LoadBalancer, Helper> helpers = new HashMap<>();
|
||||
private final Helper mockHelper = mock(Helper.class);
|
||||
|
@ -102,8 +97,8 @@ public class GracefulSwitchLoadBalancerTest {
|
|||
.build()));
|
||||
Subchannel subchannel = mock(Subchannel.class);
|
||||
ConnectivityStateInfo connectivityStateInfo = ConnectivityStateInfo.forNonError(READY);
|
||||
thrown.expect(UnsupportedOperationException.class);
|
||||
gracefulSwitchLb.handleSubchannelState(subchannel, connectivityStateInfo);
|
||||
assertThrows(UnsupportedOperationException.class,
|
||||
() -> gracefulSwitchLb.handleSubchannelState(subchannel, connectivityStateInfo));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package io.grpc.xds;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
@ -40,10 +41,9 @@ import java.io.IOException;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -53,9 +53,6 @@ public class GrpcBootstrapperImplTest {
|
|||
|
||||
private static final String BOOTSTRAP_FILE_PATH = "/fake/fs/path/bootstrap.json";
|
||||
private static final String SERVER_URI = "trafficdirector.googleapis.com:443";
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
private final GrpcBootstrapperImpl bootstrapper = new GrpcBootstrapperImpl();
|
||||
private String originalBootstrapPathFromEnvVar;
|
||||
|
@ -236,7 +233,7 @@ public class GrpcBootstrapperImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void parseBootstrap_missingServerChannelCreds() throws XdsInitializationException {
|
||||
public void parseBootstrap_missingServerChannelCreds() {
|
||||
String rawData = "{\n"
|
||||
+ " \"xds_servers\": [\n"
|
||||
+ " {\n"
|
||||
|
@ -246,13 +243,14 @@ public class GrpcBootstrapperImplTest {
|
|||
+ "}";
|
||||
|
||||
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
|
||||
thrown.expect(XdsInitializationException.class);
|
||||
thrown.expectMessage("Invalid bootstrap: server " + SERVER_URI + " 'channel_creds' required");
|
||||
bootstrapper.bootstrap();
|
||||
XdsInitializationException e = Assert.assertThrows(XdsInitializationException.class,
|
||||
bootstrapper::bootstrap);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Invalid bootstrap: server " + SERVER_URI + " 'channel_creds' required");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseBootstrap_unsupportedServerChannelCreds() throws XdsInitializationException {
|
||||
public void parseBootstrap_unsupportedServerChannelCreds() {
|
||||
String rawData = "{\n"
|
||||
+ " \"xds_servers\": [\n"
|
||||
+ " {\n"
|
||||
|
@ -265,9 +263,10 @@ public class GrpcBootstrapperImplTest {
|
|||
+ "}";
|
||||
|
||||
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
|
||||
thrown.expect(XdsInitializationException.class);
|
||||
thrown.expectMessage("Server " + SERVER_URI + ": no supported channel credentials found");
|
||||
bootstrapper.bootstrap();
|
||||
XdsInitializationException e = assertThrows(XdsInitializationException.class,
|
||||
bootstrapper::bootstrap);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Server " + SERVER_URI + ": no supported channel credentials found");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -294,7 +293,7 @@ public class GrpcBootstrapperImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void parseBootstrap_noXdsServers() throws XdsInitializationException {
|
||||
public void parseBootstrap_noXdsServers() {
|
||||
String rawData = "{\n"
|
||||
+ " \"node\": {\n"
|
||||
+ " \"id\": \"ENVOY_NODE_ID\",\n"
|
||||
|
@ -312,9 +311,10 @@ public class GrpcBootstrapperImplTest {
|
|||
+ "}";
|
||||
|
||||
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
|
||||
thrown.expect(XdsInitializationException.class);
|
||||
thrown.expectMessage("Invalid bootstrap: 'xds_servers' does not exist.");
|
||||
bootstrapper.bootstrap();
|
||||
XdsInitializationException e = assertThrows(XdsInitializationException.class,
|
||||
bootstrapper::bootstrap);
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Invalid bootstrap: 'xds_servers' does not exist.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -343,8 +343,9 @@ public class GrpcBootstrapperImplTest {
|
|||
+ "}";
|
||||
|
||||
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
|
||||
thrown.expectMessage("Invalid bootstrap: missing 'server_uri'");
|
||||
bootstrapper.bootstrap();
|
||||
XdsInitializationException e = assertThrows(XdsInitializationException.class,
|
||||
bootstrapper::bootstrap);
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid bootstrap: missing 'server_uri'");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -870,7 +871,7 @@ public class GrpcBootstrapperImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void badFederationConfig() throws Exception {
|
||||
public void badFederationConfig() {
|
||||
String rawData = "{\n"
|
||||
+ " \"authorities\": {\n"
|
||||
+ " \"a.com\": {\n"
|
||||
|
|
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||
import static io.envoyproxy.envoy.config.route.v3.RouteAction.ClusterSpecifierCase.CLUSTER_SPECIFIER_PLUGIN;
|
||||
import static io.grpc.xds.XdsClusterResource.TRANSPORT_SOCKET_NAME_HTTP11_PROXY;
|
||||
import static io.grpc.xds.XdsEndpointResource.GRPC_EXPERIMENTAL_XDS_DUALSTACK_ENDPOINTS;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import com.github.udpa.udpa.type.v1.TypedStruct;
|
||||
|
@ -154,9 +155,7 @@ import java.util.Map;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
|
@ -173,9 +172,6 @@ public class GrpcXdsClientImplDataTest {
|
|||
private static final String GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE =
|
||||
"GRPC_EXPERIMENTAL_XDS_AUTHORITY_REWRITE";
|
||||
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
private final FilterRegistry filterRegistry = FilterRegistry.getDefaultRegistry();
|
||||
private boolean originalEnableRouteLookup;
|
||||
private boolean originalEnableLeastRequest;
|
||||
|
@ -1572,11 +1568,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
throws ResourceInvalidException {
|
||||
@SuppressWarnings("deprecation")
|
||||
HttpConnectionManager hcm = HttpConnectionManager.newBuilder().setXffNumTrustedHops(2).build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("HttpConnectionManager with xff_num_trusted_hops unsupported");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class,
|
||||
() -> XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("HttpConnectionManager with xff_num_trusted_hops unsupported");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1586,12 +1583,13 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpConnectionManager hcm = HttpConnectionManager.newBuilder()
|
||||
.addOriginalIpDetectionExtensions(TypedExtensionConfig.newBuilder().build())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("HttpConnectionManager with original_ip_detection_extensions unsupported");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry, false, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry, false, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("HttpConnectionManager with original_ip_detection_extensions unsupported");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void parseHttpConnectionManager_missingRdsAndInlinedRouteConfiguration()
|
||||
throws ResourceInvalidException {
|
||||
|
@ -1604,11 +1602,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpFilter.newBuilder().setName("terminal").setTypedConfig(
|
||||
Any.pack(Router.newBuilder().build())).setIsOptional(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("HttpConnectionManager neither has inlined route_config nor RDS");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("HttpConnectionManager neither has inlined route_config nor RDS");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1623,11 +1622,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpFilter.newBuilder().setName("terminal").setTypedConfig(
|
||||
Any.pack(Router.newBuilder().build())).setIsOptional(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("HttpConnectionManager contains duplicate HttpFilter: envoy.filter.foo");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("HttpConnectionManager contains duplicate HttpFilter: envoy.filter.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1641,11 +1641,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpFilter.newBuilder().setName("envoy.filter.bar").setIsOptional(true)
|
||||
.setTypedConfig(Any.pack(HTTPFault.newBuilder().build())))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("The last HttpFilter must be a terminal filter: envoy.filter.bar");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("The last HttpFilter must be a terminal filter: envoy.filter.bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1659,11 +1660,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
.addHttpFilters(
|
||||
HttpFilter.newBuilder().setName("envoy.filter.foo").setIsOptional(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("A terminal HttpFilter must be the last filter: terminal");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true, getXdsResourceTypeArgs(true));
|
||||
true, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("A terminal HttpFilter must be the last filter: terminal");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1675,11 +1677,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
.addHttpFilters(
|
||||
HttpFilter.newBuilder().setName("envoy.filter.bar").setIsOptional(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("The last HttpFilter must be a terminal filter: envoy.filter.bar");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("The last HttpFilter must be a terminal filter: envoy.filter.bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1687,11 +1690,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpConnectionManager hcm =
|
||||
HttpConnectionManager.newBuilder()
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Missing HttpFilter in HttpConnectionManager.");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Missing HttpFilter in HttpConnectionManager.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1815,12 +1819,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
Any.pack(Router.newBuilder().build())).setIsOptional(true))
|
||||
.build();
|
||||
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Multiple ClusterSpecifierPlugins with the same name: rls-plugin-1");
|
||||
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Multiple ClusterSpecifierPlugins with the same name: rls-plugin-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1867,12 +1871,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
Any.pack(Router.newBuilder().build())).setIsOptional(true))
|
||||
.build();
|
||||
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("ClusterSpecifierPlugin for [invalid-plugin-name] not found");
|
||||
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.contains("ClusterSpecifierPlugin for [invalid-plugin-name] not found");
|
||||
}
|
||||
|
||||
|
||||
|
@ -2001,12 +2005,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
HttpFilter.newBuilder().setName("terminal").setTypedConfig(
|
||||
Any.pack(Router.newBuilder().build())).setIsOptional(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm3, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"HttpConnectionManager contains invalid RDS: must specify ADS or self ConfigSource");
|
||||
XdsListenerResource.parseHttpConnectionManager(
|
||||
hcm3, filterRegistry,
|
||||
true /* does not matter */, getXdsResourceTypeArgs(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2096,11 +2100,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTypedConfig(Any.pack(StringValue.of("unregistered"))))
|
||||
.build();
|
||||
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsRouteConfigureResource.parseClusterSpecifierPlugin(pluginProto, registry));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"Unsupported ClusterSpecifierPlugin type: type.googleapis.com/google.protobuf.StringValue");
|
||||
|
||||
XdsRouteConfigureResource.parseClusterSpecifierPlugin(pluginProto, registry);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2297,11 +2300,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
Cluster.TransportSocketMatch.newBuilder().setName("match1").build())
|
||||
.build();
|
||||
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.processCluster(cluster, null, LRS_SERVER_INFO,
|
||||
LoadBalancerRegistry.getDefaultRegistry()));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"Cluster cluster-foo.googleapis.com: transport-socket-matches not supported.");
|
||||
XdsClusterResource.processCluster(cluster, null, LRS_SERVER_INFO,
|
||||
LoadBalancerRegistry.getDefaultRegistry());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2346,12 +2349,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setLbPolicy(LbPolicy.ROUND_ROBIN)
|
||||
.build();
|
||||
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.processCluster(cluster3, null, LRS_SERVER_INFO,
|
||||
LoadBalancerRegistry.getDefaultRegistry()));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"Cluster cluster-foo.googleapis.com: field eds_cluster_config must be set to indicate to"
|
||||
+ " use EDS over ADS or self ConfigSource");
|
||||
XdsClusterResource.processCluster(cluster3, null, LRS_SERVER_INFO,
|
||||
LoadBalancerRegistry.getDefaultRegistry());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2620,10 +2623,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setName("listener1")
|
||||
.setTrafficDirection(TrafficDirection.OUTBOUND)
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Listener listener1 with invalid traffic direction: OUTBOUND");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Listener listener1 with invalid traffic direction: OUTBOUND");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2644,10 +2648,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTrafficDirection(TrafficDirection.INBOUND)
|
||||
.addListenerFilters(ListenerFilter.newBuilder().build())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Listener listener1 cannot have listener_filters");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(listener, null, filterRegistry, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Listener listener1 cannot have listener_filters");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2658,10 +2663,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTrafficDirection(TrafficDirection.INBOUND)
|
||||
.setUseOriginalDst(BoolValue.of(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Listener listener1 cannot have use_original_dst set to true");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener,null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(listener, null, filterRegistry, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Listener listener1 cannot have use_original_dst set to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2674,11 +2680,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setSocketAddress(
|
||||
SocketAddress.newBuilder()))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Invalid address: Empty address is not allowed.");
|
||||
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener,null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo("Invalid address: Empty address is not allowed.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2692,11 +2697,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
SocketAddress.newBuilder()
|
||||
.setAddress("172.14.14.5").setNamedPort("")))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("NAMED_PORT is not supported in gRPC.");
|
||||
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener,null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo("NAMED_PORT is not supported in gRPC.");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2742,10 +2746,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTrafficDirection(TrafficDirection.INBOUND)
|
||||
.addAllFilterChains(Arrays.asList(filterChain1, filterChain2))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("FilterChainMatch must be unique. Found duplicate:");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.startsWith("FilterChainMatch must be unique. Found duplicate:");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2791,10 +2796,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTrafficDirection(TrafficDirection.INBOUND)
|
||||
.addAllFilterChains(Arrays.asList(filterChain1, filterChain2))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("FilterChainMatch must be unique. Found duplicate:");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener,null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listener, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.startsWith("FilterChainMatch must be unique. Found duplicate:");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2854,12 +2860,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setFilterChainMatch(FilterChainMatch.getDefaultInstance())
|
||||
.setTransportSocket(TransportSocket.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"FilterChain filter-chain-foo should contain exact one HttpConnectionManager filter");
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2873,12 +2879,12 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTransportSocket(TransportSocket.getDefaultInstance())
|
||||
.addAllFilters(Arrays.asList(filter, filter))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"FilterChain filter-chain-foo should contain exact one HttpConnectionManager filter");
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2891,13 +2897,13 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTransportSocket(TransportSocket.getDefaultInstance())
|
||||
.addFilters(filter)
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"FilterChain filter-chain-foo contains filter envoy.http_connection_manager "
|
||||
+ "without typed_config");
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2914,13 +2920,13 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTransportSocket(TransportSocket.getDefaultInstance())
|
||||
.addFilters(filter)
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"FilterChain filter-chain-foo contains filter unsupported with unsupported "
|
||||
+ "typed_config type unsupported-type-url");
|
||||
XdsListenerResource.parseFilterChain(
|
||||
filterChain, "filter-chain-foo", null, filterRegistry, null, null,
|
||||
getXdsResourceTypeArgs(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -2996,53 +3002,55 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTrafficDirection(TrafficDirection.INBOUND)
|
||||
.addAllFilterChains(Arrays.asList(filterChain0, filterChain1))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("Filter chain names must be unique. Found duplicate: filter_chain");
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listenerProto, null, filterRegistry, null, getXdsResourceTypeArgs(true));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.parseServerSideListener(
|
||||
listenerProto, null, filterRegistry, null, getXdsResourceTypeArgs(true)));
|
||||
assertThat(e).hasMessageThat()
|
||||
.isEqualTo("Filter chain names must be unique. Found duplicate: filter_chain");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommonTlsContext_tlsParams() throws ResourceInvalidException {
|
||||
public void validateCommonTlsContext_tlsParams() {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.setTlsParams(TlsParameters.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("common-tls-context with tls_params is not supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo("common-tls-context with tls_params is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommonTlsContext_customHandshaker() throws ResourceInvalidException {
|
||||
public void validateCommonTlsContext_customHandshaker() {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.setCustomHandshaker(TypedExtensionConfig.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("common-tls-context with custom_handshaker is not supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"common-tls-context with custom_handshaker is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommonTlsContext_validationContext() throws ResourceInvalidException {
|
||||
public void validateCommonTlsContext_validationContext() {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.setValidationContext(CertificateValidationContext.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("ca_certificate_provider_instance or system_root_certs is required "
|
||||
+ "in upstream-tls-context");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"ca_certificate_provider_instance or system_root_certs is required "
|
||||
+ "in upstream-tls-context");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateCommonTlsContext_validationContextSdsSecretConfig()
|
||||
throws ResourceInvalidException {
|
||||
public void validateCommonTlsContext_validationContextSdsSecretConfig() {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.setValidationContextSdsSecretConfig(SdsSecretConfig.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"common-tls-context with validation_context_sds_secret_config is not supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3050,10 +3058,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
throws ResourceInvalidException {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, true));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"tls_certificate_provider_instance is required in downstream-tls-context");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3085,11 +3093,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTlsCertificateProviderInstance(
|
||||
CertificateProviderPluginInstance.newBuilder().setInstanceName("bad-name"))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext,
|
||||
ImmutableSet.of("name1", "name2"), true));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"CertificateProvider instance name 'bad-name' not defined in the bootstrap file.");
|
||||
XdsClusterResource
|
||||
.validateCommonTlsContext(commonTlsContext, ImmutableSet.of("name1", "name2"), true);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3197,11 +3205,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCaCertificateProviderInstance(CertificateProviderPluginInstance.newBuilder()
|
||||
.setInstanceName("bad-name"))))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext,
|
||||
ImmutableSet.of("name1", "name2"), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"ca_certificate_provider_instance name 'bad-name' not defined in the bootstrap file.");
|
||||
XdsClusterResource
|
||||
.validateCommonTlsContext(commonTlsContext, ImmutableSet.of("name1", "name2"), false);
|
||||
}
|
||||
|
||||
|
||||
|
@ -3210,9 +3218,9 @@ public class GrpcXdsClientImplDataTest {
|
|||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.addTlsCertificates(TlsCertificate.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("tls_certificate_provider_instance is unset");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo("tls_certificate_provider_instance is unset");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3221,10 +3229,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.addTlsCertificateSdsSecretConfigs(SdsSecretConfig.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"tls_certificate_provider_instance is unset");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3232,10 +3240,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
throws ResourceInvalidException {
|
||||
CommonTlsContext commonTlsContext = CommonTlsContext.newBuilder()
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("ca_certificate_provider_instance or system_root_certs is required "
|
||||
+ "in upstream-tls-context");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"ca_certificate_provider_instance or system_root_certs is required "
|
||||
+ "in upstream-tls-context");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3245,11 +3254,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCombinedValidationContext(
|
||||
CommonTlsContext.CombinedCertificateValidationContext.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"ca_certificate_provider_instance or system_root_certs is required in "
|
||||
+ "upstream-tls-context");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, null, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3267,9 +3276,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTlsCertificateProviderInstance(
|
||||
CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("match_subject_alt_names only allowed in upstream_tls_context");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), true);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), true));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"match_subject_alt_names only allowed in upstream_tls_context");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3284,10 +3294,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
.addVerifyCertificateSpki("foo")))
|
||||
.setTlsCertificateProviderInstance(CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("verify_certificate_spki in default_validation_context is not "
|
||||
+ "supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"verify_certificate_spki in default_validation_context is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3302,10 +3312,10 @@ public class GrpcXdsClientImplDataTest {
|
|||
.addVerifyCertificateHash("foo")))
|
||||
.setTlsCertificateProviderInstance(CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("verify_certificate_hash in default_validation_context is not "
|
||||
+ "supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"verify_certificate_hash in default_validation_context is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3321,11 +3331,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setTlsCertificateProviderInstance(
|
||||
CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"require_signed_certificate_timestamp in default_validation_context is not "
|
||||
+ "supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3340,9 +3350,9 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCrl(DataSource.getDefaultInstance())))
|
||||
.setTlsCertificateProviderInstance(CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("crl in default_validation_context is not supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo("crl in default_validation_context is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3357,18 +3367,19 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCustomValidatorConfig(TypedExtensionConfig.getDefaultInstance())))
|
||||
.setTlsCertificateProviderInstance(CertificateProviderPluginInstance.getDefaultInstance())
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("custom_validator_config in default_validation_context is not "
|
||||
+ "supported");
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateCommonTlsContext(commonTlsContext, ImmutableSet.of(""), false));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"custom_validator_config in default_validation_context is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateDownstreamTlsContext_noCommonTlsContext() throws ResourceInvalidException {
|
||||
DownstreamTlsContext downstreamTlsContext = DownstreamTlsContext.getDefaultInstance();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("common-tls-context is required in downstream-tls-context");
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext, null);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext, null));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"common-tls-context is required in downstream-tls-context");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3385,9 +3396,11 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCommonTlsContext(commonTlsContext)
|
||||
.setRequireSni(BoolValue.of(true))
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("downstream-tls-context with require-sni is not supported");
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext, ImmutableSet.of(""));
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext,
|
||||
ImmutableSet.of("")));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"downstream-tls-context with require-sni is not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -3404,18 +3417,20 @@ public class GrpcXdsClientImplDataTest {
|
|||
.setCommonTlsContext(commonTlsContext)
|
||||
.setOcspStaplePolicy(DownstreamTlsContext.OcspStaplePolicy.STRICT_STAPLING)
|
||||
.build();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage(
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext,
|
||||
ImmutableSet.of("")));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"downstream-tls-context with ocsp_staple_policy value STRICT_STAPLING is not supported");
|
||||
XdsListenerResource.validateDownstreamTlsContext(downstreamTlsContext, ImmutableSet.of(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateUpstreamTlsContext_noCommonTlsContext() throws ResourceInvalidException {
|
||||
UpstreamTlsContext upstreamTlsContext = UpstreamTlsContext.getDefaultInstance();
|
||||
thrown.expect(ResourceInvalidException.class);
|
||||
thrown.expectMessage("common-tls-context is required in upstream-tls-context");
|
||||
XdsClusterResource.validateUpstreamTlsContext(upstreamTlsContext, null);
|
||||
ResourceInvalidException e = assertThrows(ResourceInvalidException.class, () ->
|
||||
XdsClusterResource.validateUpstreamTlsContext(upstreamTlsContext, null));
|
||||
assertThat(e).hasMessageThat().isEqualTo(
|
||||
"common-tls-context is required in upstream-tls-context");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package io.grpc.xds;
|
||||
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
@ -26,17 +27,13 @@ import io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig;
|
|||
import io.grpc.xds.PriorityLoadBalancerProvider.PriorityLbConfig.PriorityChildConfig;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
/** Tests for {@link PriorityLoadBalancerProvider}. */
|
||||
@RunWith(JUnit4.class)
|
||||
public class PriorityLoadBalancerProviderTest {
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@SuppressWarnings("ExpectedExceptionChecker")
|
||||
@Test
|
||||
|
@ -48,8 +45,8 @@ public class PriorityLoadBalancerProviderTest {
|
|||
newChildConfig(mock(LoadBalancerProvider.class), null), true));
|
||||
List<String> priorities = ImmutableList.of();
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new PriorityLbConfig(childConfigs, priorities);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new PriorityLbConfig(childConfigs, priorities));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ExpectedExceptionChecker")
|
||||
|
@ -62,8 +59,8 @@ public class PriorityLoadBalancerProviderTest {
|
|||
newChildConfig(mock(LoadBalancerProvider.class), null), true));
|
||||
List<String> priorities = ImmutableList.of("p0", "p1");
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new PriorityLbConfig(childConfigs, priorities);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new PriorityLbConfig(childConfigs, priorities));
|
||||
}
|
||||
|
||||
private Object newChildConfig(LoadBalancerProvider provider, Object config) {
|
||||
|
|
|
@ -19,6 +19,7 @@ package io.grpc.xds;
|
|||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
@ -50,7 +51,6 @@ import java.util.Collections;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mock;
|
||||
|
@ -64,9 +64,6 @@ public class SharedXdsClientPoolProviderTest {
|
|||
private static final String SERVER_URI = "trafficdirector.googleapis.com";
|
||||
@Rule
|
||||
public final MockitoRule mocks = MockitoJUnit.rule();
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
private final Node node = Node.newBuilder().setId("SharedXdsClientPoolProviderTest").build();
|
||||
private final MetricRecorder metricRecorder = new MetricRecorder() {};
|
||||
private static final String DUMMY_TARGET = "dummy";
|
||||
|
@ -83,9 +80,9 @@ public class SharedXdsClientPoolProviderTest {
|
|||
BootstrapInfo.builder().servers(Collections.<ServerInfo>emptyList()).node(node).build();
|
||||
when(bootstrapper.bootstrap()).thenReturn(bootstrapInfo);
|
||||
SharedXdsClientPoolProvider provider = new SharedXdsClientPoolProvider(bootstrapper);
|
||||
thrown.expect(XdsInitializationException.class);
|
||||
thrown.expectMessage("No xDS server provided");
|
||||
provider.getOrCreate(DUMMY_TARGET, metricRecorder);
|
||||
XdsInitializationException e = assertThrows(XdsInitializationException.class,
|
||||
() -> provider.getOrCreate(DUMMY_TARGET, metricRecorder));
|
||||
assertThat(e).hasMessageThat().isEqualTo("No xDS server provided");
|
||||
assertThat(provider.get(DUMMY_TARGET)).isNull();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
package io.grpc.xds;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import io.grpc.LoadBalancer.PickResult;
|
||||
|
@ -30,7 +31,6 @@ import java.util.Arrays;
|
|||
import java.util.List;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
import org.mockito.Mock;
|
||||
|
@ -42,9 +42,6 @@ import org.mockito.junit.MockitoRule;
|
|||
*/
|
||||
@RunWith(JUnit4.class)
|
||||
public class WeightedRandomPickerTest {
|
||||
@SuppressWarnings("deprecation") // https://github.com/grpc/grpc-java/issues/7467
|
||||
@Rule
|
||||
public final ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
@Rule
|
||||
public final MockitoRule mockitoRule = MockitoJUnit.rule();
|
||||
|
@ -128,20 +125,18 @@ public class WeightedRandomPickerTest {
|
|||
public void emptyList() {
|
||||
List<WeightedChildPicker> emptyList = new ArrayList<>();
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new WeightedRandomPicker(emptyList);
|
||||
assertThrows(IllegalArgumentException.class, () -> new WeightedRandomPicker(emptyList));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void negativeWeight() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new WeightedChildPicker(-1, childPicker0);
|
||||
assertThrows(IllegalArgumentException.class, () -> new WeightedChildPicker(-1, childPicker0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void overWeightSingle() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new WeightedChildPicker(Integer.MAX_VALUE * 3L, childPicker0);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new WeightedChildPicker(Integer.MAX_VALUE * 3L, childPicker0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -152,8 +147,8 @@ public class WeightedRandomPickerTest {
|
|||
new WeightedChildPicker(Integer.MAX_VALUE, childPicker1),
|
||||
new WeightedChildPicker(10, childPicker2));
|
||||
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
new WeightedRandomPicker(weightedChildPickers, fakeRandom);
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> new WeightedRandomPicker(weightedChildPickers, fakeRandom));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue