From 93a90e6132d4c6cdf06ae3b0d7176c2ee3944967 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 18 Jun 2018 18:39:56 -0700 Subject: [PATCH 1/8] Support codegen generic on server side --- BUILD | 2 + CMakeLists.txt | 16 +++ Makefile | 16 +++ build.yaml | 2 + gRPC-C++.podspec | 1 + gRPC-Core.podspec | 2 + grpc.def | 14 +- grpc.gemspec | 2 + include/grpc/impl/codegen/log.h | 112 +++++++++++++++ include/grpc/module.modulemap | 2 + include/grpc/support/log.h | 90 +----------- .../grpcpp/generic/async_generic_service.h | 58 +------- .../impl/codegen/async_generic_service.h | 81 +++++++++++ .../grpcpp/impl/codegen/rpc_service_method.h | 1 + include/grpcpp/impl/codegen/service_type.h | 8 ++ package.xml | 2 + src/compiler/cpp_generator.cc | 129 ++++++++++++------ src/ruby/ext/grpc/rb_grpc_imports.generated.c | 28 ++-- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 44 +++--- .../core/surface/public_headers_must_be_c89.c | 15 +- test/cpp/codegen/compiler_test_golden | 127 +++++++++++++++-- tools/doxygen/Doxyfile.c++ | 2 + tools/doxygen/Doxyfile.c++.internal | 2 + tools/doxygen/Doxyfile.core | 2 + tools/doxygen/Doxyfile.core.internal | 2 + .../generated/sources_and_headers.json | 4 + 26 files changed, 518 insertions(+), 246 deletions(-) create mode 100644 include/grpc/impl/codegen/log.h create mode 100644 include/grpcpp/impl/codegen/async_generic_service.h diff --git a/BUILD b/BUILD index fea71153bba..3b0f70887ca 100644 --- a/BUILD +++ b/BUILD @@ -580,6 +580,7 @@ grpc_cc_library( "include/grpc/impl/codegen/fork.h", "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", + "include/grpc/impl/codegen/log.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/sync.h", "include/grpc/impl/codegen/sync_custom.h", @@ -1850,6 +1851,7 @@ grpc_cc_library( "include/grpc++/impl/codegen/stub_options.h", "include/grpc++/impl/codegen/sync_stream.h", "include/grpc++/impl/codegen/time.h", + "include/grpcpp/impl/codegen/async_generic_service.h", "include/grpcpp/impl/codegen/async_stream.h", "include/grpcpp/impl/codegen/async_unary_call.h", "include/grpcpp/impl/codegen/byte_buffer.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index 63c670606ce..9bf5cdbd691 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -866,6 +866,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -1285,6 +1286,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -1655,6 +1657,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -1968,6 +1971,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -2273,6 +2277,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -2587,6 +2592,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -2904,6 +2910,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -2960,6 +2967,7 @@ foreach(_hdr include/grpc++/impl/codegen/stub_options.h include/grpc++/impl/codegen/sync_stream.h include/grpc++/impl/codegen/time.h + include/grpcpp/impl/codegen/async_generic_service.h include/grpcpp/impl/codegen/async_stream.h include/grpcpp/impl/codegen/async_unary_call.h include/grpcpp/impl/codegen/byte_buffer.h @@ -3467,6 +3475,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -3523,6 +3532,7 @@ foreach(_hdr include/grpc++/impl/codegen/stub_options.h include/grpc++/impl/codegen/sync_stream.h include/grpc++/impl/codegen/time.h + include/grpcpp/impl/codegen/async_generic_service.h include/grpcpp/impl/codegen/async_stream.h include/grpcpp/impl/codegen/async_unary_call.h include/grpcpp/impl/codegen/byte_buffer.h @@ -3932,6 +3942,7 @@ foreach(_hdr include/grpc++/impl/codegen/stub_options.h include/grpc++/impl/codegen/sync_stream.h include/grpc++/impl/codegen/time.h + include/grpcpp/impl/codegen/async_generic_service.h include/grpcpp/impl/codegen/async_stream.h include/grpcpp/impl/codegen/async_unary_call.h include/grpcpp/impl/codegen/byte_buffer.h @@ -3977,6 +3988,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -4108,6 +4120,7 @@ foreach(_hdr include/grpc++/impl/codegen/stub_options.h include/grpc++/impl/codegen/sync_stream.h include/grpc++/impl/codegen/time.h + include/grpcpp/impl/codegen/async_generic_service.h include/grpcpp/impl/codegen/async_stream.h include/grpcpp/impl/codegen/async_unary_call.h include/grpcpp/impl/codegen/byte_buffer.h @@ -4153,6 +4166,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -4367,6 +4381,7 @@ foreach(_hdr include/grpc/impl/codegen/fork.h include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/log.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/sync.h include/grpc/impl/codegen/sync_custom.h @@ -4423,6 +4438,7 @@ foreach(_hdr include/grpc++/impl/codegen/stub_options.h include/grpc++/impl/codegen/sync_stream.h include/grpc++/impl/codegen/time.h + include/grpcpp/impl/codegen/async_generic_service.h include/grpcpp/impl/codegen/async_stream.h include/grpcpp/impl/codegen/async_unary_call.h include/grpcpp/impl/codegen/byte_buffer.h diff --git a/Makefile b/Makefile index 5bb4fbab438..e1392bb90bb 100644 --- a/Makefile +++ b/Makefile @@ -3234,6 +3234,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -3624,6 +3625,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -3993,6 +3995,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -4307,6 +4310,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -4603,6 +4607,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -4893,6 +4898,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -5189,6 +5195,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -5245,6 +5252,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/stub_options.h \ include/grpc++/impl/codegen/sync_stream.h \ include/grpc++/impl/codegen/time.h \ + include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ @@ -5759,6 +5767,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -5815,6 +5824,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/stub_options.h \ include/grpc++/impl/codegen/sync_stream.h \ include/grpc++/impl/codegen/time.h \ + include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ @@ -6204,6 +6214,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/stub_options.h \ include/grpc++/impl/codegen/sync_stream.h \ include/grpc++/impl/codegen/time.h \ + include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ @@ -6249,6 +6260,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -6356,6 +6368,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/stub_options.h \ include/grpc++/impl/codegen/sync_stream.h \ include/grpc++/impl/codegen/time.h \ + include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ @@ -6401,6 +6414,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -6619,6 +6633,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ + include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/sync.h \ include/grpc/impl/codegen/sync_custom.h \ @@ -6675,6 +6690,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/stub_options.h \ include/grpc++/impl/codegen/sync_stream.h \ include/grpc++/impl/codegen/time.h \ + include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ diff --git a/build.yaml b/build.yaml index f963f0c9139..4f02560d077 100644 --- a/build.yaml +++ b/build.yaml @@ -208,6 +208,7 @@ filegroups: - include/grpc/impl/codegen/fork.h - include/grpc/impl/codegen/gpr_slice.h - include/grpc/impl/codegen/gpr_types.h + - include/grpc/impl/codegen/log.h - include/grpc/impl/codegen/port_platform.h - include/grpc/impl/codegen/sync.h - include/grpc/impl/codegen/sync_custom.h @@ -1138,6 +1139,7 @@ filegroups: - include/grpc++/impl/codegen/stub_options.h - include/grpc++/impl/codegen/sync_stream.h - include/grpc++/impl/codegen/time.h + - include/grpcpp/impl/codegen/async_generic_service.h - include/grpcpp/impl/codegen/async_stream.h - include/grpcpp/impl/codegen/async_unary_call.h - include/grpcpp/impl/codegen/byte_buffer.h diff --git a/gRPC-C++.podspec b/gRPC-C++.podspec index 2380da9476b..e4561298aed 100644 --- a/gRPC-C++.podspec +++ b/gRPC-C++.podspec @@ -121,6 +121,7 @@ Pod::Spec.new do |s| 'include/grpcpp/support/stub_options.h', 'include/grpcpp/support/sync_stream.h', 'include/grpcpp/support/time.h', + 'include/grpcpp/impl/codegen/async_generic_service.h', 'include/grpcpp/impl/codegen/async_stream.h', 'include/grpcpp/impl/codegen/async_unary_call.h', 'include/grpcpp/impl/codegen/byte_buffer.h', diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index b7548e31d9d..c9cc3f6df75 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -133,6 +133,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/codegen/fork.h', 'include/grpc/impl/codegen/gpr_slice.h', 'include/grpc/impl/codegen/gpr_types.h', + 'include/grpc/impl/codegen/log.h', 'include/grpc/impl/codegen/port_platform.h', 'include/grpc/impl/codegen/sync.h', 'include/grpc/impl/codegen/sync_custom.h', @@ -154,6 +155,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/codegen/fork.h', 'include/grpc/impl/codegen/gpr_slice.h', 'include/grpc/impl/codegen/gpr_types.h', + 'include/grpc/impl/codegen/log.h', 'include/grpc/impl/codegen/port_platform.h', 'include/grpc/impl/codegen/sync.h', 'include/grpc/impl/codegen/sync_custom.h', diff --git a/grpc.def b/grpc.def index 6a91214e8c3..d118093affe 100644 --- a/grpc.def +++ b/grpc.def @@ -131,6 +131,13 @@ EXPORTS grpc_byte_buffer_reader_next grpc_byte_buffer_reader_readall grpc_raw_byte_buffer_from_reader + gpr_log_severity_string + gpr_log + gpr_should_log + gpr_log_message + gpr_set_log_verbosity + gpr_log_verbosity_init + gpr_set_log_function grpc_slice_ref grpc_slice_unref grpc_slice_copy @@ -189,13 +196,6 @@ EXPORTS gpr_get_allocation_functions gpr_cpu_num_cores gpr_cpu_current_cpu - gpr_log_severity_string - gpr_log - gpr_should_log - gpr_log_message - gpr_set_log_verbosity - gpr_log_verbosity_init - gpr_set_log_function gpr_format_message gpr_strdup gpr_asprintf diff --git a/grpc.gemspec b/grpc.gemspec index eb059d85144..1e87cce61e7 100644 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -75,6 +75,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/codegen/fork.h ) s.files += %w( include/grpc/impl/codegen/gpr_slice.h ) s.files += %w( include/grpc/impl/codegen/gpr_types.h ) + s.files += %w( include/grpc/impl/codegen/log.h ) s.files += %w( include/grpc/impl/codegen/port_platform.h ) s.files += %w( include/grpc/impl/codegen/sync.h ) s.files += %w( include/grpc/impl/codegen/sync_custom.h ) @@ -159,6 +160,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/codegen/fork.h ) s.files += %w( include/grpc/impl/codegen/gpr_slice.h ) s.files += %w( include/grpc/impl/codegen/gpr_types.h ) + s.files += %w( include/grpc/impl/codegen/log.h ) s.files += %w( include/grpc/impl/codegen/port_platform.h ) s.files += %w( include/grpc/impl/codegen/sync.h ) s.files += %w( include/grpc/impl/codegen/sync_custom.h ) diff --git a/include/grpc/impl/codegen/log.h b/include/grpc/impl/codegen/log.h new file mode 100644 index 00000000000..ad7f0241582 --- /dev/null +++ b/include/grpc/impl/codegen/log.h @@ -0,0 +1,112 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPC_IMPL_CODEGEN_LOG_H +#define GRPC_IMPL_CODEGEN_LOG_H + +#include + +#include +#include /* for abort() */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** GPR log API. + + Usage (within grpc): + + int argument1 = 3; + char* argument2 = "hello"; + gpr_log(GPR_DEBUG, "format string %d", argument1); + gpr_log(GPR_INFO, "hello world"); + gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */ + +/** The severity of a log message - use the #defines below when calling into + gpr_log to additionally supply file and line data */ +typedef enum gpr_log_severity { + GPR_LOG_SEVERITY_DEBUG, + GPR_LOG_SEVERITY_INFO, + GPR_LOG_SEVERITY_ERROR +} gpr_log_severity; + +#define GPR_LOG_VERBOSITY_UNSET -1 + +/** Returns a string representation of the log severity */ +GPRAPI const char* gpr_log_severity_string(gpr_log_severity severity); + +/** Macros to build log contexts at various severity levels */ +#define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG +#define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO +#define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR + +/** Log a message. It's advised to use GPR_xxx above to generate the context + * for each message */ +GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity, + const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); + +GPRAPI int gpr_should_log(gpr_log_severity severity); + +GPRAPI void gpr_log_message(const char* file, int line, + gpr_log_severity severity, const char* message); + +/** Set global log verbosity */ +GPRAPI void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print); + +GPRAPI void gpr_log_verbosity_init(void); + +/** Log overrides: applications can use this API to intercept logging calls + and use their own implementations */ + +struct gpr_log_func_args { + const char* file; + int line; + gpr_log_severity severity; + const char* message; +}; + +typedef struct gpr_log_func_args gpr_log_func_args; + +typedef void (*gpr_log_func)(gpr_log_func_args* args); +GPRAPI void gpr_set_log_function(gpr_log_func func); + +/** abort() the process if x is zero, having written a line to the log. + + Intended for internal invariants. If the error can be recovered from, + without the possibility of corruption, or might best be reflected via + an exception in a higher-level language, consider returning error code. */ +#define GPR_ASSERT(x) \ + do { \ + if (GPR_UNLIKELY(!(x))) { \ + gpr_log(GPR_ERROR, "assertion failed: %s", #x); \ + abort(); \ + } \ + } while (0) + +#ifndef NDEBUG +#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) +#else +#define GPR_DEBUG_ASSERT(x) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GRPC_IMPL_CODEGEN_LOG_H */ diff --git a/include/grpc/module.modulemap b/include/grpc/module.modulemap index e0d5404e8a4..9612a05bf5b 100644 --- a/include/grpc/module.modulemap +++ b/include/grpc/module.modulemap @@ -17,6 +17,7 @@ framework module grpc { header "impl/codegen/fork.h" header "impl/codegen/gpr_slice.h" header "impl/codegen/gpr_types.h" + header "impl/codegen/log.h" header "impl/codegen/port_platform.h" header "impl/codegen/sync.h" header "impl/codegen/sync_generic.h" @@ -32,6 +33,7 @@ framework module grpc { header "impl/codegen/fork.h" header "impl/codegen/gpr_slice.h" header "impl/codegen/gpr_types.h" + header "impl/codegen/log.h" header "impl/codegen/port_platform.h" header "impl/codegen/sync.h" header "impl/codegen/sync_generic.h" diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index 1837d4bd221..cdf1886084f 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -19,94 +19,6 @@ #ifndef GRPC_SUPPORT_LOG_H #define GRPC_SUPPORT_LOG_H -#include - -#include -#include /* for abort() */ - -#ifdef __cplusplus -extern "C" { -#endif - -/** GPR log API. - - Usage (within grpc): - - int argument1 = 3; - char* argument2 = "hello"; - gpr_log(GPR_DEBUG, "format string %d", argument1); - gpr_log(GPR_INFO, "hello world"); - gpr_log(GPR_ERROR, "%d %s!!", argument1, argument2); */ - -/** The severity of a log message - use the #defines below when calling into - gpr_log to additionally supply file and line data */ -typedef enum gpr_log_severity { - GPR_LOG_SEVERITY_DEBUG, - GPR_LOG_SEVERITY_INFO, - GPR_LOG_SEVERITY_ERROR -} gpr_log_severity; - -#define GPR_LOG_VERBOSITY_UNSET -1 - -/** Returns a string representation of the log severity */ -GPRAPI const char* gpr_log_severity_string(gpr_log_severity severity); - -/** Macros to build log contexts at various severity levels */ -#define GPR_DEBUG __FILE__, __LINE__, GPR_LOG_SEVERITY_DEBUG -#define GPR_INFO __FILE__, __LINE__, GPR_LOG_SEVERITY_INFO -#define GPR_ERROR __FILE__, __LINE__, GPR_LOG_SEVERITY_ERROR - -/** Log a message. It's advised to use GPR_xxx above to generate the context - * for each message */ -GPRAPI void gpr_log(const char* file, int line, gpr_log_severity severity, - const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); - -GPRAPI int gpr_should_log(gpr_log_severity severity); - -GPRAPI void gpr_log_message(const char* file, int line, - gpr_log_severity severity, const char* message); - -/** Set global log verbosity */ -GPRAPI void gpr_set_log_verbosity(gpr_log_severity min_severity_to_print); - -GPRAPI void gpr_log_verbosity_init(void); - -/** Log overrides: applications can use this API to intercept logging calls - and use their own implementations */ - -struct gpr_log_func_args { - const char* file; - int line; - gpr_log_severity severity; - const char* message; -}; - -typedef struct gpr_log_func_args gpr_log_func_args; - -typedef void (*gpr_log_func)(gpr_log_func_args* args); -GPRAPI void gpr_set_log_function(gpr_log_func func); - -/** abort() the process if x is zero, having written a line to the log. - - Intended for internal invariants. If the error can be recovered from, - without the possibility of corruption, or might best be reflected via - an exception in a higher-level language, consider returning error code. */ -#define GPR_ASSERT(x) \ - do { \ - if (GPR_UNLIKELY(!(x))) { \ - gpr_log(GPR_ERROR, "assertion failed: %s", #x); \ - abort(); \ - } \ - } while (0) - -#ifndef NDEBUG -#define GPR_DEBUG_ASSERT(x) GPR_ASSERT(x) -#else -#define GPR_DEBUG_ASSERT(x) -#endif - -#ifdef __cplusplus -} -#endif +#include #endif /* GRPC_SUPPORT_LOG_H */ diff --git a/include/grpcpp/generic/async_generic_service.h b/include/grpcpp/generic/async_generic_service.h index 7eaa541151a..2c67edc5170 100644 --- a/include/grpcpp/generic/async_generic_service.h +++ b/include/grpcpp/generic/async_generic_service.h @@ -1,6 +1,6 @@ /* * - * Copyright 2015 gRPC authors. + * Copyright 2018 gRPC authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,60 +19,6 @@ #ifndef GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H #define GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H -#include -#include - -struct grpc_server; - -namespace grpc { - -typedef ServerAsyncReaderWriter - GenericServerAsyncReaderWriter; - -class GenericServerContext final : public ServerContext { - public: - const grpc::string& method() const { return method_; } - const grpc::string& host() const { return host_; } - - private: - friend class Server; - friend class ServerInterface; - - grpc::string method_; - grpc::string host_; -}; - -// A generic service at the server side accepts all RPC methods and hosts. It is -// typically used in proxies. The generic service can be registered to a server -// which also has other services. -// Sample usage: -// ServerBuilder builder; -// auto cq = builder.AddCompletionQueue(); -// AsyncGenericService generic_service; -// builder.RegisterAsyncGeneicService(&generic_service); -// auto server = builder.BuildAndStart(); -// -// // request a new call -// GenericServerContext context; -// GenericAsyncReaderWriter stream; -// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); -// -// When tag is retrieved from cq->Next(), context.method() can be used to look -// at the method and the RPC can be handled accordingly. -class AsyncGenericService final { - public: - AsyncGenericService() : server_(nullptr) {} - - void RequestCall(GenericServerContext* ctx, - GenericServerAsyncReaderWriter* reader_writer, - CompletionQueue* call_cq, - ServerCompletionQueue* notification_cq, void* tag); - - private: - friend class Server; - Server* server_; -}; - -} // namespace grpc +#include #endif // GRPCPP_GENERIC_ASYNC_GENERIC_SERVICE_H diff --git a/include/grpcpp/impl/codegen/async_generic_service.h b/include/grpcpp/impl/codegen/async_generic_service.h new file mode 100644 index 00000000000..957bb776f1d --- /dev/null +++ b/include/grpcpp/impl/codegen/async_generic_service.h @@ -0,0 +1,81 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#ifndef GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H +#define GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H + +#include +#include + +struct grpc_server; + +namespace grpc { + +typedef ServerAsyncReaderWriter + GenericServerAsyncReaderWriter; +typedef ServerAsyncResponseWriter GenericServerAsyncResponseWriter; +typedef ServerAsyncReader GenericServerAsyncReader; +typedef ServerAsyncWriter GenericServerAsyncWriter; + +class GenericServerContext final : public ServerContext { + public: + const grpc::string& method() const { return method_; } + const grpc::string& host() const { return host_; } + + private: + friend class Server; + friend class ServerInterface; + + grpc::string method_; + grpc::string host_; +}; + +// A generic service at the server side accepts all RPC methods and hosts. It is +// typically used in proxies. The generic service can be registered to a server +// which also has other services. +// Sample usage: +// ServerBuilder builder; +// auto cq = builder.AddCompletionQueue(); +// AsyncGenericService generic_service; +// builder.RegisterAsyncGeneicService(&generic_service); +// auto server = builder.BuildAndStart(); +// +// // request a new call +// GenericServerContext context; +// GenericAsyncReaderWriter stream; +// generic_service.RequestCall(&context, &stream, cq.get(), cq.get(), tag); +// +// When tag is retrieved from cq->Next(), context.method() can be used to look +// at the method and the RPC can be handled accordingly. +class AsyncGenericService final { + public: + AsyncGenericService() : server_(nullptr) {} + + void RequestCall(GenericServerContext* ctx, + GenericServerAsyncReaderWriter* reader_writer, + CompletionQueue* call_cq, + ServerCompletionQueue* notification_cq, void* tag); + + private: + friend class Server; + Server* server_; +}; + +} // namespace grpc + +#endif // GRPCPP_IMPL_CODEGEN_ASYNC_GENERIC_SERVICE_H diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h index dd85405e7a6..1b4e57d80ce 100644 --- a/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/include/grpcpp/impl/codegen/rpc_service_method.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h index a576f66911e..af94d653f07 100644 --- a/include/grpcpp/impl/codegen/service_type.h +++ b/include/grpcpp/impl/codegen/service_type.h @@ -139,6 +139,14 @@ class Service { methods_[index].reset(); } + void MarkMethodCodegenGeneric(int index) { + GPR_CODEGEN_ASSERT(methods_[index]->handler() != nullptr && + "Cannot mark the method as 'codegen generic' because it " + "has already been " + "marked as 'async' or 'generic'."); + methods_[index]->ResetHandler(); + } + void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() && "Cannot mark an async or generic method Streamed"); diff --git a/package.xml b/package.xml index 51f82e18898..2cf8e41fc1f 100644 --- a/package.xml +++ b/package.xml @@ -80,6 +80,7 @@ + @@ -164,6 +165,7 @@ + diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index 30d66b444f6..f01f279a44e 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -128,6 +128,7 @@ grpc::string GetHeaderIncludes(grpc_generator::File* file, ""); } static const char* headers_strs[] = { + "grpcpp/impl/codegen/async_generic_service.h", "grpcpp/impl/codegen/async_stream.h", "grpcpp/impl/codegen/async_unary_call.h", "grpcpp/impl/codegen/method_handler_impl.h", @@ -588,43 +589,27 @@ void PrintHeaderServerMethodSync(grpc_generator::Printer* printer, printer->Print(method->GetTrailingComments("//").c_str()); } -void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, - const grpc_generator::Method* method, - std::map* vars) { - (*vars)["Method"] = method->name(); - (*vars)["Request"] = method->input_type_name(); - (*vars)["Response"] = method->output_type_name(); - printer->Print(*vars, "template \n"); - printer->Print(*vars, - "class WithAsyncMethod_$Method$ : public BaseClass {\n"); - printer->Print( - " private:\n" - " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); - printer->Print(" public:\n"); - printer->Indent(); - printer->Print(*vars, - "WithAsyncMethod_$Method$() {\n" - " ::grpc::Service::MarkMethodAsync($Idx$);\n" - "}\n"); - printer->Print(*vars, - "~WithAsyncMethod_$Method$() override {\n" - " BaseClassMustBeDerivedFromService(this);\n" - "}\n"); +// Helper generator. Disabled the sync API for Request and Response, then adds +// in an async API for RealRequest and RealResponse types. This is to be used +// to generate async and codegen generic APIs. +void PrintHeaderServerAsyncMethodsHelper( + grpc_generator::Printer* printer, const grpc_generator::Method* method, + std::map* vars) { if (method->NoStreaming()) { printer->Print( *vars, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "$Response$* response) override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); printer->Print( *vars, "void Request$Method$(" - "::grpc::ServerContext* context, $Request$* request, " - "::grpc::ServerAsyncResponseWriter< $Response$>* response, " + "::grpc::ServerContext* context, $RealRequest$* request, " + "::grpc::ServerAsyncResponseWriter< $RealResponse$>* response, " "::grpc::CompletionQueue* new_call_cq, " "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n"); printer->Print(*vars, @@ -638,7 +623,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, "::grpc::Status $Method$(" "::grpc::ServerContext* context, " "::grpc::ServerReader< $Request$>* reader, " - "$Response$* response) final override {\n" + "$Response$* response) override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -646,7 +631,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, *vars, "void Request$Method$(" "::grpc::ServerContext* context, " - "::grpc::ServerAsyncReader< $Response$, $Request$>* reader, " + "::grpc::ServerAsyncReader< $RealResponse$, $RealRequest$>* reader, " "::grpc::CompletionQueue* new_call_cq, " "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n"); printer->Print(*vars, @@ -659,7 +644,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, "// disable synchronous version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerWriter< $Response$>* writer) override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -667,8 +652,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, printer->Print( *vars, "void Request$Method$(" - "::grpc::ServerContext* context, $Request$* request, " - "::grpc::ServerAsyncWriter< $Response$>* writer, " + "::grpc::ServerContext* context, $RealRequest$* request, " + "::grpc::ServerAsyncWriter< $RealResponse$>* writer, " "::grpc::CompletionQueue* new_call_cq, " "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n"); printer->Print( @@ -683,7 +668,7 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, "::grpc::Status $Method$(" "::grpc::ServerContext* context, " "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) " - "final override {\n" + " override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -691,7 +676,8 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, *vars, "void Request$Method$(" "::grpc::ServerContext* context, " - "::grpc::ServerAsyncReaderWriter< $Response$, $Request$>* stream, " + "::grpc::ServerAsyncReaderWriter< $RealResponse$, $RealRequest$>* " + "stream, " "::grpc::CompletionQueue* new_call_cq, " "::grpc::ServerCompletionQueue* notification_cq, void *tag) {\n"); printer->Print(*vars, @@ -699,6 +685,35 @@ void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, "context, stream, new_call_cq, notification_cq, tag);\n"); printer->Print("}\n"); } +} + +void PrintHeaderServerMethodAsync(grpc_generator::Printer* printer, + const grpc_generator::Method* method, + std::map* vars) { + (*vars)["Method"] = method->name(); + // These will be disabled + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + // These will be used for the async API + (*vars)["RealRequest"] = method->input_type_name(); + (*vars)["RealResponse"] = method->output_type_name(); + printer->Print(*vars, "template \n"); + printer->Print(*vars, + "class WithAsyncMethod_$Method$ : public BaseClass {\n"); + printer->Print( + " private:\n" + " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); + printer->Print(" public:\n"); + printer->Indent(); + printer->Print(*vars, + "WithAsyncMethod_$Method$() {\n" + " ::grpc::Service::MarkMethodAsync($Idx$);\n" + "}\n"); + printer->Print(*vars, + "~WithAsyncMethod_$Method$() override {\n" + " BaseClassMustBeDerivedFromService(this);\n" + "}\n"); + PrintHeaderServerAsyncMethodsHelper(printer, method, vars); printer->Outdent(); printer->Print(*vars, "};\n"); } @@ -738,7 +753,7 @@ void PrintHeaderServerMethodStreamedUnary( "// disable regular version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "$Response$* response) override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -790,7 +805,7 @@ void PrintHeaderServerMethodSplitStreaming( "// disable regular version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerWriter< $Response$>* writer) override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -835,7 +850,7 @@ void PrintHeaderServerMethodGeneric( "// disable synchronous version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "$Response$* response) final override {\n" + "$Response$* response) override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -846,7 +861,7 @@ void PrintHeaderServerMethodGeneric( "::grpc::Status $Method$(" "::grpc::ServerContext* context, " "::grpc::ServerReader< $Request$>* reader, " - "$Response$* response) final override {\n" + "$Response$* response) override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -856,7 +871,7 @@ void PrintHeaderServerMethodGeneric( "// disable synchronous version of this method\n" "::grpc::Status $Method$(" "::grpc::ServerContext* context, const $Request$* request, " - "::grpc::ServerWriter< $Response$>* writer) final override " + "::grpc::ServerWriter< $Response$>* writer) override " "{\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" @@ -868,7 +883,7 @@ void PrintHeaderServerMethodGeneric( "::grpc::Status $Method$(" "::grpc::ServerContext* context, " "::grpc::ServerReaderWriter< $Response$, $Request$>* stream) " - "final override {\n" + " override {\n" " abort();\n" " return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, \"\");\n" "}\n"); @@ -877,6 +892,37 @@ void PrintHeaderServerMethodGeneric( printer->Print(*vars, "};\n"); } +void PrintHeaderServerMethodCodegenGeneric( + grpc_generator::Printer* printer, const grpc_generator::Method* method, + std::map* vars) { + (*vars)["Method"] = method->name(); + // These will be disabled + (*vars)["Request"] = method->input_type_name(); + (*vars)["Response"] = method->output_type_name(); + // These will be used for codegen generic API + (*vars)["RealRequest"] = "::grpc::ByteBuffer"; + (*vars)["RealResponse"] = "::grpc::ByteBuffer"; + printer->Print(*vars, "template \n"); + printer->Print( + *vars, "class WithCodegenGenericMethod_$Method$ : public BaseClass {\n"); + printer->Print( + " private:\n" + " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); + printer->Print(" public:\n"); + printer->Indent(); + printer->Print(*vars, + "WithCodegenGenericMethod_$Method$() {\n" + " ::grpc::Service::MarkMethodCodegenGeneric($Idx$);\n" + "}\n"); + printer->Print(*vars, + "~WithCodegenGenericMethod_$Method$() override {\n" + " BaseClassMustBeDerivedFromService(this);\n" + "}\n"); + PrintHeaderServerAsyncMethodsHelper(printer, method, vars); + printer->Outdent(); + printer->Print(*vars, "};\n"); +} + void PrintHeaderService(grpc_generator::Printer* printer, const grpc_generator::Service* service, std::map* vars) { @@ -981,6 +1027,13 @@ void PrintHeaderService(grpc_generator::Printer* printer, PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars); } + // Server side - CodegenGeneric + for (int i = 0; i < service->method_count(); ++i) { + (*vars)["Idx"] = as_string(i); + PrintHeaderServerMethodCodegenGeneric(printer, service->method(i).get(), + vars); + } + // Server side - Streamed Unary for (int i = 0; i < service->method_count(); ++i) { (*vars)["Idx"] = as_string(i); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 02f84c0b962..b047e4f16ea 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -154,6 +154,13 @@ grpc_byte_buffer_reader_destroy_type grpc_byte_buffer_reader_destroy_import; grpc_byte_buffer_reader_next_type grpc_byte_buffer_reader_next_import; grpc_byte_buffer_reader_readall_type grpc_byte_buffer_reader_readall_import; grpc_raw_byte_buffer_from_reader_type grpc_raw_byte_buffer_from_reader_import; +gpr_log_severity_string_type gpr_log_severity_string_import; +gpr_log_type gpr_log_import; +gpr_should_log_type gpr_should_log_import; +gpr_log_message_type gpr_log_message_import; +gpr_set_log_verbosity_type gpr_set_log_verbosity_import; +gpr_log_verbosity_init_type gpr_log_verbosity_init_import; +gpr_set_log_function_type gpr_set_log_function_import; grpc_slice_ref_type grpc_slice_ref_import; grpc_slice_unref_type grpc_slice_unref_import; grpc_slice_copy_type grpc_slice_copy_import; @@ -212,13 +219,6 @@ gpr_set_allocation_functions_type gpr_set_allocation_functions_import; gpr_get_allocation_functions_type gpr_get_allocation_functions_import; gpr_cpu_num_cores_type gpr_cpu_num_cores_import; gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; -gpr_log_severity_string_type gpr_log_severity_string_import; -gpr_log_type gpr_log_import; -gpr_should_log_type gpr_should_log_import; -gpr_log_message_type gpr_log_message_import; -gpr_set_log_verbosity_type gpr_set_log_verbosity_import; -gpr_log_verbosity_init_type gpr_log_verbosity_init_import; -gpr_set_log_function_type gpr_set_log_function_import; gpr_format_message_type gpr_format_message_import; gpr_strdup_type gpr_strdup_import; gpr_asprintf_type gpr_asprintf_import; @@ -402,6 +402,13 @@ void grpc_rb_load_imports(HMODULE library) { grpc_byte_buffer_reader_next_import = (grpc_byte_buffer_reader_next_type) GetProcAddress(library, "grpc_byte_buffer_reader_next"); grpc_byte_buffer_reader_readall_import = (grpc_byte_buffer_reader_readall_type) GetProcAddress(library, "grpc_byte_buffer_reader_readall"); grpc_raw_byte_buffer_from_reader_import = (grpc_raw_byte_buffer_from_reader_type) GetProcAddress(library, "grpc_raw_byte_buffer_from_reader"); + gpr_log_severity_string_import = (gpr_log_severity_string_type) GetProcAddress(library, "gpr_log_severity_string"); + gpr_log_import = (gpr_log_type) GetProcAddress(library, "gpr_log"); + gpr_should_log_import = (gpr_should_log_type) GetProcAddress(library, "gpr_should_log"); + gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); + gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity"); + gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init"); + gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function"); grpc_slice_ref_import = (grpc_slice_ref_type) GetProcAddress(library, "grpc_slice_ref"); grpc_slice_unref_import = (grpc_slice_unref_type) GetProcAddress(library, "grpc_slice_unref"); grpc_slice_copy_import = (grpc_slice_copy_type) GetProcAddress(library, "grpc_slice_copy"); @@ -460,13 +467,6 @@ void grpc_rb_load_imports(HMODULE library) { gpr_get_allocation_functions_import = (gpr_get_allocation_functions_type) GetProcAddress(library, "gpr_get_allocation_functions"); gpr_cpu_num_cores_import = (gpr_cpu_num_cores_type) GetProcAddress(library, "gpr_cpu_num_cores"); gpr_cpu_current_cpu_import = (gpr_cpu_current_cpu_type) GetProcAddress(library, "gpr_cpu_current_cpu"); - gpr_log_severity_string_import = (gpr_log_severity_string_type) GetProcAddress(library, "gpr_log_severity_string"); - gpr_log_import = (gpr_log_type) GetProcAddress(library, "gpr_log"); - gpr_should_log_import = (gpr_should_log_type) GetProcAddress(library, "gpr_should_log"); - gpr_log_message_import = (gpr_log_message_type) GetProcAddress(library, "gpr_log_message"); - gpr_set_log_verbosity_import = (gpr_set_log_verbosity_type) GetProcAddress(library, "gpr_set_log_verbosity"); - gpr_log_verbosity_init_import = (gpr_log_verbosity_init_type) GetProcAddress(library, "gpr_log_verbosity_init"); - gpr_set_log_function_import = (gpr_set_log_function_type) GetProcAddress(library, "gpr_set_log_function"); gpr_format_message_import = (gpr_format_message_type) GetProcAddress(library, "gpr_format_message"); gpr_strdup_import = (gpr_strdup_type) GetProcAddress(library, "gpr_strdup"); gpr_asprintf_import = (gpr_asprintf_type) GetProcAddress(library, "gpr_asprintf"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 46d3bf5a33a..c2129f9aa22 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -30,11 +30,11 @@ #include #include #include +#include #include #include #include #include -#include #include #include #include @@ -437,6 +437,27 @@ extern grpc_byte_buffer_reader_readall_type grpc_byte_buffer_reader_readall_impo typedef grpc_byte_buffer*(*grpc_raw_byte_buffer_from_reader_type)(grpc_byte_buffer_reader* reader); extern grpc_raw_byte_buffer_from_reader_type grpc_raw_byte_buffer_from_reader_import; #define grpc_raw_byte_buffer_from_reader grpc_raw_byte_buffer_from_reader_import +typedef const char*(*gpr_log_severity_string_type)(gpr_log_severity severity); +extern gpr_log_severity_string_type gpr_log_severity_string_import; +#define gpr_log_severity_string gpr_log_severity_string_import +typedef void(*gpr_log_type)(const char* file, int line, gpr_log_severity severity, const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); +extern gpr_log_type gpr_log_import; +#define gpr_log gpr_log_import +typedef int(*gpr_should_log_type)(gpr_log_severity severity); +extern gpr_should_log_type gpr_should_log_import; +#define gpr_should_log gpr_should_log_import +typedef void(*gpr_log_message_type)(const char* file, int line, gpr_log_severity severity, const char* message); +extern gpr_log_message_type gpr_log_message_import; +#define gpr_log_message gpr_log_message_import +typedef void(*gpr_set_log_verbosity_type)(gpr_log_severity min_severity_to_print); +extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import; +#define gpr_set_log_verbosity gpr_set_log_verbosity_import +typedef void(*gpr_log_verbosity_init_type)(void); +extern gpr_log_verbosity_init_type gpr_log_verbosity_init_import; +#define gpr_log_verbosity_init gpr_log_verbosity_init_import +typedef void(*gpr_set_log_function_type)(gpr_log_func func); +extern gpr_set_log_function_type gpr_set_log_function_import; +#define gpr_set_log_function gpr_set_log_function_import typedef grpc_slice(*grpc_slice_ref_type)(grpc_slice s); extern grpc_slice_ref_type grpc_slice_ref_import; #define grpc_slice_ref grpc_slice_ref_import @@ -611,27 +632,6 @@ extern gpr_cpu_num_cores_type gpr_cpu_num_cores_import; typedef unsigned(*gpr_cpu_current_cpu_type)(void); extern gpr_cpu_current_cpu_type gpr_cpu_current_cpu_import; #define gpr_cpu_current_cpu gpr_cpu_current_cpu_import -typedef const char*(*gpr_log_severity_string_type)(gpr_log_severity severity); -extern gpr_log_severity_string_type gpr_log_severity_string_import; -#define gpr_log_severity_string gpr_log_severity_string_import -typedef void(*gpr_log_type)(const char* file, int line, gpr_log_severity severity, const char* format, ...) GPR_PRINT_FORMAT_CHECK(4, 5); -extern gpr_log_type gpr_log_import; -#define gpr_log gpr_log_import -typedef int(*gpr_should_log_type)(gpr_log_severity severity); -extern gpr_should_log_type gpr_should_log_import; -#define gpr_should_log gpr_should_log_import -typedef void(*gpr_log_message_type)(const char* file, int line, gpr_log_severity severity, const char* message); -extern gpr_log_message_type gpr_log_message_import; -#define gpr_log_message gpr_log_message_import -typedef void(*gpr_set_log_verbosity_type)(gpr_log_severity min_severity_to_print); -extern gpr_set_log_verbosity_type gpr_set_log_verbosity_import; -#define gpr_set_log_verbosity gpr_set_log_verbosity_import -typedef void(*gpr_log_verbosity_init_type)(void); -extern gpr_log_verbosity_init_type gpr_log_verbosity_init_import; -#define gpr_log_verbosity_init gpr_log_verbosity_init_import -typedef void(*gpr_set_log_function_type)(gpr_log_func func); -extern gpr_set_log_function_type gpr_set_log_function_import; -#define gpr_set_log_function gpr_set_log_function_import typedef char*(*gpr_format_message_type)(int messageid); extern gpr_format_message_type gpr_format_message_import; #define gpr_format_message gpr_format_message_import diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index 52a1b039980..2883810eaad 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -189,6 +190,13 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) grpc_byte_buffer_reader_next); printf("%lx", (unsigned long) grpc_byte_buffer_reader_readall); printf("%lx", (unsigned long) grpc_raw_byte_buffer_from_reader); + printf("%lx", (unsigned long) gpr_log_severity_string); + printf("%lx", (unsigned long) gpr_log); + printf("%lx", (unsigned long) gpr_should_log); + printf("%lx", (unsigned long) gpr_log_message); + printf("%lx", (unsigned long) gpr_set_log_verbosity); + printf("%lx", (unsigned long) gpr_log_verbosity_init); + printf("%lx", (unsigned long) gpr_set_log_function); printf("%lx", (unsigned long) grpc_slice_ref); printf("%lx", (unsigned long) grpc_slice_unref); printf("%lx", (unsigned long) grpc_slice_copy); @@ -247,13 +255,6 @@ int main(int argc, char **argv) { printf("%lx", (unsigned long) gpr_get_allocation_functions); printf("%lx", (unsigned long) gpr_cpu_num_cores); printf("%lx", (unsigned long) gpr_cpu_current_cpu); - printf("%lx", (unsigned long) gpr_log_severity_string); - printf("%lx", (unsigned long) gpr_log); - printf("%lx", (unsigned long) gpr_should_log); - printf("%lx", (unsigned long) gpr_log_message); - printf("%lx", (unsigned long) gpr_set_log_verbosity); - printf("%lx", (unsigned long) gpr_log_verbosity_init); - printf("%lx", (unsigned long) gpr_set_log_function); printf("%lx", (unsigned long) gpr_strdup); printf("%lx", (unsigned long) gpr_asprintf); printf("%lx", (unsigned long) gpr_mu_init); diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index ca7db5db326..033c963dc4a 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -26,6 +26,7 @@ #include "src/proto/grpc/testing/compiler_test.pb.h" +#include #include #include #include @@ -207,7 +208,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -227,7 +228,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -247,7 +248,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -267,7 +268,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -288,7 +289,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -305,7 +306,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -322,7 +323,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -339,12 +340,92 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) final override { + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } }; template + class WithCodegenGenericMethod_MethodA1 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithCodegenGenericMethod_MethodA1() { + ::grpc::Service::MarkMethodCodegenGeneric(0); + } + ~WithCodegenGenericMethod_MethodA1() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA1(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template + class WithCodegenGenericMethod_MethodA2 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithCodegenGenericMethod_MethodA2() { + ::grpc::Service::MarkMethodCodegenGeneric(1); + } + ~WithCodegenGenericMethod_MethodA2() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA2(::grpc::ServerContext* context, ::grpc::ServerReader< ::grpc::testing::Request>* reader, ::grpc::testing::Response* response) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA2(::grpc::ServerContext* context, ::grpc::ServerAsyncReader< ::grpc::ByteBuffer, ::grpc::ByteBuffer>* reader, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncClientStreaming(1, context, reader, new_call_cq, notification_cq, tag); + } + }; + template + class WithCodegenGenericMethod_MethodA3 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithCodegenGenericMethod_MethodA3() { + ::grpc::Service::MarkMethodCodegenGeneric(2); + } + ~WithCodegenGenericMethod_MethodA3() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA3(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncWriter< ::grpc::ByteBuffer>* writer, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncServerStreaming(2, context, request, writer, new_call_cq, notification_cq, tag); + } + }; + template + class WithCodegenGenericMethod_MethodA4 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithCodegenGenericMethod_MethodA4() { + ::grpc::Service::MarkMethodCodegenGeneric(3); + } + ~WithCodegenGenericMethod_MethodA4() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodA4(::grpc::ServerContext* context, ::grpc::ServerReaderWriter< ::grpc::testing::Response, ::grpc::testing::Request>* stream) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodA4(::grpc::ServerContext* context, ::grpc::ServerAsyncReaderWriter< ::grpc::ByteBuffer, ::grpc::ByteBuffer>* stream, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncBidiStreaming(3, context, stream, new_call_cq, notification_cq, tag); + } + }; + template class WithStreamedUnaryMethod_MethodA1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} @@ -357,7 +438,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable regular version of this method - ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodA1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -378,7 +459,7 @@ class ServiceA final { BaseClassMustBeDerivedFromService(this); } // disable regular version of this method - ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) final override { + ::grpc::Status MethodA3(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::ServerWriter< ::grpc::testing::Response>* writer) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -450,7 +531,7 @@ class ServiceB final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } @@ -471,12 +552,32 @@ class ServiceB final { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method - ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } }; template + class WithCodegenGenericMethod_MethodB1 : public BaseClass { + private: + void BaseClassMustBeDerivedFromService(const Service *service) {} + public: + WithCodegenGenericMethod_MethodB1() { + ::grpc::Service::MarkMethodCodegenGeneric(0); + } + ~WithCodegenGenericMethod_MethodB1() override { + BaseClassMustBeDerivedFromService(this); + } + // disable synchronous version of this method + ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { + abort(); + return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); + } + void RequestMethodB1(::grpc::ServerContext* context, ::grpc::ByteBuffer* request, ::grpc::ServerAsyncResponseWriter< ::grpc::ByteBuffer>* response, ::grpc::CompletionQueue* new_call_cq, ::grpc::ServerCompletionQueue* notification_cq, void *tag) { + ::grpc::Service::RequestAsyncUnary(0, context, request, response, new_call_cq, notification_cq, tag); + } + }; + template class WithStreamedUnaryMethod_MethodB1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} @@ -489,7 +590,7 @@ class ServiceB final { BaseClassMustBeDerivedFromService(this); } // disable regular version of this method - ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) final override { + ::grpc::Status MethodB1(::grpc::ServerContext* context, const ::grpc::testing::Request* request, ::grpc::testing::Response* response) override { abort(); return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED, ""); } diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 3da41dc7e7a..7ac4ed4b3ec 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -891,6 +891,7 @@ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ +include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/slice.h \ @@ -936,6 +937,7 @@ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \ include/grpcpp/impl/channel_argument_option.h \ include/grpcpp/impl/client_unary_call.h \ +include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index e552b4ed567..c37d0fee361 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -892,6 +892,7 @@ include/grpc/impl/codegen/fork.h \ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ +include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/propagation_bits.h \ include/grpc/impl/codegen/slice.h \ @@ -937,6 +938,7 @@ include/grpcpp/health_check_service_interface.h \ include/grpcpp/impl/call.h \ include/grpcpp/impl/channel_argument_option.h \ include/grpcpp/impl/client_unary_call.h \ +include/grpcpp/impl/codegen/async_generic_service.h \ include/grpcpp/impl/codegen/async_stream.h \ include/grpcpp/impl/codegen/async_unary_call.h \ include/grpcpp/impl/codegen/byte_buffer.h \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 592c94e51bf..a85c328b07b 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -825,6 +825,8 @@ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ +include/grpc/impl/codegen/log.h \ +include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/propagation_bits.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 0a3f7fbdc26..264f854cfcb 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -825,6 +825,8 @@ include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ +include/grpc/impl/codegen/log.h \ +include/grpc/impl/codegen/log.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/propagation_bits.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 66191656ffc..9a9ddd7024f 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -9256,6 +9256,7 @@ "include/grpc/impl/codegen/fork.h", "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", + "include/grpc/impl/codegen/log.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/sync.h", "include/grpc/impl/codegen/sync_custom.h", @@ -9274,6 +9275,7 @@ "include/grpc/impl/codegen/fork.h", "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", + "include/grpc/impl/codegen/log.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/sync.h", "include/grpc/impl/codegen/sync_custom.h", @@ -10896,6 +10898,7 @@ "include/grpc++/impl/codegen/stub_options.h", "include/grpc++/impl/codegen/sync_stream.h", "include/grpc++/impl/codegen/time.h", + "include/grpcpp/impl/codegen/async_generic_service.h", "include/grpcpp/impl/codegen/async_stream.h", "include/grpcpp/impl/codegen/async_unary_call.h", "include/grpcpp/impl/codegen/byte_buffer.h", @@ -10961,6 +10964,7 @@ "include/grpc++/impl/codegen/stub_options.h", "include/grpc++/impl/codegen/sync_stream.h", "include/grpc++/impl/codegen/time.h", + "include/grpcpp/impl/codegen/async_generic_service.h", "include/grpcpp/impl/codegen/async_stream.h", "include/grpcpp/impl/codegen/async_unary_call.h", "include/grpcpp/impl/codegen/byte_buffer.h", From bacd625d375471d34ec6afd127bac6feb06e4ec8 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 18 Jun 2018 18:40:39 -0700 Subject: [PATCH 2/8] Add end2end test for codegen_generic --- CMakeLists.txt | 40 ++ Makefile | 48 ++ build.yaml | 13 + .../end2end/codegen_generic_end2end_test.cc | 454 ++++++++++++++++++ test/cpp/util/byte_buffer_proto_helper.cc | 13 + test/cpp/util/byte_buffer_proto_helper.h | 3 + .../generated/sources_and_headers.json | 19 + tools/run_tests/generated/tests.json | 24 + 8 files changed, 614 insertions(+) create mode 100644 test/cpp/end2end/codegen_generic_end2end_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bf5cdbd691..796dcd6eb80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -554,6 +554,7 @@ add_dependencies(buildtests_cxx client_crash_test) endif() add_dependencies(buildtests_cxx client_crash_test_server) add_dependencies(buildtests_cxx client_lb_end2end_test) +add_dependencies(buildtests_cxx codegen_generic_end2end_test) add_dependencies(buildtests_cxx codegen_test_full) add_dependencies(buildtests_cxx codegen_test_minimal) add_dependencies(buildtests_cxx credentials_test) @@ -11137,6 +11138,45 @@ target_link_libraries(client_lb_end2end_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(codegen_generic_end2end_test + test/cpp/end2end/codegen_generic_end2end_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(codegen_generic_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(codegen_generic_end2end_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(codegen_test_full ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.grpc.pb.cc diff --git a/Makefile b/Makefile index e1392bb90bb..80b307f1397 100644 --- a/Makefile +++ b/Makefile @@ -1130,6 +1130,7 @@ client_channel_stress_test: $(BINDIR)/$(CONFIG)/client_channel_stress_test client_crash_test: $(BINDIR)/$(CONFIG)/client_crash_test client_crash_test_server: $(BINDIR)/$(CONFIG)/client_crash_test_server client_lb_end2end_test: $(BINDIR)/$(CONFIG)/client_lb_end2end_test +codegen_generic_end2end_test: $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test codegen_test_full: $(BINDIR)/$(CONFIG)/codegen_test_full codegen_test_minimal: $(BINDIR)/$(CONFIG)/codegen_test_minimal credentials_test: $(BINDIR)/$(CONFIG)/credentials_test @@ -1627,6 +1628,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/client_crash_test \ $(BINDIR)/$(CONFIG)/client_crash_test_server \ $(BINDIR)/$(CONFIG)/client_lb_end2end_test \ + $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test \ $(BINDIR)/$(CONFIG)/codegen_test_full \ $(BINDIR)/$(CONFIG)/codegen_test_minimal \ $(BINDIR)/$(CONFIG)/credentials_test \ @@ -1803,6 +1805,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/client_crash_test \ $(BINDIR)/$(CONFIG)/client_crash_test_server \ $(BINDIR)/$(CONFIG)/client_lb_end2end_test \ + $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test \ $(BINDIR)/$(CONFIG)/codegen_test_full \ $(BINDIR)/$(CONFIG)/codegen_test_minimal \ $(BINDIR)/$(CONFIG)/credentials_test \ @@ -2247,6 +2250,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/client_crash_test || ( echo test client_crash_test failed ; exit 1 ) $(E) "[RUN] Testing client_lb_end2end_test" $(Q) $(BINDIR)/$(CONFIG)/client_lb_end2end_test || ( echo test client_lb_end2end_test failed ; exit 1 ) + $(E) "[RUN] Testing codegen_generic_end2end_test" + $(Q) $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test || ( echo test codegen_generic_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing codegen_test_full" $(Q) $(BINDIR)/$(CONFIG)/codegen_test_full || ( echo test codegen_test_full failed ; exit 1 ) $(E) "[RUN] Testing codegen_test_minimal" @@ -16788,6 +16793,49 @@ endif endif +CODEGEN_GENERIC_END2END_TEST_SRC = \ + test/cpp/end2end/codegen_generic_end2end_test.cc \ + +CODEGEN_GENERIC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CODEGEN_GENERIC_END2END_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. + +$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: $(PROTOBUF_DEP) $(CODEGEN_GENERIC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_GENERIC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/codegen_generic_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_codegen_generic_end2end_test: $(CODEGEN_GENERIC_END2END_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CODEGEN_GENERIC_END2END_TEST_OBJS:.o=.dep) +endif +endif + + CODEGEN_TEST_FULL_SRC = \ $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc \ diff --git a/build.yaml b/build.yaml index 4f02560d077..0725b8ae7bc 100644 --- a/build.yaml +++ b/build.yaml @@ -4354,6 +4354,19 @@ targets: - grpc - gpr_test_util - gpr +- name: codegen_generic_end2end_test + gtest: true + build: test + language: c++ + src: + - test/cpp/end2end/codegen_generic_end2end_test.cc + deps: + - grpc++_test_util + - grpc_test_util + - grpc++ + - grpc + - gpr_test_util + - gpr - name: codegen_test_full gtest: true build: test diff --git a/test/cpp/end2end/codegen_generic_end2end_test.cc b/test/cpp/end2end/codegen_generic_end2end_test.cc new file mode 100644 index 00000000000..f8f8a702a70 --- /dev/null +++ b/test/cpp/end2end/codegen_generic_end2end_test.cc @@ -0,0 +1,454 @@ +/* + * + * Copyright 2015 gRPC authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "src/core/lib/gpr/env.h" +#include "src/core/lib/iomgr/port.h" +#include "src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h" +#include "src/proto/grpc/testing/echo.grpc.pb.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" +#include "test/cpp/util/byte_buffer_proto_helper.h" +#include "test/cpp/util/string_ref_helper.h" + +#include + +using grpc::testing::EchoRequest; +using grpc::testing::EchoResponse; + +namespace grpc { +namespace testing { + +namespace { + +void* tag(int i) { return (void*)static_cast(i); } +int detag(void* p) { return static_cast(reinterpret_cast(p)); } + +class Verifier { + public: + Verifier() : lambda_run_(false) {} + // Expect sets the expected ok value for a specific tag + Verifier& Expect(int i, bool expect_ok) { + return ExpectUnless(i, expect_ok, false); + } + // ExpectUnless sets the expected ok value for a specific tag + // unless the tag was already marked seen (as a result of ExpectMaybe) + Verifier& ExpectUnless(int i, bool expect_ok, bool seen) { + if (!seen) { + expectations_[tag(i)] = expect_ok; + } + return *this; + } + // ExpectMaybe sets the expected ok value for a specific tag, but does not + // require it to appear + // If it does, sets *seen to true + Verifier& ExpectMaybe(int i, bool expect_ok, bool* seen) { + if (!*seen) { + maybe_expectations_[tag(i)] = MaybeExpect{expect_ok, seen}; + } + return *this; + } + + // Next waits for 1 async tag to complete, checks its + // expectations, and returns the tag + int Next(CompletionQueue* cq, bool ignore_ok) { + bool ok; + void* got_tag; + EXPECT_TRUE(cq->Next(&got_tag, &ok)); + GotTag(got_tag, ok, ignore_ok); + return detag(got_tag); + } + + template + CompletionQueue::NextStatus DoOnceThenAsyncNext( + CompletionQueue* cq, void** got_tag, bool* ok, T deadline, + std::function lambda) { + if (lambda_run_) { + return cq->AsyncNext(got_tag, ok, deadline); + } else { + lambda_run_ = true; + return cq->DoThenAsyncNext(lambda, got_tag, ok, deadline); + } + } + + // Verify keeps calling Next until all currently set + // expected tags are complete + void Verify(CompletionQueue* cq) { Verify(cq, false); } + + // This version of Verify allows optionally ignoring the + // outcome of the expectation + void Verify(CompletionQueue* cq, bool ignore_ok) { + GPR_ASSERT(!expectations_.empty() || !maybe_expectations_.empty()); + while (!expectations_.empty()) { + Next(cq, ignore_ok); + } + } + + // This version of Verify stops after a certain deadline + void Verify(CompletionQueue* cq, + std::chrono::system_clock::time_point deadline) { + if (expectations_.empty()) { + bool ok; + void* got_tag; + EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), + CompletionQueue::TIMEOUT); + } else { + while (!expectations_.empty()) { + bool ok; + void* got_tag; + EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), + CompletionQueue::GOT_EVENT); + GotTag(got_tag, ok, false); + } + } + } + + // This version of Verify stops after a certain deadline, and uses the + // DoThenAsyncNext API + // to call the lambda + void Verify(CompletionQueue* cq, + std::chrono::system_clock::time_point deadline, + std::function lambda) { + if (expectations_.empty()) { + bool ok; + void* got_tag; + EXPECT_EQ(DoOnceThenAsyncNext(cq, &got_tag, &ok, deadline, lambda), + CompletionQueue::TIMEOUT); + } else { + while (!expectations_.empty()) { + bool ok; + void* got_tag; + EXPECT_EQ(DoOnceThenAsyncNext(cq, &got_tag, &ok, deadline, lambda), + CompletionQueue::GOT_EVENT); + GotTag(got_tag, ok, false); + } + } + } + + private: + void GotTag(void* got_tag, bool ok, bool ignore_ok) { + auto it = expectations_.find(got_tag); + if (it != expectations_.end()) { + if (!ignore_ok) { + EXPECT_EQ(it->second, ok); + } + expectations_.erase(it); + } else { + auto it2 = maybe_expectations_.find(got_tag); + if (it2 != maybe_expectations_.end()) { + if (it2->second.seen != nullptr) { + EXPECT_FALSE(*it2->second.seen); + *it2->second.seen = true; + } + if (!ignore_ok) { + EXPECT_EQ(it2->second.ok, ok); + } + } else { + gpr_log(GPR_ERROR, "Unexpected tag: %p", tag); + abort(); + } + } + } + + struct MaybeExpect { + bool ok; + bool* seen; + }; + + std::map expectations_; + std::map maybe_expectations_; + bool lambda_run_; +}; + +class CodegenGenericEnd2EndTest : public ::testing::Test { + protected: + CodegenGenericEnd2EndTest() {} + + void SetUp() override { + port_ = grpc_pick_unused_port_or_die(); + server_address_ << "localhost:" << port_; + } + + void TearDown() override { + server_->Shutdown(); + void* ignored_tag; + bool ignored_ok; + cq_->Shutdown(); + while (cq_->Next(&ignored_tag, &ignored_ok)) + ; + stub_.reset(); + grpc_recycle_unused_port(port_); + } + + template + std::unique_ptr BuildAndStartServer() { + ServerBuilder builder; + builder.AddListeningPort(server_address_.str(), + grpc::InsecureServerCredentials()); + std::unique_ptr service(new ServerType()); + builder.RegisterService(service.get()); + cq_ = builder.AddCompletionQueue(); + server_ = builder.BuildAndStart(); + return service; + } + + void ResetStub() { + ChannelArguments args; + std::shared_ptr channel = CreateChannel( + server_address_.str(), grpc::InsecureChannelCredentials()); + stub_ = grpc::testing::EchoTestService::NewStub(channel); + } + + std::unique_ptr cq_; + std::unique_ptr stub_; + std::unique_ptr server_; + std::ostringstream server_address_; + int port_; + + // For the client application to populate and send to server. + EchoRequest send_request_; + ::grpc::ByteBuffer send_request_buffer_; + + // For the server to give to gRPC to be populated by incoming request + // from client. + EchoRequest recv_request_; + ::grpc::ByteBuffer recv_request_buffer_; + + // For the server application to populate and send back to client. + EchoResponse send_response_; + ::grpc::ByteBuffer send_response_buffer_; + + // For the client to give to gRPC to be populated by incoming response + // from server. + EchoResponse recv_response_; + ::grpc::ByteBuffer recv_response_buffer_; + Status recv_status_; + + // Both sides need contexts + ClientContext cli_ctx_; + ServerContext srv_ctx_; +}; + +// Regular Async, both peers use proto +TEST_F(CodegenGenericEnd2EndTest, PureAsyncService) { + typedef grpc::testing::EchoTestService::AsyncService SType; + ResetStub(); + auto service = BuildAndStartServer(); + grpc::ServerAsyncResponseWriter response_writer(&srv_ctx_); + + send_request_.set_message("hello"); + std::unique_ptr> response_reader( + stub_->AsyncEcho(&cli_ctx_, send_request_, cq_.get())); + service->RequestEcho(&srv_ctx_, &recv_request_, &response_writer, cq_.get(), + cq_.get(), tag(2)); + response_reader->Finish(&recv_response_, &recv_status_, tag(4)); + Verifier().Expect(2, true).Verify(cq_.get()); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + send_response_.set_message(recv_request_.message()); + response_writer.Finish(send_response_, Status::OK, tag(3)); + Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); + + EXPECT_EQ(send_response_.message(), recv_response_.message()); + EXPECT_TRUE(recv_status_.ok()); +} + +// Client uses proto, server uses generic codegen, unary +TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerUnary) { + typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_Echo< + grpc::testing::EchoTestService::Service> + SType; + ResetStub(); + auto service = BuildAndStartServer(); + grpc::GenericServerAsyncResponseWriter response_writer(&srv_ctx_); + + send_request_.set_message("hello unary"); + std::unique_ptr> response_reader( + stub_->AsyncEcho(&cli_ctx_, send_request_, cq_.get())); + service->RequestEcho(&srv_ctx_, &recv_request_buffer_, &response_writer, + cq_.get(), cq_.get(), tag(2)); + response_reader->Finish(&recv_response_, &recv_status_, tag(4)); + Verifier().Expect(2, true).Verify(cq_.get()); + EXPECT_TRUE(ParseFromByteBuffer(&recv_request_buffer_, &recv_request_)); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + send_response_.set_message(recv_request_.message()); + EXPECT_TRUE( + SerializeToByteBufferInPlace(&send_response_, &send_response_buffer_)); + response_writer.Finish(send_response_buffer_, Status::OK, tag(3)); + Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); + + EXPECT_EQ(send_response_.message(), recv_response_.message()); + EXPECT_TRUE(recv_status_.ok()); +} + +// Client uses proto, server uses generic codegen, client streaming +TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { + typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_RequestStream< + grpc::testing::EchoTestService::Service> + SType; + ResetStub(); + auto service = BuildAndStartServer(); + + grpc::GenericServerAsyncReader srv_stream(&srv_ctx_); + + send_request_.set_message("hello client streaming"); + std::unique_ptr> cli_stream( + stub_->AsyncRequestStream(&cli_ctx_, &recv_response_, cq_.get(), tag(1))); + + service->RequestRequestStream(&srv_ctx_, &srv_stream, cq_.get(), cq_.get(), + tag(2)); + + Verifier().Expect(2, true).Expect(1, true).Verify(cq_.get()); + + cli_stream->Write(send_request_, tag(3)); + srv_stream.Read(&recv_request_buffer_, tag(4)); + Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); + ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + + cli_stream->Write(send_request_, tag(5)); + srv_stream.Read(&recv_request_buffer_, tag(6)); + Verifier().Expect(5, true).Expect(6, true).Verify(cq_.get()); + + ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + cli_stream->WritesDone(tag(7)); + srv_stream.Read(&recv_request_buffer_, tag(8)); + Verifier().Expect(7, true).Expect(8, false).Verify(cq_.get()); + + ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); + send_response_.set_message(recv_request_.message()); + SerializeToByteBufferInPlace(&send_response_, &send_response_buffer_); + srv_stream.Finish(send_response_buffer_, Status::OK, tag(9)); + cli_stream->Finish(&recv_status_, tag(10)); + Verifier().Expect(9, true).Expect(10, true).Verify(cq_.get()); + + EXPECT_EQ(send_response_.message(), recv_response_.message()); + EXPECT_TRUE(recv_status_.ok()); +} + +// Client uses proto, server uses generic codegen, server streaming +TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerServerStreaming) { + typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_ResponseStream< + grpc::testing::EchoTestService::Service> + SType; + ResetStub(); + auto service = BuildAndStartServer(); + grpc::GenericServerAsyncWriter srv_stream(&srv_ctx_); + + send_request_.set_message("hello server streaming"); + std::unique_ptr> cli_stream( + stub_->AsyncResponseStream(&cli_ctx_, send_request_, cq_.get(), tag(1))); + + service->RequestResponseStream(&srv_ctx_, &recv_request_buffer_, &srv_stream, + cq_.get(), cq_.get(), tag(2)); + + Verifier().Expect(1, true).Expect(2, true).Verify(cq_.get()); + ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + + send_response_.set_message(recv_request_.message()); + SerializeToByteBufferInPlace(&send_response_, &send_response_buffer_); + srv_stream.Write(send_response_buffer_, tag(3)); + cli_stream->Read(&recv_response_, tag(4)); + Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); + EXPECT_EQ(send_response_.message(), recv_response_.message()); + + srv_stream.Write(send_response_buffer_, tag(5)); + cli_stream->Read(&recv_response_, tag(6)); + Verifier().Expect(5, true).Expect(6, true).Verify(cq_.get()); + EXPECT_EQ(send_response_.message(), recv_response_.message()); + + srv_stream.Finish(Status::OK, tag(7)); + cli_stream->Read(&recv_response_, tag(8)); + Verifier().Expect(7, true).Expect(8, false).Verify(cq_.get()); + + cli_stream->Finish(&recv_status_, tag(9)); + Verifier().Expect(9, true).Verify(cq_.get()); + + EXPECT_TRUE(recv_status_.ok()); +} + +// Client uses proto, server uses generic codegen, bidi streaming +TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerBidiStreaming) { + typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_BidiStream< + grpc::testing::EchoTestService::Service> + SType; + ResetStub(); + auto service = BuildAndStartServer(); + + grpc::GenericServerAsyncReaderWriter srv_stream(&srv_ctx_); + + send_request_.set_message("hello bidi streaming"); + std::unique_ptr> + cli_stream(stub_->AsyncBidiStream(&cli_ctx_, cq_.get(), tag(1))); + + service->RequestBidiStream(&srv_ctx_, &srv_stream, cq_.get(), cq_.get(), + tag(2)); + + Verifier().Expect(1, true).Expect(2, true).Verify(cq_.get()); + + cli_stream->Write(send_request_, tag(3)); + srv_stream.Read(&recv_request_buffer_, tag(4)); + Verifier().Expect(3, true).Expect(4, true).Verify(cq_.get()); + ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); + EXPECT_EQ(send_request_.message(), recv_request_.message()); + + send_response_.set_message(recv_request_.message()); + SerializeToByteBufferInPlace(&send_response_, &send_response_buffer_); + srv_stream.Write(send_response_buffer_, tag(5)); + cli_stream->Read(&recv_response_, tag(6)); + Verifier().Expect(5, true).Expect(6, true).Verify(cq_.get()); + EXPECT_EQ(send_response_.message(), recv_response_.message()); + + cli_stream->WritesDone(tag(7)); + srv_stream.Read(&recv_request_buffer_, tag(8)); + Verifier().Expect(7, true).Expect(8, false).Verify(cq_.get()); + + srv_stream.Finish(Status::OK, tag(9)); + cli_stream->Finish(&recv_status_, tag(10)); + Verifier().Expect(9, true).Expect(10, true).Verify(cq_.get()); + + EXPECT_TRUE(recv_status_.ok()); +} + +} // namespace +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + // Change the backup poll interval from 5s to 100ms to speed up the + // ReconnectChannel test + grpc_test_init(argc, argv); + ::testing::InitGoogleTest(&argc, argv); + int ret = RUN_ALL_TESTS(); + return ret; +} diff --git a/test/cpp/util/byte_buffer_proto_helper.cc b/test/cpp/util/byte_buffer_proto_helper.cc index bb5162f86e6..37098955d40 100644 --- a/test/cpp/util/byte_buffer_proto_helper.cc +++ b/test/cpp/util/byte_buffer_proto_helper.cc @@ -40,5 +40,18 @@ std::unique_ptr SerializeToByteBuffer( return std::unique_ptr(new ByteBuffer(&slice, 1)); } +bool SerializeToByteBufferInPlace(grpc::protobuf::Message* message, + ByteBuffer* buffer) { + grpc::string buf; + if (!message->SerializeToString(&buf)) { + return false; + } + buffer->Clear(); + Slice slice(buf); + ByteBuffer tmp(&slice, 1); + buffer->Swap(&tmp); + return true; +} + } // namespace testing } // namespace grpc diff --git a/test/cpp/util/byte_buffer_proto_helper.h b/test/cpp/util/byte_buffer_proto_helper.h index 94603db1100..eb923eccb57 100644 --- a/test/cpp/util/byte_buffer_proto_helper.h +++ b/test/cpp/util/byte_buffer_proto_helper.h @@ -32,6 +32,9 @@ bool ParseFromByteBuffer(ByteBuffer* buffer, grpc::protobuf::Message* message); std::unique_ptr SerializeToByteBuffer( grpc::protobuf::Message* message); +bool SerializeToByteBufferInPlace(grpc::protobuf::Message* message, + ByteBuffer* buffer); + } // namespace testing } // namespace grpc diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 9a9ddd7024f..6870213c46a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3248,6 +3248,25 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++", + "grpc++_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "codegen_generic_end2end_test", + "src": [ + "test/cpp/end2end/codegen_generic_end2end_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 498edbb35d7..3cc0974302e 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3855,6 +3855,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "codegen_generic_end2end_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, From a6194db176cbcf958e77e0bc012981181f05663c Mon Sep 17 00:00:00 2001 From: ncteisen Date: Mon, 18 Jun 2018 18:40:55 -0700 Subject: [PATCH 3/8] Add codegen generic to hybrid tests --- test/cpp/end2end/hybrid_end2end_test.cc | 103 ++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 10e16429e6f..4238c59380a 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -74,6 +74,27 @@ void HandleEcho(Service* service, ServerCompletionQueue* cq, bool dup_service) { Verify(cq, 2, true); } +// Handlers to handle codegen generic request at a server. To be run in a +// separate thread. Note that this is the same as the async version, except +// that the req/resp are ByteBuffers +template +void HandleCodegenGenericEcho(Service* service, ServerCompletionQueue* cq, + bool dup_service) { + ServerContext srv_ctx; + GenericServerAsyncResponseWriter response_writer(&srv_ctx); + ByteBuffer recv_buffer; + service->RequestEcho(&srv_ctx, &recv_buffer, &response_writer, cq, cq, + tag(1)); + Verify(cq, 1, true); + EchoRequest recv_request; + EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request)); + EchoResponse send_response; + send_response.set_message(recv_request.message()); + auto send_buffer = SerializeToByteBuffer(&send_response); + response_writer.Finish(*send_buffer, Status::OK, tag(2)); + Verify(cq, 2, true); +} + template void HandleClientStreaming(Service* service, ServerCompletionQueue* cq) { ServerContext srv_ctx; @@ -92,6 +113,31 @@ void HandleClientStreaming(Service* service, ServerCompletionQueue* cq) { Verify(cq, 100, true); } +template +void HandleCodegenGenericClientStreaming(Service* service, + ServerCompletionQueue* cq) { + ServerContext srv_ctx; + ByteBuffer recv_buffer; + EchoRequest recv_request; + EchoResponse send_response; + GenericServerAsyncReader srv_stream(&srv_ctx); + service->RequestRequestStream(&srv_ctx, &srv_stream, cq, cq, tag(1)); + Verify(cq, 1, true); + int i = 1; + while (true) { + i++; + srv_stream.Read(&recv_buffer, tag(i)); + if (!VerifyReturnSuccess(cq, i)) { + break; + } + EXPECT_TRUE(ParseFromByteBuffer(&recv_buffer, &recv_request)); + send_response.mutable_message()->append(recv_request.message()); + } + auto send_buffer = SerializeToByteBuffer(&send_response); + srv_stream.Finish(*send_buffer, Status::OK, tag(100)); + Verify(cq, 100, true); +} + template void HandleServerStreaming(Service* service, ServerCompletionQueue* cq) { ServerContext srv_ctx; @@ -379,6 +425,63 @@ TEST_F(HybridEnd2endTest, AsyncEcho) { echo_handler_thread.join(); } +TEST_F(HybridEnd2endTest, CodegenGenericEcho) { + typedef EchoTestService::WithCodegenGenericMethod_Echo SType; + SType service; + SetUpServer(&service, nullptr, nullptr); + ResetStub(); + std::thread echo_handler_thread(HandleCodegenGenericEcho, &service, + cqs_[0].get(), false); + TestAllMethods(); + echo_handler_thread.join(); +} + +TEST_F(HybridEnd2endTest, CodegenGenericRequestStream) { + typedef EchoTestService::WithCodegenGenericMethod_RequestStream< + TestServiceImpl> + SType; + SType service; + SetUpServer(&service, nullptr, nullptr); + ResetStub(); + std::thread request_stream_handler_thread( + HandleCodegenGenericClientStreaming, &service, cqs_[0].get()); + TestAllMethods(); + request_stream_handler_thread.join(); +} + +TEST_F(HybridEnd2endTest, AsyncEchoCodegenGenericRequestStream) { + typedef EchoTestService::WithCodegenGenericMethod_RequestStream< + EchoTestService::WithAsyncMethod_Echo> + SType; + SType service; + SetUpServer(&service, nullptr, nullptr); + ResetStub(); + std::thread echo_handler_thread(HandleEcho, &service, cqs_[0].get(), + false); + std::thread request_stream_handler_thread( + HandleCodegenGenericClientStreaming, &service, cqs_[1].get()); + TestAllMethods(); + request_stream_handler_thread.join(); + echo_handler_thread.join(); +} + +TEST_F(HybridEnd2endTest, GenericEchoCodegenGenericRequestStream) { + typedef EchoTestService::WithCodegenGenericMethod_RequestStream< + EchoTestService::WithGenericMethod_Echo> + SType; + SType service; + AsyncGenericService generic_service; + SetUpServer(&service, nullptr, &generic_service); + ResetStub(); + std::thread generic_handler_thread(HandleGenericCall, &generic_service, + cqs_[0].get()); + std::thread request_stream_handler_thread( + HandleCodegenGenericClientStreaming, &service, cqs_[1].get()); + TestAllMethods(); + generic_handler_thread.join(); + request_stream_handler_thread.join(); +} + TEST_F(HybridEnd2endTest, AsyncEchoRequestStream) { typedef EchoTestService::WithAsyncMethod_RequestStream< EchoTestService::WithAsyncMethod_Echo> From d170b83e0d29b93d3de7c508281cfeae38ae141e Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 19 Jun 2018 08:11:13 -0700 Subject: [PATCH 4/8] Allow AsyncServer with one generic to compile --- .../grpcpp/impl/codegen/rpc_service_method.h | 45 ++++++++++++++++++- include/grpcpp/impl/codegen/service_type.h | 30 ++++++++----- test/cpp/codegen/compiler_test_golden | 2 +- .../end2end/codegen_generic_end2end_test.cc | 29 ++++++++---- 4 files changed, 84 insertions(+), 22 deletions(-) diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h index 1b4e57d80ce..c38ea2b0625 100644 --- a/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/include/grpcpp/impl/codegen/rpc_service_method.h @@ -31,6 +31,8 @@ #include #include +#include + namespace grpc { class ServerContext; @@ -59,18 +61,57 @@ class RpcServiceMethod : public RpcMethod { /// Takes ownership of the handler RpcServiceMethod(const char* name, RpcMethod::RpcType type, MethodHandler* handler) - : RpcMethod(name, type), server_tag_(nullptr), handler_(handler) {} + : RpcMethod(name, type), + server_tag_(nullptr), + async_type_(AsyncType::UNSET), + handler_(handler) {} + + enum class AsyncType { + UNSET, + ASYNC, + CODEGEN_GENERIC, + }; void set_server_tag(void* tag) { server_tag_ = tag; } void* server_tag() const { return server_tag_; } /// if MethodHandler is nullptr, then this is an async method MethodHandler* handler() const { return handler_.get(); } - void ResetHandler() { handler_.reset(); } void SetHandler(MethodHandler* handler) { handler_.reset(handler); } + void SetServerAsyncType(RpcServiceMethod::AsyncType type) { + if (async_type_ == AsyncType::UNSET) { + // this marks this method as async + handler_.reset(); + } else { + // this is not an error condition, as it allows users to declare a server + // like WithCodegenGenericMethod_foo. However since it + // overwrites behavior, it should be logged. + gpr_log( + GPR_INFO, + "You are marking method %s as '%s', even though it was " + "previously marked '%s'. This behavior will overwrite the original " + "behavior. If you expected this then ignore this message.", + name(), TypeToString(async_type_), TypeToString(type)); + } + async_type_ = type; + } private: void* server_tag_; + RpcServiceMethod::AsyncType async_type_; std::unique_ptr handler_; + + const char* TypeToString(RpcServiceMethod::AsyncType type) { + switch (type) { + case AsyncType::UNSET: + return "unset"; + case AsyncType::ASYNC: + return "async"; + case AsyncType::CODEGEN_GENERIC: + return "codegen generic"; + default: + GPR_UNREACHABLE_CODE(return "unknown"); + } + } }; } // namespace internal diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h index af94d653f07..dc63b9dc21c 100644 --- a/include/grpcpp/impl/codegen/service_type.h +++ b/include/grpcpp/impl/codegen/service_type.h @@ -124,30 +124,40 @@ class Service { } void MarkMethodAsync(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. GPR_CODEGEN_ASSERT( methods_[index].get() != nullptr && "Cannot mark the method as 'async' because it has already been " "marked as 'generic'."); - methods_[index]->ResetHandler(); + methods_[index]->SetServerAsyncType( + internal::RpcServiceMethod::AsyncType::ASYNC); + } + + void MarkMethodCodegenGeneric(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. + GPR_CODEGEN_ASSERT( + methods_[index].get() != nullptr && + "Cannot mark the method as 'codegen generic' because it has already " + "been marked as 'generic'."); + methods_[index]->SetServerAsyncType( + internal::RpcServiceMethod::AsyncType::CODEGEN_GENERIC); } void MarkMethodGeneric(int index) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. GPR_CODEGEN_ASSERT( methods_[index]->handler() != nullptr && "Cannot mark the method as 'generic' because it has already been " - "marked as 'async'."); + "marked as 'async' or 'codegen generic'."); methods_[index].reset(); } - void MarkMethodCodegenGeneric(int index) { - GPR_CODEGEN_ASSERT(methods_[index]->handler() != nullptr && - "Cannot mark the method as 'codegen generic' because it " - "has already been " - "marked as 'async' or 'generic'."); - methods_[index]->ResetHandler(); - } - void MarkMethodStreamed(int index, internal::MethodHandler* streamed_method) { + // This does not have to be a hard error, however no one has approached us + // with a use case yet. Please file an issue if you believe you have one. GPR_CODEGEN_ASSERT(methods_[index] && methods_[index]->handler() && "Cannot mark an async or generic method Streamed"); methods_[index]->SetHandler(streamed_method); diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index 033c963dc4a..90dabb5cb74 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -26,7 +26,7 @@ #include "src/proto/grpc/testing/compiler_test.pb.h" -#include +#include #include #include #include diff --git a/test/cpp/end2end/codegen_generic_end2end_test.cc b/test/cpp/end2end/codegen_generic_end2end_test.cc index f8f8a702a70..6bb5712eb26 100644 --- a/test/cpp/end2end/codegen_generic_end2end_test.cc +++ b/test/cpp/end2end/codegen_generic_end2end_test.cc @@ -311,9 +311,10 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerUnary) { // Client uses proto, server uses generic codegen, client streaming TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { - typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_RequestStream< - grpc::testing::EchoTestService::Service> - SType; + typedef grpc::testing::EchoTestService:: + WithCodegenGenericMethod_RequestStream< + grpc::testing::EchoTestService::Service> + SType; ResetStub(); auto service = BuildAndStartServer(); @@ -324,7 +325,7 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { stub_->AsyncRequestStream(&cli_ctx_, &recv_response_, cq_.get(), tag(1))); service->RequestRequestStream(&srv_ctx_, &srv_stream, cq_.get(), cq_.get(), - tag(2)); + tag(2)); Verifier().Expect(2, true).Expect(1, true).Verify(cq_.get()); @@ -357,9 +358,10 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { // Client uses proto, server uses generic codegen, server streaming TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerServerStreaming) { - typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_ResponseStream< - grpc::testing::EchoTestService::Service> - SType; + typedef grpc::testing::EchoTestService:: + WithCodegenGenericMethod_ResponseStream< + grpc::testing::EchoTestService::Service> + SType; ResetStub(); auto service = BuildAndStartServer(); grpc::GenericServerAsyncWriter srv_stream(&srv_ctx_); @@ -369,7 +371,7 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerServerStreaming) { stub_->AsyncResponseStream(&cli_ctx_, send_request_, cq_.get(), tag(1))); service->RequestResponseStream(&srv_ctx_, &recv_request_buffer_, &srv_stream, - cq_.get(), cq_.get(), tag(2)); + cq_.get(), cq_.get(), tag(2)); Verifier().Expect(1, true).Expect(2, true).Verify(cq_.get()); ParseFromByteBuffer(&recv_request_buffer_, &recv_request_); @@ -412,7 +414,7 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerBidiStreaming) { cli_stream(stub_->AsyncBidiStream(&cli_ctx_, cq_.get(), tag(1))); service->RequestBidiStream(&srv_ctx_, &srv_stream, cq_.get(), cq_.get(), - tag(2)); + tag(2)); Verifier().Expect(1, true).Expect(2, true).Verify(cq_.get()); @@ -440,6 +442,15 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerBidiStreaming) { EXPECT_TRUE(recv_status_.ok()); } +// Testing that this pattern compiles +TEST_F(CodegenGenericEnd2EndTest, CompileTest) { + typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_Echo< + grpc::testing::EchoTestService::AsyncService> + SType; + ResetStub(); + auto service = BuildAndStartServer(); +} + } // namespace } // namespace testing } // namespace grpc From 9e26b6c282e737c43cbdc5c8e4fd1857859a1625 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 19 Jun 2018 13:51:28 -0700 Subject: [PATCH 5/8] Regenerate project and fix sanity --- CMakeLists.txt | 1 + include/grpc/support/log.h | 2 ++ tools/run_tests/generated/sources_and_headers.json | 8 ++++---- tools/run_tests/generated/tests.json | 4 ++-- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 796dcd6eb80..b0e5da8b0fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11155,6 +11155,7 @@ target_include_directories(codegen_generic_end2end_test PRIVATE ${_gRPC_CARES_INCLUDE_DIR} PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR} PRIVATE third_party/googletest/googletest/include PRIVATE third_party/googletest/googletest PRIVATE third_party/googletest/googlemock/include diff --git a/include/grpc/support/log.h b/include/grpc/support/log.h index cdf1886084f..8d8742b95d6 100644 --- a/include/grpc/support/log.h +++ b/include/grpc/support/log.h @@ -19,6 +19,8 @@ #ifndef GRPC_SUPPORT_LOG_H #define GRPC_SUPPORT_LOG_H +#include + #include #endif /* GRPC_SUPPORT_LOG_H */ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 6870213c46a..ded1589ea26 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3260,9 +3260,9 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "codegen_generic_end2end_test", + "name": "client_lb_end2end_test", "src": [ - "test/cpp/end2end/codegen_generic_end2end_test.cc" + "test/cpp/end2end/client_lb_end2end_test.cc" ], "third_party": false, "type": "target" @@ -3279,9 +3279,9 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "client_lb_end2end_test", + "name": "codegen_generic_end2end_test", "src": [ - "test/cpp/end2end/client_lb_end2end_test.cc" + "test/cpp/end2end/codegen_generic_end2end_test.cc" ], "third_party": false, "type": "target" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 3cc0974302e..cb0fb34f4c0 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3870,7 +3870,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "codegen_generic_end2end_test", + "name": "client_lb_end2end_test", "platforms": [ "linux", "mac", @@ -3894,7 +3894,7 @@ "flaky": false, "gtest": true, "language": "c++", - "name": "client_lb_end2end_test", + "name": "codegen_generic_end2end_test", "platforms": [ "linux", "mac", From 0d878eae6cedf32e6e77e02f4c29ec232b41eb63 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 19 Jun 2018 15:51:23 -0700 Subject: [PATCH 6/8] Fix build --- include/grpcpp/impl/codegen/rpc_service_method.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h index c38ea2b0625..0f26cbe4853 100644 --- a/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/include/grpcpp/impl/codegen/rpc_service_method.h @@ -31,8 +31,6 @@ #include #include -#include - namespace grpc { class ServerContext; From a0a59537d2a8d25124cc1fe21cee10713012bceb Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 28 Jun 2018 18:26:22 -0700 Subject: [PATCH 7/8] s/CodegenGeneric/Raw/g --- CMakeLists.txt | 82 ++++++++-------- Makefile | 96 +++++++++---------- build.yaml | 26 ++--- .../grpcpp/impl/codegen/rpc_service_method.h | 8 +- include/grpcpp/impl/codegen/service_type.h | 13 ++- src/compiler/cpp_generator.cc | 24 +++-- test/cpp/codegen/compiler_test_golden | 40 ++++---- test/cpp/end2end/BUILD | 20 ++++ test/cpp/end2end/hybrid_end2end_test.cc | 43 ++++----- ...ic_end2end_test.cc => raw_end2end_test.cc} | 36 ++++--- .../generated/sources_and_headers.json | 38 ++++---- tools/run_tests/generated/tests.json | 48 +++++----- 12 files changed, 243 insertions(+), 231 deletions(-) rename test/cpp/end2end/{codegen_generic_end2end_test.cc => raw_end2end_test.cc} (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index b95023f6ed9..2bce42c85b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -559,7 +559,6 @@ add_dependencies(buildtests_cxx client_crash_test) endif() add_dependencies(buildtests_cxx client_crash_test_server) add_dependencies(buildtests_cxx client_lb_end2end_test) -add_dependencies(buildtests_cxx codegen_generic_end2end_test) add_dependencies(buildtests_cxx codegen_test_full) add_dependencies(buildtests_cxx codegen_test_minimal) add_dependencies(buildtests_cxx credentials_test) @@ -617,6 +616,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_dependencies(buildtests_cxx qps_openloop_test) endif() add_dependencies(buildtests_cxx qps_worker) +add_dependencies(buildtests_cxx raw_end2end_test) add_dependencies(buildtests_cxx reconnect_interop_client) add_dependencies(buildtests_cxx reconnect_interop_server) add_dependencies(buildtests_cxx ref_counted_ptr_test) @@ -11225,46 +11225,6 @@ target_link_libraries(client_lb_end2end_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(codegen_generic_end2end_test - test/cpp/end2end/codegen_generic_end2end_test.cc - third_party/googletest/googletest/src/gtest-all.cc - third_party/googletest/googlemock/src/gmock-all.cc -) - - -target_include_directories(codegen_generic_end2end_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${_gRPC_SSL_INCLUDE_DIR} - PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} - PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} - PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} - PRIVATE ${_gRPC_CARES_INCLUDE_DIR} - PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} - PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} - PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR} - PRIVATE third_party/googletest/googletest/include - PRIVATE third_party/googletest/googletest - PRIVATE third_party/googletest/googlemock/include - PRIVATE third_party/googletest/googlemock - PRIVATE ${_gRPC_PROTO_GENS_DIR} -) - -target_link_libraries(codegen_generic_end2end_test - ${_gRPC_PROTOBUF_LIBRARIES} - ${_gRPC_ALLTARGETS_LIBRARIES} - grpc++_test_util - grpc_test_util - grpc++ - grpc - gpr_test_util - gpr - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(codegen_test_full ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.grpc.pb.cc @@ -13314,6 +13274,46 @@ target_link_libraries(qps_worker endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(raw_end2end_test + test/cpp/end2end/raw_end2end_test.cc + third_party/googletest/googletest/src/gtest-all.cc + third_party/googletest/googlemock/src/gmock-all.cc +) + + +target_include_directories(raw_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${_gRPC_SSL_INCLUDE_DIR} + PRIVATE ${_gRPC_PROTOBUF_INCLUDE_DIR} + PRIVATE ${_gRPC_ZLIB_INCLUDE_DIR} + PRIVATE ${_gRPC_BENCHMARK_INCLUDE_DIR} + PRIVATE ${_gRPC_CARES_INCLUDE_DIR} + PRIVATE ${_gRPC_GFLAGS_INCLUDE_DIR} + PRIVATE ${_gRPC_ADDRESS_SORTING_INCLUDE_DIR} + PRIVATE ${_gRPC_NANOPB_INCLUDE_DIR} + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest + PRIVATE third_party/googletest/googlemock/include + PRIVATE third_party/googletest/googlemock + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(raw_end2end_test + ${_gRPC_PROTOBUF_LIBRARIES} + ${_gRPC_ALLTARGETS_LIBRARIES} + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(reconnect_interop_client ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc diff --git a/Makefile b/Makefile index 9a41d12f05e..bbaa3e79e51 100644 --- a/Makefile +++ b/Makefile @@ -1151,7 +1151,6 @@ client_channel_stress_test: $(BINDIR)/$(CONFIG)/client_channel_stress_test client_crash_test: $(BINDIR)/$(CONFIG)/client_crash_test client_crash_test_server: $(BINDIR)/$(CONFIG)/client_crash_test_server client_lb_end2end_test: $(BINDIR)/$(CONFIG)/client_lb_end2end_test -codegen_generic_end2end_test: $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test codegen_test_full: $(BINDIR)/$(CONFIG)/codegen_test_full codegen_test_minimal: $(BINDIR)/$(CONFIG)/codegen_test_minimal credentials_test: $(BINDIR)/$(CONFIG)/credentials_test @@ -1200,6 +1199,7 @@ qps_interarrival_test: $(BINDIR)/$(CONFIG)/qps_interarrival_test qps_json_driver: $(BINDIR)/$(CONFIG)/qps_json_driver qps_openloop_test: $(BINDIR)/$(CONFIG)/qps_openloop_test qps_worker: $(BINDIR)/$(CONFIG)/qps_worker +raw_end2end_test: $(BINDIR)/$(CONFIG)/raw_end2end_test reconnect_interop_client: $(BINDIR)/$(CONFIG)/reconnect_interop_client reconnect_interop_server: $(BINDIR)/$(CONFIG)/reconnect_interop_server ref_counted_ptr_test: $(BINDIR)/$(CONFIG)/ref_counted_ptr_test @@ -1647,7 +1647,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/client_crash_test \ $(BINDIR)/$(CONFIG)/client_crash_test_server \ $(BINDIR)/$(CONFIG)/client_lb_end2end_test \ - $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test \ $(BINDIR)/$(CONFIG)/codegen_test_full \ $(BINDIR)/$(CONFIG)/codegen_test_minimal \ $(BINDIR)/$(CONFIG)/credentials_test \ @@ -1689,6 +1688,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/qps_json_driver \ $(BINDIR)/$(CONFIG)/qps_openloop_test \ $(BINDIR)/$(CONFIG)/qps_worker \ + $(BINDIR)/$(CONFIG)/raw_end2end_test \ $(BINDIR)/$(CONFIG)/reconnect_interop_client \ $(BINDIR)/$(CONFIG)/reconnect_interop_server \ $(BINDIR)/$(CONFIG)/ref_counted_ptr_test \ @@ -1825,7 +1825,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/client_crash_test \ $(BINDIR)/$(CONFIG)/client_crash_test_server \ $(BINDIR)/$(CONFIG)/client_lb_end2end_test \ - $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test \ $(BINDIR)/$(CONFIG)/codegen_test_full \ $(BINDIR)/$(CONFIG)/codegen_test_minimal \ $(BINDIR)/$(CONFIG)/credentials_test \ @@ -1867,6 +1866,7 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/qps_json_driver \ $(BINDIR)/$(CONFIG)/qps_openloop_test \ $(BINDIR)/$(CONFIG)/qps_worker \ + $(BINDIR)/$(CONFIG)/raw_end2end_test \ $(BINDIR)/$(CONFIG)/reconnect_interop_client \ $(BINDIR)/$(CONFIG)/reconnect_interop_server \ $(BINDIR)/$(CONFIG)/ref_counted_ptr_test \ @@ -2275,8 +2275,6 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/client_crash_test || ( echo test client_crash_test failed ; exit 1 ) $(E) "[RUN] Testing client_lb_end2end_test" $(Q) $(BINDIR)/$(CONFIG)/client_lb_end2end_test || ( echo test client_lb_end2end_test failed ; exit 1 ) - $(E) "[RUN] Testing codegen_generic_end2end_test" - $(Q) $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test || ( echo test codegen_generic_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing codegen_test_full" $(Q) $(BINDIR)/$(CONFIG)/codegen_test_full || ( echo test codegen_test_full failed ; exit 1 ) $(E) "[RUN] Testing codegen_test_minimal" @@ -2339,6 +2337,8 @@ test_cxx: buildtests_cxx $(Q) $(BINDIR)/$(CONFIG)/proto_utils_test || ( echo test proto_utils_test failed ; exit 1 ) $(E) "[RUN] Testing qps_openloop_test" $(Q) $(BINDIR)/$(CONFIG)/qps_openloop_test || ( echo test qps_openloop_test failed ; exit 1 ) + $(E) "[RUN] Testing raw_end2end_test" + $(Q) $(BINDIR)/$(CONFIG)/raw_end2end_test || ( echo test raw_end2end_test failed ; exit 1 ) $(E) "[RUN] Testing ref_counted_ptr_test" $(Q) $(BINDIR)/$(CONFIG)/ref_counted_ptr_test || ( echo test ref_counted_ptr_test failed ; exit 1 ) $(E) "[RUN] Testing ref_counted_test" @@ -16943,49 +16943,6 @@ endif endif -CODEGEN_GENERIC_END2END_TEST_SRC = \ - test/cpp/end2end/codegen_generic_end2end_test.cc \ - -CODEGEN_GENERIC_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CODEGEN_GENERIC_END2END_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: openssl_dep_error - -else - - - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. - -$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/codegen_generic_end2end_test: $(PROTOBUF_DEP) $(CODEGEN_GENERIC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(CODEGEN_GENERIC_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/codegen_generic_end2end_test - -endif - -endif - -$(OBJDIR)/$(CONFIG)/test/cpp/end2end/codegen_generic_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_codegen_generic_end2end_test: $(CODEGEN_GENERIC_END2END_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(CODEGEN_GENERIC_END2END_TEST_OBJS:.o=.dep) -endif -endif - - CODEGEN_TEST_FULL_SRC = \ $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc \ @@ -19006,6 +18963,49 @@ endif endif +RAW_END2END_TEST_SRC = \ + test/cpp/end2end/raw_end2end_test.cc \ + +RAW_END2END_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(RAW_END2END_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/raw_end2end_test: openssl_dep_error + +else + + + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.5.0+. + +$(BINDIR)/$(CONFIG)/raw_end2end_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/raw_end2end_test: $(PROTOBUF_DEP) $(RAW_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(RAW_END2END_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(LDLIBS_SECURE) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/raw_end2end_test + +endif + +endif + +$(OBJDIR)/$(CONFIG)/test/cpp/end2end/raw_end2end_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_raw_end2end_test: $(RAW_END2END_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(RAW_END2END_TEST_OBJS:.o=.dep) +endif +endif + + RECONNECT_INTEROP_CLIENT_SRC = \ $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc \ diff --git a/build.yaml b/build.yaml index c22c9e04aa6..77d0ca32672 100644 --- a/build.yaml +++ b/build.yaml @@ -4422,19 +4422,6 @@ targets: - grpc - gpr_test_util - gpr -- name: codegen_generic_end2end_test - gtest: true - build: test - language: c++ - src: - - test/cpp/end2end/codegen_generic_end2end_test.cc - deps: - - grpc++_test_util - - grpc_test_util - - grpc++ - - grpc - - gpr_test_util - - gpr - name: codegen_test_full gtest: true build: test @@ -5111,6 +5098,19 @@ targets: - gpr_test_util - gpr - grpc++_test_config +- name: raw_end2end_test + gtest: true + build: test + language: c++ + src: + - test/cpp/end2end/raw_end2end_test.cc + deps: + - grpc++_test_util + - grpc_test_util + - grpc++ + - grpc + - gpr_test_util + - gpr - name: reconnect_interop_client build: test run: false diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h index 0f26cbe4853..92c66bbf15b 100644 --- a/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/include/grpcpp/impl/codegen/rpc_service_method.h @@ -67,7 +67,7 @@ class RpcServiceMethod : public RpcMethod { enum class AsyncType { UNSET, ASYNC, - CODEGEN_GENERIC, + RAW, }; void set_server_tag(void* tag) { server_tag_ = tag; } @@ -81,7 +81,7 @@ class RpcServiceMethod : public RpcMethod { handler_.reset(); } else { // this is not an error condition, as it allows users to declare a server - // like WithCodegenGenericMethod_foo. However since it + // like WithRawMethod_foo. However since it // overwrites behavior, it should be logged. gpr_log( GPR_INFO, @@ -104,8 +104,8 @@ class RpcServiceMethod : public RpcMethod { return "unset"; case AsyncType::ASYNC: return "async"; - case AsyncType::CODEGEN_GENERIC: - return "codegen generic"; + case AsyncType::RAW: + return "raw"; default: GPR_UNREACHABLE_CODE(return "unknown"); } diff --git a/include/grpcpp/impl/codegen/service_type.h b/include/grpcpp/impl/codegen/service_type.h index dc63b9dc21c..a0bbd659e28 100644 --- a/include/grpcpp/impl/codegen/service_type.h +++ b/include/grpcpp/impl/codegen/service_type.h @@ -134,15 +134,14 @@ class Service { internal::RpcServiceMethod::AsyncType::ASYNC); } - void MarkMethodCodegenGeneric(int index) { + void MarkMethodRaw(int index) { // This does not have to be a hard error, however no one has approached us // with a use case yet. Please file an issue if you believe you have one. - GPR_CODEGEN_ASSERT( - methods_[index].get() != nullptr && - "Cannot mark the method as 'codegen generic' because it has already " - "been marked as 'generic'."); + GPR_CODEGEN_ASSERT(methods_[index].get() != nullptr && + "Cannot mark the method as 'raw' because it has already " + "been marked as 'generic'."); methods_[index]->SetServerAsyncType( - internal::RpcServiceMethod::AsyncType::CODEGEN_GENERIC); + internal::RpcServiceMethod::AsyncType::RAW); } void MarkMethodGeneric(int index) { @@ -151,7 +150,7 @@ class Service { GPR_CODEGEN_ASSERT( methods_[index]->handler() != nullptr && "Cannot mark the method as 'generic' because it has already been " - "marked as 'async' or 'codegen generic'."); + "marked as 'async' or 'raw'."); methods_[index].reset(); } diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index f01f279a44e..1e0c36451bb 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -591,7 +591,7 @@ void PrintHeaderServerMethodSync(grpc_generator::Printer* printer, // Helper generator. Disabled the sync API for Request and Response, then adds // in an async API for RealRequest and RealResponse types. This is to be used -// to generate async and codegen generic APIs. +// to generate async and raw APIs. void PrintHeaderServerAsyncMethodsHelper( grpc_generator::Printer* printer, const grpc_generator::Method* method, std::map* vars) { @@ -892,30 +892,29 @@ void PrintHeaderServerMethodGeneric( printer->Print(*vars, "};\n"); } -void PrintHeaderServerMethodCodegenGeneric( - grpc_generator::Printer* printer, const grpc_generator::Method* method, - std::map* vars) { +void PrintHeaderServerMethodRaw(grpc_generator::Printer* printer, + const grpc_generator::Method* method, + std::map* vars) { (*vars)["Method"] = method->name(); // These will be disabled (*vars)["Request"] = method->input_type_name(); (*vars)["Response"] = method->output_type_name(); - // These will be used for codegen generic API + // These will be used for raw API (*vars)["RealRequest"] = "::grpc::ByteBuffer"; (*vars)["RealResponse"] = "::grpc::ByteBuffer"; printer->Print(*vars, "template \n"); - printer->Print( - *vars, "class WithCodegenGenericMethod_$Method$ : public BaseClass {\n"); + printer->Print(*vars, "class WithRawMethod_$Method$ : public BaseClass {\n"); printer->Print( " private:\n" " void BaseClassMustBeDerivedFromService(const Service *service) {}\n"); printer->Print(" public:\n"); printer->Indent(); printer->Print(*vars, - "WithCodegenGenericMethod_$Method$() {\n" - " ::grpc::Service::MarkMethodCodegenGeneric($Idx$);\n" + "WithRawMethod_$Method$() {\n" + " ::grpc::Service::MarkMethodRaw($Idx$);\n" "}\n"); printer->Print(*vars, - "~WithCodegenGenericMethod_$Method$() override {\n" + "~WithRawMethod_$Method$() override {\n" " BaseClassMustBeDerivedFromService(this);\n" "}\n"); PrintHeaderServerAsyncMethodsHelper(printer, method, vars); @@ -1027,11 +1026,10 @@ void PrintHeaderService(grpc_generator::Printer* printer, PrintHeaderServerMethodGeneric(printer, service->method(i).get(), vars); } - // Server side - CodegenGeneric + // Server side - Raw for (int i = 0; i < service->method_count(); ++i) { (*vars)["Idx"] = as_string(i); - PrintHeaderServerMethodCodegenGeneric(printer, service->method(i).get(), - vars); + PrintHeaderServerMethodRaw(printer, service->method(i).get(), vars); } // Server side - Streamed Unary diff --git a/test/cpp/codegen/compiler_test_golden b/test/cpp/codegen/compiler_test_golden index 90dabb5cb74..756f6a0224c 100644 --- a/test/cpp/codegen/compiler_test_golden +++ b/test/cpp/codegen/compiler_test_golden @@ -346,14 +346,14 @@ class ServiceA final { } }; template - class WithCodegenGenericMethod_MethodA1 : public BaseClass { + class WithRawMethod_MethodA1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} public: - WithCodegenGenericMethod_MethodA1() { - ::grpc::Service::MarkMethodCodegenGeneric(0); + WithRawMethod_MethodA1() { + ::grpc::Service::MarkMethodRaw(0); } - ~WithCodegenGenericMethod_MethodA1() override { + ~WithRawMethod_MethodA1() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method @@ -366,14 +366,14 @@ class ServiceA final { } }; template - class WithCodegenGenericMethod_MethodA2 : public BaseClass { + class WithRawMethod_MethodA2 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} public: - WithCodegenGenericMethod_MethodA2() { - ::grpc::Service::MarkMethodCodegenGeneric(1); + WithRawMethod_MethodA2() { + ::grpc::Service::MarkMethodRaw(1); } - ~WithCodegenGenericMethod_MethodA2() override { + ~WithRawMethod_MethodA2() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method @@ -386,14 +386,14 @@ class ServiceA final { } }; template - class WithCodegenGenericMethod_MethodA3 : public BaseClass { + class WithRawMethod_MethodA3 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} public: - WithCodegenGenericMethod_MethodA3() { - ::grpc::Service::MarkMethodCodegenGeneric(2); + WithRawMethod_MethodA3() { + ::grpc::Service::MarkMethodRaw(2); } - ~WithCodegenGenericMethod_MethodA3() override { + ~WithRawMethod_MethodA3() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method @@ -406,14 +406,14 @@ class ServiceA final { } }; template - class WithCodegenGenericMethod_MethodA4 : public BaseClass { + class WithRawMethod_MethodA4 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} public: - WithCodegenGenericMethod_MethodA4() { - ::grpc::Service::MarkMethodCodegenGeneric(3); + WithRawMethod_MethodA4() { + ::grpc::Service::MarkMethodRaw(3); } - ~WithCodegenGenericMethod_MethodA4() override { + ~WithRawMethod_MethodA4() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method @@ -558,14 +558,14 @@ class ServiceB final { } }; template - class WithCodegenGenericMethod_MethodB1 : public BaseClass { + class WithRawMethod_MethodB1 : public BaseClass { private: void BaseClassMustBeDerivedFromService(const Service *service) {} public: - WithCodegenGenericMethod_MethodB1() { - ::grpc::Service::MarkMethodCodegenGeneric(0); + WithRawMethod_MethodB1() { + ::grpc::Service::MarkMethodRaw(0); } - ~WithCodegenGenericMethod_MethodB1() override { + ~WithRawMethod_MethodB1() override { BaseClassMustBeDerivedFromService(this); } // disable synchronous version of this method diff --git a/test/cpp/end2end/BUILD b/test/cpp/end2end/BUILD index 8ab0811ffaf..23dde69dd0a 100644 --- a/test/cpp/end2end/BUILD +++ b/test/cpp/end2end/BUILD @@ -241,6 +241,26 @@ grpc_cc_test( ], ) +grpc_cc_test( + name = "raw_end2end_test", + srcs = ["raw_end2end_test.cc"], + external_deps = [ + "gtest", + ], + deps = [ + ":test_service_impl", + "//:gpr", + "//:grpc", + "//:grpc++", + "//src/proto/grpc/testing:echo_messages_proto", + "//src/proto/grpc/testing:echo_proto", + "//src/proto/grpc/testing/duplicate:echo_duplicate_proto", + "//test/core/util:gpr_test_util", + "//test/core/util:grpc_test_util", + "//test/cpp/util:test_util", + ], +) + grpc_cc_test( name = "mock_test", srcs = ["mock_test.cc"], diff --git a/test/cpp/end2end/hybrid_end2end_test.cc b/test/cpp/end2end/hybrid_end2end_test.cc index 4238c59380a..339eadde92e 100644 --- a/test/cpp/end2end/hybrid_end2end_test.cc +++ b/test/cpp/end2end/hybrid_end2end_test.cc @@ -74,12 +74,12 @@ void HandleEcho(Service* service, ServerCompletionQueue* cq, bool dup_service) { Verify(cq, 2, true); } -// Handlers to handle codegen generic request at a server. To be run in a +// Handlers to handle raw request at a server. To be run in a // separate thread. Note that this is the same as the async version, except // that the req/resp are ByteBuffers template -void HandleCodegenGenericEcho(Service* service, ServerCompletionQueue* cq, - bool dup_service) { +void HandleRawEcho(Service* service, ServerCompletionQueue* cq, + bool dup_service) { ServerContext srv_ctx; GenericServerAsyncResponseWriter response_writer(&srv_ctx); ByteBuffer recv_buffer; @@ -114,8 +114,7 @@ void HandleClientStreaming(Service* service, ServerCompletionQueue* cq) { } template -void HandleCodegenGenericClientStreaming(Service* service, - ServerCompletionQueue* cq) { +void HandleRawClientStreaming(Service* service, ServerCompletionQueue* cq) { ServerContext srv_ctx; ByteBuffer recv_buffer; EchoRequest recv_request; @@ -425,32 +424,30 @@ TEST_F(HybridEnd2endTest, AsyncEcho) { echo_handler_thread.join(); } -TEST_F(HybridEnd2endTest, CodegenGenericEcho) { - typedef EchoTestService::WithCodegenGenericMethod_Echo SType; +TEST_F(HybridEnd2endTest, RawEcho) { + typedef EchoTestService::WithRawMethod_Echo SType; SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread echo_handler_thread(HandleCodegenGenericEcho, &service, - cqs_[0].get(), false); + std::thread echo_handler_thread(HandleRawEcho, &service, cqs_[0].get(), + false); TestAllMethods(); echo_handler_thread.join(); } -TEST_F(HybridEnd2endTest, CodegenGenericRequestStream) { - typedef EchoTestService::WithCodegenGenericMethod_RequestStream< - TestServiceImpl> - SType; +TEST_F(HybridEnd2endTest, RawRequestStream) { + typedef EchoTestService::WithRawMethod_RequestStream SType; SType service; SetUpServer(&service, nullptr, nullptr); ResetStub(); - std::thread request_stream_handler_thread( - HandleCodegenGenericClientStreaming, &service, cqs_[0].get()); + std::thread request_stream_handler_thread(HandleRawClientStreaming, + &service, cqs_[0].get()); TestAllMethods(); request_stream_handler_thread.join(); } -TEST_F(HybridEnd2endTest, AsyncEchoCodegenGenericRequestStream) { - typedef EchoTestService::WithCodegenGenericMethod_RequestStream< +TEST_F(HybridEnd2endTest, AsyncEchoRawRequestStream) { + typedef EchoTestService::WithRawMethod_RequestStream< EchoTestService::WithAsyncMethod_Echo> SType; SType service; @@ -458,15 +455,15 @@ TEST_F(HybridEnd2endTest, AsyncEchoCodegenGenericRequestStream) { ResetStub(); std::thread echo_handler_thread(HandleEcho, &service, cqs_[0].get(), false); - std::thread request_stream_handler_thread( - HandleCodegenGenericClientStreaming, &service, cqs_[1].get()); + std::thread request_stream_handler_thread(HandleRawClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); request_stream_handler_thread.join(); echo_handler_thread.join(); } -TEST_F(HybridEnd2endTest, GenericEchoCodegenGenericRequestStream) { - typedef EchoTestService::WithCodegenGenericMethod_RequestStream< +TEST_F(HybridEnd2endTest, GenericEchoRawRequestStream) { + typedef EchoTestService::WithRawMethod_RequestStream< EchoTestService::WithGenericMethod_Echo> SType; SType service; @@ -475,8 +472,8 @@ TEST_F(HybridEnd2endTest, GenericEchoCodegenGenericRequestStream) { ResetStub(); std::thread generic_handler_thread(HandleGenericCall, &generic_service, cqs_[0].get()); - std::thread request_stream_handler_thread( - HandleCodegenGenericClientStreaming, &service, cqs_[1].get()); + std::thread request_stream_handler_thread(HandleRawClientStreaming, + &service, cqs_[1].get()); TestAllMethods(); generic_handler_thread.join(); request_stream_handler_thread.join(); diff --git a/test/cpp/end2end/codegen_generic_end2end_test.cc b/test/cpp/end2end/raw_end2end_test.cc similarity index 93% rename from test/cpp/end2end/codegen_generic_end2end_test.cc rename to test/cpp/end2end/raw_end2end_test.cc index 6bb5712eb26..37fdc423fd7 100644 --- a/test/cpp/end2end/codegen_generic_end2end_test.cc +++ b/test/cpp/end2end/raw_end2end_test.cc @@ -189,9 +189,9 @@ class Verifier { bool lambda_run_; }; -class CodegenGenericEnd2EndTest : public ::testing::Test { +class RawEnd2EndTest : public ::testing::Test { protected: - CodegenGenericEnd2EndTest() {} + RawEnd2EndTest() {} void SetUp() override { port_ = grpc_pick_unused_port_or_die(); @@ -259,7 +259,7 @@ class CodegenGenericEnd2EndTest : public ::testing::Test { }; // Regular Async, both peers use proto -TEST_F(CodegenGenericEnd2EndTest, PureAsyncService) { +TEST_F(RawEnd2EndTest, PureAsyncService) { typedef grpc::testing::EchoTestService::AsyncService SType; ResetStub(); auto service = BuildAndStartServer(); @@ -282,8 +282,8 @@ TEST_F(CodegenGenericEnd2EndTest, PureAsyncService) { } // Client uses proto, server uses generic codegen, unary -TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerUnary) { - typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_Echo< +TEST_F(RawEnd2EndTest, RawServerUnary) { + typedef grpc::testing::EchoTestService::WithRawMethod_Echo< grpc::testing::EchoTestService::Service> SType; ResetStub(); @@ -310,11 +310,10 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerUnary) { } // Client uses proto, server uses generic codegen, client streaming -TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { - typedef grpc::testing::EchoTestService:: - WithCodegenGenericMethod_RequestStream< - grpc::testing::EchoTestService::Service> - SType; +TEST_F(RawEnd2EndTest, RawServerClientStreaming) { + typedef grpc::testing::EchoTestService::WithRawMethod_RequestStream< + grpc::testing::EchoTestService::Service> + SType; ResetStub(); auto service = BuildAndStartServer(); @@ -357,11 +356,10 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerClientStreaming) { } // Client uses proto, server uses generic codegen, server streaming -TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerServerStreaming) { - typedef grpc::testing::EchoTestService:: - WithCodegenGenericMethod_ResponseStream< - grpc::testing::EchoTestService::Service> - SType; +TEST_F(RawEnd2EndTest, RawServerServerStreaming) { + typedef grpc::testing::EchoTestService::WithRawMethod_ResponseStream< + grpc::testing::EchoTestService::Service> + SType; ResetStub(); auto service = BuildAndStartServer(); grpc::GenericServerAsyncWriter srv_stream(&srv_ctx_); @@ -400,8 +398,8 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerServerStreaming) { } // Client uses proto, server uses generic codegen, bidi streaming -TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerBidiStreaming) { - typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_BidiStream< +TEST_F(RawEnd2EndTest, RawServerBidiStreaming) { + typedef grpc::testing::EchoTestService::WithRawMethod_BidiStream< grpc::testing::EchoTestService::Service> SType; ResetStub(); @@ -443,8 +441,8 @@ TEST_F(CodegenGenericEnd2EndTest, CodegenGenericServerBidiStreaming) { } // Testing that this pattern compiles -TEST_F(CodegenGenericEnd2EndTest, CompileTest) { - typedef grpc::testing::EchoTestService::WithCodegenGenericMethod_Echo< +TEST_F(RawEnd2EndTest, CompileTest) { + typedef grpc::testing::EchoTestService::WithRawMethod_Echo< grpc::testing::EchoTestService::AsyncService> SType; ResetStub(); diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 7c1b845565b..cb863e7d218 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3327,25 +3327,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util", - "grpc", - "grpc++", - "grpc++_test_util", - "grpc_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "codegen_generic_end2end_test", - "src": [ - "test/cpp/end2end/codegen_generic_end2end_test.cc" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -4299,6 +4280,25 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc++", + "grpc++_test_util", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "raw_end2end_test", + "src": [ + "test/cpp/end2end/raw_end2end_test.cc" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index a954a8d2d5d..9aff58351f5 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3945,30 +3945,6 @@ ], "uses_polling": true }, - { - "args": [], - "benchmark": false, - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": true, - "language": "c++", - "name": "codegen_generic_end2end_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "uses_polling": true - }, { "args": [], "benchmark": false, @@ -4733,6 +4709,30 @@ ], "uses_polling": true }, + { + "args": [], + "benchmark": false, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": true, + "language": "c++", + "name": "raw_end2end_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "uses_polling": true + }, { "args": [], "benchmark": false, From 7d474811ab068580919df1f9027ee774b4d24f46 Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 29 Jun 2018 14:59:59 -0700 Subject: [PATCH 8/8] Reviewer feedback --- .../grpcpp/impl/codegen/rpc_service_method.h | 2 +- test/cpp/end2end/raw_end2end_test.cc | 105 +----------------- 2 files changed, 7 insertions(+), 100 deletions(-) diff --git a/include/grpcpp/impl/codegen/rpc_service_method.h b/include/grpcpp/impl/codegen/rpc_service_method.h index 92c66bbf15b..5cf88e216f9 100644 --- a/include/grpcpp/impl/codegen/rpc_service_method.h +++ b/include/grpcpp/impl/codegen/rpc_service_method.h @@ -95,7 +95,7 @@ class RpcServiceMethod : public RpcMethod { private: void* server_tag_; - RpcServiceMethod::AsyncType async_type_; + AsyncType async_type_; std::unique_ptr handler_; const char* TypeToString(RpcServiceMethod::AsyncType type) { diff --git a/test/cpp/end2end/raw_end2end_test.cc b/test/cpp/end2end/raw_end2end_test.cc index 37fdc423fd7..a413905ef7a 100644 --- a/test/cpp/end2end/raw_end2end_test.cc +++ b/test/cpp/end2end/raw_end2end_test.cc @@ -55,26 +55,11 @@ int detag(void* p) { return static_cast(reinterpret_cast(p)); } class Verifier { public: - Verifier() : lambda_run_(false) {} + Verifier() {} + // Expect sets the expected ok value for a specific tag Verifier& Expect(int i, bool expect_ok) { - return ExpectUnless(i, expect_ok, false); - } - // ExpectUnless sets the expected ok value for a specific tag - // unless the tag was already marked seen (as a result of ExpectMaybe) - Verifier& ExpectUnless(int i, bool expect_ok, bool seen) { - if (!seen) { - expectations_[tag(i)] = expect_ok; - } - return *this; - } - // ExpectMaybe sets the expected ok value for a specific tag, but does not - // require it to appear - // If it does, sets *seen to true - Verifier& ExpectMaybe(int i, bool expect_ok, bool* seen) { - if (!*seen) { - maybe_expectations_[tag(i)] = MaybeExpect{expect_ok, seen}; - } + expectations_[tag(i)] = expect_ok; return *this; } @@ -88,69 +73,12 @@ class Verifier { return detag(got_tag); } - template - CompletionQueue::NextStatus DoOnceThenAsyncNext( - CompletionQueue* cq, void** got_tag, bool* ok, T deadline, - std::function lambda) { - if (lambda_run_) { - return cq->AsyncNext(got_tag, ok, deadline); - } else { - lambda_run_ = true; - return cq->DoThenAsyncNext(lambda, got_tag, ok, deadline); - } - } - // Verify keeps calling Next until all currently set // expected tags are complete - void Verify(CompletionQueue* cq) { Verify(cq, false); } - - // This version of Verify allows optionally ignoring the - // outcome of the expectation - void Verify(CompletionQueue* cq, bool ignore_ok) { - GPR_ASSERT(!expectations_.empty() || !maybe_expectations_.empty()); + void Verify(CompletionQueue* cq) { + GPR_ASSERT(!expectations_.empty()); while (!expectations_.empty()) { - Next(cq, ignore_ok); - } - } - - // This version of Verify stops after a certain deadline - void Verify(CompletionQueue* cq, - std::chrono::system_clock::time_point deadline) { - if (expectations_.empty()) { - bool ok; - void* got_tag; - EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), - CompletionQueue::TIMEOUT); - } else { - while (!expectations_.empty()) { - bool ok; - void* got_tag; - EXPECT_EQ(cq->AsyncNext(&got_tag, &ok, deadline), - CompletionQueue::GOT_EVENT); - GotTag(got_tag, ok, false); - } - } - } - - // This version of Verify stops after a certain deadline, and uses the - // DoThenAsyncNext API - // to call the lambda - void Verify(CompletionQueue* cq, - std::chrono::system_clock::time_point deadline, - std::function lambda) { - if (expectations_.empty()) { - bool ok; - void* got_tag; - EXPECT_EQ(DoOnceThenAsyncNext(cq, &got_tag, &ok, deadline, lambda), - CompletionQueue::TIMEOUT); - } else { - while (!expectations_.empty()) { - bool ok; - void* got_tag; - EXPECT_EQ(DoOnceThenAsyncNext(cq, &got_tag, &ok, deadline, lambda), - CompletionQueue::GOT_EVENT); - GotTag(got_tag, ok, false); - } + Next(cq, false); } } @@ -162,31 +90,10 @@ class Verifier { EXPECT_EQ(it->second, ok); } expectations_.erase(it); - } else { - auto it2 = maybe_expectations_.find(got_tag); - if (it2 != maybe_expectations_.end()) { - if (it2->second.seen != nullptr) { - EXPECT_FALSE(*it2->second.seen); - *it2->second.seen = true; - } - if (!ignore_ok) { - EXPECT_EQ(it2->second.ok, ok); - } - } else { - gpr_log(GPR_ERROR, "Unexpected tag: %p", tag); - abort(); - } } } - struct MaybeExpect { - bool ok; - bool* seen; - }; - std::map expectations_; - std::map maybe_expectations_; - bool lambda_run_; }; class RawEnd2EndTest : public ::testing::Test {