mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 06:37:19 -04:00
parent
7049e61c26
commit
61ffed279b
7 changed files with 22 additions and 17 deletions
|
@ -13,6 +13,7 @@ public final class Cloner {
|
|||
|
||||
private Cloner(){}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T deep(final T input) {
|
||||
if (input instanceof Map<?, ?>) {
|
||||
return (T) deepMap((Map<?, ?>) input);
|
||||
|
|
|
@ -35,6 +35,7 @@ public class Util {
|
|||
return map;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void mapMerge(final Map<String, Object> target, final Map<String, Object> add) {
|
||||
LinkedHashSet<Object> buffer = null;
|
||||
for (final Map.Entry<String, Object> entry : add.entrySet()) {
|
||||
|
|
|
@ -114,7 +114,7 @@ public class Queue implements Closeable {
|
|||
|
||||
// retrieve the deserialize method
|
||||
try {
|
||||
final Class<?>[] cArg = new Class[1];
|
||||
final Class<?>[] cArg = new Class<?>[1];
|
||||
cArg[0] = byte[].class;
|
||||
this.deserializeMethod = this.elementClass.getDeclaredMethod("deserialize", cArg);
|
||||
} catch (NoSuchMethodException e) {
|
||||
|
|
|
@ -9,8 +9,7 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.MatcherAssert;
|
||||
|
||||
import org.jruby.RubySymbol;
|
||||
import org.jruby.RubyTime;
|
||||
import org.jruby.java.proxies.ConcreteJavaProxy;
|
||||
|
@ -343,6 +342,7 @@ public final class EventTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testTagOnEmptyTagsField() throws Exception {
|
||||
Event e = new Event();
|
||||
e.tag("foo");
|
||||
|
@ -353,6 +353,7 @@ public final class EventTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testTagOnExistingTagsField() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("tags", "foo");
|
||||
|
@ -366,7 +367,7 @@ public final class EventTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toStringwithTimestamp() throws Exception {
|
||||
public void toStringWithTimestamp() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("host", "foo");
|
||||
data.put("message", "bar");
|
||||
|
@ -375,7 +376,7 @@ public final class EventTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void toStringwithoutTimestamp() throws Exception {
|
||||
public void toStringWithoutTimestamp() throws Exception {
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("host", "foo");
|
||||
data.put("message", "bar");
|
||||
|
|
|
@ -754,9 +754,9 @@ public class QueueTest {
|
|||
final int count = 20_000;
|
||||
final int concurrent = 2;
|
||||
queue.open();
|
||||
final Future<Integer>[] futures = new Future[concurrent];
|
||||
final List<Future<Integer>> futures = new ArrayList<>(concurrent);
|
||||
for (int c = 0; c < concurrent; ++c) {
|
||||
futures[c] = exec.submit(() -> {
|
||||
futures.add(exec.submit(() -> {
|
||||
int i = 0;
|
||||
try {
|
||||
while (i < count / concurrent) {
|
||||
|
@ -771,7 +771,7 @@ public class QueueTest {
|
|||
} catch (final IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
for (int i = 0; i < count; ++i) {
|
||||
try {
|
||||
|
@ -782,7 +782,7 @@ public class QueueTest {
|
|||
}
|
||||
}
|
||||
assertThat(
|
||||
Arrays.stream(futures).map(i -> {
|
||||
futures.stream().map(i -> {
|
||||
try {
|
||||
return i.get(2L, TimeUnit.MINUTES);
|
||||
} catch (final InterruptedException | ExecutionException | TimeoutException ex) {
|
||||
|
|
|
@ -22,11 +22,12 @@ public class ProcessMonitorTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testReportCpuStats(){
|
||||
Map<String, Object> processStats = ProcessMonitor.detect().toMap();
|
||||
assumeTrue((Boolean) processStats.get("is_unix"));
|
||||
assertThat("cpu", processStats.get("cpu"), instanceOf(Map.class));
|
||||
Map cpuStats = ((Map)processStats.get("cpu"));
|
||||
Map<String, Object> cpuStats = (Map<String, Object>) processStats.get("cpu");
|
||||
assertThat("cpu.process_percent", (Short)cpuStats.get("process_percent") >= 0, is(true));
|
||||
assertThat("cpu.system_percent", (Short)cpuStats.get("system_percent") >= -1, is(true));
|
||||
assertThat("cpu.total_in_millis", (Long)cpuStats.get("total_in_millis") > 0L, is(true));
|
||||
|
|
|
@ -5,10 +5,9 @@ import java.time.Duration;
|
|||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
import java.util.stream.Collectors;
|
||||
import org.logstash.ackedqueue.Batch;
|
||||
import org.logstash.ackedqueue.SettingsImpl;
|
||||
import org.logstash.ackedqueue.Queue;
|
||||
|
@ -54,6 +53,7 @@ public class Concurrent {
|
|||
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void oneProducersOneConsumer() throws IOException, InterruptedException {
|
||||
List<StringElement> input = new ArrayList<>();
|
||||
List<StringElement> output = new ArrayList<>();
|
||||
|
@ -67,7 +67,7 @@ public class Concurrent {
|
|||
System.out.print("stating single producers and single consumers stress test... ");
|
||||
|
||||
for (int i = 0; i < ELEMENT_COUNT; i++) {
|
||||
input.add(new StringElement(new Integer(i).toString()));
|
||||
input.add(new StringElement(Integer.toString(i)));
|
||||
}
|
||||
|
||||
Thread consumer = new Thread(() -> {
|
||||
|
@ -106,6 +106,7 @@ public class Concurrent {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void oneProducersOneMultipleConsumer() throws IOException, InterruptedException {
|
||||
final List<StringElement> input = new ArrayList<>();
|
||||
final Collection<StringElement> output = new ConcurrentLinkedQueue<>();
|
||||
|
@ -121,7 +122,7 @@ public class Concurrent {
|
|||
System.out.print("stating single producers and multiple consumers stress test... ");
|
||||
|
||||
for (int i = 0; i < ELEMENT_COUNT; i++) {
|
||||
input.add(new StringElement(new Integer(i).toString()));
|
||||
input.add(new StringElement(Integer.toString(i)));
|
||||
}
|
||||
|
||||
for (int i = 0; i < CONSUMERS; i++) {
|
||||
|
@ -145,7 +146,7 @@ public class Concurrent {
|
|||
}));
|
||||
}
|
||||
|
||||
consumers.forEach(c -> c.start());
|
||||
consumers.forEach(Thread::start);
|
||||
|
||||
Thread producer = producer(q, input);
|
||||
producer.start();
|
||||
|
@ -156,8 +157,8 @@ public class Concurrent {
|
|||
|
||||
Instant end = Instant.now();
|
||||
|
||||
List<StringElement> result = output.stream().collect(Collectors.toList());
|
||||
Collections.sort(result, (p1, p2) -> Integer.valueOf(p1.toString()).compareTo(Integer.valueOf(p2.toString())));
|
||||
List<StringElement> result = new ArrayList<>(output);
|
||||
result.sort(Comparator.comparing(p -> Integer.valueOf(p.toString())));
|
||||
|
||||
if (! input.equals(result)) {
|
||||
System.out.println("ERROR: input and output are not equal");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue