xref: /3.0.3-GA/ep-engine/tests/ep_test_apis.h (revision 0389c521)
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 *     Copyright 2012 Couchbase, Inc
4 *
5 *   Licensed under the Apache License, Version 2.0 (the "License");
6 *   you may not use this file except in compliance with the License.
7 *   You may obtain a copy of the License at
8 *
9 *       http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *   Unless required by applicable law or agreed to in writing, software
12 *   distributed under the License is distributed on an "AS IS" BASIS,
13 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *   See the License for the specific language governing permissions and
15 *   limitations under the License.
16 */
17
18#ifndef TESTS_EP_TEST_APIS_H_
19#define TESTS_EP_TEST_APIS_H_ 1
20
21#include "config.h"
22
23#include <memcached/engine.h>
24#include <memcached/engine_testapp.h>
25
26#include <map>
27#include <string>
28
29#include "ep-engine/command_ids.h"
30#include "item.h"
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36bool add_response(const void *key, uint16_t keylen, const void *ext,
37                  uint8_t extlen, const void *body, uint32_t bodylen,
38                  uint8_t datatype, uint16_t status, uint64_t cas,
39                  const void *cookie);
40
41void add_stats(const char *key, const uint16_t klen, const char *val,
42               const uint32_t vlen, const void *cookie);
43
44ENGINE_ERROR_CODE vb_map_response(const void *cookie, const void *map,
45                                  size_t mapsize);
46
47#ifdef __cplusplus
48}
49#endif
50
51extern protocol_binary_response_status last_status;
52extern char *last_key;
53extern char *last_body;
54extern bool dump_stats;
55extern std::map<std::string, std::string> vals;
56extern uint32_t last_bodylen;
57extern uint64_t last_cas;
58extern uint8_t last_datatype;
59extern bool last_deleted_flag;
60extern ItemMetaData last_meta;
61
62extern uint8_t upr_last_op;
63extern uint8_t upr_last_status;
64extern uint8_t upr_last_nru;
65extern uint16_t upr_last_vbucket;
66extern uint32_t upr_last_opaque;
67extern uint32_t upr_last_flags;
68extern uint32_t upr_last_stream_opaque;
69extern uint32_t upr_last_locktime;
70extern uint32_t upr_last_packet_size;
71extern uint64_t upr_last_cas;
72extern uint64_t upr_last_start_seqno;
73extern uint64_t upr_last_end_seqno;
74extern uint64_t upr_last_vbucket_uuid;
75extern uint64_t upr_last_high_seqno;
76extern uint64_t upr_last_byseqno;
77extern uint64_t upr_last_revseqno;
78extern std::string upr_last_key;
79extern vbucket_state_t upr_last_vbucket_state;
80
81
82void decayingSleep(useconds_t *sleepTime);
83
84
85protocol_binary_request_header* createPacket(uint8_t opcode,
86                                             uint16_t vbid = 0,
87                                             uint64_t cas = 0,
88                                             const char *ext = NULL,
89                                             uint8_t extlen = 0,
90                                             const char *key = NULL,
91                                             uint32_t keylen = 0,
92                                             const char *val = NULL,
93                                             uint32_t vallen = 0,
94                                             uint8_t datatype = 0x00);
95
96// Basic Operations
97ENGINE_ERROR_CODE del(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
98                      uint64_t cas, uint16_t vbucket, const void* cookie = NULL);
99void disable_traffic(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
100void enable_traffic(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
101void evict_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
102               uint16_t vbucketId = 0, const char *msg = NULL,
103               bool expectError = false);
104size_t estimateVBucketMove(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
105                           uint16_t vbid = 0, const char* tap_name = "");
106void gat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
107         uint16_t vb, uint32_t exp, bool quiet = false);
108bool get_item_info(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, item_info *info,
109                   const char* key, uint16_t vb = 0);
110bool get_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, item *i,
111             std::string &key);
112void getl(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key, uint16_t vb,
113          uint32_t lock_timeout);
114void get_replica(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
115                 uint16_t vb);
116void observe(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
117             std::map<std::string, uint16_t> obskeys);
118protocol_binary_request_header* prepare_get_replica(ENGINE_HANDLE *h,
119                                                    ENGINE_HANDLE_V1 *h1,
120                                                    vbucket_state_t state,
121                                                    bool makeinvalidkey = false);
122bool set_param(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, protocol_binary_engine_param_t paramtype,
123               const char *param, const char *val);
124bool set_vbucket_state(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
125                       uint16_t vb, vbucket_state_t state);
126void start_persistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
127void stop_persistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
128ENGINE_ERROR_CODE store(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
129                        const void *cookie, ENGINE_STORE_OPERATION op,
130                        const char *key, const char *value, item **outitem,
131                        uint64_t casIn = 0, uint16_t vb = 0,
132                        uint32_t exp = 3600);
133ENGINE_ERROR_CODE storeCasVb11(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
134                               const void *cookie, ENGINE_STORE_OPERATION op,
135                               const char *key, const char *value, size_t vlen,
136                               uint32_t flags, item **outitem, uint64_t casIn,
137                               uint16_t vb, uint32_t exp = 3600,
138                               uint8_t datatype = 0x00);
139void touch(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
140           uint16_t vb, uint32_t exp);
141void unl(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
142         uint16_t vb, uint64_t cas = 0);
143ENGINE_ERROR_CODE verify_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
144                             const char* key, uint16_t vbucket = 0);
145bool verify_vbucket_missing(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
146                            uint16_t vb);
147bool verify_vbucket_state(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, uint16_t vb,
148                          vbucket_state_t expected, bool mute = false);
149
150void sendUprAck(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
151                const void* cookie, protocol_binary_command opcode,
152                protocol_binary_response_status status, uint32_t opaque);
153
154// Checkpoint Operations
155void createCheckpoint(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
156void extendCheckpoint(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
157                      uint32_t checkpoint_num);
158ENGINE_ERROR_CODE checkpointPersistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
159                                        uint64_t checkpoint_id, uint16_t vb);
160ENGINE_ERROR_CODE seqnoPersistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
161                                   uint16_t vbucket, uint64_t seqno);
162
163// Stats Operations
164int get_int_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *statname,
165                 const char *statkey = NULL);
166uint64_t get_ull_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *statname,
167                      const char *statkey);
168std::string get_str_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
169                         const char *statname, const char *statkey = NULL);
170void verify_curr_items(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, int exp,
171                       const char *msg);
172void wait_for_stat_change(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
173                          const char *stat, int initial);
174void wait_for_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *stat,
175                         int final, const char* stat_key = NULL);
176void wait_for_str_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
177                             const char *stat, const char* final,
178                             const char* stat_key);
179bool wait_for_warmup_complete(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
180void wait_for_flusher_to_settle(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
181void wait_for_persisted_value(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
182                              const char *key, const char *val,
183                              uint16_t vbucketId = 0);
184
185void wait_for_memory_usage_below(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
186                                 int mem_threshold);
187
188// Tap Operations
189void changeVBFilter(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, std::string name,
190                    std::map<uint16_t, uint64_t> &filtermap);
191
192// VBucket operations
193void vbucketDelete(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, uint16_t vb,
194                   const char* args = NULL);
195
196void compact_db(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
197                const uint16_t vbid,
198                const uint64_t purge_before_ts,
199                const uint64_t purge_before_seq,
200                const uint8_t  drop_deletes);
201
202// XDCR Operations
203void add_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
204                   const size_t keylen, const char *val, const size_t vallen,
205                   const uint32_t vb, ItemMetaData *itemMeta,
206                   bool skipConflictResolution = false);
207bool get_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key);
208void del_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
209                   const size_t keylen, const uint32_t vb,
210                   ItemMetaData *itemMeta, uint64_t cas_for_delete = 0,
211                   bool skipConflictResolution = false);
212void set_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
213                   const size_t keylen, const char *val, const size_t vallen,
214                   const uint32_t vb, ItemMetaData *itemMeta,
215                   uint64_t cas_for_set, bool skipConflictResolution = false,
216                   uint8_t datatype = 0x00);
217void return_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
218                 const size_t keylen, const char *val, const size_t vallen,
219                 const uint32_t vb, const uint64_t cas, const uint32_t flags,
220                 const uint32_t exp, const uint32_t type,
221                 uint8_t datatype = 0x00);
222void set_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
223                  const size_t keylen, const char *val, const size_t vallen,
224                  const uint32_t vb, const uint64_t cas = 0,
225                  const uint32_t flags = 0, const uint32_t exp = 0,
226                  uint8_t datatype = 0x00);
227void add_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
228                  const size_t keylen, const char *val, const size_t vallen,
229                  const uint32_t vb, const uint64_t cas = 0,
230                  const uint32_t flags = 0, const uint32_t exp = 0,
231                  uint8_t datatype = 0x00);
232void del_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
233                  const size_t keylen, const uint32_t vb,
234                  const uint64_t cas = 0);
235
236// UPR Operations
237void upr_step(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const void* cookie);
238
239#endif  // TESTS_EP_TEST_APIS_H_
240