Created
September 15, 2016 08:54
-
-
Save tomblench/9da4e9a82ea28299c94474a39e8a3d43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)testCompactedConflictedTree | |
{ | |
NSError * error; | |
CDTDocumentRevision *mutableRev; | |
mutableRev = [CDTDocumentRevision revisionWithDocId:@"aTestDocId"]; | |
mutableRev.body = [@{ @"hello" : @"world" } mutableCopy]; | |
CDTDocumentRevision * rev = [self.datastore createDocumentFromRevision:mutableRev error:&error]; | |
XCTAssertNotNil(rev, @"Document was not created"); | |
//borrow conversion code from update then do force insert | |
NSMutableArray *leafRevIds = [NSMutableArray array]; | |
for (int i=0;i<10;i++) { | |
NSDictionary *newBody = @{ @"leaf_number" : @(i)}; | |
TD_Revision *converted = [[TD_Revision alloc]initWithDocID:rev.docId | |
revID:rev.revId | |
deleted:rev.deleted]; | |
converted.body = [[TD_Body alloc] initWithProperties:newBody]; | |
TDStatus status; | |
TD_Revision *leaf = [self.datastore.database putRevision:converted | |
prevRevisionID:rev.revId | |
allowConflict:YES | |
status:&status]; | |
XCTAssertTrue(status == 201, @"Status not 0, found %ld", (long)status); | |
[leafRevIds addObject:leaf.revID]; | |
} | |
for(NSString *revId in leafRevIds) { | |
CDTDocumentRevision *leaf = [self.datastore getDocumentWithId:rev.docId rev:revId error:&error]; | |
XCTAssertTrue(leaf.body != nil, @"Leaf body must not be nil"); | |
} | |
[self.datastore compactWithError:&error]; | |
// check root tidied up | |
CDTDocumentRevision *root = [self.datastore getDocumentWithId:rev.docId rev:rev.revId error:&error]; | |
XCTAssertTrue(root.body == nil, @"Root body must be nil"); | |
// check leafs not tidied up | |
for(NSString *revId in leafRevIds) { | |
CDTDocumentRevision *leaf = [self.datastore getDocumentWithId:rev.docId rev:revId error:&error]; | |
XCTAssertTrue(leaf.body != nil, @"Leaf body must not be nil"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment