|
1 | 1 | package org.influxdb;
|
2 | 2 |
|
3 |
| -import java.util.Collections; |
| 3 | +import okhttp3.OkHttpClient; |
4 | 4 | import org.influxdb.InfluxDB.LogLevel;
|
5 | 5 | import org.influxdb.InfluxDB.ResponseFormat;
|
6 | 6 | import org.influxdb.dto.BatchPoints;
|
|
19 | 19 | import org.junit.platform.runner.JUnitPlatform;
|
20 | 20 | import org.junit.runner.RunWith;
|
21 | 21 |
|
22 |
| -import okhttp3.OkHttpClient; |
23 |
| - |
24 | 22 | import java.io.IOException;
|
25 | 23 | import java.net.ConnectException;
|
26 | 24 | import java.time.Instant;
|
27 | 25 | import java.time.ZoneId;
|
28 | 26 | import java.time.format.DateTimeFormatter;
|
29 | 27 | import java.util.ArrayList;
|
30 | 28 | import java.util.Arrays;
|
| 29 | +import java.util.Collections; |
31 | 30 | import java.util.List;
|
32 | 31 | import java.util.Set;
|
33 | 32 | import java.util.concurrent.BlockingQueue;
|
|
40 | 39 | import java.util.concurrent.TimeUnit;
|
41 | 40 | import java.util.concurrent.atomic.LongAdder;
|
42 | 41 | import java.util.function.Consumer;
|
| 42 | +import java.util.regex.Pattern; |
43 | 43 |
|
44 | 44 | /**
|
45 | 45 | * Test the InfluxDB API.
|
@@ -175,24 +175,47 @@ public void testBoundParameterQuery() throws InterruptedException {
|
175 | 175 | }
|
176 | 176 | }
|
177 | 177 |
|
178 |
| - /** |
179 |
| - * Tests for callback query. |
180 |
| - */ |
181 |
| - @Test |
182 |
| - public void testCallbackQuery() throws Throwable { |
183 |
| - final AsyncResult<QueryResult> result = new AsyncResult<>(); |
184 |
| - final Consumer<QueryResult> firstQueryConsumer = new Consumer<QueryResult>() { |
185 |
| - @Override |
186 |
| - public void accept(QueryResult queryResult) { |
187 |
| - influxDB.query(new Query("DROP DATABASE mydb2", "mydb"), result.resultConsumer, result.errorConsumer); |
188 |
| - } |
189 |
| - }; |
| 178 | + /** |
| 179 | + * Tests for callback query. |
| 180 | + */ |
| 181 | + @Test |
| 182 | + public void testCallbackQuery() throws Throwable { |
| 183 | + final AsyncResult<QueryResult> result = new AsyncResult<>(); |
| 184 | + final Consumer<QueryResult> firstQueryConsumer = new Consumer<QueryResult>() { |
| 185 | + @Override |
| 186 | + public void accept(QueryResult queryResult) { |
| 187 | + influxDB.query(new Query("DROP DATABASE mydb2", "mydb"), result.resultConsumer, result.errorConsumer); |
| 188 | + } |
| 189 | + }; |
190 | 190 |
|
191 |
| - this.influxDB.query(new Query("CREATE DATABASE mydb2", "mydb"), firstQueryConsumer, result.errorConsumer); |
| 191 | + this.influxDB.query(new Query("CREATE DATABASE mydb2", "mydb"), firstQueryConsumer, result.errorConsumer); |
192 | 192 |
|
193 |
| - // Will throw exception in case of error. |
194 |
| - result.result(); |
195 |
| - } |
| 193 | + // Will throw exception in case of error. |
| 194 | + result.result(); |
| 195 | + } |
| 196 | + |
| 197 | + /** |
| 198 | + * Tests for callback query with a failure. |
| 199 | + * see Issue #602 |
| 200 | + */ |
| 201 | + @Test |
| 202 | + public void testCallbackQueryFailureHandling() throws Throwable { |
| 203 | + final AsyncResult<QueryResult> res = new AsyncResult<>(); |
| 204 | + |
| 205 | + this.influxDB.query(new Query("SHOW SERRIES"), res.resultConsumer, res.errorConsumer); |
| 206 | + |
| 207 | + try{ |
| 208 | + res.result(); |
| 209 | + Assertions.fail("Malformed query should throw InfluxDBException"); |
| 210 | + } |
| 211 | + catch (InfluxDBException e){ |
| 212 | + Pattern errorPattern = Pattern.compile("Bad Request.*error parsing query: found SERRIES, expected.*", |
| 213 | + Pattern.DOTALL); |
| 214 | + |
| 215 | + Assertions.assertTrue(errorPattern.matcher(e.getMessage()).matches(), |
| 216 | + "Error string \"" + e.getMessage() + "\" does not match error pattern"); |
| 217 | + } |
| 218 | + } |
196 | 219 |
|
197 | 220 | /**
|
198 | 221 | * Test that describe Databases works.
|
|
0 commit comments