xref: /6.0.3/moxi/tests/vbucket/regression.c (revision d0366df5)
1/* -*- Mode: C; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2#undef NDEBUG
3#include <errno.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <string.h>
7
8#include <libvbucket/vbucket.h>
9#include <platform/cbassert.h>
10
11#include "macros.h"
12
13const char *test_cases[] = {
14   "regression-bug2112",
15   NULL
16};
17
18int main(int argc, char **argv) {
19   char *root = getenv("CMAKE_CURRENT_SOURCE_DIR");
20   char buffer[FILENAME_MAX];
21   VBUCKET_CONFIG_HANDLE h;
22   char key1[9] = "00000000";
23   int v, m, num_replicas, ff;
24   const char *master;
25
26   if (root == NULL) {
27       if (argc > 1) {
28           root = argv[1];
29       } else {
30           root = ".";
31       }
32   }
33
34   for (ff = 0; test_cases[ff] != NULL; ++ff) {
35       sprintf(buffer, "%s/tests/vbucket/config/%s", root, test_cases[ff]);
36       fprintf(stderr, "Running regression test for: %s\n", test_cases[ff]);
37       h = vbucket_config_create();
38       cb_assert(vbucket_config_parse(h, LIBVBUCKET_SOURCE_FILE, buffer) == 0);
39
40       fprintf(stderr, "Testing a key can be hashed.");
41       v = vbucket_get_vbucket_by_key(h, key1, strlen(key1));
42       m = vbucket_get_master(h, v);
43       master = vbucket_config_get_server(h, m);
44       fprintf(stderr, "  key: %s vBucketId: %d master: %s", key1, v, master);
45       num_replicas = vbucket_config_get_num_replicas(h);
46       if (num_replicas > 0) {
47           int j;
48           fprintf(stderr, " replicas:");
49           for (j = 0; j < num_replicas; j++) {
50               int r = vbucket_get_replica(h, v, j);
51               if (r >= 0) {
52                   const char *replica = vbucket_config_get_server(h, r);
53                   fprintf(stderr, " %s", replica == NULL ? "(null)" : replica);
54               }
55           }
56       }
57       fprintf(stderr, "\n");
58       vbucket_config_destroy(h);
59   }
60
61   exit(EXIT_SUCCESS);
62}
63