🤬
  • ■ ■ ■ ■ ■ ■
    build.gradle
    skipped 62 lines
    63 63   guice_assisted: "com.google.inject.extensions:guice-assistedinject:${guiceVersion}",
    64 64   grpc_protobuf: "io.grpc:grpc-protobuf:${grpcVersion}",
    65 65   grpc_stub: "io.grpc:grpc-stub:${grpcVersion}",
     66 + grpc_core: "io.grpc:grpc-core:${grpcVersion}",
     67 + grpc_testing: "io.grpc:grpc-testing:${grpcVersion}",
    66 68   javax_annotations: "javax.annotation:javax.annotation-api:${javaxAnnotationVersion}",
    67 69   gson: "com.google.code.gson:gson:${gsonVersion}",
    68 70   jaxb_runtime: "org.glassfish.jaxb:jaxb-runtime:${jaxbVersion}",
    skipped 154 lines
  • ■ ■ ■ ■ ■ ■
    plugin/build.gradle
    skipped 13 lines
    14 14   compile deps.mock_web_server
    15 15   compile deps.protobuf
    16 16   compile deps.protobuf_util
     17 + compile deps.grpc_core
     18 + compile deps.grpc_testing
    17 19   compile deps.tcs_common, deps.tcs_proto
    18 20   annotationProcessor deps.autovalue_annotation_processor
    19 21   
    skipped 6 lines
  • ■ ■ ■ ■ ■ ■
    plugin/src/main/java/com/google/tsunami/plugin/PluginServiceClient.java
     1 +/*
     2 + * Copyright 2022 Google LLC
     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 +package com.google.tsunami.plugin;
     17 + 
     18 +import static com.google.common.base.Preconditions.checkNotNull;
     19 + 
     20 +import com.google.common.util.concurrent.ListeningScheduledExecutorService;
     21 +import com.google.tsunami.proto.PluginServiceGrpc;
     22 +import com.google.tsunami.proto.PluginServiceGrpc.PluginServiceFutureStub;
     23 +import io.grpc.Channel;
     24 + 
     25 +/**
     26 + * Client side gRPC handler for the PluginService RPC protocol. Main handler for all gRPC calls to
     27 + * the language-specific servers.
     28 + */
     29 +public class PluginServiceClient {
     30 + 
     31 + private final PluginServiceFutureStub pluginService;
     32 + private final ListeningScheduledExecutorService scheduledExecutorService;
     33 + 
     34 + PluginServiceClient(Channel channel, ListeningScheduledExecutorService service) {
     35 + this.pluginService = PluginServiceGrpc.newFutureStub(checkNotNull(channel));
     36 + this.scheduledExecutorService = checkNotNull(service);
     37 + }
     38 +}
     39 + 
  • ■ ■ ■ ■ ■ ■
    plugin/src/test/java/com/google/tsunami/plugin/PluginServiceClientTest.java
     1 +/*
     2 + * Copyright 2022 Google LLC
     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 +package com.google.tsunami.plugin;
     17 + 
     18 +import static com.google.common.truth.Truth.assertThat;
     19 + 
     20 +import com.google.common.util.concurrent.ListeningScheduledExecutorService;
     21 +import com.google.inject.Guice;
     22 +import com.google.inject.Key;
     23 +import com.google.tsunami.common.concurrent.ScheduledThreadPoolModule;
     24 +import io.grpc.inprocess.InProcessChannelBuilder;
     25 +import io.grpc.inprocess.InProcessServerBuilder;
     26 +import io.grpc.testing.GrpcCleanupRule;
     27 +import io.grpc.util.MutableHandlerRegistry;
     28 +import java.lang.annotation.Retention;
     29 +import java.lang.annotation.RetentionPolicy;
     30 +import javax.inject.Qualifier;
     31 +import org.junit.Before;
     32 +import org.junit.Rule;
     33 +import org.junit.Test;
     34 +import org.junit.runner.RunWith;
     35 +import org.junit.runners.JUnit4;
     36 + 
     37 +/** Tests for {@link PluginServiceClient}. */
     38 +@RunWith(JUnit4.class)
     39 +public final class PluginServiceClientTest {
     40 + 
     41 + // Useful test thread pool used for testing grpc handlers
     42 + @Qualifier
     43 + @Retention(RetentionPolicy.RUNTIME)
     44 + @interface TestThreadPool {}
     45 + 
     46 + @Rule public final GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
     47 + 
     48 + private static final int THREAD_POOLS = 1;
     49 + private static final String THREAD_POOL_NAME = "test";
     50 + 
     51 + private PluginServiceClient pluginService;
     52 + private final MutableHandlerRegistry serviceRegistry = new MutableHandlerRegistry();
     53 + 
     54 + @Before
     55 + public void setUp() throws Exception {
     56 + String serverName = InProcessServerBuilder.generateName();
     57 + grpcCleanup.register(
     58 + InProcessServerBuilder.forName(serverName)
     59 + .fallbackHandlerRegistry(serviceRegistry)
     60 + .directExecutor()
     61 + .build()
     62 + .start());
     63 + 
     64 + pluginService =
     65 + new PluginServiceClient(
     66 + InProcessChannelBuilder.forName(serverName).directExecutor().build(),
     67 + Guice.createInjector(
     68 + new ScheduledThreadPoolModule.Builder()
     69 + .setName(THREAD_POOL_NAME)
     70 + .setSize(THREAD_POOLS)
     71 + .setAnnotation(TestThreadPool.class)
     72 + .build())
     73 + .getInstance(
     74 + Key.get(ListeningScheduledExecutorService.class, TestThreadPool.class)));
     75 + }
     76 + 
     77 + @Test
     78 + public void pluginService_isNotNull() {
     79 + assertThat(pluginService).isNotNull();
     80 + }
     81 + 
     82 +}
     83 + 
  • ■ ■ ■ ■
    proto/plugin_service.proto
    1 1  /*
    2  - * Copyright 2020 Google LLC
     2 + * Copyright 2022 Google LLC
    3 3   *
    4 4   * Licensed under the Apache License, Version 2.0 (the "License");
    5 5   * you may not use this file except in compliance with the License.
    skipped 68 lines
Please wait...
Page is in error, reload to recover