You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by br...@apache.org on 2021/09/17 13:52:18 UTC

[cassandra] branch cassandra-3.11 updated: Add test to ensure Caffeine cache does not return stale entries

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

brandonwilliams pushed a commit to branch cassandra-3.11
in repository https://gitbox.apache.org/repos/asf/cassandra.git


The following commit(s) were added to refs/heads/cassandra-3.11 by this push:
     new b3af67f  Add test to ensure Caffeine cache does not return stale entries
b3af67f is described below

commit b3af67f0ee950bed75593e0e6ce27547375f4096
Author: Aleksei Zotov <az...@gmail.com>
AuthorDate: Sat Sep 11 23:00:53 2021 +0400

    Add test to ensure Caffeine cache does not return stale entries
    
    Patch by Aleksei Zotov; reviewed by brandonwilliams and mck for
    CASSANDRA-15153
---
 .../org/apache/cassandra/auth/AuthCacheTest.java   | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/test/unit/org/apache/cassandra/auth/AuthCacheTest.java b/test/unit/org/apache/cassandra/auth/AuthCacheTest.java
index 0030603..c99438f7 100644
--- a/test/unit/org/apache/cassandra/auth/AuthCacheTest.java
+++ b/test/unit/org/apache/cassandra/auth/AuthCacheTest.java
@@ -27,6 +27,7 @@ import org.apache.cassandra.db.ConsistencyLevel;
 import org.apache.cassandra.exceptions.UnavailableException;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 public class AuthCacheTest
 {
@@ -131,6 +132,29 @@ public class AuthCacheTest
         cache.get("expect-exception");
     }
 
+    @Test
+    public void testCassandraExceptionPassThroughWhenCacheRefreshed() throws InterruptedException
+    {
+        setValidity(50);
+        TestCache<String, Integer> cache = new TestCache<>(this::countingLoaderWithException, this::setValidity, () -> validity, () -> isCacheEnabled);
+        cache.get("10");
+
+        // wait until the cached record expires
+        Thread.sleep(60);
+
+        for (int i = 1; i <= 5; i++)
+        {
+            try
+            {
+                cache.get("10");
+                fail("Did not get expected Exception on attempt " + i);
+            }
+            catch (UnavailableException expected)
+            {
+            }
+        }
+    }
+
     private void setValidity(int validity)
     {
         this.validity = validity;
@@ -142,6 +166,16 @@ public class AuthCacheTest
         return Integer.parseInt(s);
     }
 
+    private Integer countingLoaderWithException(String s)
+    {
+        Integer loadedValue = countingLoader(s);
+
+        if (loadCounter > 1)
+            throw new UnavailableException(ConsistencyLevel.QUORUM, 3, 1);
+
+        return loadedValue;
+    }
+
     private static class TestCache<K, V> extends AuthCache<K, V>
     {
         private static int nameCounter = 0; // Allow us to create many instances of cache with same name prefix

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org