|
21 | 21 | */ |
22 | 22 | package com.influxdb.v3.client; |
23 | 23 |
|
24 | | -import java.math.BigInteger; |
25 | | -import java.time.Instant; |
26 | | -import java.util.ArrayList; |
27 | | -import java.util.List; |
28 | 24 | import java.util.Map; |
29 | 25 | import java.util.Properties; |
30 | | -import java.util.UUID; |
31 | | -import java.util.stream.Stream; |
32 | 26 |
|
33 | | -import org.apache.arrow.flight.FlightRuntimeException; |
34 | 27 | import org.assertj.core.api.Assertions; |
35 | 28 | import org.junit.jupiter.api.Test; |
36 | 29 |
|
@@ -72,14 +65,6 @@ void requiredHostConnectionString() { |
72 | 65 | .hasMessageContaining("no protocol"); |
73 | 66 | } |
74 | 67 |
|
75 | | - @Test |
76 | | - void requiredHostEnvOrProperties() { |
77 | | - |
78 | | - Assertions.assertThatThrownBy(InfluxDBClient::getInstance) |
79 | | - .isInstanceOf(IllegalArgumentException.class) |
80 | | - .hasMessage("The URL of the InfluxDB server has to be defined."); |
81 | | - } |
82 | | - |
83 | 68 | @Test |
84 | 69 | void fromParameters() throws Exception { |
85 | 70 |
|
@@ -143,164 +128,4 @@ public void unsupportedQueryParams() throws Exception { |
143 | 128 | + "class com.influxdb.v3.client.internal.InfluxDBClientImpl"); |
144 | 129 | } |
145 | 130 | } |
146 | | - |
147 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
148 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
149 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
150 | | - @Test |
151 | | - public void testQuery() throws Exception { |
152 | | - try (InfluxDBClient client = InfluxDBClient.getInstance( |
153 | | - System.getenv("TESTING_INFLUXDB_URL"), |
154 | | - System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray(), |
155 | | - System.getenv("TESTING_INFLUXDB_DATABASE"), |
156 | | - null)) { |
157 | | - String uuid = UUID.randomUUID().toString(); |
158 | | - long timestamp = Instant.now().getEpochSecond(); |
159 | | - String record = String.format( |
160 | | - "host12,tag=empty " |
161 | | - + "name=\"intel\"," |
162 | | - + "mem_total=2048," |
163 | | - + "disk_free=100i," |
164 | | - + "temperature=100.86," |
165 | | - + "isActive=true," |
166 | | - + "testId=\"%s\" %d", |
167 | | - uuid, |
168 | | - timestamp |
169 | | - ); |
170 | | - client.writeRecord(record, new WriteOptions(null, WritePrecision.S, null)); |
171 | | - |
172 | | - Map<String, Object> parameters = Map.of("testId", uuid); |
173 | | - String sql = "Select * from host12 where \"testId\"=$testId"; |
174 | | - try (Stream<Object[]> stream = client.query(sql, parameters)) { |
175 | | - stream.findFirst() |
176 | | - .ifPresent(objects -> { |
177 | | - Assertions.assertThat(objects[0].getClass()).isEqualTo(Long.class); |
178 | | - Assertions.assertThat(objects[0]).isEqualTo(100L); |
179 | | - |
180 | | - Assertions.assertThat(objects[1].getClass()).isEqualTo(Boolean.class); |
181 | | - Assertions.assertThat(objects[1]).isEqualTo(true); |
182 | | - |
183 | | - Assertions.assertThat(objects[2].getClass()).isEqualTo(Double.class); |
184 | | - Assertions.assertThat(objects[2]).isEqualTo(2048.0); |
185 | | - |
186 | | - Assertions.assertThat(objects[3].getClass()).isEqualTo(String.class); |
187 | | - Assertions.assertThat(objects[3]).isEqualTo("intel"); |
188 | | - |
189 | | - Assertions.assertThat(objects[4].getClass()).isEqualTo(String.class); |
190 | | - Assertions.assertThat(objects[4]).isEqualTo("empty"); |
191 | | - |
192 | | - Assertions.assertThat(objects[7].getClass()).isEqualTo(BigInteger.class); |
193 | | - Assertions.assertThat(objects[7]).isEqualTo(BigInteger.valueOf(timestamp * 1_000_000_000)); |
194 | | - }); |
195 | | - } |
196 | | - } |
197 | | - } |
198 | | - |
199 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
200 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
201 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
202 | | - @Test |
203 | | - public void testQueryRows() throws Exception { |
204 | | - try (InfluxDBClient client = InfluxDBClient.getInstance( |
205 | | - System.getenv("TESTING_INFLUXDB_URL"), |
206 | | - System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray(), |
207 | | - System.getenv("TESTING_INFLUXDB_DATABASE"), |
208 | | - null)) { |
209 | | - String uuid = UUID.randomUUID().toString(); |
210 | | - String measurement = "host21"; |
211 | | - List<Map<String, Object>> testDatas = new ArrayList<>(); |
212 | | - for (int i = 0; i <= 9; i++) { |
213 | | - long timestamp = System.currentTimeMillis(); |
214 | | - Map<String, Object> map = Map.of( |
215 | | - "measurement", measurement, |
216 | | - "tag", "tagValue", |
217 | | - "name", "intel", |
218 | | - "mem_total", 2048.0, |
219 | | - "disk_free", 100L, |
220 | | - "temperature", 100.86, |
221 | | - "isActive", true, |
222 | | - "time", timestamp, |
223 | | - "testId", uuid |
224 | | - ); |
225 | | - String record = String.format( |
226 | | - "%s,tag=tagValue " |
227 | | - + "name=\"%s\"," |
228 | | - + "mem_total=%f," |
229 | | - + "disk_free=%di," |
230 | | - + "temperature=%f," |
231 | | - + "isActive=%b," |
232 | | - + "testId=\"%s\" %d", |
233 | | - measurement, |
234 | | - map.get("name"), |
235 | | - (Double) map.get("mem_total"), |
236 | | - (Long) map.get("disk_free"), |
237 | | - (Double) map.get("temperature"), |
238 | | - map.get("isActive"), |
239 | | - uuid, |
240 | | - timestamp |
241 | | - ); |
242 | | - client.writeRecord(record, new WriteOptions(null, WritePrecision.MS, null)); |
243 | | - testDatas.add(map); |
244 | | - } |
245 | | - |
246 | | - Map<String, Object> parameters = Map.of("testId", uuid); |
247 | | - // Result set much be ordered by time |
248 | | - String sql = String.format("Select * from %s where \"testId\"=$testId order by time", measurement); |
249 | | - try (Stream<Map<String, Object>> stream = client.queryRows(sql, parameters)) { |
250 | | - List<Map<String, Object>> results = stream.collect(Collectors.toList()); |
251 | | - for (int i = 0; i <= 9; i++) { |
252 | | - Map<String, Object> row = results.get(i); |
253 | | - Map<String, Object> testData = testDatas.get(i); |
254 | | - Assertions.assertThat(row.get("tag").getClass()).isEqualTo(String.class); |
255 | | - Assertions.assertThat(row.get("tag")).isEqualTo(testData.get("tag")); |
256 | | - |
257 | | - Assertions.assertThat(row.get("name").getClass()).isEqualTo(String.class); |
258 | | - Assertions.assertThat(row.get("name")).isEqualTo(testData.get("name")); |
259 | | - |
260 | | - Assertions.assertThat(row.get("mem_total").getClass()).isEqualTo(Double.class); |
261 | | - Assertions.assertThat(row.get("mem_total")).isEqualTo(testData.get("mem_total")); |
262 | | - |
263 | | - Assertions.assertThat(row.get("disk_free").getClass()).isEqualTo(Long.class); |
264 | | - Assertions.assertThat(row.get("disk_free")).isEqualTo(testData.get("disk_free")); |
265 | | - |
266 | | - Assertions.assertThat(row.get("isActive").getClass()).isEqualTo(Boolean.class); |
267 | | - Assertions.assertThat(row.get("isActive")).isEqualTo(testData.get("isActive")); |
268 | | - |
269 | | - Assertions.assertThat(row.get("time").getClass()).isEqualTo(BigInteger.class); |
270 | | - Assertions.assertThat(row.get("time")) |
271 | | - .isEqualTo(BigInteger.valueOf((Long) testData.get("time") * 1_000_000)); |
272 | | - } |
273 | | - } |
274 | | - } |
275 | | - } |
276 | | - |
277 | | - |
278 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_URL", matches = ".*") |
279 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_TOKEN", matches = ".*") |
280 | | - @EnabledIfEnvironmentVariable(named = "TESTING_INFLUXDB_DATABASE", matches = ".*") |
281 | | - @Test |
282 | | - public void testQueryRowsExceptionCases() throws Exception { |
283 | | - try (InfluxDBClient client = InfluxDBClient.getInstance( |
284 | | - System.getenv("TESTING_INFLUXDB_URL"), |
285 | | - System.getenv("TESTING_INFLUXDB_TOKEN").toCharArray(), |
286 | | - System.getenv("TESTING_INFLUXDB_DATABASE"), |
287 | | - null)) { |
288 | | - |
289 | | - // Empty result case |
290 | | - Map<String, Object> parameters = Map.of("testId", "NotExist"); |
291 | | - String sql = "Select * from host21 where \"testId\"=$testId"; |
292 | | - try (Stream<Map<String, Object>> stream = client.queryRows(sql, parameters)) { |
293 | | - Assertions.assertThat((int) stream.count()).isEqualTo(0); |
294 | | - } |
295 | | - |
296 | | - // Malformed query case |
297 | | - Assertions.assertThatThrownBy(() -> { |
298 | | - String query = "Select * from host21 whereabs testId=2"; |
299 | | - try (Stream<Map<String, Object>> stream = client.queryRows(query)) { |
300 | | - stream.findFirst(); |
301 | | - } |
302 | | - }) |
303 | | - .isInstanceOf(FlightRuntimeException.class); |
304 | | - } |
305 | | - } |
306 | 131 | } |
0 commit comments