Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.tosan.client.redis.api.listener.CacheListener;
import com.tosan.client.redis.api.listener.CaffeineCacheListener;
import com.tosan.client.redis.enumuration.LocalCacheProvider;
import com.tosan.client.redis.exception.TedissonRuntimeException;
import com.tosan.client.redis.impl.localCacheManager.LocalCacheManagerBase;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -155,7 +156,11 @@ private CaffeineElement incrementAtomicItemProcess(CaffeineElement element) {
newCaffeineElement.setValue(1L);
return newCaffeineElement;
}
element.setValue((long) element.getValue() + 1);
Object value = element.getValue();
if (!(value instanceof Number)) {
throw new TedissonRuntimeException("Value must be numeric");
}
element.setValue(((Number) value).longValue() + 1);
return element;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Set;
import java.util.concurrent.TimeUnit;


class LocalCacheManagerITest extends BaseITest {

public static final String CACHE_WITH_SIZE = "CACHE_WITH_SIZE";
Expand All @@ -34,7 +33,6 @@ void testCreateCache() {
Assertions.assertTrue(localCacheManager.isCacheExist(TEST_WITH_EXPIRY_TTL_TTI));
}


@Test
void testClearCache() {
String cacheName = "testClearCache";
Expand Down Expand Up @@ -305,6 +303,36 @@ void testExpireAtomicItemExpiration() throws InterruptedException {
Assertions.assertEquals(1, localCacheManager.incrementAndGetAtomicItem(cacheName, "atomicKey"));
}

@Test
void testIncrementAtomicIntegerValueItem() {
String cacheName = "testIncrementAtomicIntegerValueItem";
String key = "atomicKey";
localCacheManager.createCache(cacheName);
Integer item = Integer.valueOf(1);
localCacheManager.addItemToCache(cacheName, key, item);
Assertions.assertEquals(2, localCacheManager.incrementAndGetAtomicItem(cacheName, key));
}

@Test
void testIncrementAtomicLongValueItem() {
String cacheName = "testIncrementAtomicLongValueItem";
String key = "atomicKey";
localCacheManager.createCache(cacheName);
Long item = Long.valueOf(1);
localCacheManager.addItemToCache(cacheName, key, item);
Assertions.assertEquals(2, localCacheManager.incrementAndGetAtomicItem(cacheName, key));
}

@Test
void testIncrementAtomicShortValueItem() {
String cacheName = "testIncrementAtomicShortValueItem";
String key = "atomicKey";
localCacheManager.createCache(cacheName);
Short item = Short.valueOf((short) 1);
localCacheManager.addItemToCache(cacheName, key, item);
Assertions.assertEquals(2, localCacheManager.incrementAndGetAtomicItem(cacheName, key));
}

@Test
void testUpdateAtomicItemExpiration() throws InterruptedException {
String cacheName = "testUpdateAtomicItemExpiration";
Expand Down