clang-format

pull/16190/head
Muxi Yan 6 years ago
parent f0cbcde731
commit 680b53f7ad
  1. 17
      src/objective-c/GRPCClient/GRPCCall.m
  2. 3
      src/objective-c/GRPCClient/private/GRPCChannel.h
  3. 12
      src/objective-c/GRPCClient/private/GRPCChannel.m
  4. 4
      src/objective-c/GRPCClient/private/GRPCChannelPool.h
  5. 14
      src/objective-c/GRPCClient/private/GRPCChannelPool.m
  6. 6
      src/objective-c/GRPCClient/private/GRPCCronetChannelFactory.m
  7. 3
      src/objective-c/GRPCClient/private/GRPCHost.m
  8. 3
      src/objective-c/GRPCClient/private/GRPCInsecureChannelFactory.m
  9. 3
      src/objective-c/GRPCClient/private/GRPCSecureChannelFactory.m
  10. 7
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  11. 3
      src/objective-c/GRPCClient/private/utilities.h
  12. 6
      src/objective-c/ProtoRPC/ProtoRPC.m
  13. 102
      src/objective-c/tests/ChannelTests/ChannelPoolTest.m
  14. 4
      src/objective-c/tests/ChannelTests/ChannelTests.m
  15. 3
      src/objective-c/tests/InteropTests.m

@ -123,8 +123,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
callOptions:(GRPCCallOptions *)callOptions {
NSAssert(requestOptions.host.length != 0 && requestOptions.path.length != 0,
@"Neither host nor path can be nil.");
NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest,
@"Invalid call safety value.");
NSAssert(requestOptions.safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value.");
NSAssert(responseHandler != nil, @"Response handler required.");
if (requestOptions.host.length == 0 || requestOptions.path.length == 0) {
return nil;
@ -136,7 +135,6 @@ const char *kCFStreamVarName = "grpc_cfstream";
return nil;
}
if ((self = [super init])) {
_requestOptions = [requestOptions copy];
if (callOptions == nil) {
@ -223,7 +221,6 @@ const char *kCFStreamVarName = "grpc_cfstream";
[self issueInitialMetadata:self->_call.responseHeaders];
}
[self issueClosedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil];
}
// Clearing _call must happen *after* dispatching close in order to get trailing
// metadata from _call.
@ -237,8 +234,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
}
};
id<GRXWriteable> responseWriteable =
[[GRXWriteable alloc] initWithValueHandler:valueHandler
completionHandler:completionHandler];
[[GRXWriteable alloc] initWithValueHandler:valueHandler completionHandler:completionHandler];
[call startWithWriteable:responseWriteable];
}
@ -323,7 +319,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
- (void)issueInitialMetadata:(NSDictionary *)initialMetadata {
@synchronized(self) {
if (initialMetadata != nil && [_handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
if (initialMetadata != nil &&
[_handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
dispatch_async(_dispatchQueue, ^{
id<GRPCResponseHandler> handler = nil;
@synchronized(self) {
@ -359,8 +356,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
// Clean up _handler so that no more responses are reported to the handler.
self->_handler = nil;
}
[handler closedWithTrailingMetadata:trailingMetadata
error:error];
[handler closedWithTrailingMetadata:trailingMetadata error:error];
});
}
}
@ -489,8 +485,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
callOptions:(GRPCCallOptions *)callOptions {
// Purposely using pointer rather than length ([host length] == 0) for backwards compatibility.
NSAssert(host != nil && path != nil, @"Neither host nor path can be nil.");
NSAssert(safety <= GRPCCallSafetyCacheableRequest,
@"Invalid call safety value.");
NSAssert(safety <= GRPCCallSafetyCacheableRequest, @"Invalid call safety value.");
NSAssert(requestWriter.state == GRXWriterStateNotStarted,
@"The requests writer can't be already started.");
if (!host || !path) {

@ -64,8 +64,7 @@ NS_ASSUME_NONNULL_BEGIN
* Create a channel with remote \a host and signature \a channelConfigurations.
*/
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
NS_DESIGNATED_INITIALIZER;
(GRPCChannelConfiguration *)channelConfiguration NS_DESIGNATED_INITIALIZER;
/**
* Create a grpc core call object (grpc_call) from this channel. If no call is created, NULL is

@ -178,10 +178,8 @@
grpc_channel *_unmanagedChannel;
}
- (instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration {
NSAssert(channelConfiguration != nil,
@"channelConfiguration must not be empty.");
- (instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration {
NSAssert(channelConfiguration != nil, @"channelConfiguration must not be empty.");
if (channelConfiguration == nil) return nil;
if ((self = [super init])) {
@ -221,8 +219,7 @@
grpc_call *call = NULL;
@synchronized(self) {
NSAssert(_unmanagedChannel != NULL,
@"Channel should have valid unmanaged channel.");
NSAssert(_unmanagedChannel != NULL, @"Channel should have valid unmanaged channel.");
if (_unmanagedChannel == NULL) return NULL;
NSString *serverAuthority =
@ -236,8 +233,7 @@
}
grpc_slice path_slice = grpc_slice_from_copied_string(path.UTF8String);
gpr_timespec deadline_ms =
timeout == 0
? gpr_inf_future(GPR_CLOCK_REALTIME)
timeout == 0 ? gpr_inf_future(GPR_CLOCK_REALTIME)
: gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC),
gpr_time_from_millis((int64_t)(timeout * 1000), GPR_TIMESPAN));
call = grpc_channel_create_call(_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS,

@ -42,10 +42,10 @@ NS_ASSUME_NONNULL_BEGIN
/**
* Initialize with an actual channel object \a channel and a reference to the channel pool.
*/
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration
- (nullable instancetype)initWithChannelConfiguration:
(GRPCChannelConfiguration *)channelConfiguration
channelPool:(GRPCChannelPool *)channelPool;
/**
* Create a grpc core call object (grpc_call) from this channel. If channel is disconnected, get a
* new channel object from the channel pool.

@ -90,7 +90,8 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
}
NSAssert(_wrappedChannel != nil, @"Unable to get a raw channel for proxy.");
}
call = [_wrappedChannel unmanagedCallWithPath:path completionQueue:queue callOptions:callOptions];
call =
[_wrappedChannel unmanagedCallWithPath:path completionQueue:queue callOptions:callOptions];
if (call != NULL) {
[_unmanagedCalls addObject:[NSValue valueWithPointer:call]];
}
@ -229,8 +230,8 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
GRPCChannelRecord *record = _channelPool[configuration];
if (record == nil) {
record = [[GRPCChannelRecord alloc] init];
record.proxy = [[GRPCPooledChannel alloc] initWithChannelConfiguration:configuration
channelPool:self];
record.proxy =
[[GRPCPooledChannel alloc] initWithChannelConfiguration:configuration channelPool:self];
record.timedDestroyDate = nil;
_channelPool[configuration] = record;
channelProxy = record.proxy;
@ -282,8 +283,7 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
NSDate *now = [NSDate date];
record.timedDestroyDate = now;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(_destroyDelay * NSEC_PER_SEC)),
_dispatchQueue,
^{
_dispatchQueue, ^{
@synchronized(self) {
if (now == record.timedDestroyDate) {
// Destroy the raw channel and reset related records.
@ -301,7 +301,9 @@ static const NSTimeInterval kDefaultChannelDestroyDelay = 30;
- (void)disconnectAllChannels {
NSMutableSet<GRPCPooledChannel *> *proxySet = [NSMutableSet set];
@synchronized(self) {
[_channelPool enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration * _Nonnull key, GRPCChannelRecord * _Nonnull obj, BOOL * _Nonnull stop) {
[_channelPool
enumerateKeysAndObjectsUsingBlock:^(GRPCChannelConfiguration *_Nonnull key,
GRPCChannelRecord *_Nonnull obj, BOOL *_Nonnull stop) {
obj.channel = nil;
obj.timedDestroyDate = nil;
obj.refcount = 0;

@ -50,8 +50,7 @@
return self;
}
- (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *)args {
- (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args {
grpc_channel_args *channelArgs = GRPCBuildChannelArgs(args);
grpc_channel *unmanagedChannel =
grpc_cronet_secure_channel_create(_cronetEngine, host.UTF8String, channelArgs, NULL);
@ -71,8 +70,7 @@
return nil;
}
- (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *)args {
- (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args {
[NSException raise:NSInvalidArgumentException
format:@"Must enable macro GRPC_COMPILE_WITH_CRONET to build Cronet channel."];
return NULL;

@ -122,8 +122,7 @@ static NSMutableDictionary *gHostCache;
if (_transportType == GRPCTransportTypeInsecure) {
options.transportType = GRPCTransportTypeInsecure;
} else {
NSAssert(_transportType == GRPCTransportTypeDefault,
@"Invalid transport type");
NSAssert(_transportType == GRPCTransportTypeDefault, @"Invalid transport type");
options.transportType = GRPCTransportTypeCronet;
}
} else

@ -32,8 +32,7 @@
return instance;
}
- (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *)args {
- (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args {
grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]);
grpc_channel *unmanagedChannel =
grpc_insecure_channel_create(host.UTF8String, coreChannelArgs, NULL);

@ -115,8 +115,7 @@
return self;
}
- (grpc_channel *)createChannelWithHost:(NSString *)host
channelArgs:(NSDictionary *)args {
- (grpc_channel *)createChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)args {
grpc_channel_args *coreChannelArgs = GRPCBuildChannelArgs([args copy]);
grpc_channel *unmanagedChannel =
grpc_secure_channel_create(_channelCreds, host.UTF8String, coreChannelArgs, NULL);

@ -249,8 +249,7 @@
- (instancetype)initWithHost:(NSString *)host
path:(NSString *)path
callOptions:(GRPCCallOptions *)callOptions {
NSAssert(host.length != 0 && path.length != 0,
@"path and host cannot be nil.");
NSAssert(host.length != 0 && path.length != 0, @"path and host cannot be nil.");
if ((self = [super init])) {
// Each completion queue consumes one thread. There's a trade to be made between creating and
@ -263,9 +262,7 @@
NSLog(@"Failed to get a channel for the host.");
return nil;
}
_call = [_channel unmanagedCallWithPath:path
completionQueue:_queue
callOptions:callOptions];
_call = [_channel unmanagedCallWithPath:path completionQueue:_queue callOptions:callOptions];
if (_call == nil) {
NSAssert(_channel != nil, @"Failed to get a channel for the host.");
NSLog(@"Failed to create a call.");

@ -19,5 +19,4 @@
#import <Foundation/Foundation.h>
/** Raise exception when condition not met. */
#define GRPCAssert(condition, errorString) \
NSAssert(condition, errorString)
#define GRPCAssert(condition, errorString) NSAssert(condition, errorString)

@ -206,7 +206,8 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}
[handler receivedProtoMessage:parsed];
});
} else if (!parsed && [_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]){
} else if (!parsed &&
[_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{
id<GRPCProtoResponseHandler> handler = nil;
@synchronized(self) {
@ -222,8 +223,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing
}
}
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata
error:(NSError *)error {
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
@synchronized(self) {
if ([_handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
dispatch_async(_dispatchQueue, ^{

@ -41,12 +41,12 @@ NSString *kDummyPath = @"/dummy/path";
- (void)testCreateChannelAndCall {
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCPooledChannel *channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
XCTAssertNil(channel.wrappedChannel);
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
grpc_call *call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq callOptions:options];
grpc_call *call =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssert(call != NULL);
XCTAssertNotNil(channel.wrappedChannel);
[channel unrefUnmanagedCall:call];
@ -60,26 +60,22 @@ NSString *kDummyPath = @"/dummy/path";
GRPCMutableCallOptions *options3 = [options1 mutableCopy];
options3.transportType = GRPCTransportTypeInsecure;
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
GRPCPooledChannel *channel1 = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options1];
grpc_call *call1 = [channel1 unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options1];
GRPCPooledChannel *channel2 = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options2];
grpc_call *call2 = [channel2 unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options2];
GRPCPooledChannel *channel3 = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options3];
grpc_call *call3 = [channel3 unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options3];
GRPCPooledChannel *channel4 = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost2
callOptions:options1];
grpc_call *call4 = [channel4 unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options1];
GRPCPooledChannel *channel1 =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options1];
grpc_call *call1 =
[channel1 unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options1];
GRPCPooledChannel *channel2 =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options2];
grpc_call *call2 =
[channel2 unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options2];
GRPCPooledChannel *channel3 =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options3];
grpc_call *call3 =
[channel3 unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options3];
GRPCPooledChannel *channel4 =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost2 callOptions:options1];
grpc_call *call4 =
[channel4 unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options1];
XCTAssertEqual(channel1.wrappedChannel, channel2.wrappedChannel);
XCTAssertNotEqual(channel1.wrappedChannel, channel3.wrappedChannel);
XCTAssertNotEqual(channel1.wrappedChannel, channel4.wrappedChannel);
@ -96,32 +92,26 @@ NSString *kDummyPath = @"/dummy/path";
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
pool.destroyDelay = kDestroyDelay;
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCPooledChannel *channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
grpc_call *call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq callOptions:options];
grpc_call *call =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
GRPCChannel *wrappedChannel = channel.wrappedChannel;
[channel unrefUnmanagedCall:call];
// Confirm channel is not destroyed at this time
call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
call = [channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertEqual(wrappedChannel, channel.wrappedChannel);
[channel unrefUnmanagedCall:call];
sleep(kDestroyDelay + 1);
// Confirm channel is new at this time
call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
call = [channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotEqual(wrappedChannel, channel.wrappedChannel);
// Confirm the new channel can create call
call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
call = [channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssert(call != NULL);
[channel unrefUnmanagedCall:call];
}
@ -129,31 +119,26 @@ NSString *kDummyPath = @"/dummy/path";
- (void)testPoolDisconnection {
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCPooledChannel *channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
grpc_call *call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
grpc_call *call =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
GRPCChannel *wrappedChannel = channel.wrappedChannel;
// Test a new channel is created by requesting a channel from pool
[pool disconnectAllChannels];
channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
call = [channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
XCTAssertNotEqual(wrappedChannel, channel.wrappedChannel);
wrappedChannel = channel.wrappedChannel;
// Test a new channel is created by requesting a new call from the previous proxy
[pool disconnectAllChannels];
grpc_call *call2 = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
grpc_call *call2 =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
XCTAssertNotNil(channel.wrappedChannel);
XCTAssertNotEqual(channel.wrappedChannel, wrappedChannel);
[channel unrefUnmanagedCall:call];
@ -163,20 +148,17 @@ NSString *kDummyPath = @"/dummy/path";
- (void)testUnrefCallFromStaleChannel {
GRPCChannelPool *pool = [[GRPCChannelPool alloc] init];
GRPCCallOptions *options = [[GRPCCallOptions alloc] init];
GRPCPooledChannel *channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
GRPCPooledChannel *channel =
(GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
GRPCCompletionQueue *cq = [GRPCCompletionQueue completionQueue];
grpc_call *call = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
grpc_call *call =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
[pool disconnectAllChannels];
channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost
callOptions:options];
channel = (GRPCPooledChannel *)[pool channelWithHost:kDummyHost callOptions:options];
grpc_call *call2 = [channel unmanagedCallWithPath:kDummyPath
completionQueue:cq
callOptions:options];
grpc_call *call2 =
[channel unmanagedCallWithPath:kDummyPath completionQueue:cq callOptions:options];
// Test unref the call of a stale channel will not cause the current channel going into timed
// destroy state
XCTAssertNotNil(channel.wrappedChannel);

@ -45,8 +45,8 @@
long _grpcCallCounter;
}
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration {
return nil;
- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration
*)channelConfiguration { return nil;
}
- (instancetype)initWithCreateExpectation:(XCTestExpectation *)createExpectation

@ -114,8 +114,7 @@ BOOL isRemoteInteropTest(NSString *host) {
}
}
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata
error:(NSError *)error {
- (void)closedWithTrailingMetadata:(NSDictionary *)trailingMetadata error:(NSError *)error {
if (_closeCallback) {
_closeCallback(trailingMetadata, error);
}

Loading…
Cancel
Save