Skip to content

Migrate FSTTargetID to C++ TargetId #1697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Firestore/Example/Benchmarks/FSTLevelDBBenchmarkTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@

#include "Firestore/core/src/firebase/firestore/local/leveldb_key.h"
#include "Firestore/core/src/firebase/firestore/local/leveldb_transaction.h"
#include "Firestore/core/src/firebase/firestore/model/types.h"

NS_ASSUME_NONNULL_BEGIN

using firebase::firestore::local::LevelDbTargetDocumentKey;
using firebase::firestore::local::LevelDbTransaction;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::TargetId;

namespace {

Expand Down Expand Up @@ -113,7 +115,7 @@ void FillDB() {
protected:
void WriteIndex(LevelDbTransaction &txn, FSTDocumentKey *docKey) {
// Arbitrary target ID
FSTTargetID targetID = 1;
TargetId targetID = 1;
txn.Put(LevelDbDocumentTargetKey::Key(docKey, targetID), emptyBuffer_);
txn.Put(LevelDbTargetDocumentKey::Key(targetID, docKey), emptyBuffer_);
}
Expand Down
14 changes: 8 additions & 6 deletions Firestore/Example/Tests/Local/FSTLRUGarbageCollectorTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@
#include "Firestore/core/src/firebase/firestore/auth/user.h"
#include "Firestore/core/src/firebase/firestore/model/document_key_set.h"
#include "Firestore/core/src/firebase/firestore/model/precondition.h"
#include "Firestore/core/src/firebase/firestore/model/types.h"
#include "Firestore/core/test/firebase/firestore/testutil/testutil.h"
#include "absl/strings/str_cat.h"

namespace testutil = firebase::firestore::testutil;
using firebase::firestore::auth::User;
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::DocumentKeyHash;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::Precondition;
namespace testutil = firebase::firestore::testutil;
using firebase::firestore::model::TargetId;

NS_ASSUME_NONNULL_BEGIN

@implementation FSTLRUGarbageCollectorTests {
FSTTargetID _previousTargetID;
TargetId _previousTargetID;
int _previousDocNum;
FSTObjectValue *_testValue;
FSTObjectValue *_bigObjectValue;
Expand Down Expand Up @@ -121,7 +123,7 @@ - (int)removeOrphanedDocumentsThroughSequenceNumber:(FSTListenSequenceNumber)seq
}

- (FSTQueryData *)nextTestQuery {
FSTTargetID targetID = ++_previousTargetID;
TargetId targetID = ++_previousTargetID;
FSTListenSequenceNumber listenSequenceNumber = _persistence.currentSequenceNumber;
FSTQuery *query = FSTTestQuery(absl::StrCat("path", targetID));
return [[FSTQueryData alloc] initWithQuery:query
Expand Down Expand Up @@ -175,11 +177,11 @@ - (void)markDocumentEligibleForGCInTransaction:(const DocumentKey &)docKey {
[_persistence.referenceDelegate removeMutationReference:docKey];
}

- (void)addDocument:(const DocumentKey &)docKey toTarget:(FSTTargetID)targetId {
- (void)addDocument:(const DocumentKey &)docKey toTarget:(TargetId)targetId {
[_queryCache addMatchingKeys:DocumentKeySet{docKey} forTargetID:targetId];
}

- (void)removeDocument:(const DocumentKey &)docKey fromTarget:(FSTTargetID)targetId {
- (void)removeDocument:(const DocumentKey &)docKey fromTarget:(TargetId)targetId {
[_queryCache removeMatchingKeys:DocumentKeySet{docKey} forTargetID:targetId];
}

Expand Down Expand Up @@ -639,4 +641,4 @@ - (void)testRemoveTargetsThenGC {
}
@end

NS_ASSUME_NONNULL_END
NS_ASSUME_NONNULL_END
5 changes: 3 additions & 2 deletions Firestore/Example/Tests/Local/FSTLevelDBMigrationsTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
using firebase::firestore::local::LevelDbTargetDocumentKey;
using firebase::firestore::local::LevelDbTargetKey;
using firebase::firestore::local::LevelDbTransaction;
using firebase::firestore::util::OrderedCode;
using firebase::firestore::model::TargetId;
using firebase::firestore::testutil::Key;
using firebase::firestore::util::OrderedCode;
using leveldb::DB;
using leveldb::Options;
using leveldb::Status;
Expand Down Expand Up @@ -119,7 +120,7 @@ - (void)testSetsVersionNumber {
- (void)testDropsTheQueryCache {
std::string userID{"user"};
FSTBatchID batchID = 1;
FSTTargetID targetID = 2;
TargetId targetID = 2;

FSTDocumentKey *key1 = Key("documents/1");
FSTDocumentKey *key2 = Key("documents/2");
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Example/Tests/Local/FSTLevelDBQueryCacheTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::ResourcePath;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::TargetId;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -75,7 +76,7 @@ - (void)testMetadataPersistedAcrossRestarts {
XCTAssertEqual(versionZero, queryCache.lastRemoteSnapshotVersion);

FSTListenSequenceNumber minimumSequenceNumber = 1234;
FSTTargetID lastTargetId = 5;
TargetId lastTargetId = 5;
SnapshotVersion lastVersion(Timestamp(1, 2));

db1.run("add query data", [&]() {
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Example/Tests/Local/FSTLocalSerializerTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
using firebase::firestore::model::FieldMask;
using firebase::firestore::model::Precondition;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::TargetId;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -161,7 +162,7 @@ - (void)testEncodesDeletedDocumentAsMaybeDocument {

- (void)testEncodesQueryData {
FSTQuery *query = FSTTestQuery("room");
FSTTargetID targetID = 42;
TargetId targetID = 42;
SnapshotVersion version = testutil::Version(1039);
NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(1039);

Expand Down
37 changes: 19 additions & 18 deletions Firestore/Example/Tests/Local/FSTLocalStoreTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
using firebase::firestore::auth::User;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::TargetId;

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -56,7 +57,7 @@ @interface FSTLocalStoreTests ()

@property(nonatomic, strong, readonly) NSMutableArray<FSTMutationBatch *> *batches;
@property(nonatomic, strong, readwrite, nullable) FSTMaybeDocumentDictionary *lastChanges;
@property(nonatomic, assign, readwrite) FSTTargetID lastTargetID;
@property(nonatomic, assign, readwrite) TargetId lastTargetID;

@end

Expand Down Expand Up @@ -144,7 +145,7 @@ - (void)rejectMutation {
self.lastChanges = [self.localStore rejectBatchID:batch.batchID];
}

- (FSTTargetID)allocateQuery:(FSTQuery *)query {
- (TargetId)allocateQuery:(FSTQuery *)query {
FSTQueryData *queryData = [self.localStore allocateQuery:query];
self.lastTargetID = queryData.targetID;
return queryData.targetID;
Expand Down Expand Up @@ -240,7 +241,7 @@ - (void)testHandlesSetMutationThenDocument {
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self
applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"changed"}, NO),
Expand All @@ -254,7 +255,7 @@ - (void)testHandlesAckThenRejectThenRemoteEvent {

// Start a query that requires acks to be held.
FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
Expand Down Expand Up @@ -285,7 +286,7 @@ - (void)testHandlesDeletedDocumentThenSetMutationThenAck {
if ([self isTestBaseClass]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDeletedDoc("foo/bar", 2), @[ @(targetID) ],
@[])];
Expand Down Expand Up @@ -318,7 +319,7 @@ - (void)testHandlesSetMutationThenDeletedDocument {
if ([self isTestBaseClass]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self writeMutation:FSTTestSetMutation(@"foo/bar", @{@"foo" : @"bar"})];
FSTAssertChanged(@[ FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES) ]);
Expand All @@ -334,7 +335,7 @@ - (void)testHandlesDocumentThenSetMutationThenAckThenDocument {

// Start a query that requires acks to be held.
FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"it" : @"base"}, NO),
@[ @(targetID) ])];
Expand Down Expand Up @@ -377,7 +378,7 @@ - (void)testHandlesPatchMutationThenDocumentThenAck {
FSTAssertNotContains(@"foo/bar");

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
@[ @(targetID) ])];
Expand Down Expand Up @@ -410,7 +411,7 @@ - (void)testHandlesPatchMutationThenAckThenDocument {
FSTAssertNotContains(@"foo/bar");

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
@[ @(targetID) ], @[])];
Expand All @@ -437,7 +438,7 @@ - (void)testHandlesDocumentThenDeleteMutationThenAck {
if ([self isTestBaseClass]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
@[ @(targetID) ], @[])];
Expand All @@ -463,7 +464,7 @@ - (void)testHandlesDeleteMutationThenDocumentThenAck {
if ([self isTestBaseClass]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self writeMutation:FSTTestDeleteMutation(@"foo/bar")];
FSTAssertRemoved(@[ @"foo/bar" ]);
Expand Down Expand Up @@ -491,7 +492,7 @@ - (void)testHandlesDocumentThenDeletedDocumentThenDocument {
if ([self isTestBaseClass]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
@[ @(targetID) ], @[])];
Expand Down Expand Up @@ -524,7 +525,7 @@ - (void)testHandlesSetMutationThenPatchMutationThenDocumentThenAckThenAck {
FSTAssertContains(FSTTestDoc("foo/bar", 0, @{@"foo" : @"bar"}, YES));

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"it" : @"base"}, NO),
@[ @(targetID) ], @[])];
Expand Down Expand Up @@ -631,7 +632,7 @@ - (void)testCollectsGarbageAfterChangeBatch {
if (![self gcIsEager]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 2, @{@"foo" : @"bar"}, NO),
@[ @(targetID) ])];
Expand All @@ -648,7 +649,7 @@ - (void)testCollectsGarbageAfterAcknowledgedMutation {
if (![self gcIsEager]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO),
@[ @(targetID) ], @[])];
Expand Down Expand Up @@ -683,7 +684,7 @@ - (void)testCollectsGarbageAfterRejectedMutation {
if (![self gcIsEager]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestUpdateRemoteEvent(FSTTestDoc("foo/bar", 0, @{@"foo" : @"old"}, NO),
@[ @(targetID) ], @[])];
Expand Down Expand Up @@ -718,7 +719,7 @@ - (void)testPinsDocumentsInTheLocalView {
if (![self gcIsEager]) return;

FSTQuery *query = FSTTestQuery("foo");
FSTTargetID targetID = [self allocateQuery:query];
TargetId targetID = [self allocateQuery:query];

[self applyRemoteEvent:FSTTestAddedRemoteEvent(FSTTestDoc("foo/bar", 1, @{@"foo" : @"bar"}, NO),
@[ @(targetID) ])];
Expand Down Expand Up @@ -749,7 +750,7 @@ - (void)testThrowsAwayDocumentsWithUnknownTargetIDsImmediately {
if ([self isTestBaseClass]) return;
if (![self gcIsEager]) return;

FSTTargetID targetID = 321;
TargetId targetID = 321;
[self applyRemoteEvent:FSTTestUpdateRemoteEventWithLimboTargets(FSTTestDoc("foo/bar", 1, @{}, NO),
@[], @[], @[ @(targetID) ])];

Expand Down
11 changes: 6 additions & 5 deletions Firestore/Example/Tests/Local/FSTQueryCacheTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@

namespace testutil = firebase::firestore::testutil;
using firebase::firestore::model::DocumentKey;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::DocumentKeySet;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::TargetId;

NS_ASSUME_NONNULL_BEGIN

@implementation FSTQueryCacheTests {
FSTQuery *_queryRooms;
FSTListenSequenceNumber _previousSequenceNumber;
FSTTargetID _previousTargetID;
TargetId _previousTargetID;
FSTTestSnapshotVersion _previousSnapshotVersion;
}

Expand Down Expand Up @@ -363,7 +364,7 @@ - (FSTQueryData *)queryDataWithQuery:(FSTQuery *)query {
}

- (FSTQueryData *)queryDataWithQuery:(FSTQuery *)query
targetID:(FSTTargetID)targetID
targetID:(TargetId)targetID
listenSequenceNumber:(FSTListenSequenceNumber)sequenceNumber
version:(FSTTestSnapshotVersion)version {
NSData *resumeToken = FSTTestResumeTokenFromSnapshotVersion(version);
Expand All @@ -375,12 +376,12 @@ - (FSTQueryData *)queryDataWithQuery:(FSTQuery *)query
resumeToken:resumeToken];
}

- (void)addMatchingKey:(const DocumentKey &)key forTargetID:(FSTTargetID)targetID {
- (void)addMatchingKey:(const DocumentKey &)key forTargetID:(TargetId)targetID {
DocumentKeySet keys{key};
[self.queryCache addMatchingKeys:keys forTargetID:targetID];
}

- (void)removeMatchingKey:(const DocumentKey &)key forTargetID:(FSTTargetID)targetID {
- (void)removeMatchingKey:(const DocumentKey &)key forTargetID:(TargetId)targetID {
DocumentKeySet keys{key};
[self.queryCache removeMatchingKeys:keys forTargetID:targetID];
}
Expand Down
3 changes: 2 additions & 1 deletion Firestore/Example/Tests/SpecTests/FSTMockDatastore.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
using firebase::firestore::core::DatabaseInfo;
using firebase::firestore::model::DatabaseId;
using firebase::firestore::model::SnapshotVersion;
using firebase::firestore::model::TargetId;

@class GRPCProtoCall;

Expand Down Expand Up @@ -126,7 +127,7 @@ - (void)watchQuery:(FSTQueryData *)query {
self.activeTargets[@(query.targetID)] = sentQueryData;
}

- (void)unwatchTargetID:(FSTTargetID)targetID {
- (void)unwatchTargetID:(TargetId)targetID {
LOG_DEBUG("unwatchTargetID: %s", targetID);
[self.activeTargets removeObjectForKey:@(targetID)];
}
Expand Down
6 changes: 3 additions & 3 deletions Firestore/Example/Tests/SpecTests/FSTSpecTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ - (FSTDocumentViewChange *)parseChange:(NSArray *)change ofType:(FSTDocumentView

- (void)doListen:(NSArray *)listenSpec {
FSTQuery *query = [self parseQuery:listenSpec[1]];
FSTTargetID actualID = [self.driver addUserListenerWithQuery:query];
TargetId actualID = [self.driver addUserListenerWithQuery:query];

FSTTargetID expectedID = [listenSpec[0] intValue];
TargetId expectedID = [listenSpec[0] intValue];
XCTAssertEqual(actualID, expectedID, @"targetID assigned to listen");
}

Expand Down Expand Up @@ -579,7 +579,7 @@ - (void)validateStateExpectations:(nullable NSDictionary *)expected {
[expected[@"activeTargets"] enumerateKeysAndObjectsUsingBlock:^(NSString *targetIDString,
NSDictionary *queryData,
BOOL *stop) {
FSTTargetID targetID = [targetIDString intValue];
TargetId targetID = [targetIDString intValue];
FSTQuery *query = [self parseQuery:queryData[@"query"]];
NSData *resumeToken = [queryData[@"resumeToken"] dataUsingEncoding:NSUTF8StringEncoding];
// TODO(mcg): populate the purpose of the target once it's possible to encode that in the
Expand Down
Loading