diff --git a/BUILD b/BUILD index 607e3f481ae..25b26b7b244 100644 --- a/BUILD +++ b/BUILD @@ -209,6 +209,8 @@ cc_library( "src/core/json/json_writer.h", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", @@ -476,6 +478,8 @@ cc_library( "src/core/json/json_writer.h", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", @@ -1229,6 +1233,8 @@ objc_library( "src/core/json/json_writer.h", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", diff --git a/build.json b/build.json index c3e784b4cfe..54cae415464 100644 --- a/build.json +++ b/build.json @@ -182,6 +182,8 @@ "src/core/json/json_writer.h", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", diff --git a/gRPC.podspec b/gRPC.podspec index 0e826b5ba24..f6d09dbaa62 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -211,6 +211,8 @@ Pod::Spec.new do |s| 'src/core/json/json_writer.h', 'src/core/profiling/timers.h', 'src/core/profiling/timers_preciseclock.h', + 'src/core/statistics/census_interface.h', + 'src/core/statistics/census_rpc_stats.h', 'src/core/surface/byte_buffer_queue.h', 'src/core/surface/call.h', 'src/core/surface/channel.h', @@ -481,6 +483,8 @@ Pod::Spec.new do |s| 'src/core/json/json_writer.h', 'src/core/profiling/timers.h', 'src/core/profiling/timers_preciseclock.h', + 'src/core/statistics/census_interface.h', + 'src/core/statistics/census_rpc_stats.h', 'src/core/surface/byte_buffer_queue.h', 'src/core/surface/call.h', 'src/core/surface/channel.h', diff --git a/src/objective-c/tests/GRPCClientTests.m b/src/objective-c/tests/GRPCClientTests.m index 06581e7599a..09a55e07045 100644 --- a/src/objective-c/tests/GRPCClientTests.m +++ b/src/objective-c/tests/GRPCClientTests.m @@ -53,6 +53,37 @@ static ProtoMethod *kInexistentMethod; static ProtoMethod *kEmptyCallMethod; static ProtoMethod *kUnaryCallMethod; +// This is an observer class for testing that responseMetadata is KVO-compliant + +@interface PassthroughObserver : NSObject + +- (instancetype) initWithCallback:(void (^)(NSString*, id, NSDictionary*))callback; + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change + context:(void *)context; +@end + +@implementation PassthroughObserver { + void (^_callback)(NSString*, id, NSDictionary*); +} + +- (instancetype)initWithCallback:(void (^)(NSString *, id, NSDictionary *))callback { + self = [super init]; + if (self) { + _callback = callback; + } + return self; + +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + _callback(keyPath, object, change); + [object removeObserver:self forKeyPath:keyPath]; +} + +@end + @interface GRPCClientTests : XCTestCase @end @@ -183,4 +214,35 @@ static ProtoMethod *kUnaryCallMethod; [self waitForExpectationsWithTimeout:4 handler:nil]; } +- (void)testResponseMetadataKVO { + __weak XCTestExpectation *response = [self expectationWithDescription:@"Empty response received."]; + __weak XCTestExpectation *completion = [self expectationWithDescription:@"Empty RPC completed."]; + __weak XCTestExpectation *metadata = [self expectationWithDescription:@"Metadata changed."]; + + GRPCCall *call = [[GRPCCall alloc] initWithHost:kHostAddress + path:kEmptyCallMethod.HTTPPath + requestsWriter:[GRXWriter writerWithValue:[NSData data]]]; + + PassthroughObserver *observer = [[PassthroughObserver alloc] initWithCallback:^(NSString *keypath, id object, NSDictionary * change) { + if ([keypath isEqual: @"responseHeaders"]) { + [metadata fulfill]; + } + }]; + + [call addObserver:observer forKeyPath:@"responseHeaders" options:0 context:NULL]; + + id responsesWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { + XCTAssertNotNil(value, @"nil value received as response."); + XCTAssertEqual([value length], 0, @"Non-empty response received: %@", value); + [response fulfill]; + } completionHandler:^(NSError *errorOrNil) { + XCTAssertNil(errorOrNil, @"Finished with unexpected error: %@", errorOrNil); + [completion fulfill]; + }]; + + [call startWithWriteable:responsesWriteable]; + + [self waitForExpectationsWithTimeout:8 handler:nil]; +} + @end diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index d27c5d9246a..06f0f4ee834 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -846,6 +846,8 @@ src/core/json/json_reader.h \ src/core/json/json_writer.h \ src/core/profiling/timers.h \ src/core/profiling/timers_preciseclock.h \ +src/core/statistics/census_interface.h \ +src/core/statistics/census_rpc_stats.h \ src/core/surface/byte_buffer_queue.h \ src/core/surface/call.h \ src/core/surface/channel.h \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index f2a2abe96d2..c7df23a7c4d 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -12340,6 +12340,8 @@ "src/core/security/secure_transport_setup.h", "src/core/security/security_connector.h", "src/core/security/security_context.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", @@ -12556,6 +12558,8 @@ "src/core/security/security_context.h", "src/core/security/server_auth_filter.c", "src/core/security/server_secure_chttp2.c", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer.c", "src/core/surface/byte_buffer_queue.c", "src/core/surface/byte_buffer_queue.h", @@ -12806,6 +12810,8 @@ "src/core/json/json_writer.h", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer_queue.h", "src/core/surface/call.h", "src/core/surface/channel.h", @@ -12992,6 +12998,8 @@ "src/core/profiling/stap_timers.c", "src/core/profiling/timers.h", "src/core/profiling/timers_preciseclock.h", + "src/core/statistics/census_interface.h", + "src/core/statistics/census_rpc_stats.h", "src/core/surface/byte_buffer.c", "src/core/surface/byte_buffer_queue.c", "src/core/surface/byte_buffer_queue.h", diff --git a/vsprojects/grpc/grpc.vcxproj b/vsprojects/grpc/grpc.vcxproj index 500cf9feb50..b17eea9235d 100644 --- a/vsprojects/grpc/grpc.vcxproj +++ b/vsprojects/grpc/grpc.vcxproj @@ -308,6 +308,8 @@ + + diff --git a/vsprojects/grpc/grpc.vcxproj.filters b/vsprojects/grpc/grpc.vcxproj.filters index 02060b7830e..a955e9e9934 100644 --- a/vsprojects/grpc/grpc.vcxproj.filters +++ b/vsprojects/grpc/grpc.vcxproj.filters @@ -683,6 +683,12 @@ src\core\profiling + + src\core\statistics + + + src\core\statistics + src\core\surface @@ -845,6 +851,9 @@ {1d850ac6-e639-4eab-5338-4ba40272fcc9} + + {0ef49896-2313-4a3f-1ce2-716fa0e5c6ca} + {aeb18e82-5d25-0aad-8b02-a0a3470073ce} diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj index 13c018c020f..a692c48f81d 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj @@ -291,6 +291,8 @@ + + diff --git a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters index 5adcdd60926..1c4036d464b 100644 --- a/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -581,6 +581,12 @@ src\core\profiling + + src\core\statistics + + + src\core\statistics + src\core\surface @@ -740,6 +746,9 @@ {7f91d9bf-c9de-835a-d74d-b16f843b89a9} + + {e084164c-a069-00e3-db35-4e0b1cd6f0b7} + {6cd0127e-c24b-d43c-38f5-198db8d4322a}