|
|
@ -171,15 +171,20 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
|
|
|
|
|
|
|
@interface HookInterceptorFactory : NSObject<GRPCInterceptorFactory> |
|
|
|
@interface HookInterceptorFactory : NSObject<GRPCInterceptorFactory> |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
- (instancetype) |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
|
|
|
|
|
|
|
|
- (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager; |
|
|
|
- (GRPCInterceptor *)createInterceptorWithManager:(GRPCInterceptorManager *)interceptorManager; |
|
|
|
|
|
|
|
|
|
|
@ -187,40 +192,53 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
|
|
|
|
|
|
|
|
@interface HookIntercetpor : GRPCInterceptor |
|
|
|
@interface HookIntercetpor : GRPCInterceptor |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
- (instancetype) |
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
GRPCCallOptions *callOptions, |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
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 |
|
|
|
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook; |
|
|
|
|
|
|
|
|
|
|
|
@end |
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation HookInterceptorFactory { |
|
|
|
@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 (^_writeDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseDataHook)(NSData *data, 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); |
|
|
|
void (^_didWriteDataHook)(GRPCInterceptorManager *manager); |
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
- (instancetype) |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
initWithDispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
if ((self = [super init])) { |
|
|
|
if ((self = [super init])) { |
|
|
|
_dispatchQueue = dispatchQueue; |
|
|
|
_dispatchQueue = dispatchQueue; |
|
|
|
_startHook = startHook; |
|
|
|
_startHook = startHook; |
|
|
@ -252,13 +270,15 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
@end |
|
|
|
@end |
|
|
|
|
|
|
|
|
|
|
|
@implementation HookIntercetpor { |
|
|
|
@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 (^_writeDataHook)(NSData *data, GRPCInterceptorManager *manager); |
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
void (^_finishHook)(GRPCInterceptorManager *manager); |
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
void (^_receiveNextMessagesHook)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseHeaderHook)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager); |
|
|
|
void (^_responseDataHook)(NSData *data, 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); |
|
|
|
void (^_didWriteDataHook)(GRPCInterceptorManager *manager); |
|
|
|
GRPCInterceptorManager *_manager; |
|
|
|
GRPCInterceptorManager *_manager; |
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
|
dispatch_queue_t _dispatchQueue; |
|
|
@ -272,17 +292,25 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
return _dispatchQueue; |
|
|
|
return _dispatchQueue; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
- (instancetype) |
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
initWithInterceptorManager:(GRPCInterceptorManager *)interceptorManager |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager))startHook |
|
|
|
dispatchQueue:(dispatch_queue_t)dispatchQueue |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
startHook:(void (^)(GRPCRequestOptions *requestOptions, |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
GRPCCallOptions *callOptions, |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
GRPCInterceptorManager *manager))startHook |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
writeDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))writeDataHook |
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
finishHook:(void (^)(GRPCInterceptorManager *manager))finishHook |
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
receiveNextMessagesHook:(void (^)(NSUInteger numberOfMessages, |
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
GRPCInterceptorManager *manager))receiveNextMessagesHook |
|
|
|
if ((self = [super initWithInterceptorManager:interceptorManager requestDispatchQueue:dispatchQueue responseDispatchQueue:dispatchQueue])) { |
|
|
|
responseHeaderHook:(void (^)(NSDictionary *initialMetadata, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseHeaderHook |
|
|
|
|
|
|
|
responseDataHook:(void (^)(NSData *data, GRPCInterceptorManager *manager))responseDataHook |
|
|
|
|
|
|
|
responseCloseHook:(void (^)(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager))responseCloseHook |
|
|
|
|
|
|
|
didWriteDataHook:(void (^)(GRPCInterceptorManager *manager))didWriteDataHook { |
|
|
|
|
|
|
|
if ((self = [super initWithInterceptorManager:interceptorManager |
|
|
|
|
|
|
|
requestDispatchQueue:dispatchQueue |
|
|
|
|
|
|
|
responseDispatchQueue:dispatchQueue])) { |
|
|
|
_startHook = startHook; |
|
|
|
_startHook = startHook; |
|
|
|
_writeDataHook = writeDataHook; |
|
|
|
_writeDataHook = writeDataHook; |
|
|
|
_finishHook = finishHook; |
|
|
|
_finishHook = finishHook; |
|
|
@ -1271,39 +1299,39 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init] ]; |
|
|
|
options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init] ]; |
|
|
|
|
|
|
|
|
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
messageCallback:^(id message) { |
|
|
|
messageCallback:^(id message) { |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
@"More than 4 responses received."); |
|
|
|
@"More than 4 responses received."); |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
index += 1; |
|
|
|
index += 1; |
|
|
|
if (index < 4) { |
|
|
|
if (index < 4) { |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
[call finish]; |
|
|
|
[call finish]; |
|
|
|
} |
|
|
|
} |
|
|
|
// DEBUG |
|
|
|
// DEBUG |
|
|
|
NSLog(@"Received message"); |
|
|
|
NSLog(@"Received message"); |
|
|
|
} |
|
|
|
} |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
NSError *error) { |
|
|
|
NSError *error) { |
|
|
|
XCTAssertNil(error, |
|
|
|
XCTAssertNil(error, |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
error); |
|
|
|
error); |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
index); |
|
|
|
index); |
|
|
|
[expectation fulfill]; |
|
|
|
[expectation fulfill]; |
|
|
|
// DEBUG |
|
|
|
// DEBUG |
|
|
|
NSLog(@"Received close"); |
|
|
|
NSLog(@"Received close"); |
|
|
|
}] |
|
|
|
}] |
|
|
|
callOptions:options]; |
|
|
|
callOptions:options]; |
|
|
|
[call start]; |
|
|
|
[call start]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
|
|
|
|
|
|
|
|
@ -1322,54 +1350,56 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
__block NSUInteger didWriteDataCount = 0; |
|
|
|
__block NSUInteger didWriteDataCount = 0; |
|
|
|
id<GRPCInterceptorFactory> factory = |
|
|
|
id<GRPCInterceptorFactory> factory = [[HookInterceptorFactory alloc] |
|
|
|
[[HookInterceptorFactory alloc] initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { |
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
startCount++; |
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
NSLog(@"Interceptor - started call, %@, %@", requestOptions, callOptions); |
|
|
|
startCount++; |
|
|
|
XCTAssertEqualObjects(requestOptions.host, [[self class] host]); |
|
|
|
NSLog(@"Interceptor - started call, %@, %@", requestOptions, callOptions); |
|
|
|
XCTAssertEqualObjects(requestOptions.path, @"/grpc.testing.TestService/FullDuplexCall"); |
|
|
|
XCTAssertEqualObjects(requestOptions.host, [[self class] host]); |
|
|
|
XCTAssertEqual(requestOptions.safety, GRPCCallSafetyDefault); |
|
|
|
XCTAssertEqualObjects(requestOptions.path, @"/grpc.testing.TestService/FullDuplexCall"); |
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] callOptions:[callOptions copy]]; |
|
|
|
XCTAssertEqual(requestOptions.safety, GRPCCallSafetyDefault); |
|
|
|
} |
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] |
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
callOptions:[callOptions copy]]; |
|
|
|
writeDataCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - send data, %@", data); |
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
XCTAssertNotEqual(data.length, 0); |
|
|
|
writeDataCount++; |
|
|
|
[manager writeNextInterceptorWithData:data]; |
|
|
|
NSLog(@"Interceptor - send data, %@", data); |
|
|
|
} |
|
|
|
XCTAssertNotEqual(data.length, 0); |
|
|
|
finishHook:^(GRPCInterceptorManager *manager) { |
|
|
|
[manager writeNextInterceptorWithData:data]; |
|
|
|
finishCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - finish call"); |
|
|
|
finishHook:^(GRPCInterceptorManager *manager) { |
|
|
|
[manager finishNextInterceptor]; |
|
|
|
finishCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - finish call"); |
|
|
|
receiveNextMessagesHook:^(NSUInteger numberOfMessages, GRPCInterceptorManager *manager) { |
|
|
|
[manager finishNextInterceptor]; |
|
|
|
receiveNextMessageCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - receive next messages, %lu", (unsigned long)numberOfMessages); |
|
|
|
receiveNextMessagesHook:^(NSUInteger numberOfMessages, GRPCInterceptorManager *manager) { |
|
|
|
[manager receiveNextInterceptorMessages:numberOfMessages]; |
|
|
|
receiveNextMessageCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - receive next messages, %lu", (unsigned long)numberOfMessages); |
|
|
|
responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { |
|
|
|
[manager receiveNextInterceptorMessages:numberOfMessages]; |
|
|
|
responseHeaderCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received initial metadata, %@", initialMetadata); |
|
|
|
responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { |
|
|
|
[manager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; |
|
|
|
responseHeaderCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received initial metadata, %@", initialMetadata); |
|
|
|
responseDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
[manager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; |
|
|
|
responseDataCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received data, %@", data); |
|
|
|
responseDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
XCTAssertNotEqual(data.length, 0); |
|
|
|
responseDataCount++; |
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
NSLog(@"Interceptor - received data, %@", data); |
|
|
|
} |
|
|
|
XCTAssertNotEqual(data.length, 0); |
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager) { |
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
responseCloseCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received close, %@, %@", trailingMetadata, error); |
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata |
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
error:error]; |
|
|
|
responseCloseCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received close, %@, %@", trailingMetadata, error); |
|
|
|
didWriteDataHook:^(GRPCInterceptorManager *manager) { |
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:trailingMetadata error:error]; |
|
|
|
didWriteDataCount++; |
|
|
|
} |
|
|
|
NSLog(@"Interceptor - received did-write-data"); |
|
|
|
didWriteDataHook:^(GRPCInterceptorManager *manager) { |
|
|
|
[manager forwardPreviousInterceptorDidWriteData]; |
|
|
|
didWriteDataCount++; |
|
|
|
}]; |
|
|
|
NSLog(@"Interceptor - received did-write-data"); |
|
|
|
|
|
|
|
[manager forwardPreviousInterceptorDidWriteData]; |
|
|
|
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
|
|
NSArray *requests = @[ @1, @2, @3, @4 ]; |
|
|
|
NSArray *requests = @[ @1, @2, @3, @4 ]; |
|
|
|
NSArray *responses = @[ @1, @2, @3, @4 ]; |
|
|
|
NSArray *responses = @[ @1, @2, @3, @4 ]; |
|
|
@ -1387,41 +1417,41 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
__block BOOL canWriteData = NO; |
|
|
|
__block BOOL canWriteData = NO; |
|
|
|
|
|
|
|
|
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
messageCallback:^(id message) { |
|
|
|
messageCallback:^(id message) { |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
@"More than 4 responses received."); |
|
|
|
@"More than 4 responses received."); |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
index += 1; |
|
|
|
index += 1; |
|
|
|
if (index < 4) { |
|
|
|
if (index < 4) { |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
XCTAssertTrue(canWriteData); |
|
|
|
XCTAssertTrue(canWriteData); |
|
|
|
canWriteData = NO; |
|
|
|
canWriteData = NO; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
[call finish]; |
|
|
|
[call finish]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
NSError *error) { |
|
|
|
NSError *error) { |
|
|
|
XCTAssertNil(error, |
|
|
|
XCTAssertNil(error, |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
error); |
|
|
|
error); |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
index); |
|
|
|
index); |
|
|
|
[expectation fulfill]; |
|
|
|
[expectation fulfill]; |
|
|
|
} |
|
|
|
} |
|
|
|
writeMessageCallback:^{ |
|
|
|
writeMessageCallback:^{ |
|
|
|
canWriteData = YES; |
|
|
|
canWriteData = YES; |
|
|
|
}] |
|
|
|
}] |
|
|
|
callOptions:options]; |
|
|
|
callOptions:options]; |
|
|
|
[call start]; |
|
|
|
[call start]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
@ -1453,45 +1483,53 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
__block NSUInteger responseHeaderCount = 0; |
|
|
|
__block NSUInteger responseHeaderCount = 0; |
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
__block NSUInteger responseDataCount = 0; |
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
__block NSUInteger responseCloseCount = 0; |
|
|
|
id<GRPCInterceptorFactory> factory = |
|
|
|
id<GRPCInterceptorFactory> factory = [[HookInterceptorFactory alloc] |
|
|
|
[[HookInterceptorFactory alloc] initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
initWithDispatchQueue:dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL) |
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, GRPCInterceptorManager *manager) { |
|
|
|
startHook:^(GRPCRequestOptions *requestOptions, GRPCCallOptions *callOptions, |
|
|
|
startCount++; |
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] callOptions:[callOptions copy]]; |
|
|
|
startCount++; |
|
|
|
} |
|
|
|
[manager startNextInterceptorWithRequest:[requestOptions copy] |
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
callOptions:[callOptions copy]]; |
|
|
|
writeDataCount++; |
|
|
|
} |
|
|
|
if (index < kCancelAfterWrites) { |
|
|
|
writeDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
[manager writeNextInterceptorWithData:data]; |
|
|
|
writeDataCount++; |
|
|
|
} else if (index == kCancelAfterWrites) { |
|
|
|
if (index < kCancelAfterWrites) { |
|
|
|
[manager cancelNextInterceptor]; |
|
|
|
[manager writeNextInterceptorWithData:data]; |
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]] data]]; |
|
|
|
} else if (index == kCancelAfterWrites) { |
|
|
|
} else { // (index > kCancelAfterWrites) |
|
|
|
[manager cancelNextInterceptor]; |
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse messageWithPayloadSize:responses[index]] data]]; |
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse |
|
|
|
} |
|
|
|
messageWithPayloadSize:responses[index]] |
|
|
|
} |
|
|
|
data]]; |
|
|
|
finishHook:^(GRPCInterceptorManager *manager) { |
|
|
|
} else { // (index > kCancelAfterWrites) |
|
|
|
finishCount++; |
|
|
|
[manager forwardPreviousIntercetporWithData:[[RMTStreamingOutputCallResponse |
|
|
|
// finish must happen after the hijacking, so directly reply with a close |
|
|
|
messageWithPayloadSize:responses[index]] |
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:@{ @"grpc-status" : @"0" } error:nil]; |
|
|
|
data]]; |
|
|
|
} |
|
|
|
} |
|
|
|
receiveNextMessagesHook:nil |
|
|
|
} |
|
|
|
responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { |
|
|
|
finishHook:^(GRPCInterceptorManager *manager) { |
|
|
|
responseHeaderCount++; |
|
|
|
finishCount++; |
|
|
|
[manager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; |
|
|
|
// finish must happen after the hijacking, so directly reply with a close |
|
|
|
} |
|
|
|
[manager forwardPreviousInterceptorCloseWithTrailingMetadata:@{@"grpc-status" : @"0"} |
|
|
|
responseDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
error:nil]; |
|
|
|
responseDataCount++; |
|
|
|
} |
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
receiveNextMessagesHook:nil |
|
|
|
} |
|
|
|
responseHeaderHook:^(NSDictionary *initialMetadata, GRPCInterceptorManager *manager) { |
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, GRPCInterceptorManager *manager) { |
|
|
|
responseHeaderCount++; |
|
|
|
responseCloseCount++; |
|
|
|
[manager forwardPreviousInterceptorWithInitialMetadata:initialMetadata]; |
|
|
|
// since we canceled the call, it should return cancel error |
|
|
|
} |
|
|
|
XCTAssertNil(trailingMetadata); |
|
|
|
responseDataHook:^(NSData *data, GRPCInterceptorManager *manager) { |
|
|
|
XCTAssertNotNil(error); |
|
|
|
responseDataCount++; |
|
|
|
XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED); |
|
|
|
[manager forwardPreviousIntercetporWithData:data]; |
|
|
|
} |
|
|
|
} |
|
|
|
didWriteDataHook:nil]; |
|
|
|
responseCloseHook:^(NSDictionary *trailingMetadata, NSError *error, |
|
|
|
|
|
|
|
GRPCInterceptorManager *manager) { |
|
|
|
|
|
|
|
responseCloseCount++; |
|
|
|
|
|
|
|
// since we canceled the call, it should return cancel error |
|
|
|
|
|
|
|
XCTAssertNil(trailingMetadata); |
|
|
|
|
|
|
|
XCTAssertNotNil(error); |
|
|
|
|
|
|
|
XCTAssertEqual(error.code, GRPC_STATUS_CANCELLED); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
didWriteDataHook:nil]; |
|
|
|
|
|
|
|
|
|
|
|
NSArray *requests = @[ @1, @2, @3, @4 ]; |
|
|
|
NSArray *requests = @[ @1, @2, @3, @4 ]; |
|
|
|
|
|
|
|
|
|
|
@ -1504,36 +1542,36 @@ BOOL isRemoteInteropTest(NSString *host) { |
|
|
|
options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init], factory ]; |
|
|
|
options.interceptorFactories = @[ [[DefaultInterceptorFactory alloc] init], factory ]; |
|
|
|
|
|
|
|
|
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
__block GRPCStreamingProtoCall *call = [_service |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
fullDuplexCallWithResponseHandler:[[InteropTestsBlockCallbacks alloc] |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
initWithInitialMetadataCallback:nil |
|
|
|
messageCallback:^(id message) { |
|
|
|
messageCallback:^(id message) { |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
XCTAssertLessThan(index, 4, |
|
|
|
@"More than 4 responses received."); |
|
|
|
@"More than 4 responses received."); |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
id expected = [RMTStreamingOutputCallResponse |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
messageWithPayloadSize:responses[index]]; |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
XCTAssertEqualObjects(message, expected); |
|
|
|
index += 1; |
|
|
|
index += 1; |
|
|
|
if (index < 4) { |
|
|
|
if (index < 4) { |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
id request = [RMTStreamingOutputCallRequest |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
messageWithPayloadSize:requests[index] |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
requestedResponseSize:responses[index]]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
[call finish]; |
|
|
|
[call finish]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
closeCallback:^(NSDictionary *trailingMetadata, |
|
|
|
NSError *error) { |
|
|
|
NSError *error) { |
|
|
|
XCTAssertNil(error, |
|
|
|
XCTAssertNil(error, |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
@"Finished with unexpected error: %@", |
|
|
|
error); |
|
|
|
error); |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
XCTAssertEqual(index, 4, |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
@"Received %i responses instead of 4.", |
|
|
|
index); |
|
|
|
index); |
|
|
|
[expectation fulfill]; |
|
|
|
[expectation fulfill]; |
|
|
|
}] |
|
|
|
}] |
|
|
|
callOptions:options]; |
|
|
|
callOptions:options]; |
|
|
|
[call start]; |
|
|
|
[call start]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call receiveNextMessage]; |
|
|
|
[call writeMessage:request]; |
|
|
|
[call writeMessage:request]; |
|
|
|