Interface TestConnectionProviderSource<CONN_CONFIG extends org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig>
-
- All Known Implementing Classes:
AbstractTestConnectionProviderSource
public interface TestConnectionProviderSource<CONN_CONFIG extends org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig>Manages all external resources (Docker containers, processes) and "internal" resources (network connections and pools) required for tests.There are two ways to choose a
TestConnectionProviderSourceimplementation:- In JUnit tests, reference the implementation class directly using the
NessieExternalDatabaseannotation. - Via
findCompatibleProviderSource(DatabaseAdapterConfig, DatabaseAdapterFactory, String)using a code snippet like this:DatabaseAdapterConfig config = ...; String providerSpec = adapter.indexOf(':') == -1 ? null : adapter.substring(adapter.indexOf(':') + 1) .toLowerCase(Locale.ROOT); TestConnectionProviderSource<DatabaseConnectionConfig> providerSource = findCompatibleProviderSource( config, factory, providerSpec); providerSource .configureConnectionProviderConfigFromDefaults( SystemPropertiesConfigurer ::configureConnectionFromSystemProperties); try { providerSource.start(); } catch (Exception e) { throw new RuntimeException(e); } connectionProvider = providerSource.getConnectionProvider();
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidconfigureConnectionProviderConfigFromDefaults(java.util.function.Function<CONN_CONFIG,CONN_CONFIG> configurer)A shortcut forsetConnectionProviderConfig(DatabaseConnectionConfig)using a configuration received fromcreateDefaultConnectionProviderConfig()and passed through the given function.CONN_CONFIGcreateDefaultConnectionProviderConfig()Creates the defaultDatabaseConnectionConfig.static <CONN_CONFIG extends org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig>
TestConnectionProviderSource<CONN_CONFIG>findCompatibleProviderSource(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig databaseAdapterConfig, org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory<?,?,?,?> databaseAdapterFactory, java.lang.String providerSpec)Tries to find aTestConnectionProviderSourceimplementation that returnstrueforisCompatibleWith(DatabaseAdapterConfig, DatabaseAdapterFactory)for the given arguments using Java'sServiceLoadermechanism.org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider<CONN_CONFIG>getConnectionProvider()Returns the preconfigured connection provider.CONN_CONFIGgetConnectionProviderConfig()booleanisCompatibleWith(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig adapterConfig, org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory<?,?,?,?> databaseAdapterFactory)voidsetConnectionProviderConfig(CONN_CONFIG connectionProviderConfig)Set the configuration for theDatabaseConnectionProvidercreated whenstart()is invoked.voidstart()Initialize/start the connection provider.voidstop()Stop the connection provider and release all held resources.
-
-
-
Method Detail
-
isCompatibleWith
boolean isCompatibleWith(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig adapterConfig, org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory<?,?,?,?> databaseAdapterFactory)
-
createDefaultConnectionProviderConfig
CONN_CONFIG createDefaultConnectionProviderConfig()
Creates the defaultDatabaseConnectionConfig.
-
configureConnectionProviderConfigFromDefaults
void configureConnectionProviderConfigFromDefaults(java.util.function.Function<CONN_CONFIG,CONN_CONFIG> configurer)
A shortcut forsetConnectionProviderConfig(DatabaseConnectionConfig)using a configuration received fromcreateDefaultConnectionProviderConfig()and passed through the given function.
-
setConnectionProviderConfig
void setConnectionProviderConfig(CONN_CONFIG connectionProviderConfig)
Set the configuration for theDatabaseConnectionProvidercreated whenstart()is invoked.
-
getConnectionProviderConfig
CONN_CONFIG getConnectionProviderConfig()
-
getConnectionProvider
org.projectnessie.versioned.persist.adapter.DatabaseConnectionProvider<CONN_CONFIG> getConnectionProvider()
Returns the preconfigured connection provider.This method should be called after
start().
-
start
void start() throws java.lang.ExceptionInitialize/start the connection provider.Implementations start for example Docker containers or external processes and setup connection pools.
- Throws:
java.lang.Exception
-
stop
void stop() throws java.lang.Exception
Stop the connection provider and release all held resources.Implementations for example tear down connection pools and stop example Docker containers or external processes.
- Throws:
java.lang.Exception
-
findCompatibleProviderSource
static <CONN_CONFIG extends org.projectnessie.versioned.persist.adapter.DatabaseConnectionConfig> TestConnectionProviderSource<CONN_CONFIG> findCompatibleProviderSource(org.projectnessie.versioned.persist.adapter.DatabaseAdapterConfig databaseAdapterConfig, org.projectnessie.versioned.persist.adapter.DatabaseAdapterFactory<?,?,?,?> databaseAdapterFactory, java.lang.String providerSpec)
Tries to find aTestConnectionProviderSourceimplementation that returnstrueforisCompatibleWith(DatabaseAdapterConfig, DatabaseAdapterFactory)for the given arguments using Java'sServiceLoadermechanism.- Parameters:
databaseAdapterConfig- database-adapter configuration, passed toisCompatibleWith(DatabaseAdapterConfig, DatabaseAdapterFactory)databaseAdapterFactory- database-adapter-factory, passed toisCompatibleWith(DatabaseAdapterConfig, DatabaseAdapterFactory)providerSpec- optional string, if non-nullthe lower-case class-name of theTestConnectionProviderSourceimplementation must contain this string- Returns:
TestConnectionProviderSourceimplementation- Throws:
java.lang.IllegalStateException- if no matchingTestConnectionProviderSourceimplementation could be found
-
-