refactor: remove legacy session store enum
This commit is contained in:
@@ -3,23 +3,25 @@ package com.lingniu.ingest.session;
|
|||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
@ConfigurationProperties(prefix = "lingniu.ingest.session")
|
@ConfigurationProperties(prefix = "lingniu.ingest.session")
|
||||||
public class SessionProperties {
|
public class SessionProperties {
|
||||||
|
|
||||||
private Store store = Store.REDIS;
|
private String store = "redis";
|
||||||
|
|
||||||
private Duration ttl = Duration.ofMinutes(30);
|
private Duration ttl = Duration.ofMinutes(30);
|
||||||
|
|
||||||
public Store getStore() {
|
public String getStore() {
|
||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStore(Store store) {
|
public void setStore(String store) {
|
||||||
if (store == Store.MEMORY) {
|
String value = store == null || store.isBlank() ? "redis" : store.trim().toLowerCase(Locale.ROOT);
|
||||||
throw new IllegalStateException("session.store supports only redis; configured value: memory");
|
if (!"redis".equals(value)) {
|
||||||
|
throw new IllegalStateException("session.store supports only redis; configured value: " + store);
|
||||||
}
|
}
|
||||||
this.store = store;
|
this.store = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Duration getTtl() {
|
public Duration getTtl() {
|
||||||
@@ -30,8 +32,4 @@ public class SessionProperties {
|
|||||||
this.ttl = ttl;
|
this.ttl = ttl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Store {
|
|
||||||
MEMORY,
|
|
||||||
REDIS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,4 +61,10 @@ class SessionCoreAutoConfigurationTest {
|
|||||||
.hasStackTraceContaining("session.store supports only redis")
|
.hasStackTraceContaining("session.store supports only redis")
|
||||||
.hasStackTraceContaining("memory"));
|
.hasStackTraceContaining("memory"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void sessionPropertiesDoNotExposeLegacyStoreEnum() {
|
||||||
|
assertThatThrownBy(() -> Class.forName("com.lingniu.ingest.session.SessionProperties$Store"))
|
||||||
|
.isInstanceOf(ClassNotFoundException.class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user