Search in sources :

Example 81 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class CheckBigIntConversionTest method test.

@Test
public void test() throws Exception {
    try (Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(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 statement = con.createStatement()) {
                statement.execute("CREATE TABLE mytable (key BIGINT primary key)");
                /* With high enough longs the value was converted to double loosing "precision" */
                long value = 72057598332895235L;
                try (PreparedStatement insert = con.prepareStatement("INSERT INTO mytable (key) values(" + value + ")")) {
                    insert.executeUpdate();
                }
                try (PreparedStatement selectKey = con.prepareStatement("SELECT key FROM mytable")) {
                    try (ResultSet rs = selectKey.executeQuery()) {
                        while (rs.next()) {
                            Long result = (Long) rs.getObject(1);
                            if (result.longValue() != value) {
                                throw new IllegalStateException(value + " != " + result);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : StaticClientSideMetadataProvider(herddb.server.StaticClientSideMetadataProvider) HDBClient(herddb.client.HDBClient) Server(herddb.server.Server) Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 82 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class HerdDBCLI method describeRawLedger.

private static void describeRawLedger(long ledgerId, long fromId, long toId, HerdDBDataSource datasource) throws Exception {
    if (!datasource.getUrl().contains(":zookeeper:")) {
        // not cluster
        System.out.println("Not a cluster URL: " + datasource.getUrl());
        return;
    }
    // start embedded client
    datasource.getConnection().close();
    ClientConfiguration configuration = datasource.getClient().getConfiguration();
    try (ZookeeperMetadataStorageManager zk = buildMetadataStorageManager(datasource)) {
        BookkeeperCommitLogManager.scanRawLedger(ledgerId, fromId, toId, configuration, zk, (BookkeeperCommitLogManager.LogEntryWithSequenceNumber nextEntry) -> {
            println(nextEntry.logSequenceNumber.ledgerId + "," + nextEntry.logSequenceNumber.offset + "," + nextEntry.entry.toString());
        });
    }
}
Also used : ZookeeperMetadataStorageManager(herddb.cluster.ZookeeperMetadataStorageManager) LogEntryWithSequenceNumber(herddb.file.FileCommitLog.LogEntryWithSequenceNumber) ClientConfiguration(herddb.client.ClientConfiguration)

Example 83 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class HerdDBCLI method buildMetadataStorageManager.

private static ZookeeperMetadataStorageManager buildMetadataStorageManager(HerdDBDataSource datasource) throws MetadataStorageManagerException {
    ClientConfiguration configuration = datasource.getClient().getConfiguration();
    if (!datasource.getUrl().contains(":zookeeper:")) {
        // not cluster
        return null;
    }
    String zkAddress = configuration.getString(PROPERTY_ZOOKEEPER_ADDRESS, PROPERTY_ZOOKEEPER_ADDRESS_DEFAULT);
    String zkPath = configuration.getString(PROPERTY_ZOOKEEPER_PATH, PROPERTY_ZOOKEEPER_PATH_DEFAULT);
    int sessionTimeout = configuration.getInt(PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, 60000);
    ZookeeperMetadataStorageManager zk = new ZookeeperMetadataStorageManager(zkAddress, sessionTimeout, zkPath);
    zk.start(false);
    return zk;
}
Also used : ZookeeperMetadataStorageManager(herddb.cluster.ZookeeperMetadataStorageManager) ClientConfiguration(herddb.client.ClientConfiguration)

Example 84 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class SimpleClientScanTest method test.

@Test
public void test() throws Exception {
    try (Server server = new Server(newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        try (HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()));
            HDBConnection connection = client.openConnection()) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            long resultCreateTable = connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id string primary key, n1 long, n2 integer)", 0, false, true, Collections.emptyList()).updateCount;
            Assert.assertEquals(1, resultCreateTable);
            for (int i = 0; i < 99; i++) {
                Assert.assertEquals(1, connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", 0, false, true, Arrays.asList("test_" + i, 1, 2)).updateCount);
            }
            assertEquals(99, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable", true, Collections.emptyList(), 0, 0, 10, true).consume().size());
            // maxRows
            assertEquals(17, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable", true, Collections.emptyList(), 0, 17, 10, true).consume().size());
            // empty result set
            assertEquals(0, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='none'", true, Collections.emptyList(), 0, 0, 10, true).consume().size());
            // single fetch result test
            assertEquals(1, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test_1'", true, Collections.emptyList(), 0, 0, 10, true).consume().size());
            // agregation in transaction, this is trickier than what you can think
            long tx = connection.beginTransaction(TableSpace.DEFAULT);
            assertEquals(1, connection.executeScan(TableSpace.DEFAULT, "SELECT count(*) FROM mytable WHERE id='test_1'", true, Collections.emptyList(), tx, 0, 10, true).consume().size());
            connection.rollbackTransaction(TableSpace.DEFAULT, tx);
            assertEquals(0, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id=?", true, Arrays.<Object>asList((Object) null), 0, 0, 10, true).consume().size());
        }
    }
}
Also used : HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Example 85 with ClientConfiguration

use of herddb.client.ClientConfiguration in project herddb by diennea.

the class SimpleClientScanTest method scanMultiChunk.

@Test
public void scanMultiChunk() throws Exception {
    try (Server server = new Server(newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
        server.start();
        server.waitForStandaloneBoot();
        ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
        // more than one socket
        clientConfiguration.set(ClientConfiguration.PROPERTY_MAX_CONNECTIONS_PER_SERVER, 10);
        try (HDBClient client = new HDBClient(clientConfiguration);
            HDBConnection connection = client.openConnection()) {
            client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
            long resultCreateTable = connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id string primary key, n1 long, n2 integer)", 0, false, true, Collections.emptyList()).updateCount;
            Assert.assertEquals(1, resultCreateTable);
            for (int i = 0; i < 99; i++) {
                Assert.assertEquals(1, connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", 0, false, true, Arrays.asList("test_" + i, 1, 2)).updateCount);
            }
            checkUseOnlyOneSocket(connection, server);
            checkNoScannersOnTheServer(server);
            checkCloseScannerOnConnectionClose(client, connection, server, true);
            checkNoScannersOnTheServer(server);
            checkCloseScannerOnConnectionClose(client, connection, server, false);
            checkNoScannersOnTheServer(server);
            checkCloseResultSetNotFullyScanned(connection, server, true);
            checkNoScannersOnTheServer(server);
            checkCloseResultSetNotFullyScanned(connection, server, false);
            checkNoScannersOnTheServer(server);
            checkCloseResultSetNotFullyScannedWithTransactionAndAggregation(connection, server, true);
            checkNoScannersOnTheServer(server);
            checkCloseResultSetNotFullyScannedWithTransactionAndAggregation(connection, server, false);
            checkNoScannersOnTheServer(server);
        }
        checkNoScannersOnTheServer(server);
    }
}
Also used : HDBConnection(herddb.client.HDBConnection) HDBClient(herddb.client.HDBClient) ClientConfiguration(herddb.client.ClientConfiguration) Test(org.junit.Test)

Aggregations

ClientConfiguration (herddb.client.ClientConfiguration)89 HDBClient (herddb.client.HDBClient)83 Test (org.junit.Test)79 Server (herddb.server.Server)56 HDBConnection (herddb.client.HDBConnection)45 StaticClientSideMetadataProvider (herddb.server.StaticClientSideMetadataProvider)41 Connection (java.sql.Connection)39 Statement (java.sql.Statement)34 PreparedStatement (java.sql.PreparedStatement)30 ResultSet (java.sql.ResultSet)29 Table (herddb.model.Table)23 CreateTableStatement (herddb.model.commands.CreateTableStatement)23 InsertStatement (herddb.model.commands.InsertStatement)22 ServerConfiguration (herddb.server.ServerConfiguration)17 ScanResultSet (herddb.client.ScanResultSet)13 ByteArrayInputStream (java.io.ByteArrayInputStream)13 ProgressListener (herddb.backup.ProgressListener)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 HashSet (java.util.HashSet)12 Index (herddb.model.Index)9