aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/Example/Tests
diff options
context:
space:
mode:
authorGravatar Greg Soltis <gsoltis@google.com>2018-02-13 11:12:17 -0800
committerGravatar GitHub <noreply@github.com>2018-02-13 11:12:17 -0800
commit5f5f80825820487e1c7ed964c94a472e84adc552 (patch)
tree57ff66e437adc598a29976d24d6e14a5e9d57043 /Firestore/Example/Tests
parentc7c51a72d2c08284d3054730f6d40f86c9d579e2 (diff)
Keep track of number of queries in the query cache (#776)
* Implement schema versions * Style fixes * newlines, copyrights, assumptions * Fix nullability * Raw ptr -> shared_ptr * kVersionTableGlobal -> kVersionGlobalTable * Drop utils, move into static methods * Drop extra include * Add a few more comments * Move version constant into migrations file * formatting? * Fix comment * Split add and update queryData * Work on adding targetCount * More work on count * Using shared_ptr * Implement count for query cache * use quotes * Add cast * Styling * Revert year bump in copyright * Add adversarial key to migration test * Add comment * Fix style
Diffstat (limited to 'Firestore/Example/Tests')
-rw-r--r--Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm29
-rw-r--r--Firestore/Example/Tests/Local/FSTQueryCacheTests.mm3
2 files changed, 32 insertions, 0 deletions
diff --git a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
index 8ef0e94..3559d5d 100644
--- a/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
+++ b/Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
@@ -18,13 +18,18 @@
#include <leveldb/db.h>
#import "Firestore/Protos/objc/firestore/local/Target.pbobjc.h"
+#import "Firestore/Source/Local/FSTLevelDBKey.h"
#import "Firestore/Source/Local/FSTLevelDBMigrations.h"
#import "Firestore/Source/Local/FSTLevelDBQueryCache.h"
+#import "Firestore/Source/Local/FSTWriteGroup.h"
+
+#include "Firestore/core/src/firebase/firestore/util/ordered_code.h"
#import "Firestore/Example/Tests/Local/FSTPersistenceTestHelpers.h"
NS_ASSUME_NONNULL_BEGIN
+using firebase::firestore::util::OrderedCode;
using leveldb::DB;
using leveldb::Options;
using leveldb::Status;
@@ -70,6 +75,30 @@ using leveldb::Status;
XCTAssertGreaterThan(actual, 0, @"Expected to migrate to a schema version > 0");
}
+- (void)testCountsQueries {
+ NSUInteger expected = 50;
+ FSTWriteGroup *group = [FSTWriteGroup groupWithAction:@"Setup"];
+ for (int i = 0; i < expected; i++) {
+ std::string key = [FSTLevelDBTargetKey keyWithTargetID:i];
+ [group setData:"dummy" forKey:key];
+ }
+ // Add a dummy entry after the targets to make sure the iteration is correctly bounded.
+ // Use a table that would sort logically right after that table 'target'.
+ std::string dummyKey;
+ // Magic number that indicates a table name follows. Needed to mimic the prefix to the target
+ // table.
+ OrderedCode::WriteSignedNumIncreasing(&dummyKey, 5);
+ OrderedCode::WriteString(&dummyKey, "targetA");
+ [group setData:"dummy" forKey:dummyKey];
+
+ Status status = [group writeToDB:_db];
+ XCTAssertTrue(status.ok(), @"Failed to write targets");
+
+ [FSTLevelDBMigrations runMigrationsOnDB:_db];
+ FSTPBTargetGlobal *metadata = [FSTLevelDBQueryCache readTargetMetadataFromDB:_db];
+ XCTAssertEqual(expected, metadata.targetCount, @"Failed to count all of the targets we added");
+}
+
@end
NS_ASSUME_NONNULL_END
diff --git a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm
index 0c6a2a4..6ab655a 100644
--- a/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm
+++ b/Firestore/Example/Tests/Local/FSTQueryCacheTests.mm
@@ -89,6 +89,7 @@ NS_ASSUME_NONNULL_BEGIN
FSTQueryData *data2 = [self queryDataWithQuery:q2];
[self addQueryData:data2];
+ XCTAssertEqual(2, [self.queryCache count]);
XCTAssertEqualObjects([self.queryCache queryDataForQuery:q1], data1);
XCTAssertEqualObjects([self.queryCache queryDataForQuery:q2], data2);
@@ -96,10 +97,12 @@ NS_ASSUME_NONNULL_BEGIN
[self removeQueryData:data1];
XCTAssertNil([self.queryCache queryDataForQuery:q1]);
XCTAssertEqualObjects([self.queryCache queryDataForQuery:q2], data2);
+ XCTAssertEqual(1, [self.queryCache count]);
[self removeQueryData:data2];
XCTAssertNil([self.queryCache queryDataForQuery:q1]);
XCTAssertNil([self.queryCache queryDataForQuery:q2]);
+ XCTAssertEqual(0, [self.queryCache count]);
}
- (void)testSetQueryToNewValue {