Skip to content

Commit

Permalink
bug 2443 - append+prepend fixes with binary data
Browse files Browse the repository at this point in the history
Change-Id: I121346bfa5e160fe56c7d0a23f11427ee5ea7db5
Reviewed-on: http://review.northscale.com/2616
Reviewed-by: Chiyoung Seo <chiyoung.seo@gmail.com>
Tested-by: Chiyoung Seo <chiyoung.seo@gmail.com>
  • Loading branch information
dustin authored and chiyoung committed Sep 21, 2010
1 parent 4eec46e commit 0e3f67f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
48 changes: 48 additions & 0 deletions ep_testsuite.cc
Expand Up @@ -600,6 +600,52 @@ static enum test_result test_incr_default(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1
return check_key_value(h, h1, "key", "3\r\n", 3);
}

static enum test_result test_append(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *i = NULL;

char binaryData1[] = "abcdefg\0gfedcba";
char binaryData2[] = "abzdefg\0gfedcba";

check(storeCasVb11(h, h1, NULL, OPERATION_SET, "key",
binaryData1, sizeof(binaryData1), 82758, &i, 0, 0)
== ENGINE_SUCCESS,
"Failed set.");

check(storeCasVb11(h, h1, NULL, OPERATION_APPEND, "key",
binaryData2, sizeof(binaryData2), 82758, &i, 0, 0)
== ENGINE_SUCCESS,
"Failed append.");

std::string expected;
expected.append(binaryData1, sizeof(binaryData1));
expected.append(binaryData2, sizeof(binaryData2));

return check_key_value(h, h1, "key", expected.data(), expected.length());
}

static enum test_result test_prepend(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
item *i = NULL;

char binaryData1[] = "abcdefg\0gfedcba";
char binaryData2[] = "abzdefg\0gfedcba";

check(storeCasVb11(h, h1, NULL, OPERATION_SET, "key",
binaryData1, sizeof(binaryData1), 82758, &i, 0, 0)
== ENGINE_SUCCESS,
"Failed set.");

check(storeCasVb11(h, h1, NULL, OPERATION_PREPEND, "key",
binaryData2, sizeof(binaryData2), 82758, &i, 0, 0)
== ENGINE_SUCCESS,
"Failed append.");

std::string expected;
expected.append(binaryData2, sizeof(binaryData2));
expected.append(binaryData1, sizeof(binaryData1));

return check_key_value(h, h1, "key", expected.data(), expected.length());
}

static enum test_result test_incr(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1) {
uint64_t cas = 0, result = 0;
item *i = NULL;
Expand Down Expand Up @@ -2221,6 +2267,8 @@ engine_test_t* get_tests(void) {
{"set+change flags", test_set_change_flags, NULL, teardown, NULL},
{"add", test_add, NULL, teardown, NULL},
{"cas", test_cas, NULL, teardown, NULL},
{"append", test_append, NULL, teardown, NULL},
{"prepend", test_prepend, NULL, teardown, NULL},
{"replace", test_replace, NULL, teardown, NULL},
{"incr miss", test_incr_miss, NULL, teardown, NULL},
{"incr", test_incr, NULL, teardown, NULL},
Expand Down
4 changes: 2 additions & 2 deletions item.hh
Expand Up @@ -205,7 +205,7 @@ public:
* @return true if success
*/
bool append(const Item &item) {
std::string newValue(value->getData(), 0, value->length() - 2);
std::string newValue(value->getData(), value->length());
newValue.append(item.getValue()->to_s());
value.reset(Blob::New(newValue));
return true;
Expand All @@ -218,7 +218,7 @@ public:
* @return true if success
*/
bool prepend(const Item &item) {
std::string newValue(item.getValue()->to_s(), 0, item.getNBytes() - 2);
std::string newValue(item.getValue()->to_s());
newValue.append(value->to_s());
value.reset(Blob::New(newValue));
return true;
Expand Down

0 comments on commit 0e3f67f

Please sign in to comment.