clang-format

pull/16190/head
Muxi Yan 6 years ago
parent 1a9404876c
commit f0f6e03212
  1. 7
      src/objective-c/GRPCClient/GRPCCall.m
  2. 4
      src/objective-c/GRPCClient/private/GRPCChannel.m
  3. 4
      src/objective-c/GRPCClient/private/GRPCChannelPool+Test.h
  4. 22
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  5. 2
      src/objective-c/GRPCClient/private/GRPCWrappedCall.h
  6. 11
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  7. 10
      src/objective-c/ProtoRPC/ProtoRPC.m
  8. 49
      src/objective-c/tests/ChannelTests/ChannelTests.m
  9. 15
      src/objective-c/tests/InteropTests.m

@ -28,6 +28,8 @@
#include <grpc/support/time.h>
#import "GRPCCallOptions.h"
#import "private/GRPCChannelPool.h"
#import "private/GRPCCompletionQueue.h"
#import "private/GRPCConnectivityMonitor.h"
#import "private/GRPCHost.h"
#import "private/GRPCRequestHeaders.h"
@ -35,8 +37,6 @@
#import "private/NSData+GRPC.h"
#import "private/NSDictionary+GRPC.h"
#import "private/NSError+GRPC.h"
#import "private/GRPCChannelPool.h"
#import "private/GRPCCompletionQueue.h"
// At most 6 ops can be in an op batch for a client: SEND_INITIAL_METADATA,
// SEND_MESSAGE, SEND_CLOSE_FROM_CLIENT, RECV_INITIAL_METADATA, RECV_MESSAGE,
@ -819,7 +819,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
_responseWriteable =
[[GRXConcurrentWriteable alloc] initWithWriteable:writeable dispatchQueue:_responseQueue];
GRPCPooledChannel *channel = [[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions];
GRPCPooledChannel *channel =
[[GRPCChannelPool sharedInstance] channelWithHost:_host callOptions:_callOptions];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:_path
completionQueue:[GRPCCompletionQueue completionQueue]
callOptions:_callOptions];

@ -229,7 +229,9 @@
NSTimeInterval timeout = callOptions.timeout;
NSAssert(timeout >= 0, @"Invalid timeout");
if (timeout < 0) return NULL;
grpc_slice host_slice = serverAuthority ? grpc_slice_from_copied_string(serverAuthority.UTF8String) : grpc_empty_slice();
grpc_slice host_slice = serverAuthority
? grpc_slice_from_copied_string(serverAuthority.UTF8String)
: grpc_empty_slice();
grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String);
gpr_timespec deadline_ms =
timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME)

@ -25,7 +25,7 @@
* Initialize a pooled channel with non-default destroy delay for testing purpose.
*/
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay;
/**
@ -45,5 +45,3 @@
- (nullable instancetype)initTestPool;
@end

@ -21,15 +21,15 @@
#import "../internal/GRPCCallOptions+Internal.h"
#import "GRPCChannel.h"
#import "GRPCChannelFactory.h"
#import "GRPCChannelPool.h"
#import "GRPCChannelPool+Test.h"
#import "GRPCChannelPool.h"
#import "GRPCCompletionQueue.h"
#import "GRPCConnectivityMonitor.h"
#import "GRPCCronetChannelFactory.h"
#import "GRPCInsecureChannelFactory.h"
#import "GRPCSecureChannelFactory.h"
#import "version.h"
#import "GRPCWrappedCall.h"
#import "GRPCCompletionQueue.h"
#import "version.h"
#import <GRPCClient/GRPCCall+Cronet.h>
#include <grpc/support/log.h>
@ -53,10 +53,12 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
}
- (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration {
return [self initWithChannelConfiguration:channelConfiguration destroyDelay:kDefaultChannelDestroyDelay];
return [self initWithChannelConfiguration:channelConfiguration
destroyDelay:kDefaultChannelDestroyDelay];
}
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
destroyDelay:(NSTimeInterval)destroyDelay {
NSAssert(channelConfiguration != nil, @"channelConfiguration cannot be empty.");
if (channelConfiguration == nil) {
@ -71,8 +73,8 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
_lastTimedDestroy = nil;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 || __MAC_OS_X_VERSION_MAX_ALLOWED >= 101300
if (@available(iOS 8.0, macOS 10.10, *)) {
_timerQueue = dispatch_queue_create(NULL,
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
_timerQueue = dispatch_queue_create(NULL, dispatch_queue_attr_make_with_qos_class(
DISPATCH_QUEUE_SERIAL, QOS_CLASS_DEFAULT, 0));
} else {
#else
{
@ -115,7 +117,8 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
}
_lastTimedDestroy = nil;
grpc_call *unmanagedCall = [_wrappedChannel unmanagedCallWithPath:path
grpc_call *unmanagedCall =
[_wrappedChannel unmanagedCallWithPath:path
completionQueue:[GRPCCompletionQueue completionQueue]
callOptions:callOptions];
if (unmanagedCall == NULL) {
@ -203,8 +206,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
+ (instancetype)sharedInstance {
dispatch_once(&gInitChannelPool, ^{
gChannelPool =
[[GRPCChannelPool alloc] initPrivate];
gChannelPool = [[GRPCChannelPool alloc] initPrivate];
NSAssert(gChannelPool != nil, @"Cannot initialize global channel pool.");
});
return gChannelPool;

@ -77,7 +77,7 @@
- (instancetype)init NS_UNAVAILABLE;
+ (instancetype)new NS_UNAVAILABLE;
+ (instancetype) new NS_UNAVAILABLE;
- (instancetype)initWithUnmanagedCall:(grpc_call *)unmanagedCall
pooledChannel:(GRPCPooledChannel *)pooledChannel NS_DESIGNATED_INITIALIZER;

@ -267,7 +267,7 @@
[GRPCOpBatchLog addOpBatchToLog:operations];
#endif
@synchronized (self) {
@synchronized(self) {
if (_call != NULL) {
size_t nops = operations.count;
grpc_op *ops_array = gpr_malloc(nops * sizeof(grpc_op));
@ -275,7 +275,8 @@
for (GRPCOperation *operation in operations) {
ops_array[i++] = operation.op;
}
grpc_call_error error = grpc_call_start_batch(_call, ops_array, nops, (__bridge_retained void *)(^(bool success) {
grpc_call_error error =
grpc_call_start_batch(_call, ops_array, nops, (__bridge_retained void *)(^(bool success) {
if (!success) {
if (errorHandler) {
errorHandler();
@ -296,7 +297,7 @@
}
- (void)cancel {
@synchronized (self) {
@synchronized(self) {
if (_call != NULL) {
grpc_call_cancel(_call, NULL);
}
@ -304,7 +305,7 @@
}
- (void)channelDisconnected {
@synchronized (self) {
@synchronized(self) {
if (_call != NULL) {
grpc_call_unref(_call);
_call = NULL;
@ -313,7 +314,7 @@
}
- (void)dealloc {
@synchronized (self) {
@synchronized(self) {
if (_call != NULL) {
grpc_call_unref(_call);
_call = NULL;

@ -97,9 +97,12 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
responseHandler:(id<GRPCProtoResponseHandler>)handler
callOptions:(GRPCCallOptions *)callOptions
responseClass:(Class)responseClass {
NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0 && requestOptions.safety <= GRPCCallSafetyCacheableRequest, @"Invalid callOptions.");
NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0 &&
requestOptions.safety <= GRPCCallSafetyCacheableRequest,
@"Invalid callOptions.");
NSAssert(handler != nil, @"handler cannot be empty.");
if (requestOptions.host.length == 0 || requestOptions.path.length == 0 || requestOptions.safety > GRPCCallSafetyCacheableRequest) {
if (requestOptions.host.length == 0 || requestOptions.path.length == 0 ||
requestOptions.safety > GRPCCallSafetyCacheableRequest) {
return nil;
}
if (handler == nil) {
@ -223,7 +226,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
copiedHandler = self->_handler;
self->_handler = nil;
}
[copiedHandler didCloseWithTrailingMetadata:nil
[copiedHandler
didCloseWithTrailingMetadata:nil
error:ErrorForBadProto(message, _responseClass, error)];
});
[_call cancel];

@ -20,8 +20,8 @@
#import "../../GRPCClient/GRPCCallOptions.h"
#import "../../GRPCClient/private/GRPCChannel.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCChannelPool+Test.h"
#import "../../GRPCClient/private/GRPCChannelPool.h"
#import "../../GRPCClient/private/GRPCCompletionQueue.h"
#import "../../GRPCClient/private/GRPCWrappedCall.h"
@ -40,13 +40,12 @@ static NSString *kDummyPath = @"/dummy/path";
- (void)testPooledChannelCreatingChannel {
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost
callOptions:options];
GRPCChannelConfiguration *config =
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
GRPCWrappedCall *wrappedCall =
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
(void)wrappedCall;
}
@ -54,26 +53,22 @@ static NSString *kDummyPath = @"/dummy/path";
- (void)testTimedDestroyChannel {
const NSTimeInterval kDestroyDelay = 1.0;
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config
destroyDelay:kDestroyDelay];
GRPCChannelConfiguration *config =
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel =
[[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall;
GRPCChannel *wrappedChannel;
@autoreleasepool {
wrappedCall = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
// Unref and ref channel immediately; expect using the same raw channel.
wrappedChannel = channel.wrappedChannel;
wrappedCall = nil;
wrappedCall = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertEqual(channel.wrappedChannel, wrappedChannel);
// Unref and ref channel after destroy delay; expect a new raw channel.
@ -81,23 +76,20 @@ static NSString *kDummyPath = @"/dummy/path";
}
sleep(kDestroyDelay + 1);
XCTAssertNil(channel.wrappedChannel);
wrappedCall = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
wrappedCall = [channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotEqual(channel.wrappedChannel, wrappedChannel);
}
- (void)testDisconnect {
const NSTimeInterval kDestroyDelay = 1.0;
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCChannelConfiguration *config = [[GRPCChannelConfiguration alloc] initWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel = [[GRPCPooledChannel alloc] initWithChannelConfiguration:config
destroyDelay:kDestroyDelay];
GRPCChannelConfiguration *config =
[[GRPCChannelConfiguration alloc] initWithHost:kDummyHost callOptions:options];
GRPCPooledChannel *channel =
[[GRPCPooledChannel alloc] initWithChannelConfiguration:config destroyDelay:kDestroyDelay];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCWrappedCall *wrappedCall = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
GRPCWrappedCall *wrappedCall =
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
// Disconnect; expect wrapped channel to be dropped
@ -106,9 +98,8 @@ static NSString *kDummyPath = @"/dummy/path";
// Create a new call and unref the old call; confirm that destroy of the old call does not make
// the channel disconnect, even after the destroy delay.
GRPCWrappedCall *wrappedCall2 = [channel wrappedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
GRPCWrappedCall *wrappedCall2 =
[channel wrappedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
GRPCChannel *wrappedChannel = channel.wrappedChannel;
wrappedCall = nil;

@ -249,8 +249,10 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testLargeUnaryRPCWithV2API {
XCTAssertNotNil([[self class] host]);
__weak XCTestExpectation *expectRecvMessage = [self expectationWithDescription:@"LargeUnaryWithV2API received message"];
__weak XCTestExpectation *expectRecvComplete = [self expectationWithDescription:@"LargeUnaryWithV2API received complete"];
__weak XCTestExpectation *expectRecvMessage =
[self expectationWithDescription:@"LargeUnaryWithV2API received message"];
__weak XCTestExpectation *expectRecvComplete =
[self expectationWithDescription:@"LargeUnaryWithV2API received complete"];
RMTSimpleRequest *request = [RMTSimpleRequest message];
request.responseType = RMTPayloadType_Compressable;
@ -268,9 +270,11 @@ BOOL isRemoteInteropTest(NSString *host) {
messageCallback:^(id message) {
XCTAssertNotNil(message);
if (message) {
RMTSimpleResponse *expectedResponse = [RMTSimpleResponse message];
RMTSimpleResponse *expectedResponse =
[RMTSimpleResponse message];
expectedResponse.payload.type = RMTPayloadType_Compressable;
expectedResponse.payload.body = [NSMutableData dataWithLength:314159];
expectedResponse.payload.body =
[NSMutableData dataWithLength:314159];
XCTAssertEqualObjects(message, expectedResponse);
[expectRecvMessage fulfill];
@ -602,7 +606,8 @@ BOOL isRemoteInteropTest(NSString *host) {
- (void)testCancelAfterBeginRPCWithV2API {
XCTAssertNotNil([[self class] host]);
__weak XCTestExpectation *expectation = [self expectationWithDescription:@"CancelAfterBeginWithV2API"];
__weak XCTestExpectation *expectation =
[self expectationWithDescription:@"CancelAfterBeginWithV2API"];
// A buffered pipe to which we never write any value acts as a writer that just hangs.
__block GRPCStreamingProtoCall *call = [_service

Loading…
Cancel
Save