Merge lp:~trond-norbye/libmemcached/ascii_test_mget into lp:~brianaker/libmemcached/build

Proposed by Trond Norbye
Status: Merged
Merged at revision: 847
Proposed branch: lp:~trond-norbye/libmemcached/ascii_test_mget
Merge into: lp:~brianaker/libmemcached/build
Diff against target: 126 lines (+82/-13)
1 file modified
clients/memcapable.c (+82/-13)
To merge this branch: bzr merge lp:~trond-norbye/libmemcached/ascii_test_mget
Reviewer Review Type Date Requested Status
Libmemcached-developers Pending
Review via email: mp+27329@code.launchpad.net

Description of the change

memcapable should verify that mget return the correct set of items, not the order they are returned in.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'clients/memcapable.c'
--- clients/memcapable.c 2010-06-05 19:17:33 +0000
+++ clients/memcapable.c 2010-06-11 08:05:42 +0000
@@ -9,7 +9,6 @@
9 *9 *
10 */10 */
1111
12/* -*- Mode: C; tab-width: 2; c-basic-offset: 2; indent-tabs-mode: nil -*- */
13#undef NDEBUG12#undef NDEBUG
14#include "config.h"13#include "config.h"
15#include <pthread.h>14#include <pthread.h>
@@ -1297,6 +1296,42 @@
1297 return test_ascii_add_impl("test_ascii_add_noreply", true);1296 return test_ascii_add_impl("test_ascii_add_noreply", true);
1298}1297}
12991298
1299static enum test_return ascii_get_unknown_value(char **key, char **value,
1300 ssize_t *ndata)
1301{
1302 char buffer[1024];
1303
1304 execute(receive_line(buffer, sizeof(buffer)));
1305 verify(strncmp(buffer, "VALUE ", 6) == 0);
1306 char *end = strchr(buffer + 6, ' ');
1307 verify(end != NULL);
1308 *end = '\0';
1309 *key = strdup(buffer + 6);
1310 verify(*key != NULL);
1311 char *ptr= end + 1;
1312
1313 unsigned long val= strtoul(ptr, &end, 10); /* flags */
1314 verify(ptr != end);
1315 verify(val == 0);
1316 verify(end != NULL);
1317 *ndata = strtoul(end, &end, 10); /* size */
1318 verify(ptr != end);
1319 verify(end != NULL);
1320 while (*end != '\n' && isspace(*end))
1321 ++end;
1322 verify(*end == '\n');
1323
1324 *value = malloc(*ndata);
1325 verify(*value != NULL);
1326
1327 execute(retry_read(*value, *ndata));
1328
1329 execute(retry_read(buffer, 2));
1330 verify(memcmp(buffer, "\r\n", 2) == 0);
1331
1332 return TEST_PASS;
1333}
1334
1300static enum test_return ascii_get_value(const char *key, const char *value)1335static enum test_return ascii_get_value(const char *key, const char *value)
1301{1336{
13021337
@@ -1565,25 +1600,59 @@
15651600
1566static enum test_return test_ascii_mget(void)1601static enum test_return test_ascii_mget(void)
1567{1602{
1568 execute(ascii_set_item("test_ascii_mget1", "value"));1603 const int nkeys= 5;
1569 execute(ascii_set_item("test_ascii_mget2", "value"));1604 const char * const keys[]= {
1570 execute(ascii_set_item("test_ascii_mget3", "value"));1605 "test_ascii_mget1",
1571 execute(ascii_set_item("test_ascii_mget4", "value"));1606 "test_ascii_mget2",
1572 execute(ascii_set_item("test_ascii_mget5", "value"));1607 /* test_ascii_mget_3 does not exist :) */
15731608 "test_ascii_mget4",
1609 "test_ascii_mget5",
1610 "test_ascii_mget6"
1611 };
1612
1613
1614 for (int x= 0; x < nkeys; ++x)
1615 execute(ascii_set_item(keys[x], "value"));
1616
1617 /* Ask for a key that doesn't exist as well */
1574 execute(send_string("get test_ascii_mget1 test_ascii_mget2 test_ascii_mget3 "1618 execute(send_string("get test_ascii_mget1 test_ascii_mget2 test_ascii_mget3 "
1575 "test_ascii_mget4 test_ascii_mget5 "1619 "test_ascii_mget4 test_ascii_mget5 "
1576 "test_ascii_mget6\r\n"));1620 "test_ascii_mget6\r\n"));
1577 execute(ascii_get_value("test_ascii_mget1", "value"));1621
1578 execute(ascii_get_value("test_ascii_mget2", "value"));1622 char* returned[nkeys];
1579 execute(ascii_get_value("test_ascii_mget3", "value"));1623
1580 execute(ascii_get_value("test_ascii_mget4", "value"));1624 for (int x= 0; x < nkeys; ++x)
1581 execute(ascii_get_value("test_ascii_mget5", "value"));1625 {
1626 ssize_t nbytes;
1627 char *v;
1628 execute(ascii_get_unknown_value(&returned[x], &v, &nbytes));
1629 verify(nbytes == 5);
1630 verify(memcmp(v, "value", 5) == 0);
1631 free(v);
1632 }
15821633
1583 char buffer[5];1634 char buffer[5];
1584 execute(retry_read(buffer, 5));1635 execute(retry_read(buffer, 5));
1585 verify(memcmp(buffer, "END\r\n", 5) == 0);1636 verify(memcmp(buffer, "END\r\n", 5) == 0);
1586 return TEST_PASS;1637
1638 /* verify that we got all the keys we expected */
1639 for (int x= 0; x < nkeys; ++x)
1640 {
1641 bool found= false;
1642 for (int y= 0; y < nkeys; ++y) {
1643 if (strcmp(keys[x], returned[y]) == 0)
1644 {
1645 found = true;
1646 break;
1647 }
1648 }
1649 verify(found);
1650 }
1651
1652 for (int x= 0; x < nkeys; ++x)
1653 free(returned[x]);
1654
1655 return TEST_PASS;
1587}1656}
15881657
1589static enum test_return test_ascii_incr_impl(const char* key, bool noreply)1658static enum test_return test_ascii_incr_impl(const char* key, bool noreply)

Subscribers

People subscribed via source and target branches

to all changes: