diff --git a/rdbms/CMakeLists.txt b/rdbms/CMakeLists.txt index a899576ce772278702557d5750186fb668511781..3a4143140df1961acd071a2c90e94bfc10c096da 100644 --- a/rdbms/CMakeLists.txt +++ b/rdbms/CMakeLists.txt @@ -84,6 +84,7 @@ install (TARGETS ctardbms DESTINATION usr/${CMAKE_INSTALL_LIBDIR}) set(RDBMS_UNIT_TESTS_LIB_SRC_FILES ConnPoolTest.cpp + ConnTest.cpp LoginTest.cpp ParamNameToIdxTest.cpp SqliteStmtTest.cpp) diff --git a/rdbms/ConnTest.cpp b/rdbms/ConnTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0d0a953b915884c09493bf3fba165df61c0d7cef --- /dev/null +++ b/rdbms/ConnTest.cpp @@ -0,0 +1,102 @@ +/* + * 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 "common/exception/Exception.hpp" +#include "rdbms/ConnFactoryFactory.hpp" +#include "rdbms/ConnPool.hpp" + +#include <gtest/gtest.h> +#include <sstream> + +namespace unitTests { + +class cta_rdbms_ConnTest : public ::testing::Test { +protected: + + virtual void SetUp() { + } + + virtual void TearDown() { + } +}; + +TEST_F(cta_rdbms_ConnTest, createSameTableInTwoSeparateInMemoryDatabases_executeNonQuery) { + using namespace cta::rdbms; + + const std::string sql = "CREATE TABLE POOLED_STMT_TEST(ID INTEGER)"; + + // First in-memory database + { + const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared"); + auto connFactory = ConnFactoryFactory::create(login); + auto conn = connFactory->create(); + + ASSERT_TRUE(conn->getTableNames().empty()); + + conn->executeNonQuery(sql, Stmt::AutocommitMode::ON); + + ASSERT_EQ(1, conn->getTableNames().size()); + } + + // Second in-memory database + { + const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared"); + auto connFactory = ConnFactoryFactory::create(login); + auto conn = connFactory->create(); + + ASSERT_TRUE(conn->getTableNames().empty()); + + conn->executeNonQuery(sql, Stmt::AutocommitMode::ON); + + ASSERT_EQ(1, conn->getTableNames().size()); + } +} + +TEST_F(cta_rdbms_ConnTest, createSameTableInTwoSeparateInMemoryDatabases_executeNonQueries) { + using namespace cta::rdbms; + + const std::string sql = "CREATE TABLE POOLED_STMT_TEST(ID INTEGER);"; + + // First in-memory database + { + const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared"); + auto connFactory = ConnFactoryFactory::create(login); + auto conn = connFactory->create(); + + ASSERT_TRUE(conn->getTableNames().empty()); + + conn->executeNonQueries(sql); + + ASSERT_EQ(1, conn->getTableNames().size()); + } + + // Second in-memory database + { + const Login login(Login::DBTYPE_SQLITE, "", "", "file::memory:?cache=shared"); + auto connFactory = ConnFactoryFactory::create(login); + auto conn = connFactory->create(); + + ASSERT_TRUE(conn->getTableNames().empty()); + + conn->executeNonQueries(sql); + + ASSERT_EQ(1, conn->getTableNames().size()); + } +} + +} // namespace unitTests