couchbase 1.2.0.z.beta4 → 1.2.0.z.beta5

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,16 +18,16 @@
18
18
  #include "couchbase_ext.h"
19
19
 
20
20
  void
21
- version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_server_version_resp_t *resp)
21
+ cb_version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_server_version_resp_t *resp)
22
22
  {
23
- struct context_st *ctx = (struct context_st *)cookie;
24
- struct bucket_st *bucket = ctx->bucket;
23
+ struct cb_context_st *ctx = (struct cb_context_st *)cookie;
24
+ struct cb_bucket_st *bucket = ctx->bucket;
25
25
  VALUE node, val, *rv = ctx->rv, exc, res;
26
26
 
27
27
  node = resp->v.v0.server_endpoint ? STR_NEW_CSTR(resp->v.v0.server_endpoint) : Qnil;
28
28
  exc = cb_check_error(error, "failed to get version", node);
29
29
  if (exc != Qnil) {
30
- rb_ivar_set(exc, id_iv_operation, sym_version);
30
+ rb_ivar_set(exc, cb_id_iv_operation, cb_sym_version);
31
31
  if (NIL_P(ctx->exception)) {
32
32
  ctx->exception = cb_gc_protect(bucket, exc);
33
33
  }
@@ -37,11 +37,11 @@ version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_
37
37
  val = STR_NEW((const char*)resp->v.v0.vstring, resp->v.v0.nvstring);
38
38
  if (bucket->async) { /* asynchronous */
39
39
  if (ctx->proc != Qnil) {
40
- res = rb_class_new_instance(0, NULL, cResult);
41
- rb_ivar_set(res, id_iv_error, exc);
42
- rb_ivar_set(res, id_iv_operation, sym_version);
43
- rb_ivar_set(res, id_iv_node, node);
44
- rb_ivar_set(res, id_iv_value, val);
40
+ res = rb_class_new_instance(0, NULL, cb_cResult);
41
+ rb_ivar_set(res, cb_id_iv_error, exc);
42
+ rb_ivar_set(res, cb_id_iv_operation, cb_sym_version);
43
+ rb_ivar_set(res, cb_id_iv_node, node);
44
+ rb_ivar_set(res, cb_id_iv_value, val);
45
45
  cb_proc_call(ctx->proc, 1, res);
46
46
  }
47
47
  } else { /* synchronous */
@@ -52,6 +52,9 @@ version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_
52
52
  } else {
53
53
  ctx->nqueries--;
54
54
  cb_gc_unprotect(bucket, ctx->proc);
55
+ if (bucket->async) {
56
+ xfree(ctx);
57
+ }
55
58
  }
56
59
 
57
60
  (void)handle;
@@ -87,26 +90,26 @@ version_callback(lcb_t handle, const void *cookie, lcb_error_t error, const lcb_
87
90
  VALUE
88
91
  cb_bucket_version(int argc, VALUE *argv, VALUE self)
89
92
  {
90
- struct bucket_st *bucket = DATA_PTR(self);
91
- struct context_st *ctx;
93
+ struct cb_bucket_st *bucket = DATA_PTR(self);
94
+ struct cb_context_st *ctx;
92
95
  VALUE rv, exc, args, proc;
93
96
  lcb_error_t err;
94
- struct params_st params;
97
+ struct cb_params_st params;
95
98
 
96
99
  if (bucket->handle == NULL) {
97
- rb_raise(eConnectError, "closed connection");
100
+ rb_raise(cb_eConnectError, "closed connection");
98
101
  }
99
102
  rb_scan_args(argc, argv, "0*&", &args, &proc);
100
103
  if (!bucket->async && proc != Qnil) {
101
104
  rb_raise(rb_eArgError, "synchronous mode doesn't support callbacks");
102
105
  }
103
- memset(&params, 0, sizeof(struct params_st));
104
- params.type = cmd_version;
106
+ memset(&params, 0, sizeof(struct cb_params_st));
107
+ params.type = cb_cmd_version;
105
108
  params.bucket = bucket;
106
109
  cb_params_build(&params, RARRAY_LEN(args), args);
107
- ctx = xcalloc(1, sizeof(struct context_st));
110
+ ctx = xcalloc(1, sizeof(struct cb_context_st));
108
111
  if (ctx == NULL) {
109
- rb_raise(eClientNoMemoryError, "failed to allocate memory for context");
112
+ rb_raise(cb_eClientNoMemoryError, "failed to allocate memory for context");
110
113
  }
111
114
  rv = rb_hash_new();
112
115
  ctx->rv = &rv;
@@ -124,7 +127,7 @@ cb_bucket_version(int argc, VALUE *argv, VALUE self)
124
127
  }
125
128
  bucket->nbytes += params.npayload;
126
129
  if (bucket->async) {
127
- maybe_do_loop(bucket);
130
+ cb_maybe_do_loop(bucket);
128
131
  return Qnil;
129
132
  } else {
130
133
  if (ctx->nqueries > 0) {
@@ -17,5 +17,5 @@
17
17
 
18
18
  # Couchbase ruby client
19
19
  module Couchbase
20
- VERSION = "1.2.0.z.beta4"
20
+ VERSION = "1.2.0.z.beta5"
21
21
  end
@@ -29,6 +29,24 @@ module Couchbase
29
29
  super("#{prefix}#{from}: #{reason}")
30
30
  end
31
31
  end
32
+
33
+ class HTTP < Base
34
+ attr_reader :type, :reason
35
+
36
+ def parse_body!
37
+ if @body
38
+ hash = MultiJson.load(@body)
39
+ @type = hash["error"]
40
+ @reason = hash["reason"]
41
+ end
42
+ rescue MultiJson::DecodeError
43
+ @type = @reason = nil
44
+ end
45
+
46
+ def to_s
47
+ super.sub(/ \(/, ": #{@type}: #{@reason} (")
48
+ end
49
+ end
32
50
  end
33
51
 
34
52
  # This class implements Couchbase View execution
@@ -84,7 +84,7 @@ namespace :ports do
84
84
  directory "ports"
85
85
 
86
86
  task :libcouchbase => ["ports"] do
87
- recipe = MiniPortile.new "libcouchbase", "2.0.0beta3"
87
+ recipe = MiniPortile.new "libcouchbase", "2.0.0"
88
88
  recipe.files << "http://packages.couchbase.com/clients/c/libcouchbase-#{recipe.version}.tar.gz"
89
89
  recipe.configure_options.push("--disable-debug",
90
90
  "--disable-dependency-tracking",
@@ -48,47 +48,54 @@ end
48
48
 
49
49
  Rake::Task['test'].prerequisites.unshift('test/CouchbaseMock.jar')
50
50
 
51
- desc "Run the test suite under Valgrind."
51
+ common_flags = %w[
52
+ --tool=memcheck
53
+ --error-limit=no
54
+ --undef-value-errors=no
55
+ --leak-check=full
56
+ --show-reachable=yes
57
+ --num-callers=50
58
+ --track-fds=yes
59
+ --workaround-gcc296-bugs=yes
60
+ --leak-resolution=med
61
+ --max-stackframe=7304328
62
+ --partial-loads-ok=yes
63
+ ]
64
+
65
+ desc "Run the test suite under Valgrind memcheck."
52
66
  task "test:valgrind" do
53
- ENV['RUBY_PREFIX'] = [
54
- "valgrind",
55
- "--num-callers=50",
56
- "--error-limit=no",
57
- "--partial-loads-ok=yes",
58
- "--undef-value-errors=no",
59
- "--track-fds=yes",
60
- "--leak-check=full",
61
- "--leak-resolution=med",
62
- ].join(' ')
67
+ ENV['RUBY_PREFIX'] = "valgrind #{common_flags.join(' ')}"
63
68
  Rake::Task['test'].invoke
64
69
  end
65
70
 
66
- desc "Run the test suite under Valgrind with memory-fill."
71
+ desc "Run the test suite under Valgrind memcheck with memory-fill."
67
72
  task "test:valgrind:mem_fill" do
68
- ENV['RUBY_PREFIX'] = [
69
- "valgrind",
70
- "--num-callers=50",
71
- "--error-limit=no",
72
- "--partial-loads-ok=yes",
73
- "--undef-value-errors=no",
74
- "--freelist-vol=100000000",
75
- "--malloc-fill=6D",
76
- "--free-fill=66",
77
- ].join(' ')
73
+ local_flags = %w[
74
+ --malloc-fill=6D
75
+ --freelist-vol=100000000
76
+ --free-fill=66
77
+ ]
78
+ ENV['RUBY_PREFIX'] = "valgrind #{common_flags.join(' ')} #{local_flags.join(' ')}"
78
79
  Rake::Task['test'].invoke
79
80
  end
80
81
 
81
- desc "Run the test suite under Valgrind with memory-zero."
82
+ desc "Run the test suite under Valgrind memcheck with memory-zero."
82
83
  task "test:valgrind:mem_zero" do
83
- ENV['RUBY_PREFIX'] = [
84
- "valgrind",
85
- "--num-callers=50",
86
- "--error-limit=no",
87
- "--partial-loads-ok=yes",
88
- "--undef-value-errors=no",
89
- "--freelist-vol=100000000",
90
- "--malloc-fill=00",
91
- "--free-fill=00",
92
- ].join(' ')
84
+ local_flags = %w[
85
+ --freelist-vol=100000000
86
+ --malloc-fill=00
87
+ --free-fill=00
88
+ ]
89
+ ENV['RUBY_PREFIX'] = "valgrind #{common_flags.join(' ')} #{local_flags.join(' ')}"
90
+ Rake::Task['test'].invoke
91
+ end
92
+
93
+ desc "Run the test suite under Valgrind massif."
94
+ task "test:valgrind:massif" do
95
+ local_flags = %w[
96
+ --tool=massif
97
+ --time-unit=B
98
+ ]
99
+ ENV['RUBY_PREFIX'] = "valgrind #{local_flags.join(' ')}"
93
100
  Rake::Task['test'].invoke
94
101
  end
@@ -168,4 +168,8 @@ class MiniTest::Unit::TestCase
168
168
  def uniq_id(*suffixes)
169
169
  [caller.first[/.*[` ](.*)'/, 1], suffixes].join("_")
170
170
  end
171
+
172
+ def after_teardown
173
+ GC.start
174
+ end
171
175
  end
@@ -54,6 +54,43 @@ class TestArithmetic < MiniTest::Unit::TestCase
54
54
  end
55
55
  end
56
56
 
57
+ def test_it_allows_to_make_increments_less_verbose_by_forcing_create_by_default
58
+ connection = Couchbase.connect(:hostname => @mock.host, :port => @mock.port,
59
+ :default_arithmetic_init => true)
60
+ assert_raises(Couchbase::Error::NotFound) do
61
+ connection.get(uniq_id)
62
+ end
63
+ assert_equal 0, connection.incr(uniq_id), "return value"
64
+ assert_equal 0, connection.get(uniq_id), "via get command"
65
+ end
66
+
67
+ def test_it_allows_to_setup_initial_value_during_connection
68
+ connection = Couchbase.connect(:hostname => @mock.host, :port => @mock.port,
69
+ :default_arithmetic_init => 10)
70
+ assert_raises(Couchbase::Error::NotFound) do
71
+ connection.get(uniq_id)
72
+ end
73
+ assert_equal 10, connection.incr(uniq_id), "return value"
74
+ assert_equal 10, connection.get(uniq_id), "via get command"
75
+ end
76
+
77
+ def test_it_allows_to_change_default_initial_value_after_connection
78
+ connection = Couchbase.connect(:hostname => @mock.host, :port => @mock.port)
79
+
80
+ assert_equal 0, connection.default_arithmetic_init
81
+ assert_raises(Couchbase::Error::NotFound) do
82
+ connection.incr(uniq_id)
83
+ end
84
+
85
+ connection.default_arithmetic_init = 10
86
+ assert_equal 10, connection.default_arithmetic_init
87
+ assert_raises(Couchbase::Error::NotFound) do
88
+ connection.get(uniq_id)
89
+ end
90
+ assert_equal 10, connection.incr(uniq_id), "return value"
91
+ assert_equal 10, connection.get(uniq_id), "via get command"
92
+ end
93
+
57
94
  def test_it_creates_missing_key_when_initial_value_specified
58
95
  connection = Couchbase.new(:hostname => @mock.host, :port => @mock.port)
59
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: couchbase
3
3
  version: !ruby/object:Gem::Version
4
- hash: 4727249961
4
+ hash: -6450534404
5
5
  prerelease: 6
6
6
  segments:
7
7
  - 1
@@ -9,8 +9,8 @@ version: !ruby/object:Gem::Version
9
9
  - 0
10
10
  - z
11
11
  - beta
12
- - 4
13
- version: 1.2.0.z.beta4
12
+ - 5
13
+ version: 1.2.0.z.beta5
14
14
  platform: ruby
15
15
  authors:
16
16
  - Couchbase
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2012-11-21 00:00:00 +03:00
21
+ date: 2012-11-29 00:00:00 +03:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -311,25 +311,5 @@ rubygems_version: 1.6.2
311
311
  signing_key:
312
312
  specification_version: 3
313
313
  summary: Couchbase ruby driver
314
- test_files:
315
- - test/profile/.gitignore
316
- - test/profile/Gemfile
317
- - test/profile/benchmark.rb
318
- - test/setup.rb
319
- - test/test_arithmetic.rb
320
- - test/test_async.rb
321
- - test/test_bucket.rb
322
- - test/test_cas.rb
323
- - test/test_couchbase.rb
324
- - test/test_couchbase_rails_cache_store.rb
325
- - test/test_delete.rb
326
- - test/test_errors.rb
327
- - test/test_format.rb
328
- - test/test_get.rb
329
- - test/test_stats.rb
330
- - test/test_store.rb
331
- - test/test_timer.rb
332
- - test/test_touch.rb
333
- - test/test_unlock.rb
334
- - test/test_utils.rb
335
- - test/test_version.rb
314
+ test_files: []
315
+