Commit c629300a authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰
Browse files

fixed compilation issues for cql unittests

# Conflicts:
#	src/lib/dhcpsrv/pgsql_lease_mgr.h
parent 6b4fef59
......@@ -165,33 +165,6 @@ CqlConnection::prepareStatements(CqlTaggedStatement *statements) {
}
}
string
CqlConnection::getName() const {
string name = "";
try {
name = getParameter("name");
} catch (...) {
// Return an empty name
}
return (name);
}
string
CqlConnection::getDescription() const {
return (string("Cassandra Database"));
}
pair<uint32_t, uint32_t>
CqlConnection::getVersion() const {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL,
DHCPSRV_CQL_GET_VERSION);
uint32_t version = CASS_VERSION_MAJOR;
uint32_t minor = CASS_VERSION_MINOR;
return make_pair<uint32_t, uint32_t>(version, minor);
}
void
CqlConnection::commit() {
LOG_DEBUG(dhcpsrv_logger, DHCPSRV_DBG_TRACE_DETAIL, DHCPSRV_CQL_COMMIT);
......
......@@ -38,8 +38,12 @@ struct CqlTaggedStatement {
};
// Defines CQL backend version: 2.3
const uint32_t CQL_CURRENT_VERSION = CASS_VERSION_MAJOR;
const uint32_t CQL_CURRENT_MINOR = CASS_VERSION_MINOR;
const uint32_t CQL_DRIVER_VERSION_MAJOR = CASS_VERSION_MAJOR;
const uint32_t CQL_DRIVER_VERSION_MINOR = CASS_VERSION_MINOR;
/// Defines CQL schema version: 1.0
const uint32_t CQL_SCHEMA_VERSION_MAJOR = 1;
const uint32_t CQL_SCHEMA_VERSION_MINOR = 0;
class CqlConnection : public DatabaseConnection {
public:
......@@ -72,34 +76,6 @@ public:
/// @throw DbOpenError Error opening the database
void openDatabase();
/// @brief Return backend type
///
/// @return Type of the backend.
virtual std::string getType() const {
return (std::string("cql"));
}
/// @brief Returns name of the database.
///
/// @return database name
virtual std::string getName() const;
/// @brief Returns description of the backend.
///
/// This description may be multiline text that describes the backend.
///
/// @return Description of the backend.
virtual std::string getDescription() const;
/// @brief Returns backend version.
///
/// @return Version number as a pair of unsigned integers. "first" is the
/// major version number, "second" the minor number.
///
/// @throw isc::dhcp::DbOperationError An operation on the open database has
/// failed.
virtual std::pair<uint32_t, uint32_t> getVersion() const;
/// @brief Commit Transactions
///
/// Commits all pending database operations.
......
......@@ -429,34 +429,6 @@ CqlTaggedStatement CqlLeaseMgr::tagged_statements_[] = {
{ NULL, NULL, NULL }
};
class CqlExchange : public virtual SqlExchange {
public:
// Time conversion methods.
static void
convertToDatabaseTime(const time_t& cltt,
const uint32_t& valid_lifetime,
uint64_t& expire) {
// Calculate expiry time. Store it in the 64-bit value so as we can
// detect overflows.
int64_t expire_time = static_cast<int64_t>(cltt) +
static_cast<int64_t>(valid_lifetime);
if (expire_time > DatabaseConnection::MAX_DB_TIME) {
isc_throw(BadValue, "Time value is too large: " << expire_time);
}
expire = expire_time;
}
static void
convertFromDatabaseTime(const uint64_t& expire,
const uint32_t& valid_lifetime,
time_t& cltt) {
// Convert to local time
cltt = expire - static_cast<int64_t>(valid_lifetime);
}
};
/// @brief Common CQL and Lease Data Methods
///
/// The CqlLease4Exchange and CqlLease6Exchange classes provide the
......@@ -1154,8 +1126,8 @@ CqlLeaseMgr::~CqlLeaseMgr() {
std::string
CqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
tmp << "CQL backend " << CQL_CURRENT_VERSION;
tmp << "." << CQL_CURRENT_MINOR;
tmp << "CQL backend " << CQL_SCHEMA_VERSION_MAJOR;
tmp << "." << CQL_SCHEMA_VERSION_MINOR;
tmp << ", library " << "cassandra_static";
return (tmp.str());
}
......
......@@ -58,6 +58,38 @@ class CqlLeaseExchange;
class CqlLease4Exchange;
class CqlLease6Exchange;
/// @brief Cassandra Exchange
///
/// This class provides the basic conversion functions between Cassandra CQL and
/// base types.
class CqlExchange : public virtual SqlExchange {
public:
// Time conversion methods.
static void
convertToDatabaseTime(const time_t& cltt,
const uint32_t& valid_lifetime,
uint64_t& expire) {
// Calculate expiry time. Store it in the 64-bit value so as we can
// detect overflows.
int64_t expire_time = static_cast<int64_t>(cltt) +
static_cast<int64_t>(valid_lifetime);
if (expire_time > DatabaseConnection::MAX_DB_TIME) {
isc_throw(BadValue, "Time value is too large: " << expire_time);
}
expire = expire_time;
}
static void
convertFromDatabaseTime(const uint64_t& expire,
const uint32_t& valid_lifetime,
time_t& cltt) {
// Convert to local time
cltt = expire - static_cast<int64_t>(valid_lifetime);
}
};
/// @brief Cassandra Lease Manager
///
/// This class provides the \ref isc::dhcp::LeaseMgr interface to the Cassandra
......
......@@ -40,8 +40,8 @@ extern const int MLM_MYSQL_FETCH_FAILURE;
/// @name Current database schema version values.
//@{
const uint32_t CURRENT_VERSION_VERSION = 4;
const uint32_t CURRENT_VERSION_MINOR = 2;
const uint32_t MYSQL_SCHEMA_VERSION_MAJOR = 4;
const uint32_t MYSQL_SCHEMA_VERSION_MINOR = 2;
//@}
......
......@@ -1253,8 +1253,8 @@ MySqlLeaseMgr::~MySqlLeaseMgr() {
std::string
MySqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
tmp << "MySQL backend " << CURRENT_VERSION_VERSION;
tmp << "." << CURRENT_VERSION_MINOR;
tmp << "MySQL backend " << MYSQL_SCHEMA_VERSION_MAJOR;
tmp << "." << MYSQL_SCHEMA_VERSION_MINOR;
tmp << ", library " << mysql_get_client_info();
return (tmp.str());
}
......
......@@ -729,8 +729,8 @@ PgSqlLeaseMgr::~PgSqlLeaseMgr() {
std::string
PgSqlLeaseMgr::getDBVersion() {
std::stringstream tmp;
tmp << "PostgreSQL backend " << PG_CURRENT_VERSION;
tmp << "." << PG_CURRENT_MINOR;
tmp << "PostgreSQL backend " << PG_SCHEMA_VERSION_MAJOR;
tmp << "." << PG_SCHEMA_VERSION_MINOR;
tmp << ", library " << PQlibVersion();
return (tmp.str());
}
......
......@@ -142,36 +142,6 @@ TEST(CqlOpenTest, OpenDatabase) {
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
// Check that invalid login data causes an exception.
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, INVALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, VALID_NAME, INVALID_HOST, VALID_USER, VALID_PASSWORD)),
DbOpenError);
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
DbOpenError);
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, INVALID_PASSWORD)),
DbOpenError);
// Check for invalid timeouts
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_1)),
DbInvalidTimeout);
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD, INVALID_TIMEOUT_2)),
DbInvalidTimeout);
// Check for missing parameters
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
CQL_VALID_TYPE, NULL, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
NoDatabaseName);
// Tidy up after the test
destroyCqlSchema(false, true);
}
......@@ -217,8 +187,8 @@ TEST_F(CqlLeaseMgrTest, checkVersion) {
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
EXPECT_EQ(CQL_CURRENT_VERSION, version.first);
EXPECT_EQ(CQL_CURRENT_MINOR, version.second);
EXPECT_EQ(CQL_SCHEMA_VERSION_MAJOR, version.first);
EXPECT_EQ(CQL_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -116,7 +116,7 @@ TEST(MySqlOpenTest, OpenDatabase) {
// Check that lease manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
string connection_string = validMySQLConnectionString() + string(" ") +
string connection_string = validMySQLConnectionString() + string(" ") +
string(VALID_TIMEOUT);
LeaseMgrFactory::create(connection_string);
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
......@@ -231,8 +231,8 @@ TEST_F(MySqlLeaseMgrTest, checkVersion) {
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
EXPECT_EQ(CURRENT_VERSION_VERSION, version.first);
EXPECT_EQ(CURRENT_VERSION_MINOR, version.second);
EXPECT_EQ(MYSQL_SCHEMA_VERSION_MAJOR, version.first);
EXPECT_EQ(MYSQL_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -190,8 +190,8 @@ TEST_F(PgSqlLeaseMgrTest, checkVersion) {
// Check version
pair<uint32_t, uint32_t> version;
ASSERT_NO_THROW(version = lmptr_->getVersion());
EXPECT_EQ(PG_CURRENT_VERSION, version.first);
EXPECT_EQ(PG_CURRENT_MINOR, version.second);
EXPECT_EQ(PG_SCHEMA_VERSION_MAJOR, version.first);
EXPECT_EQ(PG_SCHEMA_VERSION_MINOR, version.second);
}
////////////////////////////////////////////////////////////////////////////////
......@@ -403,4 +403,3 @@ TEST_F(PgSqlLeaseMgrTest, getExpiredLeases6) {
}
}; // namespace
SUBDIRS = .
sqlscriptsdir = ${datarootdir}/${PACKAGE_NAME}/scripts/cql
sqlscripts_DATA = dhcpdb_create.cql dhcpdb_drop.cql
sqlscripts_DATA = dhcpdb_create.cql
sqlscripts_DATA += dhcpdb_drop.cql
EXTRA_DIST = ${sqlscripts_DATA}
Markdown is supported
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