mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
#8345 adjust test stacktrace size example to work in all cases by acting on clearly defined thread
Fixes #8350
This commit is contained in:
parent
68b22280bc
commit
ff9ccb3e59
1 changed files with 38 additions and 14 deletions
|
@ -1,14 +1,17 @@
|
||||||
package org.logstash.instruments.monitors;
|
package org.logstash.instruments.monitors;
|
||||||
|
|
||||||
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.logstash.instrument.monitors.HotThreadsMonitor;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.logstash.instrument.monitors.HotThreadsMonitor;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*;
|
import static org.hamcrest.CoreMatchers.hasItem;
|
||||||
|
import static org.hamcrest.CoreMatchers.hasItems;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,17 +48,38 @@ public class HotThreadMonitorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStackTraceSizeOption(){
|
public void testStackTraceSizeOption() throws InterruptedException {
|
||||||
final String testStackSize = "4";
|
final String testStackSize = "4";
|
||||||
Map<String, String> options = new HashMap<>();
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
options.put("stacktrace_size", testStackSize);
|
final Thread thread = new Thread() {
|
||||||
HotThreadsMonitor.detect(options).stream().filter(tr -> !tr.getThreadName().equals("Signal Dispatcher") &&
|
@Override
|
||||||
!tr.getThreadName().equals("Reference Handler") &&
|
public void run() {
|
||||||
!tr.getThreadName().equals("Attach Listener"))
|
waitEnd();
|
||||||
.forEach(tr -> {
|
}
|
||||||
List stackTrace = (List)tr.toMap().get("thread.stacktrace");
|
|
||||||
assertThat(stackTrace.size(), is(Integer.valueOf(testStackSize)));
|
void waitEnd() {
|
||||||
});
|
try {
|
||||||
|
latch.await();
|
||||||
|
} catch (final InterruptedException ex) {
|
||||||
|
throw new IllegalArgumentException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
thread.start();
|
||||||
|
TimeUnit.MILLISECONDS.sleep(300L);
|
||||||
|
final Map<String, String> options = new HashMap<>();
|
||||||
|
options.put("stacktrace_size", testStackSize);
|
||||||
|
assertThat(
|
||||||
|
((List) HotThreadsMonitor.detect(options).stream()
|
||||||
|
.filter(tr -> thread.getName().equals(tr.getThreadName())).findFirst()
|
||||||
|
.get().toMap().get("thread.stacktrace")).size(),
|
||||||
|
is(Integer.parseInt(testStackSize))
|
||||||
|
);
|
||||||
|
} finally {
|
||||||
|
latch.countDown();
|
||||||
|
thread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue