mirror of
https://github.com/elastic/logstash.git
synced 2025-04-23 22:27:21 -04:00
parent
002060cfdf
commit
6769dc4853
4 changed files with 44 additions and 0 deletions
|
@ -104,6 +104,13 @@ describe LogStash::Event do
|
|||
expect(e["foo"]).to be_kind_of(BigDecimal)
|
||||
expect(e["foo"]).to eq(BigDecimal.new(1))
|
||||
end
|
||||
|
||||
it "should set RubyBignum" do
|
||||
e = LogStash::Event.new()
|
||||
e["[foo]"] = -9223372036854776000
|
||||
expect(e["foo"]).to be_kind_of(Bignum)
|
||||
expect(e["foo"]).to eq(-9223372036854776000)
|
||||
end
|
||||
end
|
||||
|
||||
context "timestamp" do
|
||||
|
|
|
@ -13,11 +13,14 @@ import org.jruby.RubyBoolean;
|
|||
import org.jruby.RubyFixnum;
|
||||
import org.jruby.RubyTime;
|
||||
import org.jruby.RubySymbol;
|
||||
import org.jruby.RubyBignum;
|
||||
import org.jruby.ext.bigdecimal.RubyBigDecimal;
|
||||
import com.logstash.ext.JrubyTimestampExtLibrary;
|
||||
import org.jruby.runtime.builtin.IRubyObject;
|
||||
import java.math.BigDecimal;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.*;
|
||||
|
||||
public class Javafier {
|
||||
|
@ -66,6 +69,10 @@ public class Javafier {
|
|||
return bd.getBigDecimalValue();
|
||||
}
|
||||
|
||||
public static BigInteger deep(RubyBignum bn) {
|
||||
return bn.getBigIntegerValue();
|
||||
}
|
||||
|
||||
public static Timestamp deep(JrubyTimestampExtLibrary.RubyTimestamp t) {
|
||||
return t.getTimestamp();
|
||||
}
|
||||
|
@ -114,6 +121,7 @@ public class Javafier {
|
|||
case RubyTimestamp: return deep((JrubyTimestampExtLibrary.RubyTimestamp)o);
|
||||
case RubyBoolean: return deep((RubyBoolean)o);
|
||||
case RubyFixnum: return deep((RubyFixnum)o);
|
||||
case RubyBignum: return deep((RubyBignum)o);
|
||||
case RubyTime: return deep((RubyTime)o);
|
||||
case RubySymbol: return deep((RubySymbol)o);
|
||||
case RubyNil: return deep((RubyNil)o);
|
||||
|
@ -141,6 +149,7 @@ public class Javafier {
|
|||
RubyHash,
|
||||
RubyBoolean,
|
||||
RubyFixnum,
|
||||
RubyBignum,
|
||||
RubyObject,
|
||||
RubyNil,
|
||||
RubyTime,
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package com.logstash;
|
||||
|
||||
import org.jruby.Ruby;
|
||||
import org.jruby.RubyBignum;
|
||||
import java.math.BigInteger;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class JavafierTest {
|
||||
@Test
|
||||
public void testRubyBignum() {
|
||||
RubyBignum v = RubyBignum.newBignum(Ruby.getGlobalRuntime(), "-9223372036854776000");
|
||||
|
||||
Object result = Javafier.deep(v);
|
||||
assertEquals(BigInteger.class, result.getClass());
|
||||
assertEquals( "-9223372036854776000", result.toString());
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import org.junit.Test;
|
|||
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -217,4 +218,13 @@ public class RubyfierTest {
|
|||
assertEquals(RubyBigDecimal.class, rubyArray.toJavaArray()[0].getClass());
|
||||
assertEquals(1.0D, ((RubyBigDecimal)rubyArray.toJavaArray()[0]).getDoubleValue(), 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDeepWithBigInteger() {
|
||||
Object result = Rubyfier.deep(Ruby.getGlobalRuntime(), new BigInteger("1"));
|
||||
assertEquals(RubyBignum.class, result.getClass());
|
||||
assertEquals(1L, ((RubyBignum)result).getLongValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue