refactor: remove jt808 mileage state-store switch
This commit is contained in:
@@ -163,7 +163,6 @@ services:
|
|||||||
VEHICLE_STAT_ENABLED: ${VEHICLE_STAT_ENABLED:-true}
|
VEHICLE_STAT_ENABLED: ${VEHICLE_STAT_ENABLED:-true}
|
||||||
VEHICLE_STAT_ZONE_ID: ${VEHICLE_STAT_ZONE_ID:-Asia/Shanghai}
|
VEHICLE_STAT_ZONE_ID: ${VEHICLE_STAT_ZONE_ID:-Asia/Shanghai}
|
||||||
VEHICLE_STAT_JT808_MILEAGE_ENABLED: ${VEHICLE_STAT_JT808_MILEAGE_ENABLED:-true}
|
VEHICLE_STAT_JT808_MILEAGE_ENABLED: ${VEHICLE_STAT_JT808_MILEAGE_ENABLED:-true}
|
||||||
VEHICLE_STAT_JT808_STATE_STORE: ${VEHICLE_STAT_JT808_STATE_STORE:-redis}
|
|
||||||
VEHICLE_STAT_JT808_STATE_TTL_DAYS: ${VEHICLE_STAT_JT808_STATE_TTL_DAYS:-3}
|
VEHICLE_STAT_JT808_STATE_TTL_DAYS: ${VEHICLE_STAT_JT808_STATE_TTL_DAYS:-3}
|
||||||
MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}
|
MYSQL_JDBC_URL: ${MYSQL_JDBC_URL:-}
|
||||||
MYSQL_USERNAME: ${MYSQL_USERNAME:-}
|
MYSQL_USERNAME: ${MYSQL_USERNAME:-}
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ Set these in Portainer or Nacos, without committing secrets:
|
|||||||
```text
|
```text
|
||||||
KAFKA_TOPIC_JT808_EVENT=vehicle.event.jt808.v1
|
KAFKA_TOPIC_JT808_EVENT=vehicle.event.jt808.v1
|
||||||
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
|
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
|
||||||
VEHICLE_STAT_JT808_STATE_STORE=redis
|
|
||||||
MYSQL_JDBC_URL=<jdbc-url>
|
MYSQL_JDBC_URL=<jdbc-url>
|
||||||
MYSQL_USERNAME=<user>
|
MYSQL_USERNAME=<user>
|
||||||
MYSQL_PASSWORD=<password>
|
MYSQL_PASSWORD=<password>
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ KAFKA_TOPIC_JT808_EVENT=vehicle.event.jt808.v1
|
|||||||
VEHICLE_STAT_ENABLED=true
|
VEHICLE_STAT_ENABLED=true
|
||||||
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
|
VEHICLE_STAT_JT808_MILEAGE_ENABLED=true
|
||||||
VEHICLE_STAT_REPOSITORY_TYPE=jdbc
|
VEHICLE_STAT_REPOSITORY_TYPE=jdbc
|
||||||
VEHICLE_STAT_JT808_STATE_STORE=redis
|
|
||||||
MYSQL_JDBC_URL=<jdbc-url>
|
MYSQL_JDBC_URL=<jdbc-url>
|
||||||
MYSQL_USERNAME=<user>
|
MYSQL_USERNAME=<user>
|
||||||
MYSQL_PASSWORD=<password>
|
MYSQL_PASSWORD=<password>
|
||||||
|
|||||||
@@ -81,7 +81,6 @@ lingniu:
|
|||||||
zone-id: ${VEHICLE_STAT_ZONE_ID:Asia/Shanghai}
|
zone-id: ${VEHICLE_STAT_ZONE_ID:Asia/Shanghai}
|
||||||
jt808:
|
jt808:
|
||||||
enabled: ${VEHICLE_STAT_JT808_MILEAGE_ENABLED:true}
|
enabled: ${VEHICLE_STAT_JT808_MILEAGE_ENABLED:true}
|
||||||
state-store: ${VEHICLE_STAT_JT808_STATE_STORE:redis}
|
|
||||||
redis-key-prefix: ${VEHICLE_STAT_JT808_REDIS_KEY_PREFIX:vehicle:mileage:jt808:daily:}
|
redis-key-prefix: ${VEHICLE_STAT_JT808_REDIS_KEY_PREFIX:vehicle:mileage:jt808:daily:}
|
||||||
state-ttl-days: ${VEHICLE_STAT_JT808_STATE_TTL_DAYS:3}
|
state-ttl-days: ${VEHICLE_STAT_JT808_STATE_TTL_DAYS:3}
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,6 @@ class VehicleAnalyticsAppCompositionTest {
|
|||||||
"lingniu.ingest.vehicle-state.enabled=false",
|
"lingniu.ingest.vehicle-state.enabled=false",
|
||||||
"lingniu.ingest.vehicle-stat.enabled=true",
|
"lingniu.ingest.vehicle-stat.enabled=true",
|
||||||
"lingniu.ingest.vehicle-stat.jt808.enabled=true",
|
"lingniu.ingest.vehicle-stat.jt808.enabled=true",
|
||||||
"lingniu.ingest.vehicle-stat.jt808.state-store=redis",
|
|
||||||
"lingniu.ingest.event-file-store.enabled=false",
|
"lingniu.ingest.event-file-store.enabled=false",
|
||||||
"lingniu.ingest.event-history.enabled=false",
|
"lingniu.ingest.event-history.enabled=false",
|
||||||
"lingniu.ingest.gb32960.enabled=false")
|
"lingniu.ingest.gb32960.enabled=false")
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public class VehicleStatAutoConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnBean({StringRedisTemplate.class, ObjectMapper.class})
|
@ConditionalOnBean({StringRedisTemplate.class, ObjectMapper.class})
|
||||||
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat.jt808", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat.jt808", name = "enabled", havingValue = "true")
|
||||||
@ConditionalOnProperty(prefix = "lingniu.ingest.vehicle-stat.jt808", name = "state-store", havingValue = "redis")
|
|
||||||
@ConditionalOnMissingBean(Jt808MileageStateStore.class)
|
@ConditionalOnMissingBean(Jt808MileageStateStore.class)
|
||||||
public Jt808MileageStateStore redisJt808MileageStateStore(StringRedisTemplate redis,
|
public Jt808MileageStateStore redisJt808MileageStateStore(StringRedisTemplate redis,
|
||||||
ObjectMapper objectMapper,
|
ObjectMapper objectMapper,
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ public class VehicleStatProperties {
|
|||||||
|
|
||||||
public static class Jt808 {
|
public static class Jt808 {
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private String stateStore = "redis";
|
|
||||||
private String redisKeyPrefix = "vehicle:mileage:jt808:daily:";
|
private String redisKeyPrefix = "vehicle:mileage:jt808:daily:";
|
||||||
private long stateTtlDays = 3;
|
private long stateTtlDays = 3;
|
||||||
|
|
||||||
@@ -40,14 +39,6 @@ public class VehicleStatProperties {
|
|||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStateStore() {
|
|
||||||
return stateStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStateStore(String stateStore) {
|
|
||||||
this.stateStore = stateStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getRedisKeyPrefix() {
|
public String getRedisKeyPrefix() {
|
||||||
return redisKeyPrefix;
|
return redisKeyPrefix;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,8 +71,7 @@ class VehicleStatAutoConfigurationTest {
|
|||||||
.withBean(ObjectMapper.class, ObjectMapper::new)
|
.withBean(ObjectMapper.class, ObjectMapper::new)
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"lingniu.ingest.vehicle-stat.enabled=true",
|
"lingniu.ingest.vehicle-stat.enabled=true",
|
||||||
"lingniu.ingest.vehicle-stat.jt808.enabled=true",
|
"lingniu.ingest.vehicle-stat.jt808.enabled=true")
|
||||||
"lingniu.ingest.vehicle-stat.jt808.state-store=redis")
|
|
||||||
.run(context -> {
|
.run(context -> {
|
||||||
assertThat(context).hasSingleBean(Jt808MileageStateStore.class);
|
assertThat(context).hasSingleBean(Jt808MileageStateStore.class);
|
||||||
assertThat(context).hasSingleBean(RedisJt808MileageStateStore.class);
|
assertThat(context).hasSingleBean(RedisJt808MileageStateStore.class);
|
||||||
@@ -82,6 +81,24 @@ class VehicleStatAutoConfigurationTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void ignoresLegacyStateStorePropertyAndUsesRedisWhenAvailable() {
|
||||||
|
contextRunner
|
||||||
|
.withBean(JdbcTemplate.class, () -> mock(JdbcTemplate.class))
|
||||||
|
.withBean(StringRedisTemplate.class, () -> mock(StringRedisTemplate.class))
|
||||||
|
.withBean(ObjectMapper.class, ObjectMapper::new)
|
||||||
|
.withPropertyValues(
|
||||||
|
"lingniu.ingest.vehicle-stat.enabled=true",
|
||||||
|
"lingniu.ingest.vehicle-stat.jt808.enabled=true",
|
||||||
|
"lingniu.ingest.vehicle-stat.jt808.state-store=memory")
|
||||||
|
.run(context -> {
|
||||||
|
assertThat(context).hasSingleBean(Jt808MileageStateStore.class);
|
||||||
|
assertThat(context).hasSingleBean(RedisJt808MileageStateStore.class);
|
||||||
|
assertThat(context).hasSingleBean(Jt808MileageStreamProcessor.class);
|
||||||
|
assertThat(context).hasSingleBean(VehicleStatEnvelopeIngestor.class);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doesNotFallbackToMemoryJt808StateStoreWhenRedisIsDefaultButMissing() {
|
void doesNotFallbackToMemoryJt808StateStoreWhenRedisIsDefaultButMissing() {
|
||||||
contextRunner
|
contextRunner
|
||||||
@@ -97,7 +114,7 @@ class VehicleStatAutoConfigurationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void doesNotCreateJt808MileageBeansWhenMemoryStateStoreIsSelected() {
|
void doesNotCreateJt808MileageBeansWhenRedisIsMissingEvenWithLegacyStateStoreProperty() {
|
||||||
contextRunner
|
contextRunner
|
||||||
.withBean(JdbcTemplate.class, () -> mock(JdbcTemplate.class))
|
.withBean(JdbcTemplate.class, () -> mock(JdbcTemplate.class))
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
@@ -127,8 +144,7 @@ class VehicleStatAutoConfigurationTest {
|
|||||||
.withBean(ObjectMapper.class, ObjectMapper::new)
|
.withBean(ObjectMapper.class, ObjectMapper::new)
|
||||||
.withPropertyValues(
|
.withPropertyValues(
|
||||||
"lingniu.ingest.vehicle-stat.enabled=true",
|
"lingniu.ingest.vehicle-stat.enabled=true",
|
||||||
"lingniu.ingest.vehicle-stat.jt808.enabled=true",
|
"lingniu.ingest.vehicle-stat.jt808.enabled=true")
|
||||||
"lingniu.ingest.vehicle-stat.jt808.state-store=redis")
|
|
||||||
.run(context -> {
|
.run(context -> {
|
||||||
assertThat(context).hasSingleBean(JdbcTemplate.class);
|
assertThat(context).hasSingleBean(JdbcTemplate.class);
|
||||||
assertThat(context).hasSingleBean(JdbcVehicleStatMetricRepository.class);
|
assertThat(context).hasSingleBean(JdbcVehicleStatMetricRepository.class);
|
||||||
|
|||||||
Reference in New Issue
Block a user