summaryrefslogtreecommitdiffstats
path: root/filedistribution/src/tests
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2016-09-16 09:15:18 +0200
committerGitHub <noreply@github.com>2016-09-16 09:15:18 +0200
commitc0b5c9a414b5dcaacc2bf30160849f97e64d0d1a (patch)
tree20ba07f311bd83d32ccc59def7c3dd0374816058 /filedistribution/src/tests
parentc9c6e00c303ac2e4d341083433946922471cdcfc (diff)
Revert "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, 61 insertions, 85 deletions
diff --git a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
index 84d1b5b958c..3cf12722d86 100644
--- a/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
+++ b/filedistribution/src/tests/filedbmodelimpl/test-filedistributionmodelimpl.cpp
@@ -20,14 +20,12 @@ namespace {
struct Fixture {
- boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- boost::shared_ptr<ZKFacade> _zk;
- boost::shared_ptr<FileDistributionModelImpl> _distModel;
+ std::shared_ptr<ZKFacade> _zk;
+ std::shared_ptr<FileDistributionModelImpl> _distModel;
Fixture() {
- _exceptionRethrower.reset(new ExceptionRethrower());
- _zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181", _exceptionRethrower));
- _distModel.reset(new FileDistributionModelImpl("hostname", 12345, _zk, _exceptionRethrower));
+ _zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
+ _distModel.reset(new FileDistributionModelImpl("hostname", 12345, _zk));
}
~Fixture() { }
};
diff --git a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
index 94b505f4f9f..c9d93ffc218 100644
--- a/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
+++ b/filedistribution/src/tests/filedownloader/testfiledownloader.cpp
@@ -10,8 +10,6 @@
#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>
@@ -20,7 +18,6 @@
#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;
@@ -33,15 +30,14 @@ const int uploaderPort = 9113;
const int downloaderPort = 9112;
#if 0
-boost::shared_ptr<FileDownloader>
+std::shared_ptr<FileDownloader>
createDownloader(ComponentsDeleter& deleter,
int port, const fs::path& downloaderPath,
- const boost::shared_ptr<FileDistributionModel>& model,
- const boost::shared_ptr<ExceptionRethrower>& exceptionRethrower)
+ const std::shared_ptr<FileDistributionModel>& model)
{
- 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)));
+ std::shared_ptr<FileDistributorTrackerImpl> tracker(deleter.track(new FileDistributorTrackerImpl(model)));
+ std::shared_ptr<FileDownloader> downloader(deleter.track(new FileDownloader(tracker,
+ localHost, port, downloaderPath)));
tracker->setDownloader(downloader);
return downloader;
@@ -101,27 +97,22 @@ BOOST_AUTO_TEST_CASE(fileDownloaderTest) {
Buffer buffer(createTorrent.bencode());
ComponentsDeleter deleter;
- boost::shared_ptr<ExceptionRethrower> exceptionRethrower(new ExceptionRethrower());
- boost::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel()));
- boost::shared_ptr<FileDownloader> downloader =
- createDownloader(deleter, downloaderPort, downloaderPath, model, exceptionRethrower);
+ std::shared_ptr<FileDistributionModel> model(deleter.track(new MockFileDistributionModel()));
+ std::shared_ptr<FileDownloader> downloader =
+ createDownloader(deleter, downloaderPort, downloaderPath, model);
- boost::shared_ptr<FileDownloader> uploader =
- createDownloader(deleter, uploaderPort, uploaderPath, model, exceptionRethrower);
+ std::shared_ptr<FileDownloader> uploader =
+ createDownloader(deleter, uploaderPort, uploaderPath, model);
- boost::thread uploaderThread(
- boost::lambda::bind(&FileDownloader::runEventLoop, uploader.get()));
-
- boost::thread downloaderThread(
- boost::lambda::bind(&FileDownloader::runEventLoop, downloader.get()));
+ std::thread uploaderThread( [uploader] () { uploader->runEventLoop(); });
+ std::thread downloaderThread( [downloader] () { downloader->runEventLoop(); });
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 82cd03a268e..4d39e41786a 100644
--- a/filedistribution/src/tests/lib/mock-zookeeper.cpp
+++ b/filedistribution/src/tests/lib/mock-zookeeper.cpp
@@ -7,7 +7,8 @@
#include <cstring>
#include <vector>
-#include <boost/thread.hpp>
+#include <thread>
+#include <atomic>
#include <boost/lexical_cast.hpp>
#include <iostream>
@@ -55,7 +56,9 @@ struct Node {
void triggerWatches(zhandle_t* zh, const std::string& path);
};
-boost::shared_ptr<Node> sharedRoot;
+std::shared_ptr<Node> sharedRoot;
+
+void doNothing() { }
struct ZHandle {
struct Worker {
@@ -68,11 +71,12 @@ struct ZHandle {
int sequence;
- boost::shared_ptr<Node> root;
- boost::thread _watchersThread;
+ std::shared_ptr<Node> root;
+ std::atomic<bool> _closed;
+ std::thread _watchersThread;
vector<string> ephemeralNodes;
- typedef boost::function<void (void)> InvokeWatcherFun;
+ typedef std::function<void (void)> InvokeWatcherFun;
ConcurrentQueue<InvokeWatcherFun> watcherInvocations;
Node& getNode(const string& path);
@@ -83,7 +87,7 @@ struct ZHandle {
ephemeralNodes.push_back(path);
}
- ZHandle() : sequence(0), _watchersThread(Worker(this)) {
+ ZHandle() : sequence(0), _closed(false), _watchersThread(Worker(this)) {
if (!sharedRoot)
sharedRoot.reset(new Node());
@@ -92,21 +96,21 @@ struct ZHandle {
~ZHandle() {
std::for_each(ephemeralNodes.begin(), ephemeralNodes.end(),
- boost::bind(&zoo_delete, (zhandle_t*)this,
- boost::bind(&string::c_str, _1),
- 0));
-
- _watchersThread.interrupt();
+ [this] (const string & s) { zoo_delete((zhandle_t*)this, s.c_str(), 0); });
+ close();
_watchersThread.join();
}
+ void close() {
+ _closed.store(true);
+ watcherInvocations.push(std::ref(doNothing));
+ }
};
void
ZHandle::Worker::operator()()
{
- while (!boost::this_thread::interruption_requested()) {
+ while (! zhandle._closed.load()) {
InvokeWatcherFun fun = zhandle.watcherInvocations.pop();
- boost::this_thread::disable_interruption di;
fun();
}
}
@@ -134,10 +138,7 @@ 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(boost::bind(i->first, zh, \
- /*TODO: type, state*/ 0, 0,
- boost::bind(&string::c_str, path),
- i->second));
+ ((ZHandle*)zh)->watcherInvocations.push([zh, i, path] () { i->first(zh, 0, 0, path.c_str(), i->second); });
}
watchers.clear();
}
diff --git a/filedistribution/src/tests/rpc/testfileprovider.cpp b/filedistribution/src/tests/rpc/testfileprovider.cpp
index 6881eb96b8a..6be172d0afd 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");
- boost::shared_ptr<fd::MockFileProvider> provider(new fd::MockFileProvider());
- boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
+ fd::FileProvider::SP provider(new fd::MockFileProvider());
+ fd::FileDistributorRPC::SP 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");
- boost::shared_ptr<MockFileProvider> provider(new MockFileProvider());
- boost::shared_ptr<fd::FileDistributorRPC> fileDistributorRPC(new fd::FileDistributorRPC(spec, provider));
+ std::shared_ptr<MockFileProvider> provider(new MockFileProvider());
+ fd::FileDistributorRPC::SP 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 cc669690a31..a9249bbdcae 100644
--- a/filedistribution/src/tests/scheduler/test-scheduler.cpp
+++ b/filedistribution/src/tests/scheduler/test-scheduler.cpp
@@ -9,8 +9,10 @@
#include <iostream>
#include <boost/thread/barrier.hpp>
+#include <thread>
using filedistribution::Scheduler;
+using namespace std::literals;
namespace asio = boost::asio;
@@ -25,13 +27,11 @@ struct CallRun {
{}
void operator()(asio::io_service& ioService) {
- while (!boost::this_thread::interruption_requested()) {
- try {
- //No reset needed after handling exceptions.
- ioService.run();
- } catch(const TestException& e ) {
- _caughtException = true;
- }
+ 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(boost::ref(callRun))
+ : scheduler(std::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) {
- boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(100));
+ std::this_thread::sleep_for(100ms);
}
BOOST_CHECK(callRun._caughtException);
diff --git a/filedistribution/src/tests/status/test-status.cpp b/filedistribution/src/tests/status/test-status.cpp
index 7021752f316..4fbda2cb9c3 100644
--- a/filedistribution/src/tests/status/test-status.cpp
+++ b/filedistribution/src/tests/status/test-status.cpp
@@ -3,9 +3,7 @@
#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 d45e5059a53..ada601742db 100644
--- a/filedistribution/src/tests/zkfacade/test-zkfacade.cpp
+++ b/filedistribution/src/tests/zkfacade/test-zkfacade.cpp
@@ -8,7 +8,6 @@
#include <iostream>
#include <boost/thread/barrier.hpp>
-#include <boost/thread/thread.hpp>
#include <boost/checked_delete.hpp>
#include <vespa/filedistribution/common/componentsdeleter.h>
@@ -17,7 +16,7 @@
#include <zookeeper/zookeeper.h>
-
+using namespace std::literals;
using namespace filedistribution;
namespace {
@@ -35,16 +34,13 @@ struct Watcher : public ZKFacade::NodeChangedWatcher {
};
struct Fixture {
- boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- boost::shared_ptr<ZKFacade> zk;
+ std::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", _exceptionRethrower));
+ zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
testNode = "/test-node";
zk->removeIfExists(testNode);
@@ -74,7 +70,7 @@ BOOST_AUTO_TEST_CASE(hasNode)
BOOST_AUTO_TEST_CASE(hasNodeNotification)
{
- boost::shared_ptr<Watcher> watcher(new Watcher);
+ std::shared_ptr<Watcher> watcher(new Watcher);
zk->hasNode(testNode, watcher);
zk->setData(testNode, "", 0);
@@ -82,7 +78,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) {
- boost::thread::sleep(boost::get_system_time() + boost::posix_time::milliseconds(100));
+ std::this_thread::sleep_for(100ms);
}
BOOST_CHECK(watcher.unique());
}
@@ -156,8 +152,7 @@ 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", _exceptionRethrower),
- boost::checked_deleter<ZKFacade>());
+ ZKFacade::SP zk2(new ZKFacade("test1-tonyv:2181"), boost::checked_deleter<ZKFacade>());
zk2->addEphemeralNode(ephemeralNode);
BOOST_CHECK(zk->hasNode(ephemeralNode));
@@ -169,7 +164,7 @@ BOOST_AUTO_TEST_CASE(addEphemeralNode)
BOOST_AUTO_TEST_CASE(dataChangedNotification)
{
- boost::shared_ptr<Watcher> watcher(new Watcher);
+ std::shared_ptr<Watcher> watcher(new Watcher);
zk->setData(testNode, "", 0);
Buffer buffer(zk->getData(testNode, watcher));
@@ -182,7 +177,7 @@ BOOST_AUTO_TEST_CASE(dataChangedNotification)
BOOST_AUTO_TEST_CASE(getChildrenNotification)
{
- boost::shared_ptr<Watcher> watcher(new Watcher);
+ std::shared_ptr<Watcher> watcher(new Watcher);
zk->setData(testNode, "", 0);
zk->getChildren(testNode, watcher);
@@ -194,9 +189,9 @@ BOOST_AUTO_TEST_CASE(getChildrenNotification)
BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback)
{
struct DeleteZKFacadeWatcher : public Watcher {
- boost::shared_ptr<ZKFacade> _zk;
+ std::shared_ptr<ZKFacade> _zk;
- DeleteZKFacadeWatcher(const boost::shared_ptr<ZKFacade>& zk)
+ DeleteZKFacadeWatcher(const std::shared_ptr<ZKFacade>& zk)
:_zk(zk)
{}
@@ -207,7 +202,7 @@ BOOST_AUTO_TEST_CASE(require_that_zkfacade_can_be_deleted_from_callback)
}
};
- boost::shared_ptr<Watcher> watcher((Watcher*)new DeleteZKFacadeWatcher(zk));
+ std::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 b385949bb98..6a3a87aac96 100644
--- a/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp
+++ b/filedistribution/src/tests/zkfiledbmodel/test-zkfiledbmodel.cpp
@@ -7,10 +7,6 @@
#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>
@@ -26,16 +22,13 @@ namespace {
struct Fixture {
- boost::shared_ptr<ExceptionRethrower> _exceptionRethrower;
ComponentsDeleter _componentsDeleter;
- boost::shared_ptr<ZKFacade> zk;
- boost::shared_ptr<ZKFileDBModel> model;
+ std::shared_ptr<ZKFacade> zk;
+ std::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", _exceptionRethrower));
+ zk = _componentsDeleter.track(new ZKFacade("test1-tonyv:2181"));
zk->setData("/vespa", "", 0);
model = _componentsDeleter.track(new ZKFileDBModel(zk));