Commit 39f28901 authored by Eric Cano's avatar Eric Cano
Browse files

Created first unit tests for object store backend.

parent c37836b2
......@@ -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);
......@@ -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;
#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
bvfs.atomicOverwrite(testObjectName, testSecondValue);
// Check that an update goes through
// Check that we read back the value
// Check we can delete the object
// Check that the object is actually gone
ASSERT_EQ(false, bvfs.exists(testObjectName));
\ No newline at end of file
......@@ -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)
protobuf rados CTAObjectStore)
\ No newline at end of file
protobuf rados CTAObjectStore gtest gmock)
\ No newline at end of file
#include <gtest/gtest.h>
#include "BackendVFS.hpp"
#include "exception/Exception.hpp"
#include "RootEntry.hpp"
TEST(RootEntry.BasicAccess) {
\ No newline at end of file
#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
return ret;
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment