test: 测试Caffeine缓存管理器的新增Caffeine缓存功能
parent
fcb6f81a12
commit
6cb6c8d1fd
|
@ -34,7 +34,7 @@ public class CaffeineManager {
|
||||||
* @return 缓存管理器实例
|
* @return 缓存管理器实例
|
||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
public CacheManager cacheManager() {
|
public SimpleCacheManager simpleCacheManager() {
|
||||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
||||||
List<String> cacheNames = CacheNameEnums.getCodes();
|
List<String> cacheNames = CacheNameEnums.getCodes();
|
||||||
cacheManager.setCaches(cacheNames.stream()
|
cacheManager.setCaches(cacheNames.stream()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.muyu.data.processing.controller;
|
package com.muyu.data.processing.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||||
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
import com.muyu.common.caffeine.enums.CacheNameEnums;
|
||||||
import com.muyu.common.core.utils.uuid.UUID;
|
import com.muyu.common.core.utils.uuid.UUID;
|
||||||
import com.muyu.common.iotdb.config.IotDBConfig;
|
import com.muyu.common.iotdb.config.IotDBConfig;
|
||||||
|
@ -12,10 +13,14 @@ import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||||
import org.springframework.cache.Cache;
|
import org.springframework.cache.Cache;
|
||||||
import org.springframework.cache.CacheManager;
|
import org.springframework.cache.CacheManager;
|
||||||
|
import org.springframework.cache.caffeine.CaffeineCache;
|
||||||
|
import org.springframework.cache.support.SimpleCacheManager;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试控制层
|
* 测试控制层
|
||||||
* @Author: 胡杨
|
* @Author: 胡杨
|
||||||
|
@ -40,7 +45,7 @@ public class TestController {
|
||||||
// private CaffeineCacheUtils cacheUtils;
|
// private CaffeineCacheUtils cacheUtils;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CacheManager cacheManager;
|
private SimpleCacheManager cacheManager;
|
||||||
|
|
||||||
@GetMapping("/testKafka")
|
@GetMapping("/testKafka")
|
||||||
public void sendMsg() {
|
public void sendMsg() {
|
||||||
|
@ -143,4 +148,19 @@ public class TestController {
|
||||||
log.info("无缓存");
|
log.info("无缓存");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/testAddCache")
|
||||||
|
public void testAddCache(@RequestParam("vin") String vin) {
|
||||||
|
ArrayList<CaffeineCache> caches = new ArrayList<>();
|
||||||
|
caches.add(new CaffeineCache(vin, Caffeine.newBuilder().recordStats().build()));
|
||||||
|
cacheManager.setCaches(caches);
|
||||||
|
log.info("缓存管理器创建新分区: {}", vin);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/testGetCacheNames")
|
||||||
|
public void testGetCacheNames() {
|
||||||
|
cacheManager.initializeCaches();
|
||||||
|
log.info("缓存分区列表: {}", cacheManager.getCacheNames());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ import lombok.*;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CarData {
|
public class CarData {
|
||||||
private String vin;
|
private String vin;
|
||||||
private String timestamp;
|
private long timestamp;
|
||||||
private String latitude;
|
private String latitude;
|
||||||
private String longitude;
|
private String longitude;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,14 @@ import com.muyu.data.processing.domain.BasicData;
|
||||||
import com.muyu.data.processing.strategy.core.StartStrategy;
|
import com.muyu.data.processing.strategy.core.StartStrategy;
|
||||||
import org.apache.iotdb.isession.SessionDataSet;import org.apache.iotdb.rpc.IoTDBConnectionException;
|
import org.apache.iotdb.isession.SessionDataSet;import org.apache.iotdb.rpc.IoTDBConnectionException;
|
||||||
import org.apache.iotdb.rpc.StatementExecutionException;
|
import org.apache.iotdb.rpc.StatementExecutionException;
|
||||||
|
import org.apache.iotdb.tsfile.read.common.Field;
|
||||||
|
import org.apache.iotdb.tsfile.read.common.RowRecord;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import com.muyu.data.processing.mapper.DataProcessingMapper;
|
import com.muyu.data.processing.mapper.DataProcessingMapper;
|
||||||
import com.muyu.data.processing.service.DataProcessingService;
|
import com.muyu.data.processing.service.DataProcessingService;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -67,17 +70,35 @@ public class DataProcessingServiceImpl implements DataProcessingService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CarData> selectCarData(String firmCode, String vin) {
|
public List<CarData> selectCarData(String firmCode, String vin) {
|
||||||
String tableName = "root.one."+firmCode+"."+vin;
|
ArrayList<CarData> carDataList = new ArrayList<>();
|
||||||
|
String sql = "select * from root.one."+firmCode+"."+vin;
|
||||||
try {
|
try {
|
||||||
SessionDataSet sessionDataSet = iotDBConfig.iotSession().executeQueryStatement(tableName);
|
SessionDataSet sessionDataSet = iotDBConfig.iotSession().executeQueryStatement(sql);
|
||||||
List<String> columnNames = sessionDataSet.getColumnNames();
|
List<String> columnNames = sessionDataSet.getColumnNames();
|
||||||
System.out.println(columnNames);
|
while (sessionDataSet.hasNext()){
|
||||||
} catch (StatementExecutionException e) {
|
RowRecord next = sessionDataSet.next();
|
||||||
throw new RuntimeException(e);
|
CarData data = getCarData(vin, next, columnNames);
|
||||||
} catch (IoTDBConnectionException e) {
|
carDataList.add(data);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
return null;
|
return carDataList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CarData getCarData(String vin, RowRecord next, List<String> columnNames) {
|
||||||
|
List<Field> fields = next.getFields();
|
||||||
|
CarData data = new CarData();
|
||||||
|
data.setVin(vin);
|
||||||
|
data.setTimestamp(next.getTimestamp());
|
||||||
|
for (int i = 0; i < columnNames.size(); i++) {
|
||||||
|
if (columnNames.get(i).contains("latitude")) {
|
||||||
|
data.setLatitude(fields.get(i-1).getStringValue());
|
||||||
|
}else if (columnNames.get(i).contains("longitude")) {
|
||||||
|
data.setLongitude(fields.get(i-1).getStringValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue