1 /* 2 * Copyright (C) 2016 The Dagger 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 dagger.grpc.functional.server; 18 19 import dagger.grpc.server.InProcessServerModule; 20 import java.io.IOException; 21 import org.junit.rules.ExternalResource; 22 23 final class CoffeeServerResource extends ExternalResource { 24 private final String name; 25 private final CoffeeServer<?> coffeeServer; 26 CoffeeServerResource(String name, CoffeeServer.Builder<?> coffeeServerBuilder)27 CoffeeServerResource(String name, CoffeeServer.Builder<?> coffeeServerBuilder) { 28 this.name = name; 29 this.coffeeServer = 30 coffeeServerBuilder.inProcessServerModule(InProcessServerModule.serverNamed(name)).build(); 31 } 32 name()33 public String name() { 34 return name; 35 } 36 methodCount(String methodName)37 public int methodCount(String methodName) { 38 return coffeeServer.countingInterceptor().countCalls(methodName); 39 } 40 41 @Override before()42 protected void before() throws IOException, InterruptedException { 43 coffeeServer.start(); 44 } 45 46 @Override after()47 protected void after() { 48 coffeeServer.shutdown(); 49 } 50 51 @Override toString()52 public String toString() { 53 return name; 54 } 55 } 56