You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2019/11/04 14:13:13 UTC

[sling-org-apache-sling-engine] branch master updated (24e8b04 -> 8afe797)

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

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


    from 24e8b04  SLING-8635 : Close resource resolver at the end of each request
     new b16d659  SLING-8826 - add a test that demonstrates the problem
     new 8afe797  SLING-8826 - fix allowDuration() for duration provided in nanoseconds

The 2 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:
 .../debug/RequestProgressTrackerLogFilter.java     |   4 +-
 .../debug/RequestProgressTrackerLogFilterTest.java | 100 +++++++++++++++++++++
 2 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java


[sling-org-apache-sling-engine] 02/02: SLING-8826 - fix allowDuration() for duration provided in nanoseconds

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

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

commit 8afe797af9738c92e540c24182751ed501b0b619
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Nov 4 15:12:12 2019 +0100

    SLING-8826 - fix allowDuration() for duration provided in nanoseconds
---
 .../sling/engine/impl/debug/RequestProgressTrackerLogFilter.java      | 4 ++--
 .../sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java b/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
index 75947ad..7ff83ac 100644
--- a/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
+++ b/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
@@ -95,7 +95,7 @@ public class RequestProgressTrackerLogFilter implements Filter {
 
     private String[] extensions;
 
-    static final int NANOSEC_TO_MSEC = 1000000;
+    static final int NANOSEC_TO_MSEC = 1_000_000;
 
     @Override
     public void init(final FilterConfig filterConfig) throws ServletException {
@@ -167,7 +167,7 @@ public class RequestProgressTrackerLogFilter implements Filter {
 
     private boolean allowDuration(final RequestProgressTracker rpt) {
         if (rpt instanceof SlingRequestProgressTracker) {
-            long duration = ((SlingRequestProgressTracker) rpt).getDuration();
+            final long duration = ((SlingRequestProgressTracker) rpt).getDuration() / NANOSEC_TO_MSEC;
             return configuration.minDurationMs() <= duration && duration <= configuration.maxDurationMs();
         } else {
             log.debug("Logged requests can only be filtered by duration if the SlingRequestProgressTracker is used.");
diff --git a/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java b/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java
index bd7b88a..9c6ae42 100644
--- a/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java
+++ b/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java
@@ -90,11 +90,11 @@ public class RequestProgressTrackerLogFilterTest {
         Thread.sleep(delta * 2);
         rpt.done();
         final long durationNanos = rpt.getDuration();
-        final long durationMsec = durationNanos; // TODO SLING-8826: should be duration / 1000;
+        final long durationMsec = durationNanos / 1_000_000;
         final int minMsec = (int)(durationMsec - delta);
         final int maxMsec = (int)(durationMsec + delta);
         setupMinMaxDuration(filter, minMsec, maxMsec);
-        assertTrue("Expecting duration " + durationNanos + " to allowed for min=" + minMsec + " max=" + maxMsec,
+        assertTrue("Expecting duration " + durationNanos + "/" + durationMsec + " to allowed for min=" + minMsec + " max=" + maxMsec,
             (boolean)allowDuration.invoke(filter, rpt));
     }
 }


[sling-org-apache-sling-engine] 01/02: SLING-8826 - add a test that demonstrates the problem

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

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

commit b16d65991e4d7debb00dcdf80955ca6f714d9767
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Mon Nov 4 15:00:15 2019 +0100

    SLING-8826 - add a test that demonstrates the problem
---
 .../debug/RequestProgressTrackerLogFilter.java     |   2 +
 .../debug/RequestProgressTrackerLogFilterTest.java | 100 +++++++++++++++++++++
 2 files changed, 102 insertions(+)

diff --git a/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java b/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
index e52b39b..75947ad 100644
--- a/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
+++ b/src/main/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilter.java
@@ -95,6 +95,8 @@ public class RequestProgressTrackerLogFilter implements Filter {
 
     private String[] extensions;
 
+    static final int NANOSEC_TO_MSEC = 1000000;
+
     @Override
     public void init(final FilterConfig filterConfig) throws ServletException {
         // nothing to do
diff --git a/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java b/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java
new file mode 100644
index 0000000..bd7b88a
--- /dev/null
+++ b/src/test/java/org/apache/sling/engine/impl/debug/RequestProgressTrackerLogFilterTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.sling.engine.impl.debug;
+
+import static org.junit.Assert.assertTrue;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import org.apache.sling.api.request.RequestProgressTracker;
+import org.apache.sling.engine.impl.request.SlingRequestProgressTracker;
+import org.junit.Test;
+
+/** Partial tests of RequestProgressTrackerLogFilter */
+public class RequestProgressTrackerLogFilterTest {
+
+    private void setupMinMaxDuration(RequestProgressTrackerLogFilter filter, final int min, final int max)
+            throws Exception {
+
+        class TestConfig implements RequestProgressTrackerLogFilter.Config {
+            @Override
+            public Class<? extends Annotation> annotationType() {
+                return null;
+            }
+
+            @Override
+            public String[] extensions() {
+                return null;
+            }
+
+            @Override
+            public int minDurationMs() {
+                return min;
+            }
+
+            @Override
+            public int maxDurationMs() {
+                return max;
+            }
+
+            @Override
+            public boolean compactLogFormat() {
+                return false;
+            }
+        };
+
+        final Method activate = filter.getClass().getDeclaredMethod("activate", RequestProgressTrackerLogFilter.Config.class);
+        activate.setAccessible(true);
+        activate.invoke(filter, new TestConfig());
+    }
+
+    @Test
+    public void verifySlingRequestProgressTrackerDurationIsNanos() throws Exception {
+        // Verify that SlingRequestProgressTracker duration is based on nano time
+        final long startMsec = System.currentTimeMillis();
+        final SlingRequestProgressTracker rpt = new SlingRequestProgressTracker();
+        Thread.sleep(10);
+        final long rptElapsed = rpt.getDuration();
+        final long elapsedMsec = System.currentTimeMillis() - startMsec;
+        assertTrue("Expecting non-zero duration", rptElapsed > 0);
+        final float ratio = rptElapsed / elapsedMsec;
+        final int minExpectedRatio = RequestProgressTrackerLogFilter.NANOSEC_TO_MSEC / 2;
+        assertTrue("Expecting min ratio of " + minExpectedRatio + ", got " + ratio, ratio > minExpectedRatio);
+    }
+
+    @Test
+    public void testConfigMsec() throws Exception {
+        final RequestProgressTrackerLogFilter filter = new RequestProgressTrackerLogFilter();
+        final Method allowDuration = filter.getClass().getDeclaredMethod("allowDuration", RequestProgressTracker.class);
+        allowDuration.setAccessible(true);
+
+        final SlingRequestProgressTracker rpt = new SlingRequestProgressTracker();
+        final int delta = 2;
+        Thread.sleep(delta * 2);
+        rpt.done();
+        final long durationNanos = rpt.getDuration();
+        final long durationMsec = durationNanos; // TODO SLING-8826: should be duration / 1000;
+        final int minMsec = (int)(durationMsec - delta);
+        final int maxMsec = (int)(durationMsec + delta);
+        setupMinMaxDuration(filter, minMsec, maxMsec);
+        assertTrue("Expecting duration " + durationNanos + " to allowed for min=" + minMsec + " max=" + maxMsec,
+            (boolean)allowDuration.invoke(filter, rpt));
+    }
+}