Fixed BSON_CODER.update_max_bson_size return value

This commit is contained in:
Kyle Banker 2011-01-03 14:05:42 -05:00
parent b83877527e
commit c0e972470e
5 changed files with 20 additions and 3 deletions

View File

@ -904,8 +904,9 @@ static VALUE objectid_generate(VALUE self)
return oid; return oid;
} }
static void method_update_max_bson_size(VALUE self, VALUE connection) { static VALUE method_update_max_bson_size(VALUE self, VALUE connection) {
max_bson_size = FIX2INT(rb_funcall(connection, rb_intern("max_bson_size"), 0)); max_bson_size = FIX2INT(rb_funcall(connection, rb_intern("max_bson_size"), 0));
return INT2FIX(max_bson_size);
} }
static VALUE method_max_bson_size(VALUE self) { static VALUE method_max_bson_size(VALUE self) {

Binary file not shown.

View File

@ -91,10 +91,11 @@ public class RubyBSONEncoder extends BSONEncoder {
return _run.newFixnum(_max_bson_size); return _run.newFixnum(_max_bson_size);
} }
public static void update_max_bson_size(RubyObject obj, RubyObject conn) { public static RubyFixnum update_max_bson_size(RubyObject obj, RubyObject conn) {
Ruby _run = obj.getRuntime(); Ruby _run = obj.getRuntime();
_max_bson_size = ((Long)JavaEmbedUtils.invokeMethod( _run, conn, "max_bson_size", _max_bson_size = ((Long)JavaEmbedUtils.invokeMethod( _run, conn, "max_bson_size",
new Object[] {}, Object.class)).intValue(); new Object[] {}, Object.class)).intValue();
return _run.newFixnum(_max_bson_size);
} }
public RubyString encode( Object arg ) { public RubyString encode( Object arg ) {

View File

@ -6,11 +6,17 @@ MINIMUM_BSON_EXT_VERSION = "1.2.rc0"
module BSON module BSON
VERSION = "1.2.rc0" VERSION = "1.2.rc0"
if defined? Mongo
DEFAULT_MAX_BSON_SIZE = Mongo::DEFAULT_MAX_BSON_SIZE
else
DEFAULT_MAX_BSON_SIZE = 4 * 1024 * 1024
end
def self.serialize(obj, check_keys=false, move_id=false) def self.serialize(obj, check_keys=false, move_id=false)
BSON_CODER.serialize(obj, check_keys, move_id) BSON_CODER.serialize(obj, check_keys, move_id)
end end
def self.deserialize(buf=nil) def self.deserialize(buf=nil)
BSON_CODER.deserialize(buf) BSON_CODER.deserialize(buf)
end end

View File

@ -78,6 +78,15 @@ class BSONTest < Test::Unit::TestCase
assert BSON_CODER.max_bson_size >= BSON::DEFAULT_MAX_BSON_SIZE assert BSON_CODER.max_bson_size >= BSON::DEFAULT_MAX_BSON_SIZE
end end
def test_update_max_bson_size
require 'ostruct'
mock_conn = OpenStruct.new
size = 7 * 1024 * 1024
mock_conn.max_bson_size = size
assert_equal size, BSON_CODER.update_max_bson_size(mock_conn)
assert_equal size, BSON_CODER.max_bson_size
end
def test_round_trip def test_round_trip
doc = {'doc' => 123} doc = {'doc' => 123}
@encoder.deserialize(@encoder.serialize(doc)) @encoder.deserialize(@encoder.serialize(doc))