From 04f1aa809a60bda7e64e72863890bba69ac0cfbf Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Fri, 30 Jan 2015 18:26:16 -0800 Subject: [PATCH 01/28] Implement both Publisher and Subscriber. --- Makefile | 73 ++++++--- build.json | 26 +++- examples/tips/{client_main.cc => main.cc} | 49 ++++-- examples/tips/{client.cc => publisher.cc} | 30 +++- examples/tips/{client.h => publisher.h} | 14 +- examples/tips/publisher_test.cc | 144 ++++++++++++++++++ examples/tips/subscriber.cc | 86 +++++++++++ examples/tips/subscriber.h | 64 ++++++++ .../{client_test.cc => subscriber_test.cc} | 51 +++++-- tools/run_tests/tests.json | 6 +- 10 files changed, 486 insertions(+), 57 deletions(-) rename examples/tips/{client_main.cc => main.cc} (71%) rename examples/tips/{client.cc => publisher.cc} (78%) rename examples/tips/{client.h => publisher.h} (86%) create mode 100644 examples/tips/publisher_test.cc create mode 100644 examples/tips/subscriber.cc create mode 100644 examples/tips/subscriber.h rename examples/tips/{client_test.cc => subscriber_test.cc} (65%) diff --git a/Makefile b/Makefile index 9031853a43c..6e9f7195ba9 100644 --- a/Makefile +++ b/Makefile @@ -381,7 +381,8 @@ end2end_test: bins/$(CONFIG)/end2end_test interop_client: bins/$(CONFIG)/interop_client interop_server: bins/$(CONFIG)/interop_server tips_client: bins/$(CONFIG)/tips_client -tips_client_test: bins/$(CONFIG)/tips_client_test +tips_publisher_test: bins/$(CONFIG)/tips_publisher_test +tips_subscriber_test: bins/$(CONFIG)/tips_subscriber_test qps_client: bins/$(CONFIG)/qps_client qps_server: bins/$(CONFIG)/qps_server ruby_plugin: bins/$(CONFIG)/ruby_plugin @@ -567,7 +568,7 @@ buildtests: buildtests_c buildtests_cxx buildtests_c: privatelibs_c bins/$(CONFIG)/alarm_heap_test bins/$(CONFIG)/alarm_list_test bins/$(CONFIG)/alarm_test bins/$(CONFIG)/alpn_test bins/$(CONFIG)/bin_encoder_test bins/$(CONFIG)/census_hash_table_test bins/$(CONFIG)/census_statistics_multiple_writers_circular_buffer_test bins/$(CONFIG)/census_statistics_multiple_writers_test bins/$(CONFIG)/census_statistics_performance_test bins/$(CONFIG)/census_statistics_quick_test bins/$(CONFIG)/census_statistics_small_log_test bins/$(CONFIG)/census_stub_test bins/$(CONFIG)/census_window_stats_test bins/$(CONFIG)/chttp2_status_conversion_test bins/$(CONFIG)/chttp2_stream_encoder_test bins/$(CONFIG)/chttp2_stream_map_test bins/$(CONFIG)/chttp2_transport_end2end_test bins/$(CONFIG)/dualstack_socket_test bins/$(CONFIG)/echo_client bins/$(CONFIG)/echo_server bins/$(CONFIG)/echo_test bins/$(CONFIG)/fd_posix_test bins/$(CONFIG)/fling_client bins/$(CONFIG)/fling_server bins/$(CONFIG)/fling_stream_test bins/$(CONFIG)/fling_test bins/$(CONFIG)/gpr_cancellable_test bins/$(CONFIG)/gpr_cmdline_test bins/$(CONFIG)/gpr_histogram_test bins/$(CONFIG)/gpr_host_port_test bins/$(CONFIG)/gpr_log_test bins/$(CONFIG)/gpr_slice_buffer_test bins/$(CONFIG)/gpr_slice_test bins/$(CONFIG)/gpr_string_test bins/$(CONFIG)/gpr_sync_test bins/$(CONFIG)/gpr_thd_test bins/$(CONFIG)/gpr_time_test bins/$(CONFIG)/gpr_useful_test bins/$(CONFIG)/grpc_base64_test bins/$(CONFIG)/grpc_byte_buffer_reader_test bins/$(CONFIG)/grpc_channel_stack_test bins/$(CONFIG)/grpc_completion_queue_test bins/$(CONFIG)/grpc_credentials_test bins/$(CONFIG)/grpc_json_token_test bins/$(CONFIG)/grpc_stream_op_test bins/$(CONFIG)/hpack_parser_test bins/$(CONFIG)/hpack_table_test bins/$(CONFIG)/httpcli_format_request_test bins/$(CONFIG)/httpcli_parser_test bins/$(CONFIG)/httpcli_test bins/$(CONFIG)/lame_client_test bins/$(CONFIG)/message_compress_test bins/$(CONFIG)/metadata_buffer_test bins/$(CONFIG)/murmur_hash_test bins/$(CONFIG)/no_server_test bins/$(CONFIG)/poll_kick_posix_test bins/$(CONFIG)/resolve_address_test bins/$(CONFIG)/secure_endpoint_test bins/$(CONFIG)/sockaddr_utils_test bins/$(CONFIG)/tcp_client_posix_test bins/$(CONFIG)/tcp_posix_test bins/$(CONFIG)/tcp_server_posix_test bins/$(CONFIG)/time_averaged_stats_test bins/$(CONFIG)/time_test bins/$(CONFIG)/timeout_encoding_test bins/$(CONFIG)/transport_metadata_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_invoke_test bins/$(CONFIG)/chttp2_fake_security_cancel_before_invoke_test bins/$(CONFIG)/chttp2_fake_security_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_fake_security_census_simple_request_test bins/$(CONFIG)/chttp2_fake_security_disappearing_server_test bins/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_fake_security_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_fake_security_invoke_large_request_test bins/$(CONFIG)/chttp2_fake_security_max_concurrent_streams_test bins/$(CONFIG)/chttp2_fake_security_no_op_test bins/$(CONFIG)/chttp2_fake_security_ping_pong_streaming_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_simple_delayed_request_test bins/$(CONFIG)/chttp2_fake_security_simple_request_test bins/$(CONFIG)/chttp2_fake_security_thread_stress_test bins/$(CONFIG)/chttp2_fake_security_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_fullstack_no_op_test bins/$(CONFIG)/chttp2_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_fullstack_simple_request_test bins/$(CONFIG)/chttp2_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_no_op_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_no_op_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_invoke_test bins/$(CONFIG)/chttp2_socket_pair_cancel_before_invoke_test bins/$(CONFIG)/chttp2_socket_pair_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_socket_pair_census_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_disappearing_server_test bins/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_socket_pair_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_socket_pair_invoke_large_request_test bins/$(CONFIG)/chttp2_socket_pair_max_concurrent_streams_test bins/$(CONFIG)/chttp2_socket_pair_no_op_test bins/$(CONFIG)/chttp2_socket_pair_ping_pong_streaming_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_simple_delayed_request_test bins/$(CONFIG)/chttp2_socket_pair_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_thread_stress_test bins/$(CONFIG)/chttp2_socket_pair_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_invoke_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_before_invoke_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_census_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_disappearing_server_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_invoke_large_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_max_concurrent_streams_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_no_op_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_ping_pong_streaming_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_delayed_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_thread_stress_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_writes_done_hangs_with_pending_read_test -buildtests_cxx: privatelibs_cxx bins/$(CONFIG)/channel_arguments_test bins/$(CONFIG)/credentials_test bins/$(CONFIG)/end2end_test bins/$(CONFIG)/interop_client bins/$(CONFIG)/interop_server bins/$(CONFIG)/tips_client bins/$(CONFIG)/tips_client_test bins/$(CONFIG)/qps_client bins/$(CONFIG)/qps_server bins/$(CONFIG)/status_test bins/$(CONFIG)/sync_client_async_server_test bins/$(CONFIG)/thread_pool_test +buildtests_cxx: privatelibs_cxx bins/$(CONFIG)/channel_arguments_test bins/$(CONFIG)/credentials_test bins/$(CONFIG)/end2end_test bins/$(CONFIG)/interop_client bins/$(CONFIG)/interop_server bins/$(CONFIG)/tips_client bins/$(CONFIG)/tips_publisher_test bins/$(CONFIG)/tips_subscriber_test bins/$(CONFIG)/qps_client bins/$(CONFIG)/qps_server bins/$(CONFIG)/status_test bins/$(CONFIG)/sync_client_async_server_test bins/$(CONFIG)/thread_pool_test test: test_c test_cxx @@ -969,8 +970,10 @@ test_cxx: buildtests_cxx $(Q) ./bins/$(CONFIG)/credentials_test || ( echo test credentials_test failed ; exit 1 ) $(E) "[RUN] Testing end2end_test" $(Q) ./bins/$(CONFIG)/end2end_test || ( echo test end2end_test failed ; exit 1 ) - $(E) "[RUN] Testing tips_client_test" - $(Q) ./bins/$(CONFIG)/tips_client_test || ( echo test tips_client_test failed ; exit 1 ) + $(E) "[RUN] Testing tips_publisher_test" + $(Q) ./bins/$(CONFIG)/tips_publisher_test || ( echo test tips_publisher_test failed ; exit 1 ) + $(E) "[RUN] Testing tips_subscriber_test" + $(Q) ./bins/$(CONFIG)/tips_subscriber_test || ( echo test tips_subscriber_test failed ; exit 1 ) $(E) "[RUN] Testing qps_client" $(Q) ./bins/$(CONFIG)/qps_client || ( echo test qps_client failed ; exit 1 ) $(E) "[RUN] Testing qps_server" @@ -2210,7 +2213,8 @@ LIBTIPS_CLIENT_LIB_SRC = \ gens/examples/tips/label.pb.cc \ gens/examples/tips/empty.pb.cc \ gens/examples/tips/pubsub.pb.cc \ - examples/tips/client.cc \ + examples/tips/publisher.cc \ + examples/tips/subscriber.cc \ LIBTIPS_CLIENT_LIB_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBTIPS_CLIENT_LIB_SRC)))) @@ -2228,7 +2232,8 @@ ifneq ($(OPENSSL_DEP),) examples/tips/label.proto: $(OPENSSL_DEP) examples/tips/empty.proto: $(OPENSSL_DEP) examples/tips/pubsub.proto: $(OPENSSL_DEP) -examples/tips/client.cc: $(OPENSSL_DEP) +examples/tips/publisher.cc: $(OPENSSL_DEP) +examples/tips/subscriber.cc: $(OPENSSL_DEP) endif libs/$(CONFIG)/libtips_client_lib.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(LIBTIPS_CLIENT_LIB_OBJS) @@ -2255,7 +2260,8 @@ endif -objs/$(CONFIG)/examples/tips/client.o: gens/examples/tips/label.pb.cc gens/examples/tips/empty.pb.cc gens/examples/tips/pubsub.pb.cc +objs/$(CONFIG)/examples/tips/publisher.o: gens/examples/tips/label.pb.cc gens/examples/tips/empty.pb.cc gens/examples/tips/pubsub.pb.cc +objs/$(CONFIG)/examples/tips/subscriber.o: gens/examples/tips/label.pb.cc gens/examples/tips/empty.pb.cc gens/examples/tips/pubsub.pb.cc LIBEND2END_FIXTURE_CHTTP2_FAKE_SECURITY_SRC = \ @@ -5565,7 +5571,7 @@ endif TIPS_CLIENT_SRC = \ - examples/tips/client_main.cc \ + examples/tips/main.cc \ TIPS_CLIENT_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_CLIENT_SRC)))) @@ -5584,7 +5590,7 @@ bins/$(CONFIG)/tips_client: $(TIPS_CLIENT_OBJS) libs/$(CONFIG)/libtips_client_li endif -objs/$(CONFIG)/examples/tips/client_main.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a +objs/$(CONFIG)/examples/tips/main.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a deps_tips_client: $(TIPS_CLIENT_OBJS:.o=.dep) @@ -5595,33 +5601,64 @@ endif endif -TIPS_CLIENT_TEST_SRC = \ - examples/tips/client_test.cc \ +TIPS_PUBLISHER_TEST_SRC = \ + examples/tips/publisher_test.cc \ -TIPS_CLIENT_TEST_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_CLIENT_TEST_SRC)))) +TIPS_PUBLISHER_TEST_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_PUBLISHER_TEST_SRC)))) ifeq ($(NO_SECURE),true) # You can't build secure targets if you don't have OpenSSL with ALPN. -bins/$(CONFIG)/tips_client_test: openssl_dep_error +bins/$(CONFIG)/tips_publisher_test: openssl_dep_error else -bins/$(CONFIG)/tips_client_test: $(TIPS_CLIENT_TEST_OBJS) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a +bins/$(CONFIG)/tips_publisher_test: $(TIPS_PUBLISHER_TEST_OBJS) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TIPS_CLIENT_TEST_OBJS) $(GTEST_LIB) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS) $(LDLIBS_SECURE) -o bins/$(CONFIG)/tips_client_test + $(Q) $(LDXX) $(LDFLAGS) $(TIPS_PUBLISHER_TEST_OBJS) $(GTEST_LIB) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS) $(LDLIBS_SECURE) -o bins/$(CONFIG)/tips_publisher_test endif -objs/$(CONFIG)/examples/tips/client_test.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a +objs/$(CONFIG)/examples/tips/publisher_test.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a -deps_tips_client_test: $(TIPS_CLIENT_TEST_OBJS:.o=.dep) +deps_tips_publisher_test: $(TIPS_PUBLISHER_TEST_OBJS:.o=.dep) ifneq ($(NO_SECURE),true) ifneq ($(NO_DEPS),true) --include $(TIPS_CLIENT_TEST_OBJS:.o=.dep) +-include $(TIPS_PUBLISHER_TEST_OBJS:.o=.dep) +endif +endif + + +TIPS_SUBSCRIBER_TEST_SRC = \ + examples/tips/subscriber_test.cc \ + +TIPS_SUBSCRIBER_TEST_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_SUBSCRIBER_TEST_SRC)))) + +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL with ALPN. + +bins/$(CONFIG)/tips_subscriber_test: openssl_dep_error + +else + +bins/$(CONFIG)/tips_subscriber_test: $(TIPS_SUBSCRIBER_TEST_OBJS) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(TIPS_SUBSCRIBER_TEST_OBJS) $(GTEST_LIB) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS) $(LDLIBS_SECURE) -o bins/$(CONFIG)/tips_subscriber_test + +endif + +objs/$(CONFIG)/examples/tips/subscriber_test.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a + +deps_tips_subscriber_test: $(TIPS_SUBSCRIBER_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(TIPS_SUBSCRIBER_TEST_OBJS:.o=.dep) endif endif diff --git a/build.json b/build.json index bf780b71d96..625d577c516 100644 --- a/build.json +++ b/build.json @@ -426,7 +426,8 @@ "examples/tips/label.proto", "examples/tips/empty.proto", "examples/tips/pubsub.proto", - "examples/tips/client.cc" + "examples/tips/publisher.cc", + "examples/tips/subscriber.cc" ], "deps": [ "grpc++", @@ -1524,7 +1525,7 @@ "run": false, "language": "c++", "src": [ - "examples/tips/client_main.cc" + "examples/tips/main.cc" ], "deps": [ "tips_client_lib", @@ -1537,11 +1538,28 @@ ] }, { - "name": "tips_client_test", + "name": "tips_publisher_test", "build": "test", "language": "c++", "src": [ - "examples/tips/client_test.cc" + "examples/tips/publisher_test.cc" + ], + "deps": [ + "tips_client_lib", + "grpc++_test_util", + "grpc_test_util", + "grpc++", + "grpc", + "gpr_test_util", + "gpr" + ] + }, + { + "name": "tips_subscriber_test", + "build": "test", + "language": "c++", + "src": [ + "examples/tips/subscriber_test.cc" ], "deps": [ "tips_client_lib", diff --git a/examples/tips/client_main.cc b/examples/tips/main.cc similarity index 71% rename from examples/tips/client_main.cc rename to examples/tips/main.cc index 5a3a0daab7a..94a0bc7995b 100644 --- a/examples/tips/client_main.cc +++ b/examples/tips/main.cc @@ -46,7 +46,8 @@ #include #include -#include "examples/tips/client.h" +#include "examples/tips/publisher.h" +#include "examples/tips/subscriber.h" #include "test/cpp/util/create_test_channel.h" DEFINE_int32(server_port, 443, "Server port."); @@ -54,7 +55,17 @@ DEFINE_string(server_host, "pubsub-staging.googleapis.com", "Server host to connect to"); DEFINE_string(service_account_key_file, "", "Path to service account json key file."); -DEFINE_string(oauth_scope, "", "Scope for OAuth tokens."); +DEFINE_string(oauth_scope, + "https://www.googleapis.com/auth/cloud-platform", + "Scope for OAuth tokens."); + +namespace { + +const char kTopic[] = "/topics/stoked-keyword-656/testtopics"; +const char kSubscriptionName[] = "stoked-keyword-656/testsubscription"; +const char kMessageData[] = "Message Data"; + +} // namespace grpc::string GetServiceAccountJsonKey() { static grpc::string json_key; @@ -94,20 +105,40 @@ int main(int argc, char** argv) { true, // use prod roots creds)); - grpc::examples::tips::Client client(channel); + grpc::examples::tips::Publisher publisher(channel); + grpc::examples::tips::Subscriber subscriber(channel); + + grpc::string topic = kTopic; + + if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); + + grpc::Status s = publisher.CreateTopic(topic); + gpr_log(GPR_INFO, "Create topic returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + s = publisher.GetTopic(topic); + gpr_log(GPR_INFO, "Get topic returns code %d, %s", + s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); - grpc::Status s = client.CreateTopic("/topics/stoked-keyword-656/testtopics"); - gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); + s = publisher.Publish(topic, kMessageData); + gpr_log(GPR_INFO, "Publish returns code %d, %s", + s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = client.GetTopic("/topics/stoked-keyword-656/testtopics"); - gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); + s = subscriber.CreateSubscription(kTopic, kSubscriptionName); + gpr_log(GPR_INFO, "create subscrption returns code %d, %s", + s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = client.DeleteTopic("/topics/stoked-keyword-656/testtopics"); - gpr_log(GPR_INFO, "return code %d, %s", s.code(), s.details().c_str()); + s = publisher.DeleteTopic(kTopic); + gpr_log(GPR_INFO, "Delete topic returns code %d, %s", + s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); + subscriber.Shutdown(); + publisher.Shutdown(); channel.reset(); grpc_shutdown(); return 0; diff --git a/examples/tips/client.cc b/examples/tips/publisher.cc similarity index 78% rename from examples/tips/client.cc rename to examples/tips/publisher.cc index f9d53197ed9..238ea596a23 100644 --- a/examples/tips/client.cc +++ b/examples/tips/publisher.cc @@ -33,7 +33,7 @@ #include -#include "examples/tips/client.h" +#include "examples/tips/publisher.h" using tech::pubsub::Topic; using tech::pubsub::DeleteTopicRequest; @@ -41,16 +41,22 @@ using tech::pubsub::GetTopicRequest; using tech::pubsub::PublisherService; using tech::pubsub::ListTopicsRequest; using tech::pubsub::ListTopicsResponse; +using tech::pubsub::PublishRequest; +using tech::pubsub::PubsubMessage; namespace grpc { namespace examples { namespace tips { -Client::Client(std::shared_ptr channel) +Publisher::Publisher(std::shared_ptr channel) : stub_(PublisherService::NewStub(channel)) { } -Status Client::CreateTopic(grpc::string topic) { +void Publisher::Shutdown() { + stub_.reset(); +} + +Status Publisher::CreateTopic(grpc::string topic) { Topic request; Topic response; request.set_name(topic); @@ -59,7 +65,7 @@ Status Client::CreateTopic(grpc::string topic) { return stub_->CreateTopic(&context, request, &response); } -Status Client::ListTopics() { +Status Publisher::ListTopics() { ListTopicsRequest request; ListTopicsResponse response; ClientContext context; @@ -67,7 +73,7 @@ Status Client::ListTopics() { return stub_->ListTopics(&context, request, &response); } -Status Client::GetTopic(grpc::string topic) { +Status Publisher::GetTopic(grpc::string topic) { GetTopicRequest request; Topic response; ClientContext context; @@ -77,7 +83,7 @@ Status Client::GetTopic(grpc::string topic) { return stub_->GetTopic(&context, request, &response); } -Status Client::DeleteTopic(grpc::string topic) { +Status Publisher::DeleteTopic(grpc::string topic) { DeleteTopicRequest request; proto2::Empty response; ClientContext context; @@ -87,6 +93,18 @@ Status Client::DeleteTopic(grpc::string topic) { return stub_->DeleteTopic(&context, request, &response); } +Status Publisher::Publish(const grpc::string& topic, + const grpc::string& data) { + PublishRequest request; + proto2::Empty response; + ClientContext context; + + request.mutable_message()->set_data(data); + request.set_topic(topic); + + return stub_->Publish(&context, request, &response); +} + } // namespace tips } // namespace examples } // namespace grpc diff --git a/examples/tips/client.h b/examples/tips/publisher.h similarity index 86% rename from examples/tips/client.h rename to examples/tips/publisher.h index 661ee5c4af7..a97dbe6de25 100644 --- a/examples/tips/client.h +++ b/examples/tips/publisher.h @@ -31,8 +31,8 @@ * */ -#ifndef __GRPCPP_EXAMPLES_TIPS_CLIENT_H_ -#define __GRPCPP_EXAMPLES_TIPS_CLIENT_H_ +#ifndef __GRPCPP_EXAMPLES_TIPS_PUBLISHER_H_ +#define __GRPCPP_EXAMPLES_TIPS_PUBLISHER_H_ #include #include @@ -43,14 +43,18 @@ namespace grpc { namespace examples { namespace tips { -class Client { +class Publisher { public: - Client(std::shared_ptr channel); + Publisher(std::shared_ptr channel); + void Shutdown(); + Status CreateTopic(grpc::string topic); Status GetTopic(grpc::string topic); Status DeleteTopic(grpc::string topic); Status ListTopics(); + Status Publish(const grpc::string& topic, const grpc::string& data); + private: std::unique_ptr stub_; }; @@ -59,4 +63,4 @@ class Client { } // namespace examples } // namespace grpc -#endif // __GRPCPP_EXAMPLES_TIPS_CLIENT_H_ +#endif // __GRPCPP_EXAMPLES_TIPS_PUBLISHER_H_ diff --git a/examples/tips/publisher_test.cc b/examples/tips/publisher_test.cc new file mode 100644 index 00000000000..7f845fed230 --- /dev/null +++ b/examples/tips/publisher_test.cc @@ -0,0 +1,144 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "examples/tips/publisher.h" +#include "test/core/util/port.h" +#include "test/core/util/test_config.h" + +using grpc::ChannelInterface; + +namespace grpc { +namespace testing { +namespace { + +const char kTopic[] = "test topic"; +const char kMessageData[] = "test message data"; + +class PublisherServiceImpl : public tech::pubsub::PublisherService::Service { + public: + Status CreateTopic(::grpc::ServerContext* context, + const ::tech::pubsub::Topic* request, + ::tech::pubsub::Topic* response) override { + EXPECT_EQ(request->name(), kTopic); + return Status::OK; + } + + Status Publish(ServerContext* context, + const ::tech::pubsub::PublishRequest* request, + ::proto2::Empty* response) override { + EXPECT_EQ(request->message().data(), kMessageData); + return Status::OK; + } + + Status GetTopic(ServerContext* context, + const ::tech::pubsub::GetTopicRequest* request, + ::tech::pubsub::Topic* response) override { + EXPECT_EQ(request->topic(), kTopic); + return Status::OK; + } + + Status ListTopics(ServerContext* context, + const ::tech::pubsub::ListTopicsRequest* request, + ::tech::pubsub::ListTopicsResponse* response) override { + return Status::OK; + } + + Status DeleteTopic(ServerContext* context, + const ::tech::pubsub::DeleteTopicRequest* request, + ::proto2::Empty* response) override { + EXPECT_EQ(request->topic(), kTopic); + return Status::OK; + } + +}; + +class PublisherTest : public ::testing::Test { + protected: + // Setup a server and a client for PublisherService. + void SetUp() override { + int port = grpc_pick_unused_port_or_die(); + server_address_ << "localhost:" << port; + ServerBuilder builder; + builder.AddPort(server_address_.str()); + builder.RegisterService(service_.service()); + server_ = builder.BuildAndStart(); + + channel_ = CreateChannel(server_address_.str(), ChannelArguments()); + + publisher_.reset(new grpc::examples::tips::Publisher(channel_)); + } + + void TearDown() override { + server_->Shutdown(); + publisher_->Shutdown(); + } + + std::ostringstream server_address_; + std::unique_ptr server_; + PublisherServiceImpl service_; + + std::shared_ptr channel_; + + std::unique_ptr publisher_; +}; + +TEST_F(PublisherTest, TestPublisher) { + EXPECT_TRUE(publisher_->CreateTopic(kTopic).IsOk()); + EXPECT_TRUE(publisher_->Publish(kTopic, kMessageData).IsOk()); + EXPECT_TRUE(publisher_->GetTopic(kTopic).IsOk()); + EXPECT_TRUE(publisher_->ListTopics().IsOk()); +} + +} // namespace +} // namespace testing +} // namespace grpc + +int main(int argc, char** argv) { + grpc_test_init(argc, argv); + grpc_init(); + ::testing::InitGoogleTest(&argc, argv); + gpr_log(GPR_INFO, "Start test ..."); + int result = RUN_ALL_TESTS(); + grpc_shutdown(); + return result; +} diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc new file mode 100644 index 00000000000..a482ad6263d --- /dev/null +++ b/examples/tips/subscriber.cc @@ -0,0 +1,86 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include + +#include "examples/tips/subscriber.h" + +using tech::pubsub::Topic; +using tech::pubsub::DeleteTopicRequest; +using tech::pubsub::GetTopicRequest; +using tech::pubsub::SubscriberService; +using tech::pubsub::ListTopicsRequest; +using tech::pubsub::ListTopicsResponse; +using tech::pubsub::PublishRequest; +using tech::pubsub::PubsubMessage; + +namespace grpc { +namespace examples { +namespace tips { + +Subscriber::Subscriber(std::shared_ptr channel) + : stub_(SubscriberService::NewStub(channel)) { +} + +void Subscriber::Shutdown() { + stub_.reset(); +} + +Status Subscriber::CreateSubscription(const grpc::string& topic, + const grpc::string& name) { + tech::pubsub::Subscription request; + tech::pubsub::Subscription response; + ClientContext context; + + request.set_topic(topic); + request.set_name(name); + + return stub_->CreateSubscription(&context, request, &response); +} + +Status Subscriber::GetSubscription(const grpc::string& name, + grpc::string* topic) { + tech::pubsub::GetSubscriptionRequest request; + tech::pubsub::Subscription response; + ClientContext context; + + request.set_subscription(name); + + Status s = stub_->GetSubscription(&context, request, &response); + *topic = response.topic(); + return s; +} + +} // namespace tips +} // namespace examples +} // namespace grpc diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h new file mode 100644 index 00000000000..e0491ff919a --- /dev/null +++ b/examples/tips/subscriber.h @@ -0,0 +1,64 @@ +/* + * + * Copyright 2014, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef __GRPCPP_EXAMPLES_TIPS_SUBSCRIBER_H_ +#define __GRPCPP_EXAMPLES_TIPS_SUBSCRIBER_H_ + +#include +#include + +#include "examples/tips/pubsub.pb.h" + +namespace grpc { +namespace examples { +namespace tips { + +class Subscriber { + public: + Subscriber(std::shared_ptr channel); + void Shutdown(); + + Status CreateSubscription(const grpc::string& topic, + const grpc::string& name); + + Status GetSubscription(const grpc::string& name, grpc::string* topic); + + private: + std::unique_ptr stub_; +}; + +} // namespace tips +} // namespace examples +} // namespace grpc + +#endif // __GRPCPP_EXAMPLES_TIPS_SUBSCRIBER_H_ diff --git a/examples/tips/client_test.cc b/examples/tips/subscriber_test.cc similarity index 65% rename from examples/tips/client_test.cc rename to examples/tips/subscriber_test.cc index 69238f2c6fc..4894814252e 100644 --- a/examples/tips/client_test.cc +++ b/examples/tips/subscriber_test.cc @@ -41,7 +41,7 @@ #include #include -#include "examples/tips/client.h" +#include "examples/tips/subscriber.h" #include "test/core/util/port.h" #include "test/core/util/test_config.h" @@ -52,43 +52,66 @@ namespace testing { namespace { const char kTopic[] = "test topic"; +const char kSubscriptionName[] = "subscription name"; -class PublishServiceImpl : public tech::pubsub::PublisherService::Service { +class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { public: - Status CreateTopic(::grpc::ServerContext* context, - const ::tech::pubsub::Topic* request, - ::tech::pubsub::Topic* response) override { - EXPECT_EQ(request->name(), kTopic); + Status CreateSubscription(ServerContext* context, + const tech::pubsub::Subscription* request, + tech::pubsub::Subscription* response) override { + EXPECT_EQ(request->topic(), kTopic); + EXPECT_EQ(request->name(), kSubscriptionName); return Status::OK; } + + Status GetSubscription(ServerContext* context, + const tech::pubsub::GetSubscriptionRequest* request, + tech::pubsub::Subscription* response) override { + EXPECT_EQ(request->subscription(), kSubscriptionName); + response->set_topic(kTopic); + return Status::OK; + } + }; -class End2endTest : public ::testing::Test { +class SubscriberTest : public ::testing::Test { protected: + // Setup a server and a client for SubscriberService. void SetUp() override { int port = grpc_pick_unused_port_or_die(); server_address_ << "localhost:" << port; - // Setup server ServerBuilder builder; builder.AddPort(server_address_.str()); builder.RegisterService(service_.service()); server_ = builder.BuildAndStart(); channel_ = CreateChannel(server_address_.str(), ChannelArguments()); + + subscriber_.reset(new grpc::examples::tips::Subscriber(channel_)); } - void TearDown() override { server_->Shutdown(); } + void TearDown() override { + server_->Shutdown(); + subscriber_->Shutdown(); + } - std::unique_ptr server_; std::ostringstream server_address_; - PublishServiceImpl service_; + std::unique_ptr server_; + SubscriberServiceImpl service_; std::shared_ptr channel_; + + std::unique_ptr subscriber_; }; -TEST_F(End2endTest, CreateTopic) { - grpc::examples::tips::Client client(channel_); - client.CreateTopic(kTopic); +TEST_F(SubscriberTest, TestSubscriber) { + EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, + kSubscriptionName).IsOk()); + + grpc::string topic; + EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, + &topic).IsOk()); + EXPECT_EQ(topic, kTopic); } } // namespace diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index a610e92307a..8dde2aeb5b1 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -263,7 +263,11 @@ }, { "language": "c++", - "name": "tips_client_test" + "name": "tips_publisher_test" + }, + { + "language": "c++", + "name": "tips_subscriber_test" }, { "language": "c++", From 0010cdae47270a22fd4442835261c796ee565900 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Sun, 1 Feb 2015 20:44:33 -0800 Subject: [PATCH 02/28] Add Pull method to subscriber --- examples/tips/subscriber.cc | 23 +++++++++++++++++++++++ examples/tips/subscriber.h | 2 ++ examples/tips/subscriber_test.cc | 21 +++++++++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc index a482ad6263d..2e2370ee2da 100644 --- a/examples/tips/subscriber.cc +++ b/examples/tips/subscriber.cc @@ -81,6 +81,29 @@ Status Subscriber::GetSubscription(const grpc::string& name, return s; } +Status Subscriber::Pull(const grpc::string& name, + grpc::string* data) { + tech::pubsub::PullRequest request; + tech::pubsub::PullResponse response; + ClientContext context; + + request.set_subscription(name); + Status s = stub_->Pull(&context, request, &response); + if (s.IsOk()) { + tech::pubsub::PubsubEvent event = response.pubsub_event(); + if (event.has_message()) { + *data = event.message().data(); + } + tech::pubsub::AcknowledgeRequest ack; + proto2::Empty empty; + ClientContext ack_context; + ack.set_subscription(name); + ack.add_ack_id(response.ack_id()); + stub_->Acknowledge(&ack_context, ack, &empty); + } + return s; +} + } // namespace tips } // namespace examples } // namespace grpc diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h index e0491ff919a..38345c0c5a9 100644 --- a/examples/tips/subscriber.h +++ b/examples/tips/subscriber.h @@ -53,6 +53,8 @@ class Subscriber { Status GetSubscription(const grpc::string& name, grpc::string* topic); + Status Pull(const grpc::string& name, grpc::string* data); + private: std::unique_ptr stub_; }; diff --git a/examples/tips/subscriber_test.cc b/examples/tips/subscriber_test.cc index 4894814252e..4ff93643ae4 100644 --- a/examples/tips/subscriber_test.cc +++ b/examples/tips/subscriber_test.cc @@ -53,6 +53,7 @@ namespace { const char kTopic[] = "test topic"; const char kSubscriptionName[] = "subscription name"; +const char kData[] = "Message data"; class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { public: @@ -72,6 +73,21 @@ class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { return Status::OK; } + Status Pull(ServerContext* context, + const tech::pubsub::PullRequest* request, + tech::pubsub::PullResponse* response) override { + EXPECT_EQ(request->subscription(), kSubscriptionName); + response->set_ack_id("1"); + response->mutable_pubsub_event()->mutable_message()->set_data(kData); + return Status::OK; + } + + Status Acknowledge(ServerContext* context, + const tech::pubsub::AcknowledgeRequest* request, + proto2::Empty* response) override { + return Status::OK; + } + }; class SubscriberTest : public ::testing::Test { @@ -108,10 +124,15 @@ TEST_F(SubscriberTest, TestSubscriber) { EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk()); + grpc::string topic; EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk()); EXPECT_EQ(topic, kTopic); + + grpc::string data; + EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, + &data).IsOk()); } } // namespace From b532ef897340701897975b673d35ef24b5da4825 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Mon, 2 Feb 2015 10:45:17 -0800 Subject: [PATCH 03/28] Impelment full logic of publish and subcribe. --- examples/tips/empty.proto | 2 ++ examples/tips/label.proto | 2 ++ examples/tips/main.cc | 49 +++++++++++++++++++++++--------- examples/tips/publisher.cc | 9 +++--- examples/tips/publisher.h | 10 +++---- examples/tips/pubsub.proto | 2 ++ examples/tips/subscriber.cc | 19 +++++++++---- examples/tips/subscriber.h | 12 ++++---- examples/tips/subscriber_test.cc | 10 +++++++ 9 files changed, 80 insertions(+), 35 deletions(-) diff --git a/examples/tips/empty.proto b/examples/tips/empty.proto index adf66b5e614..86aaa846a24 100644 --- a/examples/tips/empty.proto +++ b/examples/tips/empty.proto @@ -1,3 +1,5 @@ +// This file will be moved to a new location. + syntax = "proto2"; package proto2; diff --git a/examples/tips/label.proto b/examples/tips/label.proto index e93ac9dea30..6ac786f0788 100644 --- a/examples/tips/label.proto +++ b/examples/tips/label.proto @@ -1,3 +1,5 @@ +// This file will be moved to a new location. + // Labels provide a way to associate user-defined metadata with various // objects. Labels may be used to organize objects into non-hierarchical // groups; think metadata tags attached to mp3s. diff --git a/examples/tips/main.cc b/examples/tips/main.cc index 94a0bc7995b..edccd69c284 100644 --- a/examples/tips/main.cc +++ b/examples/tips/main.cc @@ -53,6 +53,7 @@ DEFINE_int32(server_port, 443, "Server port."); DEFINE_string(server_host, "pubsub-staging.googleapis.com", "Server host to connect to"); +DEFINE_string(project_id, "", "GCE project id such as stoked-keyword-656"); DEFINE_string(service_account_key_file, "", "Path to service account json key file."); DEFINE_string(oauth_scope, @@ -61,9 +62,9 @@ DEFINE_string(oauth_scope, namespace { -const char kTopic[] = "/topics/stoked-keyword-656/testtopics"; -const char kSubscriptionName[] = "stoked-keyword-656/testsubscription"; -const char kMessageData[] = "Message Data"; +const char kTopic[] = "testtopics"; +const char kSubscriptionName[] = "testsubscription"; +const char kMessageData[] = "Test Data"; } // namespace @@ -83,10 +84,7 @@ int main(int argc, char** argv) { google::ParseCommandLineFlags(&argc, &argv, true); gpr_log(GPR_INFO, "Start TIPS client"); - const int host_port_buf_size = 1024; - char host_port[host_port_buf_size]; - snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), - FLAGS_server_port); + std::ostringstream ss; std::unique_ptr creds; if (FLAGS_service_account_key_file != "") { @@ -97,9 +95,10 @@ int main(int argc, char** argv) { creds = grpc::CredentialsFactory::ComputeEngineCredentials(); } + ss << FLAGS_server_host << ":" << FLAGS_server_port; std::shared_ptr channel( grpc::CreateTestChannel( - host_port, + ss.str(), FLAGS_server_host, true, // enable SSL true, // use prod roots @@ -108,8 +107,21 @@ int main(int argc, char** argv) { grpc::examples::tips::Publisher publisher(channel); grpc::examples::tips::Subscriber subscriber(channel); - grpc::string topic = kTopic; + GPR_ASSERT(FLAGS_project_id != ""); + ss.str(""); + ss << "/topics/" << FLAGS_project_id << "/" << kTopic; + grpc::string topic = ss.str(); + ss.str(""); + ss << FLAGS_project_id << "/" << kSubscriptionName; + grpc::string subscription_name = ss.str(); + + // Clean up test topic and subcription. + grpc::string subscription_topic; + if (subscriber.GetSubscription( + subscription_name, &subscription_topic).IsOk()) { + subscriber.DeleteSubscription(subscription_name); + } if (publisher.GetTopic(topic).IsOk()) publisher.DeleteTopic(topic); grpc::Status s = publisher.CreateTopic(topic); @@ -122,17 +134,26 @@ int main(int argc, char** argv) { s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = publisher.Publish(topic, kMessageData); - gpr_log(GPR_INFO, "Publish returns code %d, %s", + s = subscriber.CreateSubscription(topic, subscription_name); + gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = subscriber.CreateSubscription(kTopic, kSubscriptionName); - gpr_log(GPR_INFO, "create subscrption returns code %d, %s", + s = publisher.Publish(topic, kMessageData); + gpr_log(GPR_INFO, "Publish %s returns code %d, %s", + kMessageData, s.code(), s.details().c_str()); + GPR_ASSERT(s.IsOk()); + + grpc::string data; + s = subscriber.Pull(subscription_name, &data); + gpr_log(GPR_INFO, "Pull %s", data.c_str()); + + s = subscriber.DeleteSubscription(subscription_name); + gpr_log(GPR_INFO, "Delete subscription returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); - s = publisher.DeleteTopic(kTopic); + s = publisher.DeleteTopic(topic); gpr_log(GPR_INFO, "Delete topic returns code %d, %s", s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); diff --git a/examples/tips/publisher.cc b/examples/tips/publisher.cc index 238ea596a23..027c157da0b 100644 --- a/examples/tips/publisher.cc +++ b/examples/tips/publisher.cc @@ -56,7 +56,7 @@ void Publisher::Shutdown() { stub_.reset(); } -Status Publisher::CreateTopic(grpc::string topic) { +Status Publisher::CreateTopic(const string& topic) { Topic request; Topic response; request.set_name(topic); @@ -73,7 +73,7 @@ Status Publisher::ListTopics() { return stub_->ListTopics(&context, request, &response); } -Status Publisher::GetTopic(grpc::string topic) { +Status Publisher::GetTopic(const string& topic) { GetTopicRequest request; Topic response; ClientContext context; @@ -83,7 +83,7 @@ Status Publisher::GetTopic(grpc::string topic) { return stub_->GetTopic(&context, request, &response); } -Status Publisher::DeleteTopic(grpc::string topic) { +Status Publisher::DeleteTopic(const string& topic) { DeleteTopicRequest request; proto2::Empty response; ClientContext context; @@ -93,8 +93,7 @@ Status Publisher::DeleteTopic(grpc::string topic) { return stub_->DeleteTopic(&context, request, &response); } -Status Publisher::Publish(const grpc::string& topic, - const grpc::string& data) { +Status Publisher::Publish(const string& topic, const string& data) { PublishRequest request; proto2::Empty response; ClientContext context; diff --git a/examples/tips/publisher.h b/examples/tips/publisher.h index a97dbe6de25..b1be4d9dcb0 100644 --- a/examples/tips/publisher.h +++ b/examples/tips/publisher.h @@ -45,15 +45,15 @@ namespace tips { class Publisher { public: - Publisher(std::shared_ptr channel); + Publisher(std::shared_ptr channel); void Shutdown(); - Status CreateTopic(grpc::string topic); - Status GetTopic(grpc::string topic); - Status DeleteTopic(grpc::string topic); + Status CreateTopic(const string& topic); + Status GetTopic(const string& topic); + Status DeleteTopic(const string& topic); Status ListTopics(); - Status Publish(const grpc::string& topic, const grpc::string& data); + Status Publish(const string& topic, const string& data); private: std::unique_ptr stub_; diff --git a/examples/tips/pubsub.proto b/examples/tips/pubsub.proto index 0b3bd5d012a..15ada6063a5 100644 --- a/examples/tips/pubsub.proto +++ b/examples/tips/pubsub.proto @@ -1,3 +1,5 @@ +// This file will be moved to new location. + // Specification of the Pubsub API. syntax = "proto2"; diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc index 2e2370ee2da..6dae3ce3a90 100644 --- a/examples/tips/subscriber.cc +++ b/examples/tips/subscriber.cc @@ -56,8 +56,7 @@ void Subscriber::Shutdown() { stub_.reset(); } -Status Subscriber::CreateSubscription(const grpc::string& topic, - const grpc::string& name) { +Status Subscriber::CreateSubscription(const string& topic, const string& name) { tech::pubsub::Subscription request; tech::pubsub::Subscription response; ClientContext context; @@ -68,8 +67,7 @@ Status Subscriber::CreateSubscription(const grpc::string& topic, return stub_->CreateSubscription(&context, request, &response); } -Status Subscriber::GetSubscription(const grpc::string& name, - grpc::string* topic) { +Status Subscriber::GetSubscription(const string& name, string* topic) { tech::pubsub::GetSubscriptionRequest request; tech::pubsub::Subscription response; ClientContext context; @@ -81,8 +79,17 @@ Status Subscriber::GetSubscription(const grpc::string& name, return s; } -Status Subscriber::Pull(const grpc::string& name, - grpc::string* data) { +Status Subscriber::DeleteSubscription(const string& name) { + tech::pubsub::DeleteSubscriptionRequest request; + proto2::Empty response; + ClientContext context; + + request.set_subscription(name); + + return stub_->DeleteSubscription(&context, request, &response); +} + +Status Subscriber::Pull(const string& name, string* data) { tech::pubsub::PullRequest request; tech::pubsub::PullResponse response; ClientContext context; diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h index 38345c0c5a9..d9911149bb2 100644 --- a/examples/tips/subscriber.h +++ b/examples/tips/subscriber.h @@ -45,15 +45,17 @@ namespace tips { class Subscriber { public: - Subscriber(std::shared_ptr channel); + Subscriber(std::shared_ptr channel); void Shutdown(); - Status CreateSubscription(const grpc::string& topic, - const grpc::string& name); + Status CreateSubscription(const string& topic, + const string& name); - Status GetSubscription(const grpc::string& name, grpc::string* topic); + Status GetSubscription(const string& name, string* topic); - Status Pull(const grpc::string& name, grpc::string* data); + Status DeleteSubscription(const string& name); + + Status Pull(const string& name, string* data); private: std::unique_ptr stub_; diff --git a/examples/tips/subscriber_test.cc b/examples/tips/subscriber_test.cc index 4ff93643ae4..9c46718308b 100644 --- a/examples/tips/subscriber_test.cc +++ b/examples/tips/subscriber_test.cc @@ -73,6 +73,14 @@ class SubscriberServiceImpl : public tech::pubsub::SubscriberService::Service { return Status::OK; } + Status DeleteSubscription( + ServerContext* context, + const tech::pubsub::DeleteSubscriptionRequest* request, + proto2::Empty* response) override { + EXPECT_EQ(request->subscription(), kSubscriptionName); + return Status::OK; + } + Status Pull(ServerContext* context, const tech::pubsub::PullRequest* request, tech::pubsub::PullResponse* response) override { @@ -133,6 +141,8 @@ TEST_F(SubscriberTest, TestSubscriber) { grpc::string data; EXPECT_TRUE(subscriber_->Pull(kSubscriptionName, &data).IsOk()); + + EXPECT_TRUE(subscriber_->DeleteSubscription(kSubscriptionName).IsOk()); } } // namespace From 25e5f67bb95f4c848c003f19272b8c1030efbfe5 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 2 Feb 2015 11:05:01 -0800 Subject: [PATCH 04/28] Removed all instances of == and != in PHP code --- .../lib/Grpc/AbstractSurfaceActiveCall.php | 2 +- src/php/lib/Grpc/ActiveCall.php | 7 +--- .../Grpc/ServerStreamingSurfaceActiveCall.php | 2 +- src/php/tests/interop/interop_client.php | 34 +++++++++---------- 4 files changed, 20 insertions(+), 25 deletions(-) diff --git a/src/php/lib/Grpc/AbstractSurfaceActiveCall.php b/src/php/lib/Grpc/AbstractSurfaceActiveCall.php index 53c7d4cd1a4..83e4719c9a8 100755 --- a/src/php/lib/Grpc/AbstractSurfaceActiveCall.php +++ b/src/php/lib/Grpc/AbstractSurfaceActiveCall.php @@ -44,7 +44,7 @@ abstract class AbstractSurfaceActiveCall { protected function _read() { $response = $this->active_call->read(); - if ($response == null) { + if ($response === null) { return null; } return call_user_func($this->deserialize, $response); diff --git a/src/php/lib/Grpc/ActiveCall.php b/src/php/lib/Grpc/ActiveCall.php index e0ea43ab085..847cfee1ec2 100755 --- a/src/php/lib/Grpc/ActiveCall.php +++ b/src/php/lib/Grpc/ActiveCall.php @@ -66,12 +66,7 @@ class ActiveCall { * @param ByteBuffer $data The data to write */ public function write($data) { - if($this->call->start_write($data, - WRITE_ACCEPTED, - $this->flags) != OP_OK) { - // TODO(mlumish): more useful error - throw new \Exception("Cannot call write after writesDone"); - } + $this->call->start_write($data, WRITE_ACCEPTED, $this->flags); $this->completion_queue->pluck(WRITE_ACCEPTED, Timeval::inf_future()); } diff --git a/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php b/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php index 082f995d8aa..f131d6bab5c 100755 --- a/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php +++ b/src/php/lib/Grpc/ServerStreamingSurfaceActiveCall.php @@ -31,7 +31,7 @@ class ServerStreamingSurfaceActiveCall extends AbstractSurfaceActiveCall { * @return An iterator of response values */ public function responses() { - while(($response = $this->_read()) != null) { + while(($response = $this->_read()) !== null) { yield $response; } } diff --git a/src/php/tests/interop/interop_client.php b/src/php/tests/interop/interop_client.php index 2ff2be7bca0..d1f994a84b6 100755 --- a/src/php/tests/interop/interop_client.php +++ b/src/php/tests/interop/interop_client.php @@ -26,8 +26,8 @@ function hardAssert($value, $error_message) { */ function emptyUnary($stub) { list($result, $status) = $stub->EmptyCall(new grpc\testing\EmptyMessage())->wait(); - hardAssert($status->code == Grpc\STATUS_OK, 'Call did not complete successfully'); - hardAssert($result != null, 'Call completed with a null response'); + hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully'); + hardAssert($result !== null, 'Call completed with a null response'); } /** @@ -49,14 +49,14 @@ function largeUnary($stub) { $request->setPayload($payload); list($result, $status) = $stub->UnaryCall($request)->wait(); - hardAssert($status->code == Grpc\STATUS_OK, 'Call did not complete successfully'); - hardAssert($result != null, 'Call returned a null response'); + hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully'); + hardAssert($result !== null, 'Call returned a null response'); $payload = $result->getPayload(); - hardAssert($payload->getType() == grpc\testing\PayloadType::COMPRESSABLE, + hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE, 'Payload had the wrong type'); - hardAssert(strlen($payload->getBody()) == $response_len, + hardAssert(strlen($payload->getBody()) === $response_len, 'Payload had the wrong length'); - hardAssert($payload->getBody() == str_repeat("\0", $response_len), + hardAssert($payload->getBody() === str_repeat("\0", $response_len), 'Payload had the wrong content'); } @@ -78,8 +78,8 @@ function clientStreaming($stub) { }, $request_lengths); list($result, $status) = $stub->StreamingInputCall($requests)->wait(); - hardAssert($status->code == Grpc\STATUS_OK, 'Call did not complete successfully'); - hardAssert($result->getAggregatedPayloadSize() == 74922, + hardAssert($status->code === Grpc\STATUS_OK, 'Call did not complete successfully'); + hardAssert($result->getAggregatedPayloadSize() === 74922, 'aggregated_payload_size was incorrect'); } @@ -100,15 +100,15 @@ function serverStreaming($stub) { } $call = $stub->StreamingOutputCall($request); - hardAssert($call->getStatus()->code == Grpc\STATUS_OK, + hardAssert($call->getStatus()->code === Grpc\STATUS_OK, 'Call did not complete successfully'); $i = 0; foreach($call->responses() as $value) { hardAssert($i < 4, 'Too many responses'); $payload = $value->getPayload(); - hardAssert($payload->getType() == grpc\testing\PayloadType::COMPRESSABLE, + hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE, 'Payload ' . $i . ' had the wrong type'); - hardAssert(strlen($payload->getBody()) == $sizes[$i], + hardAssert(strlen($payload->getBody()) === $sizes[$i], 'Response ' . $i . ' had the wrong length'); } } @@ -136,16 +136,16 @@ function pingPong($stub) { $call->write($request); $response = $call->read(); - hardAssert($response != null, 'Server returned too few responses'); + hardAssert($response !== null, 'Server returned too few responses'); $payload = $response->getPayload(); - hardAssert($payload->getType() == grpc\testing\PayloadType::COMPRESSABLE, + hardAssert($payload->getType() === grpc\testing\PayloadType::COMPRESSABLE, 'Payload ' . $i . ' had the wrong type'); - hardAssert(strlen($payload->getBody()) == $response_lengths[$i], + hardAssert(strlen($payload->getBody()) === $response_lengths[$i], 'Payload ' . $i . ' had the wrong length'); } $call->writesDone(); - hardAssert($call->read() == null, 'Server returned too many responses'); - hardAssert($call->getStatus()->code == Grpc\STATUS_OK, + hardAssert($call->read() === null, 'Server returned too many responses'); + hardAssert($call->getStatus()->code === Grpc\STATUS_OK, 'Call did not complete successfully'); } From 5accd24a76e439f4e68aa412814ebebf07fbb2f1 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 2 Feb 2015 11:36:56 -0800 Subject: [PATCH 05/28] Removed uses of assertEquals, which internally uses weak comparison --- .../generated_code/GeneratedCodeTest.php | 20 ++--- src/php/tests/unit_tests/EndToEndTest.php | 90 ++++++++----------- .../tests/unit_tests/SecureEndToEndTest.php | 89 ++++++++---------- 3 files changed, 80 insertions(+), 119 deletions(-) diff --git a/src/php/tests/generated_code/GeneratedCodeTest.php b/src/php/tests/generated_code/GeneratedCodeTest.php index 42d25e46141..ee7b8711239 100755 --- a/src/php/tests/generated_code/GeneratedCodeTest.php +++ b/src/php/tests/generated_code/GeneratedCodeTest.php @@ -17,9 +17,9 @@ class GeneratedCodeTest extends PHPUnit_Framework_TestCase { $div_arg->setDividend(7); $div_arg->setDivisor(4); list($response, $status) = self::$client->Div($div_arg)->wait(); - $this->assertEquals(1, $response->getQuotient()); - $this->assertEquals(3, $response->getRemainder()); - $this->assertEquals(\Grpc\STATUS_OK, $status->code); + $this->assertSame(1, $response->getQuotient()); + $this->assertSame(3, $response->getRemainder()); + $this->assertSame(\Grpc\STATUS_OK, $status->code); } public function testServerStreaming() { @@ -31,9 +31,9 @@ class GeneratedCodeTest extends PHPUnit_Framework_TestCase { return $num->getNum(); }; $values = array_map($extract_num, $result_array); - $this->assertEquals([1, 1, 2, 3, 5, 8, 13], $values); + $this->assertSame([1, 1, 2, 3, 5, 8, 13], $values); $status = $call->getStatus(); - $this->assertEquals(\Grpc\STATUS_OK, $status->code); + $this->assertSame(\Grpc\STATUS_OK, $status->code); } public function testClientStreaming() { @@ -46,8 +46,8 @@ class GeneratedCodeTest extends PHPUnit_Framework_TestCase { }; $call = self::$client->Sum($num_iter()); list($response, $status) = $call->wait(); - $this->assertEquals(21, $response->getNum()); - $this->assertEquals(\Grpc\STATUS_OK, $status->code); + $this->assertSame(21, $response->getNum()); + $this->assertSame(\Grpc\STATUS_OK, $status->code); } public function testBidiStreaming() { @@ -58,11 +58,11 @@ class GeneratedCodeTest extends PHPUnit_Framework_TestCase { $div_arg->setDivisor(2); $call->write($div_arg); $response = $call->read(); - $this->assertEquals($i, $response->getQuotient()); - $this->assertEquals(1, $response->getRemainder()); + $this->assertSame($i, $response->getQuotient()); + $this->assertSame(1, $response->getRemainder()); } $call->writesDone(); $status = $call->getStatus(); - $this->assertEquals(\Grpc\STATUS_OK, $status->code); + $this->assertSame(\Grpc\STATUS_OK, $status->code); } } \ No newline at end of file diff --git a/src/php/tests/unit_tests/EndToEndTest.php b/src/php/tests/unit_tests/EndToEndTest.php index 78c5e9f93bf..a2d8029b047 100755 --- a/src/php/tests/unit_tests/EndToEndTest.php +++ b/src/php/tests/unit_tests/EndToEndTest.php @@ -24,62 +24,52 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ 'dummy_method', $deadline); $tag = 1; - $this->assertEquals(Grpc\CALL_OK, - $call->invoke($this->client_queue, - $tag, - $tag)); - + $call->invoke($this->client_queue, $tag, $tag); $server_tag = 2; $call->writes_done($tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // check that a server rpc new was received $this->server->start(); $this->server->request_call($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type); + $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type); $server_call = $event->call; $this->assertNotNull($server_call); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_accept($this->server_queue, - $server_tag)); + $server_call->server_accept($this->server_queue, $server_tag); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_end_initial_metadata()); + $server_call->server_end_initial_metadata(); // the server sends the status - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write_status(Grpc\STATUS_OK, - $status_text, - $server_tag)); + $server_call->start_write_status(Grpc\STATUS_OK, $status_text, $server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the client gets CLIENT_METADATA_READ $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type); + $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type); // the client gets FINISHED $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; - $this->assertEquals(Grpc\STATUS_OK, $status->code); - $this->assertEquals($status_text, $status->details); + $this->assertSame(Grpc\STATUS_OK, $status->code); + $this->assertSame($status_text, $status->details); // and the server gets FINISHED $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; unset($call); @@ -96,10 +86,7 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ 'dummy_method', $deadline); $tag = 1; - $this->assertEquals(Grpc\CALL_OK, - $call->invoke($this->client_queue, - $tag, - $tag)); + $call->invoke($this->client_queue, $tag, $tag); $server_tag = 2; @@ -107,76 +94,69 @@ class EndToEndTest extends PHPUnit_Framework_TestCase{ $call->start_write($req_text, $tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type); + $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type); // check that a server rpc new was received $this->server->start(); $this->server->request_call($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type); + $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type); $server_call = $event->call; $this->assertNotNull($server_call); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_accept($this->server_queue, - $server_tag)); + $server_call->server_accept($this->server_queue, $server_tag); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_end_initial_metadata()); + $server_call->server_end_initial_metadata(); // start the server read $server_call->start_read($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\READ, $event->type); - $this->assertEquals($req_text, $event->data); + $this->assertSame(Grpc\READ, $event->type); + $this->assertSame($req_text, $event->data); // the server replies - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write($reply_text, $server_tag)); + $server_call->start_write($reply_text, $server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type); + $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type); // the client reads the metadata $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type); + $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type); // the client reads the reply $call->start_read($tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\READ, $event->type); - $this->assertEquals($reply_text, $event->data); + $this->assertSame(Grpc\READ, $event->type); + $this->assertSame($reply_text, $event->data); // the client sends writes done $call->writes_done($tag); $event = $this->client_queue->next($deadline); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the server sends the status - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write_status(GRPC\STATUS_OK, - $status_text, - $server_tag)); + $server_call->start_write_status(GRPC\STATUS_OK, $status_text, $server_tag); $event = $this->server_queue->next($deadline); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the client gets FINISHED $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; - $this->assertEquals(Grpc\STATUS_OK, $status->code); - $this->assertEquals($status_text, $status->details); + $this->assertSame(Grpc\STATUS_OK, $status->code); + $this->assertSame($status_text, $status->details); // and the server gets FINISHED $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); unset($call); unset($server_call); diff --git a/src/php/tests/unit_tests/SecureEndToEndTest.php b/src/php/tests/unit_tests/SecureEndToEndTest.php index 7c3ad8a07c6..7ba4984bd86 100755 --- a/src/php/tests/unit_tests/SecureEndToEndTest.php +++ b/src/php/tests/unit_tests/SecureEndToEndTest.php @@ -36,59 +36,50 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{ 'dummy_method', $deadline); $tag = 1; - $this->assertEquals(Grpc\CALL_OK, - $call->invoke($this->client_queue, - $tag, - $tag)); + $call->invoke($this->client_queue, $tag, $tag); $server_tag = 2; $call->writes_done($tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // check that a server rpc new was received $this->server->request_call($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type); + $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type); $server_call = $event->call; $this->assertNotNull($server_call); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_accept($this->server_queue, - $server_tag)); + $server_call->server_accept($this->server_queue, $server_tag); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_end_initial_metadata()); + $server_call->server_end_initial_metadata(); // the server sends the status - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write_status(Grpc\STATUS_OK, - $status_text, - $server_tag)); + $server_call->start_write_status(Grpc\STATUS_OK, $status_text, $server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the client gets CLIENT_METADATA_READ $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type); + $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type); // the client gets FINISHED $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; - $this->assertEquals(Grpc\STATUS_OK, $status->code); - $this->assertEquals($status_text, $status->details); + $this->assertSame(Grpc\STATUS_OK, $status->code); + $this->assertSame($status_text, $status->details); // and the server gets FINISHED $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; unset($call); @@ -106,10 +97,7 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{ 'dummy_method', $deadline); $tag = 1; - $this->assertEquals(Grpc\CALL_OK, - $call->invoke($this->client_queue, - $tag, - $tag)); + $call->invoke($this->client_queue, $tag, $tag); $server_tag = 2; @@ -117,75 +105,68 @@ class SecureEndToEndTest extends PHPUnit_Framework_TestCase{ $call->start_write($req_text, $tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type); + $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type); // check that a server rpc new was received $this->server->request_call($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\SERVER_RPC_NEW, $event->type); + $this->assertSame(Grpc\SERVER_RPC_NEW, $event->type); $server_call = $event->call; $this->assertNotNull($server_call); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_accept($this->server_queue, - $server_tag)); + $server_call->server_accept($this->server_queue, $server_tag); - $this->assertEquals(Grpc\CALL_OK, - $server_call->server_end_initial_metadata()); + $server_call->server_end_initial_metadata(); // start the server read $server_call->start_read($server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\READ, $event->type); - $this->assertEquals($req_text, $event->data); + $this->assertSame(Grpc\READ, $event->type); + $this->assertSame($req_text, $event->data); // the server replies - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write($reply_text, $server_tag)); + $server_call->start_write($reply_text, $server_tag); $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\WRITE_ACCEPTED, $event->type); + $this->assertSame(Grpc\WRITE_ACCEPTED, $event->type); // the client reads the metadata $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\CLIENT_METADATA_READ, $event->type); + $this->assertSame(Grpc\CLIENT_METADATA_READ, $event->type); // the client reads the reply $call->start_read($tag); $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\READ, $event->type); - $this->assertEquals($reply_text, $event->data); + $this->assertSame(Grpc\READ, $event->type); + $this->assertSame($reply_text, $event->data); // the client sends writes done $call->writes_done($tag); $event = $this->client_queue->next($deadline); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the server sends the status - $this->assertEquals(Grpc\CALL_OK, - $server_call->start_write_status(GRPC\STATUS_OK, - $status_text, - $server_tag)); + $server_call->start_write_status(GRPC\STATUS_OK, $status_text, $server_tag); $event = $this->server_queue->next($deadline); - $this->assertEquals(Grpc\FINISH_ACCEPTED, $event->type); - $this->assertEquals(Grpc\OP_OK, $event->data); + $this->assertSame(Grpc\FINISH_ACCEPTED, $event->type); + $this->assertSame(Grpc\OP_OK, $event->data); // the client gets FINISHED $event = $this->client_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); $status = $event->data; - $this->assertEquals(Grpc\STATUS_OK, $status->code); - $this->assertEquals($status_text, $status->details); + $this->assertSame(Grpc\STATUS_OK, $status->code); + $this->assertSame($status_text, $status->details); // and the server gets FINISHED $event = $this->server_queue->next($deadline); $this->assertNotNull($event); - $this->assertEquals(Grpc\FINISHED, $event->type); + $this->assertSame(Grpc\FINISHED, $event->type); unset($call); unset($server_call); From d9ba1db7fa94175e5c9c4df03ac9f540719bdfb9 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 2 Feb 2015 13:38:08 -0800 Subject: [PATCH 06/28] Removed assertEquals from TimevalTest --- src/php/tests/unit_tests/TimevalTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/php/tests/unit_tests/TimevalTest.php b/src/php/tests/unit_tests/TimevalTest.php index 6af9fba0431..067254b55bf 100755 --- a/src/php/tests/unit_tests/TimevalTest.php +++ b/src/php/tests/unit_tests/TimevalTest.php @@ -2,7 +2,7 @@ class TimevalTest extends PHPUnit_Framework_TestCase{ public function testCompareSame() { $zero = Grpc\Timeval::zero(); - $this->assertEquals(0, Grpc\Timeval::compare($zero, $zero)); + $this->assertSame(0, Grpc\Timeval::compare($zero, $zero)); } public function testPastIsLessThanZero() { From 975a07b9494f3ea48ab0474f8554947018ca32f3 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 2 Feb 2015 14:10:42 -0800 Subject: [PATCH 07/28] Switched Protobuf-PHP references to my fork, removed references to git-on-borg --- src/php/README.md | 27 ++++++---------- tools/dockerfile/grpc_base/README.md | 3 +- tools/dockerfile/grpc_java/README.md | 2 +- tools/dockerfile/grpc_php/README.md | 2 +- tools/dockerfile/grpc_php_base/Dockerfile | 6 +--- tools/dockerfile/grpc_ruby/README.md | 2 +- tools/gce_setup/grpc_docker.sh | 2 +- tools/gce_setup/new_grpc_docker_builder.sh | 1 - .../new_grpc_docker_builder_on_startup.sh | 7 +---- tools/gce_setup/shared_startup_funcs.sh | 31 ------------------- 10 files changed, 17 insertions(+), 66 deletions(-) diff --git a/src/php/README.md b/src/php/README.md index 176bcfa0288..620c68fd7b5 100755 --- a/src/php/README.md +++ b/src/php/README.md @@ -7,31 +7,25 @@ Directory structure is as generated by the PHP utility ## ENVIRONMENT -To build a PHP environment that works with this extension, download and extract -PHP 5.5 (5.6 may also work), configure it, and install it: +Install `php5` and `php5-dev`. -```bash -apt-get install libxml2 libxml2-dev -curl http://php.net/get/php-5.5.16.tar.gz -tar -xf php-5.5.16.tar.gz -cd php-5.5.16 -./configure --with-zlib=/usr --with-libxml-dir=ext/libxml --with-openssl=/usr/local/ssl -make -make install -``` +To run the tests, additionally install `php5-readline` and `phpunit`. + +Alternatively, build and install PHP 5.5 or later from source with standard +configuration options. -To also download and install the patched protoc and PHP code generator: +To also download and install protoc and the PHP code generator. ```bash apt-get install -y procps curl -sSL https://get.rvm.io | sudo bash -s stable --ruby -git clone sso://team/one-platform-grpc-team/protobuf +git clone git@github.com:google/protobuf.git cd protobuf ./configure make make install -git clone sso://team/one-platform-grpc-team/grpc-php-protobuf-php -cd grpc-php-protobuf-php +git clone git@github.com:murgatroid99/Protobuf-PHP.git +cd Protobuf-PHP rake pear:package version=1.0 pear install Protobuf-1.0.tgz ``` @@ -52,5 +46,4 @@ This repo now has PHPUnit tests, which can by run by executing There is also a generated code test (`./bin/run_gen_code_test.sh`), which tests the stub `./tests/generated_code/math.php` against a running localhost server serving the math service. That stub is generated from -`./tests/generated_code/math.proto` with the head of the repo -`sso://team/one-platform-grpc-team/grpc-php-protobuf-php`. +`./tests/generated_code/math.proto`. diff --git a/tools/dockerfile/grpc_base/README.md b/tools/dockerfile/grpc_base/README.md index 4745141fc49..e3b5f2ef373 100644 --- a/tools/dockerfile/grpc_base/README.md +++ b/tools/dockerfile/grpc_base/README.md @@ -4,8 +4,7 @@ Base GRPC Dockerfile Dockerfile for creating the base gRPC development Docker instance. For now, this assumes that the development will be done on GCE instances, with source code on Git-on-Borg. -As of 2014/09/29, it includes +As of 2015/02/02, it includes - git - some useful tools like curl, emacs, strace, telnet etc -- downloads the gerrit-compute-tools and installs the script that allows access to gerrit when on git-on-borg - a patched version of protoc, to allow protos with stream tags to work diff --git a/tools/dockerfile/grpc_java/README.md b/tools/dockerfile/grpc_java/README.md index 2da2393befb..808f0fc5f38 100644 --- a/tools/dockerfile/grpc_java/README.md +++ b/tools/dockerfile/grpc_java/README.md @@ -5,5 +5,5 @@ Dockerfile for creating the Java development image As of 2014/12 this - is based on the gRPC Java base - - pulls from gRPC Java on git-on-borg + - pulls from gRPC Java on GitHub - installs it and runs the tests \ No newline at end of file diff --git a/tools/dockerfile/grpc_php/README.md b/tools/dockerfile/grpc_php/README.md index a37389ff600..f3c332b8b30 100644 --- a/tools/dockerfile/grpc_php/README.md +++ b/tools/dockerfile/grpc_php/README.md @@ -5,6 +5,6 @@ Dockerfile for creating the PHP development instances As of 2014/10 this - is based on the GRPC PHP base -- adds a pull of the HEAD GRPC PHP source from git-on-borg +- adds a pull of the HEAD GRPC PHP source from GitHub - it builds it - runs the tests, i.e, the image won't be created if the tests don't pass diff --git a/tools/dockerfile/grpc_php_base/Dockerfile b/tools/dockerfile/grpc_php_base/Dockerfile index 47266a310e3..ef58f3a887c 100644 --- a/tools/dockerfile/grpc_php_base/Dockerfile +++ b/tools/dockerfile/grpc_php_base/Dockerfile @@ -45,13 +45,9 @@ RUN cd /var/local \ && ./configure --with-zlib=/usr --with-libxml-dir=ext/libxml \ && make -j12 && make install -# Start the daemon that allows access to the protected git-on-borg repos -RUN git clone https://gerrit.googlesource.com/gcompute-tools /var/local/git/gcompute-tools -RUN /var/local/git/gcompute-tools/git-cookie-authdaemon - # Download the patched PHP protobuf so that PHP gRPC clients can be generated # from proto3 schemas. -RUN git clone https://team.googlesource.com/one-platform-grpc-team/grpc-php-protobuf-php /var/local/git/protobuf-php +RUN git clone git@github.com:murgatroid99/Protobuf-PHP.git /var/local/git/protobuf-php # Install ruby (via RVM) as ruby tools are dependencies for building Protobuf # PHP extensions. diff --git a/tools/dockerfile/grpc_ruby/README.md b/tools/dockerfile/grpc_ruby/README.md index 51fb2f59704..eaa8382f1c7 100644 --- a/tools/dockerfile/grpc_ruby/README.md +++ b/tools/dockerfile/grpc_ruby/README.md @@ -5,6 +5,6 @@ Dockerfile for creating the Ruby development instances As of 2014/10 this - is based on the GRPC Ruby base -- adds a pull of the HEAD gRPC Ruby source from git-on-borg +- adds a pull of the HEAD gRPC Ruby source from GitHub - it builds it - runs the tests, i.e, the image won't be created if the tests don't pass diff --git a/tools/gce_setup/grpc_docker.sh b/tools/gce_setup/grpc_docker.sh index a97cc88aee8..bb451141fcf 100755 --- a/tools/gce_setup/grpc_docker.sh +++ b/tools/gce_setup/grpc_docker.sh @@ -895,7 +895,7 @@ grpc_cloud_prod_gen_java_cmd() { # constructs the full dockerized php interop test cmd. # -# TODO(mlumish): update this to use the script once that's on git-on-borg +# TODO(mlumish): update this to use the script once that's on git # # call-seq: # flags= .... # generic flags to include the command diff --git a/tools/gce_setup/new_grpc_docker_builder.sh b/tools/gce_setup/new_grpc_docker_builder.sh index 5d4fc361ade..ea36cc5606b 100755 --- a/tools/gce_setup/new_grpc_docker_builder.sh +++ b/tools/gce_setup/new_grpc_docker_builder.sh @@ -86,7 +86,6 @@ add_instance() { [[ -n $the_address ]] && address_flag="--address $the_address" local the_image='container-vm-v20140925' local scopes='compute-rw storage-full' - scopes+=' https://www.googleapis.com/auth/gerritcodereview' scopes+=' https://www.googleapis.com/auth/xapi.zoo' gcloud --project $project compute instances create $instance \ $address_flag \ diff --git a/tools/gce_setup/new_grpc_docker_builder_on_startup.sh b/tools/gce_setup/new_grpc_docker_builder_on_startup.sh index 87e8aac1e72..4b20a8be7d7 100755 --- a/tools/gce_setup/new_grpc_docker_builder_on_startup.sh +++ b/tools/gce_setup/new_grpc_docker_builder_on_startup.sh @@ -3,8 +3,7 @@ # # A grpc-docker GCE machine is based on docker container image. # -# On startup, it copies the grpc dockerfiles to a local directory, and update its address -# so that the docker containers within it have git-on-borg-access. +# On startup, it copies the grpc dockerfiles to a local directory, and update its address. # _load_metadata curls a metadata url _load_metadata() { @@ -54,10 +53,6 @@ main() { # Install git and emacs apt-get update && apt-get install -y git emacs || return 1 - # Enable access to git repos on git-on-borg - local git_root='/var/local/git' - install_gob_daemon $git_root/gerrit-gcompute-tools || return 1 - # Startup the docker registry grpc_docker_launch_registry && grpc_docker_pull_known diff --git a/tools/gce_setup/shared_startup_funcs.sh b/tools/gce_setup/shared_startup_funcs.sh index 3300eb257de..3410a2a2c8a 100755 --- a/tools/gce_setup/shared_startup_funcs.sh +++ b/tools/gce_setup/shared_startup_funcs.sh @@ -251,37 +251,6 @@ update_address_to() { } } -# Allows instances to checkout repos on git-on-borg. -# -install_gob_daemon() { - local gob_dir=$1 - [[ -n $gob_dir ]] || { echo "missing args: gob_dir" >&2; return 1; } - - local gob_repo=$2 - [[ -n $gob_repo ]] || gob_repo='https://gerrit.googlesource.com/gcompute-tools/' - - if [[ -e $gob_dir ]] - then - rm -fv $gob_dir || { - echo "could not remove existing git repo at $gob_dir" >&2 - return 1 - } - fi - - git clone $gob_repo $gob_dir || { echo "failed to pull gerrit cookie repo" >&2; return 1; } - local startup_script=/etc/profile.d/gob_cookie_daemon.sh - - cat <> $startup_script -#!/bin/bash - -$gob_dir/git-cookie-authdaemon - -EOF - - chmod 755 $startup_script - $startup_script -} - # grpc_docker_add_docker_group # # Adds a docker group, restarts docker, relaunches the docker registry From 851f591956ee908347d64bf2ed6d137b963e4d9b Mon Sep 17 00:00:00 2001 From: Donna Dionne Date: Mon, 2 Feb 2015 15:06:42 -0800 Subject: [PATCH 08/28] Adding timeout for each test run so that failed tests do not block the running of the rest of the tests. --- tools/gce_setup/interop_test_runner.sh | 42 +++++++++++++++++++++----- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/tools/gce_setup/interop_test_runner.sh b/tools/gce_setup/interop_test_runner.sh index 1c0d82095c4..8ad5e82f1e6 100755 --- a/tools/gce_setup/interop_test_runner.sh +++ b/tools/gce_setup/interop_test_runner.sh @@ -1,4 +1,33 @@ #!/bin/bash +thisfile=$(readlink -ne "${BASH_SOURCE[0]}") + +run_test() { + local test_case=$1 + shift + local client=$1 + shift + local server=$1 + if grpc_interop_test $test_case grpc-docker-testclients $client grpc-docker-server $server + then + echo "$test_case $client $server passed" >> /tmp/interop_result.txt + else + echo "$test_case $client $server failed" >> /tmp/interop_result.txt + fi +} + +time_out() { + local test_case=$1 + shift + local client=$1 + shift + local server=$1 + if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + if ! timeout 20s bash -l -c "source $thisfile && run_test $test_case $client $server" + then + echo "$test_case $client $server timed out" >> /tmp/interop_result.txt + fi + fi +} main() { source grpc_docker.sh @@ -11,17 +40,14 @@ main() { do for server in "${servers[@]}" do - if grpc_interop_test $test_case grpc-docker-testclients $client grpc-docker-server $server - then - echo "$test_case $client $server passed" >> /tmp/interop_result.txt - else - echo "$test_case $client $server failed" >> /tmp/interop_result.txt - fi + time_out $test_case $client $server done done done - gsutil cp /tmp/interop_result.txt gs://stoked-keyword-656-output/interop_result.txt - rm /tmp/interop_result.txt + if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + gsutil cp /tmp/interop_result.txt gs://stoked-keyword-656-output/interop_result.txt + rm /tmp/interop_result.txt + fi } set -x From f94838b0a31683147c673d37d7904ac9ca7f91d3 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Mon, 2 Feb 2015 16:56:46 -0800 Subject: [PATCH 09/28] Make several python scripts explicitly python2.7 I tried actually doing a build on my home desktop, and none of these run with python 3.3, which is /usr/bin/python on my home desktop. --- test/core/end2end/gen_build_json.py | 2 +- tools/buildgen/mako_renderer.py | 2 +- tools/run_tests/run_tests.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/end2end/gen_build_json.py b/test/core/end2end/gen_build_json.py index 2c4368fe767..e28dbdb85d8 100755 --- a/test/core/end2end/gen_build_json.py +++ b/test/core/end2end/gen_build_json.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2.7 """Generates the appropriate build.json data for all the end2end tests.""" diff --git a/tools/buildgen/mako_renderer.py b/tools/buildgen/mako_renderer.py index 29c7cf03074..18f6eeaba6c 100755 --- a/tools/buildgen/mako_renderer.py +++ b/tools/buildgen/mako_renderer.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2.7 """Simple Mako renderer. diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 8cc029e3ccf..280c3f05cb9 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2.7 """Run tests in parallel.""" import argparse From 4d33501a2ee70a6f774a900fb641a934d7dc84b8 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Tue, 3 Feb 2015 05:17:12 +0100 Subject: [PATCH 10/28] Cleaning out remains of google3. --- test/core/end2end/README | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/core/end2end/README b/test/core/end2end/README index 31598b61b82..59daec45d00 100644 --- a/test/core/end2end/README +++ b/test/core/end2end/README @@ -5,6 +5,3 @@ To add a new test or fixture: - add the code to the relevant directory - update gen_build_json.py to reflect the change - regenerate projects -// MOE:begin_strip -- update net/grpc/c/BUILD to reflect the change -// MOE:end_strip \ No newline at end of file From 405392c2e8b7b9dcde7c47fae1607a3a26635e6f Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 10:28:39 -0800 Subject: [PATCH 11/28] fixed typos and add ListTopics implementation. --- examples/tips/main.cc | 16 ++++++++++++++-- examples/tips/publisher.cc | 27 +++++++++++++++++++++------ examples/tips/publisher.h | 11 ++++++----- examples/tips/publisher_test.cc | 15 +++++++++++++-- examples/tips/pubsub.proto | 2 +- examples/tips/subscriber.cc | 10 ++++++---- examples/tips/subscriber.h | 10 +++++----- examples/tips/subscriber_test.cc | 3 --- 8 files changed, 66 insertions(+), 28 deletions(-) diff --git a/examples/tips/main.cc b/examples/tips/main.cc index edccd69c284..df9d984ae17 100644 --- a/examples/tips/main.cc +++ b/examples/tips/main.cc @@ -69,7 +69,7 @@ const char kMessageData[] = "Test Data"; } // namespace grpc::string GetServiceAccountJsonKey() { - static grpc::string json_key; + grpc::string json_key; if (json_key.empty()) { std::ifstream json_key_file(FLAGS_service_account_key_file); std::stringstream key_stream; @@ -116,7 +116,7 @@ int main(int argc, char** argv) { ss << FLAGS_project_id << "/" << kSubscriptionName; grpc::string subscription_name = ss.str(); - // Clean up test topic and subcription. + // Clean up test topic and subcription if they exist before. grpc::string subscription_topic; if (subscriber.GetSubscription( subscription_name, &subscription_topic).IsOk()) { @@ -134,6 +134,18 @@ int main(int argc, char** argv) { s.code(), s.details().c_str()); GPR_ASSERT(s.IsOk()); + std::vector topics; + s = publisher.ListTopics(FLAGS_project_id, &topics); + gpr_log(GPR_INFO, "List topic returns code %d, %s", + s.code(), s.details().c_str()); + bool topic_found = false; + for (unsigned int i = 0; i < topics.size(); i++) { + if (topics[i] == topic) topic_found = true; + gpr_log(GPR_INFO, "topic: %s", topics[i].c_str()); + } + GPR_ASSERT(s.IsOk()); + GPR_ASSERT(topic_found); + s = subscriber.CreateSubscription(topic, subscription_name); gpr_log(GPR_INFO, "create subscrption returns code %d, %s", s.code(), s.details().c_str()); diff --git a/examples/tips/publisher.cc b/examples/tips/publisher.cc index 027c157da0b..085e6c5b6f8 100644 --- a/examples/tips/publisher.cc +++ b/examples/tips/publisher.cc @@ -31,6 +31,8 @@ * */ +#include + #include #include "examples/tips/publisher.h" @@ -56,7 +58,7 @@ void Publisher::Shutdown() { stub_.reset(); } -Status Publisher::CreateTopic(const string& topic) { +Status Publisher::CreateTopic(const grpc::string& topic) { Topic request; Topic response; request.set_name(topic); @@ -65,15 +67,28 @@ Status Publisher::CreateTopic(const string& topic) { return stub_->CreateTopic(&context, request, &response); } -Status Publisher::ListTopics() { +Status Publisher::ListTopics(const grpc::string& project_id, + std::vector* topics) { ListTopicsRequest request; ListTopicsResponse response; ClientContext context; - return stub_->ListTopics(&context, request, &response); + std::stringstream ss; + ss << "cloud.googleapis.com/project in (/projects/" << project_id << ")"; + request.set_query(ss.str()); + + Status s = stub_->ListTopics(&context, request, &response); + + tech::pubsub::Topic topic; + for (int i = 0; i < response.topic_size(); i++) { + topic = response.topic(i); + topics->push_back(topic.name()); + } + + return s; } -Status Publisher::GetTopic(const string& topic) { +Status Publisher::GetTopic(const grpc::string& topic) { GetTopicRequest request; Topic response; ClientContext context; @@ -83,7 +98,7 @@ Status Publisher::GetTopic(const string& topic) { return stub_->GetTopic(&context, request, &response); } -Status Publisher::DeleteTopic(const string& topic) { +Status Publisher::DeleteTopic(const grpc::string& topic) { DeleteTopicRequest request; proto2::Empty response; ClientContext context; @@ -93,7 +108,7 @@ Status Publisher::DeleteTopic(const string& topic) { return stub_->DeleteTopic(&context, request, &response); } -Status Publisher::Publish(const string& topic, const string& data) { +Status Publisher::Publish(const grpc::string& topic, const grpc::string& data) { PublishRequest request; proto2::Empty response; ClientContext context; diff --git a/examples/tips/publisher.h b/examples/tips/publisher.h index b1be4d9dcb0..d8d73538264 100644 --- a/examples/tips/publisher.h +++ b/examples/tips/publisher.h @@ -48,12 +48,13 @@ class Publisher { Publisher(std::shared_ptr channel); void Shutdown(); - Status CreateTopic(const string& topic); - Status GetTopic(const string& topic); - Status DeleteTopic(const string& topic); - Status ListTopics(); + Status CreateTopic(const grpc::string& topic); + Status GetTopic(const grpc::string& topic); + Status DeleteTopic(const grpc::string& topic); + Status ListTopics(const grpc::string& project_id, + std::vector* topics); - Status Publish(const string& topic, const string& data); + Status Publish(const grpc::string& topic, const grpc::string& data); private: std::unique_ptr stub_; diff --git a/examples/tips/publisher_test.cc b/examples/tips/publisher_test.cc index 7f845fed230..cb949e96fac 100644 --- a/examples/tips/publisher_test.cc +++ b/examples/tips/publisher_test.cc @@ -51,6 +51,7 @@ namespace grpc { namespace testing { namespace { +const char kProjectId[] = "project id"; const char kTopic[] = "test topic"; const char kMessageData[] = "test message data"; @@ -80,7 +81,11 @@ class PublisherServiceImpl : public tech::pubsub::PublisherService::Service { Status ListTopics(ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request, ::tech::pubsub::ListTopicsResponse* response) override { - return Status::OK; + std::stringstream ss; + ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; + EXPECT_EQ(request->query(), ss.str()); + response->add_topic()->set_name(kTopic); + return Status::OK; } Status DeleteTopic(ServerContext* context, @@ -124,9 +129,15 @@ class PublisherTest : public ::testing::Test { TEST_F(PublisherTest, TestPublisher) { EXPECT_TRUE(publisher_->CreateTopic(kTopic).IsOk()); + EXPECT_TRUE(publisher_->Publish(kTopic, kMessageData).IsOk()); + EXPECT_TRUE(publisher_->GetTopic(kTopic).IsOk()); - EXPECT_TRUE(publisher_->ListTopics().IsOk()); + + std::vector topics; + EXPECT_TRUE(publisher_->ListTopics(kProjectId, &topics).IsOk()); + EXPECT_EQ(topics.size(), 1); + EXPECT_EQ(topics[0], kTopic); } } // namespace diff --git a/examples/tips/pubsub.proto b/examples/tips/pubsub.proto index 15ada6063a5..a2dd2f5ca8e 100644 --- a/examples/tips/pubsub.proto +++ b/examples/tips/pubsub.proto @@ -1,4 +1,4 @@ -// This file will be moved to new location. +// This file will be moved to a new location. // Specification of the Pubsub API. diff --git a/examples/tips/subscriber.cc b/examples/tips/subscriber.cc index 6dae3ce3a90..c0673223ae8 100644 --- a/examples/tips/subscriber.cc +++ b/examples/tips/subscriber.cc @@ -56,7 +56,8 @@ void Subscriber::Shutdown() { stub_.reset(); } -Status Subscriber::CreateSubscription(const string& topic, const string& name) { +Status Subscriber::CreateSubscription(const grpc::string& topic, + const grpc::string& name) { tech::pubsub::Subscription request; tech::pubsub::Subscription response; ClientContext context; @@ -67,7 +68,8 @@ Status Subscriber::CreateSubscription(const string& topic, const string& name) { return stub_->CreateSubscription(&context, request, &response); } -Status Subscriber::GetSubscription(const string& name, string* topic) { +Status Subscriber::GetSubscription(const grpc::string& name, + grpc::string* topic) { tech::pubsub::GetSubscriptionRequest request; tech::pubsub::Subscription response; ClientContext context; @@ -79,7 +81,7 @@ Status Subscriber::GetSubscription(const string& name, string* topic) { return s; } -Status Subscriber::DeleteSubscription(const string& name) { +Status Subscriber::DeleteSubscription(const grpc::string& name) { tech::pubsub::DeleteSubscriptionRequest request; proto2::Empty response; ClientContext context; @@ -89,7 +91,7 @@ Status Subscriber::DeleteSubscription(const string& name) { return stub_->DeleteSubscription(&context, request, &response); } -Status Subscriber::Pull(const string& name, string* data) { +Status Subscriber::Pull(const grpc::string& name, grpc::string* data) { tech::pubsub::PullRequest request; tech::pubsub::PullResponse response; ClientContext context; diff --git a/examples/tips/subscriber.h b/examples/tips/subscriber.h index d9911149bb2..ed706ff170b 100644 --- a/examples/tips/subscriber.h +++ b/examples/tips/subscriber.h @@ -48,14 +48,14 @@ class Subscriber { Subscriber(std::shared_ptr channel); void Shutdown(); - Status CreateSubscription(const string& topic, - const string& name); + Status CreateSubscription(const grpc::string& topic, + const grpc::string& name); - Status GetSubscription(const string& name, string* topic); + Status GetSubscription(const grpc::string& name, grpc::string* topic); - Status DeleteSubscription(const string& name); + Status DeleteSubscription(const grpc::string& name); - Status Pull(const string& name, string* data); + Status Pull(const grpc::string& name, grpc::string* data); private: std::unique_ptr stub_; diff --git a/examples/tips/subscriber_test.cc b/examples/tips/subscriber_test.cc index 9c46718308b..595a6a13a13 100644 --- a/examples/tips/subscriber_test.cc +++ b/examples/tips/subscriber_test.cc @@ -45,8 +45,6 @@ #include "test/core/util/port.h" #include "test/core/util/test_config.h" -using grpc::ChannelInterface; - namespace grpc { namespace testing { namespace { @@ -132,7 +130,6 @@ TEST_F(SubscriberTest, TestSubscriber) { EXPECT_TRUE(subscriber_->CreateSubscription(kTopic, kSubscriptionName).IsOk()); - grpc::string topic; EXPECT_TRUE(subscriber_->GetSubscription(kSubscriptionName, &topic).IsOk()); From cde34e0b5d3f699405587f5f847b05d1b90ca5a9 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 10:51:24 -0800 Subject: [PATCH 12/28] change stringstream to ostringstream. --- examples/tips/publisher.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tips/publisher.cc b/examples/tips/publisher.cc index 085e6c5b6f8..eae8731139c 100644 --- a/examples/tips/publisher.cc +++ b/examples/tips/publisher.cc @@ -73,7 +73,7 @@ Status Publisher::ListTopics(const grpc::string& project_id, ListTopicsResponse response; ClientContext context; - std::stringstream ss; + std::ostringstream ss; ss << "cloud.googleapis.com/project in (/projects/" << project_id << ")"; request.set_query(ss.str()); From 0b439e42f49f97640b54e5b6b4d8d0c2140e0372 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 10:52:41 -0800 Subject: [PATCH 13/28] change stringstream to ostringstream. --- examples/tips/publisher_test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tips/publisher_test.cc b/examples/tips/publisher_test.cc index cb949e96fac..e46576a2f6c 100644 --- a/examples/tips/publisher_test.cc +++ b/examples/tips/publisher_test.cc @@ -81,7 +81,7 @@ class PublisherServiceImpl : public tech::pubsub::PublisherService::Service { Status ListTopics(ServerContext* context, const ::tech::pubsub::ListTopicsRequest* request, ::tech::pubsub::ListTopicsResponse* response) override { - std::stringstream ss; + std::ostringstream ss; ss << "cloud.googleapis.com/project in (/projects/" << kProjectId << ")"; EXPECT_EQ(request->query(), ss.str()); response->add_topic()->set_name(kTopic); From 4402b70816b9a1f8f701012b65ca3aea68fde4ea Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 12:11:29 -0800 Subject: [PATCH 14/28] Add README --- examples/tips/README | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/tips/README diff --git a/examples/tips/README b/examples/tips/README new file mode 100644 index 00000000000..faebb7343c9 --- /dev/null +++ b/examples/tips/README @@ -0,0 +1,30 @@ +C++ Client implementation for Cloud Pub/Sub service (TIPS) +(https://developers.google.com/apis-explorer/#p/pubsub/v1beta1/). + +"Google Cloud Pub/Sub" API needs to be enabled at +https://console.developers.google.com/project to open the access for a client. +Select the project name, select the "APIs" under "APIs & auth", and turn +on "Google Cloud Pub/Sub" API. + +To run the client from Google Compute Engine (GCE), the GCE instance needs to +be created with scope "https://www.googleapis.com/auth/cloud-platform" as below: + +gcloud compute instances create instance-name + --image debian-7 --scopes https://www.googleapis.com/auth/cloud-platform + +To run the client from GCE: +make tips_client +bins/opt/tips_client + +A service account credential is required to run the client from other +environments, which can be generated as a JSON key file from +https://console.developers.google.com/project/. To run the client with a service +account credential: + +bins/opt/tips_client + --service_account_key_file="absolute path to the JSON key file" + --project_id="your project id" + + + + From ddfafe8dcde56a33a1abcaf5f107f9d3f0e075b4 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 3 Feb 2015 12:26:51 -0800 Subject: [PATCH 15/28] Fixed errors in Node test running --- tools/dockerfile/grpc_node/Dockerfile | 2 +- tools/gce_setup/grpc_docker.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/dockerfile/grpc_node/Dockerfile b/tools/dockerfile/grpc_node/Dockerfile index baec0e21d84..ce582d2ef12 100644 --- a/tools/dockerfile/grpc_node/Dockerfile +++ b/tools/dockerfile/grpc_node/Dockerfile @@ -11,4 +11,4 @@ RUN make install_c -C /var/local/git/grpc RUN cd /var/local/git/grpc/src/node && npm install && node-gyp rebuild -CMD ["/usr/bin/nodejs", "/var/local/git/grpc/src/node/interop/interop_server.js", "--use_tls=true", "--port 8040"] \ No newline at end of file +CMD ["/usr/bin/nodejs", "/var/local/git/grpc/src/node/interop/interop_server.js", "--use_tls=true", "--port=8040"] \ No newline at end of file diff --git a/tools/gce_setup/grpc_docker.sh b/tools/gce_setup/grpc_docker.sh index bb451141fcf..2e7ed97a87f 100755 --- a/tools/gce_setup/grpc_docker.sh +++ b/tools/gce_setup/grpc_docker.sh @@ -317,7 +317,7 @@ grpc_interop_test_flags() { echo "$FUNCNAME: missing arg: test_case" 1>&2 return 1 } - echo "--server_host=$server_ip --server_port=$port --test_case=$test_case" + echo "--server_host_override=foo.test.google.fr --server_host=$server_ip --server_port=$port --test_case=$test_case" } # checks the positional args and assigns them to variables visible in the caller @@ -874,7 +874,7 @@ grpc_cloud_prod_gen_go_cmd() { grpc_interop_gen_java_cmd() { local cmd_prefix="sudo docker run grpc/java"; local test_script="/var/local/git/grpc-java/run-test-client.sh"; - local test_script+=" --server_host_override=foo.test.google.fr --use_test_ca=true --use_tls=true" + local test_script+=" --use_test_ca=true --use_tls=true" local the_cmd="$cmd_prefix $test_script $@"; echo $the_cmd } From ca3d6f16df60b4368901dd839dec1019bb051368 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 14:23:18 -0800 Subject: [PATCH 16/28] Remove duplicated target tips_client defintion. --- Makefile | 68 +------------------------------------- build.json | 39 ++-------------------- tools/run_tests/tests.json | 4 --- 3 files changed, 3 insertions(+), 108 deletions(-) diff --git a/Makefile b/Makefile index 13f5129f935..bd094150b77 100644 --- a/Makefile +++ b/Makefile @@ -392,8 +392,6 @@ ruby_plugin: bins/$(CONFIG)/ruby_plugin status_test: bins/$(CONFIG)/status_test sync_client_async_server_test: bins/$(CONFIG)/sync_client_async_server_test thread_pool_test: bins/$(CONFIG)/thread_pool_test -tips_client: bins/$(CONFIG)/tips_client -tips_client_test: bins/$(CONFIG)/tips_client_test chttp2_fake_security_cancel_after_accept_test: bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_test chttp2_fake_security_cancel_after_accept_and_writes_closed_test: bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_and_writes_closed_test chttp2_fake_security_cancel_after_invoke_test: bins/$(CONFIG)/chttp2_fake_security_cancel_after_invoke_test @@ -573,7 +571,7 @@ buildtests: buildtests_c buildtests_cxx buildtests_c: privatelibs_c bins/$(CONFIG)/alarm_heap_test bins/$(CONFIG)/alarm_list_test bins/$(CONFIG)/alarm_test bins/$(CONFIG)/alpn_test bins/$(CONFIG)/bin_encoder_test bins/$(CONFIG)/census_hash_table_test bins/$(CONFIG)/census_statistics_multiple_writers_circular_buffer_test bins/$(CONFIG)/census_statistics_multiple_writers_test bins/$(CONFIG)/census_statistics_performance_test bins/$(CONFIG)/census_statistics_quick_test bins/$(CONFIG)/census_statistics_small_log_test bins/$(CONFIG)/census_stub_test bins/$(CONFIG)/census_window_stats_test bins/$(CONFIG)/chttp2_status_conversion_test bins/$(CONFIG)/chttp2_stream_encoder_test bins/$(CONFIG)/chttp2_stream_map_test bins/$(CONFIG)/chttp2_transport_end2end_test bins/$(CONFIG)/dualstack_socket_test bins/$(CONFIG)/echo_client bins/$(CONFIG)/echo_server bins/$(CONFIG)/echo_test bins/$(CONFIG)/fd_posix_test bins/$(CONFIG)/fling_client bins/$(CONFIG)/fling_server bins/$(CONFIG)/fling_stream_test bins/$(CONFIG)/fling_test bins/$(CONFIG)/gpr_cancellable_test bins/$(CONFIG)/gpr_cmdline_test bins/$(CONFIG)/gpr_histogram_test bins/$(CONFIG)/gpr_host_port_test bins/$(CONFIG)/gpr_log_test bins/$(CONFIG)/gpr_slice_buffer_test bins/$(CONFIG)/gpr_slice_test bins/$(CONFIG)/gpr_string_test bins/$(CONFIG)/gpr_sync_test bins/$(CONFIG)/gpr_thd_test bins/$(CONFIG)/gpr_time_test bins/$(CONFIG)/gpr_useful_test bins/$(CONFIG)/grpc_base64_test bins/$(CONFIG)/grpc_byte_buffer_reader_test bins/$(CONFIG)/grpc_channel_stack_test bins/$(CONFIG)/grpc_completion_queue_test bins/$(CONFIG)/grpc_credentials_test bins/$(CONFIG)/grpc_json_token_test bins/$(CONFIG)/grpc_stream_op_test bins/$(CONFIG)/hpack_parser_test bins/$(CONFIG)/hpack_table_test bins/$(CONFIG)/httpcli_format_request_test bins/$(CONFIG)/httpcli_parser_test bins/$(CONFIG)/httpcli_test bins/$(CONFIG)/json_rewrite bins/$(CONFIG)/json_rewrite_test bins/$(CONFIG)/json_test bins/$(CONFIG)/lame_client_test bins/$(CONFIG)/message_compress_test bins/$(CONFIG)/metadata_buffer_test bins/$(CONFIG)/murmur_hash_test bins/$(CONFIG)/no_server_test bins/$(CONFIG)/poll_kick_posix_test bins/$(CONFIG)/resolve_address_test bins/$(CONFIG)/secure_endpoint_test bins/$(CONFIG)/sockaddr_utils_test bins/$(CONFIG)/tcp_client_posix_test bins/$(CONFIG)/tcp_posix_test bins/$(CONFIG)/tcp_server_posix_test bins/$(CONFIG)/time_averaged_stats_test bins/$(CONFIG)/time_test bins/$(CONFIG)/timeout_encoding_test bins/$(CONFIG)/transport_metadata_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_fake_security_cancel_after_invoke_test bins/$(CONFIG)/chttp2_fake_security_cancel_before_invoke_test bins/$(CONFIG)/chttp2_fake_security_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_fake_security_census_simple_request_test bins/$(CONFIG)/chttp2_fake_security_disappearing_server_test bins/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_fake_security_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_fake_security_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_fake_security_invoke_large_request_test bins/$(CONFIG)/chttp2_fake_security_max_concurrent_streams_test bins/$(CONFIG)/chttp2_fake_security_no_op_test bins/$(CONFIG)/chttp2_fake_security_ping_pong_streaming_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_payload_test bins/$(CONFIG)/chttp2_fake_security_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_fake_security_simple_delayed_request_test bins/$(CONFIG)/chttp2_fake_security_simple_request_test bins/$(CONFIG)/chttp2_fake_security_thread_stress_test bins/$(CONFIG)/chttp2_fake_security_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_fullstack_no_op_test bins/$(CONFIG)/chttp2_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_fullstack_simple_request_test bins/$(CONFIG)/chttp2_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_no_op_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_simple_ssl_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_after_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_before_invoke_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_census_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_disappearing_server_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_invoke_large_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_max_concurrent_streams_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_no_op_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_ping_pong_streaming_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_delayed_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_simple_request_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_thread_stress_test bins/$(CONFIG)/chttp2_simple_ssl_with_oauth2_fullstack_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_socket_pair_cancel_after_invoke_test bins/$(CONFIG)/chttp2_socket_pair_cancel_before_invoke_test bins/$(CONFIG)/chttp2_socket_pair_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_socket_pair_census_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_disappearing_server_test bins/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_socket_pair_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_socket_pair_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_socket_pair_invoke_large_request_test bins/$(CONFIG)/chttp2_socket_pair_max_concurrent_streams_test bins/$(CONFIG)/chttp2_socket_pair_no_op_test bins/$(CONFIG)/chttp2_socket_pair_ping_pong_streaming_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_payload_test bins/$(CONFIG)/chttp2_socket_pair_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_simple_delayed_request_test bins/$(CONFIG)/chttp2_socket_pair_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_thread_stress_test bins/$(CONFIG)/chttp2_socket_pair_writes_done_hangs_with_pending_read_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_accept_and_writes_closed_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_after_invoke_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_before_invoke_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_cancel_in_a_vacuum_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_census_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_disappearing_server_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_inflight_calls_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_early_server_shutdown_finishes_tags_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_graceful_server_shutdown_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_invoke_large_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_max_concurrent_streams_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_no_op_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_ping_pong_streaming_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_binary_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_request_response_with_trailing_metadata_and_payload_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_delayed_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_simple_request_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_thread_stress_test bins/$(CONFIG)/chttp2_socket_pair_one_byte_at_a_time_writes_done_hangs_with_pending_read_test -buildtests_cxx: privatelibs_cxx bins/$(CONFIG)/channel_arguments_test bins/$(CONFIG)/credentials_test bins/$(CONFIG)/end2end_test bins/$(CONFIG)/interop_client bins/$(CONFIG)/interop_server bins/$(CONFIG)/tips_client bins/$(CONFIG)/tips_publisher_test bins/$(CONFIG)/tips_subscriber_test bins/$(CONFIG)/qps_client bins/$(CONFIG)/qps_server bins/$(CONFIG)/status_test bins/$(CONFIG)/sync_client_async_server_test bins/$(CONFIG)/thread_pool_test bins/$(CONFIG)/tips_client bins/$(CONFIG)/tips_client_test +buildtests_cxx: privatelibs_cxx bins/$(CONFIG)/channel_arguments_test bins/$(CONFIG)/credentials_test bins/$(CONFIG)/end2end_test bins/$(CONFIG)/interop_client bins/$(CONFIG)/interop_server bins/$(CONFIG)/tips_client bins/$(CONFIG)/tips_publisher_test bins/$(CONFIG)/tips_subscriber_test bins/$(CONFIG)/qps_client bins/$(CONFIG)/qps_server bins/$(CONFIG)/status_test bins/$(CONFIG)/sync_client_async_server_test bins/$(CONFIG)/thread_pool_test test: test_c test_cxx @@ -991,8 +989,6 @@ test_cxx: buildtests_cxx $(Q) ./bins/$(CONFIG)/sync_client_async_server_test || ( echo test sync_client_async_server_test failed ; exit 1 ) $(E) "[RUN] Testing thread_pool_test" $(Q) ./bins/$(CONFIG)/thread_pool_test || ( echo test thread_pool_test failed ; exit 1 ) - $(E) "[RUN] Testing tips_client_test" - $(Q) ./bins/$(CONFIG)/tips_client_test || ( echo test tips_client_test failed ; exit 1 ) tools: privatelibs bins/$(CONFIG)/gen_hpack_tables bins/$(CONFIG)/grpc_fetch_oauth2 @@ -5972,68 +5968,6 @@ endif endif -TIPS_CLIENT_SRC = \ - examples/tips/client_main.cc \ - -TIPS_CLIENT_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_CLIENT_SRC)))) - -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL with ALPN. - -bins/$(CONFIG)/tips_client: openssl_dep_error - -else - -bins/$(CONFIG)/tips_client: $(TIPS_CLIENT_OBJS) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TIPS_CLIENT_OBJS) $(GTEST_LIB) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS) $(LDLIBS_SECURE) -o bins/$(CONFIG)/tips_client - -endif - -objs/$(CONFIG)/examples/tips/client_main.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a - -deps_tips_client: $(TIPS_CLIENT_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(TIPS_CLIENT_OBJS:.o=.dep) -endif -endif - - -TIPS_CLIENT_TEST_SRC = \ - examples/tips/client_test.cc \ - -TIPS_CLIENT_TEST_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(TIPS_CLIENT_TEST_SRC)))) - -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL with ALPN. - -bins/$(CONFIG)/tips_client_test: openssl_dep_error - -else - -bins/$(CONFIG)/tips_client_test: $(TIPS_CLIENT_TEST_OBJS) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(TIPS_CLIENT_TEST_OBJS) $(GTEST_LIB) libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a $(LDLIBSXX) $(LDLIBS) $(LDLIBS_SECURE) -o bins/$(CONFIG)/tips_client_test - -endif - -objs/$(CONFIG)/examples/tips/client_test.o: libs/$(CONFIG)/libtips_client_lib.a libs/$(CONFIG)/libgrpc++_test_util.a libs/$(CONFIG)/libgrpc_test_util.a libs/$(CONFIG)/libgrpc++.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgpr_test_util.a libs/$(CONFIG)/libgpr.a - -deps_tips_client_test: $(TIPS_CLIENT_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(TIPS_CLIENT_TEST_OBJS:.o=.dep) -endif -endif - - CHTTP2_FAKE_SECURITY_CANCEL_AFTER_ACCEPT_TEST_SRC = \ CHTTP2_FAKE_SECURITY_CANCEL_AFTER_ACCEPT_TEST_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(CHTTP2_FAKE_SECURITY_CANCEL_AFTER_ACCEPT_TEST_SRC)))) diff --git a/build.json b/build.json index 1cd8775f472..6e20d617e3a 100644 --- a/build.json +++ b/build.json @@ -1571,7 +1571,6 @@ { "name": "tips_client", "build": "test", - "run": false, "language": "c++", "src": [ "examples/tips/main.cc" @@ -1584,7 +1583,8 @@ "grpc", "gpr_test_util", "gpr" - ] + ], + "run": false }, { "name": "tips_publisher_test", @@ -1716,41 +1716,6 @@ "gpr_test_util", "gpr" ] - }, - { - "name": "tips_client", - "build": "test", - "language": "c++", - "src": [ - "examples/tips/client_main.cc" - ], - "deps": [ - "tips_client_lib", - "grpc++_test_util", - "grpc_test_util", - "grpc++", - "grpc", - "gpr_test_util", - "gpr" - ], - "run": false - }, - { - "name": "tips_client_test", - "build": "test", - "language": "c++", - "src": [ - "examples/tips/client_test.cc" - ], - "deps": [ - "tips_client_lib", - "grpc++_test_util", - "grpc_test_util", - "grpc++", - "grpc", - "gpr_test_util", - "gpr" - ] } ] } diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 01d5dc7ff1f..939a1a60951 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -289,10 +289,6 @@ "language": "c++", "name": "thread_pool_test" }, - { - "language": "c++", - "name": "tips_client_test" - }, { "language": "c", "name": "chttp2_fake_security_cancel_after_accept_test" From 1f50e26d3a6af8c10a224f1fef7b876a54fe6f00 Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 14:43:18 -0800 Subject: [PATCH 17/28] Need project_id from argument to run the client correctly. --- examples/tips/README | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/tips/README b/examples/tips/README index faebb7343c9..38351750978 100644 --- a/examples/tips/README +++ b/examples/tips/README @@ -14,7 +14,7 @@ gcloud compute instances create instance-name To run the client from GCE: make tips_client -bins/opt/tips_client +bins/opt/tips_client --project_id="your project id" A service account credential is required to run the client from other environments, which can be generated as a JSON key file from @@ -22,6 +22,7 @@ https://console.developers.google.com/project/. To run the client with a service account credential: bins/opt/tips_client + --project_id="your project id" --service_account_key_file="absolute path to the JSON key file" --project_id="your project id" From 3ebec60ec45d3b7867d80907a0acf32c94e7d98e Mon Sep 17 00:00:00 2001 From: Chen Wang Date: Tue, 3 Feb 2015 15:19:05 -0800 Subject: [PATCH 18/28] Only add project_id for GCE command line. --- examples/tips/README | 5 ----- 1 file changed, 5 deletions(-) diff --git a/examples/tips/README b/examples/tips/README index 38351750978..ae7d096c2ed 100644 --- a/examples/tips/README +++ b/examples/tips/README @@ -24,8 +24,3 @@ account credential: bins/opt/tips_client --project_id="your project id" --service_account_key_file="absolute path to the JSON key file" - --project_id="your project id" - - - - From 94c365326ae7b8c11c3310555330e5671810b3ff Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 21 Jan 2015 10:36:12 -0800 Subject: [PATCH 19/28] added grpc extension library for C# --- .gitignore | 5 ++ Makefile | 86 ++++++++++++++++++++++- build.json | 12 ++++ src/csharp/.gitignore | 2 + src/csharp/README.md | 22 ++++++ src/csharp/ext/grpc_csharp_ext.c | 113 +++++++++++++++++++++++++++++++ 6 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 src/csharp/.gitignore create mode 100755 src/csharp/README.md create mode 100644 src/csharp/ext/grpc_csharp_ext.c diff --git a/.gitignore b/.gitignore index 6eb55b12029..9c9ae5abd41 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,11 @@ coverage # python compiled objects *.pyc +#eclipse project files +.cproject +.project +.settings + # cache for run_tests.py .run_tests_cache diff --git a/Makefile b/Makefile index 13f5129f935..122bcb4bc8e 100644 --- a/Makefile +++ b/Makefile @@ -553,13 +553,13 @@ endif static: static_c static_cxx -static_c: libs/$(CONFIG)/libgpr.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgrpc_unsecure.a +static_c: libs/$(CONFIG)/libgpr.a libs/$(CONFIG)/libgrpc.a libs/$(CONFIG)/libgrpc_unsecure.a libs/$(CONFIG)/libgrpc_csharp_ext.a static_cxx: libs/$(CONFIG)/libgrpc++.a shared: shared_c shared_cxx -shared_c: libs/$(CONFIG)/libgpr.$(SHARED_EXT) libs/$(CONFIG)/libgrpc.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) +shared_c: libs/$(CONFIG)/libgpr.$(SHARED_EXT) libs/$(CONFIG)/libgrpc.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) shared_cxx: libs/$(CONFIG)/libgrpc++.$(SHARED_EXT) @@ -1020,6 +1020,8 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) libs/$(CONFIG)/libgrpc.a $(E) "[STRIP] Stripping libgrpc_unsecure.a" $(Q) $(STRIP) libs/$(CONFIG)/libgrpc_unsecure.a + $(E) "[STRIP] Stripping libgrpc_csharp_ext.a" + $(Q) $(STRIP) libs/$(CONFIG)/libgrpc_csharp_ext.a endif strip-static_cxx: static_cxx @@ -1036,6 +1038,8 @@ ifeq ($(CONFIG),opt) $(Q) $(STRIP) libs/$(CONFIG)/libgrpc.$(SHARED_EXT) $(E) "[STRIP] Stripping libgrpc_unsecure.so" $(Q) $(STRIP) libs/$(CONFIG)/libgrpc_unsecure.$(SHARED_EXT) + $(E) "[STRIP] Stripping libgrpc_csharp_ext.so" + $(Q) $(STRIP) libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) endif strip-shared_cxx: shared_cxx @@ -1141,6 +1145,8 @@ install-static_c: static_c strip-static_c $(Q) $(INSTALL) libs/$(CONFIG)/libgrpc.a $(prefix)/lib/libgrpc.a $(E) "[INSTALL] Installing libgrpc_unsecure.a" $(Q) $(INSTALL) libs/$(CONFIG)/libgrpc_unsecure.a $(prefix)/lib/libgrpc_unsecure.a + $(E) "[INSTALL] Installing libgrpc_csharp_ext.a" + $(Q) $(INSTALL) libs/$(CONFIG)/libgrpc_csharp_ext.a $(prefix)/lib/libgrpc_csharp_ext.a install-static_cxx: static_cxx strip-static_cxx $(E) "[INSTALL] Installing libgrpc++.a" @@ -1180,6 +1186,17 @@ ifneq ($(SYSTEM),Darwin) $(Q) ln -sf libgrpc_unsecure.$(SHARED_EXT) $(prefix)/lib/libgrpc_unsecure.so endif endif +ifeq ($(SYSTEM),MINGW32) + $(E) "[INSTALL] Installing grpc_csharp_ext.$(SHARED_EXT)" + $(Q) $(INSTALL) libs/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/grpc_csharp_ext.$(SHARED_EXT) + $(Q) $(INSTALL) libs/$(CONFIG)/libgrpc_csharp_ext-imp.a $(prefix)/lib/libgrpc_csharp_ext-imp.a +else + $(E) "[INSTALL] Installing libgrpc_csharp_ext.$(SHARED_EXT)" + $(Q) $(INSTALL) libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.$(SHARED_EXT) +ifneq ($(SYSTEM),Darwin) + $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(prefix)/lib/libgrpc_csharp_ext.so +endif +endif ifneq ($(SYSTEM),MINGW32) ifneq ($(SYSTEM),Darwin) $(Q) ldconfig @@ -2300,6 +2317,71 @@ objs/$(CONFIG)/examples/tips/publisher.o: gens/examples/tips/label.pb.cc objs/$(CONFIG)/examples/tips/subscriber.o: gens/examples/tips/label.pb.cc gens/examples/tips/empty.pb.cc gens/examples/tips/pubsub.pb.cc +LIBGRPC_CSHARP_EXT_SRC = \ + src/csharp/ext/grpc_csharp_ext.c \ + + +LIBGRPC_CSHARP_EXT_OBJS = $(addprefix objs/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBGRPC_CSHARP_EXT_SRC)))) + +ifeq ($(NO_SECURE),true) + +# You can't build secure libraries if you don't have OpenSSL with ALPN. + +libs/$(CONFIG)/libgrpc_csharp_ext.a: openssl_dep_error + +ifeq ($(SYSTEM),MINGW32) +libs/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT): openssl_dep_error +else +libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT): openssl_dep_error +endif + +else + +ifneq ($(OPENSSL_DEP),) +src/csharp/ext/grpc_csharp_ext.c: $(OPENSSL_DEP) +endif + +libs/$(CONFIG)/libgrpc_csharp_ext.a: $(ZLIB_DEP) $(OPENSSL_DEP) $(LIBGRPC_CSHARP_EXT_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f libs/$(CONFIG)/libgrpc_csharp_ext.a + $(Q) $(AR) rcs libs/$(CONFIG)/libgrpc_csharp_ext.a $(LIBGRPC_CSHARP_EXT_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib libs/$(CONFIG)/libgrpc_csharp_ext.a +endif + + + +ifeq ($(SYSTEM),MINGW32) +libs/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT): $(LIBGRPC_CSHARP_EXT_OBJS) $(ZLIB_DEP)libs/$(CONFIG)/gpr.$(SHARED_EXT)libs/$(CONFIG)/grpc.$(SHARED_EXT) $(OPENSSL_DEP) + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,--output-def=libs/$(CONFIG)/grpc_csharp_ext.def -Wl,--out-implib=libs/$(CONFIG)/libgrpc_csharp_ext-imp.a -o libs/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr-imp -lgrpc-imp +else +libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT): $(LIBGRPC_CSHARP_EXT_OBJS) $(ZLIB_DEP) libs/$(CONFIG)/libgpr.$(SHARED_EXT) libs/$(CONFIG)/libgrpc.$(SHARED_EXT) $(OPENSSL_DEP) + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` +ifeq ($(SYSTEM),Darwin) + $(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -dynamiclib -o libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr -lgrpc +else + $(Q) $(LD) $(LDFLAGS) -Llibs/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.0 -o libs/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LDLIBS_SECURE) $(OPENSSL_MERGE_LIBS) -lgpr -lgrpc + $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_csharp_ext.so.0 + $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) libs/$(CONFIG)/libgrpc_csharp_ext.so +endif +endif + + +endif + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(LIBGRPC_CSHARP_EXT_OBJS:.o=.dep) +endif +endif + +objs/$(CONFIG)/src/csharp/ext/grpc_csharp_ext.o: + + LIBEND2END_FIXTURE_CHTTP2_FAKE_SECURITY_SRC = \ test/core/end2end/fixtures/chttp2_fake_security.c \ diff --git a/build.json b/build.json index 1cd8775f472..e7ab14b1f2f 100644 --- a/build.json +++ b/build.json @@ -441,6 +441,18 @@ "grpc", "gpr" ] + }, + { + "name": "grpc_csharp_ext", + "build": "all", + "language": "c", + "deps": [ + "gpr", + "grpc" + ], + "src": [ + "src/csharp/ext/grpc_csharp_ext.c" + ] } ], "targets": [ diff --git a/src/csharp/.gitignore b/src/csharp/.gitignore new file mode 100644 index 00000000000..dbf38f34b73 --- /dev/null +++ b/src/csharp/.gitignore @@ -0,0 +1,2 @@ +*.userprefs +test-results diff --git a/src/csharp/README.md b/src/csharp/README.md new file mode 100755 index 00000000000..dac5a4550b6 --- /dev/null +++ b/src/csharp/README.md @@ -0,0 +1,22 @@ +gRPC C# +======= + +A C# implementation of gRPC, Google's RPC library. + +EXPERIMENTAL ONLY +----------------- + +**This gRPC C# implementation is work-in-progress and is not expected to work yet.** + +- The implementation is a wrapper around gRPC C core library +- Code only runs under mono currently, because there have been issues building + the gRPC C core library under Windows. +- It is very possible that some parts of the code will be heavily refactored or + completely rewritten. + +CONTENTS +-------- + +- ext: + The extension library that wraps C API to be more digestible by C#. + diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c new file mode 100644 index 00000000000..74d11c655b6 --- /dev/null +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -0,0 +1,113 @@ +#include +#include +#include + +#include + +grpc_byte_buffer *string_to_byte_buffer(const char *buffer, size_t len) { + gpr_slice slice = gpr_slice_from_copied_buffer(buffer, len); + grpc_byte_buffer *bb = grpc_byte_buffer_create(&slice, 1); + gpr_slice_unref(slice); + return bb; +} + +void grpc_call_start_write_from_copied_buffer(grpc_call *call, + const char *buffer, size_t len, + void *tag, gpr_uint32 flags) { + grpc_byte_buffer *byte_buffer = string_to_byte_buffer(buffer, len); + GPR_ASSERT(grpc_call_start_write_old(call, byte_buffer, tag, flags) == + GRPC_CALL_OK); + grpc_byte_buffer_destroy(byte_buffer); +} + +grpc_completion_type grpc_event_type(const grpc_event *event) { + return event->type; +} + +grpc_op_error grpc_event_write_accepted(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_WRITE_ACCEPTED); + return event->data.invoke_accepted; +} + +grpc_op_error grpc_event_finish_accepted(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_FINISH_ACCEPTED); + return event->data.finish_accepted; +} + +grpc_status_code grpc_event_finished_status(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_FINISHED); + return event->data.finished.status; +} + +const char *grpc_event_finished_details(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_FINISHED); + return event->data.finished.details; +} + +gpr_intptr grpc_event_read_length(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_READ); + if (!event->data.read) { + return -1; + } + return grpc_byte_buffer_length(event->data.read); +} + +/* + * Copies data from read event to a buffer. Fatal error occurs if + * buffer is too small. + */ +void grpc_event_read_copy_to_buffer(const grpc_event *event, char *buffer, + size_t buffer_len) { + grpc_byte_buffer_reader *reader; + gpr_slice slice; + size_t offset = 0; + + GPR_ASSERT(event->type == GRPC_READ); + reader = grpc_byte_buffer_reader_create(event->data.read); + + GPR_ASSERT(event->data.read); + while (grpc_byte_buffer_reader_next(reader, &slice)) { + size_t len = GPR_SLICE_LENGTH(slice); + GPR_ASSERT(offset + len <= buffer_len); + memcpy(buffer + offset, GPR_SLICE_START_PTR(slice), + GPR_SLICE_LENGTH(slice)); + offset += len; + gpr_slice_unref(slice); + } + grpc_byte_buffer_reader_destroy(reader); +} + +grpc_call *grpc_event_call(const grpc_event *event) { + /* we only allow this for newly incoming server calls. */ + GPR_ASSERT(event->type == GRPC_SERVER_RPC_NEW); + return event->call; +} + +const char *grpc_event_server_rpc_new_method(const grpc_event *event) { + GPR_ASSERT(event->type == GRPC_SERVER_RPC_NEW); + return event->data.server_rpc_new.method; +} + +grpc_completion_type grpc_completion_queue_next_with_callback( + grpc_completion_queue *cq) { + grpc_event *ev; + grpc_completion_type t; + void (*callback)(grpc_event *); + + ev = grpc_completion_queue_next(cq, gpr_inf_future); + t = ev->type; + if (ev->tag) { + /* call the callback in ev->tag */ + /* C forbids to cast object pointers to function pointers, so + * we cast to intptr first. + */ + callback = (void (*)(grpc_event *))(gpr_intptr)ev->tag; + (*callback)(ev); + } + grpc_event_finish(ev); + + /* return completion type to allow some handling for events that have no + * tag - such as GRPC_QUEUE_SHUTDOWN + */ + return t; +} From decdff921b87bbfba7a7099c1be71e2cd302468b Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 4 Feb 2015 01:09:47 +0100 Subject: [PATCH 20/28] Fixing potential hitch in iomgr shutdown. The background_callback_executor may sit on the condition as well. If we're not broadcasting the condition, it may eat the condition signal, and starve the shutdown sequence of it. --- src/core/iomgr/iomgr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index 8989b491d58..c280b267129 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -143,7 +143,7 @@ void grpc_iomgr_ref(void) { void grpc_iomgr_unref(void) { gpr_mu_lock(&g_mu); if (0 == --g_refs) { - gpr_cv_signal(&g_cv); + grpc_kick_poller(); } gpr_mu_unlock(&g_mu); } From e5d683ca7e77f04263822382043dd3e39dc00fc6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Feb 2015 16:37:36 -0800 Subject: [PATCH 21/28] Add some documentation to call.c --- src/core/surface/call.c | 51 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 382909c8652..66db4f4f246 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -128,30 +128,79 @@ struct grpc_call { /* TODO(ctiller): share with cq if possible? */ gpr_mu mu; - gpr_uint8 is_client; + /* how far through the stream have we read? */ read_state read_state; + /* how far through the stream have we written? */ write_state write_state; + /* client or server call */ + gpr_uint8 is_client; + /* is the alarm set */ gpr_uint8 have_alarm; + /* are we currently performing a send operation */ gpr_uint8 sending; + /* pairs with completed_requests */ gpr_uint8 num_completed_requests; + /* flag that we need to request more data */ gpr_uint8 need_more_data; + /* Active ioreqs. + request_set and request_data contain one element per active ioreq + operation. + + request_set[op] is an integer specifying a set of operations to which + the request belongs: + - if it is < GRPC_IOREQ_OP_COUNT, then this operation is pending + completion, and the integer represents to which group of operations + the ioreq belongs. Each group is represented by one master, and the + integer in request_set is an index into masters to find the master + data. + - if it is REQSET_EMPTY, the ioreq op is inactive and available to be + started + - finally, if request_set[op] is REQSET_DONE, then the operation is + complete and unavailable to be started again + + request_data[op] is the request data as supplied by the initiator of + a request, and is valid iff request_set[op] <= GRPC_IOREQ_OP_COUNT. + The set fields are as per the request type specified by op. + + Finally, one element of masters[op] is set per active _group_ of ioreq + operations. It describes work left outstanding, result status, and + what work to perform upon operation completion. As one ioreq of each + op type can be active at once, by convention we choose the first element + of a the group to be the master. This allows constant time allocation + and a strong upper bound of a count of masters to be calculated. */ gpr_uint8 request_set[GRPC_IOREQ_OP_COUNT]; grpc_ioreq_data request_data[GRPC_IOREQ_OP_COUNT]; reqinfo_master masters[GRPC_IOREQ_OP_COUNT]; + + /* Dynamic array of ioreq's that have completed: the count of + elements is queued in num_completed_requests. + This list is built up under lock(), and flushed entirely during + unlock(). + We know the upper bound of the number of elements as we can only + have one ioreq of each type active at once. */ completed_request completed_requests[GRPC_IOREQ_OP_COUNT]; + /* Incoming buffer of messages */ grpc_byte_buffer_queue incoming_queue; + /* Buffered read metadata waiting to be returned to the application. + Element 0 is initial metadata, element 1 is trailing metadata. */ grpc_metadata_array buffered_metadata[2]; + /* All metadata received - unreffed at once at the end of the call */ grpc_mdelem **owned_metadata; size_t owned_metadata_count; size_t owned_metadata_capacity; + /* Received call statuses from various sources */ received_status status[STATUS_SOURCE_COUNT]; + /* Deadline alarm - if have_alarm is non-zero */ grpc_alarm alarm; + /* Call refcount - to keep the call alive during asynchronous operations */ gpr_refcount internal_refcount; + /* Data that the legacy api needs to track. To be deleted at some point + soon */ legacy_state *legacy_state; }; From ea6f6d99f46cc0445840408da8d6096405fc209c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 3 Feb 2015 17:26:44 -0800 Subject: [PATCH 22/28] updated readme --- src/csharp/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/csharp/README.md b/src/csharp/README.md index dac5a4550b6..5b56303c147 100755 --- a/src/csharp/README.md +++ b/src/csharp/README.md @@ -9,8 +9,8 @@ EXPERIMENTAL ONLY **This gRPC C# implementation is work-in-progress and is not expected to work yet.** - The implementation is a wrapper around gRPC C core library -- Code only runs under mono currently, because there have been issues building - the gRPC C core library under Windows. +- Code only runs under mono currently, building gGRPC C core library under Windows + is in progress. - It is very possible that some parts of the code will be heavily refactored or completely rewritten. From ae7b45a84da5520a856c34e7345bfeaa0d5b80a6 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 4 Feb 2015 03:28:34 +0100 Subject: [PATCH 23/28] Adding another condition variable to fix the iomgr shutdown issue. --- src/core/iomgr/iomgr.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/iomgr/iomgr.c b/src/core/iomgr/iomgr.c index c280b267129..3d6114ca18e 100644 --- a/src/core/iomgr/iomgr.c +++ b/src/core/iomgr/iomgr.c @@ -51,6 +51,7 @@ typedef struct delayed_callback { static gpr_mu g_mu; static gpr_cv g_cv; +static gpr_cv g_rcv; static delayed_callback *g_cbs_head = NULL; static delayed_callback *g_cbs_tail = NULL; static int g_shutdown; @@ -86,6 +87,7 @@ void grpc_iomgr_init(void) { gpr_thd_id id; gpr_mu_init(&g_mu); gpr_cv_init(&g_cv); + gpr_cv_init(&g_rcv); grpc_alarm_list_init(gpr_now()); g_refs = 0; grpc_iomgr_platform_init(); @@ -115,7 +117,7 @@ void grpc_iomgr_shutdown(void) { gpr_mu_lock(&g_mu); } if (g_refs) { - if (gpr_cv_wait(&g_cv, &g_mu, shutdown_deadline) && g_cbs_head == NULL) { + if (gpr_cv_wait(&g_rcv, &g_mu, shutdown_deadline) && g_cbs_head == NULL) { gpr_log(GPR_DEBUG, "Failed to free %d iomgr objects before shutdown deadline: " "memory leaks are likely", @@ -126,12 +128,14 @@ void grpc_iomgr_shutdown(void) { } gpr_mu_unlock(&g_mu); + grpc_kick_poller(); gpr_event_wait(&g_background_callback_executor_done, gpr_inf_future); grpc_iomgr_platform_shutdown(); grpc_alarm_list_shutdown(); gpr_mu_destroy(&g_mu); gpr_cv_destroy(&g_cv); + gpr_cv_destroy(&g_rcv); } void grpc_iomgr_ref(void) { @@ -143,7 +147,7 @@ void grpc_iomgr_ref(void) { void grpc_iomgr_unref(void) { gpr_mu_lock(&g_mu); if (0 == --g_refs) { - grpc_kick_poller(); + gpr_cv_signal(&g_rcv); } gpr_mu_unlock(&g_mu); } From d44f8410dfeb114e05a44166ea0d9271438eac38 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Tue, 3 Feb 2015 18:30:48 -0800 Subject: [PATCH 24/28] Have cpu_linux.c define _GNU_SOURCE at the beginning of the file Feature test macros need to be defined before including any other headers. --- src/core/support/cpu_linux.c | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/src/core/support/cpu_linux.c b/src/core/support/cpu_linux.c index eab8b7fbd05..508ebfaebde 100644 --- a/src/core/support/cpu_linux.c +++ b/src/core/support/cpu_linux.c @@ -31,44 +31,15 @@ * */ +#define _GNU_SOURCE + #include #ifdef GPR_CPU_LINUX #include "src/core/support/cpu.h" -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#define GRPC_GNU_SOURCE -#endif - -#ifndef __USE_GNU -#define __USE_GNU -#define GRPC_USE_GNU -#endif - -#ifndef __USE_MISC -#define __USE_MISC -#define GRPC_USE_MISC -#endif - #include - -#ifdef GRPC_GNU_SOURCE -#undef _GNU_SOURCE -#undef GRPC_GNU_SOURCE -#endif - -#ifdef GRPC_USE_GNU -#undef __USE_GNU -#undef GRPC_USE_GNU -#endif - -#ifdef GRPC_USE_MISC -#undef __USE_MISC -#undef GRPC_USE_MISC -#endif - #include #include #include From 9db67cbfb0c02e445360c404361d61ec2ea151ee Mon Sep 17 00:00:00 2001 From: David Klempner Date: Tue, 3 Feb 2015 18:34:46 -0800 Subject: [PATCH 25/28] We should ifdef check the define of _GNU_SOURCE --- src/core/support/cpu_linux.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/support/cpu_linux.c b/src/core/support/cpu_linux.c index 508ebfaebde..e0df699217b 100644 --- a/src/core/support/cpu_linux.c +++ b/src/core/support/cpu_linux.c @@ -31,7 +31,9 @@ * */ +#ifndef _GNU_SOURCE #define _GNU_SOURCE +#undef /* _GNU_SOURCE */ #include From 9e1b10b027308894d484c154658933eb415eb0c4 Mon Sep 17 00:00:00 2001 From: David Klempner Date: Tue, 3 Feb 2015 18:36:37 -0800 Subject: [PATCH 26/28] undef and endif aren't the same thing --- src/core/support/cpu_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/support/cpu_linux.c b/src/core/support/cpu_linux.c index e0df699217b..ad82174894b 100644 --- a/src/core/support/cpu_linux.c +++ b/src/core/support/cpu_linux.c @@ -33,7 +33,7 @@ #ifndef _GNU_SOURCE #define _GNU_SOURCE -#undef /* _GNU_SOURCE */ +#endif /* _GNU_SOURCE */ #include From d642dcf9201ccc499690b7da4afa85cb249c32d3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Feb 2015 20:39:09 -0800 Subject: [PATCH 27/28] Use unsigned for shifts --- src/core/surface/call.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index 66db4f4f246..f3b76364467 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -76,7 +76,7 @@ typedef struct { /* Completion function to call at the end of the operation */ grpc_ioreq_completion_func on_complete; void *user_data; - /* a bit mask of which request ops are needed (1 << opid) */ + /* a bit mask of which request ops are needed (1u << opid) */ gpr_uint32 need_mask; /* a bit mask of which request ops are now completed */ gpr_uint32 complete_mask; @@ -323,7 +323,7 @@ static int is_op_live(grpc_call *call, grpc_ioreq_op op) { reqinfo_master *master; if (set >= GRPC_IOREQ_OP_COUNT) return 0; master = &call->masters[set]; - return (master->complete_mask & (1 << op)) == 0; + return (master->complete_mask & (1u << op)) == 0; } static void lock(grpc_call *call) { gpr_mu_lock(&call->mu); } @@ -411,7 +411,7 @@ static void finish_live_ioreq_op(grpc_call *call, grpc_ioreq_op op, size_t i; /* ioreq is live: we need to do something */ master = &call->masters[master_set]; - master->complete_mask |= 1 << op; + master->complete_mask |= 1u << op; if (status != GRPC_OP_OK) { master->status = status; master->complete_mask = master->need_mask; @@ -614,7 +614,7 @@ static grpc_call_error start_ioreq_error(grpc_call *call, grpc_call_error ret) { size_t i; for (i = 0; i < GRPC_IOREQ_OP_COUNT; i++) { - if (mutated_ops & (1 << i)) { + if (mutated_ops & (1u << i)) { call->request_set[i] = REQSET_EMPTY; } } @@ -700,7 +700,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, } else if (call->request_set[op] == REQSET_DONE) { return start_ioreq_error(call, have_ops, GRPC_CALL_ERROR_ALREADY_INVOKED); } - have_ops |= 1 << op; + have_ops |= 1u << op; data = reqs[i].data; call->request_data[op] = data; @@ -714,7 +714,7 @@ static grpc_call_error start_ioreq(grpc_call *call, const grpc_ioreq *reqs, master->on_complete = completion; master->user_data = user_data; - if (have_ops & (1 << GRPC_IOREQ_RECV_MESSAGE)) { + if (have_ops & (1u << GRPC_IOREQ_RECV_MESSAGE)) { call->need_more_data = 1; } From d6731628bcedbe150d4f7cd09656bd506979b00f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 3 Feb 2015 22:44:13 -0800 Subject: [PATCH 28/28] Cleanup documentation --- src/core/surface/call.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/surface/call.c b/src/core/surface/call.c index f3b76364467..8221401a70b 100644 --- a/src/core/surface/call.c +++ b/src/core/surface/call.c @@ -163,11 +163,12 @@ struct grpc_call { a request, and is valid iff request_set[op] <= GRPC_IOREQ_OP_COUNT. The set fields are as per the request type specified by op. - Finally, one element of masters[op] is set per active _group_ of ioreq + Finally, one element of masters is set per active _set_ of ioreq operations. It describes work left outstanding, result status, and what work to perform upon operation completion. As one ioreq of each op type can be active at once, by convention we choose the first element - of a the group to be the master. This allows constant time allocation + of the group to be the master -- ie the master of in-progress operation + op is masters[request_set[op]]. This allows constant time allocation and a strong upper bound of a count of masters to be calculated. */ gpr_uint8 request_set[GRPC_IOREQ_OP_COUNT]; grpc_ioreq_data request_data[GRPC_IOREQ_OP_COUNT];