Commit cffeccb2 authored by Eric Cano's avatar Eric Cano
Browse files

Fixed mocking where mocked classes had chencged signatures.

Removed mocking of classes where functions have non-copyable argumentes (unique_ptr).
Replaced NULL references to watchdogs to dummies where necessary.
parent 5fe8b842
......@@ -48,19 +48,13 @@ namespace unitTests{
using namespace castor::tape::diskFile;
struct MockMigrationReportPacker : public MigrationReportPacker {
void reportCompletedJob(std::unique_ptr<cta::ArchiveJob> successfulArchiveJob, u_int32_t checksum, u_int64_t size) {
reportCompletedJob_(successfulArchiveJob, checksum, size);
}
void reportFailedJob(std::unique_ptr<cta::ArchiveJob> failedArchiveJob, const castor::exception::Exception &ex) {
reportFailedJob_(failedArchiveJob, ex);
}
MOCK_METHOD3(reportCompletedJob_,void(std::unique_ptr<cta::ArchiveJob> &successfulArchiveJob, u_int32_t checksum, u_int64_t size));
MOCK_METHOD2(reportFailedJob_, void(std::unique_ptr<cta::ArchiveJob> &failedArchiveJob, const castor::exception::Exception &ex));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
void reportCompletedJob(std::unique_ptr<cta::ArchiveJob> successfulArchiveJob) {}
void reportFailedJob(std::unique_ptr<cta::ArchiveJob> failedArchiveJob, const castor::exception::Exception& ex) {}
void reportEndOfSession() {}
void reportEndOfSessionWithErrors(const std::string msg, int error_code) {}
void disableBulk() {}
MockMigrationReportPacker(cta::ArchiveMount *rm,castor::log::LogContext lc):
MigrationReportPacker(rm,lc){}
MigrationReportPacker(rm,lc) {}
};
class FakeTapeWriteTask : public DataConsumer{
......
......@@ -29,6 +29,7 @@
#include "castor/log/StringLogger.hpp"
#include "castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp"
#include "castor/tape/tapeserver/daemon/MemBlock.hpp"
#include "castor/messages/TapeserverProxyDummy.hpp"
//#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include "serrno.h"
......@@ -64,19 +65,31 @@ namespace unitTests{
using namespace castor::tape::tapeserver::client;
using namespace castor::tape::diskFile;
struct MockRecallReportPacker : public RecallReportPacker {
void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob, u_int32_t checksum, u_int64_t size) {
reportCompletedJob_(successfulRetrieveJob, checksum, size);
void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob) {
castor::server::MutexLocker ml(&m_mutex);
completeJobs++;
}
void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob, const castor::exception::Exception &ex) {
reportFailedJob_(failedRetrieveJob, ex);
void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob) {
castor::server::MutexLocker ml(&m_mutex);
failedJobs++;
}
void disableBulk() {}
void reportEndOfSession() {
castor::server::MutexLocker ml(&m_mutex);
endSessions++;
}
void reportEndOfSessionWithErrors(const std::string msg, int error_code) {
castor::server::MutexLocker ml(&m_mutex);
endSessionsWithError++;
}
MOCK_METHOD3(reportCompletedJob_,void(std::unique_ptr<cta::RetrieveJob> &successfulRetrieveJob, u_int32_t checksum, u_int64_t size));
MOCK_METHOD2(reportFailedJob_, void(std::unique_ptr<cta::RetrieveJob> &failedRetrieveJob, const castor::exception::Exception &ex));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
MockRecallReportPacker(cta::RetrieveMount *rm,castor::log::LogContext lc):
RecallReportPacker(rm,lc){}
RecallReportPacker(rm,lc), completeJobs(0), failedJobs(0),
endSessions(0), endSessionsWithError(0) {}
castor::server::Mutex m_mutex;
int completeJobs;
int failedJobs;
int endSessions;
int endSessionsWithError;
};
TEST(castor_tape_tapeserver_daemon, DiskWriteTaskFailedBlock){
......@@ -88,7 +101,6 @@ namespace unitTests{
std::unique_ptr<cta::SchedulerDatabase::RetrieveMount> dbrm(new TestingDatabaseRetrieveMount());
TestingRetrieveMount trm(std::move(dbrm));
MockRecallReportPacker report(&trm,lc);
EXPECT_CALL(report,reportFailedJob_(_,_));
RecallMemoryManager mm(10,100,lc);
DiskFileFactory fileFactory("RFIO","",0);
......@@ -109,7 +121,10 @@ namespace unitTests{
t.pushDataBlock(mb);
t.pushDataBlock(NULL);
t.execute(report,lc,fileFactory,*((RecallWatchDog*)NULL));
castor::messages::TapeserverProxyDummy tspd;
RecallWatchDog rwd(1,1,tspd,"", lc);
t.execute(report,lc,fileFactory,rwd);
ASSERT_EQ(1, report.failedJobs);
}
}
......@@ -28,6 +28,7 @@
#include "castor/log/StringLogger.hpp"
#include "castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp"
#include "castor/tape/tapeserver/daemon/MemBlock.hpp"
#include "castor/messages/TapeserverProxyDummy.hpp"
//#include "scheduler/mockDB/MockSchedulerDatabase.hpp"
#include <gtest/gtest.h>
......@@ -58,19 +59,31 @@ namespace unitTests{
using namespace castor::tape::tapeserver::daemon;
using namespace castor::tape::tapeserver::client;
struct MockRecallReportPacker : public RecallReportPacker {
void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob, u_int32_t checksum, u_int64_t size) {
reportCompletedJob_(successfulRetrieveJob, checksum, size);
void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob) {
castor::server::MutexLocker ml(&m_mutex);
completeJobs++;
}
void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob, const castor::exception::Exception &ex) {
reportFailedJob_(failedRetrieveJob, ex);
void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob) {
castor::server::MutexLocker ml(&m_mutex);
failedJobs++;
}
void disableBulk() {}
void reportEndOfSession() {
castor::server::MutexLocker ml(&m_mutex);
endSessions++;
}
void reportEndOfSessionWithErrors(const std::string msg, int error_code) {
castor::server::MutexLocker ml(&m_mutex);
endSessionsWithError++;
}
MOCK_METHOD3(reportCompletedJob_,void(std::unique_ptr<cta::RetrieveJob> &successfulRetrieveJob, u_int32_t checksum, u_int64_t size));
MOCK_METHOD2(reportFailedJob_, void(std::unique_ptr<cta::RetrieveJob> &failedRetrieveJob, const castor::exception::Exception &ex));
MOCK_METHOD0(reportEndOfSession, void());
MOCK_METHOD2(reportEndOfSessionWithErrors, void(const std::string,int));
MockRecallReportPacker(cta::RetrieveMount *rm, castor::log::LogContext lc):
RecallReportPacker(rm,lc){}
RecallReportPacker(rm,lc), completeJobs(0), failedJobs(0),
endSessions(0), endSessionsWithError(0) {}
castor::server::Mutex m_mutex;
int completeJobs;
int failedJobs;
int endSessions;
int endSessionsWithError;
};
struct MockTaskInjector : public RecallTaskInjector{
......@@ -85,14 +98,14 @@ namespace unitTests{
std::unique_ptr<cta::SchedulerDatabase::RetrieveMount> dbrm(new TestingDatabaseRetrieveMount);
TestingRetrieveMount trm(std::move(dbrm));
MockRecallReportPacker report(&trm,lc);
EXPECT_CALL(report,reportCompletedJob_(_,_,_)).Times(5);
EXPECT_CALL(report,reportEndOfSession()).Times(1);
MockRecallReportPacker report(&trm,lc);
RecallMemoryManager mm(10,100,lc);
DiskWriteThreadPool dwtp(2,report,*((RecallWatchDog*)NULL),lc,"RFIO","/dev/null",0);
castor::messages::TapeserverProxyDummy tspd;
RecallWatchDog rwd(1,1,tspd,"", lc);
DiskWriteThreadPool dwtp(2,report,rwd,lc,"RFIO","/dev/null",0);
dwtp.startThreads();
for(int i=0;i<5;++i){
......@@ -110,7 +123,10 @@ namespace unitTests{
}
dwtp.finish();
dwtp.waitThreads();
dwtp.waitThreads();
ASSERT_EQ(5, report.completeJobs);
ASSERT_EQ(1, report.endSessions);
}
}
......@@ -55,7 +55,7 @@ public:
* of the file. This is 0 (instead of 1) for the first file on the tape (aka
* fseq = 1).
*/
void reportCompletedJob(std::unique_ptr<cta::ArchiveJob> successfulArchiveJob);
virtual void reportCompletedJob(std::unique_ptr<cta::ArchiveJob> successfulArchiveJob);
/**
* Create into the MigrationReportPacker a report for the failled migration
......@@ -63,33 +63,33 @@ public:
* @param migratedFile the file which failled
* @param ex the reason for the failure
*/
void reportFailedJob(std::unique_ptr<cta::ArchiveJob> failedArchiveJob, const castor::exception::Exception& ex);
virtual void reportFailedJob(std::unique_ptr<cta::ArchiveJob> failedArchiveJob, const castor::exception::Exception& ex);
/**
* Create into the MigrationReportPacker a report for the signaling a flusing on tape
* @param compressStats
*
*/
void reportFlush(drive::compressionStats compressStats);
virtual void reportFlush(drive::compressionStats compressStats);
/**
* Create into the MigrationReportPacker a report for the nominal end of session
*/
void reportEndOfSession();
virtual void reportEndOfSession();
/**
* Create into the MigrationReportPacker a report for an erroneous end of session
* @param msg The error message
* @param error_code The error code given by the drive
*/
void reportEndOfSessionWithErrors(const std::string msg,int error_code);
virtual void reportEndOfSessionWithErrors(const std::string msg,int error_code);
/**
* Immediately report the end of session to the client.
* @param msg The error message
* @param error_code The error code given by the drive
*/
void synchronousReportEndWithErrors(const std::string msg,int error_code);
virtual void synchronousReportEndWithErrors(const std::string msg,int error_code);
void startThreads() { m_workerThread.start(); }
void waitThread() { m_workerThread.wait(); }
......
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