Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the unit test message too large problem #1339

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -300,48 +300,57 @@ public void testExposeTwoUniqueId() {

@Test
public void testDefaultMessageSize() {
int originInboundMessageSize = RpcConfigs.getIntValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE);
Assert.assertEquals(4194304, originInboundMessageSize);
boolean originDebugMode = RpcRunningState.isDebugMode();
RpcRunningState.setDebugMode(false);
try {
int originInboundMessageSize = RpcConfigs.getIntValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE);
Assert.assertEquals(4194304, originInboundMessageSize);

ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("triple-server1");
int port = 50052;
ServerConfig serverConfig = new ServerConfig()
.setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setPort(port);
ProviderConfig<SampleService> providerConfig = new ProviderConfig<SampleService>()
.setApplication(applicationConfig)
.setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setInterfaceId(SampleService.class.getName())
.setRef(new SampleServiceImpl())
.setServer(serverConfig);
providerConfig.export();
ApplicationConfig applicationConfig = new ApplicationConfig().setAppName("triple-server1");
int port = 50052;
ServerConfig serverConfig = new ServerConfig()
.setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setPort(port);
ProviderConfig<SampleService> providerConfig = new ProviderConfig<SampleService>()
.setApplication(applicationConfig)
.setBootstrap(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setInterfaceId(SampleService.class.getName())
.setRef(new SampleServiceImpl())
.setServer(serverConfig);
providerConfig.export();

ConsumerConfig<SampleService> consumerConfig = new ConsumerConfig<>();
consumerConfig.setInterfaceId(SampleService.class.getName())
.setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setDirectUrl("tri://127.0.0.1:" + port);
ConsumerConfig<SampleService> consumerConfig = new ConsumerConfig<>();
consumerConfig.setInterfaceId(SampleService.class.getName())
.setProtocol(RpcConstants.PROTOCOL_TYPE_TRIPLE)
.setDirectUrl("tri://127.0.0.1:" + port);

SampleService sampleService = consumerConfig.refer();
String msg = buildMsg(1);
try {
sampleService.messageSize(msg, 5*1024);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("gRPC message exceeds maximum size 4194304:"));
}
msg = buildMsg(5*1024);
SampleService sampleService = consumerConfig.refer();
String msg = buildMsg(1);
try {
sampleService.messageSize(msg, 5*1024);
Assert.fail();
} catch (Exception e) {
Assert.assertTrue(e.getMessage().contains("gRPC message exceeds maximum size 4194304:"));
}
msg = buildMsg(5*1024);

try {
sampleService.messageSize(msg, 1);
Assert.fail();
} catch (Exception e) {
// The client actively cancelled the request, resulting in the server returning a CANCELLED error.
Assert.assertTrue(e.getMessage().contains("CANCELLED: HTTP/2 error code: CANCEL"));
try {
sampleService.messageSize(msg, 1);
Assert.fail();
} catch (Exception e) {
// The client actively cancelled the request, resulting in the server returning a CANCELLED error.
Assert.assertTrue(e.getMessage().contains("CANCELLED: HTTP/2 error code: CANCEL"));
}
} finally {
RpcRunningState.setDebugMode(originDebugMode);
}

}

@Test
public void testSetInboundMessageSize() {
boolean originDebugMode = RpcRunningState.isDebugMode();
RpcRunningState.setDebugMode(false);
int originInboundMessageSize = RpcConfigs.getIntValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE);
Assert.assertEquals(4194304, originInboundMessageSize);
RpcConfigs.putValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE, "8388608");
Expand Down Expand Up @@ -374,6 +383,7 @@ public void testSetInboundMessageSize() {
Assert.fail();
}
} finally {
RpcRunningState.setDebugMode(originDebugMode);
RpcConfigs.putValue(RpcOptions.TRANSPORT_GRPC_MAX_INBOUND_MESSAGE_SIZE, originInboundMessageSize);
}
}
Expand Down