Skip to content

Commit

Permalink
Bump org.assertj:assertj-db from 2.0.2 to 3.0.0 (#935)
Browse files Browse the repository at this point in the history
Bumps [org.assertj:assertj-db](https://github.com/assertj/assertj-db)
from 2.0.2 to 3.0.0.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/assertj/assertj-db/releases">org.assertj:assertj-db's
releases</a>.</em></p>
<blockquote>
<h2>v3.0.0</h2>
<h2>:star: Improvements</h2>
<ul>
<li>Fluent construction of AssertJ-DB connection to database</li>
<li>Cacheable database schema metadata</li>
<li>Fluent database element builder ( Table, Request, Changes )</li>
</ul>
<h2>:construction: Breaking changes</h2>
<ul>
<li>Remove classes : Source, SourceWithLetterCase,
DataSourceWithLetterCase</li>
<li>Remove public constructor of classes : Table, Request, Changes</li>
</ul>
<h2>:gear: Chore</h2>
<ul>
<li>Upgrade to AssertJ Core 3.21.0</li>
<li>Upgrade GitHub actions</li>
<li>Upgrade tests dependencies</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="https://github.com/assertj/assertj-db/commit/c47219277071c8a6c320ef14d53302bddf295a68"><code>c472192</code></a>
Release assertj-db-3.0.0</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/d342a209a8c2d4e1cfc62b99a5b8a07fa4e25c84"><code>d342a20</code></a>
Bump org.hsqldb:hsqldb from 2.7.3 to 2.7.4</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/9111ddff54251aea66464a2bece4068ba08b5214"><code>9111ddf</code></a>
Bump org.apache.maven.plugins:maven-shade-plugin from 3.2.4 to
3.6.0</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/f5532a720c986197c36e524a4b6022d1fbdf624b"><code>f5532a7</code></a>
Configure dependabot to ignore major version</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/bc0cfb751e3c68dc10b29c43b968010e9601962a"><code>bc0cfb7</code></a>
Provide fluent API to build DbElement</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/e6d1dc4429d76d3f60cbfac57d27561e2c7e9ac9"><code>e6d1dc4</code></a>
Cacheable database schema metadata</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/28b7ce2d22b45224347ae7676f79d832e02dedeb"><code>28b7ce2</code></a>
Migrate SonarCloud to assertj-org</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/9756d93360b1063ea19f79a0ce4d5d4f2157667d"><code>9756d93</code></a>
Fix javadoc generation</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/c85789566a5f9cd5be35fa7a5a70a59dd32b456c"><code>c857895</code></a>
Apply assertj code style</li>
<li><a
href="https://github.com/assertj/assertj-db/commit/6250ec92bda361b8006e2039dcd6350b23f6962a"><code>6250ec9</code></a>
Bump the licence current year to 2024</li>
<li>Additional commits viewable in <a
href="https://github.com/assertj/assertj-db/compare/assertj-db-2.0.2...assertj-db-3.0.0">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=org.assertj:assertj-db&package-manager=gradle&previous-version=2.0.2&new-version=3.0.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 show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@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>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Thomas <[email protected]>
  • Loading branch information
dependabot[bot] and Rakambda authored Dec 23, 2024
1 parent 2176865 commit 1b24eee
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 51 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jetbrains-annotations-version = "26.0.1"
websocket-version = "1.6.0"
junitVersion = "5.11.4"
assertj-core-version = "3.26.3"
assertj-db-version = "2.0.2"
assertj-db-version = "3.0.0"
mockito-version = "5.14.2"
awaitility-version = "4.2.2"
json-unit-version = "4.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.rakambda.channelpointsminer.miner.database;

import com.zaxxer.hikari.HikariDataSource;
import fr.rakambda.channelpointsminer.miner.api.ws.data.message.subtype.Event;
import fr.rakambda.channelpointsminer.miner.database.converter.Converters;
import fr.rakambda.channelpointsminer.miner.database.model.prediction.OutcomeStatistic;
Expand All @@ -10,7 +9,9 @@
import org.flywaydb.core.Flyway;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.sql.DataSource;
import java.io.Closeable;
import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
Expand All @@ -27,7 +28,7 @@
@RequiredArgsConstructor
@Log4j2
public abstract class BaseDatabase implements IDatabase{
private final HikariDataSource dataSource;
private final DataSource dataSource;
private final Lock[] getOrCreatePredictionUserIdLocks = new Lock[]{
new ReentrantLock(),
new ReentrantLock(),
Expand Down Expand Up @@ -120,14 +121,14 @@ protected int getOrCreatePredictionUserId(@NotNull String username, @NotNull Str
}

try(var addUserStatement = conn.prepareStatement("""
INSERT INTO `PredictionUser`(`Username`, `ChannelID`) VALUES (?, ?) RETURNING `ID`;""")) {
INSERT INTO `PredictionUser`(`Username`, `ChannelID`) VALUES (?, ?) RETURNING `ID`;""")){
addUserStatement.setString(1, username);
addUserStatement.setString(2, channelId);
try (var generatedKeys = addUserStatement.executeQuery()) {
if (!generatedKeys.next()) {
try(var generatedKeys = addUserStatement.executeQuery()){
if(!generatedKeys.next()){
throw new SQLException("Failed to get new prediction user id");
}

var userId = generatedKeys.getInt(1);
log.debug("Added new prediction user '{}' for channel '{}' : {}", username, channelId, userId);
return userId;
Expand Down Expand Up @@ -270,8 +271,10 @@ public Collection<OutcomeStatistic> getOutcomeStatisticsForChannel(@NotNull Stri
}

@Override
public void close(){
dataSource.close();
public void close() throws IOException{
if(dataSource instanceof Closeable closeable){
closeable.close();
}
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import lombok.extern.log4j.Log4j2;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.sql.SQLException;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -155,7 +156,7 @@ private void updateBalance(@NotNull IStreamerEvent event, @NotNull Balance balan
}

@Override
public void close(){
public void close() throws IOException{
database.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import fr.rakambda.channelpointsminer.miner.api.ws.data.message.subtype.Event;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;
import java.util.Collection;
Expand All @@ -13,7 +14,7 @@ public interface IDatabase extends AutoCloseable{
void initDatabase() throws SQLException;

@Override
void close();
void close() throws IOException;

void createChannel(@NotNull String channelId, @NotNull String username) throws SQLException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package fr.rakambda.channelpointsminer.miner.database;

import com.zaxxer.hikari.HikariDataSource;
import fr.rakambda.channelpointsminer.miner.database.converter.Converters;
import org.jetbrains.annotations.NotNull;
import javax.sql.DataSource;
import java.sql.SQLException;

public class MariaDBDatabase extends BaseDatabase{
public MariaDBDatabase(HikariDataSource dataSource){
public MariaDBDatabase(DataSource dataSource){
super(dataSource);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package fr.rakambda.channelpointsminer.miner.database;

import com.zaxxer.hikari.HikariDataSource;
import javax.sql.DataSource;

public class MysqlDatabase extends MariaDBDatabase{
public MysqlDatabase(HikariDataSource dataSource){
public MysqlDatabase(DataSource dataSource){
super(dataSource);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package fr.rakambda.channelpointsminer.miner.database;

import com.zaxxer.hikari.HikariDataSource;
import fr.rakambda.channelpointsminer.miner.database.converter.Converters;
import fr.rakambda.channelpointsminer.miner.factory.TimeFactory;
import org.jetbrains.annotations.NotNull;
import javax.sql.DataSource;
import java.sql.SQLException;
import java.sql.Timestamp;

public class SQLiteDatabase extends BaseDatabase{
public SQLiteDatabase(HikariDataSource dataSource){
public SQLiteDatabase(DataSource dataSource){
super(dataSource);
}

@Override
public void initDatabase() throws SQLException{
public void initDatabase(){
applyFlyway("db/migrations/sqlite");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package fr.rakambda.channelpointsminer.miner.event;

import java.io.IOException;

public interface IEventHandler extends AutoCloseable{
void onEvent(IEvent event);

@Override
default void close(){}
default void close() throws IOException{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,58 @@
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.ThreadContext;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;

@Log4j2
@RequiredArgsConstructor
public class EventManager implements IEventManager{
@Getter(value = AccessLevel.PUBLIC, onMethod_ = {
@TestOnly,
@VisibleForTesting
})
private final Collection<IEventHandler> eventHandlers = new ConcurrentLinkedQueue<>();

private final ExecutorService handlerExecutor;

@Setter
private IMiner miner;

@Override
public void addEventHandler(@NotNull IEventHandler handler){
eventHandlers.add(handler);
}

@Override
public void onEvent(@NotNull IEvent event){
event.setMiner(miner);

var values = ThreadContext.getImmutableContext();
var messages = ThreadContext.getImmutableStack().asList();

eventHandlers.forEach(listener -> handlerExecutor.submit(() -> {
try(var ignored = LogContext.restore(values, messages)){
listener.onEvent(event);
}
}));
}

@Override
public void close(){
for(var listener : eventHandlers){
listener.close();
try{
listener.close();
}
catch(IOException e){
log.error("Failed to close event handler {}", listener, e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import java.io.IOException;
import java.sql.SQLException;
import java.time.Instant;
import java.util.List;
Expand Down Expand Up @@ -363,7 +364,7 @@ void onPredictionResultDatabaseException() throws SQLException{
}

@Test
void closeClosesDatabase(){
void closeClosesDatabase() throws IOException{
tested.close();

verify(database).close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
package fr.rakambda.channelpointsminer.miner.database;

import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import fr.rakambda.channelpointsminer.miner.api.ws.data.message.subtype.Event;
import fr.rakambda.channelpointsminer.miner.database.model.prediction.OutcomeStatistic;
import fr.rakambda.channelpointsminer.miner.factory.TimeFactory;
import org.assertj.core.api.Assertions;
import org.assertj.db.type.AssertDbConnection;
import org.assertj.db.type.AssertDbConnectionFactory;
import org.assertj.db.type.Changes;
import org.assertj.db.type.Table;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.sqlite.SQLiteDataSource;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.io.TempDir;
import java.io.IOException;
import java.nio.file.Path;
import java.sql.SQLException;
import java.time.Instant;
Expand Down Expand Up @@ -69,8 +70,8 @@ class SQLiteDatabaseTest{
private Event event;

private SQLiteDatabase tested;
private HikariDataSource dataSource;

private AssertDbConnection assertDbConnection;
private Supplier<Changes> changesBalance;
private Supplier<Changes> changesChannel;
private Supplier<Changes> changesPrediction;
Expand All @@ -79,23 +80,22 @@ class SQLiteDatabaseTest{
private Supplier<Changes> changesResolvedPrediction;

@BeforeEach
void setUp() throws SQLException{
var poolConfiguration = new HikariConfig();
poolConfiguration.setJdbcUrl("jdbc:sqlite:" + tempPath.resolve(System.currentTimeMillis() + "_test.db").toAbsolutePath());
poolConfiguration.setDriverClassName("org.sqlite.JDBC");
poolConfiguration.setMaximumPoolSize(1);
void setUp(){
var dataSource = new SQLiteDataSource();
dataSource.setUrl("jdbc:sqlite:" + tempPath.resolve(System.currentTimeMillis() + "_test.db").toAbsolutePath());

assertDbConnection = AssertDbConnectionFactory.of(dataSource).create();;

dataSource = new HikariDataSource(poolConfiguration);
tested = new SQLiteDatabase(dataSource);

tested.initDatabase();

changesBalance = () -> new Changes(new Table(dataSource, "Balance"));
changesChannel = () -> new Changes(new Table(dataSource, "Channel"));
changesPrediction = () -> new Changes(new Table(dataSource, "Prediction"));
changesPredictionUser = () -> new Changes(new Table(dataSource, "PredictionUser"));
changesUserPrediction = () -> new Changes(new Table(dataSource, "UserPrediction"));
changesResolvedPrediction = () -> new Changes(new Table(dataSource, "ResolvedPrediction"));
changesBalance = () -> assertDbConnection.changes().table("Balance").build();
changesChannel = () -> assertDbConnection.changes().table("Channel").build();
changesPrediction = () -> assertDbConnection.changes().table("Prediction").build();
changesPredictionUser = () -> assertDbConnection.changes().table("PredictionUser").build();
changesUserPrediction = () -> assertDbConnection.changes().table("UserPrediction").build();
changesResolvedPrediction = () -> assertDbConnection.changes().table("ResolvedPrediction").build();

lenient().when(event.getId()).thenReturn(EVENT_ID);
lenient().when(event.getChannelId()).thenReturn(CHANNEL_ID);
Expand All @@ -105,17 +105,17 @@ void setUp() throws SQLException{
}

@AfterEach
void tearDown(){
void tearDown() throws IOException{
tested.close();
}

@Test
void tablesAreCreated(){
assertThat(new Table(dataSource, "Balance")).exists();
assertThat(new Table(dataSource, "Channel")).exists();
assertThat(new Table(dataSource, "Prediction")).exists();
assertThat(new Table(dataSource, "PredictionUser")).exists();
assertThat(new Table(dataSource, "UserPrediction")).exists();
assertThat(assertDbConnection.table("Balance").build()).exists();
assertThat(assertDbConnection.table("Channel").build()).exists();
assertThat(assertDbConnection.table("Prediction").build()).exists();
assertThat(assertDbConnection.table("PredictionUser").build()).exists();
assertThat(assertDbConnection.table("UserPrediction").build()).exists();
}

@Test
Expand Down

0 comments on commit 1b24eee

Please sign in to comment.