Search in sources :

Example 1 with Server

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

the class BaseBench method restartServer.

public void restartServer() throws Exception {
    long _start = System.currentTimeMillis();
    System.out.println("[BENCH] restarting server");
    server.close();
    server = new Server(serverConfiguration);
    server.start();
    server.waitForTableSpaceBoot(TableSpace.DEFAULT, Integer.MAX_VALUE, true);
    long _stop = System.currentTimeMillis();
    System.out.println("[BENCH] server restarted in " + (_stop - _start) + " ms");
}
Also used : Server(herddb.server.Server)

Example 2 with Server

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

the class BaseBench method startServer.

@Before
public void startServer() throws Exception {
    makeServerConfiguration();
    threadpool = Executors.newFixedThreadPool(numThreads);
    server = new Server(serverConfiguration);
    server.start();
    server.waitForStandaloneBoot();
    client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
    client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
    dataSource = new BasicHerdDBDataSource(client);
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) BasicHerdDBDataSource(herddb.jdbc.BasicHerdDBDataSource) ClientConfiguration(herddb.client.ClientConfiguration) Before(org.junit.Before)

Example 3 with Server

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

the class AdvancedInsertSyntaxTest method testInsertFromSelect.

@Test
public void testInsertFromSelect() throws Exception {
    try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            try (BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client);
                Connection con = dataSource.getConnection();
                Statement create = con.createStatement();
                PreparedStatement statement = con.prepareStatement("INSERT INTO mytable (name) values(?)")) {
                create.execute("CREATE TABLE mytable (n1 int primary key auto_increment, name string)");
                create.execute("CREATE TABLE mytable2 (n1 int primary key auto_increment, name string)");
                {
                    for (int i = 0; i < 100; i++) {
                        statement.setString(1, "v" + i);
                        statement.addBatch();
                    }
                    int[] results = statement.executeBatch();
                    for (int i = 0; i < 100; i++) {
                        assertEquals(1, results[i]);
                    }
                    try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable ORDER BY n1")) {
                        int count = 0;
                        while (rs.next()) {
                            assertEquals("v" + count, rs.getString("name"));
                            assertEquals(count + 1, rs.getInt("n1"));
                            count++;
                        }
                        assertEquals(100, count);
                    }
                }
                statement.executeUpdate("INSERT INTO mytable2(n1,name) SELECT n1, name from mytable order by name desc");
                try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
                    assertTrue(rs.next());
                    assertEquals(100, rs.getInt(1));
                }
                // leverage auto_increment
                statement.executeUpdate("INSERT INTO mytable2(name) SELECT name from mytable order by name desc");
                try (ResultSet rs = statement.executeQuery("SELECT COUNT(*) FROM mytable2")) {
                    assertTrue(rs.next());
                    assertEquals(200, rs.getInt(1));
                }
                try (ResultSet rs = statement.executeQuery("SELECT n1 FROM mytable2 order by n1")) {
                    Set<Integer> ids = new HashSet<>();
                    while (rs.next()) {
                        int id = rs.getInt(1);
                        assertTrue(ids.add(id));
                    }
                    assertEquals(200, ids.size());
                }
            }
        }
    }
}
Also used : Server(herddb.server.Server) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) ResultSet(java.sql.ResultSet) ClientConfiguration(herddb.client.ClientConfiguration) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with Server

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

the class AuthTest method test.

@Test
public void test() throws Exception {
    ServerConfiguration serverConfiguration = new ServerConfiguration(folder.newFolder().toPath());
    serverConfiguration.set(SimpleSingleUserManager.PROPERTY_ADMIN_USERNAME, "myuser");
    serverConfiguration.set(SimpleSingleUserManager.PROPERTY_ADMIN_PASSWORD, "mypassword");
    try (Server server = new Server(serverConfiguration)) {
        server.start();
        server.waitForStandaloneBoot();
        try (Connection connection = DriverManager.getConnection("jdbc:herddb:server:localhost:7000?");
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            fail();
        } catch (SQLException authFailedExpected) {
            authFailedExpected.printStackTrace();
        }
        try (Connection connection = DriverManager.getConnection("jdbc:herddb:server:localhost:7000?", "myuser", "mypassword");
            Statement statement = connection.createStatement();
            ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES")) {
            assertTrue(rs.next());
        }
    }
}
Also used : Server(herddb.server.Server) SQLException(java.sql.SQLException) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test)

Example 5 with Server

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

the class CommonsDBCPTest method test.

@Test
public void test() throws Exception {
    try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
        server.start();
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setUrl("jdbc:herddb:server:localhost:7000?");
        dataSource.setDriverClassName(Driver.class.getName());
        try (Connection connection = dataSource.getConnection();
            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);
        }
        dataSource.close();
    }
}
Also used : Server(herddb.server.Server) Statement(java.sql.Statement) ServerConfiguration(herddb.server.ServerConfiguration) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) BasicDataSource(org.apache.commons.dbcp.BasicDataSource) Test(org.junit.Test)

Aggregations

Server (herddb.server.Server)36 Connection (java.sql.Connection)33 Test (org.junit.Test)33 ServerConfiguration (herddb.server.ServerConfiguration)32 Statement (java.sql.Statement)32 StaticClientSideMetadataProvider (herddb.server.StaticClientSideMetadataProvider)27 ClientConfiguration (herddb.client.ClientConfiguration)26 HDBClient (herddb.client.HDBClient)26 ResultSet (java.sql.ResultSet)25 PreparedStatement (java.sql.PreparedStatement)22 SQLException (java.sql.SQLException)6 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 HDBException (herddb.client.HDBException)1 BasicHerdDBDataSource (herddb.jdbc.BasicHerdDBDataSource)1 TableSpace (herddb.model.TableSpace)1 SQLPlanner (herddb.sql.SQLPlanner)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 List (java.util.List)1 Set (java.util.Set)1