Search in sources :

Example 1 with StackFrameList

use of org.gridkit.jvmtool.stacktrace.StackFrameList 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 2 with StackFrameList

use of org.gridkit.jvmtool.stacktrace.StackFrameList 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)

Aggregations

ErrorEvent (org.gridkit.jvmtool.event.ErrorEvent)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