Ejemplo n.º 1
0
static test_return_t udp_delete_test(memcached_st *memc)
{
    unsigned int num_iters= 1025; //request id rolls over at 1024

    for (size_t x= 0; x < num_iters; x++)
    {
        memcached_return_t rc;
        const char *key= "foo";
        uint16_t *expected_ids=get_udp_request_ids(memc);
        unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
        memcached_server_instance_st instance=
            memcached_server_instance_by_position(memc, server_key);
        size_t init_offset= instance->write_buffer_offset;

        rc= memcached_delete(memc, key, strlen(key), 0);
        test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);

        if (rc == MEMCACHED_SUCCESS || instance->write_buffer_offset < init_offset)
            increment_request_id(&expected_ids[server_key]);
        if (rc == MEMCACHED_SUCCESS)
        {
            test_true(instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
        }
        else
        {
            test_true(instance->write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
            test_true(instance->write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
        }
        test_true(post_udp_op_check(memc,expected_ids) == TEST_SUCCESS);
    }
    return TEST_SUCCESS;
}
Ejemplo n.º 2
0
/**
  @note This should be testing to see if the server really supports the binary protocol.
*/
static test_return_t pre_binary(memcached_st *memc)
{
    memcached_return_t rc= MEMCACHED_FAILURE;
    memcached_st *memc_clone;
    memcached_server_instance_st instance;

    memc_clone= memcached_clone(NULL, memc);
    test_true(memc_clone);
    // The memcached_version needs to be done on a clone, because the server
    // will not toggle protocol on an connection.
    memcached_version(memc_clone);

    instance= memcached_server_instance_by_position(memc_clone, 0);

    if (instance->major_version >= 1 && instance->minor_version > 2)
    {
        rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
        test_true(rc == MEMCACHED_SUCCESS);
        test_true(memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL) == 1);
    }

    memcached_free(memc_clone);

    return rc == MEMCACHED_SUCCESS ? TEST_SUCCESS : TEST_SKIPPED;
}
Ejemplo n.º 3
0
/*
  Set the value, then quit to make sure it is flushed.
  Come back in and test that add fails.
*/
static test_return_t add_test(memcached_st *memc)
{
  memcached_return_t rc;
  const char *key= "foo";
  const char *value= "when we sanitize";
  unsigned long long setting_value;

  setting_value= memcached_behavior_get(memc, MEMCACHED_BEHAVIOR_NO_BLOCK);

  rc= memcached_set(memc, key, strlen(key),
                    value, strlen(value),
                    (time_t)0, (uint32_t)0);
  test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
  memcached_quit(memc);
  rc= memcached_add(memc, key, strlen(key),
                    value, strlen(value),
                    (time_t)0, (uint32_t)0);

  /* Too many broken OS'es have broken loopback in async, so we can't be sure of the result */
  if (setting_value)
  {
    test_true(rc == MEMCACHED_NOTSTORED || rc == MEMCACHED_STORED);
  }
  else
  {
    test_true(rc == MEMCACHED_NOTSTORED);
  }

  return 0;
}
Ejemplo n.º 4
0
static test_return_t udp_get_test(memcached_st *memc)
{
    memcached_return_t rc;
    const char *key= "foo";
    size_t vlen;
    uint16_t *expected_ids = get_udp_request_ids(memc);
    char *val= memcached_get(memc, key, strlen(key), &vlen, (uint32_t)0, &rc);
    test_true(rc == MEMCACHED_NOT_SUPPORTED);
    test_true(val == NULL);
    return post_udp_op_check(memc, expected_ids);
}
Ejemplo n.º 5
0
static test_return_t pre_allocate(memcached_st *memc)
{
  (void)memc;
  memset(&benchmark_state, 0, sizeof(benchmark_state));

  benchmark_state.create= (memcached_st *)calloc(BENCHMARK_TEST_LOOP, sizeof(memcached_st));
  test_true(benchmark_state.create);
  benchmark_state.clone= (memcached_st *)calloc(BENCHMARK_TEST_LOOP, sizeof(memcached_st));
  test_true(benchmark_state.clone);

  return TEST_SUCCESS;
}
Ejemplo n.º 6
0
static test_return_t allocation_test(void *not_used)
{
  hashkit_st *hashk_ptr;
  (void)not_used;

  hashk_ptr= hashkit_create(NULL);
  test_true(hashk_ptr);
  test_true(hashkit_is_allocated(hashk_ptr) == true);
  hashkit_free(hashk_ptr);

  return TEST_SUCCESS;
}
Ejemplo n.º 7
0
/* Make sure that I cant add a tcp server to a udp client */
static test_return_t add_tcp_server_udp_client_test(memcached_st *memc)
{
    (void)memc;
#if 0
    memcached_server_st server;
    memcached_server_instance_st instance=
        memcached_server_instance_by_position(memc, 0);
    memcached_server_clone(&server, &memc->hosts[0]);
    test_true(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
    test_true(memcached_server_add(memc, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
#endif
    return TEST_SUCCESS;
}
Ejemplo n.º 8
0
static test_return_t init_test(void *not_used)
{
  hashkit_st hashk;
  hashkit_st *hashk_ptr;
  (void)not_used;

  hashk_ptr= hashkit_create(&hashk);
  test_true(hashk_ptr);
  test_true(hashk_ptr == &hashk);
  test_true(hashkit_is_allocated(hashk_ptr) == false);

  hashkit_free(hashk_ptr);

  return TEST_SUCCESS;
}
Ejemplo n.º 9
0
static test_return_t hashkit_get_function_test(hashkit_st *hashk)
{
  for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
  {
    hashkit_return_t rc;

    if (HASHKIT_HASH_CUSTOM || HASHKIT_HASH_HSIEH)
      continue;

    rc= hashkit_set_function(hashk, algo);
    test_true(rc == HASHKIT_SUCCESS);

    test_true(hashkit_get_function(hashk) == algo);
  }
  return TEST_SUCCESS;
}
Ejemplo n.º 10
0
static test_return_t udp_version_test(memcached_st *memc)
{
    memcached_return_t rc;
    uint16_t *expected_ids = get_udp_request_ids(memc);
    rc = memcached_version(memc);
    test_true(rc == MEMCACHED_NOT_SUPPORTED);
    return post_udp_op_check(memc, expected_ids);
}
Ejemplo n.º 11
0
static test_return_t clone_test(hashkit_st *hashk)
{
  // First we make sure that the testing system is giving us what we expect.
  assert(&global_hashk == hashk);

  // Second we test if hashk is even valid

  /* All null? */
  {
    hashkit_st *hashk_ptr;
    hashk_ptr= hashkit_clone(NULL, NULL);
    test_true(hashk_ptr);
    test_true(hashkit_is_allocated(hashk_ptr));
    hashkit_free(hashk_ptr);
  }

  /* Can we init from null? */
  {
    hashkit_st *hashk_ptr;

    hashk_ptr= hashkit_clone(NULL, hashk);

    test_true(hashk_ptr);
    test_true(hashkit_is_allocated(hashk_ptr));

    hashkit_free(hashk_ptr);
  }

  /* Can we init from struct? */
  {
    hashkit_st declared_clone;
    hashkit_st *hash_clone;

    hash_clone= hashkit_clone(&declared_clone, NULL);
    test_true(hash_clone);
    test_true(hash_clone == &declared_clone);
    test_false(hashkit_is_allocated(hash_clone));

    hashkit_free(hash_clone);
  }

  /* Can we init from struct? */
  {
    hashkit_st declared_clone;
    hashkit_st *hash_clone;

    hash_clone= hashkit_clone(&declared_clone, hashk);
    test_true(hash_clone);
    test_true(hash_clone == &declared_clone);
    test_false(hashkit_is_allocated(hash_clone));

    hashkit_free(hash_clone);
  }

  return TEST_SUCCESS;
}
Ejemplo n.º 12
0
static test_return_t udp_decr_test(memcached_st *memc)
{
    memcached_return_t rc;
    const char *key= "decr";
    const char *value= "1";
    rc= memcached_set(memc, key, strlen(key),
                      value, strlen(value),
                      (time_t)0, (uint32_t)0);

    test_true(rc == MEMCACHED_SUCCESS);
    uint16_t *expected_ids= get_udp_request_ids(memc);
    unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
    increment_request_id(&expected_ids[server_key]);
    uint64_t newvalue;
    rc= memcached_decrement(memc, key, strlen(key), 1, &newvalue);
    test_true(rc == MEMCACHED_SUCCESS);
    return post_udp_op_check(memc, expected_ids);
}
Ejemplo n.º 13
0
static test_return_t hashkit_set_custom_distribution_function_test(hashkit_st *hashk)
{
  hashkit_return_t rc;

  rc= hashkit_set_custom_distribution_function(hashk, hash_test_function, NULL);
  test_true(rc == HASHKIT_SUCCESS);

  return TEST_SUCCESS;
}
Ejemplo n.º 14
0
static test_return_t post_udp_op_check(memcached_st *memc, uint16_t *expected_req_ids)
{
    (void)memc;
    (void)expected_req_ids;
#if 0
    memcached_server_st *cur_server = memcached_server_list(memc);
    uint16_t *cur_req_ids = get_udp_request_ids(memc);

    for (size_t x= 0; x < memcached_server_count(memc); x++)
    {
        test_true(cur_server[x].cursor_active == 0);
        test_true(cur_req_ids[x] == expected_req_ids[x]);
    }
    free(expected_req_ids);
    free(cur_req_ids);

#endif
    return TEST_SUCCESS;
}
Ejemplo n.º 15
0
void run()
{
    test_null();
    test_true();
    test_false();
    test_integer_zero();
    test_floating_zero();
    test_floating_float();
    test_string_empty();
    test_string_alpha();
}
Ejemplo n.º 16
0
static test_return_t udp_stat_test(memcached_st *memc)
{
    memcached_stat_st * rv= NULL;
    memcached_return_t rc;
    char args[]= "";
    uint16_t *expected_ids = get_udp_request_ids(memc);
    rv = memcached_stat(memc, args, &rc);
    free(rv);
    test_true(rc == MEMCACHED_NOT_SUPPORTED);
    return post_udp_op_check(memc, expected_ids);
}
Ejemplo n.º 17
0
static test_return_t hashkit_set_custom_function_test(hashkit_st *hashk)
{
  hashkit_return_t rc;
  uint32_t x;
  const char **ptr;


  rc= hashkit_set_custom_function(hashk, hash_test_function, NULL);
  test_true(rc == HASHKIT_SUCCESS);

  for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
  {
    uint32_t hash_val;

    hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
    test_true(md5_values[x] == hash_val);
  }

  return TEST_SUCCESS;
}
Ejemplo n.º 18
0
static test_return_t hashkit_compare_test(hashkit_st *hashk)
{
  hashkit_st *clone;

  clone= hashkit_clone(NULL, hashk);

  test_true(hashkit_compare(clone, hashk));
  hashkit_free(clone);

  return TEST_SUCCESS;
}
Ejemplo n.º 19
0
static test_return_t udp_set_test(memcached_st *memc)
{
    unsigned int num_iters= 1025; //request id rolls over at 1024

    for (size_t x= 0; x < num_iters; x++)
    {
        memcached_return_t rc;
        const char *key= "foo";
        const char *value= "when we sanitize";
        uint16_t *expected_ids= get_udp_request_ids(memc);
        unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
        memcached_server_instance_st instance=
            memcached_server_instance_by_position(memc, server_key);
        size_t init_offset= instance->write_buffer_offset;

        rc= memcached_set(memc, key, strlen(key),
                          value, strlen(value),
                          (time_t)0, (uint32_t)0);
        test_true(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
        /** NB, the check below assumes that if new write_ptr is less than
         *  the original write_ptr that we have flushed. For large payloads, this
         *  maybe an invalid assumption, but for the small payload we have it is OK
         */
        if (rc == MEMCACHED_SUCCESS ||
                instance->write_buffer_offset < init_offset)
            increment_request_id(&expected_ids[server_key]);

        if (rc == MEMCACHED_SUCCESS)
        {
            test_true(instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
        }
        else
        {
            test_true(instance->write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
            test_true(instance->write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
        }
        test_true(post_udp_op_check(memc, expected_ids) == TEST_SUCCESS);
    }
    return TEST_SUCCESS;
}
Ejemplo n.º 20
0
static test_return_t udp_set_too_big_test(memcached_st *memc)
{
    memcached_return_t rc;
    const char *key= "bar";
    char value[MAX_UDP_DATAGRAM_LENGTH];
    uint16_t *expected_ids= get_udp_request_ids(memc);
    rc= memcached_set(memc, key, strlen(key),
                      value, MAX_UDP_DATAGRAM_LENGTH,
                      (time_t)0, (uint32_t)0);
    test_true(rc == MEMCACHED_WRITE_FAILURE);

    return post_udp_op_check(memc,expected_ids);
}
Ejemplo n.º 21
0
static test_return_t udp_flush_test(memcached_st *memc)
{
    memcached_return_t rc;
    uint16_t *expected_ids= get_udp_request_ids(memc);

    for (size_t x= 0; x < memcached_server_count(memc); x++)
    {
        increment_request_id(&expected_ids[x]);
    }

    rc= memcached_flush(memc,0);
    test_true(rc == MEMCACHED_SUCCESS);
    return post_udp_op_check(memc,expected_ids);
}
Ejemplo n.º 22
0
static test_return_t memcached_clone_benchmark(memcached_st *memc)
{
  benchmark_state.clone_init= true;

  for (size_t x= 0; x < BENCHMARK_TEST_LOOP; x++)
  {
    memcached_st *ptr;
    ptr= memcached_clone(&benchmark_state.clone[x], memc);

    test_true(ptr);
  }

  return TEST_SUCCESS;
}
Ejemplo n.º 23
0
/*
** There is a little bit of a hack here, instead of removing
** the servers, I just set num host to 0 and them add then new udp servers
**/
static test_return_t init_udp(memcached_st *memc)
{
    memcached_version(memc);
#if 0
    memcached_server_instance_st instance=
        memcached_server_instance_by_position(memc, 0);

    /* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
    if (instance->major_version != 1 || instance->minor_version != 2
            || instance->micro_version < 6)
        return TEST_SKIPPED;

    uint32_t num_hosts= memcached_server_count(memc);
    memcached_server_st servers[num_hosts];
    memcpy(servers, memcached_server_list(memc), sizeof(memcached_server_st) * num_hosts);
    for (uint32_t x= 0; x < num_hosts; x++)
    {
        memcached_server_instance_st set_instance=
            memcached_server_instance_by_position(memc, x);

        memcached_server_free(((memcached_server_write_instance_st)set_instance));
    }

    memc->number_of_hosts= 0;
    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1);
    for (uint32_t x= 0; x < num_hosts; x++)
    {
        memcached_server_instance_st set_instance=
            memcached_server_instance_by_position(memc, x);

        test_true(memcached_server_add_udp(memc, servers[x].hostname, servers[x].port) == MEMCACHED_SUCCESS);
        test_true(set_instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
    }
#endif

    return TEST_SKIPPED;
}
Ejemplo n.º 24
0
static test_return_t md5_run (hashkit_st *hashk)
{
  uint32_t x;
  const char **ptr;
  (void)hashk;

  for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
  {
    uint32_t hash_val;

    hash_val= libhashkit_md5(*ptr, strlen(*ptr));
    test_true(md5_values[x] == hash_val);
  }

  return TEST_SUCCESS;
}
Ejemplo n.º 25
0
void run()
{
    test_null();
    test_null_white();
    fail_nul();
    fail_nuller();

    test_false();
    test_false_white();
    fail_fals();
    fail_falser();

    test_true();
    test_true_white();
    fail_tru();
    fail_truer();
}
Ejemplo n.º 26
0
static test_return_t hashkit_set_distribution_function_test(hashkit_st *hashk)
{
  for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
  {
    hashkit_return_t rc;

    rc= hashkit_set_distribution_function(hashk, algo);

    /* Hsieh is disabled most of the time for patent issues */
    if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
      continue;

    if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
      continue;

    test_true(rc == HASHKIT_SUCCESS);
  }

  return TEST_SUCCESS;
}
Ejemplo n.º 27
0
static test_return_t udp_mixed_io_test(memcached_st *memc)
{
    test_st current_op;
    test_st mixed_io_ops [] = {
        {   "udp_set_test", 0,
            (test_callback_fn)udp_set_test
        },
        {   "udp_set_too_big_test", 0,
            (test_callback_fn)udp_set_too_big_test
        },
        {   "udp_delete_test", 0,
            (test_callback_fn)udp_delete_test
        },
        {   "udp_verbosity_test", 0,
            (test_callback_fn)udp_verbosity_test
        },
        {   "udp_quit_test", 0,
            (test_callback_fn)udp_quit_test
        },
        {   "udp_flush_test", 0,
            (test_callback_fn)udp_flush_test
        },
        {   "udp_incr_test", 0,
            (test_callback_fn)udp_incr_test
        },
        {   "udp_decr_test", 0,
            (test_callback_fn)udp_decr_test
        },
        {   "udp_version_test", 0,
            (test_callback_fn)udp_version_test
        }
    };

    for (size_t x= 0; x < 500; x++)
    {
        current_op= mixed_io_ops[random() % 9];
        test_true(current_op.test_fn(memc) == TEST_SUCCESS);
    }
    return TEST_SUCCESS;
}
Ejemplo n.º 28
0
static test_return_t set_udp_behavior_test(memcached_st *memc)
{

    memcached_quit(memc);
    memc->number_of_hosts= 0;
    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION, memc->distribution);
    test_true(memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP, 1) == MEMCACHED_SUCCESS);
    test_true(memc->flags.use_udp);
    test_true(memc->flags.no_reply);

    test_true(memcached_server_count(memc) == 0);

    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_USE_UDP,0);
    test_true(! (memc->flags.use_udp));
    memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NOREPLY,0);
    test_true(! (memc->flags.no_reply));

    return TEST_SUCCESS;
}
Ejemplo n.º 29
0
static test_return_t hashkit_set_function_test(hashkit_st *hashk)
{
  for (hashkit_hash_algorithm_t algo = HASHKIT_HASH_DEFAULT; algo < HASHKIT_HASH_MAX; algo++)
  {
    hashkit_return_t rc;
    uint32_t x;
    const char **ptr;
    uint32_t *list;

    rc= hashkit_set_function(hashk, algo);

    /* Hsieh is disabled most of the time for patent issues */
#ifndef HAVE_HSIEH_HASH
    if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_HSIEH)
      continue;
#endif

#ifndef HAVE_MURMUR_HASH
    if (rc == HASHKIT_FAILURE && algo == HASHKIT_HASH_MURMUR)
      continue;
#endif

    if (rc == HASHKIT_INVALID_ARGUMENT && algo == HASHKIT_HASH_CUSTOM)
      continue;

    test_true_got(rc == HASHKIT_SUCCESS, hashkit_strerror(NULL, rc));

    switch (algo)
    {
    case HASHKIT_HASH_DEFAULT:
      list= one_at_a_time_values;
      break;
    case HASHKIT_HASH_MD5:
      list= md5_values;
      break;
    case HASHKIT_HASH_CRC:
      list= crc_values;
      break;
    case HASHKIT_HASH_FNV1_64:
      list= fnv1_64_values;
      break;
    case HASHKIT_HASH_FNV1A_64:
      list= fnv1a_64_values;
      break;
    case HASHKIT_HASH_FNV1_32:
      list= fnv1_32_values;
      break;
    case HASHKIT_HASH_FNV1A_32:
      list= fnv1a_32_values;
      break;
    case HASHKIT_HASH_HSIEH:
      list= hsieh_values;
      break;
    case HASHKIT_HASH_MURMUR:
      list= murmur_values;
      break;
    case HASHKIT_HASH_JENKINS:
      list= jenkins_values;
      break;
    case HASHKIT_HASH_CUSTOM:
    case HASHKIT_HASH_MAX:
    default:
      list= NULL;
      break;
    }

    // Now we make sure we did set the hash correctly.
    if (list)
    {
      for (ptr= list_to_hash, x= 0; *ptr; ptr++, x++)
      {
        uint32_t hash_val;

        hash_val= hashkit_digest(hashk, *ptr, strlen(*ptr));
        test_true(list[x] == hash_val);
      }
    }
    else
    {
      return TEST_FAILURE;
    }
  }

  return TEST_SUCCESS;
}