Skip to content

Commit b51840c

Browse files
improve logging in MsSQLTestDatabase
1 parent 7038bba commit b51840c

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

airbyte-integrations/connectors/source-mssql/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
airbyteJavaConnector {
66
cdkVersionRequired = '0.19.1'
77
features = ['db-sources']
8-
useLocalCdk = false
8+
useLocalCdk = true
99
}
1010

1111
java {

airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
import java.util.HashMap;
1717
import java.util.List;
1818
import java.util.Map;
19+
import java.util.Queue;
20+
import java.util.concurrent.atomic.AtomicInteger;
21+
import java.util.stream.Collectors;
1922
import java.util.stream.Stream;
2023
import org.apache.commons.lang3.StringUtils;
24+
import org.apache.commons.lang3.exception.ExceptionUtils;
2125
import org.jooq.SQLDialect;
2226
import org.slf4j.Logger;
2327
import org.slf4j.LoggerFactory;
@@ -105,39 +109,39 @@ public MsSQLTestDatabase withShortenedCapturePollingInterval() {
105109

106110
private void waitForAgentState(final boolean running) {
107111
final String expectedValue = running ? "Running." : "Stopped.";
108-
LOGGER.debug("Waiting for SQLServerAgent state to change to '{}'.", expectedValue);
112+
LOGGER.info(formatLogLine("Waiting for SQLServerAgent state to change to '{}'."), expectedValue);
109113
for (int i = 0; i < MAX_RETRIES; i++) {
110114
try {
111115
final var r = query(ctx -> ctx.fetch("EXEC master.dbo.xp_servicecontrol 'QueryState', N'SQLServerAGENT';").get(0));
112116
if (expectedValue.equalsIgnoreCase(r.getValue(0).toString())) {
113-
LOGGER.debug("SQLServerAgent state is '{}', as expected.", expectedValue);
117+
LOGGER.info(formatLogLine("SQLServerAgent state is '{}', as expected."), expectedValue);
114118
return;
115119
}
116-
LOGGER.debug("Retrying, SQLServerAgent state {} does not match expected '{}'.", r, expectedValue);
120+
LOGGER.info(formatLogLine("Retrying, SQLServerAgent state {} does not match expected '{}'."), r, expectedValue);
117121
} catch (final SQLException e) {
118-
LOGGER.debug("Retrying agent state query after catching exception {}.", e.getMessage());
122+
LOGGER.info(formatLogLine("Retrying agent state query after catching exception {}."), e.getMessage());
119123
}
120124
try {
121125
Thread.sleep(1_000); // Wait one second between retries.
122126
} catch (final InterruptedException e) {
123127
throw new RuntimeException(e);
124128
}
125129
}
126-
throw new RuntimeException("Exhausted retry attempts while polling for agent state");
130+
throw new RuntimeException(formatLogLine("Exhausted retry attempts while polling for agent state"));
127131
}
128132

129133
public MsSQLTestDatabase withWaitUntilMaxLsnAvailable() {
130-
LOGGER.debug("Waiting for max LSN to become available for database {}.", getDatabaseName());
134+
LOGGER.info(formatLogLine("Waiting for max LSN to become available for database {}."), getDatabaseName());
131135
for (int i = 0; i < MAX_RETRIES; i++) {
132136
try {
133137
final var maxLSN = query(ctx -> ctx.fetch("SELECT sys.fn_cdc_get_max_lsn();").get(0).get(0, byte[].class));
134138
if (maxLSN != null) {
135-
LOGGER.debug("Max LSN available for database {}: {}", getDatabaseName(), Lsn.valueOf(maxLSN));
139+
LOGGER.info(formatLogLine("Max LSN available for database {}: {}"), getDatabaseName(), Lsn.valueOf(maxLSN));
136140
return self();
137141
}
138-
LOGGER.debug("Retrying, max LSN still not available for database {}.", getDatabaseName());
142+
LOGGER.info(formatLogLine("Retrying, max LSN still not available for database {}."), getDatabaseName());
139143
} catch (final SQLException e) {
140-
LOGGER.warn("Retrying max LSN query after catching exception {}", e.getMessage());
144+
LOGGER.info(formatLogLine("Retrying max LSN query after catching exception {}"), e.getMessage());
141145
}
142146
try {
143147
Thread.sleep(1_000); // Wait one second between retries.

0 commit comments

Comments
 (0)