RetrieveRequestTest.cpp 9.61 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
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/**
 * The CERN Tape Archive (CTA) project
 * Copyright © 2018 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 3 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, see <http://www.gnu.org/licenses/>.
 */
#include <gtest/gtest.h>

#include "common/log/DummyLogger.hpp"
#include "BackendVFS.hpp"
#include "RootEntry.hpp"
#include "AgentReference.hpp"
#include "Agent.hpp"
#include "RetrieveRequest.hpp"
#ifdef STDOUT_LOGGING
#include "common/log/StdoutLogger.hpp"
#endif
#include "catalogue/DummyCatalogue.hpp"
#include "Algorithms.hpp"
#include "RetrieveQueueAlgorithms.hpp"
#include "RetrieveQueue.hpp"

namespace unitTests {
  using namespace cta::objectstore;
  
  TEST(RetrieveRequest, IndividualGarbageCollectionRetrieveRequestToReportToRepackForSuccess) {
    #ifdef STDOUT_LOGGING
      cta::log::StdoutLogger dl("dummy", "unitTest");
    #else
      cta::log::DummyLogger dl("dummy", "unitTest");
    #endif
    cta::log::LogContext lc(dl);
    // We need a dummy catalogue
    cta::catalogue::DummyCatalogue catalogue;
    // Here we check that can successfully call RetrieveRequests's garbage collector
    cta::objectstore::BackendVFS be;
    // Create the root entry
    cta::objectstore::RootEntry re(be);
    re.initialize();
    re.insert();
    // Create the agent register
    cta::objectstore::EntryLogSerDeser el("user0",
        "unittesthost", time(NULL));
    cta::objectstore::ScopedExclusiveLock rel(re);
    // Create the agent for objects creation
    cta::objectstore::AgentReference agentRef("unitTestCreateEnv", dl);
    // Finish root creation.
    re.addOrGetAgentRegisterPointerAndCommit(agentRef, el, lc);
    rel.release();
    // continue agent creation.
    cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
    agent.initialize();
    agent.setTimeout_us(0);
    agent.insertAndRegisterSelf(lc);
    // Create an agent to garbage be collected
    cta::objectstore::AgentReference agrA("unitTestAgentA", dl);
    cta::objectstore::Agent agA(agrA.getAgentAddress(), be);
    agA.initialize();
    agA.setTimeout_us(0);
    agA.insertAndRegisterSelf(lc);
    
    //Create the RetrieveRequest
    std::string atfrAddr = agrA.nextId("RetrieveRequest");
    agrA.addToOwnership(atfrAddr, be);
    
    cta::objectstore::RetrieveRequest rr(atfrAddr, be);
    rr.initialize();
    cta::common::dataStructures::RetrieveFileQueueCriteria rqc;
    rqc.archiveFile.archiveFileID = 123456789L;
    rqc.archiveFile.diskFileId = "eos://diskFile";
    rqc.archiveFile.checksumBlob.insert(cta::checksum::NONE, "");
    rqc.archiveFile.creationTime = 0;
    rqc.archiveFile.reconciliationTime = 0;
    rqc.archiveFile.diskFileInfo = cta::common::dataStructures::DiskFileInfo();
    rqc.archiveFile.diskInstance = "eoseos";
    rqc.archiveFile.fileSize = 1000;
    rqc.archiveFile.storageClass = "sc";
    {
      cta::common::dataStructures::TapeFile tf;
      tf.blockId=0;
      tf.fileSize=1;
      tf.copyNb=1;
      tf.creationTime=time(nullptr);
      tf.fSeq=1;
      tf.vid="Tape0";
      rqc.archiveFile.tapeFiles.push_back(tf);
    }
    rqc.mountPolicy.archiveMinRequestAge = 1;
    rqc.mountPolicy.archivePriority = 1;
    rqc.mountPolicy.creationLog.time = time(nullptr);
    rqc.mountPolicy.lastModificationLog.time = time(nullptr);
    rqc.mountPolicy.maxDrivesAllowed = 1;
    rqc.mountPolicy.retrieveMinRequestAge = 1;
    rqc.mountPolicy.retrievePriority = 1;
    rr.setRetrieveFileQueueCriteria(rqc);
    cta::common::dataStructures::RetrieveRequest sReq;
    sReq.archiveFileID = rqc.archiveFile.archiveFileID;
    sReq.creationLog.time=time(nullptr);
    rr.setSchedulerRequest(sReq);
    rr.addJob(1, 1, 1, 1);
    rr.setJobStatus(1,cta::objectstore::serializers::RetrieveJobStatus::RJS_ToReportToRepackForSuccess);
    rr.setOwner(agA.getAddressIfSet());
    rr.setActiveCopyNumber(0);
    cta::objectstore::RetrieveRequest::RepackInfo ri;
    ri.isRepack = true;
    ri.fSeq = 1;
    ri.fileBufferURL = "testFileBufferURL";
    ri.repackRequestAddress = "repackRequestAddress";
    rr.setRepackInfo(ri);
    rr.insert();
    
    //Calling the individual garbage collection of the RetrieveRequest
    cta::objectstore::ScopedExclusiveLock sel(rr);
    ASSERT_NO_THROW(rr.garbageCollect(rr.getOwner(),agentRef,lc,catalogue));
    
    //The Retrieve Request should now be queued in the RetrieveQueueToReportToRepackForSuccess
    
    typedef cta::objectstore::ContainerAlgorithms<cta::objectstore::RetrieveQueue,cta::objectstore::RetrieveQueueToReportToRepackForSuccess> RQTRTRFSAlgo;
    RQTRTRFSAlgo algo(be,agentRef);
    RQTRTRFSAlgo::PopCriteria criteria;
    criteria.files = 1;
    auto jobs = algo.popNextBatch(ri.repackRequestAddress, criteria, lc);
    ASSERT_FALSE(jobs.elements.empty());
    
    ASSERT_EQ(123456789L,jobs.elements.front().archiveFile.archiveFileID);
    ASSERT_EQ(1,jobs.elements.front().archiveFile.tapeFiles.at(1).fSeq);
    ASSERT_EQ("Tape0",jobs.elements.front().archiveFile.tapeFiles.at(1).vid);
  }
  
  TEST(RetrieveRequest, IndividualGarbageCollectionRetrieveRequestToReportToRepackForFailure) {
    #ifdef STDOUT_LOGGING
      cta::log::StdoutLogger dl("dummy", "unitTest");
    #else
      cta::log::DummyLogger dl("dummy", "unitTest");
    #endif
    cta::log::LogContext lc(dl);
    // We need a dummy catalogue
    cta::catalogue::DummyCatalogue catalogue;
    // Here we check that can successfully call RetrieveRequests's garbage collector
    cta::objectstore::BackendVFS be;
    // Create the root entry
    cta::objectstore::RootEntry re(be);
    re.initialize();
    re.insert();
    // Create the agent register
    cta::objectstore::EntryLogSerDeser el("user0",
        "unittesthost", time(NULL));
    cta::objectstore::ScopedExclusiveLock rel(re);
    // Create the agent for objects creation
    cta::objectstore::AgentReference agentRef("unitTestCreateEnv", dl);
    // Finish root creation.
    re.addOrGetAgentRegisterPointerAndCommit(agentRef, el, lc);
    rel.release();
    // continue agent creation.
    cta::objectstore::Agent agent(agentRef.getAgentAddress(), be);
    agent.initialize();
    agent.setTimeout_us(0);
    agent.insertAndRegisterSelf(lc);
    // Create an agent to garbage be collected
    cta::objectstore::AgentReference agrA("unitTestAgentA", dl);
    cta::objectstore::Agent agA(agrA.getAgentAddress(), be);
    agA.initialize();
    agA.setTimeout_us(0);
    agA.insertAndRegisterSelf(lc);
    
    //Create the RetrieveRequest
    std::string atfrAddr = agrA.nextId("RetrieveRequest");
    agrA.addToOwnership(atfrAddr, be);
    
    cta::objectstore::RetrieveRequest rr(atfrAddr, be);
    rr.initialize();
    cta::common::dataStructures::RetrieveFileQueueCriteria rqc;
    rqc.archiveFile.archiveFileID = 123456789L;
    rqc.archiveFile.diskFileId = "eos://diskFile";
    rqc.archiveFile.checksumBlob.insert(cta::checksum::NONE, "");
    rqc.archiveFile.creationTime = 0;
    rqc.archiveFile.reconciliationTime = 0;
    rqc.archiveFile.diskFileInfo = cta::common::dataStructures::DiskFileInfo();
    rqc.archiveFile.diskInstance = "eoseos";
    rqc.archiveFile.fileSize = 1000;
    rqc.archiveFile.storageClass = "sc";
    {
      cta::common::dataStructures::TapeFile tf;
      tf.blockId=0;
      tf.fileSize=1;
      tf.copyNb=1;
      tf.creationTime=time(nullptr);
      tf.fSeq=1;
      tf.vid="Tape0";
      rqc.archiveFile.tapeFiles.push_back(tf);
    }
    rqc.mountPolicy.archiveMinRequestAge = 1;
    rqc.mountPolicy.archivePriority = 1;
    rqc.mountPolicy.creationLog.time = time(nullptr);
    rqc.mountPolicy.lastModificationLog.time = time(nullptr);
    rqc.mountPolicy.maxDrivesAllowed = 1;
    rqc.mountPolicy.retrieveMinRequestAge = 1;
    rqc.mountPolicy.retrievePriority = 1;
    rr.setRetrieveFileQueueCriteria(rqc);
    cta::common::dataStructures::RetrieveRequest sReq;
    sReq.archiveFileID = rqc.archiveFile.archiveFileID;
    sReq.creationLog.time=time(nullptr);
    rr.setSchedulerRequest(sReq);
    rr.addJob(1, 1, 1, 1);
    rr.setJobStatus(1,cta::objectstore::serializers::RetrieveJobStatus::RJS_ToReportToRepackForFailure);
    rr.setOwner(agA.getAddressIfSet());
    rr.setActiveCopyNumber(0);
    cta::objectstore::RetrieveRequest::RepackInfo ri;
    ri.isRepack = true;
    ri.fSeq = 1;
    ri.fileBufferURL = "testFileBufferURL";
    ri.repackRequestAddress = "repackRequestAddress";
    rr.setRepackInfo(ri);
    rr.insert();
    
    //Calling the individual garbage collection of the RetrieveRequest
    cta::objectstore::ScopedExclusiveLock sel(rr);
    ASSERT_NO_THROW(rr.garbageCollect(rr.getOwner(),agentRef,lc,catalogue));
    
    //The Retrieve Request should now be queued in the RetrieveQueueToReportToRepackForFailure
    
    typedef cta::objectstore::ContainerAlgorithms<cta::objectstore::RetrieveQueue,cta::objectstore::RetrieveQueueToReportToRepackForFailure> RQTRTRFFAlgo;
    RQTRTRFFAlgo algo(be,agentRef);
    RQTRTRFFAlgo::PopCriteria criteria;
    criteria.files = 1;
    auto jobs = algo.popNextBatch(ri.repackRequestAddress, criteria, lc);
    ASSERT_FALSE(jobs.elements.empty());
    
    ASSERT_EQ(123456789L,jobs.elements.front().archiveFile.archiveFileID);
    ASSERT_EQ(1,jobs.elements.front().archiveFile.tapeFiles.at(1).fSeq);
    ASSERT_EQ("Tape0",jobs.elements.front().archiveFile.tapeFiles.at(1).vid);
  }
}