本文整理汇总了Java中ru.yandex.qatools.embed.postgresql.PostgresStarter.getDefaultInstance方法的典型用法代码示例。如果您正苦于以下问题:Java PostgresStarter.getDefaultInstance方法的具体用法?Java PostgresStarter.getDefaultInstance怎么用?Java PostgresStarter.getDefaultInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ru.yandex.qatools.embed.postgresql.PostgresStarter
的用法示例。
在下文中一共展示了PostgresStarter.getDefaultInstance方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: launchPostgres
import ru.yandex.qatools.embed.postgresql.PostgresStarter; //导入方法依赖的package包/类
protected static PostgresConfig launchPostgres() throws IOException {
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
final PostgresConfig pgConfig = PostgresConfig.defaultWithDbName("eventsourcing",
"eventsourcing", "eventsourcing");
PostgresExecutable exec = runtime.prepare(pgConfig);
PostgresProcess process = exec.start();
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override public void run() {
process.stop();
}
});
return pgConfig;
}
示例2: setupPostgres
import ru.yandex.qatools.embed.postgresql.PostgresStarter; //导入方法依赖的package包/类
@BeforeClass
public static void setupPostgres() {
try {
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
final PostgresConfig config = PostgresConfig.defaultWithDbName("test","testuser","testpw");
PostgresExecutable exec = runtime.prepare(config);
postgresProcess = exec.start();
Jdbc3SimpleDataSource _postgresDatasource = new Jdbc3SimpleDataSource();
_postgresDatasource.setServerName(config.net().host());
_postgresDatasource.setPortNumber(config.net().port());
_postgresDatasource.setDatabaseName(config.storage().dbName());
_postgresDatasource.setUser(config.credentials().username());
_postgresDatasource.setPassword(config.credentials().password());
_postgresDatasource.setAutosave(AutoSave.NEVER);
postgresDatasource = Mockito.spy(_postgresDatasource);
Mockito.when(postgresDatasource.getConnection()).thenAnswer(new Answer<Connection>() {
@Override
public Connection answer(InvocationOnMock invocation) throws Throwable {
Connection connection = _postgresDatasource.getConnection();
connection.setAutoCommit(false);
return connection;
}
});
} catch (IOException | SQLException e) {
throw new RuntimeException(e);
}
}
示例3: DatabaseRule
import ru.yandex.qatools.embed.postgresql.PostgresStarter; //导入方法依赖的package包/类
DatabaseRule(ConnectionPoolBuilder builder) {
this.builder = builder;
if (builder instanceof EmbeddedConnectionPoolBuilder)
{
if (process == null)
{
try
{
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
PostgresConfig config = new PostgresConfig(V9_6_2, new AbstractPostgresConfig.Net(),
new AbstractPostgresConfig.Storage("async-pg"), new AbstractPostgresConfig.Timeout(),
new AbstractPostgresConfig.Credentials("async-pg", "async-pg"));
PostgresExecutable exec = runtime.prepare(config);
process = exec.start();
out.printf("Started postgres to %s:%d%n", process.getConfig().net().host(), process.getConfig().net().port());
}
catch (IOException e)
{
throw new RuntimeException(e);
}
}
builder.hostname(process.getConfig().net().host());
builder.port(process.getConfig().net().port());
}
}
示例4: main
import ru.yandex.qatools.embed.postgresql.PostgresStarter; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
//embedded postgres db
PostgresProcess postgresProcess;
PostgresStarter<PostgresExecutable, PostgresProcess> runtime = PostgresStarter.getDefaultInstance();
final PostgresConfig config = PostgresConfig.defaultWithDbName("test","testuser","testpw");
PostgresExecutable exec = runtime.prepare(config);
postgresProcess = exec.start();
Jdbc3SimpleDataSource postgresDatasource = new Jdbc3SimpleDataSource();
postgresDatasource.setServerName(config.net().host());
postgresDatasource.setPortNumber(config.net().port());
postgresDatasource.setDatabaseName(config.storage().dbName());
postgresDatasource.setUser(config.credentials().username());
postgresDatasource.setPassword(config.credentials().password());
postgresDatasource.setAutosave(AutoSave.NEVER);
DisableAutocommitDatasource datasource = new DisableAutocommitDatasource(postgresDatasource);
System.out.println("\n\n\n\n\n\n\n\n");
RootFactory root = new RootFactory();
root.stringAttribute.set("1");
DataSerialisationManager<RootFactory,Void> serialisationManager = new DataSerialisationManager<>(new JacksonSerialisation<>(1),new JacksonDeSerialisation<>(RootFactory.class,1),new ArrayList<>(),1);
PostgresDataStorage<RootFactory,Void> postgresFactoryStorage = new PostgresDataStorage<>(datasource, root, serialisationManager);
ApplicationServer<Void,Root, RootFactory,Void> applicationServer = new ApplicationServer<>(new FactoryManager<>(new RethrowingFactoryExceptionHandler<>()),postgresFactoryStorage);
applicationServer.start();
//output is 1 from initial factory
DataAndNewMetadata<RootFactory> update = applicationServer.prepareNewFactory();
update.root.stringAttribute.set("2");
applicationServer.updateCurrentFactory(update, "", "", s -> true);
//output is 2 from initial factory
applicationServer.stop();
ApplicationServer<Void,Root, RootFactory,Void> newApplicationServer = new ApplicationServer<>(new FactoryManager<>(new RethrowingFactoryExceptionHandler<>()),postgresFactoryStorage);
newApplicationServer.start();
//output is 2 again from the saved update
System.out.println("\n\n\n\n\n\n\n\n");
postgresProcess.stop();
}