Skip to content
Snippets Groups Projects
Commit e6bf7b47 authored by Eric Cano's avatar Eric Cano
Browse files

Duplicated the SQL middle tier unit tests and turned them into templated tests...

Duplicated the SQL middle tier unit tests and turned them into templated tests for re-use with other implementations of middle tier.
parent 9c73e436
No related branches found
No related tags found
No related merge requests found
......@@ -5,5 +5,15 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../middletier)
include_directories(${CMAKE_BINARY_DIR})
add_library (CTAObjectStoreMiddleTier
ObjectStoreMiddleTier.cpp
ObjectStoreMiddleTierAdmin.cpp
)
set(MiddleTierUnitTests
MiddleTierAdminAbstractTest.cpp
MiddleTierTest.cpp
)
add_executable(ObjectStoreMiddleTierUnitTests unit_tests.cpp ${MiddleTierUnitTests})
target_link_libraries(ObjectStoreMiddleTierUnitTests
CTAObjectStoreMiddleTier
protobuf rados CTAObjectStore gtest gmock ctamiddletier)
This diff is collapsed.
#pragma once
#include <gtest/gtest.h>
#include "cta/MiddleTierAdmin.hpp"
#include "cta/MiddleTierUser.hpp"
namespace unitTests {
class MiddleTierFull {
public:
cta::MiddleTierAdmin * admin;
cta::MiddleTierUser * user;
MiddleTierFull(cta::MiddleTierAdmin * a, cta::MiddleTierUser * u):
admin(a), user(u) {}
MiddleTierFull(): admin(NULL), user(NULL) {}
};
class MiddleTierAdminAbstractTest: public ::testing::TestWithParam<MiddleTierFull> {
protected:
MiddleTierAdminAbstractTest() {}
virtual void SetUp() {
m_middleTier = GetParam();
}
MiddleTierFull m_middleTier;
};
}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MiddleTierAdminAbstractTest.hpp"
#include "ObjectStoreMiddleTierAdmin.hpp"
#include "objectstore/BackendRados.hpp"
#include "objectstore/BackendVFS.hpp"
#include "middletier/cta/SqliteMiddleTierAdmin.hpp"
#define TEST_RADOS 0
#define TEST_VFS 0
#define TEST_SQL 1
namespace unitTests {
#if TEST_RADOS
cta::objectstore::BackendRados osRados("tapetest", "tapetest");
cta::OStoreMiddleTierAdmin mtaRados(osRados);
unitTests::MiddleTierFull middleTierRados;
middleTierRados.admin = &mtaRados;
middleTierRados.user = NULL;
INSTANTIATE_TEST_CASE_P(MiddleTierRados, MiddleTierAdminAbstractTest , ::testing::Values(middleTierRados));
#endif
#if TEST_VFS
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));
#endif
}
\ No newline at end of file
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "cta/Exception.hpp"
#include "ObjectStoreMiddleTierAdmin.hpp"
#include "objectstore/Backend.hpp"
#include "objectstore/RootEntry.hpp"
#include "objectstore/AdminUsersList.hpp"
namespace cta {
//------------------------------------------------------------------------------
// constructor
//------------------------------------------------------------------------------
OStoreMiddleTierAdmin::OStoreMiddleTierAdmin(objectstore::Backend& backend):
m_backend(backend) {
// check that we can at least access the root entry
objectstore::RootEntry re(m_backend);
objectstore::ScopedSharedLock reLock(re);
re.fetch();
}
//------------------------------------------------------------------------------
// destructor
//------------------------------------------------------------------------------
OStoreMiddleTierAdmin::~OStoreMiddleTierAdmin() throw() {
}
//------------------------------------------------------------------------------
// createAdminUser
//------------------------------------------------------------------------------
void OStoreMiddleTierAdmin::createAdminUser(
const SecurityIdentity &requester,
const UserIdentity &user,
const std::string &comment) {
// Authz is not handled in this layer. We hence store the new admin user
// without checks.
objectstore::RootEntry re(m_backend);
objectstore::ScopedSharedLock reLock(re);
re.fetch();
objectstore::AdminUsersList aul(re.getAdminUsersList(), m_backend);
reLock.release();
objectstore::ScopedExclusiveLock aulLock(aul);
aul.fetch();
AdminUser au(user, requester.user, comment);
aul.add(au);
aul.commit();
}
}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "cta/MiddleTierAdmin.hpp"
namespace cta {
namespace objectstore {
class Backend;
}
/**
* The administration API of the the middle-tier.
* ObjectStore based implementation
*/
class OStoreMiddleTierAdmin: public MiddleTierAdmin {
public:
/**
* Contructor
*/
OStoreMiddleTierAdmin(objectstore::Backend & backend);
/**
* Destructor
*/
virtual ~OStoreMiddleTierAdmin() throw();
/**
* Creates the specified administrator.
*
* @param requester The identity of the user requesting the creation of the
* administrator.
* @param user The identity of the administrator.
* @param comment The comment describing the sministrator.
*/
virtual void createAdminUser(
const SecurityIdentity &requester,
const UserIdentity &user,
const std::string &comment);
/**
* Deletes the specified administrator.
*
* @param requester The identity of the user requesting the deletion of the
* administrator.
* @param user The identity of the administrator.
*/
virtual void deleteAdminUser(
const SecurityIdentity &requester,
const UserIdentity &user);
/**
* Returns the current list of administrators in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of administrators in lexicographical order.
*/
virtual std::list<AdminUser> getAdminUsers(const SecurityIdentity &requester)
const;
/**
* Creates the specified administration host.
*
* @param requester The identity of the user requesting the creation of the
* administration host.
* @param hostName The network name of the administration host.
* @param comment The comment describing the administration host.
*/
virtual void createAdminHost(
const SecurityIdentity &requester,
const std::string &hostName,
const std::string &comment);
/**
* Deletes the specified administration host.
*
* @param requester The identity of the user requesting the deletion of the
* administration host.
* @param hostName The network name of the administration host.
* @param comment The comment describing the administration host.
*/
virtual void deleteAdminHost(
const SecurityIdentity &requester,
const std::string &hostName);
/**
* Returns the current list of administration hosts in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of administration hosts in lexicographical order.
*/
virtual std::list<AdminHost> getAdminHosts(const SecurityIdentity &requester)
const;
/**
* Creates the specified storage class.
*
* @param requester The identity of the user requesting the creation of the
* storage class.
* @param name The name of the storage class.
* @param nbCopies The number of copies a file associated with this storage
* class should have on tape.
* @param comment The comment describing the storage class.
*/
virtual void createStorageClass(
const SecurityIdentity &requester,
const std::string &name,
const uint8_t nbCopies,
const std::string &comment);
/**
* Deletes the specified storage class.
*
* @param requester The identity of the user requesting the deletion of the
* storage class.
* @param name The name of the storage class.
*/
virtual void deleteStorageClass(
const SecurityIdentity &requester,
const std::string &name);
/**
* Gets the current list of storage classes in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of storage classes in lexicographical order.
*/
virtual std::list<StorageClass> getStorageClasses(
const SecurityIdentity &requester) const;
/**
* Creates a tape pool with the specifed name.
*
* @param requester The identity of the user requesting the creation of the
* tape pool.
* @param name The name of the tape pool.
* @param nbDrives The maximum number of drives that can be concurrently
* assigned to this pool independent of whether they are archiving or
* retrieving files.
* @param nbPartialTapes The maximum number of tapes that can be partially
* full at any moment in time.
* @param comment The comment describing the tape pool.
*/
virtual void createTapePool(
const SecurityIdentity &requester,
const std::string &name,
const uint16_t nbDrives,
const uint32_t nbPartialTapes,
const std::string &comment);
/**
* Delete the tape pool with the specifed name.
*
* @param requester The identity of the user requesting the deletion of the
* tape pool.
* @param name The name of the tape pool.
*/
virtual void deleteTapePool(
const SecurityIdentity &requester,
const std::string &name);
/**
* Gets the current list of tape pools in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of tape pools in lexicographical order.
*/
virtual std::list<TapePool> getTapePools(
const SecurityIdentity &requester) const;
/**
* Creates the specified archive route.
*
* @param requester The identity of the user requesting the creation of the
* archive route.
* @param storageClassName The name of the storage class that identifies the
* source disk files.
* @param copyNb The tape copy number.
* @param tapePoolName The name of the destination tape pool.
* @param comment The comment describing the archive route.
*/
virtual void createArchivalRoute(
const SecurityIdentity &requester,
const std::string &storageClassName,
const uint8_t copyNb,
const std::string &tapePoolName,
const std::string &comment);
/**
* Deletes the specified archive route.
*
* @param requester The identity of the user requesting the deletion of the
* archive route.
* @param storageClassName The name of the storage class that identifies the
* source disk files.
* @param copyNb The tape copy number.
*/
virtual void deleteArchivalRoute(
const SecurityIdentity &requester,
const std::string &storageClassName,
const uint8_t copyNb);
/**
* Gets the current list of archive routes.
*
* @param requester The identity of the user requesting the list.
*/
virtual std::list<ArchivalRoute> getArchivalRoutes(
const SecurityIdentity &requester) const;
/**
* Creates a logical library with the specified name.
*
* @param requester The identity of the user requesting the creation of the
* logical library.
* @param name The name of the logical library.
* @param comment The comment describing the logical library.
*/
virtual void createLogicalLibrary(
const SecurityIdentity &requester,
const std::string &name,
const std::string &comment);
/**
* Deletes the logical library with the specified name.
*
* @param requester The identity of the user requesting the deletion of the
* logical library.
* @param name The name of the logical library.
*/
virtual void deleteLogicalLibrary(
const SecurityIdentity &requester,
const std::string &name);
/**
* Returns the current list of libraries in lexicographical order.
*
* @param requester The identity of the user requesting the list.
* @return The current list of libraries in lexicographical order.
*/
virtual std::list<LogicalLibrary> getLogicalLibraries(
const SecurityIdentity &requester) const;
/**
* Creates a tape.
*
* @param requester The identity of the user requesting the creation of the
* tape.
* @param vid The volume identifier of the tape.
* @param logicalLibrary The name of the logical library to which the tape
* belongs.
* @param tapePoolName The name of the tape pool to which the tape belongs.
* @param capacityInBytes The capacity of the tape.
* @param comment The comment describing the logical library.
*/
virtual void createTape(
const SecurityIdentity &requester,
const std::string &vid,
const std::string &logicalLibraryName,
const std::string &tapePoolName,
const uint64_t capacityInBytes,
const std::string &comment);
/**
* Deletes the tape with the specified volume identifier.
*
* @param requester The identity of the user requesting the deletion of the
* tape.
* @param vid The volume identifier of the tape.
*/
virtual void deleteTape(
const SecurityIdentity &requester,
const std::string &vid);
/**
* Returns the current list of tapes in the lexicographical order of their
* volume identifiers.
*
* @param requester The identity of the user requesting the list.
* @return The current list of tapes in the lexicographical order of their
* volume identifiers.
*/
virtual std::list<Tape> getTapes(
const SecurityIdentity &requester) const;
private:
/**
* Reference to the backend used for storing objects
*/
objectstore::Backend & m_backend;
};
}
/*
* The CERN Tape Archive (CTA) project
* Copyright (C) 2015 CERN
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include <gmock/gmock.h>
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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment