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");
}
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);
}
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());
}
}
}
}
}
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());
}
}
}
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();
}
}
Aggregations