This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
/
Test05_ReadAttachments.m
59 lines (49 loc) · 1.83 KB
/
Test05_ReadAttachments.m
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
//
// Test05_ReadAttachments.m
// Worker Bee
//
// Created by Pasin Suriyentrakorn on 7/7/16.
// Copyright © 2016 Couchbase, Inc. All rights reserved.
//
#import "Test05_ReadAttachments.h"
@implementation Test05_ReadAttachments
- (void) setUp {
[super setUp];
[self run];
}
- (void) run {
NSInteger numDocs = [[self configForKey: @"numDocs"] integerValue];
NSInteger attSize = [[self configForKey: @"attSize"] integerValue];
NSMutableData* data = [NSMutableData dataWithLength: attSize];
memset(data.mutableBytes, 'a', data.length);
NSMutableArray* docs = [NSMutableArray arrayWithCapacity: numDocs];
[self.database inTransaction:^BOOL{
for (int i = 0; i < numDocs; i++) {
NSData* prefix = [NSData dataWithBytes: &i length: sizeof(i)];
NSMutableData *content = [NSMutableData dataWithLength: prefix.length + data.length];
[content appendData: prefix];
[content appendData: data];
NSError* error;
CBLDocument* doc = [self.database createDocument];
CBLUnsavedRevision* rev = [doc newRevision];
[rev setAttachmentNamed: @"attach" withContentType: @"text/plain" content: content];
if (![rev save: &error]) {
[self logFormat: @"ERROR: Failed to create doc : %@", error];
return NO;
}
[docs addObject: doc];
}
return YES;
}];
uint64_t t = dispatch_benchmark(1, ^{
for (CBLDocument* doc in docs) {
CBLAttachment* att = [[doc currentRevision] attachmentNamed: @"attach"];
if (att.content.length == 0) {
[self logFormat: @"ERROR: Failed to read an attchment"];
break;
}
}
});
[self logFormat: @"%@: finished in %f ms", self, (t/1000000.0)];
}
@end