diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-02 01:42:13 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2015-06-02 01:42:13 +0100 |
commit | 2d4b1c02d4b95590ca1571592d142d31e70d441b (patch) | |
tree | 33234fdd015270d4495fe10f5620020f923a9460 | |
parent | Add tests over MySQL bulk load and read (diff) | |
download | project2-2d4b1c02d4b95590ca1571592d142d31e70d441b.tar.bz2 project2-2d4b1c02d4b95590ca1571592d142d31e70d441b.tar.xz project2-2d4b1c02d4b95590ca1571592d142d31e70d441b.zip |
Prebuild (once) SQL for cursor operations.
Don't open another transaction.
Don't make another fetch to the DB if the previous read was short
anyway.
Add bulk load and bulk read tests.
-rw-r--r-- | project2/sql/unittests/pqschema.sql | 4 | ||||
-rw-r--r-- | project2/sql/unittests/testpq.cpp | 53 |
2 files changed, 57 insertions, 0 deletions
diff --git a/project2/sql/unittests/pqschema.sql b/project2/sql/unittests/pqschema.sql index b0581ab..2c7e94a 100644 --- a/project2/sql/unittests/pqschema.sql +++ b/project2/sql/unittests/pqschema.sql @@ -31,3 +31,7 @@ AS $tag$ WHERE string != 'complex '' string;'; $tag$; +CREATE TABLE bulktest( + id int, + string text); + diff --git a/project2/sql/unittests/testpq.cpp b/project2/sql/unittests/testpq.cpp index 0890bee..da38a34 100644 --- a/project2/sql/unittests/testpq.cpp +++ b/project2/sql/unittests/testpq.cpp @@ -9,6 +9,7 @@ #include <sql-modPQ.h> #include "testCore.h" #include <sqlHandleAsVariableType.h> +#include <fstream> class StandardMockDatabase : public MockPqDatabase { public: @@ -61,6 +62,17 @@ BOOST_AUTO_TEST_CASE( bindAndSend ) template<typename T> void +assertColumnValueHelper(DB::SelectCommand & sel, const T & t) +{ + while (sel.fetch()) { + HandleAsVariableType h; + sel[0].apply(h); + BOOST_REQUIRE_EQUAL(t, h.variable.as<T>()); + } +} + +template<typename T> +void assertColumnValueHelper(DB::SelectCommand & sel, unsigned int col, const T & t) { HandleAsVariableType h; @@ -130,5 +142,46 @@ BOOST_AUTO_TEST_CASE( testP2MockScriptDir ) ds->close(); } +BOOST_AUTO_TEST_CASE( bulkload ) +{ + RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("pqmock"); + auto ro = ds->getReadonly(); + + auto count = ro->newSelectCommand("SELECT COUNT(*) FROM bulktest"); + // Test empty + ro->beginBulkUpload("bulktest", ""); + ro->endBulkUpload(NULL); + assertColumnValueHelper(*count, 0); + // Test sample file + ro->beginBulkUpload("bulktest", ""); + std::ifstream in((RootDir / "bulk.sample").string()); + if (!in.good()) throw std::runtime_error("Couldn't open bulk.sample"); + char buf[BUFSIZ]; + for (std::streamsize r; (r = in.readsome(buf, sizeof(buf))) > 0; ) { + ro->bulkUploadData(buf, r); + } + ro->endBulkUpload(NULL); + assertColumnValueHelper(*count, 800); + + delete count; + ds->close(); +} + +BOOST_AUTO_TEST_CASE( bigIterate ) +{ + RdbmsDataSource * ds = CommonObjects::dataSource<RdbmsDataSource>("pqmock"); + auto ro = ds->getReadonly(); + + auto count = ro->newSelectCommand("SELECT * FROM bulktest"); + unsigned int rows = 0; + while (count->fetch()) { + rows += 1; + } + BOOST_REQUIRE_EQUAL(800, rows); + + delete count; + ds->close(); +} + BOOST_AUTO_TEST_SUITE_END(); |