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
8b0573a2
Commit
8b0573a2
authored
9 years ago
by
Eric Cano
Browse files
Options
Downloads
Patches
Plain Diff
Fixed unit test relying on existence of /etc/fstab, which does not exist in containers.
Fixed exception failing to collect errnum.
parent
7196d04e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tapeserver/castor/io/IoTest.cpp
+4
-15
4 additions, 15 deletions
tapeserver/castor/io/IoTest.cpp
tapeserver/castor/tape/tapeserver/file/FileTest.cpp
+39
-5
39 additions, 5 deletions
tapeserver/castor/tape/tapeserver/file/FileTest.cpp
with
43 additions
and
20 deletions
tapeserver/castor/io/IoTest.cpp
+
4
−
15
View file @
8b0573a2
...
...
@@ -24,6 +24,7 @@
#include
"castor/io/io.hpp"
#include
"castor/utils/SmartFd.hpp"
#include
"castor/io/marshall.h"
#include
"castor/exception/Errnum.hpp"
#include
<fcntl.h>
#include
<gtest/gtest.h>
...
...
@@ -81,21 +82,9 @@ protected:
strncpy
(
listenAddr
.
sun_path
,
listenSockPath
,
sizeof
(
listenAddr
.
sun_path
)
-
1
);
if
(
0
!=
bind
(
smartListenSock
.
get
(),
(
const
struct
sockaddr
*
)
&
listenAddr
,
sizeof
(
listenAddr
)))
{
char
strErrBuf
[
256
];
if
(
0
!=
strerror_r
(
errno
,
strErrBuf
,
sizeof
(
strErrBuf
)))
{
memset
(
strErrBuf
,
'\0'
,
sizeof
(
strErrBuf
));
strncpy
(
strErrBuf
,
"Unknown"
,
sizeof
(
strErrBuf
)
-
1
);
}
std
::
string
errorMessage
(
"Call to bind() failed: "
);
errorMessage
+=
strErrBuf
;
castor
::
exception
::
Exception
ex
(
ECANCELED
);
ex
.
getMessage
()
<<
errorMessage
;
throw
ex
;
}
castor
::
exception
::
Errnum
::
throwOnNonZero
(
bind
(
smartListenSock
.
get
(),
(
const
struct
sockaddr
*
)
&
listenAddr
,
sizeof
(
listenAddr
)),
"Call to bind() failed: "
);
}
// Make the socket listen
...
...
This diff is collapsed.
Click to expand it.
tapeserver/castor/tape/tapeserver/file/FileTest.cpp
+
39
−
5
View file @
8b0573a2
...
...
@@ -227,17 +227,51 @@ namespace unitTests {
EXPECT_NO_THROW
(
ws
.
validateNextFSeq
(
2
));
EXPECT_THROW
(
ws
.
validateNextFSeq
(
1
),
castor
::
exception
::
Exception
);
}
// Class creating a temporary file of 1kB and deleting it
// automatically
class
TempFile
{
public:
TempFile
()
{
char
path
[]
=
"/tmp/testCTA-XXXXXX"
;
int
fd
=::
mkstemp
(
path
);
castor
::
exception
::
Errnum
::
throwOnMinusOne
(
fd
,
"In TempFile::TempFile: failed to mkstemp: "
);
::
close
(
fd
);
m_path
=
path
;
}
TempFile
(
const
std
::
string
&
path
)
:
m_path
(
path
)
{}
std
::
string
path
()
{
return
m_path
;
}
void
randomFill
(
size_t
size
)
{
std
::
ofstream
out
(
m_path
,
std
::
ios
::
out
|
std
::
ios
::
binary
);
std
::
ifstream
in
(
"/dev/urandom"
,
std
::
ios
::
in
|
std
::
ios
::
binary
);
std
::
unique_ptr
<
char
[]
>
buff
(
new
char
[
size
]);
in
.
read
(
buff
.
get
(),
size
);
out
.
write
(
buff
.
get
(),
size
);
}
~
TempFile
()
{
if
(
m_path
.
size
())
{
::
unlink
(
m_path
.
c_str
());
}
}
private
:
std
::
string
m_path
;
};
TEST
(
castorTapeDiskFile
,
canWriteAndReadDisk
)
{
const
uint32_t
block_size
=
1024
;
char
data1
[
block_size
];
char
data2
[
block_size
];
castor
::
tape
::
diskFile
::
DiskFileFactory
fileFactory
(
"RFIO"
,
""
);
TempFile
sourceFile
;
sourceFile
.
randomFill
(
1000
);
TempFile
destinationFile
(
sourceFile
.
path
()
+
"_dst"
);
// host part of file location
std
::
string
lh
=
"localhost:"
;
{
std
::
unique_ptr
<
castor
::
tape
::
diskFile
::
ReadFile
>
rf
(
fileFactory
.
createReadFile
(
"localhost:/etc/fstab"
));
fileFactory
.
createReadFile
(
lh
+
sourceFile
.
path
()
));
std
::
unique_ptr
<
castor
::
tape
::
diskFile
::
WriteFile
>
wf
(
fileFactory
.
createWriteFile
(
"localhost:/tmp/fstab"
));
fileFactory
.
createWriteFile
(
lh
+
destinationFile
.
path
()
));
size_t
res
=
0
;
do
{
res
=
rf
->
read
(
data1
,
block_size
);
...
...
@@ -246,9 +280,9 @@ namespace unitTests {
wf
->
close
();
}
std
::
unique_ptr
<
castor
::
tape
::
diskFile
::
ReadFile
>
src
(
fileFactory
.
createReadFile
(
"localhost:/tmp/fstab"
));
fileFactory
.
createReadFile
(
sourceFile
.
path
()
));
std
::
unique_ptr
<
castor
::
tape
::
diskFile
::
ReadFile
>
dst
(
fileFactory
.
createReadFile
(
"localhost:/etc/fstab"
));
fileFactory
.
createReadFile
(
destinationFile
.
path
()
));
size_t
res1
=
0
;
size_t
res2
=
0
;
do
{
...
...
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