1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
#import <objc/Ice.h>
#import <TestCommon.h>
#import <RetryTest.h>
#import <Foundation/Foundation.h>
@interface TestRetryCallback : NSObject
{
BOOL called;
NSCondition* cond;
}
-(void) check;
-(void) called;
@end
@implementation TestRetryCallback
-(id) init
{
self = [super init];
if(!self)
{
return nil;
}
cond = [[NSCondition alloc] init];
return self;
}
#if defined(__clang__) && !__has_feature(objc_arc)
-(void) dealloc
{
[cond release];
[super dealloc];
}
#endif
-(void) check
{
[cond lock];
while(!called)
{
[cond wait];
}
called = NO;
[cond unlock];
}
-(void) called
{
[cond lock];
called = YES;
[cond signal];
[cond unlock];
}
-(void) retryOpResponse
{
[self called];
}
-(void) retryOpException:(ICEException*)__unused ex
{
test(NO);
}
-(void) killRetryOpResponse
{
test(NO);
}
-(void) killRetryOpException:(ICEException*)ex
{
test([ex isKindOfClass:[ICEConnectionLostException class]] ||
[ex isKindOfClass:[ICEUnknownLocalException class]]);
[self called];
};
@end
id<TestRetryRetryPrx>
retryAllTests(id<ICECommunicator> communicator)
{
tprintf("testing stringToProxy... ");
NSString* ref = @"retry:default -p 12010";
id<ICEObjectPrx> base1 = [communicator stringToProxy:ref];
test(base1);
id<ICEObjectPrx> base2 = [communicator stringToProxy:ref];
test(base2);
tprintf("ok\n");
tprintf("testing checked cast... ");
id<TestRetryRetryPrx> retry1 = [TestRetryRetryPrx checkedCast:base1];
test(retry1);
test([retry1 isEqual:base1]);
id<TestRetryRetryPrx> retry2 = [TestRetryRetryPrx checkedCast:base2];
test(retry2);
test([retry2 isEqual:base2]);
tprintf("ok\n");
tprintf("calling regular operation with first proxy... ");
[retry1 op:NO];
tprintf("ok\n");
tprintf("calling operation to kill connection with second proxy... ");
@try
{
[retry2 op:YES];
test(NO);
}
@catch(ICEUnknownLocalException*)
{
// Expected with collocation
}
@catch(ICEConnectionLostException*)
{
}
tprintf("ok\n");
tprintf("calling regular operation with first proxy again... ");
[retry1 op:NO];
tprintf("ok\n");
TestRetryCallback* cb1 = ICE_AUTORELEASE([[TestRetryCallback alloc] init]);
TestRetryCallback* cb2 = ICE_AUTORELEASE([[TestRetryCallback alloc] init]);
tprintf("calling regular AMI operation with first proxy... ");
[retry1 begin_op:NO response:^{ [cb1 retryOpResponse]; }
exception:^(ICEException* ex) { [cb1 retryOpException:ex]; }];
[cb1 check];
tprintf("ok\n");
tprintf("calling AMI operation to kill connection with second proxy... ");
[retry2 begin_op:YES response:^{ [cb2 killRetryOpResponse]; }
exception:^(ICEException* ex) { [cb2 killRetryOpException:ex]; }];
[cb2 check];
tprintf("ok\n");
tprintf("calling regular AMI operation with first proxy again... ");
[retry1 begin_op:NO response:^{ [cb1 retryOpResponse]; }
exception:^(ICEException* ex) { [cb1 retryOpException:ex]; }];
[cb1 check];
tprintf("ok\n");
return retry1;
}
|