Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
dCache
cta
Commits
39f28901
Commit
39f28901
authored
Feb 20, 2015
by
Eric Cano
Browse files
Created first unit tests for object store backend.
parent
c37836b2
Changes
5
Hide whitespace changes
Inline
Side-by-side
objectstore/BackendVFS.cpp
View file @
39f28901
...
...
@@ -91,6 +91,10 @@ void BackendVFS::atomicOverwrite(std::string name, std::string content) {
// file descriptor.
std
::
string
tempPath
=
m_root
+
"/."
+
name
+
".pre-overwrite"
;
std
::
string
targetPath
=
m_root
+
"/"
+
name
;
// Make sure the file exists first
if
(
!
exists
(
name
))
{
throw
cta
::
exception
::
Exception
(
"In BackendVFS::atomicOverwrite, trying to update a non-existing object"
);
}
// Create the new version of the file, make sure it's visible, lock it.
int
fd
=
::
creat
(
tempPath
.
c_str
(),
S_IRWXU
);
cta
::
exception
::
Errnum
::
throwOnMinusOne
(
fd
,
...
...
@@ -134,7 +138,8 @@ void BackendVFS::remove(std::string name) {
bool
BackendVFS
::
exists
(
std
::
string
name
)
{
std
::
string
path
=
m_root
+
"/"
+
name
;
if
(
::
access
(
path
.
c_str
(),
F_OK
))
std
::
string
lockPath
=
m_root
+
"/."
+
name
+
".lock"
;
if
(
::
access
(
path
.
c_str
(),
F_OK
)
||
::
access
(
lockPath
.
c_str
(),
F_OK
))
return
false
;
return
true
;
}
...
...
objectstore/BackendVFSTest.cpp
0 → 100644
View file @
39f28901
#include
<gtest/gtest.h>
#include
"BackendVFS.hpp"
#include
"exception/Exception.hpp"
namespace
unitTests
{
TEST
(
BackendVFS
,
BasicReadWrite
)
{
cta
::
objectstore
::
BackendVFS
bvfs
;
const
std
::
string
testValue
=
"1234"
;
const
std
::
string
testSecondValue
=
"1234"
;
const
std
::
string
testObjectName
=
"testObject"
;
// Check we can verify the absence of an object
ASSERT_EQ
(
false
,
bvfs
.
exists
(
testObjectName
));
// Check that an update attempt fails on a non-existing object
ASSERT_THROW
(
bvfs
.
atomicOverwrite
(
testObjectName
,
testSecondValue
),
cta
::
exception
::
Exception
);
// Check the creation of the obecjt
bvfs
.
create
(
testObjectName
,
testValue
);
// Check we can validate the presence of the object
ASSERT_EQ
(
true
,
bvfs
.
exists
(
testObjectName
));
// Check that we can read back after creation
ASSERT_EQ
(
testValue
,
bvfs
.
read
(
testObjectName
));
bvfs
.
atomicOverwrite
(
testObjectName
,
testSecondValue
);
// Check that an update goes through
ASSERT_EQ
(
testSecondValue
,
bvfs
.
read
(
testObjectName
));
// Check that we read back the value
ASSERT_EQ
(
testSecondValue
,
bvfs
.
read
(
testObjectName
));
// Check we can delete the object
ASSERT_NO_THROW
(
bvfs
.
remove
(
testObjectName
));
// Check that the object is actually gone
ASSERT_EQ
(
false
,
bvfs
.
exists
(
testObjectName
));
}
}
\ No newline at end of file
objectstore/CMakeLists.txt
View file @
39f28901
...
...
@@ -49,6 +49,6 @@ add_library (CTAObjectStore
# target_link_libraries(createEnvironment
# protobuf rados CTAObjectStore)
add_executable
(
unitTests unitTests.cpp
)
add_executable
(
unitTests unitTests.cpp
BackendVFSTest.cpp
)
target_link_libraries
(
unitTests
protobuf rados CTAObjectStore
)
\ No newline at end of file
protobuf rados CTAObjectStore gtest gmock
)
\ No newline at end of file
objectstore/RootEntryTest.cpp
0 → 100644
View file @
39f28901
#include
<gtest/gtest.h>
#include
"BackendVFS.hpp"
#include
"exception/Exception.hpp"
#include
"RootEntry.hpp"
TEST
(
RootEntry
.
BasicAccess
)
{
}
\ No newline at end of file
objectstore/unitTests.cpp
View file @
39f28901
#include
"BackendVFS.hpp"
#include
<iostream>
#include
<memory>
#include
<gtest/gtest.h>
#include
<gmock/gmock.h>
int
main
()
{
cta
::
objectstore
::
BackendVFS
bs
;
std
::
auto_ptr
<
cta
::
objectstore
::
Backend
::
Parameters
>
params
(
bs
.
getParams
());
std
::
cout
<<
"Created a new backend store: "
<<
params
->
toStr
()
<<
std
::
endl
;
int
main
(
int
argc
,
char
**
argv
)
{
// The following line must be executed to initialize Google Mock
// (and Google Test) before running the tests.
::
testing
::
InitGoogleMock
(
&
argc
,
argv
);
int
ret
=
RUN_ALL_TESTS
();
// Close standard in, out and error so that valgrind can be used with the
// following command-line to track open file-descriptors:
//
// valgrind --track-fds=yes
close
(
0
);
close
(
1
);
close
(
2
);
return
ret
;
}
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment