Skip to content

Commit

Permalink
Merge pull request #310 from wultra/develop
Browse files Browse the repository at this point in the history
Merge develop to master
  • Loading branch information
banterCZ authored Jul 26, 2024
2 parents f260f1b + 6eaf339 commit ff06131
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 35 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "github-actions"
# Workflow files stored in the default location of `.github/workflows`. (You don't need to specify `/.github/workflows` for `directory`. You can use `directory: "/"`.)
directory: "/"
schedule:
interval: "weekly"
6 changes: 2 additions & 4 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ on:
workflow_dispatch:
push:
branches: [ 'develop', 'master', 'releases/**' ]
pull_request:
# The branches below must be a subset of the branches above
branches: [ 'develop', 'master', 'releases/**' ]
schedule:
- cron: '0 2 * * 4'

Expand All @@ -19,4 +16,5 @@ jobs:
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
# Use only 'java' to analyze code written in Java, Kotlin or both
# Use only 'javascript' to analyze code written in JavaScript, TypeScript or both
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
java_version: 21
2 changes: 2 additions & 0 deletions .github/workflows/maven-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
with:
environment: internal-publish
release_type: snapshot
java_version: 21
secrets:
username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
Expand All @@ -45,6 +46,7 @@ jobs:
with:
environment: ${{ inputs.environment }}
release_type: ${{ inputs.release_type }}
java_version: 21
secrets:
username: ${{ secrets.MAVEN_CENTRAL_USERNAME }}
password: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/maven-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ on:

jobs:
maven-tests:
uses: wultra/wultra-infrastructure/.github/workflows/maven-test.yml@develop
uses: wultra/wultra-infrastructure/.github/workflows/maven-test.yml@develop
with:
java_version: 21
45 changes: 45 additions & 0 deletions .github/workflows/maven-update-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Update version with Maven
# - validate that there is no dependency on snapshot
# - update version to non-snapshot
# - commit and tag
# - update version to snapshot
# - push changes

on:
workflow_dispatch:
inputs:
update_type:
description: Update type
required: true
type: choice
options:
# `major` not yet supported
- minor
- bugfix

jobs:
update-version:
name: Update version
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'temurin'
cache: maven
- name: Run Maven release:prepare
run: |
echo ${{ inputs.update_type }}
if [ ${{ inputs.update_type }} == "minor" ]; then
mvn -B -U -DdryRun=true release:prepare -DtagNameFormat=@{project.version} -DprojectVersionPolicyId=SemVerVersionPolicy
elif [ ${{ inputs.update_type }} == "bugfix" ]; then
mvn -B -U -DdryRun=true release:prepare -DtagNameFormat=@{project.version}
else
echo "Not supported type: ${{ inputs.update_type }}"
exit 1
fi
2 changes: 1 addition & 1 deletion annotations/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>

<artifactId>annotations</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion audit-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>

<artifactId>audit-base</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.springframework.jdbc.core.PreparedStatementCallback;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.support.TransactionTemplate;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -159,6 +160,7 @@ public void flush() {
}

synchronized (FLUSH_LOCK) {
transactionTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
transactionTemplate.executeWithoutResult(status -> {
while (!queue.isEmpty()) {
try {
Expand Down Expand Up @@ -258,11 +260,11 @@ public void cleanup() {
final LocalDateTime cleanupLimit = LocalDateTime.now().minusDays(cleanupDays);
synchronized (CLEANUP_LOCK) {
transactionTemplate.executeWithoutResult(status -> {
jdbcTemplate.execute("DELETE FROM " + tableNameAudit + " WHERE timestamp_created < ?", (PreparedStatementCallback<Boolean>) ps -> {
jdbcTemplate.execute("DELETE FROM " + tableNameParam + " WHERE timestamp_created < ?", (PreparedStatementCallback<Boolean>) ps -> {
ps.setTimestamp(1, Timestamp.valueOf(cleanupLimit));
return ps.execute();
});
jdbcTemplate.execute("DELETE FROM " + tableNameParam + " WHERE timestamp_created < ?", (PreparedStatementCallback<Boolean>) ps -> {
jdbcTemplate.execute("DELETE FROM " + tableNameAudit + " WHERE timestamp_created < ?", (PreparedStatementCallback<Boolean>) ps -> {
ps.setTimestamp(1, Timestamp.valueOf(cleanupLimit));
return ps.execute();
});
Expand All @@ -274,7 +276,7 @@ public void cleanup() {
/**
* Scheduled flush of persistence of audit data.
*/
@Scheduled(fixedDelayString = "${audit.flush.delay.fixed:1000}", initialDelayString = "${powerauth.audit.flush.delay.initial:1000}")
@Scheduled(fixedDelayString = "${audit.flush.delay.fixed:1000}", initialDelayString = "${audit.flush.delay.initial:1000}")
public void scheduledFlush() {
logger.debug("Scheduled audit log flush called");
flush();
Expand All @@ -283,7 +285,7 @@ public void scheduledFlush() {
/**
* Scheduled cleanup of audit data in database.
*/
@Scheduled(fixedDelayString = "${audit.cleanup.delay.fixed:3600000}", initialDelayString = "${powerauth.audit.cleanup.delay.initial:1000}")
@Scheduled(fixedDelayString = "${audit.cleanup.delay.fixed:3600000}", initialDelayString = "${audit.cleanup.delay.initial:1000}")
public void scheduledCleanup() {
logger.debug("Scheduled audit log cleanup called");
cleanup();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(classes = TestApplication.class, properties = {"audit.db.table.param.enabled=true"})
@SpringBootTest(classes = TestApplication.class, properties = {
"audit.db.table.param.enabled=true",
"audit.db.cleanup.days=-1", // time shift to the future to enable cleanup test
"audit.cleanup.delay.initial=60000" // delay the job start due to slow builds
})
@Sql(scripts = "/db_schema.sql")
class AuditParamEnabledTest {

Expand Down Expand Up @@ -122,4 +126,33 @@ void testAuditMoreParams() {
assertEquals(new JsonUtil().serializeObject(timestamp), rs3.getString("param_value"));
}

@Test
void testAuditCleanup() {
final Audit audit = auditFactory.getAudit();
audit.info("test message", AuditDetail.builder().param("my_id", "test_id").build());
audit.flush();

assertEquals(1, countAuditLogs());
assertEquals(1, countAuditParams());

audit.cleanup();

assertEquals(0, countAuditLogs());
assertEquals(0, countAuditParams());
}

private int countAuditLogs() {
return count("audit_log");
}

private int countAuditParams() {
return count("audit_param");
}

private int count(final String tableName) {
final SqlRowSet rs = jdbcTemplate.queryForRowSet("SELECT COUNT(*) FROM " + tableName);
assertTrue(rs.next());
return rs.getInt(1);
}

}
12 changes: 12 additions & 0 deletions audit-base/src/test/java/com/wultra/core/audit/base/AuditTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.wultra.core.audit.base.model.AuditDetail;
import com.wultra.core.audit.base.model.AuditLevel;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -26,6 +27,7 @@
import org.springframework.test.context.jdbc.Sql;

import java.sql.Timestamp;
import java.time.Duration;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -219,4 +221,14 @@ void testAuditTrace() {
assertTrue(rs.next());
assertEquals(0, rs.getInt(1));
}

@Test
void testScheduledFlush() {
Audit audit = auditFactory.getAudit();
audit.info("test message");

Awaitility.await()
.atMost(Duration.ofSeconds(5))
.until(() -> jdbcTemplate.queryForRowSet("SELECT * FROM audit_log").next());
}
}
2 changes: 2 additions & 0 deletions audit-base/src/test/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# Audit configuration
spring.application.name=test-application

spring.datasource.hikari.auto-commit=false
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>

<artifactId>core-bom</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion http-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>

<artifactId>http-common</artifactId>
Expand Down
17 changes: 9 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<description>Wultra - Core Java Libraries</description>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
<packaging>pom</packaging>

<inceptionYear>2017</inceptionYear>
Expand Down Expand Up @@ -56,12 +56,12 @@
<java.version>17</java.version>
<maven.compiler.release>${java.version}</maven.compiler.release>

<maven-compiler-plugin.version>3.12.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>3.3.1</maven-surefire-plugin.version>
<maven-enforcer-plugin.version>3.5.0</maven-enforcer-plugin.version>

<!-- Dependencies -->
<spring-boot.version>3.2.3</spring-boot.version>
<findbugs-annotations.version>3.0.1</findbugs-annotations.version>
<spring-boot.version>3.3.2</spring-boot.version>
</properties>

<dependencyManagement>
Expand Down Expand Up @@ -105,7 +105,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.3.0</version>
<version>3.3.1</version>
<executions>
<execution>
<id>attach-sources</id>
Expand All @@ -119,7 +119,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.6.3</version>
<version>3.8.0</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
Expand All @@ -135,11 +135,12 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.1</version>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>${maven-enforcer-plugin.version}</version>
<executions>
<execution>
<id>enforce-banned-dependencies</id>
Expand Down
7 changes: 1 addition & 6 deletions rest-client-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.getlime.core</groupId>
<artifactId>lime-java-core-parent</artifactId>
<version>1.9.0</version>
<version>1.10.0</version>
</parent>

<artifactId>rest-client-base</artifactId>
Expand All @@ -19,11 +19,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>${findbugs-annotations.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ public class DefaultRestClient implements RestClient {

private static final Logger logger = LoggerFactory.getLogger(DefaultRestClient.class);

/**
* Default max connections.
* As same value as in {@link reactor.netty.tcp.TcpResources#get()} avoid default to {@code 2 * available number of processors} only.
*/
private static final int DEFAULT_POOL_MAX_CONNECTIONS = 500;

private WebClient webClient;
private final RestClientConfiguration config;
private final Collection<Module> modules;
Expand Down Expand Up @@ -240,26 +246,27 @@ private static HttpClient configureKeepAlive(final HttpClient httpClient, final
}

/**
* Create HttpClient with default HttpConnectionProvider or custom one, if specified in the given config.
* @param config Config to create connection provider if specified.
* Create HttpClient with custom ConnectionProvider with options specified in the given config.
* @param config Config to create connection provider.
* @return Http client.
*/
private static HttpClient createHttpClient(final RestClientConfiguration config) {
final ConnectionProvider.Builder providerBuilder = ConnectionProvider.builder("custom")
.maxConnections(DEFAULT_POOL_MAX_CONNECTIONS)
.pendingAcquireTimeout(Duration.ofMillis(ConnectionProvider.DEFAULT_POOL_ACQUIRE_TIMEOUT));

final Duration maxIdleTime = config.getMaxIdleTime();
final Duration maxLifeTime = config.getMaxLifeTime();
if (maxIdleTime != null || maxLifeTime != null) {
logger.info("Configuring custom connection provider, maxIdleTime={}, maxLifeTime={}", maxIdleTime, maxLifeTime);
final ConnectionProvider.Builder providerBuilder = ConnectionProvider.builder("custom");
if (maxIdleTime != null) {
providerBuilder.maxIdleTime(maxIdleTime);
}
if (maxLifeTime != null) {
providerBuilder.maxLifeTime(maxLifeTime);
}
return HttpClient.create(providerBuilder.build());
} else {
return HttpClient.create();
}
return HttpClient.create(providerBuilder.build());
}

private static Optional<ObjectMapper> createObjectMapper(final RestClientConfiguration config, Collection<Module> modules) {
Expand Down
Loading

0 comments on commit ff06131

Please sign in to comment.