Class PostgreSqlJsonContainerIT

java.lang.Object
com.github.isuhorukov.log.watcher.PostgreSqlJsonContainerIT

public class PostgreSqlJsonContainerIT extends Object
  • Field Details

    • logCapture

      @RegisterExtension de.dm.infrastructure.logcapture.LogCapture logCapture
  • Constructor Details

    • PostgreSqlJsonContainerIT

      public PostgreSqlJsonContainerIT()
  • Method Details

    • testWatchPostgreSqlLogsWithContainer

      @Test void testWatchPostgreSqlLogsWithContainer(@TempDir Path tempDir)
      Tests the functionality of watching PostgreSQL logs using a Docker container.

      This test sets up a temporary directory for Postgres data and log files, configures a PostgreSQL Docker container to log in JSON format, and verifies that the application correctly processes these logs.

      The test uses a PostgreSQLContainer from the Testcontainers library to run a PostgreSQL instance with specific logging configurations. It evaluates whether the PostgreSqlJson.watchPostgreSqlLogs() method can detect and process log entries in the specified directory.

      Parameters:
      tempDir - a temporary directory provided by JUnit for test file storage.
    • applicationProcessLog

      @Step("application should detect and process log entries from the PostgreSQL logs") public static void applicationProcessLog(org.testcontainers.containers.PostgreSQLContainer<?> postgresContainer, Path pgData) throws SQLException, InterruptedException, IOException
      Throws:
      SQLException
      InterruptedException
      IOException
    • createPgDataDirectory

      @Step("a temporary directory for Postgres data and log files") public static Path createPgDataDirectory(Path tempDir) throws IOException
      Throws:
      IOException
    • configurePostgresContainer

      @Step("configure PostgreSQL container") public static org.testcontainers.containers.PostgreSQLContainer<?> configurePostgresContainer(Path pgData)
    • shutdownExecutor

      static void shutdownExecutor(ExecutorService executorService) throws InterruptedException
      Throws:
      InterruptedException
    • waitEventsAndCloseLogWatcher

      static void waitEventsAndCloseLogWatcher(PostgreSqlJson postgreSqlJson, Future<Integer> resultCode) throws InterruptedException, IOException
      Throws:
      InterruptedException
      IOException
    • startLogWatcher

      @NotNull static @NotNull Future<Integer> startLogWatcher(ExecutorService executorService, PostgreSqlJson postgreSqlJson)
    • startPostgreSqlContainer

      @Step("I start the PostgreSQL container with specific logging configurations") public static void startPostgreSqlContainer(org.testcontainers.containers.PostgreSQLContainer<?> postgresContainer) throws InterruptedException, IOException
      Throws:
      InterruptedException
      IOException
    • getPostgreSqlJson

      static PostgreSqlJson getPostgreSqlJson(org.testcontainers.containers.PostgreSQLContainer<?> postgresContainer, Path pgData)
    • executeSomeTestQueriesInPostgreSql

      static void executeSomeTestQueriesInPostgreSql(org.testcontainers.containers.PostgreSQLContainer<?> postgresContainer) throws SQLException
      Throws:
      SQLException
    • assertExpectedLogEvents

      @Step("logs are generated in the specified directory and watched & processed by postgres_log_parser") public static void assertExpectedLogEvents(de.dm.infrastructure.logcapture.LogCapture logCapture1)