Search in sources :

Example 76 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class JdbcDriverTest method testReuseSocketConnections.

@Test
public void testReuseSocketConnections() throws Exception {
    ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    try (Server server = new Server(conf)) {
        server.start();
        server.waitForStandaloneBoot();
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl());
            Connection connection2 = DriverManager.getConnection(server.getJdbcUrl());
            Statement statement = connection.createStatement();
            Statement statement2 = connection2.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES");
            ResultSet rs2 = statement2.executeQuery("SELECT * FROM SYSTABLES")) {
            int count = 0;
            while (rs.next()) {
                System.out.println("table: " + rs.getString(1));
                count++;
            }
            assertTrue(count > 0);
            // since 0.8.0 we will open multiple sockets, so this test may flap
            assertTrue(server.getActualConnections().connections.size() <= 2 && server.getActualConnections().connections.size() >= 1);
        }
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl());
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            int count = 0;
            while (rs.next()) {
                System.out.println("table: " + rs.getString(1));
                count++;
            }
            assertTrue(count > 0);
            // since 0.8.0 we will open multiple sockets, so this test may flap
            assertTrue(server.getActualConnections().connections.size() <= 3 && server.getActualConnections().connections.size() >= 1);
        }
    }
}
Also used : Server(herddb.server.Server) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 77 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class JdbcDriverTest method testNotPoolSQLConnectionsInJDBCDriverByDefault.

@Test
public void testNotPoolSQLConnectionsInJDBCDriverByDefault() throws Exception {
    ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    try (Server server = new Server(conf)) {
        server.start();
        server.waitForStandaloneBoot();
        Connection connection1;
        Connection connection2;
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl())) {
            connection1 = connection;
        }
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl())) {
            connection2 = connection;
        }
        assertNotSame(connection1, connection2);
    }
}
Also used : Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) Test(org.junit.Test)

Example 78 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class JdbcDriverTest method testForcePoolSQLConnectionsInJDBCDriver.

@Test
public void testForcePoolSQLConnectionsInJDBCDriver() throws Exception {
    ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    try (Server server = new Server(conf)) {
        server.start();
        server.waitForStandaloneBoot();
        Connection connection1;
        Connection connection2;
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl() + "?poolConnections=true")) {
            connection1 = connection;
        }
        try (Connection connection = DriverManager.getConnection(server.getJdbcUrl() + "?poolConnections=true")) {
            connection2 = connection;
        }
        assertSame(connection1, connection2);
    }
}
Also used : Server(herddb.server.Server) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) Test(org.junit.Test)

Example 79 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class HerdDBEmbeddedDataSource method startEmbeddedServer.

private void startEmbeddedServer() throws SQLException {
    if (!serverInitialized) {
        ServerConfiguration serverConfiguration = new ServerConfiguration(properties);
        try {
            serverConfiguration.readJdbcUrl(url);
        } catch (RuntimeException err) {
            throw new SQLException(err);
        }
        startServer = serverConfiguration.getBoolean("server.start", startServer);
        String mode = serverConfiguration.getString(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_LOCAL);
        if (ServerConfiguration.PROPERTY_MODE_LOCAL.equals(mode) || (ServerConfiguration.PROPERTY_MODE_STANDALONE.equals(mode) && startServer) || (ServerConfiguration.PROPERTY_MODE_CLUSTER.equals(mode) && startServer) || (ServerConfiguration.PROPERTY_MODE_DISKLESSCLUSTER.equals(mode) && startServer)) {
            LOGGER.log(Level.INFO, "Booting Local Embedded HerdDB mode, url:" + url + ", properties:" + serverConfiguration);
            server = new Server(serverConfiguration, statsLogger);
            try {
                server.start();
                int waitForTableSpaceTimeout = getWaitForTableSpaceTimeout();
                if (waitForTableSpaceTimeout > 0) {
                    server.waitForBootOfLocalTablespaces(waitForTableSpaceTimeout);
                }
                if (ServerConfiguration.PROPERTY_MODE_LOCAL.equals(mode) || ServerConfiguration.PROPERTY_MODE_STANDALONE.equals(mode)) {
                    client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
                }
            } catch (Exception ex) {
                throw new SQLException("Cannot boot embedded server " + ex, ex);
            }
        }
        serverInitialized = true;
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) Server(herddb.server.Server) SQLException(java.sql.SQLException) ServerConfiguration(herddb.server.ServerConfiguration) SQLException(java.sql.SQLException)

Example 80 with ServerConfiguration

use of herddb.server.ServerConfiguration in project herddb by diennea.

the class JdbcDriverZookeeperTest method test.

@Test
public void test() throws Exception {
    ServerConfiguration serverconfig_1 = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
    serverconfig_1.set(ServerConfiguration.PROPERTY_PORT, 7867);
    serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
    serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
    try (Server server = new Server(serverconfig_1)) {
        server.start();
        server.waitForStandaloneBoot();
        try (Connection connection = DriverManager.getConnection("jdbc:herddb:zookeeper:" + testEnv.getAddress() + "" + testEnv.getPath());
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            int count = 0;
            while (rs.next()) {
                System.out.println("table: " + rs.getString(1));
                count++;
            }
            assertTrue(count > 0);
        }
    }
}
Also used : Server(herddb.server.Server) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Aggregations

ServerConfiguration (herddb.server.ServerConfiguration)86 Test (org.junit.Test)78 Server (herddb.server.Server)60 Table (herddb.model.Table)39 CreateTableStatement (herddb.model.commands.CreateTableStatement)36 InsertStatement (herddb.model.commands.InsertStatement)34 HashSet (java.util.HashSet)21 DataScanner (herddb.model.DataScanner)20 BookkeeperCommitLog (herddb.cluster.BookkeeperCommitLog)19 AlterTableSpaceStatement (herddb.model.commands.AlterTableSpaceStatement)19 ClientConfiguration (herddb.client.ClientConfiguration)16 ArrayList (java.util.ArrayList)16 TableSpaceManager (herddb.core.TableSpaceManager)15 Index (herddb.model.Index)15 CreateIndexStatement (herddb.model.commands.CreateIndexStatement)15 Path (java.nio.file.Path)14 HDBClient (herddb.client.HDBClient)13 HDBConnection (herddb.client.HDBConnection)13 ZookeeperMetadataStorageManager (herddb.cluster.ZookeeperMetadataStorageManager)13 GetStatement (herddb.model.commands.GetStatement)13