|
21 | 21 | */ |
22 | 22 | package com.influxdb.v3.client; |
23 | 23 |
|
| 24 | +import java.math.BigInteger; |
| 25 | +import java.time.Instant; |
24 | 26 | import java.util.Map; |
25 | 27 | import java.util.Properties; |
| 28 | +import java.util.UUID; |
| 29 | +import java.util.stream.Stream; |
26 | 30 |
|
27 | 31 | import org.assertj.core.api.Assertions; |
28 | 32 | import org.junit.jupiter.api.Test; |
| 33 | +import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; |
| 34 | + |
| 35 | +import com.influxdb.v3.client.write.WriteOptions; |
| 36 | +import com.influxdb.v3.client.write.WritePrecision; |
29 | 37 |
|
30 | 38 | class InfluxDBClientTest { |
31 | 39 |
|
@@ -116,4 +124,44 @@ public void unsupportedQueryParams() throws Exception { |
116 | 124 | + "class com.influxdb.v3.client.internal.InfluxDBClientImpl"); |
117 | 125 | } |
118 | 126 | } |
| 127 | + |
| 128 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
| 129 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
| 130 | + @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
| 131 | + @Test |
| 132 | + public void testQuery() throws Exception { |
| 133 | + try (InfluxDBClient client = InfluxDBClient.getInstance( |
| 134 | + System.getenv("TESTING_INFLUXDB_URL"), |
| 135 | + System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray(), |
| 136 | + System.getenv("TESTING_INFLUXDB_DATABASE"), |
| 137 | + null)) { |
| 138 | + String uuid = UUID.randomUUID().toString(); |
| 139 | + long timestamp = Instant.now().getEpochSecond(); |
| 140 | + String record = String.format( |
| 141 | + "host9,tag=empty name=\"intel\",mem_total=2048,disk_free=100,temperature=100.86,isActive=true,testId=\"%s\" %d", |
| 142 | + uuid, |
| 143 | + timestamp |
| 144 | + ); |
| 145 | + client.writeRecord(record, new WriteOptions(null, WritePrecision.S, null)); |
| 146 | + |
| 147 | + Map<String, Object> parameters = Map.of("testId", uuid); |
| 148 | + String sql = "Select * from host9 where \"testId\"=$testId"; |
| 149 | + try (Stream<Object[]> stream = client.query(sql, parameters)) { |
| 150 | + stream.findFirst() |
| 151 | + .ifPresent(objects -> { |
| 152 | + Assertions.assertThat(objects[0].getClass()).isEqualTo(Double.class); |
| 153 | + Assertions.assertThat(objects[0]).isEqualTo(100.0); |
| 154 | + |
| 155 | + Assertions.assertThat(objects[1].getClass()).isEqualTo(Boolean.class); |
| 156 | + Assertions.assertThat(objects[1]).isEqualTo(true); |
| 157 | + |
| 158 | + Assertions.assertThat(objects[3].getClass()).isEqualTo(String.class); |
| 159 | + Assertions.assertThat(objects[3]).isEqualTo("intel"); |
| 160 | + |
| 161 | + Assertions.assertThat(objects[7].getClass()).isEqualTo(BigInteger.class); |
| 162 | + Assertions.assertThat(objects[7]).isEqualTo(BigInteger.valueOf(timestamp * 1_000_000_000)); |
| 163 | + }); |
| 164 | + } |
| 165 | + } |
| 166 | + } |
119 | 167 | } |
0 commit comments