Skip to content

Commit

Permalink
Fix the unit test message too large problem (#1339)
Browse files Browse the repository at this point in the history
* support change grpc maxInboundMessageSize

* fix the debug body message too large problem

---------

Co-authored-by: liujianjun.ljj <liujianjun.ljj@antgroup.com>
  • Loading branch information
EvenLjj and liujianjun.ljj authored Jun 15, 2023
1 parent 3338957 commit cd6167c
Showing 1 changed file with 43 additions and 33 deletions.
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

0 comments on commit cd6167c

Please sign in to comment.