Compare commits
2 Commits
163f313066
...
87830fee09
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
87830fee09 | ||
|
|
53a9b3b3b7 |
@@ -35,7 +35,6 @@ The local-day minimum and maximum GPS total mileage values stay on that same met
|
||||
KAFKA_TOPIC_JT808_EVENT=vehicle.event.jt808.v1
|
||||
VEHICLE_STAT_ENABLED=true
|
||||
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
|
||||
VEHICLE_STAT_REPOSITORY_TYPE=jdbc
|
||||
MYSQL_JDBC_URL=<jdbc-url>
|
||||
MYSQL_USERNAME=<user>
|
||||
MYSQL_PASSWORD=<password>
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.time.Duration;
|
||||
@ConfigurationProperties(prefix = "lingniu.ingest.session")
|
||||
public class SessionProperties {
|
||||
|
||||
private Store store = Store.MEMORY;
|
||||
private Store store = Store.REDIS;
|
||||
|
||||
private Duration ttl = Duration.ofMinutes(30);
|
||||
|
||||
@@ -16,6 +16,9 @@ public class SessionProperties {
|
||||
}
|
||||
|
||||
public void setStore(Store store) {
|
||||
if (store == Store.MEMORY) {
|
||||
throw new IllegalStateException("session.store supports only redis; configured value: memory");
|
||||
}
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,15 +17,10 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@EnableConfigurationProperties(SessionProperties.class)
|
||||
public class SessionCoreAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "memory")
|
||||
public Object rejectedLegacyMemorySessionStore() {
|
||||
throw new IllegalStateException("session.store=memory has been removed; configure session.store=redis");
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(StringRedisTemplate.class)
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "redis")
|
||||
@ConditionalOnProperty(prefix = "lingniu.ingest.session", name = "store", havingValue = "redis",
|
||||
matchIfMissing = true)
|
||||
@ConditionalOnMissingBean
|
||||
public SessionStore redisSessionStore(StringRedisTemplate redis, SessionProperties properties) {
|
||||
// Redis 只保存会话元数据索引;真实 Netty Channel 仍在各协议进程本地内存中。
|
||||
|
||||
@@ -43,12 +43,22 @@ class SessionCoreAutoConfigurationTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsLegacyMemorySessionStoreMode() {
|
||||
void usesRedisSessionStoreByDefaultWhenRedisTemplateExists() {
|
||||
contextRunner
|
||||
.withBean(StringRedisTemplate.class, () -> mock(StringRedisTemplate.class))
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(SessionStore.class);
|
||||
assertThat(context).hasSingleBean(RedisSessionStore.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsMemorySessionStoreModeWithRedisOnlyRule() {
|
||||
contextRunner
|
||||
.withPropertyValues("lingniu.ingest.session.store=memory")
|
||||
.run(context -> assertThat(context.getStartupFailure())
|
||||
.hasRootCauseInstanceOf(IllegalStateException.class)
|
||||
.hasMessageContaining("session.store=memory has been removed")
|
||||
.hasMessageContaining("session.store=redis"));
|
||||
.hasStackTraceContaining("session.store supports only redis")
|
||||
.hasStackTraceContaining("memory"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class VehicleStatRepositoryContractTest {
|
||||
.contains("daily_mileage_km = max_total_mileage_km - min_total_mileage_km")
|
||||
.contains("Do not create or write a protocol-specific JT808 daily-mileage table.")
|
||||
.doesNotContain("Redis `Jt808MileageStateStore`")
|
||||
.doesNotContain("VEHICLE_STAT_REPOSITORY_TYPE")
|
||||
.doesNotContain("REDIS_HOST")
|
||||
.doesNotContain("GPS segment distance")
|
||||
.doesNotContain("speed integral");
|
||||
|
||||
Reference in New Issue
Block a user