chore: remove autocommit, fix compilation
This commit is contained in:
		
							parent
							
								
									b2a2f04ba3
								
							
						
					
					
						commit
						d32915cf3f
					
				@ -3,6 +3,10 @@
 | 
			
		||||
db.url = "jdbc:postgresql://localhost:5433/example"
 | 
			
		||||
db.user = example
 | 
			
		||||
db.password = example
 | 
			
		||||
 | 
			
		||||
hikari.autoCommit = false
 | 
			
		||||
hikari.maximumPoolSize = 4
 | 
			
		||||
 | 
			
		||||
telegram.key = akey
 | 
			
		||||
 | 
			
		||||
application.lang = en en-US it it-IT
 | 
			
		||||
 | 
			
		||||
@ -6,10 +6,8 @@ import com.google.inject.AbstractModule;
 | 
			
		||||
import com.google.inject.Provides;
 | 
			
		||||
import io.jooby.Jooby;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import javax.inject.Named;
 | 
			
		||||
import javax.inject.Singleton;
 | 
			
		||||
import org.apache.commons.lang3.tuple.Pair;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
 | 
			
		||||
public class AppDI extends AbstractModule {
 | 
			
		||||
@ -37,9 +35,7 @@ public class AppDI extends AbstractModule {
 | 
			
		||||
  @Provides
 | 
			
		||||
  @Singleton
 | 
			
		||||
  @Named("services")
 | 
			
		||||
  public List<Service> getApplicationServices(
 | 
			
		||||
      Logger logger,
 | 
			
		||||
      @Named("serviceRunningCheckTime") Pair<Integer, TimeUnit> serviceRunningCheckTime) {
 | 
			
		||||
    return List.of(new BatchBeanCleanerService(logger, serviceRunningCheckTime));
 | 
			
		||||
  public List<Service> getApplicationServices(BatchBeanCleanerService batchBeanCleanerService) {
 | 
			
		||||
    return List.of(batchBeanCleanerService);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -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.query.QCallbackQueryContext;
 | 
			
		||||
import com.google.errorprone.annotations.CanIgnoreReturnValue;
 | 
			
		||||
import io.ebean.typequery.PString;
 | 
			
		||||
import java.util.concurrent.CompletableFuture;
 | 
			
		||||
import java.util.function.Supplier;
 | 
			
		||||
@ -44,6 +45,7 @@ public class CallbackQueryContextCleaner {
 | 
			
		||||
   *     been deleted from the persistence layer
 | 
			
		||||
   * @see CallbackQueryContext#getEntryGroup()
 | 
			
		||||
   */
 | 
			
		||||
  @CanIgnoreReturnValue
 | 
			
		||||
  public CompletableFuture<Integer> removeGroupAsync(String id) {
 | 
			
		||||
    log.trace("CallbackQueryContext entry group " + id + " queued for removal");
 | 
			
		||||
    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.
 | 
			
		||||
   * @see CallbackQueryContext#getId()
 | 
			
		||||
   */
 | 
			
		||||
  @CanIgnoreReturnValue
 | 
			
		||||
  public CompletableFuture<Integer> removeIdAsync(String id) {
 | 
			
		||||
    log.trace("CallbackQueryContext single entity " + id + " queued for removal");
 | 
			
		||||
    return batchBeanCleanerService.removeAsync(id, SINGLE_ENTRY.get());
 | 
			
		||||
 | 
			
		||||
@ -2,13 +2,13 @@ package com.github.polpetta.mezzotre.orm;
 | 
			
		||||
 | 
			
		||||
import com.google.inject.AbstractModule;
 | 
			
		||||
import com.google.inject.Provides;
 | 
			
		||||
import com.google.inject.Singleton;
 | 
			
		||||
import com.zaxxer.hikari.HikariConfig;
 | 
			
		||||
import io.jooby.Extension;
 | 
			
		||||
import io.jooby.ebean.EbeanModule;
 | 
			
		||||
import io.jooby.flyway.FlywayModule;
 | 
			
		||||
import io.jooby.hikari.HikariModule;
 | 
			
		||||
import javax.inject.Named;
 | 
			
		||||
import javax.inject.Singleton;
 | 
			
		||||
 | 
			
		||||
public class OrmDI extends AbstractModule {
 | 
			
		||||
  /**
 | 
			
		||||
 | 
			
		||||
@ -30,6 +30,7 @@ public class Loader {
 | 
			
		||||
      hikariConnectionProperties.put("username", container.getUsername());
 | 
			
		||||
      hikariConnectionProperties.put("password", container.getPassword());
 | 
			
		||||
      hikariConnectionProperties.put("jdbcUrl", container.getJdbcUrl());
 | 
			
		||||
      hikariConnectionProperties.put("autoCommit", "false");
 | 
			
		||||
 | 
			
		||||
      ebeanConnectionProperties.load(ebeanInputStream);
 | 
			
		||||
      ebeanConnectionProperties.put("datasource_db_username", container.getUsername());
 | 
			
		||||
 | 
			
		||||
@ -1,21 +1,18 @@
 | 
			
		||||
package com.github.polpetta.mezzotre.orm;
 | 
			
		||||
 | 
			
		||||
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 com.github.polpetta.mezzotre.helper.Loader;
 | 
			
		||||
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.typequery.PString;
 | 
			
		||||
import java.util.concurrent.CompletableFuture;
 | 
			
		||||
import java.time.Duration;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
import org.junit.jupiter.api.BeforeEach;
 | 
			
		||||
import org.junit.jupiter.api.Tag;
 | 
			
		||||
import org.junit.jupiter.api.Test;
 | 
			
		||||
import org.junit.jupiter.api.Timeout;
 | 
			
		||||
import org.mockito.ArgumentCaptor;
 | 
			
		||||
import org.apache.commons.lang3.tuple.Pair;
 | 
			
		||||
import org.junit.jupiter.api.*;
 | 
			
		||||
import org.slf4j.LoggerFactory;
 | 
			
		||||
import org.testcontainers.containers.PostgreSQLContainer;
 | 
			
		||||
import org.testcontainers.junit.jupiter.Container;
 | 
			
		||||
@ -33,7 +30,7 @@ class CallbackQueryContextCleanerIntegrationTest {
 | 
			
		||||
 | 
			
		||||
  private Database database;
 | 
			
		||||
 | 
			
		||||
  private BatchBeanCleanerService fakeBatchBeanCleanerService;
 | 
			
		||||
  private BatchBeanCleanerService batchBeanCleanerService;
 | 
			
		||||
  private CallbackQueryContextCleaner callbackQueryContextCleaner;
 | 
			
		||||
 | 
			
		||||
  @BeforeEach
 | 
			
		||||
@ -41,41 +38,41 @@ class CallbackQueryContextCleanerIntegrationTest {
 | 
			
		||||
    database =
 | 
			
		||||
        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 =
 | 
			
		||||
        new CallbackQueryContextCleaner(
 | 
			
		||||
            fakeBatchBeanCleanerService,
 | 
			
		||||
            LoggerFactory.getLogger(CallbackQueryContextCleaner.class));
 | 
			
		||||
            batchBeanCleanerService, LoggerFactory.getLogger(CallbackQueryContextCleaner.class));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @AfterEach
 | 
			
		||||
  void tearDown() throws Exception {
 | 
			
		||||
    batchBeanCleanerService.stopAsync().awaitTerminated(Duration.ofSeconds(10));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  @Timeout(value = 1, unit = TimeUnit.MINUTES)
 | 
			
		||||
  void shouldDeleteByGroupId() throws Exception {
 | 
			
		||||
    when(fakeBatchBeanCleanerService.removeAsync(eq("an id"), any()))
 | 
			
		||||
        .thenReturn(CompletableFuture.completedFuture(1));
 | 
			
		||||
    new CallbackQueryContext("doesn't matter", "an id", new CallbackQueryMetadata()).save();
 | 
			
		||||
 | 
			
		||||
    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("entryGroup", pStringArgumentCaptor.getValue().toString());
 | 
			
		||||
    assertEquals(0, new QCallbackQueryContext().findCount());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  @Test
 | 
			
		||||
  @Timeout(value = 1, unit = TimeUnit.MINUTES)
 | 
			
		||||
  void shouldDeleteById() throws Exception {
 | 
			
		||||
    when(fakeBatchBeanCleanerService.removeAsync(eq("an id"), any()))
 | 
			
		||||
        .thenReturn(CompletableFuture.completedFuture(1));
 | 
			
		||||
    new CallbackQueryContext("an id", "doesn't matter", new CallbackQueryMetadata()).save();
 | 
			
		||||
 | 
			
		||||
    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("id", pStringArgumentCaptor.getValue().toString());
 | 
			
		||||
    assertEquals(0, new QCallbackQueryContext().findCount());
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user