Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add background thread to track MSSQL container status #35128

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ final public T initialized() {
connectionProperties,
JdbcConnector.getConnectionTimeout(connectionProperties, getDatabaseDriver().getDriverClassName()));
this.dslContext = DSLContextFactory.create(dataSource, getSqlDialect());
initializedPostHook();
return self();
}

public void initializedPostHook() {

}

final public boolean isInitialized() {
return dslContext != null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,51 @@
.initialized();
}

private class MssqlTestDatabaseBackgroundThread extends Thread {

private volatile boolean stop = false;

public void run() {
LOGGER.info(formatLogLine("Started new database " + getDatabaseName()));
boolean wasRunning = false;
while (!stop) {
try {
final var r = query(ctx -> ctx.fetch(
"EXEC master.dbo.xp_servicecontrol 'QueryState', N'SQLServerAGENT';").get(0));
String agentState = r.getValue(0).toString();
LOGGER.info(formatLogLine("agentState=" + agentState));
if ("Running.".equals(agentState)) {
wasRunning = true;
} else if (wasRunning && !"Running.".equals(agentState)) {
LOGGER.info(formatLogLine("agent was running. agentState=" + agentState));
}
} catch (final Throwable t) {
String exceptionAsString = StringUtils.join(ExceptionUtils.getStackFrames(t), "\n ");

Check failure on line 90 in airbyte-integrations/connectors/source-mssql/src/testFixtures/java/io/airbyte/integrations/source/mssql/MsSQLTestDatabase.java

View workflow job for this annotation

GitHub Actions / Gradle Check

[Task :airbyte-integrations:connectors:source-mssql:compileTestFixturesJava FAILED] cannot find symbol String exceptionAsString = StringUtils.join(ExceptionUtils.getStackFrames(t), "\n "); ^ symbol: variable ExceptionUtils
LOGGER.info(formatLogLine("got exception " + exceptionAsString));
}
try {
Thread.sleep(5l);
} catch (InterruptedException e) {
LOGGER.info(formatLogLine("interrupted"));
}
}
}

}

private final MssqlTestDatabaseBackgroundThread bgThread;

public MsSQLTestDatabase(final MSSQLServerContainer<?> container) {
super(container);
bgThread = new MssqlTestDatabaseBackgroundThread();
LOGGER.info("SGX creating new database. databaseId=" + this.databaseId + ", databaseName=" + getDatabaseName());
}

@Override
public void initializedPostHook() {
bgThread.start();
}

public MsSQLTestDatabase withCdc() {
return with("EXEC sys.sp_cdc_enable_db;");
}
Expand Down Expand Up @@ -244,6 +284,11 @@
return cachedCerts.get(certificateKey);
}

public void close() {
bgThread.stop = true;
super.close();
}

@Override
public MsSQLConfigBuilder configBuilder() {
return new MsSQLConfigBuilder(this);
Expand Down
Loading