add a unit test to check database rollback
check that a database rollback works and the correct (original) data is found on lookup.
This commit is contained in:
@@ -363,6 +363,154 @@ ISC_RUN_TEST_IMPL(getnsec3parameters) {
|
||||
db1, v2, &hash, &flags, &iterations, salt, &salt_length));
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that the correct node contents are found after a rollback.
|
||||
*/
|
||||
ISC_RUN_TEST_IMPL(rollback) {
|
||||
isc_result_t res;
|
||||
dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
|
||||
dns_rdataset_t input1 = DNS_RDATASET_INIT;
|
||||
dns_rdataset_t input2 = DNS_RDATASET_INIT;
|
||||
dns_rdataset_t rdataset1 = DNS_RDATASET_INIT;
|
||||
dns_rdataset_t rdataset2 = DNS_RDATASET_INIT;
|
||||
dns_rdatalist_t rdatalist1, rdatalist2;
|
||||
dns_rdata_t out1 = DNS_RDATA_INIT, out2 = DNS_RDATA_INIT;
|
||||
dns_dbnode_t *node = NULL;
|
||||
char *txt1 = (char *)"\006text 1";
|
||||
char *txt2 = (char *)"\006text 2";
|
||||
size_t len1 = strlen(txt1), len2 = strlen(txt2);
|
||||
char buf[1024];
|
||||
isc_buffer_t b;
|
||||
|
||||
UNUSED(state);
|
||||
|
||||
isc_buffer_init(&b, buf, sizeof(buf));
|
||||
|
||||
/* Set up two rdatasets to insert */
|
||||
rdata1.rdclass = dns_rdataclass_in;
|
||||
rdata1.type = dns_rdatatype_txt;
|
||||
rdata2 = rdata1;
|
||||
|
||||
rdata1.length = len1;
|
||||
rdata1.data = (unsigned char *)txt1;
|
||||
rdata2.length = len2;
|
||||
rdata2.data = (unsigned char *)txt2;
|
||||
|
||||
dns_rdatalist_init(&rdatalist1);
|
||||
rdatalist1.rdclass = dns_rdataclass_in;
|
||||
rdatalist1.type = dns_rdatatype_txt;
|
||||
rdatalist1.ttl = 3600;
|
||||
rdatalist2 = rdatalist1;
|
||||
|
||||
ISC_LIST_APPEND(rdatalist1.rdata, &rdata1, link);
|
||||
ISC_LIST_APPEND(rdatalist2.rdata, &rdata2, link);
|
||||
|
||||
dns_rdatalist_tordataset(&rdatalist1, &input1);
|
||||
dns_rdatalist_tordataset(&rdatalist2, &input2);
|
||||
|
||||
/* db1: Insert the first version ("text 1"), and commit */
|
||||
res = dns_db_findnode(db1, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_addrdataset(db1, node, v1, 0, &input1, 0, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_db_closeversion(db1, &v1, true); /* commit */
|
||||
assert_null(v1);
|
||||
dns_db_detachnode(db1, &node);
|
||||
assert_null(node);
|
||||
|
||||
/* db2: Insert the first version ("text 1"), and commit */
|
||||
res = dns_db_findnode(db2, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_addrdataset(db2, node, v2, 0, &input1, 0, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_db_closeversion(db2, &v2, true); /* commit */
|
||||
assert_null(v2);
|
||||
dns_db_detachnode(db2, &node);
|
||||
assert_null(node);
|
||||
|
||||
/* Reopen the versions */
|
||||
dns_db_newversion(db1, &v1);
|
||||
assert_non_null(v1);
|
||||
dns_db_newversion(db2, &v2);
|
||||
assert_non_null(v2);
|
||||
|
||||
/* db1: Insert the second version ("text 2"), and roll back */
|
||||
res = dns_db_findnode(db1, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_addrdataset(db1, node, v1, 0, &input2, 0, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_db_closeversion(db1, &v1, false); /* rollback */
|
||||
assert_null(v1);
|
||||
dns_db_detachnode(db1, &node);
|
||||
assert_null(node);
|
||||
|
||||
/* db2: Insert the second version ("text 2"), and commit */
|
||||
res = dns_db_findnode(db2, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_addrdataset(db2, node, v2, 0, &input2, 0, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_db_closeversion(db2, &v2, true); /* commit */
|
||||
assert_null(v2);
|
||||
dns_db_detachnode(db2, &node);
|
||||
assert_null(node);
|
||||
|
||||
/* db1: Look it up and check that the first version is found */
|
||||
dns_db_currentversion(db1, &v1);
|
||||
assert_non_null(v1);
|
||||
res = dns_db_findnode(db1, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_findrdataset(db1, node, v1, dns_rdatatype_txt, 0, 0,
|
||||
&rdataset1, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
|
||||
/* db1: Convert result to text */
|
||||
res = dns_rdataset_first(&rdataset1);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_rdataset_current(&rdataset1, &out1);
|
||||
|
||||
res = dns_rdata_totext(&out1, NULL, &b);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
isc_buffer_putuint8(&b, 0);
|
||||
|
||||
/* db1: We should have "text 1" */
|
||||
assert_string_equal(buf, "\"text 1\"");
|
||||
|
||||
dns_rdataset_disassociate(&rdataset1);
|
||||
|
||||
dns_db_closeversion(db1, &v1, true);
|
||||
assert_null(v1);
|
||||
dns_db_detachnode(db1, &node);
|
||||
assert_null(node);
|
||||
|
||||
/* db2: Look it up and check that the second version is found */
|
||||
dns_db_currentversion(db2, &v2);
|
||||
assert_non_null(v2);
|
||||
res = dns_db_findnode(db2, dns_rootname, true, &node);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
res = dns_db_findrdataset(db2, node, v2, dns_rdatatype_txt, 0, 0,
|
||||
&rdataset2, NULL);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
|
||||
/* db2: Convert result to text */
|
||||
res = dns_rdataset_first(&rdataset2);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
dns_rdataset_current(&rdataset2, &out2);
|
||||
isc_buffer_init(&b, buf, sizeof(buf));
|
||||
res = dns_rdata_totext(&out2, NULL, &b);
|
||||
assert_int_equal(res, ISC_R_SUCCESS);
|
||||
isc_buffer_putuint8(&b, 0);
|
||||
|
||||
/* db2: We should have "text 2" */
|
||||
assert_string_equal(buf, "\"text 2\"");
|
||||
|
||||
dns_rdataset_disassociate(&rdataset2);
|
||||
|
||||
dns_db_closeversion(db2, &v2, true);
|
||||
assert_null(v2);
|
||||
dns_db_detachnode(db2, &node);
|
||||
assert_null(node);
|
||||
}
|
||||
|
||||
ISC_TEST_LIST_START
|
||||
ISC_TEST_ENTRY_CUSTOM(find, setup_test, teardown_test)
|
||||
ISC_TEST_ENTRY_CUSTOM(allrdatasets, setup_test, teardown_test)
|
||||
@@ -373,6 +521,7 @@ ISC_TEST_ENTRY_CUSTOM(addrdataset, setup_test, teardown_test)
|
||||
ISC_TEST_ENTRY_CUSTOM(getnsec3parameters, setup_test, teardown_test)
|
||||
ISC_TEST_ENTRY_CUSTOM(attachversion, setup_test, teardown_test)
|
||||
ISC_TEST_ENTRY_CUSTOM(closeversion, setup_test, teardown_test)
|
||||
ISC_TEST_ENTRY_CUSTOM(rollback, setup_test, teardown_test)
|
||||
ISC_TEST_LIST_END
|
||||
|
||||
ISC_TEST_MAIN
|
||||
|
||||
Reference in New Issue
Block a user