summaryrefslogtreecommitdiff
path: root/subversion/tests/libsvn_subr/cache-test.c
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/tests/libsvn_subr/cache-test.c')
-rw-r--r--subversion/tests/libsvn_subr/cache-test.c122
1 files changed, 117 insertions, 5 deletions
diff --git a/subversion/tests/libsvn_subr/cache-test.c b/subversion/tests/libsvn_subr/cache-test.c
index 9e7a7b3..1616441 100644
--- a/subversion/tests/libsvn_subr/cache-test.c
+++ b/subversion/tests/libsvn_subr/cache-test.c
@@ -157,7 +157,8 @@ test_memcache_basic(const svn_test_opts_t *opts,
{
SVN_ERR(svn_config_read3(&config, opts->config_file,
TRUE, FALSE, FALSE, pool));
- SVN_ERR(svn_cache__make_memcache_from_config(&memcache, config, pool));
+ SVN_ERR(svn_cache__make_memcache_from_config(&memcache, config,
+ pool, pool));
}
if (! memcache)
@@ -193,8 +194,9 @@ test_membuffer_cache_basic(apr_pool_t *pool)
deserialize_revnum,
APR_HASH_KEY_STRING,
"cache:",
+ SVN_CACHE__MEMBUFFER_DEFAULT_PRIORITY,
FALSE,
- pool));
+ pool, pool));
return basic_cache_test(cache, FALSE, pool);
}
@@ -220,6 +222,16 @@ raise_error_partial_getter_func(void **out,
return svn_error_create(APR_EGENERAL, NULL, NULL);
}
+/* Implements svn_cache__partial_setter_func_t */
+static svn_error_t *
+raise_error_partial_setter_func(void **data,
+ apr_size_t *data_len,
+ void *baton,
+ apr_pool_t *result_pool)
+{
+ return svn_error_create(APR_EGENERAL, NULL, NULL);
+}
+
static svn_error_t *
test_membuffer_serializer_error_handling(apr_pool_t *pool)
{
@@ -239,8 +251,9 @@ test_membuffer_serializer_error_handling(apr_pool_t *pool)
raise_error_deserialize_func,
APR_HASH_KEY_STRING,
"cache:",
+ SVN_CACHE__MEMBUFFER_DEFAULT_PRIORITY,
FALSE,
- pool));
+ pool, pool));
SVN_ERR(svn_cache__set(cache, "twenty", &twenty, pool));
@@ -258,6 +271,30 @@ test_membuffer_serializer_error_handling(apr_pool_t *pool)
NULL, pool),
APR_EGENERAL);
+ /* Create a new cache. */
+ SVN_ERR(svn_cache__membuffer_cache_create(&membuffer, 10*1024, 1, 0,
+ TRUE, TRUE, pool));
+ SVN_ERR(svn_cache__create_membuffer_cache(&cache,
+ membuffer,
+ serialize_revnum,
+ deserialize_revnum,
+ APR_HASH_KEY_STRING,
+ "cache:",
+ SVN_CACHE__MEMBUFFER_DEFAULT_PRIORITY,
+ FALSE,
+ pool, pool));
+
+ /* Store one entry in cache. */
+ SVN_ERR(svn_cache__set(cache, "twenty", &twenty, pool));
+
+ /* Test setting data in cache using partial setter that
+ always raises an error. */
+ SVN_TEST_ASSERT_ERROR(
+ svn_cache__set_partial(cache, "twenty",
+ raise_error_partial_setter_func,
+ NULL, pool),
+ APR_EGENERAL);
+
return SVN_NO_ERROR;
}
@@ -286,7 +323,8 @@ test_memcache_long_key(const svn_test_opts_t *opts,
{
SVN_ERR(svn_config_read3(&config, opts->config_file,
TRUE, FALSE, FALSE, pool));
- SVN_ERR(svn_cache__make_memcache_from_config(&memcache, config, pool));
+ SVN_ERR(svn_cache__make_memcache_from_config(&memcache, config,
+ pool, pool));
}
if (! memcache)
@@ -316,10 +354,80 @@ test_memcache_long_key(const svn_test_opts_t *opts,
return SVN_NO_ERROR;
}
+static svn_error_t *
+test_membuffer_cache_clearing(apr_pool_t *pool)
+{
+ svn_cache__t *cache;
+ svn_membuffer_t *membuffer;
+ svn_boolean_t found;
+ svn_revnum_t *value;
+ svn_revnum_t valueA = 12345;
+ svn_revnum_t valueB = 67890;
+
+ /* Create a simple cache for strings, keyed by strings. */
+ SVN_ERR(svn_cache__membuffer_cache_create(&membuffer, 10*1024, 1, 0,
+ TRUE, TRUE, pool));
+ SVN_ERR(svn_cache__create_membuffer_cache(&cache,
+ membuffer,
+ serialize_revnum,
+ deserialize_revnum,
+ APR_HASH_KEY_STRING,
+ "cache:",
+ SVN_CACHE__MEMBUFFER_DEFAULT_PRIORITY,
+ FALSE,
+ pool, pool));
+
+ /* Initially, the cache is empty. */
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key A", pool));
+ SVN_TEST_ASSERT(!found);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key B", pool));
+ SVN_TEST_ASSERT(!found);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key C", pool));
+ SVN_TEST_ASSERT(!found);
+
+ /* Add entries. */
+ SVN_ERR(svn_cache__set(cache, "key A", &valueA, pool));
+ SVN_ERR(svn_cache__set(cache, "key B", &valueB, pool));
+
+ /* Added entries should be cached (too small to get evicted already). */
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key A", pool));
+ SVN_TEST_ASSERT(found);
+ SVN_TEST_ASSERT(*value == valueA);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key B", pool));
+ SVN_TEST_ASSERT(found);
+ SVN_TEST_ASSERT(*value == valueB);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key C", pool));
+ SVN_TEST_ASSERT(!found);
+
+ /* Clear the cache. */
+ SVN_ERR(svn_cache__membuffer_clear(membuffer));
+
+ /* The cache is empty again. */
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key A", pool));
+ SVN_TEST_ASSERT(!found);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key B", pool));
+ SVN_TEST_ASSERT(!found);
+ SVN_ERR(svn_cache__get((void **) &value, &found, cache, "key C", pool));
+ SVN_TEST_ASSERT(!found);
+
+ /* But still functional: */
+ SVN_ERR(svn_cache__set(cache, "key B", &valueB, pool));
+ SVN_ERR(svn_cache__has_key(&found, cache, "key A", pool));
+ SVN_TEST_ASSERT(!found);
+ SVN_ERR(svn_cache__has_key(&found, cache, "key B", pool));
+ SVN_TEST_ASSERT(found);
+ SVN_ERR(svn_cache__has_key(&found, cache, "key C", pool));
+ SVN_TEST_ASSERT(!found);
+
+ return SVN_NO_ERROR;
+}
+
/* The test table. */
-struct svn_test_descriptor_t test_funcs[] =
+static int max_threads = 1;
+
+static struct svn_test_descriptor_t test_funcs[] =
{
SVN_TEST_NULL,
SVN_TEST_PASS2(test_inprocess_cache_basic,
@@ -332,5 +440,9 @@ struct svn_test_descriptor_t test_funcs[] =
"basic membuffer svn_cache test"),
SVN_TEST_PASS2(test_membuffer_serializer_error_handling,
"test for error handling in membuffer svn_cache"),
+ SVN_TEST_PASS2(test_membuffer_cache_clearing,
+ "test clearing a membuffer svn_cache"),
SVN_TEST_NULL
};
+
+SVN_TEST_MAIN