mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 22:57:16 -04:00
parent
290ea7963f
commit
b66562342d
12 changed files with 102 additions and 135 deletions
|
@ -2,12 +2,9 @@ import org.jruby.Ruby;
|
||||||
import org.jruby.runtime.load.BasicLibraryService;
|
import org.jruby.runtime.load.BasicLibraryService;
|
||||||
import org.logstash.ackedqueue.ext.JrubyAckedBatchExtLibrary;
|
import org.logstash.ackedqueue.ext.JrubyAckedBatchExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class JrubyAckedBatchExtService implements BasicLibraryService {
|
public class JrubyAckedBatchExtService implements BasicLibraryService {
|
||||||
public boolean basicLoad(final Ruby runtime)
|
@Override
|
||||||
throws IOException
|
public boolean basicLoad(final Ruby runtime) {
|
||||||
{
|
|
||||||
new JrubyAckedBatchExtLibrary().load(runtime, false);
|
new JrubyAckedBatchExtLibrary().load(runtime, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,12 +3,9 @@ import org.jruby.runtime.load.BasicLibraryService;
|
||||||
import org.logstash.ackedqueue.ext.JrubyAckedQueueExtLibrary;
|
import org.logstash.ackedqueue.ext.JrubyAckedQueueExtLibrary;
|
||||||
import org.logstash.ackedqueue.ext.JrubyAckedQueueMemoryExtLibrary;
|
import org.logstash.ackedqueue.ext.JrubyAckedQueueMemoryExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
public final class JrubyAckedQueueExtService implements BasicLibraryService {
|
||||||
|
@Override
|
||||||
public class JrubyAckedQueueExtService implements BasicLibraryService {
|
public boolean basicLoad(final Ruby runtime) {
|
||||||
public boolean basicLoad(final Ruby runtime)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
new JrubyAckedQueueExtLibrary().load(runtime, false);
|
new JrubyAckedQueueExtLibrary().load(runtime, false);
|
||||||
new JrubyAckedQueueMemoryExtLibrary().load(runtime, false);
|
new JrubyAckedQueueMemoryExtLibrary().load(runtime, false);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import org.logstash.ext.JrubyEventExtLibrary;
|
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
import org.jruby.runtime.load.BasicLibraryService;
|
import org.jruby.runtime.load.BasicLibraryService;
|
||||||
|
import org.logstash.ext.JrubyEventExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
public final class JrubyEventExtService implements BasicLibraryService {
|
||||||
|
@Override
|
||||||
public class JrubyEventExtService implements BasicLibraryService {
|
public boolean basicLoad(final Ruby runtime) {
|
||||||
public boolean basicLoad(final Ruby runtime)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
new JrubyEventExtLibrary().load(runtime, false);
|
new JrubyEventExtLibrary().load(runtime, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
import org.logstash.ext.JrubyTimestampExtLibrary;
|
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
import org.jruby.runtime.load.BasicLibraryService;
|
import org.jruby.runtime.load.BasicLibraryService;
|
||||||
|
import org.logstash.ext.JrubyTimestampExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
public final class JrubyTimestampExtService implements BasicLibraryService {
|
||||||
|
@Override
|
||||||
public class JrubyTimestampExtService implements BasicLibraryService {
|
public boolean basicLoad(final Ruby runtime) {
|
||||||
public boolean basicLoad(final Ruby runtime)
|
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
new JrubyTimestampExtLibrary().load(runtime, false);
|
new JrubyTimestampExtLibrary().load(runtime, false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,9 +20,10 @@ import org.logstash.ext.JrubyEventExtLibrary;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JrubyAckedBatchExtLibrary implements Library {
|
public final class JrubyAckedBatchExtLibrary implements Library {
|
||||||
|
|
||||||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
@Override
|
||||||
|
public void load(Ruby runtime, boolean wrap) {
|
||||||
RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
||||||
|
|
||||||
RubyClass clazz = runtime.defineClassUnder("AckedBatch", runtime.getObject(), new ObjectAllocator() {
|
RubyClass clazz = runtime.defineClassUnder("AckedBatch", runtime.getObject(), new ObjectAllocator() {
|
||||||
|
@ -35,7 +36,7 @@ public class JrubyAckedBatchExtLibrary implements Library {
|
||||||
}
|
}
|
||||||
|
|
||||||
@JRubyClass(name = "AckedBatch")
|
@JRubyClass(name = "AckedBatch")
|
||||||
public static class RubyAckedBatch extends RubyObject {
|
public static final class RubyAckedBatch extends RubyObject {
|
||||||
private static final long serialVersionUID = -3118949118637372130L;
|
private static final long serialVersionUID = -3118949118637372130L;
|
||||||
private Batch batch;
|
private Batch batch;
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,10 @@ import org.jruby.Ruby;
|
||||||
import org.jruby.RubyBoolean;
|
import org.jruby.RubyBoolean;
|
||||||
import org.jruby.RubyClass;
|
import org.jruby.RubyClass;
|
||||||
import org.jruby.RubyFixnum;
|
import org.jruby.RubyFixnum;
|
||||||
import org.jruby.RubyModule;
|
|
||||||
import org.jruby.RubyObject;
|
import org.jruby.RubyObject;
|
||||||
import org.jruby.anno.JRubyClass;
|
import org.jruby.anno.JRubyClass;
|
||||||
import org.jruby.anno.JRubyMethod;
|
import org.jruby.anno.JRubyMethod;
|
||||||
import org.jruby.runtime.Arity;
|
import org.jruby.runtime.Arity;
|
||||||
import org.jruby.runtime.ObjectAllocator;
|
|
||||||
import org.jruby.runtime.ThreadContext;
|
import org.jruby.runtime.ThreadContext;
|
||||||
import org.jruby.runtime.builtin.IRubyObject;
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
import org.jruby.runtime.load.Library;
|
import org.jruby.runtime.load.Library;
|
||||||
|
@ -23,26 +21,25 @@ import org.logstash.ackedqueue.io.FileCheckpointIO;
|
||||||
import org.logstash.ackedqueue.io.MmapPageIO;
|
import org.logstash.ackedqueue.io.MmapPageIO;
|
||||||
import org.logstash.ext.JrubyEventExtLibrary;
|
import org.logstash.ext.JrubyEventExtLibrary;
|
||||||
|
|
||||||
public class JrubyAckedQueueExtLibrary implements Library {
|
public final class JrubyAckedQueueExtLibrary implements Library {
|
||||||
|
|
||||||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
@Override
|
||||||
RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
public void load(Ruby runtime, boolean wrap) {
|
||||||
|
runtime.defineClassUnder(
|
||||||
RubyClass clazz = runtime.defineClassUnder("AckedQueue", runtime.getObject(), new ObjectAllocator() {
|
"AckedQueue", runtime.getObject(), JrubyAckedQueueExtLibrary.RubyAckedQueue::new,
|
||||||
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
|
runtime.defineModule(RubyUtil.LS_MODULE_NAME)
|
||||||
return new RubyAckedQueue(runtime, rubyClass);
|
).defineAnnotatedMethods(JrubyAckedQueueExtLibrary.RubyAckedQueue.class);
|
||||||
}
|
|
||||||
}, module);
|
|
||||||
|
|
||||||
clazz.defineAnnotatedMethods(RubyAckedQueue.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// as a simplified first prototyping implementation, the Settings class is not exposed and the queue elements
|
// as a simplified first prototyping implementation, the Settings class is not exposed and the queue elements
|
||||||
// are assumed to be logstash Event.
|
// are assumed to be logstash Event.
|
||||||
|
|
||||||
@JRubyClass(name = "AckedQueue", parent = "Object")
|
@JRubyClass(name = "AckedQueue")
|
||||||
public static class RubyAckedQueue extends RubyObject {
|
public static final class RubyAckedQueue extends RubyObject {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Queue queue;
|
private Queue queue;
|
||||||
|
|
||||||
public RubyAckedQueue(Ruby runtime, RubyClass klass) {
|
public RubyAckedQueue(Ruby runtime, RubyClass klass) {
|
||||||
|
|
|
@ -5,12 +5,10 @@ import org.jruby.Ruby;
|
||||||
import org.jruby.RubyBoolean;
|
import org.jruby.RubyBoolean;
|
||||||
import org.jruby.RubyClass;
|
import org.jruby.RubyClass;
|
||||||
import org.jruby.RubyFixnum;
|
import org.jruby.RubyFixnum;
|
||||||
import org.jruby.RubyModule;
|
|
||||||
import org.jruby.RubyObject;
|
import org.jruby.RubyObject;
|
||||||
import org.jruby.anno.JRubyClass;
|
import org.jruby.anno.JRubyClass;
|
||||||
import org.jruby.anno.JRubyMethod;
|
import org.jruby.anno.JRubyMethod;
|
||||||
import org.jruby.runtime.Arity;
|
import org.jruby.runtime.Arity;
|
||||||
import org.jruby.runtime.ObjectAllocator;
|
|
||||||
import org.jruby.runtime.ThreadContext;
|
import org.jruby.runtime.ThreadContext;
|
||||||
import org.jruby.runtime.builtin.IRubyObject;
|
import org.jruby.runtime.builtin.IRubyObject;
|
||||||
import org.jruby.runtime.load.Library;
|
import org.jruby.runtime.load.Library;
|
||||||
|
@ -23,18 +21,15 @@ import org.logstash.ackedqueue.io.ByteBufferPageIO;
|
||||||
import org.logstash.ackedqueue.io.MemoryCheckpointIO;
|
import org.logstash.ackedqueue.io.MemoryCheckpointIO;
|
||||||
import org.logstash.ext.JrubyEventExtLibrary;
|
import org.logstash.ext.JrubyEventExtLibrary;
|
||||||
|
|
||||||
public class JrubyAckedQueueMemoryExtLibrary implements Library {
|
public final class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
|
|
||||||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
@Override
|
||||||
RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
public void load(Ruby runtime, boolean wrap) {
|
||||||
|
runtime.defineClassUnder(
|
||||||
RubyClass clazz = runtime.defineClassUnder("AckedMemoryQueue", runtime.getObject(), new ObjectAllocator() {
|
"AckedMemoryQueue", runtime.getObject(),
|
||||||
public IRubyObject allocate(Ruby runtime, RubyClass rubyClass) {
|
JrubyAckedQueueMemoryExtLibrary.RubyAckedMemoryQueue::new,
|
||||||
return new RubyAckedMemoryQueue(runtime, rubyClass);
|
runtime.defineModule(RubyUtil.LS_MODULE_NAME)
|
||||||
}
|
).defineAnnotatedMethods(JrubyAckedQueueMemoryExtLibrary.RubyAckedMemoryQueue.class);
|
||||||
}, module);
|
|
||||||
|
|
||||||
clazz.defineAnnotatedMethods(RubyAckedMemoryQueue.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
|
@ -42,8 +37,11 @@ public class JrubyAckedQueueMemoryExtLibrary implements Library {
|
||||||
// are assumed to be logstash Event.
|
// are assumed to be logstash Event.
|
||||||
|
|
||||||
|
|
||||||
@JRubyClass(name = "AckedMemoryQueue", parent = "Object")
|
@JRubyClass(name = "AckedMemoryQueue")
|
||||||
public static class RubyAckedMemoryQueue extends RubyObject {
|
public static final class RubyAckedMemoryQueue extends RubyObject {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Queue queue;
|
private Queue queue;
|
||||||
|
|
||||||
public RubyAckedMemoryQueue(Ruby runtime, RubyClass klass) {
|
public RubyAckedMemoryQueue(Ruby runtime, RubyClass klass) {
|
||||||
|
|
|
@ -27,14 +27,14 @@ import org.logstash.RubyUtil;
|
||||||
import org.logstash.Rubyfier;
|
import org.logstash.Rubyfier;
|
||||||
import org.logstash.Valuefier;
|
import org.logstash.Valuefier;
|
||||||
|
|
||||||
public class JrubyEventExtLibrary implements Library {
|
public final class JrubyEventExtLibrary implements Library {
|
||||||
|
|
||||||
private static RubyClass PARSER_ERROR = null;
|
private static RubyClass PARSER_ERROR = null;
|
||||||
private static RubyClass GENERATOR_ERROR = null;
|
private static RubyClass GENERATOR_ERROR = null;
|
||||||
private static RubyClass LOGSTASH_ERROR = null;
|
private static RubyClass LOGSTASH_ERROR = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
public void load(Ruby runtime, boolean wrap) {
|
||||||
final RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
final RubyModule module = runtime.defineModule(RubyUtil.LS_MODULE_NAME);
|
||||||
|
|
||||||
RubyClass clazz = runtime.defineClassUnder(
|
RubyClass clazz = runtime.defineClassUnder(
|
||||||
|
@ -68,6 +68,8 @@ public class JrubyEventExtLibrary implements Library {
|
||||||
@JRubyClass(name = "Event")
|
@JRubyClass(name = "Event")
|
||||||
public static final class RubyEvent extends RubyObject {
|
public static final class RubyEvent extends RubyObject {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sequence number generator, for generating {@link RubyEvent#hash}.
|
* Sequence number generator, for generating {@link RubyEvent#hash}.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package org.logstash.ext;
|
package org.logstash.ext;
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
import java.io.IOException;
|
|
||||||
import org.jruby.Ruby;
|
import org.jruby.Ruby;
|
||||||
import org.jruby.RubyClass;
|
import org.jruby.RubyClass;
|
||||||
import org.jruby.RubyFixnum;
|
import org.jruby.RubyFixnum;
|
||||||
|
@ -23,7 +22,7 @@ import org.logstash.ObjectMappers;
|
||||||
import org.logstash.RubyUtil;
|
import org.logstash.RubyUtil;
|
||||||
import org.logstash.Timestamp;
|
import org.logstash.Timestamp;
|
||||||
|
|
||||||
public class JrubyTimestampExtLibrary implements Library {
|
public final class JrubyTimestampExtLibrary implements Library {
|
||||||
|
|
||||||
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
||||||
public RubyTimestamp allocate(Ruby runtime, RubyClass rubyClass) {
|
public RubyTimestamp allocate(Ruby runtime, RubyClass rubyClass) {
|
||||||
|
@ -31,7 +30,8 @@ public class JrubyTimestampExtLibrary implements Library {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public void load(Ruby runtime, boolean wrap) throws IOException {
|
@Override
|
||||||
|
public void load(Ruby runtime, boolean wrap) {
|
||||||
createTimestamp(runtime);
|
createTimestamp(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +44,9 @@ public class JrubyTimestampExtLibrary implements Library {
|
||||||
|
|
||||||
@JRubyClass(name = "Timestamp")
|
@JRubyClass(name = "Timestamp")
|
||||||
@JsonSerialize(using = ObjectMappers.RubyTimestampSerializer.class)
|
@JsonSerialize(using = ObjectMappers.RubyTimestampSerializer.class)
|
||||||
public static class RubyTimestamp extends RubyObject {
|
public static final class RubyTimestamp extends RubyObject {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private Timestamp timestamp;
|
private Timestamp timestamp;
|
||||||
|
|
||||||
|
@ -69,11 +71,6 @@ public class JrubyTimestampExtLibrary implements Library {
|
||||||
return new RubyTimestamp(runtime);
|
return new RubyTimestamp(runtime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RubyTimestamp newRubyTimestamp(Ruby runtime, long epoch) {
|
|
||||||
// Ruby epoch is in seconds, Java in milliseconds
|
|
||||||
return new RubyTimestamp(runtime, new Timestamp(epoch * 1000));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RubyTimestamp newRubyTimestamp(Ruby runtime, Timestamp timestamp) {
|
public static RubyTimestamp newRubyTimestamp(Ruby runtime, Timestamp timestamp) {
|
||||||
return new RubyTimestamp(runtime, timestamp);
|
return new RubyTimestamp(runtime, timestamp);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +1,32 @@
|
||||||
package org.logstash.instrument.metrics.gauge;
|
package org.logstash.instrument.metrics.gauge;
|
||||||
|
|
||||||
import org.jruby.RubyHash;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.logstash.Timestamp;
|
|
||||||
import org.logstash.ext.JrubyTimestampExtLibrary;
|
|
||||||
import org.logstash.instrument.metrics.MetricType;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import org.jruby.RubyHash;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.logstash.RubyUtil;
|
||||||
|
import org.logstash.Timestamp;
|
||||||
|
import org.logstash.ext.JrubyTimestampExtLibrary;
|
||||||
|
import org.logstash.instrument.metrics.MetricType;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link LazyDelegatingGauge}
|
* Unit tests for {@link LazyDelegatingGauge}
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class LazyDelegatingGaugeTest {
|
public class LazyDelegatingGaugeTest {
|
||||||
|
|
||||||
@Mock
|
private static final RubyHash RUBY_HASH = RubyHash.newHash(RubyUtil.RUBY);
|
||||||
RubyHash rubyHash;
|
|
||||||
|
|
||||||
@Mock
|
private static final Timestamp TIMESTAMP = new Timestamp();
|
||||||
private JrubyTimestampExtLibrary.RubyTimestamp rubyTimestamp;
|
|
||||||
|
|
||||||
private final Timestamp timestamp = new Timestamp();
|
private static final JrubyTimestampExtLibrary.RubyTimestamp RUBY_TIMESTAMP =
|
||||||
|
JrubyTimestampExtLibrary.RubyTimestamp.newRubyTimestamp(
|
||||||
|
RubyUtil.RUBY, TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
private static final String RUBY_HASH_AS_STRING = "{}";
|
private static final String RUBY_HASH_AS_STRING = "{}";
|
||||||
|
|
||||||
@Before
|
|
||||||
public void _setup() {
|
|
||||||
//hacky workaround using the toString method to avoid mocking the Ruby runtime
|
|
||||||
when(rubyHash.toString()).thenReturn(RUBY_HASH_AS_STRING);
|
|
||||||
when(rubyTimestamp.getTimestamp()).thenReturn(timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getValue() {
|
public void getValue() {
|
||||||
//Long
|
//Long
|
||||||
|
@ -62,13 +50,13 @@ public class LazyDelegatingGaugeTest {
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_TEXT);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_TEXT);
|
||||||
|
|
||||||
//Ruby Hash
|
//Ruby Hash
|
||||||
gauge = new LazyDelegatingGauge("bar", rubyHash);
|
gauge = new LazyDelegatingGauge("bar", RUBY_HASH);
|
||||||
assertThat(gauge.getValue().toString()).isEqualTo(RUBY_HASH_AS_STRING);
|
assertThat(gauge.getValue().toString()).isEqualTo(RUBY_HASH_AS_STRING);
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYHASH);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYHASH);
|
||||||
|
|
||||||
//Ruby Timestamp
|
//Ruby Timestamp
|
||||||
gauge = new LazyDelegatingGauge("bar", rubyTimestamp);
|
gauge = new LazyDelegatingGauge("bar", RUBY_TIMESTAMP);
|
||||||
assertThat(gauge.getValue()).isEqualTo(timestamp);
|
assertThat(gauge.getValue()).isEqualTo(TIMESTAMP);
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
||||||
|
|
||||||
//Unknown
|
//Unknown
|
||||||
|
@ -128,14 +116,14 @@ public class LazyDelegatingGaugeTest {
|
||||||
|
|
||||||
//Ruby Hash
|
//Ruby Hash
|
||||||
gauge = new LazyDelegatingGauge("bar");
|
gauge = new LazyDelegatingGauge("bar");
|
||||||
gauge.set(rubyHash);
|
gauge.set(RUBY_HASH);
|
||||||
assertThat(gauge.getValue().toString()).isEqualTo(RUBY_HASH_AS_STRING);
|
assertThat(gauge.getValue().toString()).isEqualTo(RUBY_HASH_AS_STRING);
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYHASH);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYHASH);
|
||||||
|
|
||||||
//Ruby Timestamp
|
//Ruby Timestamp
|
||||||
gauge = new LazyDelegatingGauge("bar");
|
gauge = new LazyDelegatingGauge("bar");
|
||||||
gauge.set(rubyTimestamp);
|
gauge.set(RUBY_TIMESTAMP);
|
||||||
assertThat(gauge.getValue()).isEqualTo(timestamp);
|
assertThat(gauge.getValue()).isEqualTo(TIMESTAMP);
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
||||||
|
|
||||||
//Unknown
|
//Unknown
|
||||||
|
@ -161,4 +149,4 @@ public class LazyDelegatingGaugeTest {
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_TEXT);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_TEXT);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,14 @@
|
||||||
package org.logstash.instrument.metrics.gauge;
|
package org.logstash.instrument.metrics.gauge;
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.logstash.RubyUtil;
|
||||||
import org.logstash.Timestamp;
|
import org.logstash.Timestamp;
|
||||||
import org.logstash.ext.JrubyTimestampExtLibrary.RubyTimestamp;
|
import org.logstash.ext.JrubyTimestampExtLibrary;
|
||||||
import org.logstash.instrument.metrics.MetricType;
|
import org.logstash.instrument.metrics.MetricType;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link RubyTimeStampGauge}
|
* Unit tests for {@link RubyTimeStampGauge}
|
||||||
|
@ -18,20 +16,17 @@ import static org.mockito.Mockito.when;
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class RubyTimeStampGaugeTest {
|
public class RubyTimeStampGaugeTest {
|
||||||
|
|
||||||
@Mock
|
private static final Timestamp TIMESTAMP = new Timestamp();
|
||||||
private RubyTimestamp rubyTimestamp;
|
|
||||||
|
|
||||||
private final Timestamp timestamp = new Timestamp();
|
private static final JrubyTimestampExtLibrary.RubyTimestamp RUBY_TIMESTAMP =
|
||||||
|
JrubyTimestampExtLibrary.RubyTimestamp.newRubyTimestamp(
|
||||||
@Before
|
RubyUtil.RUBY, TIMESTAMP
|
||||||
public void _setup() {
|
);
|
||||||
when(rubyTimestamp.getTimestamp()).thenReturn(timestamp);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getValue() {
|
public void getValue() {
|
||||||
RubyTimeStampGauge gauge = new RubyTimeStampGauge("bar", rubyTimestamp);
|
RubyTimeStampGauge gauge = new RubyTimeStampGauge("bar", RUBY_TIMESTAMP);
|
||||||
assertThat(gauge.getValue()).isEqualTo(rubyTimestamp.getTimestamp());
|
assertThat(gauge.getValue()).isEqualTo(RUBY_TIMESTAMP.getTimestamp());
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
||||||
|
|
||||||
//Null initialize
|
//Null initialize
|
||||||
|
@ -43,8 +38,8 @@ public class RubyTimeStampGaugeTest {
|
||||||
@Test
|
@Test
|
||||||
public void set() {
|
public void set() {
|
||||||
RubyTimeStampGauge gauge = new RubyTimeStampGauge("bar");
|
RubyTimeStampGauge gauge = new RubyTimeStampGauge("bar");
|
||||||
gauge.set(rubyTimestamp);
|
gauge.set(RUBY_TIMESTAMP);
|
||||||
assertThat(gauge.getValue()).isEqualTo(rubyTimestamp.getTimestamp());
|
assertThat(gauge.getValue()).isEqualTo(RUBY_TIMESTAMP.getTimestamp());
|
||||||
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
assertThat(gauge.getType()).isEqualTo(MetricType.GAUGE_RUBYTIMESTAMP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,38 +4,37 @@ package org.logstash.instrument.witness.pipeline;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.logstash.RubyUtil;
|
||||||
import org.logstash.Timestamp;
|
import org.logstash.Timestamp;
|
||||||
import org.logstash.ext.JrubyTimestampExtLibrary;
|
import org.logstash.ext.JrubyTimestampExtLibrary;
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link ReloadWitness}
|
* Unit tests for {@link ReloadWitness}
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class ReloadWitnessTest {
|
public class ReloadWitnessTest {
|
||||||
|
|
||||||
private ReloadWitness witness;
|
private ReloadWitness witness;
|
||||||
private Timestamp timestamp = new Timestamp();
|
|
||||||
@Mock
|
private static final Timestamp TIMESTAMP = new Timestamp();
|
||||||
JrubyTimestampExtLibrary.RubyTimestamp rubyTimestamp;
|
|
||||||
|
private static final JrubyTimestampExtLibrary.RubyTimestamp RUBY_TIMESTAMP =
|
||||||
|
JrubyTimestampExtLibrary.RubyTimestamp.newRubyTimestamp(
|
||||||
|
RubyUtil.RUBY, TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
witness = new ReloadWitness();
|
witness = new ReloadWitness();
|
||||||
when(rubyTimestamp.getTimestamp()).thenReturn(timestamp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSuccess() {
|
public void testSuccess() {
|
||||||
witness.success();
|
witness.success();
|
||||||
witness.lastSuccessTimestamp(rubyTimestamp);
|
witness.lastSuccessTimestamp(RUBY_TIMESTAMP);
|
||||||
assertThat(witness.snitch().successes()).isEqualTo(1);
|
assertThat(witness.snitch().successes()).isEqualTo(1);
|
||||||
assertThat(witness.snitch().lastSuccessTimestamp()).isEqualTo(timestamp);
|
assertThat(witness.snitch().lastSuccessTimestamp()).isEqualTo(TIMESTAMP);
|
||||||
witness.successes(99);
|
witness.successes(99);
|
||||||
assertThat(witness.snitch().successes()).isEqualTo(100);
|
assertThat(witness.snitch().successes()).isEqualTo(100);
|
||||||
}
|
}
|
||||||
|
@ -43,9 +42,9 @@ public class ReloadWitnessTest {
|
||||||
@Test
|
@Test
|
||||||
public void testFailure() {
|
public void testFailure() {
|
||||||
witness.failure();
|
witness.failure();
|
||||||
witness.lastFailureTimestamp(rubyTimestamp);
|
witness.lastFailureTimestamp(RUBY_TIMESTAMP);
|
||||||
assertThat(witness.snitch().failures()).isEqualTo(1);
|
assertThat(witness.snitch().failures()).isEqualTo(1);
|
||||||
assertThat(witness.snitch().lastFailureTimestamp()).isEqualTo(timestamp);
|
assertThat(witness.snitch().lastFailureTimestamp()).isEqualTo(TIMESTAMP);
|
||||||
witness.failures(99);
|
witness.failures(99);
|
||||||
assertThat(witness.snitch().failures()).isEqualTo(100);
|
assertThat(witness.snitch().failures()).isEqualTo(100);
|
||||||
}
|
}
|
||||||
|
@ -72,19 +71,21 @@ public class ReloadWitnessTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeSuccess() throws Exception {
|
public void testSerializeSuccess() throws Exception {
|
||||||
witness.success();
|
witness.success();
|
||||||
witness.lastSuccessTimestamp(rubyTimestamp);
|
witness.lastSuccessTimestamp(RUBY_TIMESTAMP);
|
||||||
String json = witness.asJson();
|
String json = witness.asJson();
|
||||||
assertThat(json).isEqualTo("{\"reloads\":{\"last_error\":{\"message\":null,\"backtrace\":null},\"successes\":1,\"last_success_timestamp\":\"" + timestamp.toString() +
|
assertThat(json).isEqualTo("{\"reloads\":{\"last_error\":{\"message\":null,\"backtrace\":null},\"successes\":1,\"last_success_timestamp\":\""
|
||||||
"\",\"last_failure_timestamp\":null,\"failures\":0}}");
|
+ TIMESTAMP.toString() + "\",\"last_failure_timestamp\":null,\"failures\":0}}");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSerializeFailure() throws Exception {
|
public void testSerializeFailure() throws Exception {
|
||||||
witness.failure();
|
witness.failure();
|
||||||
witness.lastFailureTimestamp(rubyTimestamp);
|
witness.lastFailureTimestamp(RUBY_TIMESTAMP);
|
||||||
String json = witness.asJson();
|
String json = witness.asJson();
|
||||||
assertThat(json).isEqualTo("{\"reloads\":{\"last_error\":{\"message\":null,\"backtrace\":null},\"successes\":0,\"last_success_timestamp\":null," +
|
assertThat(json).isEqualTo(
|
||||||
"\"last_failure_timestamp\":\"" + timestamp.toString() + "\",\"failures\":1}}");
|
"{\"reloads\":{\"last_error\":{\"message\":null,\"backtrace\":null},\"successes\":0,\"last_success_timestamp\":null," +
|
||||||
|
"\"last_failure_timestamp\":\"" + TIMESTAMP.toString() + "\",\"failures\":1}}"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue