Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
df9021cc
Commit
df9021cc
authored
9 years ago
by
Daniele Kruse
Browse files
Options
Downloads
Patches
Plain Diff
Fixed and added the DiskReadTaskTest
parent
309679fe
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tapeserver/castor/tape/tapeserver/daemon/DiskReadTaskTest.cpp
+64
-51
64 additions, 51 deletions
...server/castor/tape/tapeserver/daemon/DiskReadTaskTest.cpp
with
64 additions
and
51 deletions
tapeserver/castor/tape/tapeserver/daemon/DiskReadTaskTest.cpp
+
64
−
51
View file @
df9021cc
...
...
@@ -23,23 +23,50 @@
#include
"castor/tape/tapeserver/daemon/DiskReadTask.hpp"
#include
"castor/tape/tapeserver/daemon/DataConsumer.hpp"
#include
"castor/tape/tapeserver/daemon/MigrationMemoryManager.hpp"
#include
"castor/tape/tapeserver/daemon/MigrationReportPacker.hpp"
#include
"castor/tape/tapeserver/daemon/MemBlock.hpp"
#include
"castor/log/LogContext.hpp"
#include
"castor/log/StringLogger.hpp"
#include
"scheduler/ArchiveMount.hpp"
#include
<gtest/gtest.h>
#include
<fstream>
#include
<cmath>
#include
<ext/stdio_filebuf.h>
namespace
unitTests
{
using
namespace
castor
::
tape
::
tapeserver
::
daemon
;
class
TestingArchiveMount
:
public
cta
::
ArchiveMount
{
public:
TestingArchiveMount
(
std
::
unique_ptr
<
cta
::
SchedulerDatabase
::
ArchiveMount
>
dbrm
)
:
ArchiveMount
(
std
::
move
(
dbrm
))
{
}
};
class
TestingArchiveJob
:
public
cta
::
ArchiveJob
{
public:
TestingArchiveJob
()
{
}
};
};
using
namespace
castor
::
tape
::
tapeserver
::
daemon
;
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
));
MockMigrationReportPacker
(
cta
::
ArchiveMount
*
rm
,
castor
::
log
::
LogContext
lc
)
:
MigrationReportPacker
(
rm
,
lc
){}
};
class
FakeTapeWriteTask
:
public
DataConsumer
{
castor
::
server
::
BlockingQueue
<
MemBlock
*>
fifo
;
unsigned
long
m_checksum
;
...
...
@@ -67,53 +94,39 @@ namespace unitTests{
in
.
read
(
&
v
[
0
],
size
);
checksum
=
adler32
(
checksum
,
reinterpret_cast
<
unsigned
char
*>
(
&
v
[
0
]),
size
);
out
.
write
(
&
v
[
0
],
size
);
// out.seekg(0, std::ios::beg);
return
checksum
;
}
TEST
(
castor_tape_tapeserver_daemon
,
DiskReadTaskTest
){
char
path
[]
=
"/tmp/testDRT-XXXXXX"
;
mkstemp
(
path
);
std
::
ofstream
out
(
path
,
std
::
ios
::
out
|
std
::
ios
::
binary
);
castor
::
server
::
AtomicFlag
flag
;
castor
::
log
::
StringLogger
log
(
"castor_tape_tapeserver_daemon_DiskReadTaskTest"
);
castor
::
log
::
LogContext
lc
(
log
);
const
int
blockSize
=
1500
;
const
int
fileSize
(
1024
*
2000
);
// This test was commented out in the CMakeLists.txt file that would have
// compiled it. There was no comment explaining why it was commented out.
// The following commit message was associated with the commenting out of the
// CMakeLists.txt line:
//
// commit 165117042951769b7d0023933cc6e705b04fad54
// Author: David COME <david.come@cern.ch>
// Date: Tue Apr 22 11:35:11 2014 +0200
//
// Commented out DiskReadTaskTest
//
// This test is commented and left here in the hope that somebody in the future
// will have the time to make this test compile again.
//
//TEST(castor_tape_tapeserver_daemon, DiskReadTaskTest){
// char path[]="/tmp/testDRT-XXXXXX";
// mkstemp(path);
// std::ofstream out(path,std::ios::out | std::ios::binary);
// castor::server::AtomicFlag flag;
// castor::log::StringLogger log("castor_tape_tapeserver_daemon_DiskReadTaskTest");
// castor::log::LogContext lc(log);
//
// const int blockSize=1500;
// const int fileSize(1024*2000);
//
// const unsigned long original_checksum = mycopy(out,fileSize);
// castor::tape::tapeserver::daemon::MigrationMemoryManager mm(1,blockSize,lc);
//
// TestingArchiveJob file;
//
// file.archiveFile.lastKnownPath = path;
// file.archiveFile.size = fileSize;
//
// const int blockNeeded=fileSize/mm.blockCapacity()+((fileSize%mm.blockCapacity()==0) ? 0 : 1);
// int value=std::ceil(1024*2000./blockSize);
// ASSERT_EQ(value,blockNeeded);
//
// FakeTapeWriteTask ftwt;
// ftwt.pushDataBlock(new MemBlock(1,blockSize));
// castor::tape::tapeserver::daemon::DiskReadTask drt(ftwt,&file,blockNeeded,flag);
// drt.execute(lc);
//
// ASSERT_EQ(original_checksum,ftwt.getChecksum());
// delete ftwt.getFreeBlock();
//}
}
const
unsigned
long
original_checksum
=
mycopy
(
out
,
fileSize
);
castor
::
tape
::
tapeserver
::
daemon
::
MigrationMemoryManager
mm
(
1
,
blockSize
,
lc
);
TestingArchiveJob
file
;
file
.
archiveFile
.
path
=
path
;
file
.
archiveFile
.
size
=
fileSize
;
const
int
blockNeeded
=
fileSize
/
mm
.
blockCapacity
()
+
((
fileSize
%
mm
.
blockCapacity
()
==
0
)
?
0
:
1
);
int
value
=
std
::
ceil
(
1024
*
2000.
/
blockSize
);
ASSERT_EQ
(
value
,
blockNeeded
);
FakeTapeWriteTask
ftwt
;
ftwt
.
pushDataBlock
(
new
MemBlock
(
1
,
blockSize
));
castor
::
tape
::
tapeserver
::
daemon
::
DiskReadTask
drt
(
ftwt
,
&
file
,
blockNeeded
,
flag
);
DiskFileFactory
fileFactory
(
"RFIO"
,
""
,
0
);
drt
.
execute
(
lc
,
fileFactory
,
*
((
MigrationWatchDog
*
)
NULL
));
ASSERT_EQ
(
original_checksum
,
ftwt
.
getChecksum
());
delete
ftwt
.
getFreeBlock
();
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment