Commit 90899166 authored by Steven Murray's avatar Steven Murray
Browse files

Completed my first every gmock unit-test - RecallReportPackerNominal

Please note that I still must complete the remaining unit tests
within the RecallReportPackerTest.cpp file.
parent 6b92b1bb
......@@ -100,7 +100,7 @@ add_library(castortapeserverdaemonunittests SHARED
DriveConfigTest.cpp
# MigrationReportPackerTest.cpp
ProcessForkerTest.cpp
# RecallReportPackerTest.cpp
RecallReportPackerTest.cpp
# RecallTaskInjectorTest.cpp
# We dot know why but the TapeDaemonTest causes the following segmentation
......
......@@ -22,39 +22,107 @@
*****************************************************************************/
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
#include "castor/tape/tapeserver/client/FakeClient.hpp"
#include "castor/log/StringLogger.hpp"
#include "serrno.h"
#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
using ::testing::_;
using ::testing::Invoke;
namespace unitTests{
TEST(castor_tape_tapeserver_daemon, RecallReportPackerNominal) {
MockClient client;
class castor_tape_tapeserver_daemonTest: public ::testing::Test {
protected:
void SetUp() {
}
void TearDown() {
}
class MockRetrieveJob: public cta::RetrieveJob {
public:
MockRetrieveJob() {
}
~MockRetrieveJob() throw() {
}
MOCK_METHOD2(complete, void(const uint32_t checksumOfTransfer, const uint64_t fileSizeOfTransfer));
}; // class MockRetrieveJob
class MockRetrieveMount: public cta::RetrieveMount {
public:
MockRetrieveMount() {
const unsigned int nbRecallJobs = 2;
createRetrieveJobs(nbRecallJobs);
}
~MockRetrieveMount() throw() {
}
std::unique_ptr<cta::RetrieveJob> getNextJob() {
internalGetNextJob();
if(m_jobs.empty()) {
return std::unique_ptr<cta::RetrieveJob>();
} else {
std::unique_ptr<cta::RetrieveJob> job = std::move(m_jobs.front());
m_jobs.pop_front();
return job;
}
}
MOCK_METHOD0(internalGetNextJob, cta::RetrieveJob*());
MOCK_METHOD0(complete, void());
private:
std::list<std::unique_ptr<cta::RetrieveJob>> m_jobs;
void createRetrieveJobs(const unsigned int nbJobs) {
for(unsigned int i = 0; i < nbJobs; i++) {
std::unique_ptr<MockRetrieveJob> job(new MockRetrieveJob());
EXPECT_CALL(*job, complete(_,_)).Times(1);
m_jobs.push_back(std::unique_ptr<cta::RetrieveJob>(
job.release()));
}
}
}; // class MockRetrieveMount
}; // class castor_tape_tapeserver_daemonTest
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerNominal) {
MockRetrieveMount retrieveMount;
::testing::InSequence dummy;
EXPECT_CALL(client, reportRecallResults(_,_)).Times(1);
EXPECT_CALL(client, reportEndOfSession(_)).Times(1);
EXPECT_CALL(retrieveMount, internalGetNextJob()).Times(3);
EXPECT_CALL(retrieveMount, complete()).Times(1);
castor::log::StringLogger log("castor_tape_tapeserver_RecallReportPackerNominal");
castor::log::LogContext lc(log);
std::unique_ptr<cta::MockSchedulerDatabase> mdb(new cta::MockSchedulerDatabase);
tapeserver::daemon::RecallReportPacker rrp(dynamic_cast<cta::RetrieveMount *>((mdb->getNextMount("ll","drive")).get()),lc);
castor::tape::tapeserver::daemon::RecallReportPacker rrp(dynamic_cast<cta::RetrieveMount *>(&retrieveMount),lc);
rrp.startThreads();
tapegateway::FileToRecallStruct recalledFiled;
rrp.reportCompletedJob(recalledFiled,0,0);
rrp.reportCompletedJob(recalledFiled,0,0);
std::unique_ptr<cta::RetrieveJob> job1 = retrieveMount.getNextJob();
std::unique_ptr<cta::RetrieveJob> job2 = retrieveMount.getNextJob();
std::unique_ptr<cta::RetrieveJob> job3 = retrieveMount.getNextJob();
ASSERT_EQ(NULL, job3.get());
rrp.reportCompletedJob(std::move(job1),0,0);
rrp.reportCompletedJob(std::move(job2),0,0);
rrp.reportEndOfSession();
rrp.waitThread();
std::string temp = log.getLog();
ASSERT_NE(std::string::npos, temp.find("Nominal RecallReportPacker::EndofSession has been reported"));
}
TEST(castor_tape_tapeserver_daemon, RecallReportPackerCumulated) {
/*
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerCumulated) {
MockClient client;
::testing::InSequence dummy;
EXPECT_CALL(client, reportRecallResults(_,_)).Times(2);
......@@ -77,7 +145,7 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerCumulated) {
ASSERT_NE(std::string::npos, temp.find("Nominal RecallReportPacker::EndofSession has been reported"));
}
TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadBadEnd) {
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerBadBadEnd) {
std::string error_msg="ERROR_TEST_MSG";
int error_code=std::numeric_limits<int>::max();
//FakeClient client;
......@@ -105,7 +173,7 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadBadEnd) {
ASSERT_NE(std::string::npos, temp.find(error_msg));
}
TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadGoodEnd) {
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerBadGoodEnd) {
std::string error_msg="ERROR_TEST_MSG";
......@@ -135,7 +203,7 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerBadGoodEnd) {
std::string temp = log.getLog();
ASSERT_NE(std::string::npos, temp.find("EndofSession has been reported but an error happened somewhere in the process"));
}
TEST(castor_tape_tapeserver_daemon, RecallReportPackerGoodBadEnd) {
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerGoodBadEnd) {
std::string error_msg="ERROR_TEST_MSG";
int error_code=std::numeric_limits<int>::max();
......@@ -164,7 +232,7 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerGoodBadEnd) {
ASSERT_NE(std::string::npos, temp.find("EndofSessionWithErrors has been reported but NO error was detected during the process"));
}
TEST(castor_tape_tapeserver_daemon, RecallReportPackerFaillure) {
TEST_F(castor_tape_tapeserver_daemonTest, RecallReportPackerFaillure) {
std::string error_msg="ERROR_TEST_MSG";
int error_code=std::numeric_limits<int>::max();
......@@ -192,4 +260,5 @@ TEST(castor_tape_tapeserver_daemon, RecallReportPackerFaillure) {
std::string temp = log.getLog();
ASSERT_NE(std::string::npos, temp.find("Successfully closed client's session after the failed report RecallResult"));
}
*/
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment