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(new ServerConfiguration(folder.newFolder().toPath()))) {
server.start();
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, 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, Arrays.asList("test_" + i, 1, 2)).updateCount);
}
assertEquals(99, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable", Collections.emptyList(), 0, 0, 10).consume().size());
// maxRows
assertEquals(17, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable", Collections.emptyList(), 0, 17, 10).consume().size());
// empty result set
assertEquals(0, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='none'", Collections.emptyList(), 0, 0, 10).consume().size());
// single fetch result test
assertEquals(1, connection.executeScan(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test_1'", Collections.emptyList(), 0, 0, 10).consume().size());
}
}
}
use of herddb.client.ClientConfiguration in project herddb by diennea.
the class SimpleClientServerAutoTransactionTest method test.
@Test
public void test() throws Exception {
Path baseDir = folder.newFolder().toPath();
;
String _baseDir = baseDir.toString();
try (Server server = new Server(new ServerConfiguration(baseDir))) {
server.start();
ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
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, Collections.emptyList()).updateCount;
Assert.assertEquals(1, resultCreateTable);
DMLResult executeUpdateResult = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", TransactionContext.AUTOTRANSACTION_ID, false, Arrays.asList("test", 1, 2));
long tx = executeUpdateResult.transactionId;
long countInsert = executeUpdateResult.updateCount;
Assert.assertEquals(1, countInsert);
GetResult res = connection.executeGet(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", tx, Collections.emptyList());
;
Map<String, Object> record = res.data;
Assert.assertNotNull(record);
assertEquals("test", record.get("id"));
assertEquals(Long.valueOf(1), record.get("n1"));
assertEquals(Integer.valueOf(2), record.get("n2"));
connection.commitTransaction(TableSpace.DEFAULT, tx);
try (ScanResultSet scan = connection.executeScan(server.getManager().getVirtualTableSpaceId(), "SELECT * FROM sysconfig", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
for (Map<String, Object> aa : all) {
String name = (String) aa.get("name");
assertEquals("server.base.dir", name);
String value = (String) aa.get("value");
assertEquals(_baseDir, value);
}
}
try (ScanResultSet scan = connection.executeScan(null, "SELECT * FROM " + server.getManager().getVirtualTableSpaceId() + ".sysclients", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
for (Map<String, Object> aa : all) {
assertEquals("jvm-local", aa.get("address"));
assertEquals("1", aa.get("id") + "");
assertEquals(ClientConfiguration.PROPERTY_CLIENT_USERNAME_DEFAULT, aa.get("username"));
assertNotNull(aa.get("connectionts"));
}
assertEquals(1, all.size());
}
}
}
}
use of herddb.client.ClientConfiguration in project herddb by diennea.
the class SimpleClientServerTest method test.
@Test
public void test() throws Exception {
Path baseDir = folder.newFolder().toPath();
;
String _baseDir = baseDir.toString();
try (Server server = new Server(new ServerConfiguration(baseDir))) {
server.start();
server.waitForStandaloneBoot();
ClientConfiguration clientConfiguration = new ClientConfiguration(folder.newFolder().toPath());
try (HDBClient client = new HDBClient(clientConfiguration);
HDBConnection connection = client.openConnection()) {
client.setClientSideMetadataProvider(new StaticClientSideMetadataProvider(server));
assertTrue(connection.waitForTableSpace(TableSpace.DEFAULT, 100));
assertFalse(connection.waitForTableSpace("bad-tablespace", 100));
long resultCreateTable = connection.executeUpdate(TableSpace.DEFAULT, "CREATE TABLE mytable (id string primary key, n1 long, n2 integer)", 0, false, Collections.emptyList()).updateCount;
Assert.assertEquals(1, resultCreateTable);
long tx = connection.beginTransaction(TableSpace.DEFAULT);
long countInsert = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", tx, false, Arrays.asList("test", 1, 2)).updateCount;
Assert.assertEquals(1, countInsert);
long countInsert2 = connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", tx, false, Arrays.asList("test2", 2, 3)).updateCount;
Assert.assertEquals(1, countInsert2);
GetResult res = connection.executeGet(TableSpace.DEFAULT, "SELECT * FROM mytable WHERE id='test'", tx, Collections.emptyList());
Map<String, Object> record = res.data;
Assert.assertNotNull(record);
assertEquals("test", record.get("id"));
assertEquals(Long.valueOf(1), record.get("n1"));
assertEquals(Integer.valueOf(2), record.get("n2"));
List<DMLResult> executeUpdates = connection.executeUpdates(TableSpace.DEFAULT, "UPDATE mytable set n2=? WHERE id=?", tx, false, Arrays.asList(Arrays.asList(1, "test"), Arrays.asList(2, "test2"), Arrays.asList(3, "test_not_exists")));
assertEquals(3, executeUpdates.size());
assertEquals(1, executeUpdates.get(0).updateCount);
assertEquals(1, executeUpdates.get(1).updateCount);
assertEquals(0, executeUpdates.get(2).updateCount);
assertEquals(tx, executeUpdates.get(0).transactionId);
assertEquals(tx, executeUpdates.get(1).transactionId);
assertEquals(tx, executeUpdates.get(2).transactionId);
connection.commitTransaction(TableSpace.DEFAULT, tx);
try (ScanResultSet scan = connection.executeScan(server.getManager().getVirtualTableSpaceId(), "SELECT * FROM sysconfig", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
for (Map<String, Object> aa : all) {
String name = (String) aa.get("name");
assertEquals("server.base.dir", name);
String value = (String) aa.get("value");
assertEquals(_baseDir, value);
}
}
try (ScanResultSet scan = connection.executeScan(null, "SELECT * FROM " + server.getManager().getVirtualTableSpaceId() + ".sysclients", Collections.emptyList(), 0, 0, 10)) {
List<Map<String, Object>> all = scan.consume();
for (Map<String, Object> aa : all) {
assertEquals("jvm-local", aa.get("address"));
assertNotNull(aa.get("id"));
assertEquals(ClientConfiguration.PROPERTY_CLIENT_USERNAME_DEFAULT, aa.get("username"));
assertNotNull(aa.get("connectionts"));
}
assertEquals(1, all.size());
}
}
}
}
use of herddb.client.ClientConfiguration in project herddb by diennea.
the class AtomicCounterTest method test.
@Test
public void test() throws Exception {
try (Server server = new Server(new ServerConfiguration(folder.newFolder().toPath()))) {
server.start();
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, Collections.emptyList()).updateCount;
Assert.assertEquals(1, resultCreateTable);
Assert.assertEquals(1, connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", 0, false, Arrays.asList("test_0", 1, 2)).updateCount);
Map<String, Object> newValue = connection.executeUpdate(TableSpace.DEFAULT, "UPDATE mytable set n1= n1+1 where id=?", 0, true, Arrays.asList("test_0")).newvalue;
assertEquals(Long.valueOf(2), newValue.get("n1"));
}
}
}
use of herddb.client.ClientConfiguration in project herddb by diennea.
the class JAASKerberosTest method test.
@Test
public void test() throws Exception {
ServerConfiguration serverConfig = new ServerConfiguration(folder.newFolder().toPath());
serverConfig.set(ServerConfiguration.PROPERTY_HOST, "localhost.localdomain");
try (Server server = new Server(serverConfig)) {
server.start();
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, Collections.emptyList()).updateCount;
Assert.assertEquals(1, resultCreateTable);
Assert.assertEquals(1, connection.executeUpdate(TableSpace.DEFAULT, "INSERT INTO mytable (id,n1,n2) values(?,?,?)", 0, false, Arrays.asList("test_0", 1, 2)).updateCount);
Map<String, Object> newValue = connection.executeUpdate(TableSpace.DEFAULT, "UPDATE mytable set n1= n1+1 where id=?", 0, true, Arrays.asList("test_0")).newvalue;
assertEquals(Long.valueOf(2), newValue.get("n1"));
}
} finally {
System.clearProperty("java.security.auth.login.config");
}
}
Aggregations