DiskWriteTaskTest.cpp 6.17 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/****************************************************************************** 
 *
 * 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
 *****************************************************************************/
23

24
25
26
27
#include "castor/tape/tapeserver/daemon/DiskWriteThreadPool.hpp"
#include "castor/tape/tapeserver/daemon/RecallTaskInjector.hpp"
#include "castor/tape/tapeserver/daemon/RecallReportPacker.hpp"
#include "castor/tape/tapeserver/daemon/ReportPackerInterface.hpp"
Victor Kotlyar's avatar
Victor Kotlyar committed
28
29
#include "common/log/LogContext.hpp"
#include "common/log/StringLogger.hpp"
30
31
#include "castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp"
#include "castor/tape/tapeserver/daemon/MemBlock.hpp"
32
#include "castor/messages/TapeserverProxyDummy.hpp"
33
#include "scheduler/TapeMountDummy.hpp"
34

35
#include "scheduler/Scheduler.hpp"
36
#include "scheduler/SchedulerDatabase.hpp"
37
#include "scheduler/testingMocks/MockRetrieveMount.hpp"
38

39
#include <memory>
40
41
42
#include <gtest/gtest.h>

namespace unitTests{
43
  class TestingDatabaseRetrieveMount: public cta::SchedulerDatabase::RetrieveMount {
44
    const MountInfo & getMountInfo() override { throw std::runtime_error("Not implemented"); }
45
    std::list<std::unique_ptr<cta::SchedulerDatabase::RetrieveJob> > getNextJobBatch(uint64_t filesRequested, uint64_t bytesRequested,
46
      cta::disk::DiskSystemFreeSpaceList & diskSystemFreeSpace, cta::log::LogContext& logContext) override { throw std::runtime_error("Not implemented");}
47

48
    void complete(time_t completionTime) override { throw std::runtime_error("Not implemented"); }
49
    void setDriveStatus(cta::common::dataStructures::DriveStatus status, time_t completionTime, const cta::optional<std::string> & reason) override { throw std::runtime_error("Not implemented"); }
50
    void setTapeSessionStats(const castor::tape::tapeserver::daemon::TapeSessionStats &stats) override { throw std::runtime_error("Not implemented"); }
51
    void flushAsyncSuccessReports(std::list<cta::SchedulerDatabase::RetrieveJob*>& jobsBatch, cta::log::LogContext& lc) override { throw std::runtime_error("Not implemented"); }
52
  };
53
54
55
  
  class TestingRetrieveMount: public cta::RetrieveMount {
  public:
56
    TestingRetrieveMount(cta::catalogue::Catalogue &catalogue, std::unique_ptr<cta::SchedulerDatabase::RetrieveMount> dbrm): RetrieveMount(catalogue, std::move(dbrm)) {
57
58
59
60
61
    }
  };
  
  class TestingRetrieveJob: public cta::RetrieveJob {
  public:
62
    TestingRetrieveJob(cta::RetrieveMount & rm): cta::RetrieveJob(&rm,
63
64
    cta::common::dataStructures::RetrieveRequest(), 
    cta::common::dataStructures::ArchiveFile(), 1,
65
    cta::PositioningMethod::ByBlock) {}
66
67
  };
  
68
69
  using namespace castor::tape::tapeserver::daemon;
  using namespace castor::tape::tapeserver::client;
70
  using namespace cta::disk;
71
  struct MockRecallReportPacker : public RecallReportPacker {
72
    void reportCompletedJob(std::unique_ptr<cta::RetrieveJob> successfulRetrieveJob) override {
73
      cta::threading::MutexLocker ml(m_mutex);
74
      completeJobs++;
75
    }
76
    void reportFailedJob(std::unique_ptr<cta::RetrieveJob> failedRetrieveJob, const cta::exception::Exception & ex) override {
77
      cta::threading::MutexLocker ml(m_mutex);
78
79
      failedJobs++;
    }
80
81
    void disableBulk() override {}
    void reportEndOfSession() override {
82
      cta::threading::MutexLocker ml(m_mutex);
83
84
      endSessions++;
    }
85
    void reportEndOfSessionWithErrors(const std::string msg, int error_code) override {
86
      cta::threading::MutexLocker ml(m_mutex);
87
      endSessionsWithError++;
88
    }
89
90
91
92
    void setDiskDone() override {}
    
    void setTapeDone() override {}
    
Victor Kotlyar's avatar
Victor Kotlyar committed
93
    MockRecallReportPacker(cta::RetrieveMount *rm,cta::log::LogContext lc):
94
95
     RecallReportPacker(rm,lc), completeJobs(0), failedJobs(0),
      endSessions(0), endSessionsWithError(0) {}
96
    cta::threading::Mutex m_mutex;
97
98
99
100
    int completeJobs;
    int failedJobs;
    int endSessions;
    int endSessionsWithError;
101
102
  };
  
103
  TEST(castor_tape_tapeserver_daemon, DiskWriteTaskFailedBlock){
104
105
    using ::testing::_;
    
106
    cta::log::StringLogger log("dummy","castor_tape_tapeserver_daemon_DiskWriteTaskFailedBlock",cta::log::DEBUG);
Victor Kotlyar's avatar
Victor Kotlyar committed
107
    cta::log::LogContext lc(log);
108
    
109
    std::unique_ptr<cta::SchedulerDatabase::RetrieveMount> dbrm(new TestingDatabaseRetrieveMount());
110
111
    std::unique_ptr<cta::catalogue::Catalogue> catalogue(new cta::catalogue::DummyCatalogue);
    TestingRetrieveMount trm(*catalogue, std::move(dbrm));
112
    MockRecallReportPacker report(&trm,lc);
113
    RecallMemoryManager mm(10,100,lc);
114
    cta::disk::RadosStriperPool striperPool;
115
    DiskFileFactory fileFactory("", 0, striperPool);
116
    
117
    cta::MockRetrieveMount mrm(*catalogue);
118
119
120
    std::unique_ptr<TestingRetrieveJob> fileToRecall(new TestingRetrieveJob(mrm));
    fileToRecall->retrieveRequest.archiveFileID = 1;
    fileToRecall->selectedCopyNb=1;
121
122
123
    cta::common::dataStructures::TapeFile tf;
    tf.copyNb = 1;
    fileToRecall->archiveFile.tapeFiles.push_back(tf);
124
    DiskWriteTask t(fileToRecall.release(),mm);
125
126
127
128
    for(int i=0;i<6;++i){
      MemBlock* mb=mm.getFreeBlock();
      mb->m_fileid=0;
      mb->m_fileBlock=i;
129
      if(5==i){
130
        mb->markAsFailed("Test error",666);
131
      }
132
      t.pushDataBlock(mb);
133
    }
134
135
136
137
    MemBlock* mb=mm.getFreeBlock();

    t.pushDataBlock(mb);
    t.pushDataBlock(NULL);
138
    castor::messages::TapeserverProxyDummy tspd;
139
140
    cta::TapeMountDummy tmd;
    RecallWatchDog rwd(1,1,tspd,tmd,"", lc);
141
    t.execute(report,lc,fileFactory,rwd, 0);
142
    ASSERT_EQ(1, report.failedJobs);
143
144
145
  }
}