Search in sources :

Example 1 with Server

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));
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) SshPairImpl(org.eclipse.che.api.ssh.server.model.impl.SshPairImpl) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) SshDao(org.eclipse.che.api.ssh.server.spi.SshDao) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) TypeLiteral(com.google.inject.TypeLiteral) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl)

Example 2 with Server

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);
}
Also used : TckResourcesCleaner(org.eclipse.che.commons.test.tck.TckResourcesCleaner) H2DBTestServer(org.eclipse.che.commons.test.db.H2DBTestServer) AccountImpl(org.eclipse.che.account.spi.AccountImpl) Driver(org.h2.Driver) PreferenceDao(org.eclipse.che.api.user.server.spi.PreferenceDao) SHA512PasswordEncryptor(org.eclipse.che.security.SHA512PasswordEncryptor) H2JpaCleaner(org.eclipse.che.commons.test.db.H2JpaCleaner) PersistTestModuleBuilder(org.eclipse.che.commons.test.db.PersistTestModuleBuilder) SchemaInitializer(org.eclipse.che.core.db.schema.SchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) FlywaySchemaInitializer(org.eclipse.che.core.db.schema.impl.flyway.FlywaySchemaInitializer) ProfileDao(org.eclipse.che.api.user.server.spi.ProfileDao) TypeLiteral(com.google.inject.TypeLiteral) UserDao(org.eclipse.che.api.user.server.spi.UserDao) ProfileImpl(org.eclipse.che.api.user.server.model.impl.ProfileImpl) DBInitializer(org.eclipse.che.core.db.DBInitializer) UserImpl(org.eclipse.che.api.user.server.model.impl.UserImpl) Pair(org.eclipse.che.commons.lang.Pair)

Example 3 with Server

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());
}
Also used : JdbcDataSource(org.h2.jdbcx.JdbcDataSource) File(java.io.File)

Example 4 with Server

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();
}
Also used : Server(org.h2.tools.Server) TestRunner(org.apache.nifi.util.TestRunner) Connection(java.sql.Connection) Test(org.junit.Test)

Example 5 with Server

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);
        }
    }
}
Also used : Server(org.h2.tools.Server) JdbcDataSource(org.h2.jdbcx.JdbcDataSource) IOException(java.io.IOException) File(java.io.File) Test(org.junit.Test) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Server (org.h2.tools.Server)45 Connection (java.sql.Connection)26 SQLException (java.sql.SQLException)22 Statement (java.sql.Statement)17 PreparedStatement (java.sql.PreparedStatement)15 IOException (java.io.IOException)13 ResultSet (java.sql.ResultSet)10 DbException (org.h2.message.DbException)9 Socket (java.net.Socket)8 Properties (java.util.Properties)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 ServerSocket (java.net.ServerSocket)6 Test (org.junit.Test)6 PrintStream (java.io.PrintStream)5 Task (org.h2.util.Task)5 File (java.io.File)4 JdbcDataSource (org.h2.jdbcx.JdbcDataSource)4 TcpServer (org.h2.server.TcpServer)4 PgServer (org.h2.server.pg.PgServer)4 WebServer (org.h2.server.web.WebServer)4