summaryrefslogtreecommitdiffstats
path: root/filedistribution/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-15 16:45:03 +0200
committerGitHub <noreply@github.com>2016-09-15 16:45:03 +0200
commit75e9061a9f1a716d3bd79a3496d07f0ad7256e46 (patch)
tree07a26b47994dc53e8288c9372c3e8febdade6ad5 /filedistribution/src/tests
parentbf1333c9d6fe3ebd5f736035857f155131702961 (diff)
Revert "Balder/remove boost noncopyable 2"
Diffstat (limited to 'filedistribution/src/tests')
-rw-r--r--filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp10
-rw-r--r--filedistribution/src/tests/filedownloader/testfiledownloader.cpp33
-rw-r--r--filedistribution/src/tests/lib/mock-zookeeper.cpp35
-rw-r--r--filedistribution/src/tests/rpc/testfileprovider.cpp8
-rw-r--r--filedistribution/src/tests/scheduler/test-scheduler.cpp18
-rw-r--r--filedistribution/src/tests/status/test-status.cpp2
-rw-r--r--filedistribution/src/tests/zkfacade/test-zkfacade.cpp27
-rw-r--r--filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp13
8 files changed, 85 insertions, 61 deletions
diff --git a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
index 3cf12722d86..84d1b5b958c 100644
--- a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
+++ b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
@@ -20,12 +20,14 @@ namespace {
struct Fixture {
+ boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- std::shared_ptr<ZKFacade> _zk;
- std::shared_ptr<FileDistributionModelImpl> _distModel;
+ boost::shared_ptr<ZKFacade> _zk;
+ boost::shared_ptr<FileDistributionModelImpl> _distModel;
Fixture() {
- _zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
- _distModel.reset(new FileDistributionModelImpl("hostname", 12345, _zk));
+ _exceptionRethrower.reset(new ExceptionRethrower());
+ _zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181", _exceptionRethrower));
+ _distModel.reset(new FileDistributionModelImpl("hostname", 12345, _zk, _exceptionRethrower));
}
~Fixture() { }
};
diff --git a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
index c9d93ffc218..94b505f4f9f 100644
--- a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
+++ b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
@@ -10,6 +10,8 @@
#include <boost/test/unit_test.hpp>
#include <boost/filesystem.hpp>
+#include <boost/thread.hpp>
+#include <boost/lambda/bind.hpp>
#include <boost/filesystem/fstream.hpp>
#include <libtorrent/session.hpp>
@@ -18,6 +20,7 @@
#include <vespa/filedistribution/manager/createtorrent.h>
#include <vespa/filedistribution/model/filedistributionmodel.h>
+#include <vespa/filedistribution/common/exceptionrethrower.h>
#include <vespa/filedistribution/common/componentsdeleter.h>
namespace fs = boost::filesystem;
@@ -30,14 +33,15 @@ const int uploaderPort = 9113;
const int downloaderPort = 9112;
#if 0
-std::shared_ptr<FileDownloader>
+boost::shared_ptr<FileDownloader>
createDownloader(ComponentsDeleter& deleter,
int port, const fs::path& downloaderPath,
- const std::shared_ptr<FileDistributionModel>& model)
+ const boost::shared_ptr<FileDistributionModel>& model,
+ const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower)
{
- std::shared_ptr<FileDistributorTrackerImpl> tracker(deleter.track(new FileDistributorTrackerImpl(model)));
- std::shared_ptr<FileDownloader> downloader(deleter.track(new FileDownloader(tracker,
- localHost, port, downloaderPath)));
+ boost::shared_ptr<FileDistributorTrackerImpl> tracker(deleter.track(new FileDistributorTrackerImpl(model, exceptionRethrower)));
+ boost::shared_ptr<FileDownloader> downloader(deleter.track(new FileDownloader(tracker,
+ localHost, port, downloaderPath, exceptionRethrower)));
tracker->setDownloader(downloader);
return downloader;
@@ -97,22 +101,27 @@ BOOST_AUTO_TEST_CASE(fileDownloaderTest) {
Buffer buffer(createTorrent.bencode());
ComponentsDeleter deleter;
+ boost::shared_ptr<ExceptionRethrower> exceptionRethrower(new ExceptionRethrower());
- std::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel()));
- std::shared_ptr<FileDownloader> downloader =
- createDownloader(deleter, downloaderPort, downloaderPath, model);
+ boost::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel()));
+ boost::shared_ptr<FileDownloader> downloader =
+ createDownloader(deleter, downloaderPort, downloaderPath, model, exceptionRethrower);
- std::shared_ptr<FileDownloader> uploader =
- createDownloader(deleter, uploaderPort, uploaderPath, model);
+ boost::shared_ptr<FileDownloader> uploader =
+ createDownloader(deleter, uploaderPort, uploaderPath, model, exceptionRethrower);
- std::thread uploaderThread( [uploader] () { uploader->runEventLoop(); });
- std::thread downloaderThread( [downloader] () { downloader->runEventLoop(); });
+ boost::thread uploaderThread(
+ boost::lambda::bind(&FileDownloader::runEventLoop, uploader.get()));
+
+ boost::thread downloaderThread(
+ boost::lambda::bind(&FileDownloader::runEventLoop, downloader.get()));
uploader->addTorrent(fileReference, buffer);
downloader->addTorrent(fileReference, buffer);
sleep(5);
BOOST_CHECK(fs::exists(downloaderPath / fileReference / fileToSend));
+ BOOST_CHECK(!exceptionRethrower->exceptionStored());
uploaderThread.interrupt();
uploaderThread.join();
diff --git a/filedistribution/src/tests/lib/mock-zookeeper.cpp b/filedistribution/src/tests/lib/mock-zookeeper.cpp
index 4d39e41786a..82cd03a268e 100644
--- a/filedistribution/src/tests/lib/mock-zookeeper.cpp
+++ b/filedistribution/src/tests/lib/mock-zookeeper.cpp
@@ -7,8 +7,7 @@
#include <cstring>
#include <vector>
-#include <thread>
-#include <atomic>
+#include <boost/thread.hpp>
#include <boost/lexical_cast.hpp>
#include <iostream>
@@ -56,9 +55,7 @@ struct Node {
void triggerWatches(zhandle_t* zh, const std::string& path);
};
-std::shared_ptr<Node> sharedRoot;
-
-void doNothing() { }
+boost::shared_ptr<Node> sharedRoot;
struct ZHandle {
struct Worker {
@@ -71,12 +68,11 @@ struct ZHandle {
int sequence;
- std::shared_ptr<Node> root;
- std::atomic<bool> _closed;
- std::thread _watchersThread;
+ boost::shared_ptr<Node> root;
+ boost::thread _watchersThread;
vector<string> ephemeralNodes;
- typedef std::function<void (void)> InvokeWatcherFun;
+ typedef boost::function<void (void)> InvokeWatcherFun;
ConcurrentQueue<InvokeWatcherFun> watcherInvocations;
Node& getNode(const string& path);
@@ -87,7 +83,7 @@ struct ZHandle {
ephemeralNodes.push_back(path);
}
- ZHandle() : sequence(0), _closed(false), _watchersThread(Worker(this)) {
+ ZHandle() : sequence(0), _watchersThread(Worker(this)) {
if (!sharedRoot)
sharedRoot.reset(new Node());
@@ -96,21 +92,21 @@ struct ZHandle {
~ZHandle() {
std::for_each(ephemeralNodes.begin(), ephemeralNodes.end(),
- [this] (const string & s) { zoo_delete((zhandle_t*)this, s.c_str(), 0); });
- close();
+ boost::bind(&zoo_delete, (zhandle_t*)this,
+ boost::bind(&string::c_str, _1),
+ 0));
+
+ _watchersThread.interrupt();
_watchersThread.join();
}
- void close() {
- _closed.store(true);
- watcherInvocations.push(std::ref(doNothing));
- }
};
void
ZHandle::Worker::operator()()
{
- while (! zhandle._closed.load()) {
+ while (!boost::this_thread::interruption_requested()) {
InvokeWatcherFun fun = zhandle.watcherInvocations.pop();
+ boost::this_thread::disable_interruption di;
fun();
}
}
@@ -138,7 +134,10 @@ ZHandle::getParent(const string& childPath)
void
Node::triggerWatches(zhandle_t* zh, const std::string& path) {
for (auto i = watchers.begin(); i != watchers.end(); ++i) {
- ((ZHandle*)zh)->watcherInvocations.push([zh, i, path] () { i->first(zh, 0, 0, path.c_str(), i->second); });
+ ((ZHandle*)zh)->watcherInvocations.push(boost::bind(i->first, zh, \
+ /*TODO: type, state*/ 0, 0,
+ boost::bind(&string::c_str, path),
+ i->second));
}
watchers.clear();
}
diff --git a/filedistribution/src/tests/rpc/testfileprovider.cpp b/filedistribution/src/tests/rpc/testfileprovider.cpp
index 6be172d0afd..6881eb96b8a 100644
--- a/filedistribution/src/tests/rpc/testfileprovider.cpp
+++ b/filedistribution/src/tests/rpc/testfileprovider.cpp
@@ -17,8 +17,8 @@ const std::string MockFileProvider::_queueForeverFileReference("queue-forever");
BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) {
const std::string spec("tcp/localhost:9111");
- fd::FileProvider::SP provider(new fd::MockFileProvider());
- fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
+ boost::shared_ptr<fd::MockFileProvider> provider(new fd::MockFileProvider());
+ boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
fileDistributorRPC->start();
frtstream::FrtClientStream rpc(spec);
@@ -37,8 +37,8 @@ BOOST_AUTO_TEST_CASE(fileDistributionRPCTest) {
//must be run through valgrind
BOOST_AUTO_TEST_CASE(require_that_queued_requests_does_not_leak_memory) {
const std::string spec("tcp/localhost:9111");
- std::shared_ptr<MockFileProvider> provider(new MockFileProvider());
- fd::FileDistributorRPC::SP fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
+ boost::shared_ptr<MockFileProvider> provider(new MockFileProvider());
+ boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
fileDistributorRPC->start();
FRT_Supervisor supervisor;
diff --git a/filedistribution/src/tests/scheduler/test-scheduler.cpp b/filedistribution/src/tests/scheduler/test-scheduler.cpp
index a9249bbdcae..cc669690a31 100644
--- a/filedistribution/src/tests/scheduler/test-scheduler.cpp
+++ b/filedistribution/src/tests/scheduler/test-scheduler.cpp
@@ -9,10 +9,8 @@
#include <iostream>
#include <boost/thread/barrier.hpp>
-#include <thread>
using filedistribution::Scheduler;
-using namespace std::literals;
namespace asio = boost::asio;
@@ -27,11 +25,13 @@ struct CallRun {
{}
void operator()(asio::io_service& ioService) {
- try {
- //No reset needed after handling exceptions.
- ioService.run();
- } catch(const TestException& e ) {
- _caughtException = true;
+ while (!boost::this_thread::interruption_requested()) {
+ try {
+ //No reset needed after handling exceptions.
+ ioService.run();
+ } catch(const TestException& e ) {
+ _caughtException = true;
+ }
}
}
};
@@ -41,7 +41,7 @@ struct Fixture {
Scheduler scheduler;
Fixture()
- : scheduler(std::ref(callRun))
+ : scheduler(boost::ref(callRun))
{}
};
@@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(require_exception_from_tasks_can_be_caught) {
task->scheduleNow();
for (int i=0; i<200 && !callRun._caughtException; ++i) {
- std::this_thread::sleep_for(100ms);
+ boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(100));
}
BOOST_CHECK(callRun._caughtException);
diff --git a/filedistribution/src/tests/status/test-status.cpp b/filedistribution/src/tests/status/test-status.cpp
index 4fbda2cb9c3..7021752f316 100644
--- a/filedistribution/src/tests/status/test-status.cpp
+++ b/filedistribution/src/tests/status/test-status.cpp
@@ -3,7 +3,9 @@
#define BOOST_TEST_MAIN
#include <vespa/fastos/fastos.h>
#include <boost/test/unit_test.hpp>
+#include <boost/foreach.hpp>
+#include <vespa/filedistribution/common/exceptionrethrower.h>
#include <vespa/filedistribution/model/zkfacade.h>
#include <vespa/filedistribution/model/filedistributionmodel.h>
#include <vespa/filedistribution/model/filedistributionmodelimpl.h>
diff --git a/filedistribution/src/tests/zkfacade/test-zkfacade.cpp b/filedistribution/src/tests/zkfacade/test-zkfacade.cpp
index ada601742db..d45e5059a53 100644
--- a/filedistribution/src/tests/zkfacade/test-zkfacade.cpp
+++ b/filedistribution/src/tests/zkfacade/test-zkfacade.cpp
@@ -8,6 +8,7 @@
#include <iostream>
#include <boost/thread/barrier.hpp>
+#include <boost/thread/thread.hpp>
#include <boost/checked_delete.hpp>
#include <vespa/filedistribution/common/componentsdeleter.h>
@@ -16,7 +17,7 @@
#include <zookeeper/zookeeper.h>
-using namespace std::literals;
+
using namespace filedistribution;
namespace {
@@ -34,13 +35,16 @@ struct Watcher : public ZKFacade::NodeChangedWatcher {
};
struct Fixture {
+ boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- std::shared_ptr<ZKFacade> zk;
+ boost::shared_ptr<ZKFacade> zk;
ZKFacade::Path testNode;
Fixture() {
+ _exceptionRethrower.reset(new ExceptionRethrower());
+
zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
- zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
+ zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181", _exceptionRethrower));
testNode = "/test-node";
zk->removeIfExists(testNode);
@@ -70,7 +74,7 @@ BOOST_AUTO_TEST_CASE(hasNode)
BOOST_AUTO_TEST_CASE(hasNodeNotification)
{
- std::shared_ptr<Watcher> watcher(new Watcher);
+ boost::shared_ptr<Watcher> watcher(new Watcher);
zk->hasNode(testNode, watcher);
zk->setData(testNode, "", 0);
@@ -78,7 +82,7 @@ BOOST_AUTO_TEST_CASE(hasNodeNotification)
//after the notification has returned, the watcher must no longer reside in watchers map.
for (int i=0; i<20 && !watcher.unique(); ++i) {
- std::this_thread::sleep_for(100ms);
+ boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(100));
}
BOOST_CHECK(watcher.unique());
}
@@ -152,7 +156,8 @@ BOOST_AUTO_TEST_CASE(addEphemeralNode)
zk->removeIfExists(ephemeralNode);
//Checked deleter is ok here since we're not installing any watchers
- ZKFacade::SP zk2(new ZKFacade("test1-tonyv:2181"), boost::checked_deleter<ZKFacade>());
+ ZKFacade::SP zk2(new ZKFacade("test1-tonyv:2181", _exceptionRethrower),
+ boost::checked_deleter<ZKFacade>());
zk2->addEphemeralNode(ephemeralNode);
BOOST_CHECK(zk->hasNode(ephemeralNode));
@@ -164,7 +169,7 @@ BOOST_AUTO_TEST_CASE(addEphemeralNode)
BOOST_AUTO_TEST_CASE(dataChangedNotification)
{
- std::shared_ptr<Watcher> watcher(new Watcher);
+ boost::shared_ptr<Watcher> watcher(new Watcher);
zk->setData(testNode, "", 0);
Buffer buffer(zk->getData(testNode, watcher));
@@ -177,7 +182,7 @@ BOOST_AUTO_TEST_CASE(dataChangedNotification)
BOOST_AUTO_TEST_CASE(getChildrenNotification)
{
- std::shared_ptr<Watcher> watcher(new Watcher);
+ boost::shared_ptr<Watcher> watcher(new Watcher);
zk->setData(testNode, "", 0);
zk->getChildren(testNode, watcher);
@@ -189,9 +194,9 @@ BOOST_AUTO_TEST_CASE(getChildrenNotification)
BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback)
{
struct DeleteZKFacadeWatcher : public Watcher {
- std::shared_ptr<ZKFacade> _zk;
+ boost::shared_ptr<ZKFacade> _zk;
- DeleteZKFacadeWatcher(const std::shared_ptr<ZKFacade>& zk)
+ DeleteZKFacadeWatcher(const boost::shared_ptr<ZKFacade>& zk)
:_zk(zk)
{}
@@ -202,7 +207,7 @@ BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback)
}
};
- std::shared_ptr<Watcher> watcher((Watcher*)new DeleteZKFacadeWatcher(zk));
+ boost::shared_ptr<Watcher> watcher((Watcher*)new DeleteZKFacadeWatcher(zk));
zk->setData(testNode, "", 0);
zk->getData(testNode, watcher);
diff --git a/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp b/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp
index 6a3a87aac96..b385949bb98 100644
--- a/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp
+++ b/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp
@@ -7,6 +7,10 @@
#include <iostream>
+#include <boost/thread/barrier.hpp>
+#include <boost/thread/thread.hpp>
+#include <boost/checked_delete.hpp>
+
#include <vespa/filedistribution/common/componentsdeleter.h>
#include <vespa/filedistribution/model/zkfacade.h>
#include <vespa/filedistribution/model/zkfiledbmodel.h>
@@ -22,13 +26,16 @@ namespace {
struct Fixture {
+ boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- std::shared_ptr<ZKFacade> zk;
- std::shared_ptr<ZKFileDBModel> model;
+ boost::shared_ptr<ZKFacade> zk;
+ boost::shared_ptr<ZKFileDBModel> model;
Fixture() {
+ _exceptionRethrower.reset(new ExceptionRethrower());
+
zoo_set_debug_level(ZOO_LOG_LEVEL_WARN);
- zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
+ zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181", _exceptionRethrower));
zk->setData("/vespa", "", 0);
model = _componentsDeleter.track(new ZKFileDBModel(zk));