From 9524cd241d97b7505f14399cc659538898a575a3 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 5 Oct 2021 00:52:00 +0100 Subject: Create a separate connection pool for write operations --- gentoobrowse-api/service/main.cpp | 5 +++-- gentoobrowse-api/unittests/mockDefs.cpp | 12 ++++++++++++ gentoobrowse-api/unittests/mockDefs.h | 10 ++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/gentoobrowse-api/service/main.cpp b/gentoobrowse-api/service/main.cpp index 8d21d92..7fd74ca 100644 --- a/gentoobrowse-api/service/main.cpp +++ b/gentoobrowse-api/service/main.cpp @@ -37,10 +37,11 @@ namespace Gentoo { const Ice::ObjectAdapterPtr & adp) override { auto db = getConnectionPool(ic, "postgresql", "GentooBrowseAPI"); + auto dbp = getConnectionPool(ic, "postgresql", "GentooBrowseAPIprimary"); auto props = ic->getProperties(); IceTray::Cube::addObject(adp, "portage", db); - IceTray::Cube::addObject(adp, "maintenance", db, ic, props); - IceTray::Cube::addObject(adp, "users", db); + IceTray::Cube::addObject(adp, "maintenance", dbp, ic, props); + IceTray::Cube::addObject(adp, "users", dbp); IceTray::Cube::add(); IceTray::Cube::add( props->getPropertyWithDefault("GentooBrowseAPI.MailServer", "localhost:25")); diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp index 60241cd..2152220 100644 --- a/gentoobrowse-api/unittests/mockDefs.cpp +++ b/gentoobrowse-api/unittests/mockDefs.cpp @@ -6,6 +6,18 @@ #include #include +DbAlias::DbAlias() +{ + AdHoc::PluginManager::getDefault()->add( + AdHoc::PluginManager::getDefault()->get("GentooBrowseAPI")->implementation(), + "GentooBrowseAPIprimary", __FILE__, __LINE__); +} + +DbAlias::~DbAlias() +{ + AdHoc::PluginManager::getDefault()->remove("GentooBrowseAPIprimary"); +} + Service::Service() : DB::PluginMock("GentooBrowseAPI", {rootDir.parent_path() / "db" / "schema.sql", rootDir / "data.sql"}, "user=postgres dbname=postgres") diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h index 7600e15..327f293 100644 --- a/gentoobrowse-api/unittests/mockDefs.h +++ b/gentoobrowse-api/unittests/mockDefs.h @@ -12,12 +12,18 @@ #include #include -class DLL_PUBLIC Service : public IceTray::DryIce, DB::PluginMock { +class DLL_PUBLIC DbAlias { +public: + DbAlias(); + virtual ~DbAlias(); +}; + +class DLL_PUBLIC Service : public IceTray::DryIce, DB::PluginMock, DbAlias { public: Service(); }; -class DLL_PUBLIC Maintenance : public IceTray::DryIce, DB::PluginMock { +class DLL_PUBLIC Maintenance : public IceTray::DryIce, DB::PluginMock, DbAlias { public: Maintenance(); }; -- cgit v1.2.3