From 61a744c7b22fcc19bc5ceafbc03f325b1105fc73 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Fri, 13 Aug 2021 08:26:18 +0300 Subject: [PATCH 1/6] [2.2.2-SNAPSHOT] Dev ver up --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index de6bc5c..4c4eb8f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=com.github.goodforgod artifactId=micronaut-arangodb -artifactVersion=2.2.1 +artifactVersion=2.2.2-SNAPSHOT ##### GRADLE From 77ee21b3f249f6942d5ef93fe005ba87481eb759 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 16 Aug 2021 09:53:06 +0300 Subject: [PATCH 2/6] [2.3.0-SNAPSHOT] ArangoHealthConfiguration introduced and integrated ArangoClusterHealthConfiguration introduced and integrated ToString for configs added Tests reinforced --- .github/workflows/gradle.yml | 2 +- build.gradle | 100 +++++++++--------- gradle.properties | 2 +- .../arango/AbstractArangoConfiguration.java | 30 +----- .../ArangoClusterHealthConfiguration.java | 54 ++++++++++ .../health/ArangoClusterHealthIndicator.java | 11 +- .../health/ArangoHealthConfiguration.java | 54 ++++++++++ .../arango/health/ArangoHealthIndicator.java | 10 +- .../ArangoSSLCertificateConfiguration.java | 11 ++ .../ArangoAsyncConfigurationAuthTests.java | 5 - .../arango/ArangoConfigurationAuthTests.java | 6 +- .../arango/ArangoConfigurationTests.java | 8 ++ .../arango/ArangoSSLContextTests.java | 7 ++ .../health/ArangoHealthUpClusterTests.java | 7 ++ 14 files changed, 211 insertions(+), 96 deletions(-) create mode 100644 src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java create mode 100644 src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 7b2bd9a..72505ec 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -26,7 +26,7 @@ jobs: java-version: ${{ matrix.java }} - name: Build - run: ./gradlew classes + run: ./gradlew classes spotlessJavaCheck - name: Test run: ./gradlew test jacocoTestReport diff --git a/build.gradle b/build.gradle index d99f3ee..58c6f64 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,10 @@ plugins { - id 'jacoco' - id 'maven-publish' + id "jacoco" + id "maven-publish" - id 'io.micronaut.library' version '2.0.3' - id 'org.sonarqube' version '3.3' - id 'com.diffplug.spotless' version '5.11.0' + id "io.micronaut.library" version "2.0.3" + id "org.sonarqube" version "3.3" + id "com.diffplug.spotless" version "5.11.0" } repositories { @@ -20,7 +20,7 @@ targetCompatibility = 11 spotless { java { - encoding 'UTF-8' + encoding "UTF-8" removeUnusedImports() eclipse().configFile "${projectDir}/config/codestyle.xml" } @@ -28,49 +28,54 @@ spotless { sonarqube { properties { - property 'sonar.host.url', 'https://sonarcloud.io' - property 'sonar.organization', 'goodforgod' - property 'sonar.projectKey', 'GoodforGod_micronaut-arangodb' + property "sonar.host.url", "https://sonarcloud.io" + property "sonar.organization", "goodforgod" + property "sonar.projectKey", "GoodforGod_micronaut-arangodb" } } micronaut { - version '2.5.11' + version("2.5.12") processing { - incremental true - module project.name - group project.group - annotations 'io.micronaut.configuration.arango.*' + incremental(true) + module(project.name) + group(project.group) + annotations("io.micronaut.configuration.arango.*") } } dependencies { - annotationProcessor 'io.micronaut:micronaut-inject-java' - compileOnly 'io.micronaut:micronaut-inject-java' + annotationProcessor "io.micronaut:micronaut-inject-java" + compileOnly "io.micronaut:micronaut-inject-java" - api 'com.arangodb:arangodb-java-driver:6.12.3' + api "com.arangodb:arangodb-java-driver:6.12.3" - implementation 'org.apache.httpcomponents:httpclient:4.5.13' - implementation 'io.micronaut:micronaut-management' + implementation "org.apache.httpcomponents:httpclient:4.5.13" + implementation "io.micronaut:micronaut-management" - testAnnotationProcessor 'io.micronaut:micronaut-inject-java' + testAnnotationProcessor "io.micronaut:micronaut-inject-java" - testRuntimeOnly 'ch.qos.logback:logback-classic:1.2.3' - testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' + testRuntimeOnly "ch.qos.logback:logback-classic:1.2.3" + testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine" - testImplementation 'org.testcontainers:junit-jupiter:1.15.3' - testImplementation 'com.github.goodforgod:arangodb-testcontainer:1.3.0' + testImplementation "org.testcontainers:junit-jupiter:1.15.3" + testImplementation "com.github.goodforgod:arangodb-testcontainer:1.3.0" - testImplementation 'io.micronaut.test:micronaut-test-core' - testImplementation 'io.micronaut.test:micronaut-test-junit5' - testImplementation 'org.junit.jupiter:junit-jupiter-api' + testImplementation "io.micronaut.test:micronaut-test-core" + testImplementation "io.micronaut.test:micronaut-test-junit5" + testImplementation "org.junit.jupiter:junit-jupiter-api" } test { useJUnitPlatform() testLogging { - events "passed", "skipped", "failed" - exceptionFormat "full" + events("passed", "skipped", "failed") + exceptionFormat("full") + } + + reports { + html.enabled(false) + junitXml.enabled(false) } } @@ -80,11 +85,6 @@ tasks.withType(JavaCompile) { options.fork = true } -tasks.withType(Test) { - reports.html.enabled = false - reports.junitXml.enabled = false -} - java { withJavadocJar() withSourcesJar() @@ -96,27 +96,27 @@ publishing { from components.java pom { - name = 'Micronaut ArangoDB Configuration' - url = 'https://github.com/GoodforGod/micronaut-arangodb' - description = 'This is integration between Micronaut and ArangoDB.' + name = "Micronaut ArangoDB Configuration" + url = "https://github.com/GoodforGod/micronaut-arangodb" + description = "This is integration between Micronaut and ArangoDB." license { - name = 'Apache License 2.0' - url = 'https://github.com/GoodforGod/micronaut-arangodb/blob/master/LICENSE' - distribution = 'repo' + name = "Apache License 2.0" + url = "https://github.com/GoodforGod/micronaut-arangodb/blob/master/LICENSE" + distribution = "repo" } developer { - id = 'GoodforGod' - name = 'Anton Kurako' - email = 'goodforgod.dev@gmail.com' - url = 'https://github.com/GoodforGod' + id = "GoodforGod" + name = "Anton Kurako" + email = "goodforgod.dev@gmail.com" + url = "https://github.com/GoodforGod" } scm { - connection = 'scm:git:git://github.com/GoodforGod/micronaut-arangodb.git' - developerConnection = 'scm:git:ssh://GoodforGod/micronaut-arangodb.git' - url = 'https://github.com/GoodforGod/micronaut-arangodb/tree/master' + connection = "scm:git:git://github.com/GoodforGod/micronaut-arangodb.git" + developerConnection = "scm:git:ssh://GoodforGod/micronaut-arangodb.git" + url = "https://github.com/GoodforGod/micronaut-arangodb/tree/master" } } } @@ -126,7 +126,7 @@ publishing { maven { def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2" def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/" - url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + url = version.endsWith("SNAPSHOT") ? snapshotsRepoUrl : releasesRepoUrl credentials { username System.getenv("OSS_USERNAME") password System.getenv("OSS_PASSWORD") @@ -144,7 +144,7 @@ jacocoTestReport { } if (project.hasProperty("signing.keyId")) { - apply plugin: 'signing' + apply plugin: "signing" signing { sign publishing.publications.mavenJava } @@ -153,6 +153,6 @@ if (project.hasProperty("signing.keyId")) { javadoc { options.encoding = "UTF-8" if (JavaVersion.current().isJava9Compatible()) { - options.addBooleanOption('html5', true) + options.addBooleanOption("html5", true) } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 4c4eb8f..2a846de 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=com.github.goodforgod artifactId=micronaut-arangodb -artifactVersion=2.2.2-SNAPSHOT +artifactVersion=2.3.0-SNAPSHOT ##### GRADLE diff --git a/src/main/java/io/micronaut/configuration/arango/AbstractArangoConfiguration.java b/src/main/java/io/micronaut/configuration/arango/AbstractArangoConfiguration.java index cc0c0d4..ebcad52 100644 --- a/src/main/java/io/micronaut/configuration/arango/AbstractArangoConfiguration.java +++ b/src/main/java/io/micronaut/configuration/arango/AbstractArangoConfiguration.java @@ -3,7 +3,6 @@ import com.arangodb.entity.LoadBalancingStrategy; import com.arangodb.internal.ArangoDefaults; import io.micronaut.configuration.arango.ssl.ArangoSSLConfiguration; -import io.micronaut.context.annotation.ConfigurationBuilder; import io.micronaut.context.exceptions.ConfigurationException; import io.micronaut.core.util.CollectionUtils; import io.micronaut.core.util.StringUtils; @@ -25,11 +24,6 @@ */ public abstract class AbstractArangoConfiguration { - @ConfigurationBuilder("health") - protected EnableConfiguration health = new EnableConfiguration(true); - @ConfigurationBuilder("health-cluster") - protected EnableConfiguration healthCluster = new EnableConfiguration(false); - protected final ArangoSSLConfiguration sslConfiguration; private String user = ArangoDefaults.DEFAULT_USER; @@ -51,7 +45,7 @@ public abstract class AbstractArangoConfiguration { private boolean createDatabaseAsync = false; private int createDatabaseTimeoutInMillis = 10000; - public AbstractArangoConfiguration(ArangoSSLConfiguration sslConfiguration) { + protected AbstractArangoConfiguration(ArangoSSLConfiguration sslConfiguration) { this.sslConfiguration = sslConfiguration; } @@ -309,32 +303,12 @@ public void setLoadBalancingStrategy(LoadBalancingStrategy loadBalancingStrategy this.loadBalancingStrategy = loadBalancingStrategy; } - /** - * @return health indicator configuration - */ - public EnableConfiguration getHealth() { - return health; - } - - /** - * @return cluster health indicator configuration - */ - public EnableConfiguration getHealthCluster() { - return healthCluster; - } - public ArangoSSLConfiguration getSslConfiguration() { return sslConfiguration; } @Override public String toString() { - return "AbstractArangoConfiguration{" + - "user='" + user + '\'' + - ", host='" + host + '\'' + - ", port=" + port + - ", database='" + database + '\'' + - ", createDatabaseIfNotExist=" + createDatabaseIfNotExist + - '}'; + return getProperties().toString(); } } diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java new file mode 100644 index 0000000..6b61142 --- /dev/null +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java @@ -0,0 +1,54 @@ +package io.micronaut.configuration.arango.health; + +import io.micronaut.configuration.arango.ArangoSettings; +import io.micronaut.context.annotation.ConfigurationProperties; +import io.micronaut.context.annotation.Requires; +import io.micronaut.context.exceptions.ConfigurationException; + +/** + * @author Anton Kurako (GoodforGod) + * @since 13.08.2021 + */ +@Requires(property = ArangoSettings.PREFIX) +@ConfigurationProperties(ArangoSettings.PREFIX + ".health-cluster") +public class ArangoClusterHealthConfiguration { + + private boolean enabled = true; + private long timeoutInMillis = 5000; + private int retry = 2; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public long getTimeoutInMillis() { + return timeoutInMillis; + } + + public void setTimeoutInMillis(long timeoutInMillis) { + if (timeoutInMillis < 0) + throw new ConfigurationException("Timeout for health can not be less than 0"); + this.timeoutInMillis = timeoutInMillis; + } + + public int getRetry() { + return retry; + } + + public void setRetry(int retry) { + if (retry < 1) + throw new ConfigurationException("Retry for health can not be less than 1"); + this.retry = retry; + } + + @Override + public String toString() { + return "[enabled=" + enabled + + ", timeoutInMillis=" + timeoutInMillis + + ", retry=" + retry + ']'; + } +} diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthIndicator.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthIndicator.java index eb1a279..1d2918f 100644 --- a/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthIndicator.java +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthIndicator.java @@ -46,19 +46,24 @@ public class ArangoClusterHealthIndicator implements HealthIndicator { private final ArangoDB accessor; private final ObjectMapper mapper; private final String database; + private final ArangoClusterHealthConfiguration healthConfiguration; @Inject - public ArangoClusterHealthIndicator(ArangoDB accessor, ArangoConfiguration configuration, ObjectMapper mapper) { + public ArangoClusterHealthIndicator(ArangoDB accessor, + ArangoConfiguration configuration, + ObjectMapper mapper, + ArangoClusterHealthConfiguration healthConfiguration) { this.accessor = accessor; this.mapper = mapper; this.database = configuration.getDatabase(); + this.healthConfiguration = healthConfiguration; } @Override public Flowable getResult() { return Flowable.fromCallable(() -> accessor.db(database).route("/_admin/cluster/health").get()) - .timeout(20000, TimeUnit.MILLISECONDS) - .retry(2) + .timeout(healthConfiguration.getTimeoutInMillis(), TimeUnit.MILLISECONDS) + .retry(healthConfiguration.getRetry()) .map(this::buildReport) .onErrorReturn(this::buildErrorReport); } diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java new file mode 100644 index 0000000..31a5615 --- /dev/null +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java @@ -0,0 +1,54 @@ +package io.micronaut.configuration.arango.health; + +import io.micronaut.configuration.arango.ArangoSettings; +import io.micronaut.context.annotation.ConfigurationProperties; +import io.micronaut.context.annotation.Requires; +import io.micronaut.context.exceptions.ConfigurationException; + +/** + * @author Anton Kurako (GoodforGod) + * @since 13.08.2021 + */ +@Requires(property = ArangoSettings.PREFIX) +@ConfigurationProperties(ArangoSettings.PREFIX + ".health") +public class ArangoHealthConfiguration { + + private boolean enabled = true; + private long timeoutInMillis = 5000; + private int retry = 2; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public long getTimeoutInMillis() { + return timeoutInMillis; + } + + public void setTimeoutInMillis(long timeoutInMillis) { + if (timeoutInMillis < 0) + throw new ConfigurationException("Timeout for health can not be less than 0"); + this.timeoutInMillis = timeoutInMillis; + } + + public int getRetry() { + return retry; + } + + public void setRetry(int retry) { + if (retry < 1) + throw new ConfigurationException("Retry for health can not be less than 1"); + this.retry = retry; + } + + @Override + public String toString() { + return "[enabled=" + enabled + + ", timeoutInMillis=" + timeoutInMillis + + ", retry=" + retry + ']'; + } +} diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthIndicator.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthIndicator.java index 56098de..10d8fa2 100644 --- a/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthIndicator.java +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthIndicator.java @@ -38,18 +38,22 @@ public class ArangoHealthIndicator implements HealthIndicator { private static final String NAME = "arangodb"; private final ArangoDB accessor; private final String database; + private final ArangoHealthConfiguration healthConfiguration; @Inject - public ArangoHealthIndicator(ArangoDB accessor, ArangoConfiguration configuration) { + public ArangoHealthIndicator(ArangoDB accessor, + ArangoConfiguration configuration, + ArangoHealthConfiguration healthConfiguration) { this.accessor = accessor; this.database = configuration.getDatabase(); + this.healthConfiguration = healthConfiguration; } @Override public Flowable getResult() { return Flowable.fromCallable(() -> accessor.db(database).getInfo()) - .timeout(20000, TimeUnit.MILLISECONDS) - .retry(2) + .timeout(healthConfiguration.getTimeoutInMillis(), TimeUnit.MILLISECONDS) + .retry(healthConfiguration.getRetry()) .map(this::buildUpReport) .onErrorReturn(this::buildDownReport); } diff --git a/src/main/java/io/micronaut/configuration/arango/ssl/ArangoSSLCertificateConfiguration.java b/src/main/java/io/micronaut/configuration/arango/ssl/ArangoSSLCertificateConfiguration.java index 85ecd23..98969a3 100644 --- a/src/main/java/io/micronaut/configuration/arango/ssl/ArangoSSLCertificateConfiguration.java +++ b/src/main/java/io/micronaut/configuration/arango/ssl/ArangoSSLCertificateConfiguration.java @@ -110,4 +110,15 @@ public String getProtocol() { public void setProtocol(String protocol) { this.protocol = protocol; } + + @Override + public String toString() { + return "[enabled=" + enabled + + ", type=" + type + + ", algorithm=" + algorithm + + ", keyStore=" + keyStore + + ", value=" + value + + ", alias=" + alias + + ", protocol=" + protocol + ']'; + } } diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoAsyncConfigurationAuthTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoAsyncConfigurationAuthTests.java index bf81b96..f37d5ad 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoAsyncConfigurationAuthTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoAsyncConfigurationAuthTests.java @@ -47,12 +47,7 @@ void createConnectionSuccessWithCorrectAuth() { properties.put("arangodb.password", PASS); try (final ApplicationContext context = ApplicationContext.run(properties)) { - final ArangoAsyncConfiguration configuration = context.getBean(ArangoAsyncConfiguration.class); final ArangoDBAsync accessor = context.getBean(ArangoDBAsync.class); - assertNotNull(configuration.getHealth()); - assertTrue(configuration.getHealth().isEnabled()); - assertNotNull(configuration.getHealthCluster()); - assertFalse(configuration.getHealthCluster().isEnabled()); final DatabaseEntity entity = accessor.db(ArangoSettings.SYSTEM_DATABASE).getInfo().join(); assertNotNull(entity); } diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationAuthTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationAuthTests.java index 96253c7..3aca38d 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationAuthTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationAuthTests.java @@ -54,11 +54,6 @@ void createConnectionSuccessWithCorrectAuth() { final ArangoConfiguration configuration = context.getBean(ArangoConfiguration.class); final ArangoDB accessor = context.getBean(ArangoDB.class); - assertNotNull(configuration.getHealth()); - assertTrue(configuration.getHealth().isEnabled()); - assertNotNull(configuration.getHealthCluster()); - assertFalse(configuration.getHealthCluster().isEnabled()); - final DatabaseEntity entity = accessor.db(ArangoSettings.SYSTEM_DATABASE).getInfo(); assertNotNull(entity); @@ -69,6 +64,7 @@ void createConnectionSuccessWithCorrectAuth() { configuration.setConnectionTtl(10000L); configuration.setHosts(List.of("localhost:8080", "localhost:8081")); configuration.setHost("localhost"); + final Properties configurationProperties = configuration.getProperties(); assertNotNull(configurationProperties.getProperty(ArangoProperties.HOSTS)); assertNotNull(configuration.toString()); diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java index a337107..1730e2a 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java @@ -1,5 +1,6 @@ package io.micronaut.configuration.arango; +import io.micronaut.configuration.arango.health.ArangoHealthConfiguration; import io.micronaut.context.ApplicationContext; import io.testcontainers.arangodb.containers.ArangoContainer; import org.junit.jupiter.api.Order; @@ -43,6 +44,13 @@ void createConnectionWithCreateDatabaseIfNotExistOnStartup() { final ArangoClient client = context.getBean(ArangoClient.class); assertEquals("custom", client.database()); + final ArangoHealthConfiguration healthConfiguration = context.getBean(ArangoHealthConfiguration.class); + assertNotNull(healthConfiguration); + assertNotNull(healthConfiguration.toString()); + assertEquals(10000, healthConfiguration.getTimeoutInMillis()); + assertEquals(2, healthConfiguration.getRetry()); + assertTrue(healthConfiguration.isEnabled()); + final boolean databaseCreated = client.db().exists(); assertTrue(databaseCreated); } diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoSSLContextTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoSSLContextTests.java index dc39cf9..3975253 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoSSLContextTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoSSLContextTests.java @@ -33,9 +33,16 @@ void sslContextBuilded() { try (final ApplicationContext context = ApplicationContext.run(properties)) { final ArangoSSLConfiguration sslConfiguration = context.getBean(ArangoSSLConfiguration.class); + assertNotNull(sslConfiguration); + assertNotNull(sslConfiguration.toString()); + + assertNotNull(sslConfiguration.getCertificateConfiguration()); + assertNotNull(sslConfiguration.getCertificateConfiguration().toString()); + final DefaultSSLContextProvider sslContextProvider = context.getBean(DefaultSSLContextProvider.class); final SSLContext sslContext = sslContextProvider.get(sslConfiguration); assertNotNull(sslContext); + assertNotNull(sslContext.toString()); } } diff --git a/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java b/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java index f7da3af..c19a53e 100644 --- a/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java +++ b/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java @@ -113,6 +113,13 @@ void healthClusterUpForCustomDatabase() { properties.put("arangodb.health-cluster.enabled", true); try (final ApplicationContext context = ApplicationContext.run(properties)) { + final ArangoClusterHealthConfiguration healthConfiguration = context.getBean(ArangoClusterHealthConfiguration.class); + assertNotNull(healthConfiguration); + assertNotNull(healthConfiguration.toString()); + assertEquals(10000, healthConfiguration.getTimeoutInMillis()); + assertEquals(2, healthConfiguration.getRetry()); + assertTrue(healthConfiguration.isEnabled()); + final ArangoClusterHealthIndicator clusterHealthIndicator = context.getBean(ArangoClusterHealthIndicator.class); final HealthResult result = Single.fromPublisher(clusterHealthIndicator.getResult()) From a7e42e61735a4ed89d3d6e041944996b8e73c898 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 16 Aug 2021 18:43:51 +0300 Subject: [PATCH 3/6] [2.3.0] 2.3.0 prepared README.md updated --- README.md | 8 ++++++-- gradle.properties | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bc8919e..21cea81 100644 --- a/README.md +++ b/README.md @@ -220,7 +220,9 @@ You can explicitly *turn off* health check. ```yaml arangodb: health: - enabled: false # default - true + enabled: false # default - true + timeout-in-millis: 5000 # default - 5000 + retry: 2 # default - 2 ``` #### Cluster Health Check @@ -290,7 +292,9 @@ You can turn on Cluster Health Check via configuration: ```yaml arangodb: health-cluster: - enabled: true # default - false + enabled: true # default - false + timeout-in-millis: 5000 # default - 5000 + retry: 2 # default - 2 ``` ## Testing diff --git a/gradle.properties b/gradle.properties index 2a846de..7db8c21 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ groupId=com.github.goodforgod artifactId=micronaut-arangodb -artifactVersion=2.3.0-SNAPSHOT +artifactVersion=2.3.0 ##### GRADLE From 8093fd789677fea8d0cffbfd8441c492cf6f2459 Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 16 Aug 2021 18:46:57 +0300 Subject: [PATCH 4/6] [2.3.0] README.md version updated --- README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 21cea81..a90a183 100644 --- a/README.md +++ b/README.md @@ -9,16 +9,10 @@ This project includes integration between Micronaut and ArangoDB. ## Dependency :rocket: -Starting from version *2.0.0* library ships for *Micronaut 2*. - -Starting from version *2.1.0* Java 11+ is required (previous version 1.8+ compatible). - -Last release for **Micronaut 1** is [version *1.2.1*](https://github.com/GoodforGod/micronaut-arangodb/releases/tag/v1.2.1). - **Gradle** ```groovy dependencies { - compile 'com.github.goodforgod:micronaut-arangodb:2.2.1' + compile 'com.github.goodforgod:micronaut-arangodb:2.3.0' } ``` @@ -27,7 +21,7 @@ dependencies { com.github.goodforgod micronaut-arangodb - 2.2.1 + 2.3.0 ``` @@ -305,6 +299,14 @@ For testing purposes it is recommended to use [ArangoDB TestContainer library](h TestContainers allows you to use integration tests against real database in all docker friendly environments, check here for [TestContainers](https://www.testcontainers.org/). +## Micronaut Compatability + +Starting from version *2.0.0* library ships for *Micronaut 2*. + +Starting from version *2.1.0* Java 11+ is required (previous version 1.8+ compatible). + +Last release for **Micronaut 1** is [version *1.2.1*](https://github.com/GoodforGod/micronaut-arangodb/releases/tag/v1.2.1). + ## License This project licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. From 72ea77e1dac590905cb9399e32a58f3bb825848a Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 16 Aug 2021 18:50:49 +0300 Subject: [PATCH 5/6] [2.3.0] Test fixed --- .../configuration/arango/ArangoConfigurationTests.java | 2 +- .../configuration/arango/health/ArangoHealthUpClusterTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java index 1730e2a..b31713a 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java @@ -47,7 +47,7 @@ void createConnectionWithCreateDatabaseIfNotExistOnStartup() { final ArangoHealthConfiguration healthConfiguration = context.getBean(ArangoHealthConfiguration.class); assertNotNull(healthConfiguration); assertNotNull(healthConfiguration.toString()); - assertEquals(10000, healthConfiguration.getTimeoutInMillis()); + assertEquals(5000, healthConfiguration.getTimeoutInMillis()); assertEquals(2, healthConfiguration.getRetry()); assertTrue(healthConfiguration.isEnabled()); diff --git a/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java b/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java index c19a53e..04df92d 100644 --- a/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java +++ b/src/test/java/io/micronaut/configuration/arango/health/ArangoHealthUpClusterTests.java @@ -116,7 +116,7 @@ void healthClusterUpForCustomDatabase() { final ArangoClusterHealthConfiguration healthConfiguration = context.getBean(ArangoClusterHealthConfiguration.class); assertNotNull(healthConfiguration); assertNotNull(healthConfiguration.toString()); - assertEquals(10000, healthConfiguration.getTimeoutInMillis()); + assertEquals(5000, healthConfiguration.getTimeoutInMillis()); assertEquals(2, healthConfiguration.getRetry()); assertTrue(healthConfiguration.isEnabled()); From bcd1dee481d555307a9e7ce8c82e9b0274b57bcb Mon Sep 17 00:00:00 2001 From: Anton Kurako Date: Mon, 16 Aug 2021 18:58:57 +0300 Subject: [PATCH 6/6] [2.3.0] AbstractHealthConfiguration introduced to simplify same configs ArangoConfigurationTests improved --- .../health/AbstractHealthConfiguration.java | 49 +++++++++++++++++++ .../ArangoClusterHealthConfiguration.java | 41 +--------------- .../health/ArangoHealthConfiguration.java | 41 +--------------- .../arango/ArangoConfigurationTests.java | 32 ++++++++++++ 4 files changed, 83 insertions(+), 80 deletions(-) create mode 100644 src/main/java/io/micronaut/configuration/arango/health/AbstractHealthConfiguration.java diff --git a/src/main/java/io/micronaut/configuration/arango/health/AbstractHealthConfiguration.java b/src/main/java/io/micronaut/configuration/arango/health/AbstractHealthConfiguration.java new file mode 100644 index 0000000..df94d8d --- /dev/null +++ b/src/main/java/io/micronaut/configuration/arango/health/AbstractHealthConfiguration.java @@ -0,0 +1,49 @@ +package io.micronaut.configuration.arango.health; + +import io.micronaut.context.exceptions.ConfigurationException; + +/** + * @author Anton Kurako (GoodforGod) + * @since 13.08.2021 + */ +public abstract class AbstractHealthConfiguration { + + private boolean enabled = true; + private long timeoutInMillis = 5000; + private int retry = 2; + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public long getTimeoutInMillis() { + return timeoutInMillis; + } + + public void setTimeoutInMillis(long timeoutInMillis) { + if (timeoutInMillis < 0) + throw new ConfigurationException("Timeout for health can not be less than 0"); + this.timeoutInMillis = timeoutInMillis; + } + + public int getRetry() { + return retry; + } + + public void setRetry(int retry) { + if (retry < 1) + throw new ConfigurationException("Retry for health can not be less than 1"); + this.retry = retry; + } + + @Override + public String toString() { + return "[enabled=" + enabled + + ", timeoutInMillis=" + timeoutInMillis + + ", retry=" + retry + ']'; + } +} diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java index 6b61142..db49332 100644 --- a/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoClusterHealthConfiguration.java @@ -3,7 +3,6 @@ import io.micronaut.configuration.arango.ArangoSettings; import io.micronaut.context.annotation.ConfigurationProperties; import io.micronaut.context.annotation.Requires; -import io.micronaut.context.exceptions.ConfigurationException; /** * @author Anton Kurako (GoodforGod) @@ -11,44 +10,6 @@ */ @Requires(property = ArangoSettings.PREFIX) @ConfigurationProperties(ArangoSettings.PREFIX + ".health-cluster") -public class ArangoClusterHealthConfiguration { +public class ArangoClusterHealthConfiguration extends AbstractHealthConfiguration { - private boolean enabled = true; - private long timeoutInMillis = 5000; - private int retry = 2; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public long getTimeoutInMillis() { - return timeoutInMillis; - } - - public void setTimeoutInMillis(long timeoutInMillis) { - if (timeoutInMillis < 0) - throw new ConfigurationException("Timeout for health can not be less than 0"); - this.timeoutInMillis = timeoutInMillis; - } - - public int getRetry() { - return retry; - } - - public void setRetry(int retry) { - if (retry < 1) - throw new ConfigurationException("Retry for health can not be less than 1"); - this.retry = retry; - } - - @Override - public String toString() { - return "[enabled=" + enabled + - ", timeoutInMillis=" + timeoutInMillis + - ", retry=" + retry + ']'; - } } diff --git a/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java index 31a5615..366ca36 100644 --- a/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java +++ b/src/main/java/io/micronaut/configuration/arango/health/ArangoHealthConfiguration.java @@ -3,7 +3,6 @@ import io.micronaut.configuration.arango.ArangoSettings; import io.micronaut.context.annotation.ConfigurationProperties; import io.micronaut.context.annotation.Requires; -import io.micronaut.context.exceptions.ConfigurationException; /** * @author Anton Kurako (GoodforGod) @@ -11,44 +10,6 @@ */ @Requires(property = ArangoSettings.PREFIX) @ConfigurationProperties(ArangoSettings.PREFIX + ".health") -public class ArangoHealthConfiguration { +public class ArangoHealthConfiguration extends AbstractHealthConfiguration { - private boolean enabled = true; - private long timeoutInMillis = 5000; - private int retry = 2; - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public long getTimeoutInMillis() { - return timeoutInMillis; - } - - public void setTimeoutInMillis(long timeoutInMillis) { - if (timeoutInMillis < 0) - throw new ConfigurationException("Timeout for health can not be less than 0"); - this.timeoutInMillis = timeoutInMillis; - } - - public int getRetry() { - return retry; - } - - public void setRetry(int retry) { - if (retry < 1) - throw new ConfigurationException("Retry for health can not be less than 1"); - this.retry = retry; - } - - @Override - public String toString() { - return "[enabled=" + enabled + - ", timeoutInMillis=" + timeoutInMillis + - ", retry=" + retry + ']'; - } } diff --git a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java index b31713a..1f71d6b 100644 --- a/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java +++ b/src/test/java/io/micronaut/configuration/arango/ArangoConfigurationTests.java @@ -2,6 +2,7 @@ import io.micronaut.configuration.arango.health.ArangoHealthConfiguration; import io.micronaut.context.ApplicationContext; +import io.micronaut.context.exceptions.ConfigurationException; import io.testcontainers.arangodb.containers.ArangoContainer; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -55,4 +56,35 @@ void createConnectionWithCreateDatabaseIfNotExistOnStartup() { assertTrue(databaseCreated); } } + + @Test + void healthConfigurationBuilded() { + final ArangoHealthConfiguration healthConfiguration = new ArangoHealthConfiguration(); + healthConfiguration.setRetry(2); + healthConfiguration.setTimeoutInMillis(1000); + assertEquals(2, healthConfiguration.getRetry()); + assertEquals(1000, healthConfiguration.getTimeoutInMillis()); + } + + @Test + void healthConfigurationRetryFail() { + try { + final ArangoHealthConfiguration healthConfiguration = new ArangoHealthConfiguration(); + healthConfiguration.setRetry(-1); + fail("Should not happen!"); + } catch (Exception e) { + assertTrue(e instanceof ConfigurationException); + } + } + + @Test + void healthConfigurationTimeoutFail() { + try { + final ArangoHealthConfiguration healthConfiguration = new ArangoHealthConfiguration(); + healthConfiguration.setTimeoutInMillis(-1); + fail("Should not happen!"); + } catch (Exception e) { + assertTrue(e instanceof ConfigurationException); + } + } }