memcached_return_t rc;
memcached_server_fn callbacks[1];
memcached_st *local_memc;
+ memcached_server_instance_st *instance;
local_memc= memcached_create(NULL);
test_truth(local_memc);
rc= memcached_server_add_with_weight(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43043, 0);
test_truth(rc == MEMCACHED_SUCCESS);
- test_truth(local_memc->hosts[0].port == 43043);
+ instance= memcached_server_instance_fetch(local_memc, 0);
+ test_truth(instance->port == 43043);
rc= memcached_server_add_with_weight(local_memc, "MEMCACHED_BEHAVIOR_SORT_HOSTS", 43042, 0);
test_truth(rc == MEMCACHED_SUCCESS);
- test_truth(local_memc->hosts[0].port == 43042);
- test_truth(local_memc->hosts[1].port == 43043);
+
+ instance= memcached_server_instance_fetch(local_memc, 0);
+ test_truth(instance->port == 43042);
+
+ instance= memcached_server_instance_fetch(local_memc, 1);
+ test_truth(instance->port == 43043);
callbacks[0]= server_display_function;
memcached_server_cursor(local_memc, callbacks, (void *)&bigger, 1);
test_ports[x]= (uint32_t)(random() % 64000);
rc= memcached_server_add_with_weight(local_memc, "localhost", test_ports[x], 0);
test_truth(memcached_server_count(local_memc) == x+1);
- test_truth(memcached_servers_count(local_memc->hosts) == x+1);
+ test_truth(memcached_servers_count(memcached_server_list(local_memc)) == x+1);
test_truth(rc == MEMCACHED_SUCCESS);
}
{
memcached_return_t rc;
memcached_stat_st memc_stat;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
+
rc= memcached_stat_servername(&memc_stat, NULL,
- memc->hosts[0].hostname,
- memc->hosts[0].port);
+ instance->hostname,
+ instance->port);
return TEST_SUCCESS;
}
for (x= 0; x < 99; x++)
{
uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key));
- char *hostname = memc->hosts[server_idx].hostname;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, server_idx);
+ char *hostname = instance->hostname;
test_strcmp(hostname, ketama_test_cases[x].server);
}
static test_return_t auto_eject_hosts(memcached_st *trash)
{
(void) trash;
+ memcached_server_instance_st *instance;
memcached_return_t rc;
memcached_st *memc= memcached_create(NULL);
test_truth(server_pool[7].port == 11211);
test_truth(server_pool[7].weight == 100);
- memc->hosts[2].next_retry = time(NULL) + 15;
+ instance= memcached_server_instance_fetch(memc, 2);
+ instance->next_retry = time(NULL) + 15;
memc->next_distribution_rebuild= time(NULL) - 1;
for (int x= 0; x < 99; x++)
}
/* and re-added when it's back. */
- memc->hosts[2].next_retry = time(NULL) - 1;
+ instance->next_retry = time(NULL) - 1;
memc->next_distribution_rebuild= time(NULL) - 1;
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_DISTRIBUTION,
memc->distribution);
for (int x= 0; x < 99; x++)
{
uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key));
- char *hostname = memc->hosts[server_idx].hostname;
+ // We re-use instance from above.
+ instance=
+ memcached_server_instance_fetch(memc, server_idx);
+ char *hostname = instance->hostname;
test_truth(strcmp(hostname, ketama_test_cases[x].server) == 0);
}
{
memcached_return_t rc= MEMCACHED_FAILURE;
memcached_st *memc_clone;
+ memcached_server_instance_st *instance;
memc_clone= memcached_clone(NULL, memc);
test_truth(memc_clone);
// will not toggle protocol on an connection.
memcached_version(memc_clone);
- if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2)
+ instance= memcached_server_instance_fetch(memc_clone, 0);
+
+ if (instance->major_version >= 1 && instance->minor_version > 2)
{
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_NO_BLOCK, 0);
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
{
memcached_return_t rc= MEMCACHED_FAILURE;
memcached_st *memc_clone;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
memc_clone= memcached_clone(NULL, memc);
test_truth(memc_clone);
// will not toggle protocol on an connection.
memcached_version(memc_clone);
- if (memc_clone->hosts[0].major_version >= 1 && memc_clone->hosts[0].minor_version > 2)
+ if (instance->major_version >= 1 && instance->minor_version > 2)
{
rc = memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_BINARY_PROTOCOL, 1);
test_truth(rc == MEMCACHED_SUCCESS);
{
unsigned int set= 1;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
+
memcached_version(memc);
- if ((memc->hosts[0].major_version >= 1 && (memc->hosts[0].minor_version == 2 && memc->hosts[0].micro_version >= 4))
- || memc->hosts[0].minor_version > 2)
+ if ((instance->major_version >= 1 && (instance->minor_version == 2 && instance->micro_version >= 4))
+ || instance->minor_version > 2)
{
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SUPPORT_CAS, set);
static test_return_t check_for_1_2_3(memcached_st *memc)
{
memcached_version(memc);
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
- if ((memc->hosts[0].major_version >= 1 && (memc->hosts[0].minor_version == 2 && memc->hosts[0].micro_version >= 4))
- || memc->hosts[0].minor_version > 2)
+ if ((instance->major_version >= 1 && (instance->minor_version == 2 && instance->micro_version >= 4))
+ || instance->minor_version > 2)
return TEST_SUCCESS;
return TEST_SKIPPED;
static test_return_t init_udp(memcached_st *memc)
{
memcached_version(memc);
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
+
/* For the time being, only support udp test for >= 1.2.6 && < 1.3 */
- if (memc->hosts[0].major_version != 1 || memc->hosts[0].minor_version != 2
- || memc->hosts[0].micro_version < 6)
+ if (instance->major_version != 1 || instance->minor_version != 2
+ || instance->micro_version < 6)
return TEST_SKIPPED;
uint32_t num_hosts= memcached_server_count(memc);
(void)memc;
#if 0
memcached_server_st server;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
memcached_server_clone(&server, &memc->hosts[0]);
test_truth(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
test_truth(memcached_server_add(memc, server.hostname, server.port) == MEMCACHED_INVALID_HOST_PROTOCOL);
(void)memc;
#if 0
memcached_server_st server;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, 0);
memcached_server_clone(&server, &memc->hosts[0]);
test_truth(memcached_server_remove(&(memc->hosts[0])) == MEMCACHED_SUCCESS);
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));
- size_t init_offset= memc->hosts[server_key].write_buffer_offset;
+ unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(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);
* maybe an invalid assumption, but for the small payload we have it is OK
*/
if (rc == MEMCACHED_SUCCESS ||
- memc->hosts[server_key].write_buffer_offset < init_offset)
+ instance->write_buffer_offset < init_offset)
increment_request_id(&expected_ids[server_key]);
if (rc == MEMCACHED_SUCCESS)
{
- test_truth(memc->hosts[server_key].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
+ test_truth(instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
}
else
{
- test_truth(memc->hosts[server_key].write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
- test_truth(memc->hosts[server_key].write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
+ test_truth(instance->write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
+ test_truth(instance->write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
}
- test_truth(post_udp_op_check(memc,expected_ids) == TEST_SUCCESS);
+ test_truth(post_udp_op_check(memc, expected_ids) == TEST_SUCCESS);
}
return TEST_SUCCESS;
}
const char *key= "foo";
uint16_t *expected_ids=get_udp_request_ids(memc);
unsigned int server_key= memcached_generate_hash(memc, key, strlen(key));
- size_t init_offset= memc->hosts[server_key].write_buffer_offset;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, server_key);
+ size_t init_offset= instance->write_buffer_offset;
+
rc= memcached_delete(memc, key, strlen(key), 0);
test_truth(rc == MEMCACHED_SUCCESS || rc == MEMCACHED_BUFFERED);
- if (rc == MEMCACHED_SUCCESS || memc->hosts[server_key].write_buffer_offset < init_offset)
+
+ if (rc == MEMCACHED_SUCCESS || instance->write_buffer_offset < init_offset)
increment_request_id(&expected_ids[server_key]);
if (rc == MEMCACHED_SUCCESS)
{
- test_truth(memc->hosts[server_key].write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
+ test_truth(instance->write_buffer_offset == UDP_DATAGRAM_HEADER_LENGTH);
}
else
{
- test_truth(memc->hosts[server_key].write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
- test_truth(memc->hosts[server_key].write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
+ test_truth(instance->write_buffer_offset != UDP_DATAGRAM_HEADER_LENGTH);
+ test_truth(instance->write_buffer_offset <= MAX_UDP_DATAGRAM_LENGTH);
}
test_truth(post_udp_op_check(memc,expected_ids) == TEST_SUCCESS);
}
for (x= 0; x < 99; x++)
{
uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases[x].key, strlen(ketama_test_cases[x].key));
- char *hostname = memc->hosts[server_idx].hostname;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, server_idx);
+ char *hostname = instance->hostname;
test_strcmp(hostname, ketama_test_cases[x].server);
}
for (x= 0; x < 99; x++)
{
uint32_t server_idx = memcached_generate_hash(memc, ketama_test_cases_spy[x].key, strlen(ketama_test_cases_spy[x].key));
- char *hostname = memc->hosts[server_idx].hostname;
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc, server_idx);
+ char *hostname = instance->hostname;
test_strcmp(hostname, ketama_test_cases_spy[x].server);
}
test_truth(memc_clone != NULL);
test_truth(memcached_version(memc_clone) == MEMCACHED_SUCCESS);
- if (memc_clone->hosts[0].major_version > 1 ||
- (memc_clone->hosts[0].major_version == 1 &&
- memc_clone->hosts[0].minor_version > 2))
+ memcached_server_instance_st *instance=
+ memcached_server_instance_fetch(memc_clone, 0);
+
+ if (instance->major_version > 1 ||
+ (instance->major_version == 1 &&
+ instance->minor_version > 2))
{
/* Binary protocol doesn't support deferred delete */
memcached_st *bin_clone= memcached_clone(NULL, memc);