#pragma once
/* This seems to be required for older compilers @note http://stackoverflow.com/questions/8132399/how-to-printf-uint64-t */
-#define __STDC_FORMAT_MACROS
+#ifndef __STDC_FORMAT_MACROS
+# define __STDC_FORMAT_MACROS
+#endif
#ifdef __cplusplus
# include <tr1/cinttypes>
uint64_t memcached_behavior_get(memcached_st *ptr,
const memcached_behavior_t flag)
{
- if (not ptr)
+ if (ptr == NULL)
{
return MEMCACHED_INVALID_ARGUMENTS;
}
return MEMCACHED_CONNECTION_FAILURE;
}
-static ssize_t _io_write(memcached_server_write_instance_st ptr,
- const void *buffer, size_t length, bool with_flush)
+static bool _io_write(memcached_server_write_instance_st ptr,
+ const void *buffer, size_t length, bool with_flush,
+ size_t& written)
{
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
assert(memcached_is_udp(ptr->root) == false);
- size_t original_length= length;
const char *buffer_ptr= static_cast<const char *>(buffer);
+ const size_t original_length= length;
+
while (length)
{
char *write_ptr;
memcached_return_t rc;
if (io_flush(ptr, with_flush, rc) == false)
{
- return -1;
+ written= original_length -length;
+ return false;
}
}
}
WATCHPOINT_ASSERT(ptr->fd != INVALID_SOCKET);
if (io_flush(ptr, with_flush, rc) == false)
{
- return -1;
+ written= original_length -length;
+ return false;
}
}
- return ssize_t(original_length);
+ written= original_length -length;
+
+ return true;
}
bool memcached_io_write(memcached_server_write_instance_st ptr)
{
- return (_io_write(ptr, NULL, 0, true) >= 0);
+ size_t written;
+ return _io_write(ptr, NULL, 0, true, written);
}
ssize_t memcached_io_write(memcached_server_write_instance_st ptr,
const void *buffer, const size_t length, const bool with_flush)
{
- return _io_write(ptr, buffer, length, with_flush);
+ size_t written;
+
+ if (_io_write(ptr, buffer, length, with_flush, written) == false)
+ {
+ return -1;
+ }
+
+ return ssize_t(written);
}
ssize_t memcached_io_writev(memcached_server_write_instance_st ptr,
for (size_t x= 0; x < number_of; x++, vector++)
{
- ssize_t returnable;
-
if (vector->length)
{
- if ((returnable= _io_write(ptr, vector->buffer, vector->length, false)) == -1)
+ size_t written;
+ if ((_io_write(ptr, vector->buffer, vector->length, false, written)) == false)
{
return -1;
}
- total+= returnable;
+ total+= written;
}
}
libtest_libtest_la_SOURCES+= libtest/server_container.cc
libtest_libtest_la_SOURCES+= libtest/signal.cc
libtest_libtest_la_SOURCES+= libtest/socket.cc
-libtest_libtest_la_SOURCES+= libtest/stream.cc
libtest_libtest_la_SOURCES+= libtest/strerror.cc
libtest_libtest_la_SOURCES+= libtest/timer.cc
libtest_libtest_la_SOURCES+= libtest/tmpfile.cc
+++ /dev/null
-/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
- *
- * Data Differential YATL (i.e. libtest) library
- *
- * Copyright (C) 2012 Data Differential, http://datadifferential.com/
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above
- * copyright notice, this list of conditions and the following disclaimer
- * in the documentation and/or other materials provided with the
- * distribution.
- *
- * * The names of its contributors may not be used to endorse or
- * promote products derived from this software without specific prior
- * written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- */
-
-#include <config.h>
-#include <libtest/stream.h>
-
-namespace libtest {
-namespace stream {
-
-namespace detail {
-
-} // namespace detail
-
-make_cerr::make_cerr(const char* filename, int line_number, const char* func) :
- log(std::cerr, filename, line_number, func)
-{ }
-
-cerr::cerr(const char* filename, int line_number, const char* func) :
- log(std::cout, filename, line_number, func)
- { }
-
-clog::clog(const char* filename, int line_number, const char* func) :
- log(std::clog, filename, line_number, func)
- { }
-
-cout::cout(const char* filename, int line_number, const char* func) :
- log(std::cout, filename, line_number, func)
- { }
-
-} // namespace stream
-} // namespace libtest
class make_cerr : public detail::log<detail::channelln> {
public:
- make_cerr(const char* filename, int line_number, const char* func);
+ make_cerr(const char* filename, int line_number, const char* func) :
+ detail::log<detail::channelln>(std::cerr, filename, line_number, func)
+ { }
};
class cerr : public detail::log<detail::channel> {
public:
- cerr(const char* filename, int line_number, const char* func);
+ cerr(const char* filename, int line_number, const char* func) :
+ detail::log<detail::channel>(std::cout, filename, line_number, func)
+ { }
};
class clog : public detail::log<detail::channel> {
public:
- clog(const char* filename, int line_number, const char* func);
+ clog(const char* filename, int line_number, const char* func) :
+ detail::log<detail::channel>(std::clog, filename, line_number, func)
+ { }
};
class cout : public detail::log<detail::channel> {
public:
- cout(const char* filename, int line_number, const char* func);
+ cout(const char* filename, int line_number, const char* func) :
+ detail::log<detail::channel>(std::cout, filename, line_number, func)
+ { }
};
AH_BOTTOM([
-#define __STDC_FORMAT_MACROS
+#ifndef __STDC_FORMAT_MACROS
+# define __STDC_FORMAT_MACROS
+#endif
#if defined(__cplusplus)
# include CINTTYPES_H
test_return_t check_replication_sanity_TEST(memcached_st *memc)
{
test_true(memc);
- test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+ test_compare(uint64_t(1),
+ memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
/*
* Make sure that we store the item on all servers
test_return_t replication_set_test(memcached_st *memc)
{
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
- memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ test_true(memc_clone);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0));
test_compare(MEMCACHED_SUCCESS,
memcached_set(memc, "bubba", 5, "0", 1, 0, 0));
const char key[2]= { (char)x, 0 };
size_t len;
uint32_t flags;
+ memcached_return_t rc;
char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_return_t replication_get_test(memcached_st *memc)
{
- memcached_return_t rc;
/*
* Don't do the following in your code. I am abusing the internal details
const char key[2]= { (char)x, 0 };
size_t len;
uint32_t flags;
+ memcached_return_t rc;
char *val= memcached_get_by_key(memc_clone, key, 1, "bubba", 5,
&len, &flags, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_return_t replication_mget_test(memcached_st *memc)
{
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
- memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0);
+ test_true(memc_clone);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 0));
const char *keys[]= { "bubba", "key1", "key2", "key3" };
size_t len[]= { 5, 4, 4, 4 };
for (size_t x= 0; x< 4; ++x)
{
- rc= memcached_set(memc, keys[x], len[x], "0", 1, 0, 0);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS, memcached_set(memc, keys[x], len[x], "0", 1, 0, 0));
}
/*
{
char key[2]= { (char)x, 0 };
- rc= memcached_mget_by_key(new_clone, key, 1, keys, len, 4);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_mget_by_key(new_clone, key, 1, keys, len, 4));
memcached_result_st *results= memcached_result_create(new_clone, &result_obj);
test_true(results);
int hits= 0;
+ memcached_return_t rc;
while ((results= memcached_fetch_result(new_clone, &result_obj, &rc)) != NULL)
{
hits++;
test_return_t replication_randomize_mget_test(memcached_st *memc)
{
memcached_result_st result_obj;
- memcached_return_t rc;
memcached_st *memc_clone= memcached_clone(NULL, memc);
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_NUMBER_OF_REPLICAS, 3);
memcached_behavior_set(memc_clone, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, 1);
for (size_t x= 0; x< 7; ++x)
{
- rc= memcached_set(memc, keys[x], len[x], "1", 1, 0, 0);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS,
+ memcached_set(memc, keys[x], len[x], "1", 1, 0, 0));
}
memcached_quit(memc);
test_true(results);
int hits= 0;
+ memcached_return_t rc;
while ((results= memcached_fetch_result(memc_clone, &result_obj, &rc)) != NULL)
{
++hits;
memcached_result_free(&result_obj);
}
memcached_free(memc_clone);
+
return TEST_SUCCESS;
}
memcached_st *memc_replicated= memcached_clone(NULL, memc_just_cloned);
const char *keys[]= { "bubba", "key1", "key2", "key3", "key4" };
- test_true(memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
+ test_compare(uint64_t(1), memcached_behavior_get(memc_replicated, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL));
test_compare(MEMCACHED_SUCCESS, memcached_behavior_set(memc_replicated, MEMCACHED_BEHAVIOR_RANDOMIZE_REPLICA_READ, false));
// Make one copy
for (int x= int(MEMCACHED_SUCCESS); x < int(MEMCACHED_MAXIMUM_RETURN); ++x)
{
const char *key= memcached_strerror(NULL, memcached_return_t(x));
- memcached_return_t rc;
uint32_t flags;
size_t value_length;
+ memcached_return_t rc;
char *value= memcached_get(memc_clone, key, strlen(key), &value_length, &flags, &rc);
- test_true(rc == MEMCACHED_SUCCESS);
+ test_compare(MEMCACHED_SUCCESS, rc);
test_compare(strlen(key), value_length);
test_strcmp(key, value);
free(value);