1 /* 2 * Copyright 2014 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.testing.integration; 18 19 import io.grpc.ServerBuilder; 20 import io.grpc.netty.InternalNettyChannelBuilder; 21 import io.grpc.netty.InternalNettyServerBuilder; 22 import io.grpc.netty.NegotiationType; 23 import io.grpc.netty.NettyChannelBuilder; 24 import io.grpc.netty.NettyServerBuilder; 25 import io.netty.channel.DefaultEventLoopGroup; 26 import io.netty.channel.local.LocalAddress; 27 import io.netty.channel.local.LocalChannel; 28 import io.netty.channel.local.LocalServerChannel; 29 import org.junit.After; 30 import org.junit.runner.RunWith; 31 import org.junit.runners.JUnit4; 32 33 /** 34 * Run transport tests over the Netty in-process channel. 35 */ 36 @RunWith(JUnit4.class) 37 public class Http2NettyLocalChannelTest extends AbstractInteropTest { 38 39 private DefaultEventLoopGroup eventLoopGroup = new DefaultEventLoopGroup(); 40 41 @Override getServerBuilder()42 protected ServerBuilder<?> getServerBuilder() { 43 NettyServerBuilder builder = NettyServerBuilder 44 .forAddress(new LocalAddress("in-process-1")) 45 .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) 46 .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE) 47 .channelType(LocalServerChannel.class) 48 .workerEventLoopGroup(eventLoopGroup) 49 .bossEventLoopGroup(eventLoopGroup); 50 // Disable the default census stats tracer, use testing tracer instead. 51 InternalNettyServerBuilder.setStatsEnabled(builder, false); 52 return builder.addStreamTracerFactory(createCustomCensusTracerFactory()); 53 } 54 55 @Override createChannelBuilder()56 protected NettyChannelBuilder createChannelBuilder() { 57 NettyChannelBuilder builder = NettyChannelBuilder 58 .forAddress(new LocalAddress("in-process-1")) 59 .negotiationType(NegotiationType.PLAINTEXT) 60 .channelType(LocalChannel.class) 61 .eventLoopGroup(eventLoopGroup) 62 .flowControlWindow(AbstractInteropTest.TEST_FLOW_CONTROL_WINDOW) 63 .maxInboundMessageSize(AbstractInteropTest.MAX_MESSAGE_SIZE); 64 // Disable the default census stats interceptor, use testing interceptor instead. 65 InternalNettyChannelBuilder.setStatsEnabled(builder, false); 66 return builder.intercept(createCensusStatsClientInterceptor()); 67 } 68 69 @Override 70 @After 71 @SuppressWarnings("FutureReturnValueIgnored") tearDown()72 public void tearDown() { 73 super.tearDown(); 74 eventLoopGroup.shutdownGracefully(); 75 } 76 } 77