summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-23 20:01:01 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-23 20:01:01 +0000
commit6f4c84b7841eb6670895c2a5ba708f538555dee7 (patch)
tree82286713df93e3d9122513e39b3379e54638ad73
parentSimplified escape sequence handling (diff)
downloadgentoobrowse-api-6f4c84b7841eb6670895c2a5ba708f538555dee7.tar.bz2
gentoobrowse-api-6f4c84b7841eb6670895c2a5ba708f538555dee7.tar.xz
gentoobrowse-api-6f4c84b7841eb6670895c2a5ba708f538555dee7.zip
Create IceTray and DryIce for bootstrapping and dry running IceBox services
-rw-r--r--gentoobrowse-api/etc/icebox.config2
-rw-r--r--gentoobrowse-api/service/Jamfile.jam1
-rw-r--r--gentoobrowse-api/service/abstractDatabaseClient.cpp34
-rw-r--r--gentoobrowse-api/service/abstractDatabaseClient.h64
-rw-r--r--gentoobrowse-api/service/main.cpp39
-rw-r--r--gentoobrowse-api/service/portageimpl.cpp4
-rw-r--r--gentoobrowse-api/service/portageimpl.h6
-rw-r--r--gentoobrowse-api/unittests/Jamfile.jam17
-rw-r--r--gentoobrowse-api/unittests/mockDefs.cpp9
-rw-r--r--gentoobrowse-api/unittests/mockDefs.h14
-rw-r--r--gentoobrowse-api/unittests/testInit.cpp26
-rw-r--r--gentoobrowse-api/unittests/testPortage.cpp74
12 files changed, 59 insertions, 231 deletions
diff --git a/gentoobrowse-api/etc/icebox.config b/gentoobrowse-api/etc/icebox.config
index 48ef26d..27ead52 100644
--- a/gentoobrowse-api/etc/icebox.config
+++ b/gentoobrowse-api/etc/icebox.config
@@ -1 +1 @@
-IceBox.Service.GentooBrowseAPI=gentoobrowse-service:createGentooBrowseAPI --GentooBrowseAPI.ThreadPool.Size=8 --GentooBrowseAPI.ThreadPool.SizeMax=50 --GentooBrowseAPI.Database.ConnectionString="user=postgres dbname=gentoo" --GentooBrowseAPI.Endpoints="tcp -p 9001"
+IceBox.Service.GentooBrowseAPI=gentoobrowse-service:createIceTrayService --GentooBrowseAPI.ThreadPool.Size=8 --GentooBrowseAPI.ThreadPool.SizeMax=50 --GentooBrowseAPI.Database.ConnectionString="user=postgres dbname=gentoo" --GentooBrowseAPI.Endpoints="tcp -p 9001"
diff --git a/gentoobrowse-api/service/Jamfile.jam b/gentoobrowse-api/service/Jamfile.jam
index 777c453..fd2e8b5 100644
--- a/gentoobrowse-api/service/Jamfile.jam
+++ b/gentoobrowse-api/service/Jamfile.jam
@@ -10,6 +10,7 @@ lib gentoobrowse-service :
:
<slicer>pure
<library>..//adhocutil
+ <library>../../icetray//icetray
<library>..//dbppcore
<library>..//IceBox
<library>..//slicer
diff --git a/gentoobrowse-api/service/abstractDatabaseClient.cpp b/gentoobrowse-api/service/abstractDatabaseClient.cpp
deleted file mode 100644
index 9844cc4..0000000
--- a/gentoobrowse-api/service/abstractDatabaseClient.cpp
+++ /dev/null
@@ -1,34 +0,0 @@
-#include "abstractDatabaseClient.h"
-#include <cache.impl.h>
-
-template class AdHoc::Cache<boost::shared_ptr<boost::any>, std::vector<std::size_t>>;
-
-AbstractDatabaseClient::AbstractDatabaseClient(AdHoc::ResourcePool<DB::Connection> & d) :
- db(d)
-{
-}
-
-template<>
-void
-AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const std::string & p)
-{
- cmd->bindParamS(o, p);
-}
-
-template<>
-void
-AbstractDatabaseClient::bind1(int o, DB::Command * cmd, const int & p)
-{
- cmd->bindParamI(o, p);
-}
-
-void
-AbstractDatabaseClient::bind(int, DB::Command *)
-{
-}
-
-void
-AbstractDatabaseClient::keyPushParams(CacheKey &)
-{
-}
-
diff --git a/gentoobrowse-api/service/abstractDatabaseClient.h b/gentoobrowse-api/service/abstractDatabaseClient.h
deleted file mode 100644
index a3072cb..0000000
--- a/gentoobrowse-api/service/abstractDatabaseClient.h
+++ /dev/null
@@ -1,64 +0,0 @@
-#ifndef ABSTRACTDATABASECLIENT_H
-#define ABSTRACTDATABASECLIENT_H
-
-#include <connectionPool.h>
-#include <db/sqlSelectDeserializer.h>
-#include <slicer/slicer.h>
-#include <cache.h>
-#include <boost/any.hpp>
-
-class AbstractDatabaseClient {
- protected:
- AbstractDatabaseClient(AdHoc::ResourcePool<DB::Connection> & d);
- typedef std::vector<std::size_t> CacheKey;
- typedef boost::shared_ptr<boost::any> CacheItem;
-
- template<typename Domain, typename Sql, typename ... Params>
- Domain inline fetch(const Params & ... params)
- {
- CacheKey key;
- key.reserve(4);
- key.push_back(Sql::hash);
- key.push_back(typeid(Domain).hash_code());
- keyPushParams(key, params...);
- if (auto cached = cache.get(key)) {
- return boost::any_cast<Domain>(**cached);
- }
- Domain d;
- {
- auto c = db.get();
- auto s = DB::SelectCommandPtr(c->newSelectCommand(Sql::sql));
- bind(0, s.get(), params...);
- d = Slicer::DeserializeAny<Slicer::SqlSelectDeserializer, Domain>(*s);
- }
- cache.add(key, CacheItem(new boost::any(d)), time(NULL) + 40);
- return d;
- }
-
- template<typename Param, typename ... Params>
- static void inline bind(int offset, DB::Command * cmd, const Param & p, const Params & ... params)
- {
- bind1(offset, cmd, p);
- bind(offset + 1, cmd, params...);
- }
-
- static void bind(int offset, DB::Command * cmd);
-
- template<typename Param>
- static void bind1(int offset, DB::Command * cmd, const Param & p);
-
- template<typename Param, typename ... Params>
- static void inline keyPushParams(CacheKey & k, const Param & p, const Params & ... params)
- {
- k.push_back(std::hash<Param>()(p));
- keyPushParams(k, params...);
- }
-
- static void keyPushParams(CacheKey &);
-
- AdHoc::ResourcePool<DB::Connection> & db;
- AdHoc::Cache<CacheItem, CacheKey> cache;
-};
-
-#endif
-
diff --git a/gentoobrowse-api/service/main.cpp b/gentoobrowse-api/service/main.cpp
index fcab795..21473af 100644
--- a/gentoobrowse-api/service/main.cpp
+++ b/gentoobrowse-api/service/main.cpp
@@ -1,39 +1,16 @@
-#include <Ice/Ice.h>
-#include <IceBox/IceBox.h>
-#include <visibility.h>
+#include <Ice/Communicator.h>
+#include <Ice/ObjectAdapter.h>
+#include <icetrayService.h>
#include "portageimpl.h"
-#include <connectionPool.h>
-class Api : public IceBox::Service {
+class Api : public IceTray::Service {
public:
- typedef boost::shared_ptr<DB::ConnectionPool> DBCPoolPtr;
- void start(const std::string & name, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &)
+ void addObjects(const std::string &, const Ice::CommunicatorPtr & ic, const Ice::StringSeq &, const Ice::ObjectAdapterPtr & adp) override
{
- db = DBCPoolPtr(new DB::ConnectionPool(
- ic->getProperties()->getPropertyAsIntWithDefault(name + ".Database.PoolMax", 10),
- ic->getProperties()->getPropertyAsIntWithDefault(name + ".Database.PoolKeep", 2),
- "postgresql",
- ic->getProperties()->getProperty(name + ".Database.ConnectionString")));
- adp = ic->createObjectAdapter(name);
- adp->add(new Portage(*db), ic->stringToIdentity("portage"));
- adp->activate();
+ auto db = getConnectionPool(ic, "postgresql", "GentooBrowseAPI");
+ adp->add(new Portage(db), ic->stringToIdentity("portage"));
}
- void stop()
- {
- adp->deactivate();
- adp->destroy();
- }
-
- DBCPoolPtr db;
- Ice::ObjectAdapterPtr adp;
};
-extern "C" {
- DLL_PUBLIC
- IceBox::Service *
- createGentooBrowseAPI(Ice::CommunicatorPtr)
- {
- return new Api();
- }
-}
+NAMEDFACTORY("default", Api, IceTray::ServiceFactory);
diff --git a/gentoobrowse-api/service/portageimpl.cpp b/gentoobrowse-api/service/portageimpl.cpp
index 408d467..291e903 100644
--- a/gentoobrowse-api/service/portageimpl.cpp
+++ b/gentoobrowse-api/service/portageimpl.cpp
@@ -17,8 +17,8 @@
#include <sql/portage/getNewsSearch.h>
#include <sql/portage/getNewsRecent.h>
-Portage::Portage(AdHoc::ResourcePool<DB::Connection> & d) :
- AbstractDatabaseClient(d)
+Portage::Portage(boost::shared_ptr<AdHoc::ResourcePool<DB::Connection>> d) :
+ IceTray::AbstractDatabaseClient(d)
{
}
diff --git a/gentoobrowse-api/service/portageimpl.h b/gentoobrowse-api/service/portageimpl.h
index 9a8246d..d36cb70 100644
--- a/gentoobrowse-api/service/portageimpl.h
+++ b/gentoobrowse-api/service/portageimpl.h
@@ -3,11 +3,11 @@
#include <portage.h>
#include <visibility.h>
-#include "abstractDatabaseClient.h"
+#include <abstractDatabaseClient.h>
-class DLL_PUBLIC Portage : public Gentoo::Portage, AbstractDatabaseClient {
+class DLL_PUBLIC Portage : public Gentoo::Portage, IceTray::AbstractDatabaseClient {
public:
- Portage(AdHoc::ResourcePool<DB::Connection> & d);
+ Portage(boost::shared_ptr<AdHoc::ResourcePool<DB::Connection>> d);
Gentoo::CategoryPtr getCategory(Ice::Int id, const Ice::Current &) override;
Gentoo::Categories getAllCategories(const Ice::Current &) override;
diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam
index e2a5b28..1a6f41c 100644
--- a/gentoobrowse-api/unittests/Jamfile.jam
+++ b/gentoobrowse-api/unittests/Jamfile.jam
@@ -21,9 +21,16 @@ lib testCommon :
<define>ROOT=\"$(me)\"
<library>..//boost_system
<library>..//boost_filesystem
+ <library>..//Ice
+ <library>..//IceUtil
+ <library>..//IceBox
+ <library>../../icetray//dryice
+ <library>../service//gentoobrowse-service
: :
<library>..//dbppcore
<library>..//adhocutil
+ <library>..//IceBox
+ <library>../../icetray//dryice
;
@@ -53,13 +60,3 @@ run testPerf.cpp
<library>boost_utf
: testPerf ;
-run testInit.cpp
- : : :
- <define>BOOST_TEST_DYN_LINK
- <library>../service//gentoobrowse-service
- <library>boost_utf
- <library>..//Ice
- <library>..//IceBox
- <library>dl
- : testInit ;
-
diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp
index abcff03..3d7a679 100644
--- a/gentoobrowse-api/unittests/mockDefs.cpp
+++ b/gentoobrowse-api/unittests/mockDefs.cpp
@@ -1,10 +1,15 @@
#include "mockDefs.h"
#include <definedDirs.h>
-StandardMockDatabase::StandardMockDatabase() :
- PQ::Mock("user=postgres dbname=postgres", "postgres", {
+Service::Service() :
+ PQ::Mock("user=postgres dbname=postgres", "GentooBrowseAPI", {
rootDir.parent_path() / "db" / "schema.sql",
rootDir / "data.sql" })
{
}
+TestClient::TestClient() :
+ p(Gentoo::PortagePrx::checkedCast(ic->stringToProxy("portage:tcp -p 9002")))
+{
+}
+
diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h
index ca43d4d..8b4d642 100644
--- a/gentoobrowse-api/unittests/mockDefs.h
+++ b/gentoobrowse-api/unittests/mockDefs.h
@@ -3,12 +3,20 @@
#include <mock.h>
#include <visibility.h>
+#include <dryice.h>
+#include <portage.h>
-#define DECLAREMOCK(Name) class DLL_PUBLIC Name : public PQ::Mock { public: Name(); }
+class DLL_PUBLIC Service : public IceTray::DryIce, PQ::Mock {
+ public:
+ Service();
+};
-DECLAREMOCK(StandardMockDatabase);
+class DLL_PUBLIC TestClient : public IceTray::DryIceClient {
+ public:
+ TestClient();
-#undef DECLAREMOCK
+ Gentoo::PortagePrx p;
+};
#endif
diff --git a/gentoobrowse-api/unittests/testInit.cpp b/gentoobrowse-api/unittests/testInit.cpp
deleted file mode 100644
index 15479ac..0000000
--- a/gentoobrowse-api/unittests/testInit.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#define BOOST_TEST_MODULE TestInit
-#include <boost/test/unit_test.hpp>
-#include <dlfcn.h>
-#include <Ice/Ice.h>
-#include <IceBox/IceBox.h>
-
-typedef IceBox::Service *(* SetupFunction)(Ice::CommunicatorPtr);
-
-BOOST_AUTO_TEST_CASE( init )
-{
- void * i = dlsym(NULL, "createGentooBrowseAPI");
- BOOST_REQUIRE(i);
- auto sf = (SetupFunction)i;
- BOOST_REQUIRE(sf);
- Ice::StringSeq args;
- Ice::InitializationData id;
- id.properties = Ice::createProperties();
- id.properties->setProperty("GentooBrowseAPI.Endpoints", "tcp -p 9002");
- auto ic = Ice::initialize(args, id);
- IceBox::Service * s = sf(nullptr);
- s->start("GentooBrowseAPI", ic, {});
- s->stop();
- delete s;
- ic->destroy();
-}
-
diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp
index 271ff34..fee3751 100644
--- a/gentoobrowse-api/unittests/testPortage.cpp
+++ b/gentoobrowse-api/unittests/testPortage.cpp
@@ -4,37 +4,18 @@
#include "mockDefs.h"
#include <portageimpl.h>
-BOOST_GLOBAL_FIXTURE( StandardMockDatabase );
+BOOST_GLOBAL_FIXTURE( Service );
-class MockPool : public AdHoc::ResourcePool<DB::Connection> {
- public:
- MockPool() : AdHoc::ResourcePool<DB::Connection>(1, 1) { }
- DB::Connection * createResource() const override {
- return DB::MockDatabase::openConnectionTo("postgres");
- }
-};
-
-class TestPortage {
- public:
- TestPortage() :
- p(new Portage(mp))
- {
- }
-
- MockPool mp;
- Portage::PointerType p;
-};
-
-BOOST_FIXTURE_TEST_SUITE(tp, TestPortage)
+BOOST_FIXTURE_TEST_SUITE(tp, TestClient)
BOOST_AUTO_TEST_CASE( getCategoryMissing )
{
- BOOST_REQUIRE_THROW(p->getCategory(0, Ice::Current()), std::exception);
+ BOOST_REQUIRE_THROW(p->getCategory(0), std::exception);
}
BOOST_AUTO_TEST_CASE( getCategory )
{
- auto cat = p->getCategory(316, Ice::Current());
+ auto cat = p->getCategory(316);
BOOST_REQUIRE(cat);
BOOST_REQUIRE_EQUAL(316, cat->categoryid);
BOOST_REQUIRE_EQUAL("app-backup", cat->name);
@@ -44,7 +25,7 @@ BOOST_AUTO_TEST_CASE( getCategory )
BOOST_AUTO_TEST_CASE( getAllCategories )
{
- auto cats = p->getAllCategories(Ice::Current());
+ auto cats = p->getAllCategories();
BOOST_REQUIRE_EQUAL(5, cats.size());
BOOST_REQUIRE_EQUAL(316, cats.front()->categoryid);
BOOST_REQUIRE_EQUAL(313, cats.back()->categoryid);
@@ -54,38 +35,38 @@ BOOST_AUTO_TEST_CASE( getAllCategories )
BOOST_AUTO_TEST_CASE( getCategoriesInSuper )
{
- auto cats = p->getCategoriesInSuper("dev", Ice::Current());
+ auto cats = p->getCategoriesInSuper("dev");
BOOST_REQUIRE_EQUAL(2, cats.size());
BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name);
BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name);
- cats = p->getCategoriesInSuper("net", Ice::Current());
+ cats = p->getCategoriesInSuper("net");
BOOST_REQUIRE_EQUAL(1, cats.size());
- cats = p->getCategoriesInSuper("sys", Ice::Current());
+ cats = p->getCategoriesInSuper("sys");
BOOST_REQUIRE_EQUAL(0, cats.size());
}
BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper )
{
- auto cats = p->getOverviewCategoriesInSuper("dev", Ice::Current());
+ auto cats = p->getOverviewCategoriesInSuper("dev");
BOOST_REQUIRE_EQUAL(2, cats.size());
BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name);
BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name);
BOOST_REQUIRE_EQUAL(136, cats.front()->packagecount);
BOOST_REQUIRE_EQUAL(88, cats.back()->packagecount);
- cats = p->getOverviewCategoriesInSuper("net", Ice::Current());
+ cats = p->getOverviewCategoriesInSuper("net");
BOOST_REQUIRE_EQUAL(1, cats.size());
- cats = p->getOverviewCategoriesInSuper("sys", Ice::Current());
+ cats = p->getOverviewCategoriesInSuper("sys");
BOOST_REQUIRE_EQUAL(0, cats.size());
}
BOOST_AUTO_TEST_CASE( getPackageMissing )
{
- BOOST_REQUIRE_THROW(p->getPackage(0, Ice::Current()), std::exception);
+ BOOST_REQUIRE_THROW(p->getPackage(0), std::exception);
}
BOOST_AUTO_TEST_CASE( getPackage )
{
- auto pkg = p->getPackage(53258, Ice::Current());
+ auto pkg = p->getPackage(53258);
BOOST_REQUIRE(pkg);
BOOST_REQUIRE_EQUAL(53258, pkg->packageid);
BOOST_REQUIRE_EQUAL(311, pkg->categoryid);
@@ -99,20 +80,20 @@ BOOST_AUTO_TEST_CASE( getPackage )
BOOST_AUTO_TEST_CASE( findPackage )
{
- auto cat = p->findPackage("not", "here", Ice::Current());
+ auto cat = p->findPackage("not", "here");
BOOST_REQUIRE(!cat);
}
BOOST_AUTO_TEST_CASE( findPackageMissing )
{
- auto pkg = p->findPackage("dev-vcs", "archway", Ice::Current());
+ auto pkg = p->findPackage("dev-vcs", "archway");
BOOST_REQUIRE(pkg);
BOOST_REQUIRE_EQUAL(53258, (*pkg)->packageid);
}
BOOST_AUTO_TEST_CASE( getPackagesInCategory )
{
- auto pkgs = p->getPackagesInCategory(311, Ice::Current());
+ auto pkgs = p->getPackagesInCategory(311);
BOOST_REQUIRE_EQUAL(88, pkgs.size());
BOOST_REQUIRE_EQUAL("archway", pkgs.front()->name);
BOOST_REQUIRE_EQUAL("veracity", pkgs.back()->name);
@@ -120,13 +101,13 @@ BOOST_AUTO_TEST_CASE( getPackagesInCategory )
BOOST_AUTO_TEST_CASE( searchEmpty )
{
- auto matches = p->getPackagesSearch("", Ice::Current());
+ auto matches = p->getPackagesSearch("");
BOOST_REQUIRE(matches.empty());
}
BOOST_AUTO_TEST_CASE( search )
{
- auto matches = p->getPackagesSearch("git", Ice::Current());
+ auto matches = p->getPackagesSearch("git");
BOOST_REQUIRE_EQUAL(40, matches.size());
BOOST_REQUIRE_EQUAL(58252, matches.front()->packageid);
BOOST_REQUIRE_CLOSE(0.72, matches.front()->rank, 1.0);
@@ -134,7 +115,7 @@ BOOST_AUTO_TEST_CASE( search )
BOOST_AUTO_TEST_CASE( searchNotFound )
{
- auto matches = p->getPackagesSearch("something that doesn't exist", Ice::Current());
+ auto matches = p->getPackagesSearch("something that doesn't exist");
BOOST_REQUIRE(matches.empty());
}
@@ -259,22 +240,5 @@ BOOST_AUTO_TEST_CASE( getNewsRecent )
BOOST_REQUIRE_EQUAL("2015-10-07T00:00:00", ns.back()->posted);
}
-BOOST_AUTO_TEST_CASE( cache )
-{
- auto c1 = p->getCategory(311, Ice::Current());
- BOOST_REQUIRE(c1);
- BOOST_REQUIRE_EQUAL(311, c1->categoryid);
- auto c2 = p->getCategory(311, Ice::Current());
- BOOST_REQUIRE(c2);
- BOOST_REQUIRE_EQUAL(311, c2->categoryid);
- BOOST_REQUIRE_EQUAL(c1.get(), c2.get());
- auto c3 = p->getCategory(316, Ice::Current());
- BOOST_REQUIRE(c3);
- BOOST_REQUIRE_EQUAL(316, c3->categoryid);
- BOOST_REQUIRE(c1.get() != c3.get());
- BOOST_REQUIRE_EQUAL(311, c1->categoryid);
- BOOST_REQUIRE_EQUAL(311, c2->categoryid);
-}
-
BOOST_AUTO_TEST_SUITE_END();