You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ch...@apache.org on 2018/01/19 06:26:46 UTC

[sling-org-apache-sling-tracer] branch master updated (37560c1 -> c3443ea)

This is an automated email from the ASF dual-hosted git repository.

chetanm pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tracer.git.


    from 37560c1  [maven-release-plugin] prepare for next development iteration
     add c09c86b  SLING-6506 - Handling of UNION'd queries in Sling Log Tracer
     new c3443ea  SLING-6506 - Sling Log Tracer queries reports Plan that does not match Query statement

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../sling/tracer/internal/JSONRecording.java       | 14 +++++++-
 .../org/apache/sling/tracer/internal/Util.java     | 18 ++++++++++
 .../sling/tracer/internal/JSONRecordingTest.java   | 39 ++++++++++++++++++++++
 .../org/apache/sling/tracer/internal/UtilTest.java |  7 ++++
 4 files changed, 77 insertions(+), 1 deletion(-)

-- 
To stop receiving notification emails like this one, please contact
['"commits@sling.apache.org" <co...@sling.apache.org>'].

[sling-org-apache-sling-tracer] 01/01: SLING-6506 - Sling Log Tracer queries reports Plan that does not match Query statement

Posted by ch...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

chetanm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-tracer.git

commit c3443eaeb8ec12156947588e9cf05b018c1b5464
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Fri Jan 19 11:51:32 2018 +0530

    SLING-6506 - Sling Log Tracer queries reports Plan that does not match Query statement
    
    Refactor the count method
---
 .../sling/tracer/internal/JSONRecording.java       | 25 ++++------------------
 .../org/apache/sling/tracer/internal/Util.java     | 18 ++++++++++++++++
 .../org/apache/sling/tracer/internal/UtilTest.java |  7 ++++++
 3 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java b/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java
index 192cc04..05d8959 100644
--- a/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java
+++ b/src/main/java/org/apache/sling/tracer/internal/JSONRecording.java
@@ -54,6 +54,7 @@ import org.slf4j.helpers.FormattingTuple;
 import org.slf4j.helpers.MessageFormatter;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.sling.tracer.internal.Util.count;
 import static org.apache.sling.tracer.internal.Util.nullSafeString;
 import static org.apache.sling.tracer.internal.Util.nullSafeTrim;
 
@@ -399,33 +400,15 @@ class JSONRecording implements Recording, Comparable<JSONRecording> {
                         plan = nullSafeString(args[0]);
 
                         // Determine number of sub-queries in this UNION query so they can be ignored
-                        int tmp = count(plan, "*/ union ");
-                        if (tmp > 0) {
-                            subPlans = tmp + 1;
+                        int unionCount = count(plan, "*/ union ");
+                        if (unionCount > 0) {
+                            subPlans = unionCount + 1;
                         }
                     }
                 }
             }
         }
 
-        /**
-         * Counts the number of instances the needle in the haystack.
-         * @param haystack the string to count the occurrences of the needle in.
-         * @param needle the string to count the number of occurrences of.
-         * @return the number of occurences the needle appears in the haystack.
-         */
-        private int count(final String haystack, final String needle) {
-            int count = 0;
-            int i = 0;
-
-            while ((i = haystack.indexOf(needle, i)) != -1) {
-                i++;
-                count++;
-            }
-
-            return count;
-        }
-
         private String determineCaller() {
             StackTraceElement caller = queryCallerFinder.determineCaller(Thread.currentThread().getStackTrace());
             if (caller != null) {
diff --git a/src/main/java/org/apache/sling/tracer/internal/Util.java b/src/main/java/org/apache/sling/tracer/internal/Util.java
index 617881e..fd32254 100644
--- a/src/main/java/org/apache/sling/tracer/internal/Util.java
+++ b/src/main/java/org/apache/sling/tracer/internal/Util.java
@@ -44,4 +44,22 @@ class Util {
         }
         return s.trim();
     }
+
+    /**
+     * Counts the number of instances the needle in the haystack.
+     * @param haystack the string to count the occurrences of the needle in.
+     * @param needle the string to count the number of occurrences of.
+     * @return the number of occurences the needle appears in the haystack.
+     */
+    static int count(final String haystack, final String needle) {
+        int count = 0;
+        int i = 0;
+
+        while ((i = haystack.indexOf(needle, i)) != -1) {
+            i++;
+            count++;
+        }
+
+        return count;
+    }
 }
diff --git a/src/test/java/org/apache/sling/tracer/internal/UtilTest.java b/src/test/java/org/apache/sling/tracer/internal/UtilTest.java
index 8dd878e..829845e 100644
--- a/src/test/java/org/apache/sling/tracer/internal/UtilTest.java
+++ b/src/test/java/org/apache/sling/tracer/internal/UtilTest.java
@@ -46,4 +46,11 @@ public class UtilTest {
         assertEquals("foo", Util.nullSafeTrim(" foo"));
     }
 
+    @Test
+    public void count() throws Exception{
+        assertEquals(2, Util.count("she sell sea shells on the sea shore", "sea"));
+        assertEquals(1, Util.count("she sell sea shells on the sea shore", "shore"));
+        assertEquals(0, Util.count("she sell sea shells on the sea shore", "tiger"));
+    }
+
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.