Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/api_tst.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ ${TESTSBUILDDIR}/cdb2api_string_escape
[[ $? -ne 0 ]] && echo "cdb2api_string_escape - fail" && exit 1
echo 'cdb2api_string_escape - pass'

if [[ -n "$CLUSTER" ]]; then
CDB2_HOST_NAME=$(${CDB2SQL_EXE} ${CDB2_OPTIONS} -tabs -s ${db} ${tier} "select comdb2_host()")
CDB2_CLASS=$(${CDB2SQL_EXE} ${CDB2_OPTIONS} -tabs -s ${db} ${tier} "select comdb2_sysinfo('class')")
${TESTSBUILDDIR}/cdb2api_direct ${DBNAME} ${CDB2_CLASS} ${CDB2_HOST_NAME}
[[ $? -ne 0 ]] && echo "cdb2api_direct - fail" && exit 1
fi

echo 'cdb2api_direct - pass'

${TESTSBUILDDIR}/cdb2api_txn ${DBNAME}
[[ $? -ne 0 ]] && echo "cdb2api_txn - fail" && exit 1
echo 'cdb2api_txn - pass'
Expand Down
1 change: 1 addition & 0 deletions tests/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_exe(cdb2api_admin cdb2api_admin.cpp)
add_exe(cdb2api_caller cdb2api_caller.cpp)
add_exe(cdb2api_cfg cdb2api_cfg.cpp)
add_exe(cdb2api_chunk cdb2api_chunk.cpp)
add_exe(cdb2api_direct cdb2api_direct.cpp)
add_exe(cdb2api_drain cdb2api_drain.cpp)
add_exe(cdb2api_effects_on_chunk_error cdb2api_effects_on_chunk_error.c)
add_exe(cdb2api_enforce_timeout cdb2api_enforce_timeout.cpp)
Expand Down
91 changes: 91 additions & 0 deletions tests/tools/cdb2api_direct.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#undef NDEBUG
#include <assert.h>
#include <cstdio>
#include <signal.h>
#include <string.h>

#include <cdb2api.h>

#include <iostream>

static void test(const char *dbname, const char *type, int flag)
{
int rc;
cdb2_hndl_tp *hndl = NULL;

rc = cdb2_open(&hndl, dbname, type, flag);
if (rc != 0) {
std::cerr << "cdb2_open failed rc=" << rc << " " << cdb2_errstr(hndl) << std::endl;
assert(rc == 0);
}

rc = cdb2_run_statement(hndl, "select comdb2_dbname(), comdb2_host(), comdb2_sysinfo('class')");
assert(rc == 0);

rc = cdb2_next_record(hndl);
assert(rc == CDB2_OK);

const char *col_dbname = (char *)cdb2_column_value(hndl, 0);
assert(strcmp(col_dbname, dbname) == 0);

if (flag == CDB2_DIRECT_CPU) {
const char *host = (char *)cdb2_column_value(hndl, 1);
std::cout << "Host: " << host << std::endl;
assert(strcmp(host, type) == 0);
} else {
const char *cluster = (char *)cdb2_column_value(hndl, 2);
assert(strcmp(cluster, type) == 0);
}

rc = cdb2_next_record(hndl);
assert(rc == CDB2_OK_DONE);

rc = cdb2_close(hndl);
assert(rc == 0);
}

static void load_cfg(const char *db, const char *tier)
{
cdb2_hndl_tp *hndl = NULL;
int rc = cdb2_open(&hndl, db, tier, CDB2_RANDOM);
assert(rc == 0);
rc = cdb2_run_statement(hndl, "select 1");
assert(rc == 0);
rc = cdb2_next_record(hndl);
assert(rc == CDB2_OK);
rc = cdb2_next_record(hndl);
assert(rc == CDB2_OK_DONE);
rc = cdb2_close(hndl);
assert(rc == 0);
}

int main(int argc, char **argv)
{
if (argc < 4) {
std::cerr << "Usage: " << argv[0] << " <dbname> <tier> <hostname>" << std::endl;
return 1;
}

signal(SIGPIPE, SIG_IGN);

char *conf = getenv("CDB2_CONFIG");
if (conf)
cdb2_set_comdb2db_config(conf);

const char *dbname = argv[1];
const char *tier = argv[2];
const char *hostname = argv[3];

// Load config using default tier
load_cfg(dbname, tier);

// Test CDB2_DIRECT_CPU with hostname
test(dbname, hostname, CDB2_DIRECT_CPU);

// Test other flags with tier
test(dbname, tier, CDB2_RANDOM);
test(dbname, tier, CDB2_RANDOMROOM);
test(dbname, tier, CDB2_ROOM);

return 0;
}