|
| 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