Test for exception throws when channel name exist

Reviewers: zuza

Reviewed By: zuza

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D641
This commit is contained in:
Sasa Stanko 2017-08-07 17:26:41 +02:00
parent 7fe799f232
commit 82f1cb333d
2 changed files with 22 additions and 1 deletions

View File

@ -34,6 +34,10 @@ std::pair<EventStream*, std::shared_ptr<Channel>> Reactor::Open(const std::strin
// TODO: Improve the check that the channel name does not exist in the
// system.
assert(connectors_.count(connector_name) == 0);
if (connectors_.count(connector_name) != 0) {
throw std::runtime_error("Connector with name " + connector_name
+ "already exists");
}
auto it = connectors_.emplace(connector_name,
std::make_shared<Connector>(Connector::Params{system_, name_, connector_name, mutex_, cvar_})).first;
it->second->self_ptr_ = it->second;

View File

@ -10,9 +10,26 @@
#include "communication.hpp"
TEST(ChannelCreationTest, ThrowOnReusingChannelName) {
struct Master : public Reactor {
Master(System *system, std::string name) : Reactor(system, name) {}
virtual void Run() {
Open("channel");
ASSERT_THROW(Open("channel"), std::runtime_error);
CloseConnector("main");
CloseConnector("channel");
}
};
System system;
system.Spawn<Master>("master");
system.AwaitShutdown();
}
TEST(ConnectorSetUpTest, CheckMainChannelIsSet) {
struct Master : public Reactor {
Master(System *system, std::string name) : Reactor(system, name) {}
Master(System *system, std::string name) : Reactor(system, name) {}
virtual void Run() {
std::shared_ptr<Channel> channel;
while (!(channel = system_->FindChannel("worker", "main")))