From 06122eb830e4a538e1f23b6a68ff28380629cb28 Mon Sep 17 00:00:00 2001 From: "koo.taejin" Date: Fri, 29 Apr 2016 15:06:59 +0900 Subject: [PATCH] the number of success and failure dot in scatter chart different from success and failure dot count . #1732 --- .../pinpoint/web/scatter/DotGroups.java | 66 ++++++++++++++++--- .../pinpoint/web/scatter/ScatterDataTest.java | 48 +++++++++++++- 2 files changed, 103 insertions(+), 11 deletions(-) diff --git a/web/src/main/java/com/navercorp/pinpoint/web/scatter/DotGroups.java b/web/src/main/java/com/navercorp/pinpoint/web/scatter/DotGroups.java index 342ba0450002..31fb40039e57 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/scatter/DotGroups.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/scatter/DotGroups.java @@ -34,17 +34,19 @@ public class DotGroups { private static final DotComparator DOT_COMPARATOR = new DotComparator(); private final long xCoordinates; - private final Map dotGroupMap = new HashMap<>(); + private final Map dotGroupMap = new HashMap<>(); public DotGroups(long xCoordinates) { this.xCoordinates = xCoordinates; } void addDot(Coordinates coordinates, Dot dot) { - DotGroup dotGroup = dotGroupMap.get(coordinates); + Key key = new Key(coordinates, dot.getSimpleExceptionCode()); + + DotGroup dotGroup = dotGroupMap.get(key); if (dotGroup == null) { dotGroup = new DotGroup(coordinates); - dotGroupMap.put(coordinates, dotGroup); + dotGroupMap.put(key, dotGroup); } dotGroup.addDot(dot); @@ -55,9 +57,9 @@ void merge(DotGroups dotGroups) { return; } - Map dotGroupMap = dotGroups.getDotGroupMap(); - for (Map.Entry entry : dotGroupMap.entrySet()) { - Coordinates key = entry.getKey(); + Map dotGroupMap = dotGroups.getDotGroupMap(); + for (Map.Entry entry : dotGroupMap.entrySet()) { + Key key = entry.getKey(); DotGroup dotGroup = this.dotGroupMap.get(key); if (dotGroup == null) { @@ -72,7 +74,7 @@ public long getXCoordinates() { return xCoordinates; } - public Map getDotGroupMap() { + public Map getDotGroupMap() { return dotGroupMap; } @@ -142,8 +144,56 @@ public int compare(Dot o1, Dot o2) { return compare; } - } + class Key { + + private final Coordinates coordinates; + private final int code; + + public Key(Coordinates coordinates, int code) { + this.coordinates = coordinates; + this.code = code; + } + + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null || getClass() != obj.getClass()) { + return false; + } + + Key that = (Key) obj; + + if (!coordinates.equals(that.coordinates)) { + return false; + } + + if (code != that.code) { + return false; + } + + return true; + } + + @Override + public int hashCode() { + int result = coordinates != null ? coordinates.hashCode() : 0; + result = 31 * result + code; + return result; + } + + @Override + public String toString() { + return "Key{" + + "coordinates=" + coordinates + + ", code=" + code + + '}'; + } + + } } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/scatter/ScatterDataTest.java b/web/src/test/java/com/navercorp/pinpoint/web/scatter/ScatterDataTest.java index cdd7d893c023..d5f683cb1a1a 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/scatter/ScatterDataTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/scatter/ScatterDataTest.java @@ -21,8 +21,10 @@ import org.junit.Test; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Random; import java.util.concurrent.ThreadLocalRandom; @@ -31,6 +33,9 @@ */ public class ScatterDataTest { + String agentId = "agent"; + String transactionAgentId = "transactionAgent"; + @Test public void addDotTest() throws Exception { int count = 100; @@ -41,7 +46,7 @@ public void addDotTest() throws Exception { int yGroupUnit = 100; ScatterData scatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit); - List dotList = createDotList("agent", "transactionAgent", count, from); + List dotList = createDotList(agentId, transactionAgentId, count, from); for (Dot dot : dotList) { scatterData.addDot(dot); @@ -51,6 +56,42 @@ public void addDotTest() throws Exception { Assert.assertEquals(count, dots.size()); } + @Test + public void addDotTest2() throws Exception { + long from = 1000; + long to = 10000; + int xGroupUnit = 100; + int yGroupUnit = 100; + + ScatterData scatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit); + + long currentTime = System.currentTimeMillis(); + + TransactionId transactionId1 = new TransactionId(transactionAgentId, currentTime, 1); + TransactionId transactionId2 = new TransactionId(transactionAgentId, currentTime, 2); + + long acceptedTime = Math.max(Math.abs(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)), from); + int executionTime = (int) Math.abs(ThreadLocalRandom.current().nextLong(60 * 1000)); + + long acceptedTime2 = Math.max(Math.abs(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)), from); + + Dot dot1 = new Dot(transactionId1, acceptedTime2, executionTime, 0, agentId); + Dot dot2 = new Dot(transactionId2, acceptedTime2, executionTime, 1, agentId); + + scatterData.addDot(dot1); + scatterData.addDot(dot2); + + Map scatterDataMap = scatterData.getScatterDataMap(); + Collection values = scatterDataMap.values(); + Assert.assertTrue(values.size() == 1); + + for (DotGroups dotGroups : values) { + Map dotGroupLeaders = dotGroups.getDotGroupLeaders(); + Assert.assertTrue(dotGroupLeaders.keySet().size() == 2); + } + } + + @Test public void mergeTest() throws Exception { int count = 100; @@ -61,7 +102,7 @@ public void mergeTest() throws Exception { int yGroupUnit = 100; ScatterData scatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit); - List dotList = createDotList("agent", "transactionAgent", count, from); + List dotList = createDotList(agentId, transactionAgentId, count, from); for (Dot dot : dotList) { ScatterData newScatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit); newScatterData.addDot(dot); @@ -85,7 +126,8 @@ private List createDotList(String agentId, String transactionAgentId, int c List dotList = new ArrayList<>(createSize); for (int i = 0; i < createSize; i++) { - dotList.add(new Dot(transactionIdList.get(i), Math.max(Math.abs(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)), from), executionTime, Dot.EXCEPTION_NONE, agentId)); + int exceptionCode = ThreadLocalRandom.current().nextInt(0, 2); + dotList.add(new Dot(transactionIdList.get(i), Math.max(Math.abs(ThreadLocalRandom.current().nextLong(Long.MAX_VALUE)), from), executionTime, exceptionCode, agentId)); } long seed = System.nanoTime();