eab8c5193fb9832bc2b109e1fb79673cfffbdd28
[platform/upstream/grpc.git] / src / objective-c / tests / ChannelTests / ChannelPoolTest.m
1 /*
2  *
3  * Copyright 2018 gRPC authors.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18
19 #import <XCTest/XCTest.h>
20
21 #import "../../GRPCClient/private/GRPCChannel.h"
22 #import "../../GRPCClient/private/GRPCChannelPool+Test.h"
23 #import "../../GRPCClient/private/GRPCCompletionQueue.h"
24
25 #define TEST_TIMEOUT 32
26
27 static NSString *kDummyHost = @"dummy.host";
28 static NSString *kDummyHost2 = @"dummy.host.2";
29 static NSString *kDummyPath = @"/dummy/path";
30
31 @interface ChannelPoolTest : XCTestCase
32
33 @end
34
35 @implementation ChannelPoolTest
36
37 + (void)setUp {
38   grpc_init();
39 }
40
41 - (void)testCreateAndCacheChannel {
42   GRPCChannelPool *pool = [[GRPCChannelPool alloc] initTestPool];
43   GRPCCallOptions *options1 = [[GRPCCallOptions alloc] init];
44   GRPCCallOptions *options2 = [options1 copy];
45   GRPCMutableCallOptions *options3 = [options1 mutableCopy];
46   options3.transportType = GRPCTransportTypeInsecure;
47
48   GRPCPooledChannel *channel1 = [pool channelWithHost:kDummyHost callOptions:options1];
49   GRPCPooledChannel *channel2 = [pool channelWithHost:kDummyHost callOptions:options2];
50   GRPCPooledChannel *channel3 = [pool channelWithHost:kDummyHost callOptions:options3];
51   GRPCPooledChannel *channel4 = [pool channelWithHost:kDummyHost2 callOptions:options1];
52
53   XCTAssertNotNil(channel1);
54   XCTAssertNotNil(channel2);
55   XCTAssertNotNil(channel3);
56   XCTAssertNotNil(channel4);
57   XCTAssertEqual(channel1, channel2);
58   XCTAssertNotEqual(channel1, channel3);
59   XCTAssertNotEqual(channel1, channel4);
60   XCTAssertNotEqual(channel3, channel4);
61 }
62
63 @end