Class EmbeddedPostgres
java.lang.Object
de.softwareforge.testing.postgres.embedded.EmbeddedPostgres
- All Implemented Interfaces:
AutoCloseable
Manages a single, embedded Postgres instance.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic interfaceCallback interface to customize a builder in progress. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic EmbeddedPostgres.Builderbuilder()Returns a new builder.static EmbeddedPostgres.BuilderReturns a builder with defaultEmbeddedPostgres.Builder.withDefaults()configuration already applied.voidclose()Closing anEmbeddedPostgresinstance shuts down the connected database instance.createDataSource(String user, String databaseName) Creates aDataSourcewith a specific user and database name.Creates aDatabaseInfoobject describing the default database (normallyCreates aDataSourceobject that connects to the default databases (normallyCreates aDataSourceobject that connects to the template database (normallystatic EmbeddedPostgresReturns an instance that has been started and configured.booleanintgetPort()Returns the TCP port for this Postgres instance.inthashCode()Returns the instance id for this postgres instance.toString()
-
Field Details
-
DEFAULT_PG_STARTUP_WAIT
-
-
Method Details
-
defaultInstance
Returns an instance that has been started and configured. TheEmbeddedPostgres.Builder.withDefaults()configuration has been applied.- Throws:
IOException
-
builderWithDefaults
Returns a builder with defaultEmbeddedPostgres.Builder.withDefaults()configuration already applied. -
builder
Returns a new builder. -
createDefaultDatabaseInfo
Creates aDatabaseInfoobject describing the default database (normallypostgres
). -
createTemplateDataSource
Creates aDataSourceobject that connects to the template database (normallytemplate1
). Any modification to this database will be visible in new database created withCREATE DATABASE...
.- Throws:
SQLException
-
createDefaultDataSource
Creates aDataSourceobject that connects to the default databases (normallypostgres
).- Throws:
SQLException
-
createDataSource
Creates aDataSourcewith a specific user and database name. Creating the DataSource does not also create the database or the user itself. Those must be creates e.g. with aDatabasePreparer.- Throws:
SQLException
-
getPort
public int getPort()Returns the TCP port for this Postgres instance. -
instanceId
Returns the instance id for this postgres instance. -
toString
-
equals
-
hashCode
public int hashCode() -
close
Closing anEmbeddedPostgresinstance shuts down the connected database instance.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException
-