2 Sample test application.
10 #include <sys/types.h>
15 #include "../lib/common.h"
16 #include "../src/generator.h"
17 #include "../src/execute.h"
20 #define INT64_MAX LONG_MAX
23 #define INT32_MAX INT_MAX
29 #define GLOBAL_COUNT 100000
30 #define TEST_COUNTER 100000
31 static uint32_t global_count
;
33 static pairs_st
*global_pairs
;
34 static char *global_keys
[GLOBAL_COUNT
];
35 static size_t global_keys_length
[GLOBAL_COUNT
];
37 uint8_t cleanup_pairs(memcached_st
*memc
)
39 pairs_free(global_pairs
);
44 uint8_t generate_pairs(memcached_st
*memc
)
47 global_pairs
= pairs_generate(GLOBAL_COUNT
, 400);
48 global_count
= GLOBAL_COUNT
;
50 for (x
= 0; x
< global_count
; x
++)
52 global_keys
[x
]= global_pairs
[x
].key
;
53 global_keys_length
[x
]= global_pairs
[x
].key_length
;
59 uint8_t drizzle(memcached_st
*memc
)
66 size_t return_value_length
;
69 for (x
= 0; x
< TEST_COUNTER
; x
++)
74 test_bit
= random() % GLOBAL_COUNT
;
79 return_value
= memcached_get(memc
, global_keys
[test_bit
], global_keys_length
[test_bit
],
80 &return_value_length
, &flags
, &rc
);
81 if (rc
== MEMCACHED_SUCCESS
&& return_value
)
88 rc
= memcached_set(memc
, global_pairs
[test_bit
].key
,
89 global_pairs
[test_bit
].key_length
,
90 global_pairs
[test_bit
].value
,
91 global_pairs
[test_bit
].value_length
,
93 if (rc
!= MEMCACHED_SUCCESS
&& rc
!= MEMCACHED_BUFFERED
)
105 memcached_return
pre_nonblock(memcached_st
*memc
)
107 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_NO_BLOCK
, NULL
);
109 return MEMCACHED_SUCCESS
;
112 memcached_return
pre_md5(memcached_st
*memc
)
114 memcached_hash value
= MEMCACHED_HASH_MD5
;
115 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, &value
);
117 return MEMCACHED_SUCCESS
;
120 memcached_return
pre_hsieh(memcached_st
*memc
)
122 memcached_hash value
= MEMCACHED_HASH_HSIEH
;
123 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_HASH
, &value
);
125 return MEMCACHED_SUCCESS
;
128 memcached_return
enable_consistent(memcached_st
*memc
)
130 memcached_server_distribution value
= MEMCACHED_DISTRIBUTION_CONSISTENT
;
132 memcached_behavior_set(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
, &value
);
135 value
= (memcached_server_distribution
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_DISTRIBUTION
);
136 assert(value
== MEMCACHED_DISTRIBUTION_CONSISTENT
);
138 hash
= (memcached_hash
)memcached_behavior_get(memc
, MEMCACHED_BEHAVIOR_HASH
);
139 assert(hash
== MEMCACHED_HASH_HSIEH
);
142 return MEMCACHED_SUCCESS
;
145 test_st generate_tests
[] ={
146 {"generate_pairs", 1, generate_pairs
},
147 {"cleanup", 1, cleanup_pairs
},
152 collection_st collection
[] ={
153 {"generate", 0, 0, generate_tests
},
154 {"generate_hsieh", pre_hsieh
, 0, generate_tests
},
155 {"generate_hsieh_consistent", enable_consistent
, 0, generate_tests
},
156 {"generate_md5", pre_md5
, 0, generate_tests
},
157 {"generate_nonblock", pre_nonblock
, 0, generate_tests
},
161 #define SERVERS_TO_CREATE 5
163 void *world_create(void)
165 server_startup_st
*construct
;
167 construct
= (server_startup_st
*)malloc(sizeof(server_startup_st
));
168 memset(construct
, 0, sizeof(server_startup_st
));
169 construct
->count
= SERVERS_TO_CREATE
;
171 server_startup(construct
);
176 void world_destroy(void *p
)
178 server_startup_st
*construct
= (server_startup_st
*)p
;
179 memcached_server_st
*servers
= (memcached_server_st
*)construct
->servers
;
180 memcached_server_list_free(servers
);
182 server_shutdown(construct
);
186 void get_world(world_st
*world
)
188 world
->collections
= collection
;
189 world
->create
= world_create
;
190 world
->destroy
= world_destroy
;