libcouchbase 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/libcouchbase/cmake/Modules/GetLibcouchbaseFlags.cmake +1 -0
- data/ext/libcouchbase/cmake/source_files.cmake +2 -2
- data/ext/libcouchbase/contrib/cliopts/cliopts.c +32 -1
- data/ext/libcouchbase/contrib/cliopts/cliopts.h +9 -1
- data/ext/libcouchbase/src/aspend.h +9 -10
- data/ext/libcouchbase/src/connspec.h +13 -0
- data/ext/libcouchbase/src/instance.cc +26 -34
- data/ext/libcouchbase/src/mcserver/negotiate.cc +617 -0
- data/ext/libcouchbase/src/mcserver/negotiate.h +1 -1
- data/ext/libcouchbase/src/n1ql/params.cc +1 -1
- data/ext/libcouchbase/src/packetutils.h +88 -2
- data/ext/libcouchbase/tests/iotests/t_misc.cc +20 -0
- data/ext/libcouchbase/tools/cbc-handlers.h +5 -5
- data/ext/libcouchbase/tools/cbc.cc +10 -1
- data/ext/libcouchbase/tools/docgen/docgen.h +1 -1
- data/lib/libcouchbase/bucket.rb +28 -5
- data/lib/libcouchbase/connection.rb +14 -2
- data/lib/libcouchbase/version.rb +1 -1
- data/spec/bucket_spec.rb +6 -0
- data/spec/connection_spec.rb +5 -0
- data/spec/fts_spec.rb +6 -0
- data/spec/n1ql_spec.rb +5 -0
- data/spec/view_spec.rb +6 -0
- metadata +3 -6
- data/ext/libcouchbase/src/hashset.c +0 -164
- data/ext/libcouchbase/src/hashset.h +0 -86
- data/ext/libcouchbase/src/mcserver/negotiate.c +0 -657
- data/ext/libcouchbase/tests/basic/t_hashset.cc +0 -262
@@ -1,262 +0,0 @@
|
|
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
|
-
#include "config.h"
|
19
|
-
#include <libcouchbase/couchbase.h>
|
20
|
-
#include "hashset.h"
|
21
|
-
#include <gtest/gtest.h>
|
22
|
-
#include <vector>
|
23
|
-
|
24
|
-
#ifdef _MSC_VER
|
25
|
-
/* We get a ton of these warnings inside the file */
|
26
|
-
#pragma message( __FILE__ ": Disabling C4800 (cast-to-bool performance)" )
|
27
|
-
#pragma warning( disable : 4800 )
|
28
|
-
#endif /* _MSC_VER */
|
29
|
-
|
30
|
-
class Hashset : public ::testing::Test
|
31
|
-
{
|
32
|
-
public:
|
33
|
-
virtual void SetUp(void) {
|
34
|
-
set = hashset_create();
|
35
|
-
ASSERT_NE((hashset_t)NULL, set);
|
36
|
-
}
|
37
|
-
|
38
|
-
virtual void TearDown(void) {
|
39
|
-
hashset_destroy(set);
|
40
|
-
}
|
41
|
-
|
42
|
-
protected:
|
43
|
-
hashset_t set;
|
44
|
-
};
|
45
|
-
|
46
|
-
TEST_F(Hashset, trivial)
|
47
|
-
{
|
48
|
-
char *missing = (char *)"missing";
|
49
|
-
char *items[] = {(char *)"zero", (char *)"one",
|
50
|
-
(char *)"two", (char *)"three", NULL
|
51
|
-
};
|
52
|
-
char *foo = (char *)"foo";
|
53
|
-
size_t ii, nitems = 4;
|
54
|
-
|
55
|
-
for (ii = 0; ii < nitems; ++ii) {
|
56
|
-
hashset_add(set, items[ii]);
|
57
|
-
}
|
58
|
-
|
59
|
-
for (ii = 0; ii < nitems; ++ii) {
|
60
|
-
assert(hashset_is_member(set, items[ii]));
|
61
|
-
}
|
62
|
-
|
63
|
-
EXPECT_EQ(0, hashset_is_member(set, missing));
|
64
|
-
EXPECT_EQ(1, hashset_remove(set, items[1]));
|
65
|
-
EXPECT_EQ(3, hashset_num_items(set));
|
66
|
-
EXPECT_EQ(0, hashset_remove(set, items[1]));
|
67
|
-
|
68
|
-
EXPECT_EQ(1, hashset_add(set, foo));
|
69
|
-
EXPECT_EQ(0, hashset_add(set, foo));
|
70
|
-
}
|
71
|
-
|
72
|
-
TEST_F(Hashset, testGaps)
|
73
|
-
{
|
74
|
-
/* fill the hashset */
|
75
|
-
EXPECT_NE(0, hashset_add(set, (void *)0xbabe));
|
76
|
-
EXPECT_NE(0, hashset_add(set, (void *)0xbeef));
|
77
|
-
EXPECT_NE(0, hashset_add(set, (void *)0xbad));
|
78
|
-
EXPECT_NE(0, hashset_add(set, (void *)0xf00d));
|
79
|
-
/* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0xbeef */
|
80
|
-
|
81
|
-
/* make a gap */
|
82
|
-
EXPECT_NE(0, hashset_remove(set, (void *)0xbeef));
|
83
|
-
/* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0x1 */
|
84
|
-
|
85
|
-
/* check that 0xf00d is still reachable */
|
86
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)0xf00d));
|
87
|
-
|
88
|
-
/* add 0xbeef back */
|
89
|
-
EXPECT_NE(0, hashset_add(set, (void *)0xbeef));
|
90
|
-
/* 0xf00d (nil) (nil) (nil) (nil) 0xbad 0xbabe 0xbeef */
|
91
|
-
|
92
|
-
/* verify */
|
93
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)0xbeef));
|
94
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)0xf00d));
|
95
|
-
}
|
96
|
-
|
97
|
-
TEST_F(Hashset, testExceptions)
|
98
|
-
{
|
99
|
-
EXPECT_EQ(-1, hashset_add(set, (void *)0));
|
100
|
-
EXPECT_EQ(-1, hashset_add(set, (void *)1));
|
101
|
-
}
|
102
|
-
|
103
|
-
TEST_F(Hashset, testRehashingItemsPlacedBeyondNumItems)
|
104
|
-
{
|
105
|
-
EXPECT_TRUE(hashset_add(set, (void *)20644128));
|
106
|
-
EXPECT_TRUE(hashset_add(set, (void *)21747760));
|
107
|
-
EXPECT_TRUE(hashset_add(set, (void *)17204864));
|
108
|
-
EXPECT_TRUE(hashset_add(set, (void *)22937440));
|
109
|
-
EXPECT_TRUE(hashset_add(set, (void *)14734272));
|
110
|
-
EXPECT_TRUE(hashset_add(set, (void *)13948320));
|
111
|
-
EXPECT_TRUE(hashset_add(set, (void *)18116496));
|
112
|
-
EXPECT_TRUE(hashset_add(set, (void *)18229952));
|
113
|
-
EXPECT_TRUE(hashset_add(set, (void *)20390128));
|
114
|
-
EXPECT_TRUE(hashset_add(set, (void *)23523264));
|
115
|
-
EXPECT_TRUE(hashset_add(set, (void *)22866784));
|
116
|
-
EXPECT_TRUE(hashset_add(set, (void *)17501248));
|
117
|
-
EXPECT_TRUE(hashset_add(set, (void *)17168832));
|
118
|
-
EXPECT_TRUE(hashset_add(set, (void *)13389824));
|
119
|
-
EXPECT_TRUE(hashset_add(set, (void *)15795136));
|
120
|
-
EXPECT_TRUE(hashset_add(set, (void *)15154464));
|
121
|
-
EXPECT_TRUE(hashset_add(set, (void *)22507840));
|
122
|
-
EXPECT_TRUE(hashset_add(set, (void *)22977920));
|
123
|
-
EXPECT_TRUE(hashset_add(set, (void *)20527584));
|
124
|
-
EXPECT_TRUE(hashset_add(set, (void *)21557872));
|
125
|
-
EXPECT_TRUE(hashset_add(set, (void *)23089952));
|
126
|
-
EXPECT_TRUE(hashset_add(set, (void *)21606240));
|
127
|
-
EXPECT_TRUE(hashset_add(set, (void *)25168704));
|
128
|
-
EXPECT_TRUE(hashset_add(set, (void *)25198096));
|
129
|
-
EXPECT_TRUE(hashset_add(set, (void *)25248000));
|
130
|
-
EXPECT_TRUE(hashset_add(set, (void *)25260976));
|
131
|
-
EXPECT_TRUE(hashset_add(set, (void *)25905520));
|
132
|
-
EXPECT_TRUE(hashset_add(set, (void *)25934608));
|
133
|
-
EXPECT_TRUE(hashset_add(set, (void *)26015264));
|
134
|
-
EXPECT_TRUE(hashset_add(set, (void *)26044352));
|
135
|
-
EXPECT_TRUE(hashset_add(set, (void *)24784800));
|
136
|
-
EXPECT_TRUE(hashset_add(set, (void *)24813888));
|
137
|
-
EXPECT_TRUE(hashset_add(set, (void *)24663936));
|
138
|
-
EXPECT_TRUE(hashset_add(set, (void *)24693536));
|
139
|
-
EXPECT_TRUE(hashset_add(set, (void *)24743792));
|
140
|
-
EXPECT_TRUE(hashset_add(set, (void *)24756480));
|
141
|
-
|
142
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)20644128));
|
143
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)21747760));
|
144
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)17204864));
|
145
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)22937440));
|
146
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)14734272));
|
147
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)13948320));
|
148
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)18116496));
|
149
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)18229952));
|
150
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)20390128));
|
151
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)23523264));
|
152
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)22866784));
|
153
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)17501248));
|
154
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)17168832));
|
155
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)13389824));
|
156
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)15795136));
|
157
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)15154464));
|
158
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)22507840));
|
159
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)22977920));
|
160
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)20527584));
|
161
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)21557872));
|
162
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)23089952));
|
163
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)21606240));
|
164
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25168704));
|
165
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25198096));
|
166
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25248000));
|
167
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25260976));
|
168
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25905520));
|
169
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)25934608));
|
170
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)26015264));
|
171
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)26044352));
|
172
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24784800));
|
173
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24813888));
|
174
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24663936));
|
175
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24693536));
|
176
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24743792));
|
177
|
-
EXPECT_TRUE(hashset_is_member(set, (void *)24756480));
|
178
|
-
}
|
179
|
-
|
180
|
-
static void hsXref(hashset_t hs,
|
181
|
-
void **itemarry,
|
182
|
-
const std::set<size_t> &src)
|
183
|
-
{
|
184
|
-
// Cross-reference stuff here
|
185
|
-
std::set<size_t> got;
|
186
|
-
|
187
|
-
size_t n_items = hashset_num_items(hs);
|
188
|
-
ASSERT_EQ(n_items, src.size());
|
189
|
-
|
190
|
-
for (unsigned ii = 0; ii < n_items; ii++) {
|
191
|
-
|
192
|
-
size_t cur = (size_t) itemarry[ii];
|
193
|
-
|
194
|
-
ASSERT_TRUE(hashset_is_member(hs, (void *)cur));
|
195
|
-
ASSERT_TRUE(src.find(cur) != src.end());
|
196
|
-
|
197
|
-
got.insert(cur);
|
198
|
-
}
|
199
|
-
|
200
|
-
ASSERT_EQ(src.size(), got.size());
|
201
|
-
|
202
|
-
for (std::set<size_t>::const_iterator iter = src.begin();
|
203
|
-
iter != src.end();
|
204
|
-
iter++) {
|
205
|
-
|
206
|
-
ASSERT_TRUE(got.find(*iter) != got.end());
|
207
|
-
}
|
208
|
-
}
|
209
|
-
|
210
|
-
TEST_F(Hashset, testGetAll)
|
211
|
-
{
|
212
|
-
std::set<size_t> items, items_base;
|
213
|
-
items_base.insert(0xdeadbeef);
|
214
|
-
items_base.insert(0xbeef);
|
215
|
-
items_base.insert(0xcafe);
|
216
|
-
items_base.insert(0xbabe);
|
217
|
-
items_base.insert(0xf00d);
|
218
|
-
items_base.insert(0xfab);
|
219
|
-
items_base.insert(0xbad);
|
220
|
-
|
221
|
-
// Fill it up
|
222
|
-
for (std::set<size_t>::iterator iter = items_base.begin();
|
223
|
-
iter != items_base.end();
|
224
|
-
iter++) {
|
225
|
-
|
226
|
-
size_t cur = *iter;
|
227
|
-
items.insert(cur);
|
228
|
-
items.insert(cur * cur);
|
229
|
-
items.insert(cur + cur);
|
230
|
-
items.insert(cur * 3);
|
231
|
-
}
|
232
|
-
|
233
|
-
for (std::set<size_t>::iterator iter = items.begin();
|
234
|
-
iter != items.end();
|
235
|
-
iter++) {
|
236
|
-
|
237
|
-
hashset_add(set, (void *)*iter);
|
238
|
-
}
|
239
|
-
|
240
|
-
void **list_hsalloc = hashset_get_items(set, NULL);
|
241
|
-
ASSERT_TRUE(list_hsalloc != NULL);
|
242
|
-
hsXref(set, list_hsalloc, items);
|
243
|
-
free(list_hsalloc);
|
244
|
-
|
245
|
-
void **list_myalloc = (void **)malloc(
|
246
|
-
sizeof(void *) * hashset_num_items(set));
|
247
|
-
|
248
|
-
void **ret = hashset_get_items(set, list_myalloc);
|
249
|
-
|
250
|
-
ASSERT_TRUE(ret == list_myalloc);
|
251
|
-
hsXref(set, list_myalloc, items);
|
252
|
-
free(list_myalloc);
|
253
|
-
|
254
|
-
for (std::set<size_t>::iterator iter = items.begin();
|
255
|
-
iter != items.end();
|
256
|
-
iter++) {
|
257
|
-
hashset_remove(set, (void *)*iter);
|
258
|
-
}
|
259
|
-
|
260
|
-
ASSERT_EQ(0, hashset_num_items(set));
|
261
|
-
ASSERT_TRUE(NULL == hashset_get_items(set, NULL));
|
262
|
-
}
|