-struct test_pool_context_st {
- memcached_pool_st* pool;
- memcached_st* mmc;
-};
-
-static void* connection_release(void *arg)
-{
- test_pool_context_st *resource= static_cast<test_pool_context_st *>(arg);
-
- usleep(250);
- // Release all of the memc we are holding
- assert(memcached_success(memcached_pool_push(resource->pool, resource->mmc)));
- return arg;
-}
-
-#define POOL_SIZE 10
-static test_return_t connection_pool_test(memcached_st *memc)
-{
- memcached_pool_st* pool= memcached_pool_create(memc, 5, POOL_SIZE);
- test_true(pool != NULL);
- memcached_st *mmc[POOL_SIZE];
- memcached_return_t rc;
-
- // Fill up our array that we will store the memc that are in the pool
- for (size_t x= 0; x < POOL_SIZE; ++x)
- {
- mmc[x]= memcached_pool_pop(pool, false, &rc);
- test_true(mmc[x] != NULL);
- test_compare(MEMCACHED_SUCCESS, rc);
- }
-
- // All memc should be gone
- test_true(memcached_pool_pop(pool, false, &rc) == NULL);
- test_compare(MEMCACHED_SUCCESS, rc);
-
- pthread_t tid;
- test_pool_context_st item= { pool, mmc[9] };
-
- pthread_create(&tid, NULL, connection_release, &item);
- mmc[9]= memcached_pool_pop(pool, true, &rc);
- test_compare(MEMCACHED_SUCCESS, rc);
- pthread_join(tid, NULL);
- test_true(mmc[9]);
- const char *key= "key";
- size_t keylen= strlen(key);
-
- // verify that I can do ops with all connections
- test_compare(MEMCACHED_SUCCESS,
- memcached_set(mmc[0], key, keylen, "0", 1, 0, 0));
-
- for (uint64_t x= 0; x < POOL_SIZE; ++x)
- {
- uint64_t number_value;
- test_compare(MEMCACHED_SUCCESS,
- memcached_increment(mmc[x], key, keylen, 1, &number_value));
- test_compare(number_value, (x+1));
- }
-
- // Release them..
- for (size_t x= 0; x < POOL_SIZE; ++x)
- {
- test_compare(MEMCACHED_SUCCESS, memcached_pool_push(pool, mmc[x]));
- }
-
-
- /* verify that I can set behaviors on the pool when I don't have all
- * of the connections in the pool. It should however be enabled
- * when I push the item into the pool
- */
- mmc[0]= memcached_pool_pop(pool, false, &rc);
- test_true(mmc[0]);
-
- rc= memcached_pool_behavior_set(pool, MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK, 9999);
- test_compare(MEMCACHED_SUCCESS, rc);
-
- mmc[1]= memcached_pool_pop(pool, false, &rc);
- test_true(mmc[1]);
-
- test_compare(UINT64_C(9999), memcached_behavior_get(mmc[1], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
- test_compare(MEMCACHED_SUCCESS, memcached_pool_push(pool, mmc[1]));
- test_compare(MEMCACHED_SUCCESS, memcached_pool_push(pool, mmc[0]));
-
- mmc[0]= memcached_pool_pop(pool, false, &rc);
- test_compare(UINT64_C(9999), memcached_behavior_get(mmc[0], MEMCACHED_BEHAVIOR_IO_MSG_WATERMARK));
- test_compare(MEMCACHED_SUCCESS, memcached_pool_push(pool, mmc[0]));
-
- test_true(memcached_pool_destroy(pool) == memc);
-
- return TEST_SUCCESS;
-}
-