use of org.gridkit.jvmtool.event.TimestampedEvent 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;
}
use of org.gridkit.jvmtool.event.TimestampedEvent in project jvm-tools by aragozin.
the class StackTraceEventWriterV4 method storeThreadEvent.
protected void storeThreadEvent(ThreadTraceEvent snap) throws IOException {
TagCollection stags = (snap instanceof TaggedEvent) ? ((TaggedEvent) snap).tags() : null;
CounterCollection scc = (snap instanceof MultiCounterEvent) ? ((MultiCounterEvent) snap).counters() : null;
tagBuilder.clear();
// mark unconditionally
markTags();
long timestamp = -1;
if (snap instanceof TimestampedEvent) {
markTimestamp();
timestamp = ((TimestampedEvent) snap).timestamp();
}
//TODO empty stack trace is encoded for compatibility with old readers
if (snap.stackTrace() != null) /*&& !snap.stackTrace().isEmpty()*/
{
markThreadStackTrace();
for (StackFrame ste : snap.stackTrace()) {
intern(ste.toStackTraceElement());
}
}
if (scc != null) {
ensureCounters(scc);
}
int tagSetId = ensureTagSet(stags);
dos.writeByte(StackTraceCodec.TAG_EVENT);
StackTraceCodec.writeVarInt(dos, tagSetId);
writeTimestamp(timestamp);
writeCounters(scc);
writeTrace(snap.stackTrace());
}
use of org.gridkit.jvmtool.event.TimestampedEvent 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;
}
Aggregations