Commit df16b6f0 authored by Andrei Pavel's avatar Andrei Pavel Committed by Tomek Mrugalski
Browse files

refactored cassandra backend and fixed minor issues

parent 74b0e917
/memfile_tests.sh
/mysql_tests.sh
/pgsql_tests.sh
/cql_tests.sh
......@@ -60,6 +60,36 @@
namespace isc {
namespace dhcp {
enum ExchangeDataType {
EXCHANGE_DATA_TYPE_NONE,
EXCHANGE_DATA_TYPE_BOOL,
EXCHANGE_DATA_TYPE_INT32,
EXCHANGE_DATA_TYPE_INT64,
EXCHANGE_DATA_TYPE_TIMESTAMP,
EXCHANGE_DATA_TYPE_STRING,
EXCHANGE_DATA_TYPE_BYTES
};
enum ExchangeDataTypeIO {
EXCHANGE_DATA_TYPE_IO_IN,
EXCHANGE_DATA_TYPE_IO_OUT,
EXCHANGE_DATA_TYPE_IO_IN_OUT
};
struct ExchangeColumnInfo {
ExchangeColumnInfo () : column_(NULL), type_io_(EXCHANGE_DATA_TYPE_IO_IN), type_(EXCHANGE_DATA_TYPE_NONE) {};
ExchangeColumnInfo (const char *column, ExchangeDataTypeIO type_io, ExchangeDataType type) : column_(column), type_io_(type_io), type_(type) {};
const char* column_;
ExchangeDataTypeIO type_io_;
ExchangeDataType type_;
};
class SqlExchange {
public:
SqlExchange () {};
virtual ~SqlExchange() {};
std::vector<ExchangeColumnInfo> parameters_; ///< Column names and types
};
/// @brief Abstract Lease Manager
///
/// This is an abstract API for lease database backends. It provides unified
......
......@@ -394,14 +394,19 @@ public:
hostname_ = getRawColumnValue(r, row, HOSTNAME_COL);
uint32_t state;
getColumnValue(r, row , STATE_COL, state);
HWAddrPtr hwaddr(new HWAddr(hwaddr_buffer_, hwaddr_length_,
HTYPE_ETHER));
return (Lease4Ptr(new Lease4(addr4_, hwaddr,
Lease4Ptr result(new Lease4(addr4_, hwaddr,
client_id_buffer_, client_id_length_,
valid_lifetime_, 0, 0, cltt_,
subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_)));
hostname_));
result->state_ = state;
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
"Could not convert data to Lease4, reason: "
......@@ -588,6 +593,9 @@ public:
hostname_ = getRawColumnValue(r, row, HOSTNAME_COL);
uint32_t state;
getColumnValue(r, row , STATE_COL, state);
/// @todo: implement this in #3557.
HWAddrPtr hwaddr;
......@@ -597,6 +605,7 @@ public:
subnet_id_, fqdn_fwd_, fqdn_rev_,
hostname_, hwaddr, prefix_len_));
result->cltt_ = cltt_;
result->state_ = state;
return (result);
} catch (const std::exception& ex) {
isc_throw(DbOperationError,
......
......@@ -101,7 +101,7 @@ TEST(CqlOpenTest, OpenDatabase) {
createCqlSchema(false, true);
// Check that lease manager open the database opens correctly and tidy up.
// If it fails, print the error message.
// If it fails, print the error message.
try {
LeaseMgrFactory::create(validCqlConnectionString());
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
......@@ -113,6 +113,21 @@ TEST(CqlOpenTest, OpenDatabase) {
<< "*** before the CQL tests will run correctly.\n";
}
// Check that lease manager open the database opens correctly with a longer
// timeout. If it fails, print the error message.
try {
string connection_string = validCqlConnectionString() + string(" ") +
string(VALID_TIMEOUT);
LeaseMgrFactory::create(connection_string);
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
LeaseMgrFactory::destroy();
} catch (const isc::Exception& ex) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
<< "*** The test environment is broken and must be fixed\n"
<< "*** before the CQL tests will run correctly.\n";
}
// Check that attempting to get an instance of the lease manager when
// none is set throws an exception.
EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager);
......@@ -123,6 +138,7 @@ TEST(CqlOpenTest, OpenDatabase) {
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
NULL, VALID_NAME, VALID_HOST, INVALID_USER, VALID_PASSWORD)),
InvalidParameter);
EXPECT_THROW(LeaseMgrFactory::create(connectionString(
INVALID_TYPE, VALID_NAME, VALID_HOST, VALID_USER, VALID_PASSWORD)),
InvalidType);
......@@ -131,16 +147,27 @@ TEST(CqlOpenTest, OpenDatabase) {
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)),
......
......@@ -69,7 +69,7 @@ public:
/// Closes the database and re-open it. Anything committed should be
/// visible.
///
/// Parameter is ignored for Postgres abckend as the v4 and v6 leases share
/// Parameter is ignored for Postgres backend as the v4 and v6 leases share
/// the same database.
void reopen(Universe) {
LeaseMgrFactory::destroy();
......@@ -93,7 +93,7 @@ TEST(PgSqlOpenTest, OpenDatabase) {
createPgSQLSchema(true);
// Check that lease manager open the database opens correctly and tidy up.
// If it fails, print the error message.
// If it fails, print the error message.
try {
LeaseMgrFactory::create(validPgSQLConnectionString());
EXPECT_NO_THROW((void) LeaseMgrFactory::instance());
......@@ -117,7 +117,7 @@ TEST(PgSqlOpenTest, OpenDatabase) {
FAIL() << "*** ERROR: unable to open database, reason:\n"
<< " " << ex.what() << "\n"
<< "*** The test environment is broken and must be fixed\n"
<< "*** before the MySQL tests will run correctly.\n";
<< "*** before the PostgreSQL tests will run correctly.\n";
}
// Check that attempting to get an instance of the lease manager when
......
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