Delay SQL availability check during Tool start (#643)

* Delay SQL availability check during Tool start

During Cloud SQL migration, Cloud SQL password setup in Registry
server requires a few tool commands. Such commands must be able
to run before Cloud SQL is configured.

In this change, we deplay SQL credential loading until access is
needed.
This commit is contained in:
Weimin Yu 2020-06-24 14:00:36 -04:00 committed by GitHub
parent 75659671db
commit 071800ae50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View file

@ -21,6 +21,7 @@ import static org.testcontainers.containers.PostgreSQLContainer.POSTGRESQL_PORT;
import com.google.common.base.Charsets;
import com.google.common.base.Joiner;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
@ -199,12 +200,12 @@ abstract class JpaTransactionManagerRule extends ExternalResource {
}
JpaTransactionManagerImpl txnManager = new JpaTransactionManagerImpl(emf, clock);
cachedTm = TransactionManagerFactory.jpaTm();
TransactionManagerFactory.setJpaTm(txnManager);
TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(txnManager));
}
@Override
public void after() {
TransactionManagerFactory.setJpaTm(cachedTm);
TransactionManagerFactory.setJpaTm(Suppliers.ofInstance(cachedTm));
cachedTm = null;
}