Skip to content
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

Mila/multi db #1321

Merged
merged 23 commits into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ Firestore* FirestoreIntegrationTest::TestFirestore(
return TestFirestoreWithProjectId(name, /*project_id=*/"");
}

Firestore* FirestoreIntegrationTest::TestFirestoreWithDatabaseId(
const std::string& name, const std::string& database_id) const {
return TestFirestoreWithProjectId(name, /*project_id=*/"", database_id);
}

Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
const std::string& name, const std::string& project_id) const {
const std::string& name,
const std::string& project_id,
const std::string& database_id) const {
for (const auto& entry : firestores_) {
const FirestoreInfo& firestore_info = entry.second;
if (firestore_info.name() == name) {
if (firestore_info.name() == name &&
firestore_info.database_id() == database_id) {
return firestore_info.firestore();
}
}
Expand All @@ -129,9 +137,9 @@ Firestore* FirestoreIntegrationTest::TestFirestoreWithProjectId(
if (apps_.find(app) == apps_.end()) {
apps_[app] = std::unique_ptr<App>(app);
}

Firestore* db = new Firestore(CreateTestFirestoreInternal(app));
firestores_[db] = FirestoreInfo(name, std::unique_ptr<Firestore>(db));
Firestore* db = new Firestore(CreateTestFirestoreInternal(app, database_id));
firestores_[db] =
FirestoreInfo(name, database_id, std::unique_ptr<Firestore>(db));

firestore::LocateEmulator(db);
return db;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <mutex>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

#include "app/meta/move.h"
Expand All @@ -49,7 +50,8 @@ const int kCheckIntervalMillis = 100;
// The timeout of waiting for a Future or a listener.
const int kTimeOutMillis = 15000;

FirestoreInternal* CreateTestFirestoreInternal(App* app);
FirestoreInternal* CreateTestFirestoreInternal(
App* app, const std::string& database_id = kDefaultDatabase);

App* GetApp();
App* GetApp(const char* name, const std::string& override_project_id);
Expand Down Expand Up @@ -252,9 +254,16 @@ class FirestoreIntegrationTest : public testing::Test {
Firestore* TestFirestore(const std::string& name = kDefaultAppName) const;

// Returns a Firestore instance for an app with the given `name`, associated
// with the database with the given `project_id`.
Firestore* TestFirestoreWithProjectId(const std::string& name,
const std::string& project_id) const;
// with the database with the given `project_id` and default `database_id`.
Firestore* TestFirestoreWithProjectId(
const std::string& name,
const std::string& project_id,
const std::string& database_id = kDefaultDatabase) const;

// Returns a Firestore instance for an app with the given `name`, associated
// with the database with the given `database_id`.
Firestore* TestFirestoreWithDatabaseId(const std::string& name,
const std::string& database_id) const;

// Deletes the given `Firestore` instance, which must have been returned by a
// previous invocation of `TestFirestore()`, and removes it from the cache of
Expand Down Expand Up @@ -419,15 +428,22 @@ class FirestoreIntegrationTest : public testing::Test {
class FirestoreInfo {
public:
FirestoreInfo() = default;
FirestoreInfo(const std::string& name, std::unique_ptr<Firestore> firestore)
: name_(name), firestore_(std::move(firestore)) {}
FirestoreInfo(const std::string& name,
const std::string& database_id,
std::unique_ptr<Firestore> firestore)
: name_(name),
database_id_(database_id),
firestore_(std::move(firestore)) {}

const std::string& name() const { return name_; }
Firestore* firestore() const { return firestore_.get(); }
const std::string& database_id() const { return database_id_; }

void ReleaseFirestore() { firestore_.release(); }

private:
std::string name_;
std::string database_id_;
std::unique_ptr<Firestore> firestore_;
};

Expand Down
Loading