use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.
the class TestAdhocCreateDropRole method testBasic.
@Test
public void testBasic() throws Exception {
System.out.println("\n\n-----\n testBasic \n-----\n\n");
String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");
VoltProjectBuilder builder = new VoltProjectBuilder();
// Need to parallel dbuilder as we modify builder
DeploymentBuilder dbuilder = new DeploymentBuilder(2, 1, 0);
builder.addLiteralSchema("create table FOO (" + "ID integer not null," + "VAL bigint, " + "constraint PK_TREE primary key (ID)" + ");\n" + "create table FOO_R (" + "ID integer not null," + "VAL bigint, " + "constraint PK_TREE_R primary key (ID)" + ");\n");
builder.addPartitionInfo("FOO", "ID");
dbuilder.setUseDDLSchema(true);
// Use random caps in role names to check case-insensitivity
dbuilder.addUsers(new DeploymentBuilder.UserInfo[] { new DeploymentBuilder.UserInfo("admin", "admin", new String[] { "Administrator" }) });
dbuilder.setSecurityEnabled(true);
dbuilder.setEnableCommandLogging(false);
boolean success = builder.compile(pathToCatalog, 2, 1, 0);
assertTrue("Schema compilation failed", success);
dbuilder.writeXML(pathToDeployment);
//MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = pathToCatalog;
config.m_pathToDeployment = pathToDeployment;
try {
startServer(config);
ClientConfig adminConfig = new ClientConfig("admin", "admin");
Client adminClient = ClientFactory.createClient(adminConfig);
ClientConfig userConfig = new ClientConfig("user", "user");
Client userClient = ClientFactory.createClient(userConfig);
adminClient.createConnection("localhost");
// Can't connect a user which doesn't exist
boolean threw = false;
try {
userClient.createConnection("localhost");
} catch (IOException ioe) {
ioe.printStackTrace();
threw = true;
assertTrue(ioe.getMessage().contains("Authentication rejected"));
}
assertTrue("Connecting bad user should have failed", threw);
// Add the user with the new role
dbuilder.addUsers(new UserInfo[] { new UserInfo("user", "user", new String[] { "NEWROLE" }) });
dbuilder.writeXML(pathToDeployment);
try {
adminClient.updateApplicationCatalog(null, new File(pathToDeployment));
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Should be able to add a user even with a role that doesn't exist");
}
// Check that we can connect the new user
try {
userClient.createConnection("localhost");
} catch (IOException ioe) {
ioe.printStackTrace();
fail("Should have been able to connect 'user'");
}
// Make sure the user doesn't actually have DEFAULTPROC permissions yet
threw = false;
try {
userClient.callProcedure("FOO.insert", 0, 0);
} catch (ProcCallException pce) {
pce.printStackTrace();
threw = true;
}
assertTrue("'user' shouldn't be able to call procedures yet", threw);
// Okay, it's showtime. Let's add the role through live DDL
try {
adminClient.callProcedure("@AdHoc", "create role NEWROLE with DEFAULTPROC");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Creating role should have succeeded");
}
try {
adminClient.updateApplicationCatalog(null, new File(pathToDeployment));
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Adding 'user' should have succeeded this time");
}
// Make sure the user now has DEFAULTPROC permissions
try {
userClient.callProcedure("FOO.insert", 0, 0);
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("'user' should be able to call default procs now");
}
threw = false;
try {
adminClient.callProcedure("@AdHoc", "create role NEWROLE with ALLPROC");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("already exists"));
threw = true;
}
assertTrue("Shouldn't be able to 'create' same role twice", threw);
threw = false;
try {
// Use random caps in role names to check case-insensitivity
adminClient.callProcedure("@AdHoc", "create role aDministrator with ALLPROC");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("already exists"));
threw = true;
}
assertTrue("Shouldn't be able to 'create' ADMINISTRATOR role", threw);
threw = false;
try {
adminClient.callProcedure("@AdHoc", "create role USER with ALLPROC");
} catch (ProcCallException pce) {
assertTrue(pce.getMessage().contains("already exists"));
threw = true;
}
assertTrue("Shouldn't be able to 'create' USER role", threw);
try {
adminClient.callProcedure("@AdHoc", "drop role NEWROLE;");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Should be able to drop role NEWROLE");
}
// Can't drop twice
try {
adminClient.callProcedure("@AdHoc", "drop role NEWROLE;");
} catch (ProcCallException pce) {
pce.printStackTrace();
threw = true;
}
assertTrue("Can't vanilla DROP a role which doesn't exist", threw);
// unless you use IF EXISTS
try {
adminClient.callProcedure("@AdHoc", "drop role NEWROLE if exists;");
} catch (ProcCallException pce) {
pce.printStackTrace();
fail("Should be able to drop role NEWROLE if exists");
}
// Make sure the user doesn't actually have DEFAULTPROC permissions any more
threw = false;
try {
userClient.callProcedure("FOO.insert", 0, 0);
} catch (ProcCallException pce) {
pce.printStackTrace();
threw = true;
}
assertTrue("'user' shouldn't be able to call procedures yet", threw);
threw = false;
try {
adminClient.callProcedure("@AdHoc", "drop role USER;");
} catch (ProcCallException pce) {
threw = true;
assertTrue(pce.getMessage().contains("You may not drop the built-in role"));
pce.printStackTrace();
}
assertTrue("Shouldn't be able to drop role USER", threw);
// CHeck the administrator error message, there should end up being multiple
// reasons why we can't get rid of this role (like, we will require you to always
// have a user with this role)
threw = false;
try {
// Use random caps in role names to check case-insensitivity
adminClient.callProcedure("@AdHoc", "drop role adMinistrator;");
} catch (ProcCallException pce) {
threw = true;
assertTrue(pce.getMessage().contains("You may not drop the built-in role"));
pce.printStackTrace();
}
assertTrue("Shouldn't be able to drop role ADMINISTRATOR", threw);
// Make sure that we can't get rid of the administrator user
dbuilder.removeUser("admin");
dbuilder.writeXML(pathToDeployment);
threw = false;
try {
adminClient.updateApplicationCatalog(null, new File(pathToDeployment));
} catch (ProcCallException pce) {
pce.printStackTrace();
threw = true;
}
assertTrue("Shouldn't be able to remove the last remaining ADMINSTRATOR user", threw);
} finally {
teardownSystem();
}
}
use of org.voltdb.client.ClientConfig 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.client.ClientConfig in project voltdb by VoltDB.
the class IndexOverflowDebugTool method testSimple.
public void testSimple() throws Exception {
String simpleSchema = "CREATE TABLE P1 (\n" + " ID INTEGER DEFAULT '0' NOT NULL,\n" + " TINY TINYINT NOT NULL,\n" + " SMALL SMALLINT NOT NULL,\n" + " BIG BIGINT NOT NULL,\n" + " PRIMARY KEY (ID)\n" + ");\n" + "CREATE UNIQUE INDEX I1 ON P1 (ID, TINY);\n" + "\n" + "CREATE TABLE R1 (\n" + " ID INTEGER DEFAULT '0' NOT NULL,\n" + " TINY TINYINT NOT NULL,\n" + " SMALL SMALLINT NOT NULL,\n" + " BIG BIGINT NOT NULL,\n" + " PRIMARY KEY (ID)\n" + ");";
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(simpleSchema);
builder.addPartitionInfo("P1", "ID");
builder.addStmtProcedure("nocrash", "select * from P1 where ID = 6000000000;");
builder.addStmtProcedure("crash", "UPDATE P1 SET BIG = BIG + 4 WHERE P1.ID>= 5200704751286217677");
builder.addStmtProcedure("crash2", "SELECT * FROM P1 WHERE P1.ID>-6611959682909750107");
builder.addStmtProcedure("crash3", "SELECT * FROM P1 INNER JOIN R1 ON P1.ID = R1.BIG");
builder.addStmtProcedure("crash4", "SELECT * FROM P1 WHERE P1.ID = 5 AND P1.TINY > -2000;");
boolean success = builder.compile(Configuration.getPathToCatalogForTest("indexoverflow.jar"), 1, 1, 0);
assert (success);
MiscUtils.copyFile(builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("indexoverflow.xml"));
VoltDB.Configuration config = new VoltDB.Configuration();
config.m_pathToCatalog = Configuration.getPathToCatalogForTest("indexoverflow.jar");
config.m_pathToDeployment = Configuration.getPathToCatalogForTest("indexoverflow.xml");
config.m_backend = BackendTarget.NATIVE_EE_IPC;
config.m_ipcPort = 10001;
ServerThread localServer = new ServerThread(config);
localServer.start();
localServer.waitForInitialization();
ClientConfig clientConfig = new ClientConfig();
Client client = ClientFactory.createClient(clientConfig);
client.createConnection("127.0.0.1");
client.callProcedure("P1.insert", 5, 5, 5, 5);
ClientResponse cr = client.callProcedure("crash4");
assert (cr.getStatus() == ClientResponse.SUCCESS);
assert (cr.getResults().length == 1);
assert (cr.getResults()[0].getRowCount() == 1);
client.close();
client = null;
localServer.shutdown();
localServer = null;
System.gc();
}
use of org.voltdb.client.ClientConfig in project voltdb by VoltDB.
the class ScanPerfTest method testHaltLiveRejoinOnOverflow.
@Test
public void testHaltLiveRejoinOnOverflow() throws Exception {
LocalCluster cluster = null;
Client client = null;
VoltTable pTable = TableHelper.quickTable("P (ID:BIGINT-N, VALUE:BIGINT-N) PK(ID)");
// build and compile a catalog
System.out.println("Compiling catalog.");
VoltProjectBuilder builder = new VoltProjectBuilder();
builder.addLiteralSchema(TableHelper.ddlForTable(pTable, false));
builder.addLiteralSchema("PARTITION TABLE P ON COLUMN ID;\n" + "CREATE PROCEDURE FROM CLASS org.voltdb.planner.ScanPerfTest$ScanTable;\n" + "PARTITION PROCEDURE ScanPerfTest$ScanTable ON TABLE P COLUMN ID;\n");
cluster = new LocalCluster("scanperf.jar", 8, 1, 0, BackendTarget.NATIVE_EE_JNI);
//cluster.setMaxHeap(10);
boolean success = cluster.compile(builder);
assertTrue(success);
//fail();
System.out.println("Starting cluster.");
cluster.setHasLocalServer(false);
cluster.overrideAnyRequestForValgrind();
cluster.startUp(true);
System.out.println("Getting client connected.");
ClientConfig clientConfig = new ClientConfig();
client = ClientFactory.createClient(clientConfig);
for (String address : cluster.getListenerAddresses()) {
client.createConnection(address);
}
System.out.println("Loading");
Random r = new Random();
// load up > 1gb data
fillTable(6000, client, r);
System.out.println("100% loaded.");
client.drain();
client.close();
System.out.println("Getting client re-connected.");
clientConfig = new ClientConfig();
clientConfig.setProcedureCallTimeout(Long.MAX_VALUE);
clientConfig.setMaxOutstandingTxns(50);
client = ClientFactory.createClient(clientConfig);
for (String address : cluster.getListenerAddresses()) {
client.createConnection(address);
}
long start = System.currentTimeMillis();
for (int i = 0; i < 12; i++) {
while ((System.currentTimeMillis() - start) < ((i + 1) * 5000)) {
client.callProcedure(new ScanCallback(), "ScanPerfTest$ScanTable", r.nextLong());
}
System.out.printf("Scanned at %.2f rows/sec when %.0f%% done.\n", rows.get() / (nanos.get() / 1000000000.0), ((i + 1) / 12.0) * 100);
System.out.printf("%d scans on an average of %d rows/partition\n", scans.get(), rows.get() / scans.get());
System.out.printf("%.2f scans per second\n", scans.get() / (nanos.get() / 1000000000.0));
}
System.out.println("Draining.");
client.drain();
client.close();
System.out.printf("Scanned at %f rows/sec after drain.\n", rows.get() / (nanos.get() / 1000000000.0));
cluster.shutDown();
}
use of org.voltdb.client.ClientConfig 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");
}
Aggregations