Skip to content

Commit d1aaafc

Browse files
committed
tomcat
1 parent e9165f7 commit d1aaafc

File tree

4 files changed

+500
-0
lines changed

4 files changed

+500
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2019 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.servlet;
18+
19+
import io.grpc.ManagedChannel;
20+
import io.grpc.ManagedChannelBuilder;
21+
import io.grpc.ServerBuilder;
22+
import io.grpc.internal.AbstractManagedChannelImplBuilder;
23+
import io.grpc.testing.integration.AbstractInteropTest;
24+
import org.eclipse.jetty.http2.server.HTTP2CServerConnectionFactory;
25+
import org.eclipse.jetty.server.HttpConfiguration;
26+
import org.eclipse.jetty.server.Server;
27+
import org.eclipse.jetty.server.ServerConnector;
28+
import org.eclipse.jetty.servlet.ServletContextHandler;
29+
import org.eclipse.jetty.servlet.ServletHolder;
30+
import org.junit.After;
31+
import org.junit.Ignore;
32+
import org.junit.Test;
33+
34+
public class JettyInteroptTest extends AbstractInteropTest {
35+
36+
private static final String HOST = "localhost";
37+
private static final String MYAPP = "/grpc.testing.TestService";
38+
private int port;
39+
private Server server;
40+
41+
@After
42+
@Override
43+
public void tearDown() {
44+
super.tearDown();
45+
try {
46+
server.stop();
47+
} catch (Exception e) {
48+
throw new AssertionError(e);
49+
}
50+
}
51+
52+
@Override
53+
protected ServerBuilder<?> getServerBuilder() {
54+
return new ServletServerBuilder().maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
55+
}
56+
57+
@Override
58+
protected void startServer(ServerBuilder<?> builer) {
59+
GrpcServlet grpcServlet =
60+
new GrpcServlet(((ServletServerBuilder) builer).buildServletAdapter());
61+
server = new Server(0);
62+
ServerConnector sc = (ServerConnector)server.getConnectors()[0];
63+
sc.addConnectionFactory(new HTTP2CServerConnectionFactory(new HttpConfiguration()));
64+
ServletContextHandler context =
65+
new ServletContextHandler(ServletContextHandler.SESSIONS);
66+
context.setContextPath(MYAPP);
67+
context.addServlet(new ServletHolder(grpcServlet), "/*");
68+
server.setHandler(context);
69+
70+
try {
71+
server.start();
72+
} catch (Exception e) {
73+
throw new AssertionError(e);
74+
}
75+
76+
port = sc.getLocalPort();
77+
}
78+
79+
80+
@Override
81+
protected ManagedChannel createChannel() {
82+
AbstractManagedChannelImplBuilder<?> builder =
83+
(AbstractManagedChannelImplBuilder<?>) ManagedChannelBuilder.forAddress(HOST, port)
84+
.usePlaintext()
85+
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
86+
io.grpc.internal.TestingAccessor.setStatsImplementation(
87+
builder, createClientCensusStatsModule());
88+
return builder.build();
89+
}
90+
91+
// FIXME
92+
@Override
93+
@Ignore("Jetty is broken on client GOAWAY")
94+
@Test
95+
public void gracefulShutdown() {}
96+
}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* Copyright 2018 The gRPC Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.grpc.servlet;
18+
19+
import io.grpc.ManagedChannel;
20+
import io.grpc.ManagedChannelBuilder;
21+
import io.grpc.ServerBuilder;
22+
import io.grpc.internal.AbstractManagedChannelImplBuilder;
23+
import io.grpc.internal.AbstractServerImplBuilder;
24+
import io.grpc.testing.integration.AbstractInteropTest;
25+
import java.io.File;
26+
27+
import java.util.logging.Handler;
28+
import java.util.logging.Level;
29+
import java.util.logging.LogManager;
30+
import java.util.logging.Logger;
31+
import org.apache.catalina.Context;
32+
import org.apache.catalina.LifecycleException;
33+
import org.apache.catalina.startup.Tomcat;
34+
import org.apache.coyote.http2.Http2Protocol;
35+
import org.apache.tomcat.util.http.fileupload.FileUtils;
36+
import org.junit.After;
37+
import org.junit.AfterClass;
38+
import org.junit.Before;
39+
40+
/**
41+
* Interop test for Tomcat server and Netty client.
42+
*/
43+
public class TomcatInteropTest extends AbstractInteropTest {
44+
45+
private static final String HOST = "localhost";
46+
private static final String MYAPP = "/grpc.testing.TestService";
47+
private int port;
48+
private Tomcat server;
49+
50+
@Before
51+
public void before() {
52+
Logger rootLogger = LogManager.getLogManager().getLogger("");
53+
// rootLogger.setLevel(Level.ALL);
54+
for (Handler h : rootLogger.getHandlers()) {
55+
h.setLevel(Level.FINEST);
56+
}
57+
Logger.getLogger(ServletServerStream.class.getName()).setLevel(Level.FINEST);
58+
Logger.getLogger(AsyncServletOutputStreamWriter.class.getName()).setLevel(Level.FINEST);
59+
}
60+
61+
@After
62+
@Override
63+
public void tearDown() {
64+
super.tearDown();
65+
try {
66+
server.stop();
67+
} catch (LifecycleException e) {
68+
throw new AssertionError(e);
69+
}
70+
}
71+
72+
@AfterClass
73+
public static void cleanUp() throws Exception {
74+
FileUtils.deleteDirectory(new File("tomcat.0"));
75+
}
76+
77+
@Override
78+
protected AbstractServerImplBuilder<?> getServerBuilder() {
79+
return new ServletServerBuilder().maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
80+
}
81+
82+
@Override
83+
protected void startServer(ServerBuilder<?> builer) {
84+
server = new Tomcat();
85+
server.setPort(0);
86+
Context ctx = server.addContext(MYAPP, new File("build/tmp").getAbsolutePath());
87+
Tomcat
88+
.addServlet(
89+
ctx, "TomcatInteropTest",
90+
new GrpcServlet(((ServletServerBuilder) builer).buildServletAdapter()))
91+
.setAsyncSupported(true);
92+
ctx.addServletMappingDecoded("/*", "TomcatInteropTest");
93+
server.getConnector().addUpgradeProtocol(new Http2Protocol());
94+
try {
95+
server.start();
96+
} catch (LifecycleException e) {
97+
throw new RuntimeException(e);
98+
}
99+
100+
port = server.getConnector().getLocalPort();
101+
}
102+
103+
@Override
104+
protected ManagedChannel createChannel() {
105+
AbstractManagedChannelImplBuilder<?> builder =
106+
(AbstractManagedChannelImplBuilder<?>) ManagedChannelBuilder.forAddress(HOST, port)
107+
.usePlaintext()
108+
.maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE);
109+
io.grpc.internal.TestingAccessor.setStatsImplementation(
110+
builder, createClientCensusStatsModule());
111+
return builder.build();
112+
}
113+
114+
@Override
115+
protected boolean metricsExpected() {
116+
return false; // otherwise re-test will not work
117+
}
118+
119+
// FIXME
120+
@Override
121+
@org.junit.Ignore("Tomcat is broken on client GOAWAY")
122+
@org.junit.Test
123+
public void gracefulShutdown() {}
124+
125+
// FIXME
126+
@Override
127+
@org.junit.Ignore("Tomcat is not able to send trailer only")
128+
@org.junit.Test
129+
public void specialStatusMessage() {}
130+
131+
// FIXME
132+
@Override
133+
@org.junit.Ignore("Tomcat is not able to send trailer only")
134+
@org.junit.Test
135+
public void unimplementedMethod() {}
136+
137+
// FIXME
138+
@Override
139+
@org.junit.Ignore("Tomcat is not able to send trailer only")
140+
@org.junit.Test
141+
public void statusCodeAndMessage() {}
142+
}

0 commit comments

Comments
 (0)