package com.iailab; import com.iailab.module.model.influxdb.pojo.InfluxPointValuePOJO; import com.iailab.module.model.influxdb.pojo.InfluxPointValueSimPOJO; import com.iailab.module.model.influxdb.service.InfluxDBService; import org.junit.Test; import org.junit.runner.RunWith; import javax.annotation.Resource; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.List; /** * @author PanZhibao * @Description * @createTime 2023年12月10日 12:19:00 */ @SpringBootTest @RunWith(SpringRunner.class) public class InfluxDBTest { @Resource private InfluxDBService influxDBService; @Test public void testWrite() { try { List pointValues = new ArrayList<>(); InfluxPointValuePOJO pojo = new InfluxPointValueSimPOJO(); pojo.setPoint("88880102030001"); pojo.setType("float"); pojo.setTimestamp(new Date().toInstant()); ((InfluxPointValueSimPOJO) pojo).setValue(123d); pointValues.add(pojo); InfluxPointValuePOJO pojo1 = new InfluxPointValueSimPOJO(); pojo1.setPoint("88880102030001"); pojo1.setType("float"); pojo1.setTimestamp(new Date().toInstant()); ((InfluxPointValueSimPOJO) pojo1).setValue(456d); pointValues.add(pojo1); influxDBService.asyncWritePointValues(pointValues); } catch (Exception ex) { ex.printStackTrace(); } } @Test public void testQueryPointMaxValue() { InfluxPointValuePOJO point = new InfluxPointValuePOJO(); point.setType("float"); point.setPoint("88880102030001"); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.HOUR_OF_DAY, -1); Object value = influxDBService.queryPointMaxValue(point, calendar.getTime()); System.out.println("value=" + value); } }