Skip to content

Commit 15e586b

Browse files
authored
Update bucket settings to be compatible with dp9 and not set defaults for optional fields (#121)
1 parent ab1b94d commit 15e586b

File tree

7 files changed

+36
-44
lines changed

7 files changed

+36
-44
lines changed

ext/couchbase.cxx

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4370,18 +4370,20 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
43704370
static void
43714371
cb_generate_bucket_settings(VALUE bucket, couchbase::core::management::cluster::bucket_settings& entry, bool is_create)
43724372
{
4373-
if (VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type"))); TYPE(bucket_type) == T_SYMBOL) {
4374-
if (bucket_type == rb_id2sym(rb_intern("couchbase")) || bucket_type == rb_id2sym(rb_intern("membase"))) {
4375-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::couchbase;
4376-
} else if (bucket_type == rb_id2sym(rb_intern("memcached"))) {
4377-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::memcached;
4378-
} else if (bucket_type == rb_id2sym(rb_intern("ephemeral"))) {
4379-
entry.bucket_type = couchbase::core::management::cluster::bucket_type::ephemeral;
4373+
if (VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type"))); !NIL_P(bucket_type)) {
4374+
if (TYPE(bucket_type) == T_SYMBOL) {
4375+
if (bucket_type == rb_id2sym(rb_intern("couchbase")) || bucket_type == rb_id2sym(rb_intern("membase"))) {
4376+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::couchbase;
4377+
} else if (bucket_type == rb_id2sym(rb_intern("memcached"))) {
4378+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::memcached;
4379+
} else if (bucket_type == rb_id2sym(rb_intern("ephemeral"))) {
4380+
entry.bucket_type = couchbase::core::management::cluster::bucket_type::ephemeral;
4381+
} else {
4382+
throw ruby_exception(rb_eArgError, rb_sprintf("unknown bucket type, given %+" PRIsVALUE, bucket_type));
4383+
}
43804384
} else {
4381-
throw ruby_exception(rb_eArgError, rb_sprintf("unknown bucket type, given %+" PRIsVALUE, bucket_type));
4385+
throw ruby_exception(rb_eArgError, rb_sprintf("bucket type must be a Symbol, given %+" PRIsVALUE, bucket_type));
43824386
}
4383-
} else {
4384-
throw ruby_exception(rb_eArgError, rb_sprintf("bucket type must be a Symbol, given %+" PRIsVALUE, bucket_type));
43854387
}
43864388

43874389
if (VALUE name = rb_hash_aref(bucket, rb_id2sym(rb_intern("name"))); TYPE(name) == T_STRING) {
@@ -4390,10 +4392,12 @@ cb_generate_bucket_settings(VALUE bucket, couchbase::core::management::cluster::
43904392
throw ruby_exception(rb_eArgError, rb_sprintf("bucket name must be a String, given %+" PRIsVALUE, name));
43914393
}
43924394

4393-
if (VALUE quota = rb_hash_aref(bucket, rb_id2sym(rb_intern("ram_quota_mb"))); TYPE(quota) == T_FIXNUM) {
4394-
entry.ram_quota_mb = FIX2ULONG(quota);
4395-
} else {
4396-
throw ruby_exception(rb_eArgError, rb_sprintf("bucket RAM quota must be an Integer, given %+" PRIsVALUE, quota));
4395+
if (VALUE quota = rb_hash_aref(bucket, rb_id2sym(rb_intern("ram_quota_mb"))); !NIL_P(quota)) {
4396+
if (TYPE(quota) == T_FIXNUM) {
4397+
entry.ram_quota_mb = FIX2ULONG(quota);
4398+
} else {
4399+
throw ruby_exception(rb_eArgError, rb_sprintf("bucket RAM quota must be an Integer, given %+" PRIsVALUE, quota));
4400+
}
43974401
}
43984402

43994403
if (VALUE expiry = rb_hash_aref(bucket, rb_id2sym(rb_intern("max_expiry"))); !NIL_P(expiry)) {
@@ -4679,7 +4683,7 @@ cb_extract_bucket_settings(const couchbase::core::management::cluster::bucket_se
46794683
rb_hash_aset(bucket, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
46804684
rb_hash_aset(bucket, rb_id2sym(rb_intern("uuid")), cb_str_new(entry.uuid));
46814685
rb_hash_aset(bucket, rb_id2sym(rb_intern("ram_quota_mb")), ULL2NUM(entry.ram_quota_mb));
4682-
if (const auto &val = entry.max_expiry; val.has_value()) {
4686+
if (const auto& val = entry.max_expiry; val.has_value()) {
46834687
rb_hash_aset(bucket, rb_id2sym(rb_intern("max_expiry")), ULONG2NUM(val.value()));
46844688
}
46854689
switch (entry.compression_mode) {
@@ -4696,11 +4700,15 @@ cb_extract_bucket_settings(const couchbase::core::management::cluster::bucket_se
46964700
rb_hash_aset(bucket, rb_id2sym(rb_intern("compression_mode")), Qnil);
46974701
break;
46984702
}
4699-
if (const auto &val = entry.num_replicas; val.has_value()) {
4703+
if (const auto& val = entry.num_replicas; val.has_value()) {
47004704
rb_hash_aset(bucket, rb_id2sym(rb_intern("num_replicas")), ULONG2NUM(val.value()));
47014705
}
4702-
rb_hash_aset(bucket, rb_id2sym(rb_intern("replica_indexes")), entry.replica_indexes ? Qtrue : Qfalse);
4703-
rb_hash_aset(bucket, rb_id2sym(rb_intern("flush_enabled")), entry.flush_enabled ? Qtrue : Qfalse);
4706+
if (const auto& val = entry.replica_indexes; val.has_value()) {
4707+
rb_hash_aset(bucket, rb_id2sym(rb_intern("replica_indexes")), val.value() ? Qtrue : Qfalse);
4708+
}
4709+
if (const auto& val = entry.flush_enabled; val.has_value()) {
4710+
rb_hash_aset(bucket, rb_id2sym(rb_intern("flush_enabled")), val.value() ? Qtrue : Qfalse);
4711+
}
47044712
switch (entry.eviction_policy) {
47054713
case couchbase::core::management::cluster::bucket_eviction_policy::full:
47064714
rb_hash_aset(bucket, rb_id2sym(rb_intern("eviction_policy")), rb_id2sym(rb_intern("full")));
@@ -4754,10 +4762,10 @@ cb_extract_bucket_settings(const couchbase::core::management::cluster::bucket_se
47544762
rb_id2sym(rb_intern("history_retention_collection_default")),
47554763
entry.history_retention_collection_default.value() ? Qtrue : Qfalse);
47564764
}
4757-
if (const auto &val = entry.history_retention_bytes; val.has_value()) {
4765+
if (const auto& val = entry.history_retention_bytes; val.has_value()) {
47584766
rb_hash_aset(bucket, rb_id2sym(rb_intern("history_retention_bytes")), ULONG2NUM(val.value()));
47594767
}
4760-
if (const auto &val = entry.history_retention_duration; val.has_value()) {
4768+
if (const auto& val = entry.history_retention_duration; val.has_value()) {
47614769
rb_hash_aset(bucket, rb_id2sym(rb_intern("history_retention_duration")), ULONG2NUM(val.value()));
47624770
}
47634771

lib/couchbase/management/bucket_manager.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -436,22 +436,6 @@ def ejection_policy=(val)
436436

437437
# @yieldparam [BucketSettings] self
438438
def initialize
439-
@bucket_type = :couchbase
440-
@name = nil
441-
@minimum_durability_level = nil
442-
@healthy = true
443-
@flush_enabled = false
444-
@ram_quota_mb = 100
445-
@num_replicas = 1
446-
@replica_indexes = false
447-
@max_expiry = 0
448-
@compression_mode = :passive
449-
@conflict_resolution_type = :sequence_number
450-
@eviction_policy = :value_only
451-
@storage_backend = nil
452-
@history_retention_collection_default = nil
453-
@history_retention_bytes = nil
454-
@history_retention_duration = nil
455439
yield self if block_given?
456440
end
457441
end

test/bucket_manager_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ def test_update_bucket_history_retention_unsupported
124124
res = @bucket_manager.get_bucket(bucket_name)
125125

126126
assert_nil res.history_retention_collection_default
127-
assert_equal 0, res.history_retention_bytes
128-
assert_equal 0, res.history_retention_duration
127+
assert_nil res.history_retention_bytes
128+
assert_nil res.history_retention_duration
129129

130130
assert_raises(Error::InvalidArgument) do
131131
@bucket_manager.update_bucket(

test/crud_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def test_error_insert_get_with_expiration
365365
assert_kind_of Time, res.expiry_time
366366
now = Time.now
367367

368-
assert res.expiry_time >= now, "now: #{now} (#{now.to_i}), expiry_time: #{res.expiry_time} (#{res.expiry_time.to_i})"
368+
assert_operator res.expiry_time, :>=, now, "now: #{now} (#{now.to_i}), expiry_time: #{res.expiry_time} (#{res.expiry_time.to_i})"
369369
end
370370

371371
def test_expiry_option_as_time_instance
@@ -601,7 +601,7 @@ def test_upsert_get_projection_16_fields_and_expiry
601601

602602
assert_equal(expected, res.content, "expected result do not include field17, field18")
603603
assert_kind_of(Time, res.expiry_time)
604-
assert(res.expiry_time > Time.now)
604+
assert_operator(res.expiry_time, :>, Time.now)
605605
end
606606

607607
def test_upsert_get_projection_missing_path

test/scan_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def validate_sampling_scan(scan_result, limit, ids_only: false)
7575

7676
assert_equal(ids_only, item.id_only)
7777
end
78-
assert(items.size <= limit)
78+
assert_operator(items.size, :<=, limit)
7979

8080
return if ids_only
8181

test/search_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_simple_search
100100
end
101101
warn "search with at_plus took #{attempts} attempts, probably server bug" if attempts > 1
102102

103-
assert attempts < 20, "it is very suspicious that search with at_plus took more than 20 attempts (#{attempts})"
103+
assert_operator attempts, :<, 20, "it is very suspicious that search with at_plus took more than 20 attempts (#{attempts})"
104104
end
105105

106106
def test_doc_id_search_query
@@ -136,7 +136,7 @@ def test_doc_id_search_query
136136
end
137137
warn "search took #{attempts} attempts, probably a server bug" if attempts > 1
138138

139-
assert attempts < 20, "it is very suspicious that search took more than 20 attempts (#{attempts})"
139+
assert_operator attempts, :<, 20, "it is very suspicious that search took more than 20 attempts (#{attempts})"
140140
end
141141
end
142142
end

test/subdoc_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ def test_expiration
11971197
res = @collection.get(doc_id, options)
11981198

11991199
assert_kind_of Time, res.expiry_time
1200-
assert res.expiry_time > Time.now
1200+
assert_operator res.expiry_time, :>, Time.now
12011201
end
12021202

12031203
def test_more_than_16_entries

0 commit comments

Comments
 (0)