public void testCatalogUpdateAfterRejoin() throws Exception { System.out.println("testCatalogUpdateAfterRejoin"); VoltProjectBuilder builder = getBuilderForTest(); LocalCluster cluster = new LocalCluster("rejoin.jar", 2, 2, 1, BackendTarget.NATIVE_EE_JNI); boolean success = cluster.compile(builder); assertTrue(success); MiscUtils.copyFile( builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml")); try { cluster.startUp(); for (int ii = 0; ii < 3; ii++) { cluster.shutDownSingleHost(1); Thread.sleep(1000); cluster.recoverOne(1, 0, "localhost"); File newCatalog = new File(Configuration.getPathToCatalogForTest("rejoin.jar")); File deployment = new File(Configuration.getPathToCatalogForTest("rejoin.xml")); Client client = ClientFactory.createClient(); client.createConnection("localhost"); VoltTable[] results = client.updateApplicationCatalog(newCatalog, deployment).getResults(); assertTrue(results.length == 1); client.close(); } } finally { cluster.shutDown(); } }
public void testRestoreThenRejoinPropagatesRestore() throws Exception { System.out.println("testRestoreThenRejoinThenRestore"); VoltProjectBuilder builder = getBuilderForTest(); builder.setSecurityEnabled(true); LocalCluster cluster = new LocalCluster("rejoin.jar", 2, 2, 1, BackendTarget.NATIVE_EE_JNI, true); ServerThread localServer = null; try { boolean success = cluster.compileWithAdminMode(builder, 9998, false); assertTrue(success); MiscUtils.copyFile( builder.getPathToDeployment(), Configuration.getPathToCatalogForTest("rejoin.xml")); cluster.setHasLocalServer(false); cluster.startUp(); Client client; client = ClientFactory.createClient(m_cconfig); client.createConnection("localhost"); deleteTestFiles(); client.callProcedure("@SnapshotSave", TMPDIR, TESTNONCE, (byte) 1).getResults(); client.callProcedure("@SnapshotRestore", TMPDIR, TESTNONCE); cluster.shutDownSingleHost(0); Thread.sleep(1000); VoltDB.Configuration config = new VoltDB.Configuration(); config.m_pathToCatalog = Configuration.getPathToCatalogForTest("rejoin.jar"); config.m_pathToDeployment = Configuration.getPathToCatalogForTest("rejoin.xml"); config.m_rejoinToHostAndPort = m_username + ":" + m_password + "@localhost:21213"; config.m_isRejoinTest = true; localServer = new ServerThread(config); localServer.start(); localServer.waitForInitialization(); Thread.sleep(2000); client.close(); assertTrue(org.voltdb.sysprocs.SnapshotRestore.m_haveDoneRestore); client = ClientFactory.createClient(m_cconfig); client.createConnection("localhost"); // Also make sure a catalog update doesn't reset m_haveDoneRestore File newCatalog = new File(Configuration.getPathToCatalogForTest("rejoin.jar")); File deployment = new File(Configuration.getPathToCatalogForTest("rejoin.xml")); VoltTable[] results = client.updateApplicationCatalog(newCatalog, deployment).getResults(); assertTrue(results.length == 1); client.close(); assertTrue(org.voltdb.sysprocs.SnapshotRestore.m_haveDoneRestore); } finally { cluster.shutDown(); if (localServer != null) { localServer.shutdown(); } } }
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) { 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(); } }