chore: remove autocommit, fix compilation
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

pull/3/head
Davide Polonio 2023-04-20 11:10:26 +02:00
parent b2a2f04ba3
commit d32915cf3f
6 changed files with 33 additions and 32 deletions

View File

@ -3,6 +3,10 @@
db.url = "jdbc:postgresql://localhost:5433/example" db.url = "jdbc:postgresql://localhost:5433/example"
db.user = example db.user = example
db.password = example db.password = example
hikari.autoCommit = false
hikari.maximumPoolSize = 4
telegram.key = akey telegram.key = akey
application.lang = en en-US it it-IT application.lang = en en-US it it-IT

View File

@ -6,10 +6,8 @@ import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import io.jooby.Jooby; import io.jooby.Jooby;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton; import javax.inject.Singleton;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger; import org.slf4j.Logger;
public class AppDI extends AbstractModule { public class AppDI extends AbstractModule {
@ -37,9 +35,7 @@ public class AppDI extends AbstractModule {
@Provides @Provides
@Singleton @Singleton
@Named("services") @Named("services")
public List<Service> getApplicationServices( public List<Service> getApplicationServices(BatchBeanCleanerService batchBeanCleanerService) {
Logger logger, return List.of(batchBeanCleanerService);
@Named("serviceRunningCheckTime") Pair<Integer, TimeUnit> serviceRunningCheckTime) {
return List.of(new BatchBeanCleanerService(logger, serviceRunningCheckTime));
} }
} }

View File

@ -2,6 +2,7 @@ package com.github.polpetta.mezzotre.orm;
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext; import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
import com.github.polpetta.mezzotre.orm.model.query.QCallbackQueryContext; import com.github.polpetta.mezzotre.orm.model.query.QCallbackQueryContext;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import io.ebean.typequery.PString; import io.ebean.typequery.PString;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -44,6 +45,7 @@ public class CallbackQueryContextCleaner {
* been deleted from the persistence layer * been deleted from the persistence layer
* @see CallbackQueryContext#getEntryGroup() * @see CallbackQueryContext#getEntryGroup()
*/ */
@CanIgnoreReturnValue
public CompletableFuture<Integer> removeGroupAsync(String id) { public CompletableFuture<Integer> removeGroupAsync(String id) {
log.trace("CallbackQueryContext entry group " + id + " queued for removal"); log.trace("CallbackQueryContext entry group " + id + " queued for removal");
return batchBeanCleanerService.removeAsync(id, ENTRY_GROUP.get()); return batchBeanCleanerService.removeAsync(id, ENTRY_GROUP.get());
@ -57,6 +59,7 @@ public class CallbackQueryContextCleaner {
* been deleted from the persistence layer. Can be 0 or 1. * been deleted from the persistence layer. Can be 0 or 1.
* @see CallbackQueryContext#getId() * @see CallbackQueryContext#getId()
*/ */
@CanIgnoreReturnValue
public CompletableFuture<Integer> removeIdAsync(String id) { public CompletableFuture<Integer> removeIdAsync(String id) {
log.trace("CallbackQueryContext single entity " + id + " queued for removal"); log.trace("CallbackQueryContext single entity " + id + " queued for removal");
return batchBeanCleanerService.removeAsync(id, SINGLE_ENTRY.get()); return batchBeanCleanerService.removeAsync(id, SINGLE_ENTRY.get());

View File

@ -2,13 +2,13 @@ package com.github.polpetta.mezzotre.orm;
import com.google.inject.AbstractModule; import com.google.inject.AbstractModule;
import com.google.inject.Provides; import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.zaxxer.hikari.HikariConfig; import com.zaxxer.hikari.HikariConfig;
import io.jooby.Extension; import io.jooby.Extension;
import io.jooby.ebean.EbeanModule; import io.jooby.ebean.EbeanModule;
import io.jooby.flyway.FlywayModule; import io.jooby.flyway.FlywayModule;
import io.jooby.hikari.HikariModule; import io.jooby.hikari.HikariModule;
import javax.inject.Named; import javax.inject.Named;
import javax.inject.Singleton;
public class OrmDI extends AbstractModule { public class OrmDI extends AbstractModule {
/** /**

View File

@ -30,6 +30,7 @@ public class Loader {
hikariConnectionProperties.put("username", container.getUsername()); hikariConnectionProperties.put("username", container.getUsername());
hikariConnectionProperties.put("password", container.getPassword()); hikariConnectionProperties.put("password", container.getPassword());
hikariConnectionProperties.put("jdbcUrl", container.getJdbcUrl()); hikariConnectionProperties.put("jdbcUrl", container.getJdbcUrl());
hikariConnectionProperties.put("autoCommit", "false");
ebeanConnectionProperties.load(ebeanInputStream); ebeanConnectionProperties.load(ebeanInputStream);
ebeanConnectionProperties.put("datasource_db_username", container.getUsername()); ebeanConnectionProperties.put("datasource_db_username", container.getUsername());

View File

@ -1,21 +1,18 @@
package com.github.polpetta.mezzotre.orm; package com.github.polpetta.mezzotre.orm;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
import com.github.polpetta.mezzotre.helper.Loader; import com.github.polpetta.mezzotre.helper.Loader;
import com.github.polpetta.mezzotre.helper.TestConfig; import com.github.polpetta.mezzotre.helper.TestConfig;
import com.github.polpetta.mezzotre.orm.model.CallbackQueryContext;
import com.github.polpetta.mezzotre.orm.model.query.QCallbackQueryContext;
import com.github.polpetta.types.json.CallbackQueryMetadata;
import io.ebean.Database; import io.ebean.Database;
import io.ebean.typequery.PString; import java.time.Duration;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach; import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.mockito.ArgumentCaptor;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Container;
@ -33,7 +30,7 @@ class CallbackQueryContextCleanerIntegrationTest {
private Database database; private Database database;
private BatchBeanCleanerService fakeBatchBeanCleanerService; private BatchBeanCleanerService batchBeanCleanerService;
private CallbackQueryContextCleaner callbackQueryContextCleaner; private CallbackQueryContextCleaner callbackQueryContextCleaner;
@BeforeEach @BeforeEach
@ -41,41 +38,41 @@ class CallbackQueryContextCleanerIntegrationTest {
database = database =
Loader.connectToDatabase(Loader.loadDefaultEbeanConfigWithPostgresSettings(postgresServer)); Loader.connectToDatabase(Loader.loadDefaultEbeanConfigWithPostgresSettings(postgresServer));
fakeBatchBeanCleanerService = mock(BatchBeanCleanerService.class); batchBeanCleanerService =
new BatchBeanCleanerService(
LoggerFactory.getLogger(BatchBeanCleanerService.class),
Pair.of(0, TimeUnit.MILLISECONDS));
batchBeanCleanerService.startAsync().awaitRunning(Duration.ofSeconds(10));
callbackQueryContextCleaner = callbackQueryContextCleaner =
new CallbackQueryContextCleaner( new CallbackQueryContextCleaner(
fakeBatchBeanCleanerService, batchBeanCleanerService, LoggerFactory.getLogger(CallbackQueryContextCleaner.class));
LoggerFactory.getLogger(CallbackQueryContextCleaner.class)); }
@AfterEach
void tearDown() throws Exception {
batchBeanCleanerService.stopAsync().awaitTerminated(Duration.ofSeconds(10));
} }
@Test @Test
@Timeout(value = 1, unit = TimeUnit.MINUTES) @Timeout(value = 1, unit = TimeUnit.MINUTES)
void shouldDeleteByGroupId() throws Exception { void shouldDeleteByGroupId() throws Exception {
when(fakeBatchBeanCleanerService.removeAsync(eq("an id"), any())) new CallbackQueryContext("doesn't matter", "an id", new CallbackQueryMetadata()).save();
.thenReturn(CompletableFuture.completedFuture(1));
final Integer got = callbackQueryContextCleaner.removeGroupAsync("an id").get(); final Integer got = callbackQueryContextCleaner.removeGroupAsync("an id").get();
final ArgumentCaptor<PString> pStringArgumentCaptor = ArgumentCaptor.forClass(PString.class);
verify(fakeBatchBeanCleanerService, times(1))
.removeAsync(eq("an id"), pStringArgumentCaptor.capture());
assertEquals(1, got); assertEquals(1, got);
assertEquals("entryGroup", pStringArgumentCaptor.getValue().toString()); assertEquals(0, new QCallbackQueryContext().findCount());
} }
@Test @Test
@Timeout(value = 1, unit = TimeUnit.MINUTES) @Timeout(value = 1, unit = TimeUnit.MINUTES)
void shouldDeleteById() throws Exception { void shouldDeleteById() throws Exception {
when(fakeBatchBeanCleanerService.removeAsync(eq("an id"), any())) new CallbackQueryContext("an id", "doesn't matter", new CallbackQueryMetadata()).save();
.thenReturn(CompletableFuture.completedFuture(1));
final Integer got = callbackQueryContextCleaner.removeIdAsync("an id").get(); final Integer got = callbackQueryContextCleaner.removeIdAsync("an id").get();
final ArgumentCaptor<PString> pStringArgumentCaptor = ArgumentCaptor.forClass(PString.class);
verify(fakeBatchBeanCleanerService, times(1))
.removeAsync(eq("an id"), pStringArgumentCaptor.capture());
assertEquals(1, got); assertEquals(1, got);
assertEquals("id", pStringArgumentCaptor.getValue().toString()); assertEquals(0, new QCallbackQueryContext().findCount());
} }
} }