Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
## 1.9.0 [unreleased]

### API
### Features
1. [#119](https://github.com/influxdata/influxdb-client-java/pull/119): Scala and Kotlin clients has their own user agent string

### API
1. [#117](https://github.com/influxdata/influxdb-client-java/pull/117): Update swagger to latest version

### Bug Fixes

1. [#116](https://github.com/influxdata/influxdb-client-java/pull/116): The closing message of the `WriteApi` has `Fine` log level

### Dependencies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.IOException;
import javax.annotation.Nonnull;

import com.influxdb.Arguments;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
Expand All @@ -35,11 +37,17 @@ public class UserAgentInterceptor implements Interceptor {

private final String userAgent;

public UserAgentInterceptor() {
/**
* @param clientType type of client - java, scala, kotlin
*/
public UserAgentInterceptor(final String clientType) {

Arguments.checkNonEmpty(clientType, "clientType");

Package mainPackage = UserAgentInterceptor.class.getPackage();
String version = null != mainPackage ? mainPackage.getImplementationVersion() : null;

userAgent = "influxdb-client-java/" + (version != null ? version : "unknown");
userAgent = String.format("influxdb-client-%s/%s", clientType, version != null ? version : "unknown");
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class ITUserAgentInterceptor extends AbstractMockServerTest {
void setUp() {

client = new OkHttpClient.Builder()
.addInterceptor(new UserAgentInterceptor())
.addInterceptor(new UserAgentInterceptor("java"))
.build();

url = startMockServer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.influxdb.client.service.QueryService
/**
* @author Jakub Bednar (bednar@github) (07/02/2019 13:21)
*/
internal class InfluxDBClientKotlinImpl(options: InfluxDBClientOptions) : AbstractInfluxDBClient(options), InfluxDBClientKotlin {
internal class InfluxDBClientKotlinImpl(options: InfluxDBClientOptions) : AbstractInfluxDBClient(options, "kotlin"), InfluxDBClientKotlin {

override fun getQueryKotlinApi(): QueryKotlinApi {
return QueryKotlinApiImpl(retrofit.create<QueryService>(QueryService::class.java), options)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.client.kotlin

import com.influxdb.test.AbstractMockServerTest
import org.assertj.core.api.Assertions
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import java.util.concurrent.TimeUnit

/**
* @author Jakub Bednar (09/06/2020 07:11)
*/
@RunWith(JUnitPlatform::class)
class InfluxDBClientKotlinTest : AbstractMockServerTest() {

@Test
fun userAgent() {
val client = InfluxDBClientKotlinFactory.create(startMockServer())

enqueuedResponse()

val queryKotlinApi = client.getQueryKotlinApi()
val flux = "from(bucket:\"my-bucket\")\n\t" +
"|> range(start: 1970-01-01T00:00:00.000000001Z)\n\t" +
"|> filter(fn: (r) => (r[\"_measurement\"] == \"mem\" and r[\"_field\"] == \"free\"))\n\t" +
"|> sum()"

queryKotlinApi.query(flux, "my-org")

val request = mockServer.takeRequest(10L, TimeUnit.SECONDS)

Assertions.assertThat(request?.getHeader("User-Agent")).startsWith("influxdb-client-kotlin/")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public FluxApiImpl(@Nonnull final FluxConnectionOptions options) {
}

this.okHttpClient = options.getOkHttpClient()
.addInterceptor(new UserAgentInterceptor())
.addInterceptor(new UserAgentInterceptor("java"))
.addInterceptor(this.loggingInterceptor)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class InfluxDBClientReactiveImpl extends AbstractInfluxDBClient
implements InfluxDBClientReactive {

public InfluxDBClientReactiveImpl(@Nonnull final InfluxDBClientOptions options) {
super(options);
super(options, "java");
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import javax.annotation.Nonnull
*/
class InfluxDBClientScalaImpl(@Nonnull options: InfluxDBClientOptions,
@Nonnull val bufferSize: Int,
@Nonnull val overflowStrategy: OverflowStrategy) extends AbstractInfluxDBClient(options) with InfluxDBClientScala {
@Nonnull val overflowStrategy: OverflowStrategy) extends AbstractInfluxDBClient(options, "scala") with InfluxDBClientScala {
/**
* Get the Query client.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
*/
package com.influxdb.client.scala

import org.scalatest.{BeforeAndAfter, FunSuite}
import org.scalatest.BeforeAndAfter
import org.scalatest.funsuite.AnyFunSuite

/**
* @author Jakub Bednar (bednar@github) (06/11/2018 09:34)
*/
abstract class AbstractITQueryScalaApi extends FunSuite with BeforeAndAfter {
abstract class AbstractITQueryScalaApi extends AnyFunSuite with BeforeAndAfter {

var influxDBUtils: InfluxDBUtils = _

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ package com.influxdb.client.scala

import com.influxdb.LogLevel
import com.influxdb.client.domain.HealthCheck
import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers

/**
* @author Jakub Bednar (bednar@github) (06/11/2018 09:52)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import com.influxdb.client.domain._
import com.influxdb.client.internal.AbstractInfluxDBClient
import com.influxdb.exceptions.InfluxException
import com.influxdb.query.FluxRecord
import org.scalatest.Matchers
import org.scalatest.matchers.should.Matchers

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._

/**
* @author Jakub Bednar (bednar@github) (07/11/2018 10:00)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import com.influxdb.LogLevel
import com.influxdb.client.InfluxDBClientOptions
import com.influxdb.client.internal.AbstractInfluxDBClient
import okhttp3.OkHttpClient
import org.scalatest.{FunSuite, Matchers}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import retrofit2.Retrofit

/**
* @author Jakub Bednar (bednar@github) (05/11/2018 09:22)
*/
class InfluxDBClientScalaFactoryTest extends FunSuite with Matchers {
class InfluxDBClientScalaFactoryTest extends AnyFunSuite with Matchers {

test("connect") {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.influxdb.client.scala

import akka.actor.ActorSystem
import akka.stream.testkit.scaladsl.TestSink
import com.influxdb.query.FluxRecord
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.scalatest.BeforeAndAfter

/**
* @author Jakub Bednar (09/06/2020 07:19)
*/
class InfluxDBClientScalaTest extends AnyFunSuite with Matchers with BeforeAndAfter{

implicit val system: ActorSystem = ActorSystem("unit-tests")

var utils: InfluxDBUtils = _

before {
utils = new InfluxDBUtils {}
}

after {
utils.serverStop()
}

test("userAgent") {

val url = utils.serverStart
utils.serverMockResponse()

val client = InfluxDBClientScalaFactory.create(url)

val queryScalaApi = client.getQueryScalaApi()
val flux = "from(bucket:\"my-bucket\")\n\t" +
"|> range(start: 1970-01-01T00:00:00.000000001Z)\n\t" +
"|> filter(fn: (r) => (r[\"_measurement\"] == \"mem\" and r[\"_field\"] == \"free\" and r[\"host\"] == \"A\"))" +
"|> sum()"

val source = queryScalaApi.query(flux, "my-org").runWith(TestSink.probe[FluxRecord])
source.expectSubscriptionAndComplete()

val request = utils.serverTakeRequest()
request.getHeader("User-Agent") should startWith("influxdb-client-scala/")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,24 @@
*/
package com.influxdb.client.scala

import com.influxdb.test.AbstractTest
import com.influxdb.test.AbstractMockServerTest
import okhttp3.mockwebserver.RecordedRequest

/**
* @author Jakub Bednar (bednar@github) (25/06/2019 11:22)
*/
class InfluxDBUtils extends AbstractTest {
class InfluxDBUtils extends AbstractMockServerTest {

def getUrl: String = super.getInfluxDb2Url

def serverStart: String = super.startMockServer

def serverStop(): Unit = super.after()

def serverMockResponse(): Unit = super.enqueuedResponse()

def serverTakeRequest(): RecordedRequest = super.takeRequest()

override def generateName(prefix: String): String = super.generateName(prefix)

override def getDeclaredField[V](obj: Any, field: String, `type`: Class[_]): V = super.getDeclaredField(obj, field, `type`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,19 @@
package com.influxdb.test;

import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.jupiter.api.AfterEach;

/**
* @author Jakub Bednar (bednar@github) (05/10/2018 08:36)
*/
@SuppressWarnings("MagicNumber")
public abstract class AbstractMockServerTest extends AbstractTest {

private static final int INTERNAL_SERVER_ERROR = 500;
Expand Down Expand Up @@ -110,4 +113,12 @@ protected MockResponse createErrorResponse(@Nullable final String influxError,

return mockResponse.setBody(body);
}

protected void enqueuedResponse() {
mockServer.enqueue(createResponse(""));
}

protected RecordedRequest takeRequest() throws InterruptedException {
return mockServer.takeRequest(10L, TimeUnit.SECONDS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ public abstract class AbstractInfluxDBClient extends AbstractRestClient {
private final OkHttpClient okHttpClient;
protected final Collection<AutoCloseable> autoCloseables = new CopyOnWriteArrayList<>();

public AbstractInfluxDBClient(@Nonnull final InfluxDBClientOptions options) {
public AbstractInfluxDBClient(@Nonnull final InfluxDBClientOptions options, @Nonnull final String clientType) {

Arguments.checkNotNull(options, "InfluxDBClientOptions");
Arguments.checkNonEmpty(clientType, "clientType");

this.options = options;
this.loggingInterceptor = new HttpLoggingInterceptor();
Expand All @@ -81,7 +82,7 @@ public AbstractInfluxDBClient(@Nonnull final InfluxDBClientOptions options) {
this.gzipInterceptor = new GzipInterceptor();

this.okHttpClient = options.getOkHttpClient()
.addInterceptor(new UserAgentInterceptor())
.addInterceptor(new UserAgentInterceptor(clientType))
.addInterceptor(this.loggingInterceptor)
.addInterceptor(this.authenticateInterceptor)
.addInterceptor(this.gzipInterceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public final class InfluxDBClientImpl extends AbstractInfluxDBClient implements

public InfluxDBClientImpl(@Nonnull final InfluxDBClientOptions options) {

super(options);
super(options, "java");

setupService = retrofit.create(SetupService.class);
readyService = retrofit.create(ReadyService.class);
Expand Down
1 change: 1 addition & 0 deletions client/src/test/java/com/influxdb/client/ITBucketsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ void labelAddNotExists() {
}

@Test
@Disabled("TODO https://github.com/influxdata/influxdb/issues/18409")
void labelDeleteNotExists() {

Bucket bucket = bucketsApi.createBucket(generateName("robot sensor"), retentionRule(), organization);
Expand Down
2 changes: 2 additions & 0 deletions client/src/test/java/com/influxdb/client/ITChecksApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -341,6 +342,7 @@ void labelAddNotExists() {
}

@Test
@Disabled("TODO https://github.com/influxdata/influxdb/issues/18409")
void labelDeleteNotExists() {

GreaterThreshold greater = new GreaterThreshold();
Expand Down
2 changes: 2 additions & 0 deletions client/src/test/java/com/influxdb/client/ITDashboardsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -276,6 +277,7 @@ void labelAddNotExists() {
}

@Test
@Disabled("TODO https://github.com/influxdata/influxdb/issues/18409")
void labelDeleteNotExists() {

Dashboard dashboard = dashboardsApi.createDashboard(generateName("dashboard"), "coolest dashboard", organization.getId());
Expand Down
Loading