use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.
the class MaxRowsTest 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")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
statement.setMaxRows(2);
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(2, count);
}
statement.setMaxRows(0);
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
statement.setMaxRows(Integer.MAX_VALUE);
try (ResultSet rs = statement.executeQuery("SELECT * FROM mytable")) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
try (PreparedStatement ps = con.prepareStatement("SELECT * FROM mytable")) {
try (ResultSet rs = ps.executeQuery()) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
ps.setMaxRows(2);
try (ResultSet rs = ps.executeQuery()) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(2, count);
}
ps.setMaxRows(0);
try (ResultSet rs = ps.executeQuery()) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
ps.setMaxRows(Integer.MAX_VALUE);
try (ResultSet rs = ps.executeQuery()) {
int count = 0;
while (rs.next()) {
count++;
}
assertEquals(3, count);
}
}
}
}
}
}
use of herddb.server.StaticClientSideMetadataProvider 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.StaticClientSideMetadataProvider 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.StaticClientSideMetadataProvider in project herddb by diennea.
the class CreateTableSpaceWithStaticMetadataProviderTest 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());
dataSource.setMaxActive(20);
try (Connection con = dataSource.getConnection()) {
}
assertTrue(dataSource.getClient().getClientSideMetadataProvider() instanceof StaticClientSideMetadataProvider);
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
String leader = dataSource.getClient().getClientSideMetadataProvider().getTableSpaceLeader(TableSpace.DEFAULT);
statement.execute("CREATE TABLESPACE 'mytablespace','wait:5000','leader:" + leader + "'");
statement.execute("CREATE TABLE mytablespace.mytable(pk int primary key)");
}
}
}
use of herddb.server.StaticClientSideMetadataProvider in project herddb by diennea.
the class CreateTableSpaceWithStaticMetadataProviderTest method testStandAloneServer.
@Test
public void testStandAloneServer() 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());
dataSource.getProperties().setProperty(ClientConfiguration.PROPERTY_MODE, ClientConfiguration.PROPERTY_MODE_STANDALONE);
dataSource.getProperties().setProperty(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_STANDALONE);
dataSource.setStartServer(true);
dataSource.setMaxActive(20);
try (Connection con = dataSource.getConnection()) {
}
assertTrue(dataSource.getClient().getClientSideMetadataProvider() instanceof StaticClientSideMetadataProvider);
try (Connection con = dataSource.getConnection();
Statement statement = con.createStatement()) {
String leader = dataSource.getClient().getClientSideMetadataProvider().getTableSpaceLeader(TableSpace.DEFAULT);
System.out.println("leader:" + leader);
statement.execute("CREATE TABLESPACE 'mytablespace','wait:5000','leader:" + leader + "'");
statement.execute("CREATE TABLE mytablespace.mytable(pk int primary key)");
}
}
}
Aggregations