use of herddb.server.ServerConfiguration in project herddb by diennea.
the class JdbcDriverTest method testReuseSocketConnections.
@Test
public void testReuseSocketConnections() throws Exception {
ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
try (Server server = new Server(conf)) {
server.start();
server.waitForStandaloneBoot();
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl());
Connection connection2 = DriverManager.getConnection(server.getJdbcUrl());
Statement statement = connection.createStatement();
Statement statement2 = connection2.createStatement();
ResultSet rs = statement.executeQuery("SELECT * FROM SYSTABLES");
ResultSet rs2 = statement2.executeQuery("SELECT * FROM SYSTABLES")) {
int count = 0;
while (rs.next()) {
System.out.println("table: " + rs.getString(1));
count++;
}
assertTrue(count > 0);
// since 0.8.0 we will open multiple sockets, so this test may flap
assertTrue(server.getActualConnections().connections.size() <= 2 && server.getActualConnections().connections.size() >= 1);
}
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl());
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);
// since 0.8.0 we will open multiple sockets, so this test may flap
assertTrue(server.getActualConnections().connections.size() <= 3 && server.getActualConnections().connections.size() >= 1);
}
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class JdbcDriverTest method testNotPoolSQLConnectionsInJDBCDriverByDefault.
@Test
public void testNotPoolSQLConnectionsInJDBCDriverByDefault() throws Exception {
ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
try (Server server = new Server(conf)) {
server.start();
server.waitForStandaloneBoot();
Connection connection1;
Connection connection2;
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl())) {
connection1 = connection;
}
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl())) {
connection2 = connection;
}
assertNotSame(connection1, connection2);
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class JdbcDriverTest method testForcePoolSQLConnectionsInJDBCDriver.
@Test
public void testForcePoolSQLConnectionsInJDBCDriver() throws Exception {
ServerConfiguration conf = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
try (Server server = new Server(conf)) {
server.start();
server.waitForStandaloneBoot();
Connection connection1;
Connection connection2;
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl() + "?poolConnections=true")) {
connection1 = connection;
}
try (Connection connection = DriverManager.getConnection(server.getJdbcUrl() + "?poolConnections=true")) {
connection2 = connection;
}
assertSame(connection1, connection2);
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class HerdDBEmbeddedDataSource method startEmbeddedServer.
private void startEmbeddedServer() throws SQLException {
if (!serverInitialized) {
ServerConfiguration serverConfiguration = new ServerConfiguration(properties);
try {
serverConfiguration.readJdbcUrl(url);
} catch (RuntimeException err) {
throw new SQLException(err);
}
startServer = serverConfiguration.getBoolean("server.start", startServer);
String mode = serverConfiguration.getString(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_LOCAL);
if (ServerConfiguration.PROPERTY_MODE_LOCAL.equals(mode) || (ServerConfiguration.PROPERTY_MODE_STANDALONE.equals(mode) && startServer) || (ServerConfiguration.PROPERTY_MODE_CLUSTER.equals(mode) && startServer) || (ServerConfiguration.PROPERTY_MODE_DISKLESSCLUSTER.equals(mode) && startServer)) {
LOGGER.log(Level.INFO, "Booting Local Embedded HerdDB mode, url:" + url + ", properties:" + serverConfiguration);
server = new Server(serverConfiguration, statsLogger);
try {
server.start();
int waitForTableSpaceTimeout = getWaitForTableSpaceTimeout();
if (waitForTableSpaceTimeout > 0) {
server.waitForBootOfLocalTablespaces(waitForTableSpaceTimeout);
}
if (ServerConfiguration.PROPERTY_MODE_LOCAL.equals(mode) || ServerConfiguration.PROPERTY_MODE_STANDALONE.equals(mode)) {
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
}
} catch (Exception ex) {
throw new SQLException("Cannot boot embedded server " + ex, ex);
}
}
serverInitialized = true;
}
}
use of herddb.server.ServerConfiguration in project herddb by diennea.
the class JdbcDriverZookeeperTest method test.
@Test
public void test() throws Exception {
ServerConfiguration serverconfig_1 = TestUtils.newServerConfigurationWithAutoPort(folder.newFolder().toPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_NODEID, "server1");
serverconfig_1.set(ServerConfiguration.PROPERTY_PORT, 7867);
serverconfig_1.set(ServerConfiguration.PROPERTY_MODE, ServerConfiguration.PROPERTY_MODE_CLUSTER);
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_ADDRESS, testEnv.getAddress());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_PATH, testEnv.getPath());
serverconfig_1.set(ServerConfiguration.PROPERTY_ZOOKEEPER_SESSIONTIMEOUT, testEnv.getTimeout());
try (Server server = new Server(serverconfig_1)) {
server.start();
server.waitForStandaloneBoot();
try (Connection connection = DriverManager.getConnection("jdbc:herddb:zookeeper:" + testEnv.getAddress() + "" + testEnv.getPath());
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);
}
}
}
Aggregations