Ejemplo n.º 1
0
 public void testInvalidCalls() throws Exception {
   System.out.println("\n\nTESTING INVALID CALLS\n\n\n");
   Client client = getFullyConnectedClient();
   //
   // invalid selector
   //
   try {
     // No selector at all.
     client.callProcedure("@Statistics");
     fail();
   } catch (ProcCallException ex) {
     // All badness gets turned into ProcCallExceptions, so we need
     // to check specifically for this error, otherwise things that
     // crash the cluster also turn into ProcCallExceptions and don't
     // trigger failure (ENG-2347)
     assertEquals(
         "Incorrect number of arguments to @Statistics (expects 2, received 0)", ex.getMessage());
   }
   try {
     // extra stuff
     client.callProcedure("@Statistics", "table", 0, "OHHAI");
     fail();
   } catch (ProcCallException ex) {
     assertEquals(
         "Incorrect number of arguments to @Statistics (expects 2, received 3)", ex.getMessage());
   }
   try {
     // Invalid selector
     client.callProcedure("@Statistics", "garbage", 0);
     fail();
   } catch (ProcCallException ex) {
   }
 }
Ejemplo n.º 2
0
  protected static void verifyProcFails(
      Client client, String expectedPattern, String storedProc, Object... args) throws IOException {

    String what;
    if (storedProc.compareTo("@AdHoc") == 0) {
      what = "the statement \"" + args[0] + "\"";
    } else {
      what = "the stored procedure \"" + storedProc + "\"";
    }

    try {
      client.callProcedure(storedProc, args);
    } catch (ProcCallException pce) {
      String msg = pce.getMessage();
      String diagnostic =
          "Expected "
              + what
              + " to throw an exception matching the pattern \""
              + expectedPattern
              + "\", but instead it threw an exception containing \""
              + msg
              + "\".";
      Pattern pattern = Pattern.compile(expectedPattern, Pattern.MULTILINE);
      assertTrue(diagnostic, pattern.matcher(msg).find());
      return;
    }

    String diagnostic =
        "Expected "
            + what
            + " to throw an exception matching the pattern \""
            + expectedPattern
            + "\", but instead it threw nothing.";
    fail(diagnostic);
  }
Ejemplo n.º 3
0
 private void runAndCheck(boolean expectException) throws Exception {
   try {
     VoltTable[] results =
         m_env.m_client.callProcedure("@AdHoc", StringUtils.join(m_queries, "; ")).getResults();
     int i = 0;
     assertEquals(m_expectedCounts.size(), results.length);
     for (String query : m_queries) {
       int expectedCount = m_expectedCounts.get(i);
       if (expectedCount >= 0) {
         String s = query.toLowerCase().trim();
         if (!s.isEmpty()) {
           if (s.startsWith("insert") || s.startsWith("update") || s.startsWith("delete")) {
             assertEquals(String.format("%s (row count):", query), 1, results[i].getRowCount());
             assertEquals(
                 String.format("%s (result count):", query),
                 expectedCount,
                 results[i].asScalarLong());
           } else {
             assertEquals(
                 String.format("%s (row count):", query),
                 expectedCount,
                 results[i].getRowCount());
           }
           i++;
         }
       }
     }
   } catch (ProcCallException e) {
     assertTrue("Unexpected exception for batch: " + e.getMessage(), expectException);
   } finally {
     m_queries.clear();
     m_expectedCounts.clear();
   }
 }
  public void testBasicCreateStatementProc() throws Exception {
    String pathToCatalog = Configuration.getPathToCatalogForTest("adhocddl.jar");
    String pathToDeployment = Configuration.getPathToCatalogForTest("adhocddl.xml");

    VoltProjectBuilder builder = new VoltProjectBuilder();
    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");
    builder.setUseDDLSchema(true);
    boolean success = builder.compile(pathToCatalog, 2, 1, 0);
    assertTrue("Schema compilation failed", success);
    MiscUtils.copyFile(builder.getPathToDeployment(), pathToDeployment);

    VoltDB.Configuration config = new VoltDB.Configuration();
    config.m_pathToCatalog = pathToCatalog;
    config.m_pathToDeployment = pathToDeployment;

    try {
      startSystem(config);
      // Procedure shouldn't exist
      boolean threw = false;
      assertFalse(findProcedureInSystemCatalog("FOOCOUNT"));
      try {
        m_client.callProcedure("FOOCOUNT", 1000L);
      } catch (ProcCallException pce) {
        assertTrue(pce.getMessage().contains("Procedure FOOCOUNT was not found"));
        threw = true;
      }
      assertTrue("FOOCOUNT procedure shouldn't exist", threw);
      try {
        m_client.callProcedure(
            "@AdHoc", "create procedure FOOCOUNT as select * from FOO where ID=?;");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to create statement procedure");
      }
      assertTrue(findProcedureInSystemCatalog("FOOCOUNT"));
      assertFalse(verifySinglePartitionProcedure("FOOCOUNT"));
      // Make sure we can call it
      try {
        m_client.callProcedure("FOOCOUNT", 1000L);
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to call procedure FOOCOUNT");
      }
      // partition that sucker
      try {
        m_client.callProcedure(
            "@AdHoc", "partition procedure FOOCOUNT on table FOO column ID parameter 0;");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to partition the procedure FOOCOUNT");
      }
      // Make sure we can call it
      assertTrue(verifySinglePartitionProcedure("FOOCOUNT"));
      try {
        m_client.callProcedure("FOOCOUNT", 1000L);
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to call procedure FOOCOUNT");
      }

      // now drop it
      try {
        m_client.callProcedure("@AdHoc", "drop procedure FOOCOUNT");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to drop procedure FOOCOUNT");
      }
      assertFalse(findProcedureInSystemCatalog("FOOCOUNT"));

      // Can't drop it twice
      threw = false;
      try {
        m_client.callProcedure("@AdHoc", "drop procedure FOOCOUNT");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        threw = true;
      }
      assertTrue("Can't vanilla drop procedure FOOCOUNT twice", threw);

      // unless we use if exists
      try {
        m_client.callProcedure("@AdHoc", "drop procedure FOOCOUNT if exists");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to drop procedure FOOCOUNT twice with if exists");
      }

      // Create it again so we can destroy it with drop with if exists, just to be sure
      try {
        m_client.callProcedure(
            "@AdHoc", "create procedure FOOCOUNT as select * from FOO where ID=?;");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to create statement procedure");
      }
      assertTrue(findProcedureInSystemCatalog("FOOCOUNT"));

      // now drop it
      try {
        m_client.callProcedure("@AdHoc", "drop procedure FOOCOUNT if exists");
      } catch (ProcCallException pce) {
        pce.printStackTrace();
        fail("Should be able to drop procedure FOOCOUNT");
      }
      assertFalse(findProcedureInSystemCatalog("FOOCOUNT"));
    } finally {
      teardownSystem();
    }
  }
Ejemplo n.º 5
0
  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();
    }
  }