mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 15:54:13 +08:00
mdbx-test: add data-check before delete/update.
Change-Id: I5afc1cbd95b5db0b442714229510d6786bf68d43
This commit is contained in:
parent
68fd9c9908
commit
01ae5bad7d
@ -114,6 +114,7 @@ bool testcase_hill::run() {
|
|||||||
log_trace("uphill: update-a (age %" PRIu64 "->0) %" PRIu64, age_shift,
|
log_trace("uphill: update-a (age %" PRIu64 "->0) %" PRIu64, age_shift,
|
||||||
a_serial);
|
a_serial);
|
||||||
generate_pair(a_serial, a_key, a_data_0, 0);
|
generate_pair(a_serial, a_key, a_data_0, 0);
|
||||||
|
checkdata("uphill: update-a", dbi, a_key->value, a_data_1->value);
|
||||||
rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_0->value,
|
rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_0->value,
|
||||||
&a_data_1->value, update_flags);
|
&a_data_1->value, update_flags);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
@ -126,6 +127,7 @@ bool testcase_hill::run() {
|
|||||||
|
|
||||||
// удаляем вторую запись
|
// удаляем вторую запись
|
||||||
log_trace("uphill: delete-b %" PRIu64, b_serial);
|
log_trace("uphill: delete-b %" PRIu64, b_serial);
|
||||||
|
checkdata("uphill: delete-b", dbi, b_key->value, b_data->value);
|
||||||
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
failure_perror("mdbx_del(b)", rc);
|
failure_perror("mdbx_del(b)", rc);
|
||||||
@ -158,6 +160,7 @@ bool testcase_hill::run() {
|
|||||||
a_serial);
|
a_serial);
|
||||||
generate_pair(a_serial, a_key, a_data_0, 0);
|
generate_pair(a_serial, a_key, a_data_0, 0);
|
||||||
generate_pair(a_serial, a_key, a_data_1, age_shift);
|
generate_pair(a_serial, a_key, a_data_1, age_shift);
|
||||||
|
checkdata("downhill: update-a", dbi, a_key->value, a_data_0->value);
|
||||||
int rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_1->value,
|
int rc = mdbx_replace(txn_guard.get(), dbi, &a_key->value, &a_data_1->value,
|
||||||
&a_data_0->value, update_flags);
|
&a_data_0->value, update_flags);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
@ -184,6 +187,7 @@ bool testcase_hill::run() {
|
|||||||
// удаляем первую запись
|
// удаляем первую запись
|
||||||
log_trace("downhill: delete-a (age %" PRIu64 ") %" PRIu64, age_shift,
|
log_trace("downhill: delete-a (age %" PRIu64 ") %" PRIu64, age_shift,
|
||||||
a_serial);
|
a_serial);
|
||||||
|
checkdata("downhill: delete-a", dbi, a_key->value, a_data_1->value);
|
||||||
rc = mdbx_del(txn_guard.get(), dbi, &a_key->value, &a_data_1->value);
|
rc = mdbx_del(txn_guard.get(), dbi, &a_key->value, &a_data_1->value);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
failure_perror("mdbx_del(a)", rc);
|
failure_perror("mdbx_del(a)", rc);
|
||||||
@ -195,6 +199,7 @@ bool testcase_hill::run() {
|
|||||||
|
|
||||||
// удаляем вторую запись
|
// удаляем вторую запись
|
||||||
log_trace("downhill: delete-b %" PRIu64, b_serial);
|
log_trace("downhill: delete-b %" PRIu64, b_serial);
|
||||||
|
checkdata("downhill: delete-b", dbi, b_key->value, b_data->value);
|
||||||
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
rc = mdbx_del(txn_guard.get(), dbi, &b_key->value, &b_data->value);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
failure_perror("mdbx_del(b)", rc);
|
failure_perror("mdbx_del(b)", rc);
|
||||||
|
10
test/test.cc
10
test/test.cc
@ -410,6 +410,16 @@ void testcase::db_table_close(MDBX_dbi handle) {
|
|||||||
log_trace("<< testcase::db_table_close");
|
log_trace("<< testcase::db_table_close");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testcase::checkdata(const char *step, MDBX_dbi handle, MDBX_val key,
|
||||||
|
MDBX_val expect) {
|
||||||
|
MDBX_val data = expect;
|
||||||
|
int rc = mdbx_get2(txn_guard.get(), handle, &key, &data);
|
||||||
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
failure_perror(step, rc);
|
||||||
|
if (!is_samedata(&data, &expect))
|
||||||
|
failure("%s data mismatch", step);
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool test_execute(const actor_config &config) {
|
bool test_execute(const actor_config &config) {
|
||||||
|
@ -112,6 +112,8 @@ protected:
|
|||||||
void fetch_canary();
|
void fetch_canary();
|
||||||
void update_canary(uint64_t increment);
|
void update_canary(uint64_t increment);
|
||||||
void kick_progress(bool active) const;
|
void kick_progress(bool active) const;
|
||||||
|
void checkdata(const char *step, MDBX_dbi handle, MDBX_val key,
|
||||||
|
MDBX_val expect);
|
||||||
|
|
||||||
MDBX_dbi db_table_open(bool create);
|
MDBX_dbi db_table_open(bool create);
|
||||||
void db_table_drop(MDBX_dbi handle);
|
void db_table_drop(MDBX_dbi handle);
|
||||||
|
@ -91,6 +91,11 @@ bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool is_samedata(const MDBX_val *a, const MDBX_val *b) {
|
||||||
|
return a->iov_len == b->iov_len &&
|
||||||
|
memcmp(a->iov_base, b->iov_base, a->iov_len) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
/* TODO: replace my 'libmera' from t1ha. */
|
/* TODO: replace my 'libmera' from t1ha. */
|
||||||
|
@ -317,7 +317,7 @@ struct simple_checksum {
|
|||||||
std::string data2hex(const void *ptr, size_t bytes, simple_checksum &checksum);
|
std::string data2hex(const void *ptr, size_t bytes, simple_checksum &checksum);
|
||||||
bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
|
bool hex2data(const char *hex_begin, const char *hex_end, void *ptr,
|
||||||
size_t bytes, simple_checksum &checksum);
|
size_t bytes, simple_checksum &checksum);
|
||||||
|
bool is_samedata(const MDBX_val *a, const MDBX_val *b);
|
||||||
std::string format(const char *fmt, ...);
|
std::string format(const char *fmt, ...);
|
||||||
|
|
||||||
uint64_t entropy_ticks(void);
|
uint64_t entropy_ticks(void);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user