ahanikel commented on code in PR #1155:
URL: https://github.com/apache/jackrabbit-oak/pull/1155#discussion_r1384690587


##########
oak-blob-plugins/src/test/java/org/apache/jackrabbit/oak/plugins/blob/CachingDataStoreTest.java:
##########
@@ -638,4 +643,35 @@ private void waitFinish() {
             e.printStackTrace();
         }
     }
+
+    @Test
+    public void testRecordCacheInGetRecordIfStored() throws Exception {
+        // we have to initialise the datastore with the recordCache enabled
+        tear();
+
+        final File f = copyToFile(randomStream(0, 4 * 1024), folder.newFile());
+        final String id = getIdForInputStream(f);
+        final DataIdentifier di = new DataIdentifier(id);
+
+        init(1, 64 * 1024 * 1024, 10, 10000L);
+        // we write directly to the backend because that's the situation we 
have in a shared remote datastore:
+        // the file was already written by a different datastore but isn't 
present in the datastore.cache.
+        backend.write(di, f);
+
+        assertTrue("The datastore was initialised with a recordCacheSize of 
10000 but the recordCache is not present",
+                dataStore.recordCache.isPresent());
+        assertNull("Record with id " + id + " should not be in the recordCache 
yet",
+                dataStore.recordCache.get().getIfPresent(id));
+        assertNotNull("The record could not be loaded from the backend",
+                dataStore.getRecordIfStored(di));
+        assertNotNull("Record with id " + id + " should be in the recordCache 
now",
+                dataStore.recordCache.get().getIfPresent(id));
+        // make sure the record is loaded from the record cache
+        backend.deleteRecord(di);
+        dataStore.cache.invalidate(id);
+        assertNull("Record with id " + id + " should not be in the backend 
anymore",
+                backend.getRecord(di));
+        assertNotNull("The record could not be loaded from the cache",

Review Comment:
   Ah, you want to make sure that the record is no longer in the cache after 
deletion, right? I'll add a check for that in the next commit. The check above 
is to ensure that the record is loaded from the cache without using the backend 
when accessed a second time. That's why I'm deleting it from the backend, that 
way I can be sure it comes from the cache.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to