Skip to content

Commit ea02978

Browse files
committed
feat: Add getter for DynamoCacheWriter and DynamoSerializer
1 parent 4819789 commit ea02978

File tree

2 files changed

+46
-3
lines changed

2 files changed

+46
-3
lines changed

src/main/java/com/dasburo/spring/cache/dynamo/DynamoCache.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import com.dasburo.spring.cache.dynamo.rootattribute.RootAttribute;
1919
import com.dasburo.spring.cache.dynamo.rootattribute.RootAttributeConfig;
2020
import com.dasburo.spring.cache.dynamo.rootattribute.RootAttributeReader;
21+
import com.dasburo.spring.cache.dynamo.serializer.DynamoSerializer;
2122
import org.slf4j.Logger;
2223
import org.slf4j.LoggerFactory;
2324
import org.springframework.cache.Cache;
@@ -166,6 +167,24 @@ public final List<RootAttributeConfig> getRootAttributes() {
166167
return cacheConfig.getRootAttributes();
167168
}
168169

170+
/**
171+
* Returns the implementation of {@link DynamoCacheWriter} used for caching
172+
*
173+
* @return the DynamoCacheWriter implementation.
174+
*/
175+
public final DynamoCacheWriter getWriter() {
176+
return writer;
177+
}
178+
179+
/**
180+
* Returns the implementation of {@link DynamoSerializer} used to serialize the value to be cached
181+
*
182+
* @return the DynamoSerializer implementation.
183+
*/
184+
public final DynamoSerializer getSerializer() {
185+
return cacheConfig.getSerializer();
186+
}
187+
169188
@Override
170189
public void put(Object key, Object value) {
171190
Assert.isTrue(key instanceof String, "'key' must be an instance of 'java.lang.String'.");
@@ -210,8 +229,8 @@ private byte[] serialize(Object value) {
210229

211230
private List<RootAttribute> readRootAttributes(List<RootAttributeConfig> rootAttributeConfigs, Object value) {
212231
return rootAttributeConfigs.stream()
213-
.map(rootAttributeConfig -> rootAttributeReader.readRootAttribute(rootAttributeConfig, value))
214-
.filter(Objects::nonNull)
215-
.collect(Collectors.toList());
232+
.map(rootAttributeConfig -> rootAttributeReader.readRootAttribute(rootAttributeConfig, value))
233+
.filter(Objects::nonNull)
234+
.collect(Collectors.toList());
216235
}
217236
}

src/test/java/com/dasburo/spring/cache/dynamo/DynamoCacheTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
import com.amazonaws.services.dynamodbv2.model.GetItemResult;
2020
import com.dasburo.spring.cache.dynamo.helper.Address;
2121
import com.dasburo.spring.cache.dynamo.rootattribute.RootAttributeConfig;
22+
import com.dasburo.spring.cache.dynamo.serializer.DynamoSerializer;
2223
import com.dasburo.spring.cache.dynamo.serializer.Jackson2JsonSerializer;
24+
import com.dasburo.spring.cache.dynamo.serializer.StringSerializer;
2325
import org.junit.Assert;
2426
import org.junit.Before;
2527
import org.junit.ClassRule;
@@ -63,13 +65,17 @@ public class DynamoCacheTest {
6365

6466
private DynamoCache cache;
6567

68+
private DynamoSerializer serializer;
69+
6670
@Before
6771
public void setup() {
6872
writer = spy(writer);
73+
serializer = new StringSerializer();
6974

7075
DynamoCacheConfiguration config = DynamoCacheConfiguration.defaultCacheConfig();
7176
config.setTtl(TTL);
7277
config.setFlushOnBoot(true);
78+
config.setSerializer(serializer);
7379

7480
cache = new DynamoCache(CACHE_NAME, writer, config);
7581
reset(writer);
@@ -126,6 +132,24 @@ public void getTtl() {
126132
Assert.assertEquals(TTL, ttl);
127133
}
128134

135+
/**
136+
* Test for {@link DynamoCache#getWriter()}.
137+
*/
138+
@Test
139+
public void getCacheWriter() {
140+
final Object cacheWriter = cache.getWriter();
141+
Assert.assertEquals(writer, cacheWriter);
142+
}
143+
144+
/**
145+
* Test for {@link DynamoCache#getSerializer()}.
146+
*/
147+
@Test
148+
public void getSerializer() {
149+
final DynamoSerializer serializer = cache.getSerializer();
150+
Assert.assertEquals(this.serializer, serializer);
151+
}
152+
129153
/**
130154
* Test for {@link DynamoCache#get(Object)}.
131155
*/

0 commit comments

Comments
 (0)