use of herddb.server.Server in project herddb by diennea.
the class ConnectionPoolMaxActiveTest method testMaxActive.
@Test
public void testMaxActive() throws Exception {
try (HerdDBEmbeddedDataSource dataSource = new HerdDBEmbeddedDataSource()) {
dataSource.setMaxActive(20);
dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
statement.execute("CREATE TABLE mytable (key string primary key, name string)");
}
Server server = dataSource.getServer();
List<Connection> connections = new ArrayList<>();
try {
for (int i = 0; i < 10; i++) {
Connection con = dataSource.getConnection();
connections.add(con);
try (Statement statement = con.createStatement()) {
assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1" + i + "','name1')"));
}
}
// this is the number of sockets
assertTrue(server.getConnectionCount() >= 1);
} finally {
for (Connection c : connections) {
c.close();
}
}
}
}
use of herddb.server.Server in project herddb by diennea.
the class GenericClientDataSourceTest method test.
@Test
public void test() throws Exception {
try (Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
server.start();
try (HerdDBDataSource dataSource = new HerdDBDataSource()) {
dataSource.setUrl(server.getJdbcUrl());
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);
}
}
}
}
use of herddb.server.Server in project herddb by diennea.
the class HerdDBResultSetTest method getStatement.
@Test
public void getStatement() throws Exception {
try (final Server server = new Server(TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath()))) {
server.start();
server.waitForStandaloneBoot();
try (final HDBClient client = new HDBClient(new ClientConfiguration(folder.newFolder().toPath()))) {
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
try (final BasicHerdDBDataSource dataSource = new BasicHerdDBDataSource(client)) {
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
statement.execute("CREATE TABLE mytable (c1 int primary key)");
}
try (final Connection con = dataSource.getConnection();
final PreparedStatement statement = con.prepareStatement("select * from mytable");
final ResultSet rows = statement.executeQuery()) {
Assert.assertEquals(statement, rows.getStatement());
}
}
}
}
}
use of herddb.server.Server in project herddb by diennea.
the class SimpleJoinTest 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 string primary key, name string)");
assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1','name1')"));
assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k2','name2')"));
assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k3','name3')"));
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable a" + " INNER JOIN mytable b ON 1=1")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(9, count);
}
}
}
}
}
use of herddb.server.Server in project herddb by diennea.
the class TransactionIsolationTest method test.
@Test
public void test() throws Exception {
try (HerdDBEmbeddedDataSource dataSource = new HerdDBEmbeddedDataSource()) {
dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_BASEDIR, folder.newFolder().getAbsolutePath());
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
statement.execute("CREATE TABLE mytable (key string primary key, name string)");
statement.execute("CREATE TABLE mytable2 (key string primary key, name string)");
}
Server server = dataSource.getServer();
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
assertEquals(1, statement.executeUpdate("INSERT INTO mytable (key,name) values('k1','name1')"));
assertEquals(Connection.TRANSACTION_READ_COMMITTED, con.getTransactionIsolation());
assertEquals(TableSpace.DEFAULT, con.getSchema());
assertTrue(con.getAutoCommit());
con.setAutoCommit(false);
{
HerdDBConnection hCon = (HerdDBConnection) con;
assertEquals(0, hCon.getTransactionId());
// force the creation of a transaction, by issuing a DML command
assertEquals(1, statement.executeUpdate("INSERT INTO mytable2 (key,name) values('c1','name1')"));
long tx = hCon.getTransactionId();
statement.executeQuery("SELECT * FROM mytable").close();
Transaction transaction = server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTransaction(tx);
// in TRANSACTION_READ_COMMITTED no lock is to be retained
assertTrue(transaction.locks.get("mytable").isEmpty());
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
statement.executeQuery("SELECT * FROM mytable").close();
LockHandle lock = transaction.lookupLock("mytable", Bytes.from_string("k1"));
assertFalse(lock.write);
statement.executeQuery("SELECT * FROM mytable FOR UPDATE").close();
lock = transaction.lookupLock("mytable", Bytes.from_string("k1"));
assertTrue(lock.write);
con.rollback();
assertNull(server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTransaction(tx));
}
// test SELECT ... FOR UPDATE
{
HerdDBConnection hCon = (HerdDBConnection) con;
assertEquals(0, hCon.getTransactionId());
con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
// force the creation of a transaction, by issuing a DML command
assertEquals(1, statement.executeUpdate("INSERT INTO mytable2 (key,name) values('c2','name1')"));
long tx = hCon.getTransactionId();
statement.executeQuery("SELECT * FROM mytable FOR UPDATE").close();
Transaction transaction = server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTransaction(tx);
LockHandle lock = transaction.lookupLock("mytable", Bytes.from_string("k1"));
assertTrue(lock.write);
con.rollback();
assertNull(server.getManager().getTableSpaceManager(TableSpace.DEFAULT).getTransaction(tx));
}
}
}
}
Aggregations