|
|
|
@ -171,14 +171,19 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
|
|
|
|
|
@interface HookInterceptorFactory : NSObject<GRPCInterceptorFactory> |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
|
- (instancetype) |
|
|
|
|
initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
|
|
|
|
|
|
- (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager; |
|
|
|
@ -187,39 +192,52 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
|
|
|
|
|
@interface HookIntercetpor : GRPCInterceptor |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
|
- (instancetype) |
|
|
|
|
initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, |
|
|
|
|
GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
|
|
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
@implementation HookInterceptorFactory { |
|
|
|
|
void (^_startHook)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_startHook)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager); |
|
|
|
|
void (^_writeDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseCloseHook)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseCloseHook)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager); |
|
|
|
|
void (^_didWriteDataHook)(GRPCInterceptorManager *manager); |
|
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
|
- (instancetype) |
|
|
|
|
initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
|
if ((self = [super init])) { |
|
|
|
|
_dispatchQueue = dispatchQueue; |
|
|
|
@ -252,13 +270,15 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
@end |
|
|
|
|
|
|
|
|
|
@implementation HookIntercetpor { |
|
|
|
|
void (^_startHook)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_startHook)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager); |
|
|
|
|
void (^_writeDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseCloseHook)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager); |
|
|
|
|
void (^_responseCloseHook)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager); |
|
|
|
|
void (^_didWriteDataHook)(GRPCInterceptorManager *manager); |
|
|
|
|
GRPCInterceptorManager *_manager; |
|
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
|
@ -272,17 +292,25 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
return _dispatchQueue; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
- (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
|
- (instancetype) |
|
|
|
|
initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, |
|
|
|
|
GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
|
if ((self = [super initWithInterceptorManager:interceptorManager requestDispatchQueue:dispatchQueue responseDispatchQueue:dispatchQueue])) { |
|
|
|
|
if ((self = [super initWithInterceptorManager:interceptorManager |
|
|
|
|
requestDispatchQueue:dispatchQueue |
|
|
|
|
responseDispatchQueue:dispatchQueue])) { |
|
|
|
|
_startHook = startHook; |
|
|
|
|
_writeDataHook = writeDataHook; |
|
|
|
|
_finishHook = finishHook; |
|
|
|
@ -1322,15 +1350,17 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
|
__block NSUInteger didWriteDataCount = 0; |
|
|
|
|
id<GRPCInterceptorFactory> factory = |
|
|
|
|
[[HookInterceptorFactory alloc] initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { |
|
|
|
|
id<GRPCInterceptorFactory> factory = [[HookInterceptorFactory alloc] |
|
|
|
|
initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
|
startCount++; |
|
|
|
|
NSLog(@"Interceptor - started call, %@, %@", requestOptions, callOptions); |
|
|
|
|
XCTAssertEqualObjects(requestOptions.host, [[self class] host]); |
|
|
|
|
XCTAssertEqualObjects(requestOptions.path, @"/grpc.testing.TestService/FullDuplexCall"); |
|
|
|
|
XCTAssertEqual(requestOptions.safety, GRPCCallSafetyDefault); |
|
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] callOptions:[callOptions copy]]; |
|
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] |
|
|
|
|
callOptions:[callOptions copy]]; |
|
|
|
|
} |
|
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
|
writeDataCount++; |
|
|
|
@ -1359,11 +1389,11 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
XCTAssertNotEqual(data.length, 0); |
|
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
|
} |
|
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager) { |
|
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
|
responseCloseCount++; |
|
|
|
|
NSLog(@"Interceptor - received close, %@, %@", trailingMetadata, error); |
|
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata |
|
|
|
|
error:error]; |
|
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata error:error]; |
|
|
|
|
} |
|
|
|
|
didWriteDataHook:^(GRPCInterceptorManager *manager) { |
|
|
|
|
didWriteDataCount++; |
|
|
|
@ -1453,11 +1483,13 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
__block NSUInteger responseHeaderCount = 0; |
|
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
|
id<GRPCInterceptorFactory> factory = |
|
|
|
|
[[HookInterceptorFactory alloc] initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { |
|
|
|
|
id<GRPCInterceptorFactory> factory = [[HookInterceptorFactory alloc] |
|
|
|
|
initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
|
startCount++; |
|
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] callOptions:[callOptions copy]]; |
|
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] |
|
|
|
|
callOptions:[callOptions copy]]; |
|
|
|
|
} |
|
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
|
writeDataCount++; |
|
|
|
@ -1465,15 +1497,20 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
[manager writeNextInterceptorWithData:data]; |
|
|
|
|
} else if (index == kCancelAfterWrites) { |
|
|
|
|
[manager cancelNextInterceptor]; |
|
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]] data]]; |
|
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse |
|
|
|
|
messageWithPayloadSize:responses[index]] |
|
|
|
|
data]]; |
|
|
|
|
} else { // (index > kCancelAfterWrites) |
|
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]] data]]; |
|
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse |
|
|
|
|
messageWithPayloadSize:responses[index]] |
|
|
|
|
data]]; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
finishHook:^(GRPCInterceptorManager *manager) { |
|
|
|
|
finishCount++; |
|
|
|
|
// finish must happen after the hijacking, so directly reply with a close |
|
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:@{ @"grpc-status" : @"0" } error:nil]; |
|
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:@{@"grpc-status" : @"0"} |
|
|
|
|
error:nil]; |
|
|
|
|
} |
|
|
|
|
receiveNextMessagesHook:nil |
|
|
|
|
responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { |
|
|
|
@ -1484,7 +1521,8 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
responseDataCount++; |
|
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
|
} |
|
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager) { |
|
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
|
responseCloseCount++; |
|
|
|
|
// since we canceled the call, it should return cancel error |
|
|
|
|
XCTAssertNil(trailingMetadata); |
|
|
|
|