hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject [2/4] httpcomponents-client git commit: Bugfix: fixed incorrect behaviour of HttpCacheEntryMatcher, fixed incorrect mapping of cache entries returned by bulk retrieval methods
Date Fri, 22 Dec 2017 14:20:20 GMT
Bugfix: fixed incorrect behaviour of HttpCacheEntryMatcher, fixed incorrect mapping of cache
entries returned by bulk retrieval methods


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/commit/8d08c38d
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/tree/8d08c38d
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-client/diff/8d08c38d

Branch: refs/heads/master
Commit: 8d08c38d4f7f1baf76eb483a295de557ed1e9d45
Parents: 29666a1
Author: Oleg Kalnichevski <olegk@apache.org>
Authored: Thu Dec 21 14:44:37 2017 +0100
Committer: Oleg Kalnichevski <olegk@apache.org>
Committed: Thu Dec 21 14:49:25 2017 +0100

----------------------------------------------------------------------
 .../cache/AbstractSerializingAsyncCacheStorage.java  | 15 +++++++++------
 .../impl/cache/AbstractSerializingCacheStorage.java  | 13 ++++++++-----
 .../http/impl/cache/HttpCacheEntryMatcher.java       |  3 ++-
 .../TestAbstractSerializingAsyncCacheStorage.java    |  8 ++++----
 .../cache/TestAbstractSerializingCacheStorage.java   |  8 ++++----
 5 files changed, 27 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8d08c38d/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
index 69eb18c..60805dd 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingAsyncCacheStorage.java
@@ -244,14 +244,17 @@ public abstract class AbstractSerializingAsyncCacheStorage<T, CAS>
implements Ht
             return bulkRestore(storageKeys, new FutureCallback<Map<String, T>>()
{
 
                 @Override
-                public void completed(final Map<String, T> storageObjects) {
+                public void completed(final Map<String, T> storageObjectMap) {
                     try {
                         final Map<String, HttpCacheEntry> resultMap = new HashMap<>();
-                        for (final Map.Entry<String, T> storageEntry: storageObjects.entrySet())
{
-                            final String key = storageEntry.getKey();
-                            final HttpCacheStorageEntry entry = serializer.deserialize(storageEntry.getValue());
-                            if (key.equals(entry.getKey())) {
-                                resultMap.put(key, entry.getContent());
+                        for (final String key: keys) {
+                            final String storageKey = digestToStorageKey(key);
+                            final T storageObject = storageObjectMap.get(storageKey);
+                            if (storageObject != null) {
+                                final HttpCacheStorageEntry entry = serializer.deserialize(storageObject);
+                                if (key.equals(entry.getKey())) {
+                                    resultMap.put(key, entry.getContent());
+                                }
                             }
                         }
                         callback.completed(resultMap);

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8d08c38d/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java
b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java
index 4a5ae98..c0b683a 100644
--- a/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java
+++ b/httpclient5-cache/src/main/java/org/apache/hc/client5/http/impl/cache/AbstractSerializingCacheStorage.java
@@ -141,11 +141,14 @@ public abstract class AbstractSerializingCacheStorage<T, CAS>
implements HttpCac
         }
         final Map<String, T> storageObjectMap = bulkRestore(storageKeys);
         final Map<String, HttpCacheEntry> resultMap = new HashMap<>();
-        for (final Map.Entry<String, T> storageEntry: storageObjectMap.entrySet())
{
-            final String key = storageEntry.getKey();
-            final HttpCacheStorageEntry entry = serializer.deserialize(storageEntry.getValue());
-            if (key.equals(entry.getKey())) {
-                resultMap.put(key, entry.getContent());
+        for (final String key: keys) {
+            final String storageKey = digestToStorageKey(key);
+            final T storageObject = storageObjectMap.get(storageKey);
+            if (storageObject != null) {
+                final HttpCacheStorageEntry entry = serializer.deserialize(storageObject);
+                if (key.equals(entry.getKey())) {
+                    resultMap.put(key, entry.getContent());
+                }
             }
         }
         return resultMap;

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8d08c38d/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
index 7721d89..c0db981 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/HttpCacheEntryMatcher.java
@@ -80,11 +80,12 @@ public class HttpCacheEntryMatcher extends BaseMatcher<HttpCacheEntry>
{
                 if (!Arrays.equals(expectedContent, otherContent)) {
                     return false;
                 }
+                return true;
             } catch (final ResourceIOException ex) {
                 throw new RuntimeException(ex);
             }
         }
-        return true;
+        return false;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8d08c38d/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
index 8e5455e..8c0097a 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingAsyncCacheStorage.java
@@ -498,8 +498,8 @@ public class TestAbstractSerializingAsyncCacheStorage {
         Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
         Assert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
 
-        verify(impl).digestToStorageKey(key1);
-        verify(impl).digestToStorageKey(key2);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key1);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key2);
         verify(impl).bulkRestore(
                 Mockito.eq(Arrays.asList(storageKey1, storageKey2)),
                 Mockito.<FutureCallback<Map<String, byte[]>>>any());
@@ -547,8 +547,8 @@ public class TestAbstractSerializingAsyncCacheStorage {
         Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
         Assert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
 
-        verify(impl).digestToStorageKey(key1);
-        verify(impl).digestToStorageKey(key2);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key1);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key2);
         verify(impl).bulkRestore(
                 Mockito.eq(Arrays.asList(storageKey1, storageKey2)),
                 Mockito.<FutureCallback<Map<String, byte[]>>>any());

http://git-wip-us.apache.org/repos/asf/httpcomponents-client/blob/8d08c38d/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
----------------------------------------------------------------------
diff --git a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
index 0537be7..a6bb2dc 100644
--- a/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
+++ b/httpclient5-cache/src/test/java/org/apache/hc/client5/http/impl/cache/TestAbstractSerializingCacheStorage.java
@@ -294,8 +294,8 @@ public class TestAbstractSerializingCacheStorage {
         Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
         Assert.assertThat(entryMap.get(key2), HttpCacheEntryMatcher.equivalent(value2));
 
-        verify(impl).digestToStorageKey(key1);
-        verify(impl).digestToStorageKey(key2);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key1);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key2);
         verify(impl).bulkRestore(Arrays.asList(storageKey1, storageKey2));
     }
 
@@ -332,8 +332,8 @@ public class TestAbstractSerializingCacheStorage {
         Assert.assertThat(entryMap.get(key1), HttpCacheEntryMatcher.equivalent(value1));
         Assert.assertThat(entryMap.get(key2), CoreMatchers.nullValue());
 
-        verify(impl).digestToStorageKey(key1);
-        verify(impl).digestToStorageKey(key2);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key1);
+        verify(impl, Mockito.times(2)).digestToStorageKey(key2);
         verify(impl).bulkRestore(Arrays.asList(storageKey1, storageKey2));
     }
 


Mime
View raw message