|
| 1 | +/* |
| 2 | + * The MIT License |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal |
| 6 | + * in the Software without restriction, including without limitation the rights |
| 7 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 8 | + * copies of the Software, and to permit persons to whom the Software is |
| 9 | + * furnished to do so, subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 17 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 19 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 20 | + * THE SOFTWARE. |
| 21 | + */ |
| 22 | +package com.influxdb.client.internal; |
| 23 | + |
| 24 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 25 | +import static org.junit.jupiter.api.Assertions.fail; |
| 26 | + |
| 27 | +import java.time.Instant; |
| 28 | +import java.util.concurrent.CompletableFuture; |
| 29 | +import java.util.concurrent.ExecutionException; |
| 30 | +import java.util.concurrent.TimeUnit; |
| 31 | +import java.util.concurrent.TimeoutException; |
| 32 | + |
| 33 | +import com.influxdb.client.WriteApi; |
| 34 | +import com.influxdb.client.domain.WritePrecision; |
| 35 | +import com.influxdb.client.write.Point; |
| 36 | +import com.influxdb.client.write.events.WriteErrorEvent; |
| 37 | + |
| 38 | +import org.junit.jupiter.api.Test; |
| 39 | +import org.junit.platform.runner.JUnitPlatform; |
| 40 | +import org.junit.runner.RunWith; |
| 41 | + |
| 42 | +/** |
| 43 | + * This test ensures publish is called with WriteErrorEvent as described in |
| 44 | + * https://github.com/influxdata/influxdb-client-java/issues/291 |
| 45 | + */ |
| 46 | +@RunWith(JUnitPlatform.class) |
| 47 | +public class PublishRuntimeErrorAsWriteErrorEvent extends AbstractInfluxDBClientTest { |
| 48 | + |
| 49 | + @Test |
| 50 | + void publishRuntimeErrorAsWriteErrorEvent() { |
| 51 | + WriteApi writeApi = influxDBClient.makeWriteApi(); |
| 52 | + |
| 53 | + CompletableFuture<Throwable> errorEventTriggered = new CompletableFuture<>(); |
| 54 | + writeApi.listenEvents(WriteErrorEvent.class, event -> { |
| 55 | + Throwable exception = event.getThrowable(); |
| 56 | + errorEventTriggered.complete(exception); |
| 57 | + }); |
| 58 | + CompletableFuture<Object> supplyAsync = CompletableFuture.supplyAsync(() -> { |
| 59 | + for (int i = 0; i < 100000; i++) { |
| 60 | + writeApi.writePoint("my-bucket", "my-org", new Point("foo" + i).time(Instant.now(), WritePrecision.MS).addField("value", i)); |
| 61 | + } |
| 62 | + return null; |
| 63 | + }); |
| 64 | + try { |
| 65 | + supplyAsync.get(1, TimeUnit.MINUTES); |
| 66 | + assertNotNull(errorEventTriggered.get(1, TimeUnit.MINUTES)); |
| 67 | + } catch (InterruptedException | ExecutionException | TimeoutException e) { |
| 68 | + e.printStackTrace(); |
| 69 | + fail(e); |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments