RedisSessionStore implements SessionStore { @Override public Map<String, String> getAndRefresh(String sessionId, String domain, Duration sessionTimeout) { String key = sessionKey(sessionId, domain); try { Map<String, String> sessionValues = redis.hash().getAll(key); if (sessionValues.isEmpty()) return null; redis.expire(key, sessionTimeout); return sessionValues; } catch (RedisException e) { logger.warn(errorCode("INVALID_SESSION_VALUE"), "failed to get redis session values", e); return null; } } RedisSessionStore(Redis redis); @Override Map<String, String> getAndRefresh(String sessionId, String domain, Duration sessionTimeout); @Override void save(String sessionId, String domain, Map<String, String> values, Set<String> changedFields, Duration sessionTimeout); @Override void invalidate(String sessionId, String domain); @Override void invalidateByKey(String key, String value);  }
@Test void getAndRefreshWithRedisDown() { when(redis.hash()).thenReturn(redisHash); when(redisHash.getAll(anyString())).thenThrow(new UncheckedIOException(new IOException("unexpected end of stream"))); assertThatThrownBy(() -> store.getAndRefresh("sessionId", "localhost", Duration.ofMinutes(30))) .isInstanceOf(UncheckedIOException.class); }
@Test void getAndRefreshWithInvalidRedisData() { when(redis.hash()).thenReturn(redisHash); when(redisHash.getAll(anyString())).thenThrow(new RedisException("WRONGTYPE Operation against a key holding the wrong kind of value")); assertThat(store.getAndRefresh("sessionId", "localhost", Duration.ofMinutes(30))).isNull(); }