use of org.h2.tools.Server in project che by eclipse.
the class SshTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(SshPairImpl.class, UserImpl.class, AccountImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server));
bind(SshDao.class).to(JpaSshDao.class);
bind(new TypeLiteral<TckRepository<SshPairImpl>>() {
}).toInstance(new JpaTckRepository<>(SshPairImpl.class));
bind(new TypeLiteral<TckRepository<UserImpl>>() {
}).toInstance(new JpaTckRepository<>(UserImpl.class));
}
use of org.h2.tools.Server in project che by eclipse.
the class JpaTckModule method configure.
@Override
protected void configure() {
H2DBTestServer server = H2DBTestServer.startDefault();
install(new PersistTestModuleBuilder().setDriver(Driver.class).runningOn(server).addEntityClasses(UserImpl.class, ProfileImpl.class, PreferenceEntity.class, AccountImpl.class).setExceptionHandler(H2ExceptionHandler.class).build());
bind(DBInitializer.class).asEagerSingleton();
bind(SchemaInitializer.class).toInstance(new FlywaySchemaInitializer(server.getDataSource(), "che-schema"));
bind(TckResourcesCleaner.class).toInstance(new H2JpaCleaner(server.getDataSource()));
bind(new TypeLiteral<TckRepository<UserImpl>>() {
}).to(UserJpaTckRepository.class);
bind(new TypeLiteral<TckRepository<ProfileImpl>>() {
}).toInstance(new JpaTckRepository<>(ProfileImpl.class));
bind(new TypeLiteral<TckRepository<Pair<String, Map<String, String>>>>() {
}).to(PreferenceJpaTckRepository.class);
bind(UserDao.class).to(JpaUserDao.class);
bind(ProfileDao.class).to(JpaProfileDao.class);
bind(PreferenceDao.class).to(JpaPreferenceDao.class);
// SHA-512 encryptor is faster than PBKDF2 so it is better for testing
bind(PasswordEncryptor.class).to(SHA512PasswordEncryptor.class).in(Singleton.class);
}
use of org.h2.tools.Server in project aries by apache.
the class TransactionLogTest method setupServerAndDataSource.
private void setupServerAndDataSource() throws SQLException {
server = Server.createTcpServer("-tcpPort", "0");
server.start();
File dbPath = new File("target/recovery-test/database");
dataSource = new JdbcDataSource();
dataSource.setUrl("jdbc:h2:tcp://127.0.0.1:" + server.getPort() + "/" + dbPath.getAbsolutePath());
}
use of org.h2.tools.Server in project nifi by apache.
the class DBCPServiceTest method testDropInvalidConnectionsH2_Better.
/**
* Test Drop invalid connections and create new ones.
* Better behavior, invalid connections are dropped and valid created.
*/
@Test
public void testDropInvalidConnectionsH2_Better() throws Exception {
// start the H2 TCP Server
String[] args = new String[0];
Server server = Server.createTcpServer(args).start();
final TestRunner runner = TestRunners.newTestRunner(TestProcessor.class);
final DBCPConnectionPool service = new DBCPConnectionPool();
runner.addControllerService("test-dropcreate", service);
runner.setProperty(service, DBCPConnectionPool.DATABASE_URL, "jdbc:h2:tcp://localhost:" + server.getPort() + "/~/test");
runner.setProperty(service, DBCPConnectionPool.DB_DRIVERNAME, "org.h2.Driver");
runner.setProperty(service, DBCPConnectionPool.VALIDATION_QUERY, "SELECT 5");
runner.enableControllerService(service);
runner.assertValid(service);
final DBCPService dbcpService = (DBCPService) runner.getProcessContext().getControllerServiceLookup().getControllerService("test-dropcreate");
Assert.assertNotNull(dbcpService);
// get and verify connections
for (int i = 0; i < 10; i++) {
final Connection connection = dbcpService.getConnection();
System.out.println(connection);
Assert.assertNotNull(connection);
assertValidConnectionH2(connection, i);
connection.close();
}
// restart server, connections in pool should became invalid
server.stop();
server.shutdown();
server.start();
// Pool should remove invalid connections and create new valid connections.
for (int i = 0; i < 10; i++) {
final Connection connection = dbcpService.getConnection();
System.out.println(connection);
Assert.assertNotNull(connection);
assertValidConnectionH2(connection, i);
connection.close();
}
server.shutdown();
}
use of org.h2.tools.Server in project spf4j by zolyfarkas.
the class JdbcSemaphoreTest method testMultiProcess.
@Test
@SuppressFBWarnings("AFBR_ABNORMAL_FINALLY_BLOCK_RETURN")
public void testMultiProcess() throws SQLException, IOException, InterruptedException, ExecutionException, TimeoutException {
Server server = Server.createTcpServer(new String[] { "-tcpPort", "9123", "-tcpAllowOthers" }).start();
File tempDB = File.createTempFile("test", "h2db");
String connStr = "jdbc:h2:tcp://localhost:9123/nio:" + tempDB.getAbsolutePath() + ";AUTO_SERVER=TRUE";
try {
JdbcDataSource ds = new JdbcDataSource();
ds.setURL(connStr);
ds.setUser("sa");
ds.setPassword("sa");
createSchemaObjects(ds);
testReleaseAck(ds, "testSem", 2);
JdbcSemaphore semaphore = new JdbcSemaphore(ds, "test_sem2", 3);
org.spf4j.base.Runtime.jrun(BadSemaphoreHandler.class, 10000, connStr, "test_sem2");
org.spf4j.base.Runtime.jrun(BadSemaphoreHandler.class, 10000, connStr, "test_sem2");
Assert.assertTrue(semaphore.tryAcquire(1, TimeUnit.SECONDS));
Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
JdbcHeartBeat.stopHeartBeats();
server.stop();
} finally {
if (!tempDB.delete()) {
throw new IOException("Cannot delete " + tempDB);
}
}
}
Aggregations