summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorTerry Parker <tparker@google.com>2020-10-21 11:53:35 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2020-10-21 11:53:35 -0400
commitdd593205a02ecf579f55738a98820be7bbf51e01 (patch)
tree6e07480dc51a9d0e7473a0c63a04e3f5e75b1392 /org.eclipse.jgit.test
parentde914b7caf763b74161552285fed409fe552df64 (diff)
parenta09e2051764c751b69eee7ba52c5e8cf7bb3197a (diff)
downloadjgit-dd593205a02ecf579f55738a98820be7bbf51e01.tar.gz
jgit-dd593205a02ecf579f55738a98820be7bbf51e01.zip
Merge "Add new performance logging"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java66
1 files changed, 66 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
new file mode 100644
index 0000000000..e061833d17
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/logging/PerformanceLogContextTest.java
@@ -0,0 +1,66 @@
+package org.eclipse.jgit.logging;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import java.util.List;
+
+/**
+ * Tests for performance log context utilities.
+ */
+public class PerformanceLogContextTest {
+
+ @Test
+ public void testAddEvent() {
+ PerformanceLogRecord record = new PerformanceLogRecord("record", 0);
+ PerformanceLogContext.getInstance().addEvent(record);
+
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertTrue(eventRecords.contains(record));
+ assertEquals(1, eventRecords.size());
+ }
+
+ @Test
+ public void testCleanEvents() {
+ PerformanceLogRecord record1 = new PerformanceLogRecord("record1", 0);
+ PerformanceLogContext.getInstance().addEvent(record1);
+
+ PerformanceLogRecord record2 = new PerformanceLogRecord("record2", 0);
+ PerformanceLogContext.getInstance().addEvent(record2);
+
+ PerformanceLogContext.getInstance().cleanEvents();
+ List<PerformanceLogRecord> eventRecords = PerformanceLogContext
+ .getInstance().getEventRecords();
+ assertEquals(0, eventRecords.size());
+ }
+
+ @Test
+ public void testAddEventsTwoThreads() {
+ TestRunnable thread1 = new TestRunnable("record1", 1);
+ TestRunnable thread2 = new TestRunnable("record2", 2);
+
+ new Thread(thread1).start();
+ new Thread(thread2).start();
+ }
+
+ private static class TestRunnable implements Runnable {
+ private String name;
+ private long durationMs;
+
+ public TestRunnable(String name, long durationMs) {
+ this.name = name;
+ this.durationMs = durationMs;
+ }
+
+ @Override
+ public void run() {
+ PerformanceLogRecord record = new PerformanceLogRecord(name,
+ durationMs);
+ PerformanceLogContext.getInstance().addEvent(record);
+ assertEquals(1, PerformanceLogContext.getInstance()
+ .getEventRecords().size());
+ }
+ }
+}