Skip to content

Commit 8d5b00c

Browse files
add more logs into TestDatabase
1 parent 3f86a0e commit 8d5b00c

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

airbyte-cdk/java/airbyte-cdk/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ MavenLocal debugging steps:
166166

167167
| Version | Date | Pull Request | Subject |
168168
|:--------|:-----------|:-----------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------|
169+
| 0.23.4 | 2024-02-26 | [\#35507](https://github.com/airbytehq/airbyte/pull/35507) | Add more logs into TestDatabase. |
169170
| 0.23.3 | 2024-02-26 | [\#35495](https://github.com/airbytehq/airbyte/pull/35495) | Fix Junit Interceptor to print better stacktraces |
170171
| 0.23.2 | 2024-02-22 | [\#35385](https://github.com/airbytehq/airbyte/pull/35342) | Bugfix: inverted logic of disableTypeDedupe flag |
171172
| 0.23.1 | 2024-02-22 | [\#35527](https://github.com/airbytehq/airbyte/pull/35527) | reduce shutdow timeouts |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.23.3
1+
version=0.23.4

airbyte-cdk/java/airbyte-cdk/core/src/testFixtures/java/io/airbyte/cdk/testutils/TestDatabase.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
import java.io.IOException;
2020
import java.io.UncheckedIOException;
2121
import java.sql.SQLException;
22+
import java.text.DateFormat;
23+
import java.text.SimpleDateFormat;
2224
import java.time.Duration;
2325
import java.util.ArrayList;
2426
import java.util.HashMap;
2527
import java.util.List;
2628
import java.util.Map;
29+
import java.util.concurrent.ConcurrentHashMap;
30+
import java.util.concurrent.atomic.AtomicInteger;
2731
import java.util.stream.Stream;
2832
import javax.sql.DataSource;
2933
import org.jooq.DSLContext;
@@ -51,12 +55,30 @@ abstract public class TestDatabase<C extends JdbcDatabaseContainer<?>, T extends
5155
final private ArrayList<String> cleanupSQL = new ArrayList<>();
5256
final private Map<String, String> connectionProperties = new HashMap<>();
5357

54-
private DataSource dataSource;
55-
private DSLContext dslContext;
58+
private volatile DataSource dataSource;
59+
private volatile DSLContext dslContext;
5660

61+
protected final int databaseId;
62+
private static final AtomicInteger nextDatabaseId = new AtomicInteger(0);
63+
64+
protected final int containerId;
65+
private static final AtomicInteger nextContainerId = new AtomicInteger(0);
66+
private static final Map<String, Integer> containerUidToId = new ConcurrentHashMap<>();
67+
68+
@SuppressWarnings("this-escape")
5769
protected TestDatabase(C container) {
5870
this.container = container;
5971
this.suffix = Strings.addRandomSuffix("", "_", 10);
72+
this.databaseId = nextDatabaseId.getAndIncrement();
73+
this.containerId = containerUidToId.computeIfAbsent(container.getContainerId(), k -> nextContainerId.getAndIncrement());
74+
LOGGER.info(formatLogLine("creating database " + getDatabaseName()));
75+
}
76+
77+
private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
78+
79+
protected String formatLogLine(String logLine) {
80+
String retVal = "TestDatabase databaseId=" + databaseId + ", containerId=" + containerId + " - " + logLine;
81+
return retVal;
6082
}
6183

6284
@SuppressWarnings("unchecked")
@@ -187,12 +209,13 @@ protected void execInContainer(Stream<String> cmds) {
187209
return;
188210
}
189211
try {
190-
LOGGER.debug("executing {}", Strings.join(cmd, " "));
212+
LOGGER.info(formatLogLine(String.format("executing command %s", Strings.join(cmd, " "))));
191213
final var exec = getContainer().execInContainer(cmd.toArray(new String[0]));
192214
if (exec.getExitCode() == 0) {
193-
LOGGER.debug("execution success\nstdout:\n{}\nstderr:\n{}", exec.getStdout(), exec.getStderr());
215+
LOGGER.info(formatLogLine(String.format("execution success\nstdout:\n%s\nstderr:\n%s", exec.getStdout(), exec.getStderr())));
194216
} else {
195-
LOGGER.error("execution failure, code {}\nstdout:\n{}\nstderr:\n{}", exec.getExitCode(), exec.getStdout(), exec.getStderr());
217+
LOGGER.error(formatLogLine(
218+
String.format("execution failure, code %s\nstdout:\n%s\nstderr:\n%s", exec.getExitCode(), exec.getStdout(), exec.getStderr())));
196219
}
197220
} catch (IOException e) {
198221
throw new UncheckedIOException(e);
@@ -234,6 +257,7 @@ public B integrationTestConfigBuilder() {
234257
public void close() {
235258
execSQL(this.cleanupSQL.stream());
236259
execInContainer(inContainerUndoBootstrapCmd());
260+
LOGGER.info("closing database databaseId=" + databaseId);
237261
}
238262

239263
static public class ConfigBuilder<T extends TestDatabase<?, ?, ?>, B extends ConfigBuilder<T, B>> {

0 commit comments

Comments
 (0)