Repository: influxdata/influxdb-java
Pull request #772 (2021-09-13 03:01:57)

Bump junit-jupiter-engine from 5.7.2 to 5.8.0
Bumps [junit-jupiter-engine](https://github.com/junit-team/junit5) from 5.7.2 to 5.8.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a href="https://github.com/junit-team/junit5/releases">junit-jupiter-engine's releases</a>.</em></p>
<blockquote>
<p>JUnit 5.8.0 = Platform 1.8.0 + Jupiter 5.8.0 + Vintage 5.8.0</p>
<p>See <a href="http://junit.org/junit5/docs/5.8.0/release-notes/">Release Notes</a>.</p>
<p>JUnit 5.8.0-RC1 = Platform 1.8.0-RC1 + Jupiter 5.8.0-RC1 + Vintage 5.8.0-RC1</p>
<p>See <a href="http://junit.org/junit5/docs/5.8.0-RC1/release-notes/">Release Notes</a>.</p>
<p>JUnit 5.8.0-M1 = Platform 1.8.0-M1 + Jupiter 5.8.0-M1 + Vintage 5.8.0-M1</p>
<p>See <a href="http://junit.org/junit5/docs/5.8.0-M1/release-notes/">Release Notes</a>.</p>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/junit-team/junit5/commit/709fd6e1d6d311a5950e0a957283ac37530e41fd"><code>709fd6e</code></a> Release 5.8</li>
<li><a href="https://github.com/junit-team/junit5/commit/fa7405528ecdf5a274b050d117ffb2738df0c426"><code>fa74055</code></a> Use text block</li>
<li><a href="https://github.com/junit-team/junit5/commit/d36ea28cf16b59db91499d8c63fd4d409c0b9900"><code>d36ea28</code></a> Declare service in module descriptor</li>
<li><a href="https://github.com/junit-team/junit5/commit/6c0bf0229a552c926d584fea7c5b2826d464ca21"><code>6c0bf02</code></a> Fix modular user guide tests by reading module <code>jdk.httpserver</code></li>
<li><a href="https://github.com/junit-team/junit5/commit/b6dff0d53e6fdc9036d4a35b84fa76ef16e6b0fd"><code>b6dff0d</code></a> Add LauncherSessionListener example to user guide</li>
<li><a href="https://github.com/junit-team/junit5/commit/439084d2fd72d6f891d09847d6c5f26de26e4b0b"><code>439084d</code></a> Polish documentation for 5.8 GA</li>
<li><a href="https://github.com/junit-team/junit5/commit/fa021ed31335335ae64fb5dc8f3c94e4c59aa775"><code>fa021ed</code></a> Document published dependency scope change as potentially breaking</li>
<li><a href="https://github.com/junit-team/junit5/commit/efb980c4e9b24f0639f62ed91835ebf2f7b921e1"><code>efb980c</code></a> Polishing</li>
<li><a href="https://github.com/junit-team/junit5/commit/0bd6feb4910cbf0a4facbbeeddd06ce6318d179d"><code>0bd6feb</code></a> Remove link to package private class in Javadoc</li>
<li><a href="https://github.com/junit-team/junit5/commit/75538a7262f8fe44a085d061d37be8f3792eb241"><code>75538a7</code></a> Document that autoCloseArguments in <a href="https://github.com/ParameterizedTest"><code>@​ParameterizedTest</code></a> is a potentially break...</li>
<li>Additional commits viewable in <a href="https://github.com/junit-team/junit5/compare/r5.7.2...r5.8.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=org.junit.jupiter:junit-jupiter-engine&package-manager=maven&previous-version=5.7.2&new-version=5.8.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>

codecov-commenter: # [Codecov](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) Report
> Merging [#772](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) (9c0f3c9) into [master](https://codecov.io/gh/influxdata/influxdb-java/commit/920aa065129763e2aa706a782a19b0f80eaf8ffc?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) (920aa06) will **decrease** coverage by `0.87%`.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/influxdata/influxdb-java/pull/772/graphs/tree.svg?width=650&height=150&src=pr&token=QKip8tza8W&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)

```diff
@@             Coverage Diff              @@
##             master     #772      +/-   ##
============================================
- Coverage     54.99%   54.11%   -0.88%     
+ Complexity      390      383       -7     
============================================
  Files            70       70              
  Lines          2575     2574       -1     
  Branches        270      268       -2     
============================================
- Hits           1416     1393      -23     
- Misses         1093     1116      +23     
+ Partials         66       65       -1     
```


| [Impacted Files](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata) | Coverage Δ | |
|---|---|---|
| [.../influxdb/msgpack/MessagePackConverterFactory.java](https://codecov.io/gh/influxdata/influxdb-java/pull/772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-c3JjL21haW4vamF2YS9vcmcvaW5mbHV4ZGIvbXNncGFjay9NZXNzYWdlUGFja0NvbnZlcnRlckZhY3RvcnkuamF2YQ==) | `0.00% <0.00%> (-100.00%)` | :arrow_down: |
| [...uxdb/msgpack/MessagePackResponseBodyConverter.java](https://codecov.io/gh/influxdata/influxdb-java/pull/772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-c3JjL21haW4vamF2YS9vcmcvaW5mbHV4ZGIvbXNncGFjay9NZXNzYWdlUGFja1Jlc3BvbnNlQm9keUNvbnZlcnRlci5qYXZh) | `0.00% <0.00%> (-25.00%)` | :arrow_down: |
| [src/main/java/org/influxdb/impl/InfluxDBImpl.java](https://codecov.io/gh/influxdata/influxdb-java/pull/772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-c3JjL21haW4vamF2YS9vcmcvaW5mbHV4ZGIvaW1wbC9JbmZsdXhEQkltcGwuamF2YQ==) | `75.39% <0.00%> (-3.89%)` | :arrow_down: |
| [src/main/java/org/influxdb/dto/Query.java](https://codecov.io/gh/influxdata/influxdb-java/pull/772/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata#diff-c3JjL21haW4vamF2YS9vcmcvaW5mbHV4ZGIvZHRvL1F1ZXJ5LmphdmE=) | `65.00% <0.00%> (-2.50%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata). Last update [920aa06...9c0f3c9](https://codecov.io/gh/influxdata/influxdb-java/pull/772?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=influxdata).


Patch:
diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml
index d02b08b..9853c67 100644
--- a/.github/workflows/master.yml
+++ b/.github/workflows/master.yml
@@ -11,7 +11,7 @@ jobs:
 
     strategy:
       matrix:
-        jdk: [3-openjdk-16-slim, 3-jdk-14, 3-jdk-8-slim]
+        jdk: [3-openjdk-17-slim, 3-jdk-14, 3-jdk-8-slim]
         influxdb: ['1.1', '1.6', '1.8', '2.0']
 
     steps:
diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml
index d427485..405f23b 100644
--- a/.github/workflows/pr.yml
+++ b/.github/workflows/pr.yml
@@ -11,8 +11,8 @@ jobs:
 
     strategy:
       matrix:
-        jdk: [3-openjdk-16-slim, 3-jdk-14, 3-jdk-8-slim]
-        influxdb: [1.1, 1.6, 1.8, 2.0]
+        jdk: [3-openjdk-17-slim, 3-jdk-14, 3-jdk-8-slim]
+        influxdb: ['1.1', '1.6', '1.8', '2.0']
 
     steps:
       - name: Checkout
@@ -23,6 +23,9 @@ jobs:
         run: '["${{ secrets.DOCKER_REGISTRY_TOKEN }}" == ""] && echo "::set-output name=is_fork_pr::true" || echo "::set-output name=is_fork_pr::false"'
 
       - name: Build project
+        env:
+          MAVEN_JAVA_VERSION: "${{ matrix.jdk }}"
+          INFLUXDB_VERSION: "${{ matrix.influxdb }}"
         run: ./compile-and-test.sh
 
       - name: codecov
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8d74570..eb68501 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,8 @@
 # Changelog
 
-## 2.22 [unreleased]
+## 2.23 [unreleased]
+
+## 2.22 [2021-09-17]
 
 ### Improvements
 
diff --git a/mvn.sh b/mvn.sh
index 938c3df..cd99af3 100755
--- a/mvn.sh
+++ b/mvn.sh
@@ -8,4 +8,4 @@ docker run -it --rm  \
        -v $PWD:/usr/src/mymaven \
        -v $PWD/.m2:/root/.m2 \
        -w /usr/src/mymaven \
-       maven:3-openjdk-16-slim mvn clean "$@"
+       maven:3-openjdk-17-slim mvn clean "$@"
diff --git a/pom.xml b/pom.xml
index 3f71964..57f1c38 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
   <groupId>org.influxdb</groupId>
   <artifactId>influxdb-java</artifactId>
   <packaging>jar</packaging>
-  <version>2.22-SNAPSHOT</version>
+  <version>2.23-SNAPSHOT</version>
   <name>influxdb java bindings</name>
   <description>Java API to access the InfluxDB REST API</description>
   <url>http://www.influxdb.org</url>
@@ -249,7 +249,7 @@
     <dependency>
       <groupId>org.junit.jupiter</groupId>
       <artifactId>junit-jupiter-engine</artifactId>
-      <version>5.7.2</version>
+      <version>5.8.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
diff --git a/src/main/java/org/influxdb/impl/BatchProcessor.java b/src/main/java/org/influxdb/impl/BatchProcessor.java
index 4430072..28c45b6 100644
--- a/src/main/java/org/influxdb/impl/BatchProcessor.java
+++ b/src/main/java/org/influxdb/impl/BatchProcessor.java
@@ -20,6 +20,7 @@ import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
+import java.util.function.Supplier;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -46,6 +47,7 @@ public final class BatchProcessor {
   private final BatchWriter batchWriter;
   private boolean dropActionsOnQueueExhaustion;
   Consumer<Point> droppedActionHandler;
+  Supplier<Double> randomSupplier;
 
   /**
    * The Builder to create a BatchProcessor instance.
@@ -318,20 +320,21 @@ public final class BatchProcessor {
     } else {
         this.queue = new LinkedBlockingQueue<>();
     }
+    this.randomSupplier = Math::random;
 
     Runnable flushRunnable = new Runnable() {
       @Override
       public void run() {
         // write doesn't throw any exceptions
         write();
-        int jitterInterval = (int) (Math.random() * BatchProcessor.this.jitterInterval);
+        int jitterInterval = (int) (randomSupplier.get() * BatchProcessor.this.jitterInterval);
         BatchProcessor.this.scheduler.schedule(this,
                 BatchProcessor.this.flushInterval + jitterInterval, BatchProcessor.this.flushIntervalUnit);
       }
     };
     // Flush at specified Rate
     this.scheduler.schedule(flushRunnable,
-            this.flushInterval + (int) (Math.random() * BatchProcessor.this.jitterInterval),
+            this.flushInterval + (int) (randomSupplier.get() * BatchProcessor.this.jitterInterval),
             this.flushIntervalUnit);
   }
 


Test patch:
diff --git a/compile-and-test.sh b/compile-and-test.sh
index 88f0578..4e903e0 100755
--- a/compile-and-test.sh
+++ b/compile-and-test.sh
@@ -5,7 +5,7 @@
 set -e
 
 DEFAULT_INFLUXDB_VERSION="1.8"
-DEFAULT_MAVEN_JAVA_VERSION="3-openjdk-16-slim"
+DEFAULT_MAVEN_JAVA_VERSION="3-openjdk-17-slim"
 
 INFLUXDB_VERSION="${INFLUXDB_VERSION:-$DEFAULT_INFLUXDB_VERSION}"
 MAVEN_JAVA_VERSION="${MAVEN_JAVA_VERSION:-$DEFAULT_MAVEN_JAVA_VERSION}"
diff --git a/src/test/java/org/influxdb/BatchOptionsTest.java b/src/test/java/org/influxdb/BatchOptionsTest.java
index 351321b..7378746 100644
--- a/src/test/java/org/influxdb/BatchOptionsTest.java
+++ b/src/test/java/org/influxdb/BatchOptionsTest.java
@@ -7,13 +7,13 @@ import org.influxdb.dto.BatchPoints;
 import org.influxdb.dto.Point;
 import org.influxdb.dto.Query;
 import org.influxdb.dto.QueryResult;
-import org.jetbrains.annotations.NotNull;
+import org.influxdb.impl.BatchProcessor;
+import org.influxdb.impl.BatchProcessorTest;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.platform.runner.JUnitPlatform;
 import org.junit.runner.RunWith;
-import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 
@@ -21,12 +21,15 @@ import static org.mockito.Mockito.*;
 
 import java.io.IOException;
 import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
+import java.util.function.Supplier;
 
 
 @RunWith(JUnitPlatform.class)
@@ -234,15 +237,20 @@ public class BatchOptionsTest {
    * @throws InterruptedException
    */
   @Test
-  public void testJitterDuration() throws InterruptedException {
+  public void testJitterDuration() throws Exception {
 
     String dbName = "write_unittest_" + System.currentTimeMillis();
     try {
-      BatchOptions options = BatchOptions.DEFAULTS.flushDuration(100).jitterDuration(500);
+      // prepare points before start BatchProcessor
+      List<Point> points = prepareSomePoints(0, 19);
+      BatchOptions options = BatchOptions.DEFAULTS.flushDuration(100).jitterDuration(1000);
       influxDB.query(new Query("CREATE DATABASE " + dbName));
       influxDB.setDatabase(dbName);
       influxDB.enableBatch(options);
-      write20Points(influxDB);
+      BatchProcessor batchProcessor = BatchProcessorTest.getPrivateField(influxDB, "batchProcessor");
+      // random always return 1.0 to be sure that first query is null
+      BatchProcessorTest.setPrivateField(batchProcessor, "randomSupplier", (Supplier<Double>) () -> 1.0);
+      points.forEach(influxDB::write);
 
       Thread.sleep(100);
 
@@ -251,7 +259,7 @@ public class BatchOptionsTest {
       Assertions.assertNull(result.getResults().get(0).getError());
 
       //wait for at least one flush
-      Thread.sleep(1000);
+      Thread.sleep(1500);
       result = influxDB.query(new Query("select * from weather", dbName));
       Assertions.assertEquals(20, result.getResults().get(0).getSeries().get(0).getValues().size());
     }
@@ -596,6 +604,7 @@ public class BatchOptionsTest {
 
       verify(spy, times(2)).write(any(BatchPoints.class));
 
+      Thread.sleep(1_500);
       QueryResult result = influxDB.query(new Query("select * from m0", dbName));
       Assertions.assertNotNull(result.getResults().get(0).getSeries());
       Assertions.assertEquals(200, result.getResults().get(0).getSeries().get(0).getValues().size());
@@ -668,14 +677,7 @@ public class BatchOptionsTest {
   }
 
   void writeSomePoints(InfluxDB influxDB, int firstIndex, int lastIndex) {
-    for (int i = firstIndex; i <= lastIndex; i++) {
-      Point point = Point.measurement("weather")
-              .time(i,TimeUnit.HOURS)
-              .addField("temperature", (double) i)
-              .addField("humidity", (double) (i) * 1.1)
-              .addField("uv_index", "moderate").build();
-      influxDB.write(point);
-    }
+    prepareSomePoints(firstIndex, lastIndex).forEach(influxDB::write);
   }
 
   void write20Points(InfluxDB influxDB) {
@@ -686,6 +688,19 @@ public class BatchOptionsTest {
     writeSomePoints(influxDB, 0, n - 1);
   }
 
+  List<Point> prepareSomePoints(int firstIndex, int lastIndex) {
+    List<Point> points = new ArrayList<>();
+    for (int i = firstIndex; i <= lastIndex; i++) {
+      Point point = Point.measurement("weather")
+              .time(i, TimeUnit.HOURS)
+              .addField("temperature", (double) i)
+              .addField("humidity", (double) (i) * 1.1)
+              .addField("uv_index", "moderate").build();
+      points.add(point);
+    }
+    return points;
+  }
+
   private BatchPoints createBatchPoints(String dbName, String measurement, int n) {
     BatchPoints batchPoints = BatchPoints.database(dbName).build();
     for (int i = 1; i <= n; i++) {
diff --git a/src/test/java/org/influxdb/InfluxDBTest.java b/src/test/java/org/influxdb/InfluxDBTest.java
index 60dd666..38b5fcf 100644
--- a/src/test/java/org/influxdb/InfluxDBTest.java
+++ b/src/test/java/org/influxdb/InfluxDBTest.java
@@ -1330,7 +1330,7 @@ public class InfluxDBTest {
         batchPoints.point(point3);
         this.influxDB.write(batchPoints);
 
-        CountDownLatch countDownLatch = new CountDownLatch(3);
+        CountDownLatch countDownLatch = new CountDownLatch(2);
 
         Thread.sleep(2000);
         Query query = new Query("SELECT * FROM disk", dbName, true);
diff --git a/src/test/java/org/influxdb/impl/BatchProcessorTest.java b/src/test/java/org/influxdb/impl/BatchProcessorTest.java
index 213f6d3..df28da3 100644
--- a/src/test/java/org/influxdb/impl/BatchProcessorTest.java
+++ b/src/test/java/org/influxdb/impl/BatchProcessorTest.java
@@ -226,14 +226,27 @@ public class BatchProcessorTest {
       }
     }
 
+    @Test
+    @SuppressWarnings("unchecked")
+    public void randomSupplier() {
+      InfluxDB mockInfluxDB = mock(InfluxDBImpl.class);
+      BatchProcessor batchProcessor = BatchProcessor.builder(mockInfluxDB).actions(Integer.MAX_VALUE)
+                .interval(1, TimeUnit.NANOSECONDS).build();
+
+      Double random = batchProcessor.randomSupplier.get();
+      assertTrue(random >= 0);
+      assertTrue(random < 1);
+      Assertions.assertNotEquals(random, batchProcessor.randomSupplier.get());
+    }
+
     @SuppressWarnings("unchecked")
-    static <T> T getPrivateField(final Object obj, final String name) throws Exception {
+    public static <T> T getPrivateField(final Object obj, final String name) throws Exception {
       Field field = obj.getClass().getDeclaredField(name);
       field.setAccessible(true);
       return (T) field.get(obj);
     }
 
-    static void setPrivateField(final Object obj, final String name, final Object value) throws Exception {
+    public static void setPrivateField(final Object obj, final String name, final Object value) throws Exception {
       Field field = obj.getClass().getDeclaredField(name);
       field.setAccessible(true);
       field.set(obj, value);