Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
- fixed issue influxdata#523 fixing EOFException, increase code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rhajek committed Sep 26, 2018
1 parent c3fa4f8 commit c84ec5a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/main/java/org/influxdb/impl/InfluxDBImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -643,13 +643,12 @@ public boolean isCanceled() {
}
}
} catch (IOException e) {
QueryResult queryResult = new QueryResult();
queryResult.setError(e.toString());
onNext.accept(cancellable, queryResult);
//passing null onFailure consumer is here for backward compatibility
//where the empty queryResult containing error is propagating into onNext consumer
if (onFailure == null) {
QueryResult queryResult = new QueryResult();
queryResult.setError(e.toString());
onNext.accept(cancellable, queryResult);
} else {
if (onFailure != null) {
onFailure.accept(e);
}
}
Expand Down
35 changes: 26 additions & 9 deletions src/test/java/org/influxdb/impl/ChunkingExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,28 @@ public class ChunkingExceptionTest {
@Test
public void testChunkingIOException() throws IOException, InterruptedException {

testChunkingException(new IOException(), "java.io.IOException");
testChunkingException(new IOException(), "java.io.IOException", null);
}

@Test
public void testChunkingEOFException() throws IOException, InterruptedException {

testChunkingException(new EOFException(), "DONE");
testChunkingException(new EOFException(), "DONE", null);
}

public void testChunkingException(Exception ex, String message) throws IOException, InterruptedException {
@Test
public void testChunkingIOExceptionOnFailure() throws IOException, InterruptedException {

testChunkingException(new IOException(), "java.io.IOException", Assertions::assertNotNull);
}

@Test
public void testChunkingEOFExceptionOnFailure() throws IOException, InterruptedException {

testChunkingException(new EOFException(), "DONE", Assertions::assertNotNull);
}

public void testChunkingException(Exception ex, String message, Consumer<Throwable> onFailure) throws IOException, InterruptedException {

InfluxDBService influxDBService = mock(InfluxDBService.class);
JsonAdapter<QueryResult> adapter = mock(JsonAdapter.class);
Expand All @@ -71,12 +83,17 @@ public String version() {
String dbName = "write_unittest_" + System.currentTimeMillis();
final BlockingQueue<QueryResult> queue = new LinkedBlockingQueue<>();
Query query = new Query("SELECT * FROM disk", dbName);
influxDB.query(query, 2, new Consumer<QueryResult>() {
@Override
public void accept(QueryResult result) {
queue.add(result);
}
});

if (onFailure == null) {
influxDB.query(query, 2, queue::add);
} else {
//test with onComplete and onFailure consumer
influxDB.query(query, 2, (cancellable, result) -> queue.add(result),
//on complete
() -> { },
onFailure
);
}

ArgumentCaptor<Callback<ResponseBody>> argumentCaptor = ArgumentCaptor.forClass(Callback.class);
verify(call).enqueue(argumentCaptor.capture());
Expand Down

0 comments on commit c84ec5a

Please sign in to comment.