Skip to content

Commit

Permalink
Merge pull request pinpoint-apm#1733 from koo-taejin/pinpoint-apm#1732
Browse files Browse the repository at this point in the history
the number of success and failure dot in scatter chart different from…
reviewed by @jaehong-kim
  • Loading branch information
jaehong-kim committed Apr 29, 2016
2 parents f44a6fe + 06122eb commit 62f3677
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,19 @@ public class DotGroups {
private static final DotComparator DOT_COMPARATOR = new DotComparator();

private final long xCoordinates;
private final Map<Coordinates, DotGroup> dotGroupMap = new HashMap<>();
private final Map<Key, DotGroup> 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);
Expand All @@ -55,9 +57,9 @@ void merge(DotGroups dotGroups) {
return;
}

Map<Coordinates, DotGroup> dotGroupMap = dotGroups.getDotGroupMap();
for (Map.Entry<Coordinates, DotGroup> entry : dotGroupMap.entrySet()) {
Coordinates key = entry.getKey();
Map<Key, DotGroup> dotGroupMap = dotGroups.getDotGroupMap();
for (Map.Entry<Key, DotGroup> entry : dotGroupMap.entrySet()) {
Key key = entry.getKey();

DotGroup dotGroup = this.dotGroupMap.get(key);
if (dotGroup == null) {
Expand All @@ -72,7 +74,7 @@ public long getXCoordinates() {
return xCoordinates;
}

public Map<Coordinates, DotGroup> getDotGroupMap() {
public Map<Key, DotGroup> getDotGroupMap() {
return dotGroupMap;
}

Expand Down Expand Up @@ -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 +
'}';
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -31,6 +33,9 @@
*/
public class ScatterDataTest {

String agentId = "agent";
String transactionAgentId = "transactionAgent";

@Test
public void addDotTest() throws Exception {
int count = 100;
Expand All @@ -41,7 +46,7 @@ public void addDotTest() throws Exception {
int yGroupUnit = 100;

ScatterData scatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit);
List<Dot> dotList = createDotList("agent", "transactionAgent", count, from);
List<Dot> dotList = createDotList(agentId, transactionAgentId, count, from);

for (Dot dot : dotList) {
scatterData.addDot(dot);
Expand All @@ -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<Long, DotGroups> scatterDataMap = scatterData.getScatterDataMap();
Collection<DotGroups> values = scatterDataMap.values();
Assert.assertTrue(values.size() == 1);

for (DotGroups dotGroups : values) {
Map<Dot, DotGroup> dotGroupLeaders = dotGroups.getDotGroupLeaders();
Assert.assertTrue(dotGroupLeaders.keySet().size() == 2);
}
}


@Test
public void mergeTest() throws Exception {
int count = 100;
Expand All @@ -61,7 +102,7 @@ public void mergeTest() throws Exception {
int yGroupUnit = 100;

ScatterData scatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit);
List<Dot> dotList = createDotList("agent", "transactionAgent", count, from);
List<Dot> dotList = createDotList(agentId, transactionAgentId, count, from);
for (Dot dot : dotList) {
ScatterData newScatterData = new ScatterData(from, to, xGroupUnit, yGroupUnit);
newScatterData.addDot(dot);
Expand All @@ -85,7 +126,8 @@ private List<Dot> createDotList(String agentId, String transactionAgentId, int c

List<Dot> 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();
Expand Down

0 comments on commit 62f3677

Please # to comment.