You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by el...@apache.org on 2014/04/05 03:46:11 UTC

[3/6] git commit: ACCUMULO-2631 Make sure a valid range is created.

ACCUMULO-2631 Make sure a valid range is created.


Project: http://git-wip-us.apache.org/repos/asf/accumulo/repo
Commit: http://git-wip-us.apache.org/repos/asf/accumulo/commit/7ffa80a1
Tree: http://git-wip-us.apache.org/repos/asf/accumulo/tree/7ffa80a1
Diff: http://git-wip-us.apache.org/repos/asf/accumulo/diff/7ffa80a1

Branch: refs/heads/master
Commit: 7ffa80a183ad5e8e4d9487a521acae0eb6951c26
Parents: ab41a5f
Author: Josh Elser <el...@apache.org>
Authored: Fri Apr 4 21:23:32 2014 -0400
Committer: Josh Elser <el...@apache.org>
Committed: Fri Apr 4 21:23:32 2014 -0400

----------------------------------------------------------------------
 .../server/monitor/servlets/trace/Summary.java  | 21 ++++++++--
 .../monitor/servlets/trace/SummaryTest.java     | 42 ++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/accumulo/blob/7ffa80a1/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Summary.java
----------------------------------------------------------------------
diff --git a/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Summary.java b/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Summary.java
index 329cf4f..e9f7d4a 100644
--- a/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Summary.java
+++ b/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/Summary.java
@@ -121,18 +121,33 @@ public class Summary extends Basic {
       return 0;
     }
   }
+
+  protected Range getRangeForTrace(long minutesSince) {
+    long endTime = System.currentTimeMillis();
+    long millisSince = minutesSince * 60 * 1000;
+    // Catch the overflow
+    if (millisSince < minutesSince) {
+      millisSince = endTime;
+    }
+    long startTime = endTime - millisSince;
+
+    String startHexTime = Long.toHexString(startTime), endHexTime = Long.toHexString(endTime);
+    while (startHexTime.length() < endHexTime.length()) {
+      startHexTime = "0" + startHexTime;
+    }
+
+    return new Range(new Text("start:" + startHexTime), new Text("start:" + endHexTime));
+  }
   
   @Override
   public void pageBody(HttpServletRequest req, HttpServletResponse resp, StringBuilder sb) throws Exception {
     int minutes = getMinutes(req);
-    long endTime = System.currentTimeMillis();
-    long startTime = endTime - minutes * 60 * 1000;
     
     Scanner scanner = getScanner(sb);
     if (scanner == null) {
       return;
     }
-    Range range = new Range(new Text("start:" + Long.toHexString(startTime)), new Text("start:" + Long.toHexString(endTime)));
+    Range range = getRangeForTrace(minutes);
     scanner.setRange(range);
     Map<String,Stats> summary = new TreeMap<String,Stats>();
     for (Entry<Key,Value> entry : scanner) {

http://git-wip-us.apache.org/repos/asf/accumulo/blob/7ffa80a1/server/src/test/java/org/apache/accumulo/server/monitor/servlets/trace/SummaryTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/accumulo/server/monitor/servlets/trace/SummaryTest.java b/server/src/test/java/org/apache/accumulo/server/monitor/servlets/trace/SummaryTest.java
new file mode 100644
index 0000000..f983066
--- /dev/null
+++ b/server/src/test/java/org/apache/accumulo/server/monitor/servlets/trace/SummaryTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.accumulo.server.monitor.servlets.trace;
+
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * 
+ */
+public class SummaryTest {
+
+  private Summary summary;
+
+  @Before
+  public void setup() {
+    summary = new Summary();
+  }
+
+  @Test
+  public void testRangeValues() {
+    summary.getRangeForTrace(10);
+    summary.getRangeForTrace(100);
+    summary.getRangeForTrace(4990000);
+    summary.getRangeForTrace(Long.MAX_VALUE);
+  }
+
+}