diff options
author | Sean Bright <sean@malleable.com> | 2012-10-01 20:36:25 +0000 |
---|---|---|
committer | Sean Bright <sean@malleable.com> | 2012-10-01 20:36:25 +0000 |
commit | b9eeff1521cb1c0d479761dfa17cf88d19cd7bf7 (patch) | |
tree | a554bc0a54a608da5a41a4763e7aec082304e724 /tests/test_db.c | |
parent | b3c739a8424720bc63e15faebc8e6ffe15944294 (diff) |
app_queue: Support persisting and loading of long member lists.
Greenlight in #asterisk brought up that he was receiving an error message "Could
not create persistent member string, out of space" when running app_queue in
Asterisk 10. dump_queue_members() made an assumption that 8K would be enough to
store the generated string, but with queues that have large member lists this is
not always the case. This patch removes the limitation and uses ast_str instead
of a fixed sized buffer.
The complicating factor comes from the fact that ast_db_get requires a buffer
and buffer size argument, which doesn't let us pull back more than what we pass
in, so I introduced a new ast_db_get_allocated() which returns an ast_strdup()'d
copy of the value from astdb.
As an aside, I did some testing on the maximum size of data that we can store in
the BDB library we distribute and was able to store a 10MB string and retrieve
it with no problems, so I feel this is a safe patch.
Review: https://reviewboard.asterisk.org/r/2136/
........
Merged revisions 374108 from http://svn.asterisk.org/svn/asterisk/branches/1.8
........
Merged revisions 374135 from http://svn.asterisk.org/svn/asterisk/branches/10
........
Merged revisions 374150 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@374151 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_db.c')
-rw-r--r-- | tests/test_db.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/tests/test_db.c b/tests/test_db.c index 1bd69f0c1..9e1b5cb60 100644 --- a/tests/test_db.c +++ b/tests/test_db.c @@ -232,11 +232,70 @@ AST_TEST_DEFINE(perftest) return res; } + +AST_TEST_DEFINE(put_get_long) +{ + int res = AST_TEST_PASS; + struct ast_str *s; + int i, j; + +#define STR_FILL_32 "abcdefghijklmnopqrstuvwxyz123456" + + switch (cmd) { + case TEST_INIT: + info->name = "put_get_long"; + info->category = "/main/astdb/"; + info->summary = "ast_db_(put|get_allocated) unit test"; + info->description = + "Ensures that the ast_db_put and ast_db_get_allocated functions work"; + return AST_TEST_NOT_RUN; + case TEST_EXECUTE: + break; + } + + if (!(s = ast_str_create(4096))) { + return AST_TEST_FAIL; + } + + for (i = 1024; i <= 1024 * 1024 * 8; i *= 2) { + char *out = NULL; + + ast_str_reset(s); + + for (j = 0; j < i; j += sizeof(STR_FILL_32) - 1) { + ast_str_append(&s, 0, "%s", STR_FILL_32); + } + + if (ast_db_put("astdbtest", "long", ast_str_buffer(s))) { + ast_test_status_update(test, "Failed to put value of %zu bytes\n", ast_str_strlen(s)); + res = AST_TEST_FAIL; + } else if (ast_db_get_allocated("astdbtest", "long", &out)) { + ast_test_status_update(test, "Failed to get value of %zu bytes\n", ast_str_strlen(s)); + res = AST_TEST_FAIL; + } else if (strcmp(ast_str_buffer(s), out)) { + ast_test_status_update(test, "Failed to match value of %zu bytes\n", ast_str_strlen(s)); + res = AST_TEST_FAIL; + } else if (ast_db_del("astdbtest", "long")) { + ast_test_status_update(test, "Failed to delete astdbtest/long\n"); + res = AST_TEST_FAIL; + } + + if (out) { + ast_free(out); + } + } + + ast_free(s); + + return res; +} + static int unload_module(void) { AST_TEST_UNREGISTER(put_get_del); AST_TEST_UNREGISTER(gettree_deltree); AST_TEST_UNREGISTER(perftest); + AST_TEST_UNREGISTER(put_get_long); return 0; } @@ -245,6 +304,7 @@ static int load_module(void) AST_TEST_REGISTER(put_get_del); AST_TEST_REGISTER(gettree_deltree); AST_TEST_REGISTER(perftest); + AST_TEST_REGISTER(put_get_long); return AST_MODULE_LOAD_SUCCESS; } |