You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/07/26 20:18:43 UTC

svn commit: r1803106 - /jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java

Author: pmouawad
Date: Wed Jul 26 20:18:42 2017
New Revision: 1803106

URL: http://svn.apache.org/viewvc?rev=1803106&view=rev
Log:
Improve logs
Bugzilla Id: 61176

Modified:
    jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java

Modified: jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java?rev=1803106&r1=1803105&r2=1803106&view=diff
==============================================================================
--- jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java (original)
+++ jmeter/trunk/src/protocol/http/org/apache/jmeter/protocol/http/control/CacheManager.java Wed Jul 26 20:18:42 2017
@@ -142,11 +142,6 @@ public class CacheManager extends Config
             return etag;
         }
 
-        @Override
-        public String toString() {
-            return lastModified + " " + etag + " " + varyHeader;
-        }
-
         public Date getExpires() {
             return expires;
         }
@@ -154,6 +149,15 @@ public class CacheManager extends Config
         public String getVaryHeader() {
             return varyHeader;
         }
+
+        /* (non-Javadoc)
+         * @see java.lang.Object#toString()
+         */
+        @Override
+        public String toString() {
+            return "CacheEntry [lastModified=" + lastModified + ", etag=" + etag + ", expires=" + expires
+                    + ", varyHeader=" + varyHeader + "]";
+        }
     }
 
     /**
@@ -254,7 +258,12 @@ public class CacheManager extends Config
             getCache().put(url, new CacheEntry(lastModified, expiresDate, etag, varyHeader.getLeft()));
             getCache().put(varyUrl(url, varyHeader.getLeft(), varyHeader.getRight()), new CacheEntry(lastModified, expiresDate, etag, null));
         } else {
-            getCache().put(url, new CacheEntry(lastModified, expiresDate, etag, null));
+            CacheEntry cacheEntry = new CacheEntry(lastModified, expiresDate, etag, null);
+            if (log.isDebugEnabled()) {
+                log.debug("Set entry {} into cache for url {}", url,
+                        cacheEntry);
+            }
+            getCache().put(url, cacheEntry);
         }
     }
 
@@ -367,7 +376,7 @@ public class CacheManager extends Config
     public void setHeaders(URL url, HttpRequestBase request) {
         CacheEntry entry = getEntry(url.toString(), request.getAllHeaders());
         if (log.isDebugEnabled()){
-            log.debug("{}(OAH) {} {}", request.getMethod(), url.toString(), entry);
+            log.debug("setHeaders for HTTP Method:{}(OAH) URL:{} Entry:{}", request.getMethod(), url.toString(), entry);
         }
         if (entry != null){
             final String lastModified = entry.getLastModified();
@@ -396,7 +405,7 @@ public class CacheManager extends Config
         CacheEntry entry = getEntry(url.toString(), 
                 headers != null ? asHeaders(headers) : new Header[0]);
         if (log.isDebugEnabled()){
-            log.debug("{}(Java) {} {}", conn.getRequestMethod(), url.toString(), entry);
+            log.debug("setHeaders HTTP Method{}(Java) url:{} entry:{}", conn.getRequestMethod(), url.toString(), entry);
         }
         if (entry != null){
             final String lastModified = entry.getLastModified();
@@ -424,15 +433,15 @@ public class CacheManager extends Config
      */
     @Deprecated
     public boolean inCache(URL url) {
-        return entryStillValid(getEntry(url.toString(), null));
+        return entryStillValid(url, getEntry(url.toString(), null));
     }
 
     public boolean inCache(URL url, Header[] allHeaders) {
-        return entryStillValid(getEntry(url.toString(), allHeaders));
+        return entryStillValid(url, getEntry(url.toString(), allHeaders));
     }
 
     public boolean inCache(URL url, org.apache.jmeter.protocol.http.control.Header[] allHeaders) {
-        return entryStillValid(getEntry(url.toString(), asHeaders(allHeaders)));
+        return entryStillValid(url, getEntry(url.toString(), asHeaders(allHeaders)));
     }
 
     private Header[] asHeaders(
@@ -480,17 +489,19 @@ public class CacheManager extends Config
 
     }
 
-    private boolean entryStillValid(CacheEntry entry) {
-        log.debug("Check if entry {} is still valid", entry);
+    private boolean entryStillValid(URL url, CacheEntry entry) {
+        log.debug("Check if entry {} is still valid for url {}", entry, url);
         if (entry != null && entry.getVaryHeader() == null) {
             final Date expiresDate = entry.getExpires();
             if (expiresDate != null) {
                 if (expiresDate.after(new Date())) {
-                    log.debug("Expires= {} (Valid)", expiresDate);
+                    log.debug("Expires= {} (Valid) for url {}", expiresDate, url);
                     return true;
                 } else {
-                    log.debug("Expires= {} (Expired)", expiresDate);
+                    log.debug("Expires= {} (Expired) for url {}", expiresDate, url);
                 }
+            } else {
+                log.debug("expiresDate is null for url {}", expiresDate, url);
             }
         }
         return false;
@@ -498,10 +509,7 @@ public class CacheManager extends Config
 
     private CacheEntry getEntry(String url, Header[] headers) {
         CacheEntry entry = getCache().get(url);
-        if (log.isDebugEnabled()) {
-            log.debug("Cache: {}", getCache());
-            log.debug("inCache {} {} {}", url, entry, headers);
-        }
+        log.debug("getEntry url:{} entry:{} header:{}", url, entry, headers);
         if (entry == null) {
             log.debug("No entry found for url {}", url);
             return null;
@@ -511,14 +519,14 @@ public class CacheManager extends Config
             return entry;
         }
         if (headers == null) {
-            if (log.isDebugEnabled()) {
+            if(log.isDebugEnabled()) {
                 log.debug("Entry {} found, but it should depend on vary {} for url {}", entry, entry.getVaryHeader(), url);
             }
             return null;
         }
         Pair<String, String> varyPair = getVaryHeader(entry.getVaryHeader(), headers);
         if (varyPair != null) {
-            if (log.isDebugEnabled()) {
+            if(log.isDebugEnabled()) {
                 log.debug("Looking again for {} because of {} with vary: {} ({})", url, entry, entry.getVaryHeader(), varyPair);
             }
             return getEntry(varyUrl(url, entry.getVaryHeader(), varyPair.getRight()), null);