Make Tomcat sample work with grpcurl
This commit is contained in:
@@ -1,7 +1,15 @@
|
||||
package org.springframework.grpc.sample;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.coyote.UpgradeProtocol;
|
||||
import org.apache.coyote.http2.Http2Protocol;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
import io.netty.handler.ssl.ApplicationProtocolConfig.Protocol;
|
||||
|
||||
@SpringBootApplication
|
||||
public class GrpcServerApplication {
|
||||
@@ -10,4 +18,15 @@ public class GrpcServerApplication {
|
||||
SpringApplication.run(GrpcServerApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TomcatConnectorCustomizer customizer() {
|
||||
return (connector) -> {
|
||||
for (UpgradeProtocol protocol : connector.findUpgradeProtocols()) {
|
||||
if (protocol instanceof Http2Protocol http2Protocol) {
|
||||
http2Protocol.setOverheadWindowUpdateThreshold(0);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package org.springframework.grpc.sample;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -43,6 +45,16 @@ public class GrpcServerApplicationTests {
|
||||
assertEquals("Hello ==> Alien", response.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
void streamResponds() {
|
||||
Iterator<HelloReply> response = stub.streamHello(HelloRequest.newBuilder().setName("Alien").build());
|
||||
assertEquals("Hello(0) ==> Alien", response.next().getMessage());
|
||||
while (response.hasNext()) {
|
||||
log.info(response.next().getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@TestConfiguration
|
||||
static class ExtraConfiguration {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user