Skip to content
Snippets Groups Projects
Commit 9a87c65f authored by Steven Murray's avatar Steven Murray
Browse files

Added a couple of unit tests for the VdqmConnectionHandler

parent 62cdf520
No related branches found
No related tags found
No related merge requests found
......@@ -23,6 +23,7 @@ cmake_minimum_required (VERSION 2.6)
# Rules to build the reactor code that is common to both rmcd and tapeserverd
################################################################################
set (REACTOR_SRC_FILES
DummyZMQReactor.cpp
PollEventHandler.cpp
PollReactor.cpp
PollReactorImpl.cpp
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/tape/reactor/DummyZMQReactor.hpp"
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
castor::tape::reactor::DummyZMQReactor::DummyZMQReactor(log::Logger& log) throw():
ZMQReactor(log) {
}
//------------------------------------------------------------------------------
// clear
//------------------------------------------------------------------------------
void castor::tape::reactor::DummyZMQReactor::clear() {
// Do nothing
}
//------------------------------------------------------------------------------
// registerHandler
//------------------------------------------------------------------------------
void castor::tape::reactor::DummyZMQReactor::registerHandler(
ZMQPollEventHandler *const handler) {
// Do nothing
}
//------------------------------------------------------------------------------
// handleEvents
//------------------------------------------------------------------------------
void castor::tape::reactor::DummyZMQReactor::handleEvents(const int timeout) {
// Do nothing
}
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/tape/reactor/ZMQReactor.hpp"
namespace castor {
namespace tape {
namespace reactor {
/**
* This is a dummy ZmqReactor class that does nothing. The primary goal of
* this class is to facilitate unit testing.
*/
class DummyZMQReactor: public ZMQReactor {
public:
/**
* Constructor.
*
* @param log Interface to the CASTOR logging system.
*/
DummyZMQReactor(log::Logger& log) throw();
/**
* Removes and deletes all of the event handlers registered with the reactor.
*/
void clear();
/**
* Registers the specified handler.
*
* Please note that the reactor takes ownership of the handler and will
* delete it as appropriate.
*
* @param handler The handler to be registered. Please note that the handler
* MUST be allocated on the heap because the reactor will own the handler
* and therefore delete it as needed.
*/
void registerHandler(ZMQPollEventHandler *const handler);
/**
* Handles any pending events.
*
* @param timeout Timeout in milliseconds.
*/
void handleEvents(const int timeout);
}; // class DummyZMQReactor
} // namespace reactor
} // namespace tape
} // namespace castor
......@@ -33,7 +33,7 @@ namespace tape {
namespace reactor {
/**
* This reactor wraps the poll() system call.
* This reactor wraps the zmq_poll() function.
*
* This class is part of an implementation of the Reactor architecture pattern
* described in the following book:
......@@ -57,12 +57,12 @@ public:
/**
* Destructor.
*/
~ZMQReactor() throw();
virtual ~ZMQReactor() throw();
/**
* Removes and deletes all of the event handlers registered with the reactor.
*/
void clear();
virtual void clear();
/**
* Registers the specified handler.
......@@ -74,14 +74,14 @@ public:
* MUST be allocated on the heap because the reactor will own the handler
* and therefore delete it as needed.
*/
void registerHandler(ZMQPollEventHandler *const handler);
virtual void registerHandler(ZMQPollEventHandler *const handler);
/**
* Handles any pending events.
*
* @param timeout Timeout in milliseconds.
*/
void handleEvents(const int timeout);
virtual void handleEvents(const int timeout);
private:
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Interface to the CASTOR logging system
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#pragma once
#include "castor/tape/tapeserver/daemon/VdqmConnectionHandler.hpp"
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
/**
* Class used to facilitate unit testing by making public one or more of the
* protected members of its super class.
*/
class TestingVdqmConnectionHandler: public VdqmConnectionHandler {
public:
/**
* Constructor.
*
* @param fd The file descriptor of the connection with the vdqmd
* daemon.
* @param reactor The reactor with which this event handler is registered.
* @param log The object representing the API of the CASTOR logging system.
* @param driveCatalogue The catalogue of tape drives controlled by the tape
* server daemon.
* @param tapeDaemonConfig The CASTOR configuration parameters to be used by
* the tape daemon.
*/
TestingVdqmConnectionHandler(
const int fd,
reactor::ZMQReactor &reactor,
log::Logger &log,
Catalogue &driveCatalogue,
const TapeDaemonConfig &tapeDaemonConfig) throw():
VdqmConnectionHandler(
fd,
reactor,
log,
driveCatalogue,
tapeDaemonConfig) {
}
using VdqmConnectionHandler::connectionIsFromTrustedVdqmHost;
using VdqmConnectionHandler::getPeerHostName;
}; // class TestingVdqmConnectionHandler
} // namespace daemon
} // namespace tapeserver
} // namespace tape
} // namespace castor
......@@ -90,7 +90,7 @@ public:
*/
~VdqmConnectionHandler() throw();
private:
protected:
/**
* The file descriptor of the vdqm connection.
......
/******************************************************************************
*
* This file is part of the Castor project.
* See http://castor.web.cern.ch/castor
*
* Copyright (C) 2003 CERN
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
*
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "castor/legacymsg/CupvProxyDummy.hpp"
#include "castor/legacymsg/VdqmProxyDummy.hpp"
#include "castor/legacymsg/VmgrProxyDummy.hpp"
#include "castor/log/DummyLogger.hpp"
#include "castor/tape/tapeserver/daemon/ProcessForkerProxyDummy.hpp"
#include "castor/tape/tapeserver/daemon/TestingVdqmConnectionHandler.hpp"
#include "castor/tape/reactor/DummyZMQReactor.hpp"
#include "castor/utils/SmartFd.hpp"
#include <gtest/gtest.h>
namespace unitTests {
class castor_tape_tapeserver_daemon_VdqmConnectionHandlerTest:
public ::testing::Test {
protected:
castor_tape_tapeserver_daemon_VdqmConnectionHandlerTest():
m_log("unittests"),
m_reactor(m_log),
m_netTimeout(1),
m_isGrantedReturnValue(true),
m_cupv(m_isGrantedReturnValue),
m_catalogue(
m_netTimeout,
m_log,
m_processForker,
m_cupv,
m_vdqm,
m_vmgr,
"hostName",
m_catalogueConfig) {
}
castor::log::DummyLogger m_log;
castor::tape::reactor::DummyZMQReactor m_reactor;
const int m_netTimeout;
castor::tape::tapeserver::daemon::ProcessForkerProxyDummy m_processForker;
const bool m_isGrantedReturnValue;
castor::legacymsg::CupvProxyDummy m_cupv;
castor::legacymsg::VdqmProxyDummy m_vdqm;
castor::legacymsg::VmgrProxyDummy m_vmgr;
castor::tape::tapeserver::daemon::CatalogueConfig m_catalogueConfig;
castor::tape::tapeserver::daemon::Catalogue m_catalogue;
castor::tape::tapeserver::daemon::TapeDaemonConfig m_config;
virtual void SetUp() {
}
virtual void TearDown() {
}
};
TEST_F(castor_tape_tapeserver_daemon_VdqmConnectionHandlerTest, getPeerHostName) {
using namespace castor::tape::tapeserver::daemon;
int pair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pair));
castor::utils::SmartFd pairElement0(pair[0]);
castor::utils::SmartFd pairElement1(pair[1]);
TestingVdqmConnectionHandler handler(
pairElement0.get(),
m_reactor,
m_log,
m_catalogue,
m_config);
std::string peerHostName;
ASSERT_NO_THROW(peerHostName = handler.getPeerHostName(pairElement0.get()));
ASSERT_FALSE(peerHostName.empty());
}
TEST_F(castor_tape_tapeserver_daemon_VdqmConnectionHandlerTest, connectionIsFromTrustedVdqmHost) {
using namespace castor::tape::tapeserver::daemon;
int pair[2] = {-1, -1};
ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_STREAM, 0, pair));
castor::utils::SmartFd pairElement0(pair[0]);
castor::utils::SmartFd pairElement1(pair[1]);
TestingVdqmConnectionHandler handler(
pairElement0.get(),
m_reactor,
m_log,
m_catalogue,
m_config);
ASSERT_NO_THROW(handler.connectionIsFromTrustedVdqmHost());
}
} // namespace unitTests
......@@ -164,6 +164,7 @@ add_executable(castorUnitTests
../castor/tape/tapeserver/daemon/TapeDaemonTest.cpp
../castor/tape/tapeserver/daemon/VdqmAcceptHandler.cpp
../castor/tape/tapeserver/daemon/VdqmConnectionHandler.cpp
../castor/tape/tapeserver/daemon/VdqmConnectionHandlerTest.cpp
../castor/tape/tapeserver/daemon/RecallTaskInjectorTest.cpp
../castor/tape/tapeserver/daemon/MigrationReportPackerTest.cpp
../castor/tape/tapeserver/daemon/RecallReportPackerTest.cpp
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment