Пример #1
0
int kvstore_get_put_with_hash_conflicts(void) {
  /* hash("abD") == hash("aae") == hash("ac#") */
  char *retval, *key1 = "abD", *key2 = "aae", *key3 = "ac#";
  int ret;
  ret = kvstore_put(&teststore, key1, "value1");
  ret += kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key2, &retval);
  ASSERT_STRING_EQUAL(retval, "value2");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  /* Clean the store and do it again in a different order to ensure that
     the above success wasn't just because of a lucky ordering. */
  kvstore_clean(&teststore);
  kvstore_init(&teststore, KVSTORE_DIRNAME);
  ret = kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_put(&teststore, key1, "value1");
  ret += kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key2, &retval);
  ASSERT_STRING_EQUAL(retval, "value2");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  ASSERT_EQUAL(ret, 0);
  return 1;
}
Пример #2
0
int kvstore_get_put_uninitialized(void) {
  char *retval;
  int ret;
  kvstore_clean(&teststore);
  ret = kvstore_get(&teststore, "KEY", &retval);
  ASSERT_EQUAL(ret, ERRFILACCESS);
  ret = kvstore_put(&teststore, "KEY", "VALUE");
  ASSERT_EQUAL(ret, ERRFILACCESS);
  return 1;
}
Пример #3
0
int kvstore_del_hash_conflicts(void) {
  /* hash("abD") == hash("aae") == hash("ac#") */
  char *retval = NULL, *key1 = "abD", *key2 = "aae", *key3 = "ac#";
  int ret;
  ret = kvstore_put(&teststore, key1, "value1");
  ret += kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_del(&teststore, key2);
  ASSERT_EQUAL(ret, 0);
  ret = kvstore_get(&teststore, key2, &retval);
  ASSERT_PTR_NULL(retval);
  ASSERT_EQUAL(ret, ERRNOKEY);
  ret = kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  ASSERT_EQUAL(ret, 0);
  /* Clean store and do operations again with a different insertion order to
   * help ensure that success wasn't due to a lucky ordering. */
  kvstore_clean(&teststore);
  kvstore_init(&teststore, KVSTORE_DIRNAME);
  ret = kvstore_put(&teststore, key2, "value2");
  ret += kvstore_put(&teststore, key1, "value1");
  ret += kvstore_put(&teststore, key3, "value3");
  ret += kvstore_del(&teststore, key2);
  ASSERT_EQUAL(ret, 0);
  retval = NULL;
  ret = kvstore_get(&teststore, key2, &retval);
  ASSERT_PTR_NULL(retval);
  ASSERT_EQUAL(ret, ERRNOKEY);
  ret = kvstore_get(&teststore, key1, &retval);
  ASSERT_STRING_EQUAL(retval, "value1");
  free(retval);
  ret += kvstore_get(&teststore, key3, &retval);
  ASSERT_STRING_EQUAL(retval, "value3");
  free(retval);
  ASSERT_EQUAL(ret, 0);
  return 1;
}
Пример #4
0
/* Deletes all current entries in SERVER's store and removes the store
 * directory.  Also cleans the associated log. Note that you will be required
 * to reinitialize SERVER following this action. */
int tpcfollower_clean(tpcfollower_t *server) { return kvstore_clean(&server->store); }
Пример #5
0
/* Deletes all current entries in SERVER's store and removes the store
 * directory.  Also cleans the associated log. */
int kvserver_clean(kvserver_t *server) {
  return kvstore_clean(&server->store);
}
Пример #6
0
/* Deletes all current entries in the store and removes the store directory. */
int kvstore_test_clean(void) {
  return kvstore_clean(&teststore);
}