Commit 8ff55262 authored by Eric Cano's avatar Eric Cano
Browse files

Mutualised exceptions from objectore prototype to the whole project.

Used exceptions while moving Vfs to creating its temporary directory using mkdtemp. This allows several Vfs intances to run on the same
system simultaneously.
Updated the model of the abstract unit test so it can instanciate one test environement per unit test. This was needed in the current
unit test for middle tier admin.
parent 0d4ed2a5
......@@ -29,6 +29,7 @@ set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
add_subdirectory(exception)
add_subdirectory(middletier)
add_subdirectory(objectstore)
add_subdirectory(objectstore_middletier)
......
cmake_minimum_required (VERSION 2.6)
include_directories(${PROJECT_SOURCE_DIR})
add_library(CTAException
Backtrace.cpp
Errnum.cpp
Exception.cpp
strerror_r_wrapper.cpp)
......@@ -40,8 +40,8 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "objectstore/exception/Errnum.hpp"
#include "objectstore/exception/strerror_r_wrapper.h"
#include "exception/Errnum.hpp"
#include "exception/strerror_r_wrapper.h"
#include <string.h>
#include <errno.h>
......
......@@ -40,7 +40,7 @@
* @author Castor Dev team, castor-dev@cern.ch
*****************************************************************************/
#include "objectstore/exception/Exception.hpp"
#include "exception/Exception.hpp"
//------------------------------------------------------------------------------
// constructor
......
......@@ -42,7 +42,7 @@
#pragma once
#include "objectstore/exception/Backtrace.hpp"
#include "exception/Backtrace.hpp"
#include <exception>
#include <sstream>
......
cmake_minimum_required (VERSION 2.6)
find_package (sqlite REQUIRED)
include_directories (${SQLITE3_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR})
include_directories (${SQLITE3_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}
${PROJECT_SOURCE_DIR})
set (MIDDLE_TIER_LIB_SRC_FILES
cta/AdminHost.cpp
......@@ -65,7 +66,8 @@ set (MIDDLE_TIER_LIB_SRC_FILES
add_library (ctamiddletier SHARED
${MIDDLE_TIER_LIB_SRC_FILES})
target_link_libraries (ctamiddletier ${SQLITE3_LIBRARY_RELEASE})
target_link_libraries (ctamiddletier ${SQLITE3_LIBRARY_RELEASE}
CTAException)
set (MIDDLE_TIER_UNIT_TESTS_LIB_SRC_FILES
cta/SqliteMiddleTierAdminTest.cpp
......
......@@ -29,6 +29,7 @@
#include <fcntl.h>
#include "cta/Exception.hpp"
#include "exception/Errnum.hpp"
#include "cta/Utils.hpp"
#include "cta/Vfs.hpp"
......@@ -132,35 +133,25 @@ void cta::Vfs::checkStorageClassIsNotInUse(const SecurityIdentity &requester, co
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
cta::Vfs::Vfs() {
m_baseDir = "/tmp";
m_fsDir = m_baseDir+"/CTATmpFs";
checkDirectoryExists(m_baseDir);
checkPathnameDoesNotExist(m_fsDir);
int rc = mkdir(m_fsDir.c_str(), 0777);
if(rc != 0) {
char buf[256];
std::ostringstream message;
message << "Vfs() - mkdir " << m_fsDir << " error. Reason: \n" << strerror_r(errno, buf, 256);
throw(Exception(message.str()));
}
rc = setxattr(m_fsDir.c_str(), "user.CTAStorageClass", "", 0, 0);
if(rc != 0) {
char buf[256];
std::ostringstream message;
message << "Vfs() - " << m_fsDir << " setxattr error. Reason: " << strerror_r(errno, buf, 256);
throw(Exception(message.str()));
}
cta::Vfs::Vfs() {
char path[100];
strncpy(path, "/tmp/CTATmpFsXXXXXX", 100);
cta::exception::Errnum::throwOnNull(
mkdtemp(path),
"Vfs() - Failed to create temporary directory");
m_fsDir = path;
cta::exception::Errnum::throwOnNonZero(
setxattr(m_fsDir.c_str(), "user.CTAStorageClass", "", 0, 0),
std::string("Vfs() - Failed to setxattr error for ")+m_fsDir);
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
cta::Vfs::~Vfs() throw() {
system("rm -rf /tmp/CTATmpFs");
std::string cmd("rm -rf ");
cmd += m_fsDir;
system(cmd.c_str());
}
//------------------------------------------------------------------------------
......
......@@ -25,10 +25,6 @@ add_library (CTAObjectStore
FIFO.cpp
GenericObject.cpp
GarbageCollector.cpp
exception/Backtrace.cpp
exception/Errnum.cpp
exception/Exception.cpp
exception/strerror_r_wrapper.cpp
threading/ChildProcess.cpp
threading/Mutex.cpp
threading/Threading.cpp
......@@ -67,4 +63,4 @@ set(ObjectStoreUnitTests
add_executable(unitTests unitTests.cpp ${ObjectStoreUnitTests})
target_link_libraries(unitTests
protobuf rados CTAObjectStore gtest gmock)
protobuf rados CTAObjectStore CTAException gtest gmock)
......@@ -40,8 +40,8 @@
*****************************************************************************/
#pragma once
#include "objectstore/exception/Errnum.hpp"
#include "objectstore/exception/Exception.hpp"
#include "exception/Errnum.hpp"
#include "exception/Exception.hpp"
#include <unistd.h>
......
......@@ -17,8 +17,8 @@
*/
#include "objectstore/threading/Mutex.hpp"
#include "objectstore/exception/Errnum.hpp"
#include "objectstore/exception/Exception.hpp"
#include "exception/Errnum.hpp"
#include "exception/Exception.hpp"
//------------------------------------------------------------------------------
//constructor
......
......@@ -41,8 +41,8 @@
#pragma once
#include "objectstore/exception/Errnum.hpp"
#include "objectstore/exception/Exception.hpp"
#include "exception/Errnum.hpp"
#include "exception/Exception.hpp"
#include "objectstore/threading/Mutex.hpp"
#include <pthread.h>
......
......@@ -15,5 +15,5 @@ set(MiddleTierUnitTests
add_executable(ObjectStoreMiddleTierUnitTests unit_tests.cpp ${MiddleTierUnitTests})
target_link_libraries(ObjectStoreMiddleTierUnitTests
CTAObjectStoreMiddleTier
protobuf rados CTAObjectStore gtest gmock ctamiddletier)
CTAException CTAObjectStore CTAObjectStoreMiddleTier
protobuf rados gtest gmock ctamiddletier)
......@@ -5,24 +5,31 @@
#include "cta/MiddleTierUser.hpp"
namespace unitTests {
class localMiddleTier {
public:
virtual cta::MiddleTierAdmin & admin() = 0;
virtual cta::MiddleTierUser & user() = 0;
virtual ~localMiddleTier() {}
};
class MiddleTierFull {
class MiddleTierFactory {
public:
cta::MiddleTierAdmin * admin;
cta::MiddleTierUser * user;
MiddleTierFull(cta::MiddleTierAdmin * a, cta::MiddleTierUser * u):
admin(a), user(u) {}
MiddleTierFull(): admin(NULL), user(NULL) {}
virtual localMiddleTier * allocateLocalMiddleTier() = 0;
cta::MiddleTierAdmin & permanentAdmin () { return m_localMiddleTier->admin(); }
cta::MiddleTierUser & permanentUser () { return m_localMiddleTier->user(); }
virtual ~MiddleTierFactory() {}
protected:
localMiddleTier * m_localMiddleTier;
};
class MiddleTierAdminAbstractTest: public ::testing::TestWithParam<MiddleTierFull> {
protected:
MiddleTierAdminAbstractTest() {}
virtual void SetUp() {
m_middleTier = GetParam();
}
MiddleTierFull m_middleTier;
};
class MiddleTierAdminAbstractTest: public ::testing::TestWithParam<MiddleTierFactory*> {
protected:
MiddleTierAdminAbstractTest() {}
// virtual void SetUp() {
// m_middleTierFactory = GetParam();
// }
// MiddleTierFactory * m_middleTierFactory;
};
}
......@@ -20,8 +20,10 @@
#include "ObjectStoreMiddleTierAdmin.hpp"
#include "objectstore/BackendRados.hpp"
#include "objectstore/BackendVFS.hpp"
#include "middletier/cta/SqliteDatabase.hpp"
#include "middletier/cta/Vfs.hpp"
#include "middletier/cta/SqliteMiddleTierAdmin.hpp"
#include "middletier/cta/SqliteMiddleTierUser.hpp"
#define TEST_RADOS 0
#define TEST_VFS 0
......@@ -45,11 +47,31 @@ cta::objectstore::BackendVFS osVFS;
#endif
#if TEST_SQL
cta::SqliteDatabase sqlite;
cta::Vfs vfs;
cta::SqliteMiddleTierAdmin mtaSQL(vfs, sqlite);
MiddleTierFull mtfSQL(&mtaSQL, NULL);
INSTANTIATE_TEST_CASE_P(MiddleTierSQL, MiddleTierAdminAbstractTest, ::testing::Values(mtfSQL));
class SQLiteLocalMiddleTier: public localMiddleTier {
public:
SQLiteLocalMiddleTier(): m_vfs(), m_sqLite(), m_admin(m_vfs, m_sqLite),
m_user(m_vfs, m_sqLite) {}
virtual cta::MiddleTierAdmin & admin () { return m_admin; }
virtual cta::MiddleTierUser & user () { return m_user; }
private:
cta::Vfs m_vfs;
cta::SqliteDatabase m_sqLite;
cta::SqliteMiddleTierAdmin m_admin;
cta::SqliteMiddleTierUser m_user;
};
class SQLiteMiddleTierFactory: public MiddleTierFactory {
public:
SQLiteMiddleTierFactory() {
m_localMiddleTier = allocateLocalMiddleTier();
}
virtual localMiddleTier * allocateLocalMiddleTier() {
return new SQLiteLocalMiddleTier; }
} g_SQLiteMiddleTierFactory;
// Macro chokes on implicit casting of pointer so we have to do it ourselves
INSTANTIATE_TEST_CASE_P(MiddleTierSQL, MiddleTierAdminAbstractTest, ::testing::Values(
(MiddleTierFactory*)&g_SQLiteMiddleTierFactory));
#endif
}
\ 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