Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Test improvments to support testing of various documnet sizes or key …
Browse files Browse the repository at this point in the history
…sizes
  • Loading branch information
lichenyang2 committed Jan 16, 2015
1 parent 1181ba0 commit 8fdc7e6
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 33 deletions.
8 changes: 6 additions & 2 deletions Tests/Test22_Query.m
Expand Up @@ -28,14 +28,18 @@ @implementation Test22_Query

- (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
@autoreleasepool {
// The kSizeofDocument affect overall size of doc, but not key size
NSMutableData* utf8 = [NSMutableData dataWithLength: kSizeofDocument];
memset(utf8.mutableBytes, '1', utf8.length);
NSString* str = [[NSString alloc] initWithData: utf8 encoding: NSUTF8StringEncoding];

[self.database inTransaction:^BOOL{
for (int i = 0; i < kNumberOfDocuments; i++) {
@autoreleasepool {
NSString* name = [NSString stringWithFormat:@"%@%@", @"n", @(i)];
bool vacant = (i+2) % 2 ? 1 : 0;
NSDictionary* props = @{@"name":name,
@"apt": @(i),
@"phone":@(408100000+i),
@"apt": [NSString stringWithFormat:@"%@%@", str, @(i)],
@"vacant":@(vacant)};
CBLDocument* doc = [self.database createDocument];
NSError* error;
Expand Down
8 changes: 6 additions & 2 deletions Tests/Test23_ReduceQuery.m
Expand Up @@ -20,14 +20,18 @@ @implementation Test23_ReduceQuery

- (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
@autoreleasepool {
// The kSizeofDocument affect overall size of doc, but not key size
NSMutableData* utf8 = [NSMutableData dataWithLength: kSizeofDocument];
memset(utf8.mutableBytes, '1', utf8.length);
NSString* str = [[NSString alloc] initWithData: utf8 encoding: NSUTF8StringEncoding];

[self.database inTransaction:^BOOL{
for (int i = 0; i < kNumberOfDocuments; i++) {
@autoreleasepool {
NSString* name = [NSString stringWithFormat:@"%@%@", @"n", @(i)];
bool vacant = (i+2) % 2 ? 1 : 0;
NSDictionary* props = @{@"name":name,
@"apt": @(i),
@"phone":@(408100000+i),
@"apt": [NSString stringWithFormat:@"%@%@", str, @(i)],
@"vacant":@(vacant)};
CBLDocument* doc = [self.database createDocument];
NSError* error;
Expand Down
16 changes: 11 additions & 5 deletions Tests/Test26_PushReplicateWithAttachment.m
Expand Up @@ -96,14 +96,15 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofAttachment
NSURL *syncGateway = [NSURL URLWithString:syncGatewayUrl];
self.push = [self.database createPushReplication: syncGateway];
[self logFormat: @"Starting Push Replication"];

// Start measuring time from here
NSDate* start = [NSDate date];
[self.push start];

NSNotificationCenter* nctr = [NSNotificationCenter defaultCenter];
[nctr addObserver: self selector: @selector(pushReplicationChanged:)
name: kCBLReplicationChangeNotification object: self.push];


// Start measuring time from here
NSDate* start = [NSDate date];
[self.push start];

replicationRunning = YES;
while (replicationRunning) {
[[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
Expand All @@ -113,7 +114,12 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofAttachment
NSDate *methodFinish = [NSDate date];
[self logFormat: @"Push Replication Stopped"];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start] * 1000;

[nctr removeObserver:self name:kCBLReplicationChangeNotification object:self.push];
self.push = nil;

[self deleteDatabase];

sleep(20);
return executionTime;
}
Expand Down
22 changes: 11 additions & 11 deletions Tests/Test28_KeySizes.m
Expand Up @@ -25,6 +25,7 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
NSDate *start;
NSTimeInterval executionTimeTotal;
NSDate* methodFinish;
// The kSizeofDocument affect key size
NSMutableData* utf8 = [NSMutableData dataWithLength: kSizeofDocument];
memset(utf8.mutableBytes, '1', utf8.length);
NSString* str = [[NSString alloc] initWithData: utf8 encoding: NSUTF8StringEncoding];
Expand All @@ -41,7 +42,6 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
bool vacant = (i+2) % 2 ? 1 : 0;
NSDictionary* props = @{@"name":name,
@"apt": @(i),
@"phone":@(408100000+i),
@"vacant":@(vacant)};
CBLDocument* doc = [self.database createDocument];
NSError* error;
Expand All @@ -61,9 +61,9 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
id apt = [doc objectForKey: @"apt"];
id name = [doc objectForKey: @"name"];
//large key, small value
//if (apt && name) emit(name, apt);
if (apt && name) emit(name, apt);
//small key, large value
if (apt && name) emit(apt, name);
//if (apt && name) emit(apt, name);
}) reduceBlock: REDUCEBLOCK({
return @([values count]);
}) version: @"3"];
Expand All @@ -73,9 +73,9 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
// query
CBLQuery* query = [[self.database viewNamed: @"vacant"] createQuery];
query.mapOnly = YES;
// query.descending = NO;
// query.startKey = @0;
// query.endKey = [NSNumber numberWithInt:kNumberOfDocuments];
// query.descending = NO;
// query.startKey = @0;
// query.endKey = [NSNumber numberWithInt:kNumberOfDocuments];
CBLQueryEnumerator* rowEnum = [query run: &error];
for (CBLQueryRow* row in rowEnum) {
@autoreleasepool {
Expand All @@ -86,15 +86,15 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
}

// Reduce query
// CBLQuery* query = [[self.database viewNamed: @"vacant"] createQuery];
// query.mapOnly = NO;
// CBLQueryEnumerator* rowEnum = [query run: &error];
// CBLQueryRow *row = [rowEnum nextRow];
// CBLQuery* query = [[self.database viewNamed: @"vacant"] createQuery];
// query.mapOnly = NO;
// CBLQueryEnumerator* rowEnum = [query run: &error];
// CBLQueryRow *row = [rowEnum nextRow];

methodFinish = [NSDate date];
executionTimeTotal = [methodFinish timeIntervalSinceDate:start] * 1000;

[self logFormat: @"--- Query return %d records", rowEnum.count];
//[self logFormat: @"--- Query return %d records", rowEnum.count];
}
return executionTimeTotal;
}
Expand Down
14 changes: 6 additions & 8 deletions Tests/Test29_AllDocQuery.m
Expand Up @@ -19,21 +19,19 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
NSString *value = [[NSString alloc] init];
NSDate *start = [NSDate date];
NSTimeInterval executionTimeTotal;
NSMutableData* utf8 = [NSMutableData dataWithLength: kSizeofDocument];
memset(utf8.mutableBytes, '1', utf8.length);
NSString* str = [[NSString alloc] initWithData: utf8 encoding: NSUTF8StringEncoding];


// Create docs
[self.database inTransaction:^BOOL{
// The kSizeofDocument affect overall size of doc, but not key size
NSMutableData* utf8 = [NSMutableData dataWithLength: kSizeofDocument];
memset(utf8.mutableBytes, '1', utf8.length);
NSString* str = [[NSString alloc] initWithData: utf8 encoding: NSUTF8StringEncoding]; [self.database inTransaction:^BOOL{
for (int i = 0; i < kNumberOfDocuments; i++) {
@autoreleasepool {
NSUInteger r = arc4random_uniform(kNumberOfDocuments-1) + 1;
NSString* name = [NSString stringWithFormat:@"%@%@", str, @(r)];
bool vacant = (i+2) % 2 ? 1 : 0;
NSDictionary* props = @{@"name":name,
@"apt": @(i),
@"phone":@(408100000+i),
@"apt": [NSString stringWithFormat:@"%@%@", str, @(i)],
@"vacant":@(vacant)};
CBLDocument* doc = [self.database createDocument];
[self.docs addObject:doc];
Expand Down Expand Up @@ -72,7 +70,7 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
NSDate* methodFinish = [NSDate date];
executionTimeTotal = [methodFinish timeIntervalSinceDate:start] * 1000;

[self logFormat: @"Query result count - %u",(unsigned int)rowEnum.count];
//[self logFormat: @"Query result count - %u",(unsigned int)rowEnum.count];

return executionTimeTotal;
}
Expand Down
7 changes: 3 additions & 4 deletions Tests/Test30_LiveQuery.m
Expand Up @@ -54,7 +54,7 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
[view setMapBlock: MAPBLOCK({
id apt = [doc objectForKey: @"apt"];
id name = [doc objectForKey: @"name"];
if (apt && name) emit(apt, name);
if (apt && name) emit(name, apt);
}) reduceBlock: REDUCEBLOCK({
return @([values count]);
}) version: @"3"];
Expand All @@ -76,11 +76,10 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
for (int i = 0; i < kNumberOfDocuments; i++) {
@autoreleasepool {
NSUInteger r = arc4random_uniform(kNumberOfDocuments-1) + 1;
NSString* name = [NSString stringWithFormat:@"%@%@", str, @(r)];
NSString* name = [NSString stringWithFormat:@"%@%@", @"n", @(r)];
bool vacant = (i+2) % 2 ? 1 : 0;
NSDictionary* props = @{@"name":name,
@"apt": @(i),
@"phone":@(408100000+i),
@"apt": [NSString stringWithFormat:@"%@%@", str, @(i)],
@"vacant":@(vacant)};
CBLDocument* doc = [self.database createDocument];
NSError* error;
Expand Down
7 changes: 6 additions & 1 deletion Tests/Test9_LoadDB.m
Expand Up @@ -74,14 +74,19 @@ - (double) runOne:(int)kNumberOfDocuments sizeOfDocuments:(int)kSizeofDocument {
// Shutdown database
[self.mymanager close];
self.mymanager = nil;

//NSDate *start2 = [NSDate date];

// Recreate database
CBLDatabase* db = [self mydatabase];
if (!db) {
[self logFormat:@"Error database not found"];
}

NSDate *methodFinish = [NSDate date];

//NSTimeInterval shutdownTime = [start2 timeIntervalSinceDate:start] * 1000;
//NSTimeInterval recreateTime = [methodFinish timeIntervalSinceDate:start2] * 1000;
//[self logFormat: @"Shutdown %.02f, recreate %.02f ", shutdownTime,recreateTime];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:start] * 1000;
return executionTime;
}
Expand Down

0 comments on commit 8fdc7e6

Please sign in to comment.