Class EmbeddedPostgres
java.lang.Object
de.softwareforge.testing.postgres.embedded.EmbeddedPostgres
- All Implemented Interfaces:
AutoCloseable
Manages a single, embedded Postgres instance.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
Callback interface to customize a builder in progress. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic EmbeddedPostgres.Builder
builder()
Returns a new builder.static EmbeddedPostgres.Builder
Returns a builder with defaultEmbeddedPostgres.Builder.withDefaults()
configuration already applied.void
close()
Closing anEmbeddedPostgres
instance shuts down the connected database instance.createDataSource
(String user, String databaseName) Creates aDataSource
with a specific user and database name.Creates aDatabaseInfo
object describing the default database (normallyCreates aDataSource
object that connects to the default databases (normallyCreates aDataSource
object that connects to the template database (normallystatic EmbeddedPostgres
Returns an instance that has been started and configured.boolean
int
getPort()
Returns the TCP port for this Postgres instance.int
hashCode()
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 aDatabaseInfo
object describing the default database (normallypostgres
). -
createTemplateDataSource
Creates aDataSource
object 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 aDataSource
object that connects to the default databases (normallypostgres
).- Throws:
SQLException
-
createDataSource
Creates aDataSource
with 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 anEmbeddedPostgres
instance shuts down the connected database instance.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
-