use of org.voltdb.ServerThread in project voltdb by VoltDB.
the class TestBlobType method testVarbinary.
public void testVarbinary() throws Exception {
String simpleSchema = "create table blah (" + "ival bigint default 0 not null, " + "b varbinary(256) default null, " + "s varchar(256) default null," + "bs varbinary(2) default null," + "PRIMARY KEY(ival));\n" + "create index idx on blah (ival,s);";
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(simpleSchema);
builder.addPartitionInfo("blah", "ival");
builder.addStmtProcedure("Insert", "insert into blah values (?, ?, ?, ?);", null);
builder.addStmtProcedure("Select", "select * from blah;", null);
builder.addStmtProcedure("Update", "update blah set b = ? where ival = ?", null);
builder.addStmtProcedure("FindString", "select * from blah where ival = ? and s = ?", null);
builder.addStmtProcedure("LiteralUpdate", "update blah set b = '0a1A' where ival = 5", null);
builder.addStmtProcedure("LiteralInsert", "insert into blah values (13, 'aabbcc', 'hi', 'aabb');", null);
builder.addProcedures(VarbinaryStringLookup.class);
boolean success = builder.compile(Configuration.getPathToCatalogForTest("binarytest.jar"), 1, 1, 0);
assertTrue(success);
MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("binarytest.xml"));
ServerThread localServer = null;
Client client = null;
try {
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = Configuration.getPathToCatalogForTest("binarytest.jar");
config.m_pathToDeployment = Configuration.getPathToCatalogForTest("binarytest.xml");
config.m_backend = BackendTarget.NATIVE_EE_JNI;
localServer = new ServerThread(config);
localServer.start();
localServer.waitForInitialization();
client = ClientFactory.createClient();
client.createConnection("localhost");
// insert data
ClientResponse cr = client.callProcedure("Insert", 5, new byte[] { 'a', 'b', 'c', 'd' }, "hi", new byte[] { 'a' });
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
// make sure strings as bytes works
cr = client.callProcedure("FindString", 5, "hi".getBytes("UTF-8"));
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
cr = client.callProcedure("VarbinaryStringLookup", 5, "hi".getBytes("UTF-8"), "hi");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
assertEquals(1, cr.getResults()[1].getRowCount());
// literal update
cr = client.callProcedure("LiteralUpdate");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
assertEquals(1, cr.getResults()[0].asScalarLong());
// see if we can get the binary value from the '0a1A' update above
cr = client.callProcedure("Select");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
VoltTable t = cr.getResults()[0];
assertEquals(1, t.getRowCount());
t.resetRowPosition();
t.advanceRow();
byte[] vb = t.getVarbinary("b");
assertEquals(2, vb.length);
assertEquals((byte) 10, vb[0]);
assertEquals((byte) 26, vb[1]);
// try again with generic call
vb = (byte[]) t.get("b", VoltType.VARBINARY);
assertEquals(2, vb.length);
assertEquals((byte) 10, vb[0]);
assertEquals((byte) 26, vb[1]);
// insert hex data
cr = client.callProcedure("Insert", 9, "aabbccdd", "hi", "aabb");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
// literal inserts
cr = client.callProcedure("LiteralInsert");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
assertEquals(1, cr.getResults()[0].asScalarLong());
// adhoc queries
cr = client.callProcedure("@AdHoc", "update blah set b = 'Bb01' where ival = 5");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
assertEquals(1, cr.getResults()[0].asScalarLong());
cr = client.callProcedure("@AdHoc", "insert into blah values (12, 'aabbcc', 'hi', 'aabb');");
assertTrue(cr.getStatus() == ClientResponse.SUCCESS);
assertEquals(1, cr.getResults()[0].getRowCount());
assertEquals(1, cr.getResults()[0].asScalarLong());
// try bad value insert for normal query
try {
cr = client.callProcedure("Insert", 6, new byte[] { 'a' }, "hi", new byte[] { 'a', 'b', 'c' });
fail();
} catch (ProcCallException e) {
}
// try invalid hex literal strings in adhoc query
try {
cr = client.callProcedure("@AdHoc", "update blah set b = 'Bb01nt' where ival = 5");
fail();
} catch (ProcCallException e) {
}
try {
cr = client.callProcedure("@AdHoc", "update blah set b = 'Bb0' where ival = 5");
fail();
} catch (ProcCallException e) {
}
// test invalid comparison
try {
cr = client.callProcedure("@AdHoc", "update blah set ival = 5 where b = 'Bb01'");
fail();
} catch (ProcCallException e) {
}
// test too long varbinary
byte[] overlong = new byte[VoltType.MAX_VALUE_LENGTH + 1];
try {
cr = client.callProcedure("Insert", 6, new byte[] { 'a' }, "hi", overlong);
fail();
} catch (ProcCallException e) {
}
} finally {
// stop execution
if (client != null) {
client.close();
}
if (localServer != null) {
localServer.shutdown();
localServer.join();
}
}
}
use of org.voltdb.ServerThread in project voltdb by VoltDB.
the class TestLiveTableSchemaMigration method migrateSchemaUsingAlter.
/**
* Assuming given tables have schema metadata, fill them with random data
* and compare a pure-java schema migration with an EE schema migration.
*/
void migrateSchemaUsingAlter(VoltTable t1, VoltTable t2, boolean withData) throws Exception {
ServerThread server = null;
Client client = null;
TableHelper helper = new TableHelper();
try {
String alterText = TableHelper.getAlterTableDDLToMigrate(t1, t2);
if (withData) {
helper.randomFill(t1, 1000, 1024);
}
String catPath1 = catalogPathForTable(t1, "t1.jar");
DeploymentBuilder depBuilder = new DeploymentBuilder(1, 1, 0);
depBuilder.setVoltRoot("/tmp/rootbar");
depBuilder.setUseDDLSchema(true);
// disable logging
depBuilder.configureLogging("/tmp/foobar", "/tmp/goobar", false, false, 1, 1, 3);
String deployment = depBuilder.getXML();
File deploymentFile = VoltProjectBuilder.writeStringToTempFile(deployment);
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToDeployment = deploymentFile.getAbsolutePath();
config.m_pathToCatalog = catPath1;
config.m_ipcPort = 10000;
//config.m_backend = BackendTarget.NATIVE_EE_IPC;
server = new ServerThread(config);
server.start();
server.waitForInitialization();
System.out.printf("PRE: %s\n", TableHelper.ddlForTable(t1, false));
System.out.printf("POST: %s\n", TableHelper.ddlForTable(t2, false));
TableHelper.migrateTable(t1, t2);
t2 = TableHelper.sortTable(t2);
ClientConfig clientConfig = new ClientConfig();
client = ClientFactory.createClient(clientConfig);
client.createConnection("localhost");
TableHelper.loadTable(client, t1);
if (alterText.trim().length() > 0) {
ClientResponseImpl response = (ClientResponseImpl) client.callProcedure("@AdHoc", alterText, null);
System.out.println(response.toJSONString());
}
VoltTable t3 = client.callProcedure("@AdHoc", "select * from FOO").getResults()[0];
t3 = TableHelper.sortTable(t3);
// compare the tables
StringBuilder sb = new StringBuilder();
if (!TableHelper.deepEqualsWithErrorMsg(t2, t3, sb)) {
System.out.println("Table Mismatch");
//System.out.printf("PRE: %s\n", t2.toFormattedString());
//System.out.printf("POST: %s\n", t3.toFormattedString());
System.out.println(sb.toString());
fail();
}
} finally {
if (client != null) {
client.close();
}
if (server != null) {
server.shutdown();
}
}
}
use of org.voltdb.ServerThread in project voltdb by VoltDB.
the class TestClientClose method setUp.
@Override
public void setUp() {
try {
CatalogBuilder catBuilder = new CatalogBuilder();
catBuilder.addSchema(getClass().getResource("clientfeatures.sql"));
catBuilder.addProcedures(ArbitraryDurationProc.class);
boolean success = catBuilder.compile(Configuration.getPathToCatalogForTest("timeouts.jar"));
assert (success);
depBuilder = new DeploymentBuilder(1, 1, 0);
depBuilder.writeXML(Configuration.getPathToCatalogForTest("timeouts.xml"));
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = Configuration.getPathToCatalogForTest("timeouts.jar");
config.m_pathToDeployment = Configuration.getPathToCatalogForTest("timeouts.xml");
localServer = new ServerThread(config);
localServer.start();
localServer.waitForInitialization();
ClientFactory.m_preserveResources = false;
while (ClientFactory.m_activeClientCount > 0) {
try {
ClientFactory.decreaseClientNum();
} catch (InterruptedException e) {
}
}
// The DNS cache is always initialized in the started state
ReverseDNSCache.start();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
use of org.voltdb.ServerThread in project voltdb by VoltDB.
the class TPCCDebugTest method setUp.
@Override
public void setUp() throws IOException {
Class<?>[] procedures = ALL_PROCEDURES;
int siteCount = 1;
BackendTarget target = BackendTarget.NATIVE_EE_JNI;
String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
String catalogJar = testDir + File.separator + JAR;
TPCCProjectBuilder pb = new TPCCProjectBuilder();
pb.addDefaultSchema();
pb.addDefaultPartitioning();
pb.addProcedures(procedures);
pb.addSupplementalClasses(SUPPLEMENTALS);
pb.compile(catalogJar, siteCount, 0);
// start VoltDB server using hzsqlsb backend
server = new ServerThread(catalogJar, pb.getPathToDeployment(), target);
server.start();
server.waitForInitialization();
ClientConfig clientConfig = new ClientConfig("program", "none");
client = ClientFactory.createClient(clientConfig);
// connect
client.createConnection("localhost");
}
use of org.voltdb.ServerThread in project voltdb by VoltDB.
the class HTTPDBenchmark method JSONBench.
public void JSONBench(int clientCount, int iterations) throws Exception {
ServerThread server = startup();
Thread.sleep(1000);
JSONClient[] clients = new JSONClient[clientCount];
for (int i = 0; i < clientCount; i++) clients[i] = new JSONClient(i, iterations);
long execTime = 0;
long start = System.nanoTime();
for (JSONClient client : clients) {
client.start();
}
for (JSONClient client : clients) {
client.join();
execTime += client.totalExecTime;
}
long finish = System.nanoTime();
double seconds = (finish - start) / (1000d * 1000d * 1000d);
double rate = (iterations * clientCount) / seconds;
double latency = execTime / (double) (iterations * clientCount);
latency /= 1000d * 1000d;
System.out.printf("Simple bench did %.2f iterations / sec at %.2f ms latency per txn.\n", rate, latency);
server.shutdown();
server.join();
}
Aggregations