accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From els...@apache.org
Subject svn commit: r1461381 - in /accumulo/branches/1.5/server/src: main/java/org/apache/accumulo/server/monitor/servlets/trace/ test/java/org/apache/accumulo/server/monitor/
Date Wed, 27 Mar 2013 00:54:56 GMT
Author: elserj
Date: Wed Mar 27 00:54:55 2013
New Revision: 1461381

URL: http://svn.apache.org/r1461381
Log:
ACCUMULO-1206 Override compareTo to sort the trace entries by start time instead of their
toString(). Add a simple test to make sure the Comparator compares correctly.

Added:
    accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java
  (with props)
    accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java
  (with props)
Modified:
    accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ListType.java

Modified: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ListType.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ListType.java?rev=1461381&r1=1461380&r2=1461381&view=diff
==============================================================================
--- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ListType.java
(original)
+++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ListType.java
Wed Mar 27 00:54:55 2013
@@ -16,13 +16,11 @@
  */
 package org.apache.accumulo.server.monitor.servlets.trace;
 
-import java.util.Date;
 import java.util.Map.Entry;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
-import org.apache.accumulo.trace.thrift.RemoteSpan;
 import org.apache.accumulo.core.client.Scanner;
 import org.apache.accumulo.core.data.Key;
 import org.apache.accumulo.core.data.Range;
@@ -31,6 +29,7 @@ import org.apache.accumulo.core.trace.Tr
 import org.apache.accumulo.server.monitor.util.Table;
 import org.apache.accumulo.server.monitor.util.celltypes.DurationType;
 import org.apache.accumulo.server.monitor.util.celltypes.StringType;
+import org.apache.accumulo.trace.thrift.RemoteSpan;
 import org.apache.hadoop.io.Text;
 
 
@@ -46,16 +45,6 @@ public class ListType extends Basic {
     return getIntParameter(req, "minutes", Summary.DEFAULT_MINUTES);
   }
   
-  private static class ShowTraceLinkType extends StringType<RemoteSpan> {
-    
-    public String format(Object obj) {
-      if (obj == null)
-        return "-";
-      RemoteSpan span = (RemoteSpan) obj;
-      return String.format("<a href='/trace/show?id=%s'>%s</a>", Long.toHexString(span.traceId),
TraceFormatter.formatDate(new Date(span.start)));
-    }
-  }
-  
   @Override
   public void pageBody(HttpServletRequest req, HttpServletResponse resp, StringBuilder sb)
throws Exception {
     String type = getType(req);

Added: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java?rev=1461381&view=auto
==============================================================================
--- accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java
(added)
+++ accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java
Wed Mar 27 00:54:55 2013
@@ -0,0 +1,47 @@
+/*
+ * 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 java.util.Date;
+
+import org.apache.accumulo.core.trace.TraceFormatter;
+import org.apache.accumulo.server.monitor.util.celltypes.StringType;
+import org.apache.accumulo.trace.thrift.RemoteSpan;
+
+/**
+ * 
+ */
+public class ShowTraceLinkType extends StringType<RemoteSpan> {
+  @Override
+  public String format(Object obj) {
+    if (obj == null)
+      return "-";
+    RemoteSpan span = (RemoteSpan) obj;
+    return String.format("<a href='/trace/show?id=%s'>%s</a>", Long.toHexString(span.traceId),
TraceFormatter.formatDate(new Date(span.start)));
+  }
+  
+  @Override
+  public int compare(RemoteSpan o1, RemoteSpan o2) {
+    if (o1 == null && o2 == null)
+      return 0;
+    else if (o1 == null)
+      return -1;
+    else if (o2 == null)
+      return 1;
+    return o1.start < o2.start ? -1 : (o1.start == o2.start ? 0 : 1);
+  }
+}

Propchange: accumulo/branches/1.5/server/src/main/java/org/apache/accumulo/server/monitor/servlets/trace/ShowTraceLinkType.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java
URL: http://svn.apache.org/viewvc/accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java?rev=1461381&view=auto
==============================================================================
--- accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java
(added)
+++ accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java
Wed Mar 27 00:54:55 2013
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Collections;
+
+import org.apache.accumulo.trace.thrift.RemoteSpan;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class ShowTraceLinkTypeTest {
+  
+  @Test
+  public void testTraceSortingForMonitor() {
+    /* public RemoteSpan(String sender, String svc, long traceId, long spanId,
+          long parentId, long start, long stop, String description, Map<String,String>
data) */
+    ArrayList<RemoteSpan> spans = new ArrayList<RemoteSpan>(10), expectedOrdering
= new ArrayList<RemoteSpan>(10);
+
+    // "Random" ordering
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 55l, 75l, "desc5", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 25l, 30l, "desc2", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 85l, 90l, "desc8", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 45l, 60l, "desc4", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 35l, 55l, "desc3", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 95l, 110l, "desc9", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 65l, 80l, "desc6", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 100l, 120l, "desc10", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 15l, 25l, "desc1", Collections.<String,String>
emptyMap()));
+    spans.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 75l, 100l, "desc7", Collections.<String,String>
emptyMap()));
+    
+    // We expect them to be sorted by 'start'
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 15l, 25l, "desc1", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 25l, 30l, "desc2", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 35l, 55l, "desc3", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 45l, 60l, "desc4", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 55l, 75l, "desc5", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 65l, 80l, "desc6", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 75l, 100l, "desc7",
Collections.<String,String> emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 85l, 90l, "desc8", Collections.<String,String>
emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 95l, 110l, "desc9",
Collections.<String,String> emptyMap()));
+    expectedOrdering.add(new RemoteSpan("sender", "svc", 0l, 0l, 0l, 100l, 120l, "desc10",
Collections.<String,String> emptyMap()));
+    
+    Collections.sort(spans);
+    
+    Assert.assertEquals(expectedOrdering, spans);
+  }
+}

Propchange: accumulo/branches/1.5/server/src/test/java/org/apache/accumulo/server/monitor/ShowTraceLinkTypeTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message