Skip to content
Open
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
1 change: 1 addition & 0 deletions tests/consumer.test/runit
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if [ "$TESTCASE" == "consumer" ]; then
./t06.sh
./t07.sh
./t08.sh
./t10.sh
./cdb2api_drain.sh
fi
${TESTSROOTDIR}/tools/compare_results.sh -s -d $1
3 changes: 1 addition & 2 deletions tests/consumer.test/t08.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ $cdb2sql <<'EOF'
DROP LUA CONSUMER batch_consume;
DROP TABLE nt;
EOF
) 2>&1 | grep -v 'Terminated .*EXEC PROCEDURE batch_consume' > t08.output
set -x
) > t08.output
diff -q t08.output t08.expected
if [[ $? -ne 0 ]]; then
diff t08.output t08.expected | head -10
Expand Down
21 changes: 21 additions & 0 deletions tests/consumer.test/t10.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -x
tier="default"

dbname=$(${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} "select comdb2_dbname()")
cluster=$(${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} "select comdb2_sysinfo('cluster')")

# set up pingpong consumer

${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} 'create table if not exists pingpong (i int)'
${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} "create procedure pingpong version 'cdb2api_test' {local function main(a, b) local c = db:consumer() c:emit(a .. '-' .. b) end}"
${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} 'create lua consumer pingpong for (table pingpong on update)'
${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} 'drop table pingpong'

procout=$(${TESTSBUILDDIR}/cdb2api_base ${DBNAME} ${tier} "exec procedure pingpong($dbname, $cluster)")

if [[ "$procout" != "$dbname-$cluster" ]]; then
echo "consumer not emitting expected: $dbname-$cluster, got: $procout"
exit 1
fi
1 change: 1 addition & 0 deletions tests/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ add_exe(carray_insert carray_insert.c)
add_exe(cdb2_close_early cdb2_close_early.c)
add_exe(cdb2_open cdb2_open.c)
add_exe(cdb2api_admin cdb2api_admin.cpp)
add_exe(cdb2api_base cdb2api_base.c)
add_exe(cdb2api_caller cdb2api_caller.cpp)
add_exe(cdb2api_cfg cdb2api_cfg.cpp)
add_exe(cdb2api_chunk cdb2api_chunk.cpp)
Expand Down
39 changes: 39 additions & 0 deletions tests/tools/cdb2api_base.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#undef NDEBUG
#include <assert.h>
#include <signal.h>
#include <stdio.h>
#include <cdb2api.h>

int main(int argc, char **argv)
{
signal(SIGPIPE, SIG_IGN);
int rc;
cdb2_hndl_tp *hndl = NULL;

rc = cdb2_open(&hndl, argv[1], argv[2], 0);
assert(rc == 0);

rc = cdb2_run_statement(hndl, argv[3]);
if (rc != CDB2_OK) {
fprintf(stderr, "cdb2_run_statement failed: %s\n", cdb2_errstr(hndl));
return 1;
}

while ((rc = cdb2_next_record(hndl)) == CDB2_OK) {
const char *comma = "";
int columns = cdb2_numcolumns(hndl);
for (int i = 0; i < columns; ++i) {
switch (cdb2_column_type(hndl, i)) {
case CDB2_CSTRING: printf("%s%s", comma, (char *)cdb2_column_value(hndl, i)); break;
default: abort();
}
comma = ",";
}
}
assert(rc == CDB2_OK_DONE);

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

return 0;
}