Browse Source

Improve RedisTbTransactionalCacheTest

pull/11207/head
Andrii Landiak 2 years ago
parent
commit
fca1eef2c1
  1. 25
      dao/src/test/java/org/thingsboard/server/dao/cache/RedisTbTransactionalCacheTest.java

25
dao/src/test/java/org/thingsboard/server/dao/cache/RedisTbTransactionalCacheTest.java

@ -16,7 +16,6 @@
package org.thingsboard.server.dao.cache; package org.thingsboard.server.dao.cache;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.mock.mockito.MockBean;
@ -60,23 +59,17 @@ public class RedisTbTransactionalCacheTest {
@MockBean @MockBean
private RedisSslCredentials redisSslCredentials; private RedisSslCredentials redisSslCredentials;
@Test
@BeforeEach public void testNoOpWhenCacheDisabled() {
public void setup() {
when(connectionFactory.getConnection()).thenReturn(redisConnection); when(connectionFactory.getConnection()).thenReturn(redisConnection);
}
@Test relationRedisCache.put(createRelationCacheKey(), null);
public void testEvictNoOpWhenCacheDisabled() { relationRedisCache.putIfAbsent(createRelationCacheKey(), null);
relationRedisCache.evict(createRelationCacheKey());
relationRedisCache.evict(List.of(createRelationCacheKey())); relationRedisCache.evict(List.of(createRelationCacheKey()));
relationRedisCache.getAndPutInTransaction(createRelationCacheKey(), null, false);
verify(connectionFactory, never()).getConnection(); relationRedisCache.getAndPutInTransaction(createRelationCacheKey(), null, null, null, false);
verifyNoInteractions(redisConnection); relationRedisCache.getOrFetchFromDB(createRelationCacheKey(), null, false, false);
}
@Test
public void testEvictOrPutNoOpWhenCacheDisabled() {
relationRedisCache.evictOrPut(createRelationCacheKey(), null);
verify(connectionFactory, never()).getConnection(); verify(connectionFactory, never()).getConnection();
verifyNoInteractions(redisConnection); verifyNoInteractions(redisConnection);
@ -86,4 +79,4 @@ public class RedisTbTransactionalCacheTest {
return new RelationCacheKey(new DeviceId(UUID.randomUUID()), new DeviceId(UUID.randomUUID()), null, RelationTypeGroup.COMMON); return new RelationCacheKey(new DeviceId(UUID.randomUUID()), new DeviceId(UUID.randomUUID()), null, RelationTypeGroup.COMMON);
} }
} }

Loading…
Cancel
Save