Search in sources :

Example 1 with ErrorEvent

use of org.gridkit.jvmtool.event.ErrorEvent in project jvm-tools by aragozin.

the class ThreadEventReaderTest method read_dump_v2.

@Test
public void read_dump_v2() throws FileNotFoundException, IOException {
    EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream("src/test/resources/dump_v2.std"));
    int n = 0;
    for (Event e : reader) {
        if (e instanceof ErrorEvent) {
            fail("Error", ((ErrorEvent) e).exception());
        }
        //            System.out.println(((MultiCounterEvent)e).counters());
        ++n;
    }
    System.out.println("Read " + n + " traces from file");
}
Also used : ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with ErrorEvent

use of org.gridkit.jvmtool.event.ErrorEvent in project jvm-tools by aragozin.

the class EventDecoratorTest method verify_error_event.

@Test
public void verify_error_event() {
    SimpleErrorEvent ee = new SimpleErrorEvent(new Exception("Boom"));
    EventDecorator deco = new EventDecorator();
    ErrorEvent c = deco.wrap(ee);
    assertThat(c).is(eventEquals(ee));
}
Also used : SimpleErrorEvent(org.gridkit.jvmtool.event.SimpleErrorEvent) EventDecorator(org.gridkit.jvmtool.event.EventDecorator) SimpleErrorEvent(org.gridkit.jvmtool.event.SimpleErrorEvent) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) Test(org.junit.Test)

Example 3 with ErrorEvent

use of org.gridkit.jvmtool.event.ErrorEvent in project jvm-tools by aragozin.

the class EventEqualToCondition method matches.

@Override
public boolean matches(Event value) {
    if (expected instanceof ErrorEvent) {
        if (value instanceof ErrorEvent) {
            assertThat(((ErrorEvent) value).exception().toString()).isEqualTo(((ErrorEvent) expected).exception().toString());
        } else {
            fail("Event " + value + " should be ErrorEvent");
        }
    } else {
        if (value instanceof ErrorEvent) {
            fail("Event " + value + " should not be ErrorEvent");
        }
    }
    if (expected instanceof TimestampedEvent) {
        if (value instanceof TimestampedEvent) {
            assertThat(((TimestampedEvent) value).timestamp()).isEqualTo(((TimestampedEvent) expected).timestamp());
        } else {
            fail("Event " + value + " should be TimestampedEvent");
        }
    } else {
        if (value instanceof TimestampedEvent) {
            fail("Event " + value + " should not be TimestampedEvent");
        }
    }
    if (expected instanceof TaggedEvent) {
        if (value instanceof TaggedEvent) {
            assertThat(((TaggedEvent) value).tags().toString()).isEqualTo(((TaggedEvent) expected).tags().toString());
        } else {
            fail("Event " + value + " should be TaggedEvent");
        }
    } else {
        if (value instanceof TaggedEvent) {
            fail("Event " + value + " should not be TaggedEvent");
        }
    }
    if (expected instanceof MultiCounterEvent) {
        if (value instanceof MultiCounterEvent) {
            assertThat(countersToString(((MultiCounterEvent) value).counters())).isEqualTo(countersToString(((MultiCounterEvent) expected).counters()));
        } else {
            fail("Event " + value + " should be MultiCounterEvent");
        }
    } else {
        if (value instanceof MultiCounterEvent) {
            fail("Event " + value + " should not be MultiCounterEvent");
        }
    }
    if (expected instanceof ThreadSnapshotEvent) {
        if (value instanceof ThreadSnapshotEvent) {
            assertThat(((ThreadSnapshotEvent) value).threadId()).isEqualTo(((ThreadSnapshotEvent) expected).threadId());
            assertThat(((ThreadSnapshotEvent) value).threadName()).isEqualTo(((ThreadSnapshotEvent) expected).threadName());
            assertThat(((ThreadSnapshotEvent) value).threadState()).isEqualTo(((ThreadSnapshotEvent) expected).threadState());
            StackFrameList etrace = ((ThreadSnapshotEvent) expected).stackTrace();
            StackFrameList atrace = ((ThreadSnapshotEvent) value).stackTrace();
            if (etrace == null) {
                assertThat(atrace).isNull();
            } else if (atrace == null) {
                fail("Stack trace should not be null");
            }
            if (etrace != null) {
                assertThat(atrace.toArray()).containsExactly(etrace.toArray());
            }
        } else {
            fail("Event " + value + " should be ThreadSnapshotEvent");
        }
    } else {
        if (value instanceof ThreadSnapshotEvent) {
            fail("Event " + value + " should not be ThreadSnapshotEvent");
        }
    }
    return true;
}
Also used : TaggedEvent(org.gridkit.jvmtool.event.TaggedEvent) StackFrameList(org.gridkit.jvmtool.stacktrace.StackFrameList) TimestampedEvent(org.gridkit.jvmtool.event.TimestampedEvent) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) MultiCounterEvent(org.gridkit.jvmtool.event.MultiCounterEvent)

Example 4 with ErrorEvent

use of org.gridkit.jvmtool.event.ErrorEvent in project jvm-tools by aragozin.

the class EventSeqEqualToCondition method matches.

private boolean matches(Event expected, Event value) {
    if (expected instanceof ErrorEvent) {
        if (value instanceof ErrorEvent) {
            assertThat(((ErrorEvent) value).exception().toString()).isEqualTo(((ErrorEvent) expected).exception().toString());
        } else {
            fail("Event " + value + " should be ErrorEvent");
        }
    } else {
        if (value instanceof ErrorEvent) {
            fail("Event " + value + " should not be ErrorEvent", ((ErrorEvent) value).exception());
        }
    }
    if (expected instanceof TimestampedEvent) {
        if (value instanceof TimestampedEvent) {
            assertThat(((TimestampedEvent) value).timestamp()).isEqualTo(((TimestampedEvent) expected).timestamp());
        } else {
            fail("Event " + value + " should be TimestampedEvent");
        }
    } else {
        if (value instanceof TimestampedEvent) {
            fail("Event " + value + " should not be TimestampedEvent");
        }
    }
    if (expected instanceof TaggedEvent) {
        if (value instanceof TaggedEvent) {
            assertThat(((TaggedEvent) value).tags().toString()).isEqualTo(((TaggedEvent) expected).tags().toString());
        } else {
            fail("Event " + value + " should be TaggedEvent");
        }
    } else {
        if (value instanceof TaggedEvent) {
            fail("Event " + value + " should not be TaggedEvent");
        }
    }
    if (expected instanceof MultiCounterEvent) {
        if (value instanceof MultiCounterEvent) {
            assertThat(countersToString(((MultiCounterEvent) value).counters())).isEqualTo(countersToString(((MultiCounterEvent) expected).counters()));
        } else {
            fail("Event " + value + " should be MultiCounterEvent");
        }
    } else {
        if (value instanceof MultiCounterEvent) {
            fail("Event " + value + " should not be MultiCounterEvent");
        }
    }
    if (expected instanceof ThreadSnapshotEvent) {
        if (value instanceof ThreadSnapshotEvent) {
            assertThat(((ThreadSnapshotEvent) value).threadId()).isEqualTo(((ThreadSnapshotEvent) expected).threadId());
            assertThat(((ThreadSnapshotEvent) value).threadName()).isEqualTo(((ThreadSnapshotEvent) expected).threadName());
            assertThat(((ThreadSnapshotEvent) value).threadState()).isEqualTo(((ThreadSnapshotEvent) expected).threadState());
            StackFrameList etrace = ((ThreadSnapshotEvent) expected).stackTrace();
            StackFrameList atrace = ((ThreadSnapshotEvent) value).stackTrace();
            if (etrace == null) {
                assertThat(atrace).isNull();
            } else if (atrace == null) {
                fail("Stack trace should not be null");
            }
            if (etrace != null) {
                assertThat(atrace.toArray()).containsExactly(etrace.toArray());
            }
        } else {
            fail("Event " + value + " should be ThreadSnapshotEvent");
        }
    } else {
        if (value instanceof ThreadSnapshotEvent) {
            fail("Event " + value + " should not be ThreadSnapshotEvent");
        }
    }
    return true;
}
Also used : TaggedEvent(org.gridkit.jvmtool.event.TaggedEvent) StackFrameList(org.gridkit.jvmtool.stacktrace.StackFrameList) TimestampedEvent(org.gridkit.jvmtool.event.TimestampedEvent) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) MultiCounterEvent(org.gridkit.jvmtool.event.MultiCounterEvent)

Example 5 with ErrorEvent

use of org.gridkit.jvmtool.event.ErrorEvent in project jvm-tools by aragozin.

the class ThreadEventReaderTest method read_dump_v1.

@Test
public void read_dump_v1() throws FileNotFoundException, IOException {
    EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream("src/test/resources/dump_v1.std"));
    int n = 0;
    for (Event e : reader) {
        if (e instanceof ErrorEvent) {
            fail("Error", ((ErrorEvent) e).exception());
        }
        ++n;
    }
    System.out.println("Read " + n + " traces from file");
}
Also used : ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ErrorEvent (org.gridkit.jvmtool.event.ErrorEvent)5 Test (org.junit.Test)3 FileInputStream (java.io.FileInputStream)2 Event (org.gridkit.jvmtool.event.Event)2 MultiCounterEvent (org.gridkit.jvmtool.event.MultiCounterEvent)2 TaggedEvent (org.gridkit.jvmtool.event.TaggedEvent)2 TimestampedEvent (org.gridkit.jvmtool.event.TimestampedEvent)2 StackFrameList (org.gridkit.jvmtool.stacktrace.StackFrameList)2 EventDecorator (org.gridkit.jvmtool.event.EventDecorator)1 SimpleErrorEvent (org.gridkit.jvmtool.event.SimpleErrorEvent)1