From 5bda613ae4438ee9732d54beec16ac3af21564fa Mon Sep 17 00:00:00 2001 From: Woonduk Kang Date: Mon, 10 Feb 2014 07:46:59 +0000 Subject: [PATCH] =?UTF-8?q?[=EA=B0=95=EC=9A=B4=EB=8D=95]=20[PINPOINT-258]?= =?UTF-8?q?=20timestamp=EB=A5=BC=20Range=EA=B0=9D=EC=B2=B4=EB=A1=9C=20?= =?UTF-8?q?=EB=AC=B6=EC=96=B4=EC=84=9C=20=EB=8B=A4=EB=8B=88=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95=ED=95=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://svn.bds.nhncorp.com/pe/hippo-web/trunk@3302 84d0f5b1-2673-498c-a247-62c4ff18d310 --- .../web/dao/hbase/HbaseAgentStatDao.java | 11 +++---- ...baseApplicationMapStatisticsCallerDao.java | 8 ++++- .../hbase/HbaseApplicationTraceIndexDao.java | 6 ++++ .../java/com/nhn/pinpoint/web/vo/Range.java | 10 ++++++ .../com/nhn/pinpoint/web/vo/RangeTest.java | 31 +++++++++++++++++++ 5 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 src/test/java/com/nhn/pinpoint/web/vo/RangeTest.java diff --git a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseAgentStatDao.java b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseAgentStatDao.java index 2d6fed295..4150aaaed 100644 --- a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseAgentStatDao.java +++ b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseAgentStatDao.java @@ -53,21 +53,20 @@ public class HbaseAgentStatDao implements AgentStatDao { if (agentId == null) { throw new NullPointerException("agentId must not be null"); } + if (range == null) { + throw new NullPointerException("range must not be null"); + } if (logger.isDebugEnabled()) { logger.debug("scanAgentStat : agentId={}, {}", agentId, range); } - if (range.getTo() < range.getFrom()) { - logger.error("invalid parameter : agentId={}, {}", agentId, range); - return Collections.emptyList(); - } - + Scan scan = createScan(agentId, range); List> intermediate = hbaseOperations2.find(HBaseTables.AGENT_STAT, scan, rowKeyDistributor, agentStatMapper); - int expectedSize = (int)((range.getTo() - range.getFrom()) / 5000); // 5초간 데이터 + int expectedSize = (int)(range.getRange() / 5000); // 5초간 데이터 List merged = new ArrayList(expectedSize); for(List each : intermediate) { diff --git a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationMapStatisticsCallerDao.java b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationMapStatisticsCallerDao.java index ce87906cb..cf2d10e62 100644 --- a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationMapStatisticsCallerDao.java +++ b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationMapStatisticsCallerDao.java @@ -48,7 +48,13 @@ public class HbaseApplicationMapStatisticsCallerDao implements ApplicationMapSta @Override public List selectCaller(Application calleeApplication, Range range) { - Scan scan = createScan(calleeApplication, range); + if (calleeApplication == null) { + throw new NullPointerException("calleeApplication must not be null"); + } + if (range == null) { + throw new NullPointerException("range must not be null"); + } + Scan scan = createScan(calleeApplication, range); final List> foundListList = hbaseOperations2.find(HBaseTables.APPLICATION_MAP_STATISTICS_CALLER, scan, applicationMapStatisticsCallerMapper); if (foundListList.isEmpty()) { diff --git a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDao.java b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDao.java index 89f98d509..733b407a8 100644 --- a/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDao.java +++ b/src/main/java/com/nhn/pinpoint/web/dao/hbase/HbaseApplicationTraceIndexDao.java @@ -63,6 +63,9 @@ public class HbaseApplicationTraceIndexDao implements ApplicationTraceIndexDao { if (applicationName == null) { throw new NullPointerException("applicationName must not be null"); } + if (range == null) { + throw new NullPointerException("range must not be null"); + } if (limit < 0) { throw new IllegalArgumentException("negative limit:" + limit); } @@ -149,6 +152,9 @@ public class HbaseApplicationTraceIndexDao implements ApplicationTraceIndexDao { if (applicationName == null) { throw new NullPointerException("applicationName must not be null"); } + if (range == null) { + throw new NullPointerException("range must not be null"); + } if (limit < 0) { throw new IllegalArgumentException("negative limit:" + limit); } diff --git a/src/main/java/com/nhn/pinpoint/web/vo/Range.java b/src/main/java/com/nhn/pinpoint/web/vo/Range.java index 1fcc56848..eee07e8d5 100644 --- a/src/main/java/com/nhn/pinpoint/web/vo/Range.java +++ b/src/main/java/com/nhn/pinpoint/web/vo/Range.java @@ -10,6 +10,7 @@ public final class Range { public Range(long from, long to) { this.from = from; this.to = to; + isValidate(); } public long getFrom() { @@ -20,6 +21,15 @@ public final class Range { return to; } + public long getRange() { + return to - from; + } + + private void isValidate() { + if (this.to < this.from) { + throw new IllegalArgumentException("invalid range:" + this); + } + } @Override public boolean equals(Object o) { diff --git a/src/test/java/com/nhn/pinpoint/web/vo/RangeTest.java b/src/test/java/com/nhn/pinpoint/web/vo/RangeTest.java new file mode 100644 index 000000000..9d9dcaabd --- /dev/null +++ b/src/test/java/com/nhn/pinpoint/web/vo/RangeTest.java @@ -0,0 +1,31 @@ +package com.nhn.pinpoint.web.vo; + +import junit.framework.Assert; +import org.junit.Test; + +/** + * @author emeroad + */ +public class RangeTest { + @Test + public void testCreate() { + Range range1 = new Range(0, 0); + Range range2 = new Range(0, 1); + + try { + Range range3 = new Range(0, -1); + Assert.fail(); + } catch (Exception e) { + } + + } + + @Test + public void testRange() { + Range range1 = new Range(0, 0); + Assert.assertEquals(range1.getRange(), 0); + + Range range2 = new Range(0, 1); + Assert.assertEquals(range2.getRange(), 1); + } +}