ChannelPoolTest.m 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #import <XCTest/XCTest.h>
  19. #import "../../GRPCClient/private/GRPCChannel.h"
  20. #import "../../GRPCClient/private/GRPCChannelPool+Test.h"
  21. #import "../../GRPCClient/private/GRPCCompletionQueue.h"
  22. #define TEST_TIMEOUT 32
  23. static NSString *kDummyHost = @"dummy.host";
  24. static NSString *kDummyHost2 = @"dummy.host.2";
  25. static NSString *kDummyPath = @"/dummy/path";
  26. @interface ChannelPoolTest : XCTestCase
  27. @end
  28. @implementation ChannelPoolTest
  29. + (void)setUp {
  30. grpc_init();
  31. }
  32. - (void)testCreateAndCacheChannel {
  33. GRPCChannelPool *pool = [[GRPCChannelPool alloc] initTestPool];
  34. GRPCCallOptions *options1 = [[GRPCCallOptions alloc] init];
  35. GRPCCallOptions *options2 = [options1 copy];
  36. GRPCMutableCallOptions *options3 = [options1 mutableCopy];
  37. options3.transportType = GRPCTransportTypeInsecure;
  38. GRPCPooledChannel *channel1 = [pool channelWithHost:kDummyHost callOptions:options1];
  39. GRPCPooledChannel *channel2 = [pool channelWithHost:kDummyHost callOptions:options2];
  40. GRPCPooledChannel *channel3 = [pool channelWithHost:kDummyHost callOptions:options3];
  41. GRPCPooledChannel *channel4 = [pool channelWithHost:kDummyHost2 callOptions:options1];
  42. XCTAssertNotNil(channel1);
  43. XCTAssertNotNil(channel2);
  44. XCTAssertNotNil(channel3);
  45. XCTAssertNotNil(channel4);
  46. XCTAssertEqual(channel1, channel2);
  47. XCTAssertNotEqual(channel1, channel3);
  48. XCTAssertNotEqual(channel1, channel4);
  49. XCTAssertNotEqual(channel3, channel4);
  50. }
  51. @end