1ccdfed7dSMike Wiederhold/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2ccdfed7dSMike Wiederhold/*
366eb94d0SMike Wiederhold *     Copyright 2012 Couchbase, Inc
4ccdfed7dSMike Wiederhold *
5ccdfed7dSMike Wiederhold *   Licensed under the Apache License, Version 2.0 (the "License");
6ccdfed7dSMike Wiederhold *   you may not use this file except in compliance with the License.
7ccdfed7dSMike Wiederhold *   You may obtain a copy of the License at
8ccdfed7dSMike Wiederhold *
9ccdfed7dSMike Wiederhold *       http://www.apache.org/licenses/LICENSE-2.0
10ccdfed7dSMike Wiederhold *
11ccdfed7dSMike Wiederhold *   Unless required by applicable law or agreed to in writing, software
12ccdfed7dSMike Wiederhold *   distributed under the License is distributed on an "AS IS" BASIS,
13ccdfed7dSMike Wiederhold *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14ccdfed7dSMike Wiederhold *   See the License for the specific language governing permissions and
15ccdfed7dSMike Wiederhold *   limitations under the License.
16ccdfed7dSMike Wiederhold */
17ccdfed7dSMike Wiederhold
188f48f64bSMike Wiederhold#ifndef TESTS_EP_TEST_APIS_H_
198f48f64bSMike Wiederhold#define TESTS_EP_TEST_APIS_H_ 1
20ccdfed7dSMike Wiederhold
21244c0146SMike Wiederhold#include "config.h"
22ccdfed7dSMike Wiederhold
23ccdfed7dSMike Wiederhold#include <memcached/engine.h>
24ccdfed7dSMike Wiederhold#include <memcached/engine_testapp.h>
25ccdfed7dSMike Wiederhold
26244c0146SMike Wiederhold#include <map>
27244c0146SMike Wiederhold#include <string>
28244c0146SMike Wiederhold
29ccdfed7dSMike Wiederhold#include "ep-engine/command_ids.h"
30fc9615cdSMike Wiederhold#include "item.h"
31ccdfed7dSMike Wiederhold
32ccdfed7dSMike Wiederhold#ifdef __cplusplus
33ccdfed7dSMike Wiederholdextern "C" {
34ccdfed7dSMike Wiederhold#endif
35ccdfed7dSMike Wiederhold
36ccdfed7dSMike Wiederholdbool add_response(const void *key, uint16_t keylen, const void *ext,
37ccdfed7dSMike Wiederhold                  uint8_t extlen, const void *body, uint32_t bodylen,
38ccdfed7dSMike Wiederhold                  uint8_t datatype, uint16_t status, uint64_t cas,
39ccdfed7dSMike Wiederhold                  const void *cookie);
40ccdfed7dSMike Wiederhold
41ccdfed7dSMike Wiederholdvoid add_stats(const char *key, const uint16_t klen, const char *val,
42ccdfed7dSMike Wiederhold               const uint32_t vlen, const void *cookie);
43ccdfed7dSMike Wiederhold
44de6d1bf1SabhinavdangetiENGINE_ERROR_CODE vb_map_response(const void *cookie, const void *map,
45de6d1bf1Sabhinavdangeti                                  size_t mapsize);
471364ee8eSTrond Norbye#ifdef __cplusplus
481364ee8eSTrond Norbye}
491364ee8eSTrond Norbye#endif
501364ee8eSTrond Norbye
51d0d91da7STrond Norbyeextern protocol_binary_response_status last_status;
52d0d91da7STrond Norbyeextern char *last_key;
53d0d91da7STrond Norbyeextern char *last_body;
54d0d91da7STrond Norbyeextern bool dump_stats;
55d0d91da7STrond Norbyeextern std::map<std::string, std::string> vals;
56d0d91da7STrond Norbyeextern uint32_t last_bodylen;
57d0d91da7STrond Norbyeextern uint64_t last_cas;
58c7dadb61Sabhinavdangetiextern uint8_t last_datatype;
59d0d91da7STrond Norbyeextern bool last_deleted_flag;
60d0d91da7STrond Norbyeextern ItemMetaData last_meta;
61d0d91da7STrond Norbye
6290defd6dSMike Wiederholdextern uint8_t dcp_last_op;
6390defd6dSMike Wiederholdextern uint8_t dcp_last_status;
6490defd6dSMike Wiederholdextern uint8_t dcp_last_nru;
6590defd6dSMike Wiederholdextern uint16_t dcp_last_vbucket;
6690defd6dSMike Wiederholdextern uint32_t dcp_last_opaque;
6790defd6dSMike Wiederholdextern uint32_t dcp_last_flags;
6890defd6dSMike Wiederholdextern uint32_t dcp_last_stream_opaque;
6990defd6dSMike Wiederholdextern uint32_t dcp_last_locktime;
7090defd6dSMike Wiederholdextern uint32_t dcp_last_packet_size;
7190defd6dSMike Wiederholdextern uint64_t dcp_last_cas;
7290defd6dSMike Wiederholdextern uint64_t dcp_last_start_seqno;
7390defd6dSMike Wiederholdextern uint64_t dcp_last_end_seqno;
7490defd6dSMike Wiederholdextern uint64_t dcp_last_vbucket_uuid;
7590defd6dSMike Wiederholdextern uint64_t dcp_last_high_seqno;
7690defd6dSMike Wiederholdextern uint64_t dcp_last_byseqno;
7790defd6dSMike Wiederholdextern uint64_t dcp_last_revseqno;
7890defd6dSMike Wiederholdextern uint64_t dcp_last_snap_start_seqno;
7990defd6dSMike Wiederholdextern uint64_t dcp_last_snap_end_seqno;
8090defd6dSMike Wiederholdextern std::string dcp_last_key;
8190defd6dSMike Wiederholdextern vbucket_state_t dcp_last_vbucket_state;
82d0d91da7STrond Norbye
83d0d91da7STrond Norbye
841364ee8eSTrond Norbyevoid decayingSleep(useconds_t *sleepTime);
851364ee8eSTrond Norbye
861364ee8eSTrond Norbye
87ccdfed7dSMike Wiederholdprotocol_binary_request_header* createPacket(uint8_t opcode,
88ccdfed7dSMike Wiederhold                                             uint16_t vbid = 0,
89ccdfed7dSMike Wiederhold                                             uint64_t cas = 0,
90ccdfed7dSMike Wiederhold                                             const char *ext = NULL,
91e158e16eSSundar Sridharan                                             uint8_t extlen = 0,
92ccdfed7dSMike Wiederhold                                             const char *key = NULL,
93ccdfed7dSMike Wiederhold                                             uint32_t keylen = 0,
94ccdfed7dSMike Wiederhold                                             const char *val = NULL,
95284f2826Sabhinavdangeti                                             uint32_t vallen = 0,
96284f2826Sabhinavdangeti                                             uint8_t datatype = 0x00);
97ccdfed7dSMike Wiederhold
98ccdfed7dSMike Wiederhold// Basic Operations
990b8fd7deSMike WiederholdENGINE_ERROR_CODE del(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
1000b8fd7deSMike Wiederhold                      uint64_t cas, uint16_t vbucket, const void* cookie = NULL);
101b4fc25d3SMike Wiederholdvoid disable_traffic(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
102b4fc25d3SMike Wiederholdvoid enable_traffic(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
103ccdfed7dSMike Wiederholdvoid evict_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
104ccdfed7dSMike Wiederhold               uint16_t vbucketId = 0, const char *msg = NULL,
105ccdfed7dSMike Wiederhold               bool expectError = false);
106ad6475b0SMike Wiederholdsize_t estimateVBucketMove(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
107ad6475b0SMike Wiederhold                           uint16_t vbid = 0, const char* tap_name = "");
108ccdfed7dSMike Wiederholdvoid gat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
109ccdfed7dSMike Wiederhold         uint16_t vb, uint32_t exp, bool quiet = false);
110ecc1177cSMike Wiederholdbool get_item_info(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, item_info *info,
111ecc1177cSMike Wiederhold                   const char* key, uint16_t vb = 0);
112ccdfed7dSMike Wiederholdbool get_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, item *i,
113ccdfed7dSMike Wiederhold             std::string &key);
114ccdfed7dSMike Wiederholdvoid getl(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key, uint16_t vb,
115ccdfed7dSMike Wiederhold          uint32_t lock_timeout);
1168f0f3d4fSMike Wiederholdvoid get_replica(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
1178f0f3d4fSMike Wiederhold                 uint16_t vb);
118ccdfed7dSMike Wiederholdvoid observe(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
119ccdfed7dSMike Wiederhold             std::map<std::string, uint16_t> obskeys);
120ccdfed7dSMike Wiederholdprotocol_binary_request_header* prepare_get_replica(ENGINE_HANDLE *h,
121ccdfed7dSMike Wiederhold                                                    ENGINE_HANDLE_V1 *h1,
122ccdfed7dSMike Wiederhold                                                    vbucket_state_t state,
123ccdfed7dSMike Wiederhold                                                    bool makeinvalidkey = false);
1240389c521STrond Norbyebool set_param(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, protocol_binary_engine_param_t paramtype,
125ccdfed7dSMike Wiederhold               const char *param, const char *val);
126ccdfed7dSMike Wiederholdbool set_vbucket_state(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
127ccdfed7dSMike Wiederhold                       uint16_t vb, vbucket_state_t state);
128ccdfed7dSMike Wiederholdvoid start_persistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
129ccdfed7dSMike Wiederholdvoid stop_persistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
130ccdfed7dSMike WiederholdENGINE_ERROR_CODE store(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
131ccdfed7dSMike Wiederhold                        const void *cookie, ENGINE_STORE_OPERATION op,
132ccdfed7dSMike Wiederhold                        const char *key, const char *value, item **outitem,
133ad6475b0SMike Wiederhold                        uint64_t casIn = 0, uint16_t vb = 0,
13409036c32Sabhinavdangeti                        uint32_t exp = 3600, uint8_t datatype = 0x00);
135ccdfed7dSMike WiederholdENGINE_ERROR_CODE storeCasVb11(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
136ccdfed7dSMike Wiederhold                               const void *cookie, ENGINE_STORE_OPERATION op,
137ccdfed7dSMike Wiederhold                               const char *key, const char *value, size_t vlen,
138ccdfed7dSMike Wiederhold                               uint32_t flags, item **outitem, uint64_t casIn,
13982a6f303Sabhinavdangeti                               uint16_t vb, uint32_t exp = 3600,
14082a6f303Sabhinavdangeti                               uint8_t datatype = 0x00);
141ccdfed7dSMike Wiederholdvoid touch(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
142ccdfed7dSMike Wiederhold           uint16_t vb, uint32_t exp);
143ccdfed7dSMike Wiederholdvoid unl(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key,
144ccdfed7dSMike Wiederhold         uint16_t vb, uint64_t cas = 0);
145ccdfed7dSMike WiederholdENGINE_ERROR_CODE verify_key(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
1468eae74acSMike Wiederhold                             const char* key, uint16_t vbucket = 0);
147ccdfed7dSMike Wiederholdbool verify_vbucket_missing(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
148ccdfed7dSMike Wiederhold                            uint16_t vb);
149ccdfed7dSMike Wiederholdbool verify_vbucket_state(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, uint16_t vb,
150ccdfed7dSMike Wiederhold                          vbucket_state_t expected, bool mute = false);
151ccdfed7dSMike Wiederhold
15290defd6dSMike Wiederholdvoid sendDcpAck(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
153bb53d322SMike Wiederhold                const void* cookie, protocol_binary_command opcode,
154bb53d322SMike Wiederhold                protocol_binary_response_status status, uint32_t opaque);
155bb53d322SMike Wiederhold
156ccdfed7dSMike Wiederhold// Checkpoint Operations
157ccdfed7dSMike Wiederholdvoid createCheckpoint(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
158ccdfed7dSMike Wiederholdvoid extendCheckpoint(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
159ccdfed7dSMike Wiederhold                      uint32_t checkpoint_num);
160e9ce8770SChiyoung SeoENGINE_ERROR_CODE checkpointPersistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
16192cd2dedSMike Wiederhold                                        uint64_t checkpoint_id, uint16_t vb);
16279a9d87dSDavid LiaoENGINE_ERROR_CODE seqnoPersistence(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
16387e974b8SMike Wiederhold                                   uint16_t vbucket, uint64_t seqno);
164ccdfed7dSMike Wiederhold
165ccdfed7dSMike Wiederhold// Stats Operations
166ccdfed7dSMike Wiederholdint get_int_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *statname,
167ccdfed7dSMike Wiederhold                 const char *statkey = NULL);
168d221295cSMike Wiederholduint64_t get_ull_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *statname,
169d221295cSMike Wiederhold                      const char *statkey);
170ccdfed7dSMike Wiederholdstd::string get_str_stat(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
171ccdfed7dSMike Wiederhold                         const char *statname, const char *statkey = NULL);
172ccdfed7dSMike Wiederholdvoid verify_curr_items(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, int exp,
173ccdfed7dSMike Wiederhold                       const char *msg);
174ccdfed7dSMike Wiederholdvoid wait_for_stat_change(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
175c0465074SMike Wiederhold                          const char *stat, int initial,
176c0465074SMike Wiederhold                          const char *statkey = NULL);
177ccdfed7dSMike Wiederholdvoid wait_for_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *stat,
178ccdfed7dSMike Wiederhold                         int final, const char* stat_key = NULL);
179f375e172SMike Wiederholdvoid wait_for_str_stat_to_be(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
180f375e172SMike Wiederhold                             const char *stat, const char* final,
181f375e172SMike Wiederhold                             const char* stat_key);
182ccdfed7dSMike Wiederholdbool wait_for_warmup_complete(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
183ccdfed7dSMike Wiederholdvoid wait_for_flusher_to_settle(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1);
184ccdfed7dSMike Wiederholdvoid wait_for_persisted_value(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
185ccdfed7dSMike Wiederhold                              const char *key, const char *val,
186ccdfed7dSMike Wiederhold                              uint16_t vbucketId = 0);
187ccdfed7dSMike Wiederhold
1885691d832SChiyoung Seovoid wait_for_memory_usage_below(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
1895691d832SChiyoung Seo                                 int mem_threshold);
1905691d832SChiyoung Seo
191ccdfed7dSMike Wiederhold// Tap Operations
192ccdfed7dSMike Wiederholdvoid changeVBFilter(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, std::string name,
1936823c66eSMike Wiederhold                    std::map<uint16_t, uint64_t> &filtermap);
194ccdfed7dSMike Wiederhold
195ccdfed7dSMike Wiederhold// VBucket operations
196ccdfed7dSMike Wiederholdvoid vbucketDelete(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, uint16_t vb,
197ccdfed7dSMike Wiederhold                   const char* args = NULL);
198ccdfed7dSMike Wiederhold
199e158e16eSSundar Sridharanvoid compact_db(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1,
200e158e16eSSundar Sridharan                const uint16_t vbid,
201e158e16eSSundar Sridharan                const uint64_t purge_before_ts,
202e158e16eSSundar Sridharan                const uint64_t purge_before_seq,
203e158e16eSSundar Sridharan                const uint8_t  drop_deletes);
204e158e16eSSundar Sridharan
205ccdfed7dSMike Wiederhold// XDCR Operations
206ccdfed7dSMike Wiederholdvoid add_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
207ccdfed7dSMike Wiederhold                   const size_t keylen, const char *val, const size_t vallen,
208d43a1deeSMike Wiederhold                   const uint32_t vb, ItemMetaData *itemMeta,
209d43a1deeSMike Wiederhold                   bool skipConflictResolution = false);
210b4a94111SMike Wiederholdbool get_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char* key);
211ccdfed7dSMike Wiederholdvoid del_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
212ccdfed7dSMike Wiederhold                   const size_t keylen, const uint32_t vb,
213d43a1deeSMike Wiederhold                   ItemMetaData *itemMeta, uint64_t cas_for_delete = 0,
214d43a1deeSMike Wiederhold                   bool skipConflictResolution = false);
215ccdfed7dSMike Wiederholdvoid set_with_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
216ccdfed7dSMike Wiederhold                   const size_t keylen, const char *val, const size_t vallen,
217ccdfed7dSMike Wiederhold                   const uint32_t vb, ItemMetaData *itemMeta,
2185e1d9fb4Sabhinavdangeti                   uint64_t cas_for_set, bool skipConflictResolution = false,
2195e1d9fb4Sabhinavdangeti                   uint8_t datatype = 0x00);
220b4fc25d3SMike Wiederholdvoid return_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
221b4fc25d3SMike Wiederhold                 const size_t keylen, const char *val, const size_t vallen,
222b4fc25d3SMike Wiederhold                 const uint32_t vb, const uint64_t cas, const uint32_t flags,
223029716c5Sabhinavdangeti                 const uint32_t exp, const uint32_t type,
224029716c5Sabhinavdangeti                 uint8_t datatype = 0x00);
225b4fc25d3SMike Wiederholdvoid set_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
226b4fc25d3SMike Wiederhold                  const size_t keylen, const char *val, const size_t vallen,
227b4fc25d3SMike Wiederhold                  const uint32_t vb, const uint64_t cas = 0,
228029716c5Sabhinavdangeti                  const uint32_t flags = 0, const uint32_t exp = 0,
229029716c5Sabhinavdangeti                  uint8_t datatype = 0x00);
230b4fc25d3SMike Wiederholdvoid add_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
231b4fc25d3SMike Wiederhold                  const size_t keylen, const char *val, const size_t vallen,
232b4fc25d3SMike Wiederhold                  const uint32_t vb, const uint64_t cas = 0,
233029716c5Sabhinavdangeti                  const uint32_t flags = 0, const uint32_t exp = 0,
234029716c5Sabhinavdangeti                  uint8_t datatype = 0x00);
235b4fc25d3SMike Wiederholdvoid del_ret_meta(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const char *key,
236b4fc25d3SMike Wiederhold                  const size_t keylen, const uint32_t vb,
237b4fc25d3SMike Wiederhold                  const uint64_t cas = 0);
238ccdfed7dSMike Wiederhold
23990defd6dSMike Wiederhold// DCP Operations
24090defd6dSMike Wiederholdvoid dcp_step(ENGINE_HANDLE *h, ENGINE_HANDLE_V1 *h1, const void* cookie);
241df07f52aSMike Wiederhold
2428f48f64bSMike Wiederhold#endif  // TESTS_EP_TEST_APIS_H_