You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@accumulo.apache.org by ct...@apache.org on 2013/12/05 00:59:05 UTC
[24/50] [abbrv] ACCUMULO-802 Renamed "TableNamespace" to "Namespace"
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java b/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
new file mode 100644
index 0000000..5b7d11d
--- /dev/null
+++ b/test/src/test/java/org/apache/accumulo/test/NamespacesIT.java
@@ -0,0 +1,584 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.accumulo.test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.EnumSet;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map.Entry;
+import java.util.Random;
+
+import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
+import org.apache.accumulo.core.client.BatchWriter;
+import org.apache.accumulo.core.client.BatchWriterConfig;
+import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
+import org.apache.accumulo.core.client.IteratorSetting;
+import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.NamespaceNotEmptyException;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
+import org.apache.accumulo.core.client.Scanner;
+import org.apache.accumulo.core.client.TableNotFoundException;
+import org.apache.accumulo.core.client.impl.Namespaces;
+import org.apache.accumulo.core.client.impl.Tables;
+import org.apache.accumulo.core.client.security.tokens.PasswordToken;
+import org.apache.accumulo.core.conf.Property;
+import org.apache.accumulo.core.data.Key;
+import org.apache.accumulo.core.data.Mutation;
+import org.apache.accumulo.core.data.Value;
+import org.apache.accumulo.core.iterators.Filter;
+import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
+import org.apache.accumulo.core.security.Authorizations;
+import org.apache.accumulo.core.security.NamespacePermission;
+import org.apache.accumulo.core.security.SystemPermission;
+import org.apache.accumulo.core.util.UtilWaitThread;
+import org.apache.accumulo.examples.simple.constraints.NumericValueConstraint;
+import org.apache.accumulo.minicluster.MiniAccumuloCluster;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+public class NamespacesIT {
+
+ Random random = new Random();
+ public static TemporaryFolder folder = new TemporaryFolder();
+ static private MiniAccumuloCluster accumulo;
+ static private String secret = "secret";
+
+ @BeforeClass
+ static public void setUp() throws Exception {
+ folder.create();
+ accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
+ accumulo.start();
+ }
+
+ @AfterClass
+ static public void tearDown() throws Exception {
+ accumulo.stop();
+ folder.delete();
+ }
+
+ /**
+ * This test creates a table without specifying a namespace. In this case, it puts the table into the default namespace.
+ */
+ @Test
+ public void testDefaultNamespace() throws Exception {
+ String tableName = "test";
+ Connector c = accumulo.getConnector("root", secret);
+
+ assertTrue(c.namespaceOperations().exists(Constants.DEFAULT_NAMESPACE));
+ c.tableOperations().create(tableName);
+ assertTrue(c.tableOperations().exists(tableName));
+ }
+
+ /**
+ * This test creates a new namespace "testing" and a table "testing.table1" which puts "table1" into the "testing" namespace. Then we create "testing.table2"
+ * which creates "table2" and puts it into "testing" as well. Then we make sure that you can't delete a namespace with tables in it, and then we delete the
+ * tables and delete the namespace.
+ */
+ @Test
+ public void testCreateAndDeleteNamespace() throws Exception {
+ String namespace = "testing";
+ String tableName1 = namespace + ".table1";
+ String tableName2 = namespace + ".table2";
+
+ Connector c = accumulo.getConnector("root", secret);
+
+ c.namespaceOperations().create(namespace);
+ assertTrue(c.namespaceOperations().exists(namespace));
+
+ c.tableOperations().create(tableName1);
+ assertTrue(c.tableOperations().exists(tableName1));
+
+ c.tableOperations().create(tableName2);
+ assertTrue(c.tableOperations().exists(tableName2));
+
+ // deleting
+ try {
+ // can't delete a namespace with tables in it
+ c.namespaceOperations().delete(namespace);
+ fail();
+ } catch (NamespaceNotEmptyException e) {
+ // ignore, supposed to happen
+ }
+ assertTrue(c.namespaceOperations().exists(namespace));
+ assertTrue(c.tableOperations().exists(tableName1));
+ assertTrue(c.tableOperations().exists(tableName2));
+
+ c.tableOperations().delete(tableName2);
+ assertTrue(!c.tableOperations().exists(tableName2));
+ assertTrue(c.namespaceOperations().exists(namespace));
+
+ c.tableOperations().delete(tableName1);
+ assertTrue(!c.tableOperations().exists(tableName1));
+ c.namespaceOperations().delete(namespace);
+ assertTrue(!c.namespaceOperations().exists(namespace));
+ }
+
+ /**
+ * This test creates a namespace, modifies it's properties, and checks to make sure that those properties are applied to its tables. To do something on a
+ * namespace-wide level, use NamespaceOperations.
+ *
+ * Checks to make sure namespace-level properties are overridden by table-level properties.
+ *
+ * Checks to see if the default namespace's properties work as well.
+ */
+
+ @Test
+ public void testNamespaceProperties() throws Exception {
+ String namespace = "propchange";
+ String tableName1 = namespace + ".table1";
+ String tableName2 = namespace + ".table2";
+
+ String propKey = Property.TABLE_SCAN_MAXMEM.getKey();
+ String propVal = "42K";
+
+ Connector c = accumulo.getConnector("root", secret);
+
+ c.namespaceOperations().create(namespace);
+ c.tableOperations().create(tableName1);
+ c.namespaceOperations().setProperty(namespace, propKey, propVal);
+
+ // check the namespace has the property
+ assertTrue(checkNamespaceHasProp(c, namespace, propKey, propVal));
+
+ // check that the table gets it from the namespace
+ assertTrue(checkTableHasProp(c, tableName1, propKey, propVal));
+
+ // test a second table to be sure the first wasn't magical
+ // (also, changed the order, the namespace has the property already)
+ c.tableOperations().create(tableName2);
+ assertTrue(checkTableHasProp(c, tableName2, propKey, propVal));
+
+ // test that table properties override namespace properties
+ String propKey2 = Property.TABLE_FILE_MAX.getKey();
+ String propVal2 = "42";
+ String tablePropVal = "13";
+
+ c.tableOperations().setProperty(tableName2, propKey2, tablePropVal);
+ c.namespaceOperations().setProperty("propchange", propKey2, propVal2);
+
+ assertTrue(checkTableHasProp(c, tableName2, propKey2, tablePropVal));
+
+ // now check that you can change the default namespace's properties
+ propVal = "13K";
+ String tableName = "some_table";
+ c.tableOperations().create(tableName);
+ c.namespaceOperations().setProperty(Constants.DEFAULT_NAMESPACE, propKey, propVal);
+
+ assertTrue(checkTableHasProp(c, tableName, propKey, propVal));
+
+ // test the properties server-side by configuring an iterator.
+ // should not show anything with column-family = 'a'
+ String tableName3 = namespace + ".table3";
+ c.tableOperations().create(tableName3);
+
+ IteratorSetting setting = new IteratorSetting(250, "thing", SimpleFilter.class.getName());
+ c.namespaceOperations().attachIterator(namespace, setting);
+
+ BatchWriter bw = c.createBatchWriter(tableName3, new BatchWriterConfig());
+ Mutation m = new Mutation("r");
+ m.put("a", "b", new Value("abcde".getBytes()));
+ bw.addMutation(m);
+ bw.flush();
+ bw.close();
+
+ Scanner s = c.createScanner(tableName3, Authorizations.EMPTY);
+ assertTrue(!s.iterator().hasNext());
+ }
+
+ /**
+ * This test renames and clones two separate table into different namespaces. different namespace.
+ *
+ */
+ @Test
+ public void testRenameAndCloneTableToNewNamespace() throws Exception {
+ String namespace1 = "renamed";
+ String namespace2 = "cloned";
+ String tableName = "table";
+ String tableName1 = "renamed.table1";
+ String tableName2 = "cloned.table2";
+
+ Connector c = accumulo.getConnector("root", secret);
+
+ c.tableOperations().create(tableName);
+ c.namespaceOperations().create(namespace1);
+ c.namespaceOperations().create(namespace2);
+
+ c.tableOperations().rename(tableName, tableName1);
+
+ assertTrue(c.tableOperations().exists(tableName1));
+ assertTrue(!c.tableOperations().exists(tableName));
+
+ c.tableOperations().clone(tableName1, tableName2, false, null, null);
+
+ assertTrue(c.tableOperations().exists(tableName1));
+ assertTrue(c.tableOperations().exists(tableName2));
+ return;
+ }
+
+ /**
+ * This test renames a namespace and ensures that its tables are still correct
+ */
+ @Test
+ public void testNamespaceRename() throws Exception {
+ String namespace1 = "n1";
+ String namespace2 = "n2";
+ String table = "t";
+
+ Connector c = accumulo.getConnector("root", secret);
+ Instance instance = c.getInstance();
+
+ c.namespaceOperations().create(namespace1);
+ c.tableOperations().create(namespace1 + "." + table);
+
+ c.namespaceOperations().rename(namespace1, namespace2);
+
+ assertTrue(!c.namespaceOperations().exists(namespace1));
+ assertTrue(c.namespaceOperations().exists(namespace2));
+ assertTrue(c.tableOperations().exists(namespace2 + "." + table));
+ String tid = Tables.getTableId(instance, namespace2 + "." + table);
+ String tnid = Tables.getNamespace(instance, tid);
+ String tnamespace = Namespaces.getNamespaceName(instance, tnid);
+ assertTrue(namespace2.equals(tnamespace));
+ }
+
+ /**
+ * This test clones a table to a different namespace and ensures it's properties are correct
+ */
+ @Test
+ public void testCloneTableProperties() throws Exception {
+ String n1 = "namespace1";
+ String n2 = "namespace2";
+ String t1 = n1 + ".table";
+ String t2 = n2 + ".table";
+
+ String propKey = Property.TABLE_FILE_MAX.getKey();
+ String propVal1 = "55";
+ String propVal2 = "66";
+
+ Connector c = accumulo.getConnector("root", secret);
+
+ c.namespaceOperations().create(n1);
+ c.tableOperations().create(t1);
+
+ c.tableOperations().removeProperty(t1, Property.TABLE_FILE_MAX.getKey());
+ c.namespaceOperations().setProperty(n1, propKey, propVal1);
+
+ assertTrue(checkTableHasProp(c, t1, propKey, propVal1));
+
+ c.namespaceOperations().create(n2);
+ c.namespaceOperations().setProperty(n2, propKey, propVal2);
+ c.tableOperations().clone(t1, t2, true, null, null);
+ c.tableOperations().removeProperty(t2, propKey);
+
+ assertTrue(checkTableHasProp(c, t2, propKey, propVal2));
+
+ c.namespaceOperations().delete(n1, true);
+ c.namespaceOperations().delete(n2, true);
+ }
+
+ /**
+ * This tests adding iterators to a namespace, listing them, and removing them as well as adding and removing constraints
+ */
+ @Test
+ public void testNamespaceIteratorsAndConstraints() throws Exception {
+ Connector c = accumulo.getConnector("root", secret);
+
+ String namespace = "iterator";
+ String tableName = namespace + ".table";
+ String iter = "thing";
+
+ c.namespaceOperations().create(namespace);
+ c.tableOperations().create(tableName);
+
+ IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
+ HashSet<IteratorScope> scope = new HashSet<IteratorScope>();
+ scope.add(IteratorScope.scan);
+ c.namespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
+
+ BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
+ Mutation m = new Mutation("r");
+ m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
+ bw.addMutation(m);
+ bw.flush();
+
+ Scanner s = c.createScanner(tableName, Authorizations.EMPTY);
+ assertTrue(!s.iterator().hasNext());
+
+ assertTrue(c.namespaceOperations().listIterators(namespace).containsKey(iter));
+ c.namespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
+
+ c.namespaceOperations().addConstraint(namespace, NumericValueConstraint.class.getName());
+ // doesn't take effect immediately, needs time to propagate
+ UtilWaitThread.sleep(250);
+
+ m = new Mutation("rowy");
+ m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
+ try {
+ bw.addMutation(m);
+ bw.flush();
+ bw.close();
+ fail();
+ } catch (MutationsRejectedException e) {
+ // supposed to be thrown
+ }
+ int num = c.namespaceOperations().listConstraints(namespace).get(NumericValueConstraint.class.getName());
+ c.namespaceOperations().removeConstraint(namespace, num);
+ }
+
+ /**
+ * Tests that when a table moves to a new namespace that it's properties inherit from the new namespace and not the old one
+ */
+ @Test
+ public void testRenameToNewNamespaceProperties() throws Exception {
+ Connector c = accumulo.getConnector("root", secret);
+
+ String namespace1 = "moveToNewNamespace1";
+ String namespace2 = "moveToNewNamespace2";
+ String tableName1 = namespace1 + ".table";
+ String tableName2 = namespace2 + ".table";
+
+ String propKey = Property.TABLE_FILE_MAX.getKey();
+ String propVal = "42";
+
+ c.namespaceOperations().create(namespace1);
+ c.namespaceOperations().create(namespace2);
+ c.tableOperations().create(tableName1);
+
+ c.namespaceOperations().setProperty(namespace1, propKey, propVal);
+ boolean hasProp = false;
+ for (Entry<String,String> p : c.tableOperations().getProperties(tableName1)) {
+ if (p.getKey().equals(propKey) && p.getValue().equals(propVal)) {
+ hasProp = true;
+ }
+ }
+ assertTrue(hasProp);
+
+ c.tableOperations().rename(tableName1, tableName2);
+
+ hasProp = false;
+ for (Entry<String,String> p : c.tableOperations().getProperties(tableName2)) {
+ if (p.getKey().equals(propKey) && p.getValue().equals(propVal)) {
+ hasProp = true;
+ }
+ }
+ assertTrue(!hasProp);
+ }
+
+ /**
+ * Tests new Namespace permissions as well as modifications to Table permissions because of namespaces. Checks each permission to first make sure the user
+ * doesn't have permission to perform the action, then root grants them the permission and we check to make sure they could perform the action.
+ */
+ @Test
+ public void testPermissions() throws Exception {
+ Connector c = accumulo.getConnector("root", secret);
+
+ PasswordToken pass = new PasswordToken(secret);
+
+ String n1 = "spaceOfTheName";
+
+ String user1 = "dude";
+
+ c.namespaceOperations().create(n1);
+ c.tableOperations().create(n1 + ".table1");
+
+ c.securityOperations().createLocalUser(user1, pass);
+
+ Connector user1Con = accumulo.getConnector(user1, secret);
+
+ try {
+ user1Con.tableOperations().create(n1 + ".table2");
+ fail();
+ } catch (AccumuloSecurityException e) {
+ // supposed to happen
+ }
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.CREATE_TABLE);
+ user1Con.tableOperations().create(n1 + ".table2");
+ assertTrue(c.tableOperations().list().contains(n1 + ".table2"));
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.CREATE_TABLE);
+
+ try {
+ user1Con.tableOperations().delete(n1 + ".table1");
+ fail();
+ } catch (AccumuloSecurityException e) {
+ // should happen
+ }
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.DROP_TABLE);
+ user1Con.tableOperations().delete(n1 + ".table1");
+ assertTrue(!c.tableOperations().list().contains(n1 + ".table1"));
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.DROP_TABLE);
+
+ c.tableOperations().create(n1 + ".t");
+ BatchWriter bw = c.createBatchWriter(n1 + ".t", null);
+ Mutation m = new Mutation("row");
+ m.put("cf", "cq", "value");
+ bw.addMutation(m);
+ bw.close();
+
+ Iterator<Entry<Key,Value>> i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
+ try {
+ i.next();
+ fail();
+ } catch (RuntimeException e) {
+ // yup
+ }
+
+ m = new Mutation("user1");
+ m.put("cf", "cq", "turtles");
+ bw = user1Con.createBatchWriter(n1 + ".t", null);
+ try {
+ bw.addMutation(m);
+ bw.close();
+ fail();
+ } catch (MutationsRejectedException e) {
+ // good
+ }
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.READ);
+ i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
+ assertTrue(i.hasNext());
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.READ);
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.WRITE);
+ m = new Mutation("user1");
+ m.put("cf", "cq", "turtles");
+ bw = user1Con.createBatchWriter(n1 + ".t", null);
+ bw.addMutation(m);
+ bw.close();
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.WRITE);
+
+ try {
+ user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.ALTER_TABLE);
+ user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
+ user1Con.tableOperations().removeProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey());
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.ALTER_TABLE);
+
+ try {
+ user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "55");
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.ALTER_NAMESPACE);
+ user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "42");
+ user1Con.namespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.ALTER_NAMESPACE);
+
+ String user2 = "guy";
+ c.securityOperations().createLocalUser(user2, pass);
+ try {
+ user1Con.securityOperations().grantNamespacePermission(user2, n1, NamespacePermission.ALTER_NAMESPACE);
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantNamespacePermission(user1, n1, NamespacePermission.GRANT);
+ user1Con.securityOperations().grantNamespacePermission(user2, n1, NamespacePermission.ALTER_NAMESPACE);
+ user1Con.securityOperations().revokeNamespacePermission(user2, n1, NamespacePermission.ALTER_NAMESPACE);
+ c.securityOperations().revokeNamespacePermission(user1, n1, NamespacePermission.GRANT);
+
+ String n2 = "namespace2";
+ try {
+ user1Con.namespaceOperations().create(n2);
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
+ user1Con.namespaceOperations().create(n2);
+ c.securityOperations().revokeSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
+
+ try {
+ user1Con.namespaceOperations().delete(n2);
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
+ user1Con.namespaceOperations().delete(n2);
+ c.securityOperations().revokeSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
+
+ try {
+ user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
+ fail();
+ } catch (AccumuloSecurityException e) {}
+
+ c.securityOperations().grantSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
+ user1Con.namespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
+ user1Con.namespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
+ c.securityOperations().revokeSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
+ }
+
+ /**
+ * This test makes sure that system-level iterators and constraints are ignored by the system namespace so that the metadata and root tables aren't affected
+ */
+ @Test
+ public void excludeSystemIterConst() throws Exception {
+ Connector c = accumulo.getConnector("root", secret);
+
+ c.instanceOperations().setProperty("table.iterator.scan.sum", "20," + SimpleFilter.class.getName());
+ assertTrue(c.instanceOperations().getSystemConfiguration().containsValue("20," + SimpleFilter.class.getName()));
+
+ assertTrue(checkNamespaceHasProp(c, Constants.DEFAULT_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
+ assertTrue(!checkNamespaceHasProp(c, Constants.SYSTEM_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
+ c.instanceOperations().removeProperty("table.iterator.scan.sum");
+
+ c.instanceOperations().setProperty("table.constraint.42", NumericValueConstraint.class.getName());
+ assertTrue(c.instanceOperations().getSystemConfiguration().containsValue(NumericValueConstraint.class.getName()));
+
+ assertTrue(checkNamespaceHasProp(c, Constants.DEFAULT_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
+ assertTrue(!checkNamespaceHasProp(c, Constants.SYSTEM_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
+ c.instanceOperations().removeProperty("table.constraint.42");
+ }
+
+ private boolean checkTableHasProp(Connector c, String t, String propKey, String propVal) throws AccumuloException, TableNotFoundException {
+ for (Entry<String,String> e : c.tableOperations().getProperties(t)) {
+ if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private boolean checkNamespaceHasProp(Connector c, String n, String propKey, String propVal) throws AccumuloException, NamespaceNotFoundException {
+ for (Entry<String,String> e : c.namespaceOperations().getProperties(n)) {
+ if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static class SimpleFilter extends Filter {
+ @Override
+ public boolean accept(Key k, Value v) {
+ if (k.getColumnFamily().toString().equals("a"))
+ return false;
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
index e60e414..f21dfd9 100644
--- a/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/ShellServerIT.java
@@ -704,7 +704,7 @@ public class ShellServerIT extends SimpleMacIT {
exec("scan -t xyzzy", true, "value", true);
exec("deletetable -f xyzzy", true);
}
-
+
@Test(timeout = 30 * 1000)
public void tables() throws Exception {
exec("createtable zzzz");
@@ -831,33 +831,33 @@ public class ShellServerIT extends SimpleMacIT {
String err = exec("user NoSuchUser", false);
assertTrue(err.contains("BAD_CREDENTIALS for user NoSuchUser"));
}
-
+
@Test(timeout = 30 * 1000)
- public void tablenamespaces() throws Exception {
- exec("namespaces", true, Constants.DEFAULT_TABLE_NAMESPACE, true);
+ public void namespaces() throws Exception {
+ exec("namespaces", true, Constants.DEFAULT_NAMESPACE, true);
exec("createnamespace thing1", true);
String namespaces = exec("namespaces");
assertTrue(namespaces.contains("thing1"));
-
+
exec("renamenamespace thing1 thing2");
namespaces = exec("namespaces");
assertTrue(namespaces.contains("thing2"));
assertTrue(!namespaces.contains("thing1"));
-
+
// can't delete a namespace that still contains tables, unless you do -f
exec("createtable thing2.thingy", true);
exec("deletenamespace thing2");
exec("y");
exec("namespaces", true, "thing2", true);
-
+
exec("clonenamespace thing2 testers -e table.file.max", true);
exec("namespaces", true, "testers", true);
exec("tables", true, "testers.thingy", true);
exec("clonenamespace thing2 testers2 -s table.file.max=42", true);
-
+
exec("du -tn thing2", true, "thing2.thingy", true);
-
- // all "TableOperation" commands can take a table namespace
+
+ // all "TableOperation" commands can take a namespace
exec("offline -tn thing2", true);
exec("online -tn thing2", true);
exec("flush -tn thing2", true);
@@ -878,25 +878,25 @@ public class ShellServerIT extends SimpleMacIT {
exec("pass");
exec("grant Namespace.CREATE_TABLE -tn thing2 -u dude", true);
exec("revoke Namespace.CREATE_TABLE -tn thing2 -u dude", true);
-
+
// properties override and such
exec("config -tn thing2 -s table.file.max=44444", true);
exec("config -tn thing2", true, "44444", true);
exec("config -t thing2.thingy", true, "44444", true);
exec("config -t thing2.thingy -s table.file.max=55555", true);
exec("config -t thing2.thingy", true, "55555", true);
-
+
// can copy properties when creating
exec("createnamespace thing3 -cc thing2", true);
exec("config -tn thing3", true, "44444", true);
exec("createnamespace thing4 -ctc thing2.thingy", true);
exec("config -tn thing4", true, "55555", true);
-
+
exec("deletenamespace -f thing2", true);
exec("namespaces", true, "thing2", false);
exec("tables", true, "thing2.thingy", false);
-
- // put constraints on a table namespace
+
+ // put constraints on a namespace
exec("constraint -tn thing4 -a org.apache.accumulo.examples.simple.constraints.NumericValueConstraint", true);
exec("createtable thing4.constrained", true);
exec("table thing4.constrained", true);
@@ -907,7 +907,7 @@ public class ShellServerIT extends SimpleMacIT {
exec("sleep 1");
exec("insert r cf cq abc", true);
}
-
+
private int countkeys(String table) throws IOException {
exec("scan -np -t " + table);
return output.get().split("\n").length - 1;
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java b/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
deleted file mode 100644
index 6cb2568..0000000
--- a/test/src/test/java/org/apache/accumulo/test/TableNamespacesIT.java
+++ /dev/null
@@ -1,584 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.accumulo.test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.EnumSet;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map.Entry;
-import java.util.Random;
-
-import org.apache.accumulo.core.Constants;
-import org.apache.accumulo.core.client.AccumuloException;
-import org.apache.accumulo.core.client.AccumuloSecurityException;
-import org.apache.accumulo.core.client.BatchWriter;
-import org.apache.accumulo.core.client.BatchWriterConfig;
-import org.apache.accumulo.core.client.Connector;
-import org.apache.accumulo.core.client.Instance;
-import org.apache.accumulo.core.client.IteratorSetting;
-import org.apache.accumulo.core.client.MutationsRejectedException;
-import org.apache.accumulo.core.client.Scanner;
-import org.apache.accumulo.core.client.TableNamespaceNotEmptyException;
-import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
-import org.apache.accumulo.core.client.TableNotFoundException;
-import org.apache.accumulo.core.client.impl.TableNamespaces;
-import org.apache.accumulo.core.client.impl.Tables;
-import org.apache.accumulo.core.client.security.tokens.PasswordToken;
-import org.apache.accumulo.core.conf.Property;
-import org.apache.accumulo.core.data.Key;
-import org.apache.accumulo.core.data.Mutation;
-import org.apache.accumulo.core.data.Value;
-import org.apache.accumulo.core.iterators.Filter;
-import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
-import org.apache.accumulo.core.security.Authorizations;
-import org.apache.accumulo.core.security.SystemPermission;
-import org.apache.accumulo.core.security.TableNamespacePermission;
-import org.apache.accumulo.core.util.UtilWaitThread;
-import org.apache.accumulo.examples.simple.constraints.NumericValueConstraint;
-import org.apache.accumulo.minicluster.MiniAccumuloCluster;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-public class TableNamespacesIT {
-
- Random random = new Random();
- public static TemporaryFolder folder = new TemporaryFolder();
- static private MiniAccumuloCluster accumulo;
- static private String secret = "secret";
-
- @BeforeClass
- static public void setUp() throws Exception {
- folder.create();
- accumulo = new MiniAccumuloCluster(folder.getRoot(), secret);
- accumulo.start();
- }
-
- @AfterClass
- static public void tearDown() throws Exception {
- accumulo.stop();
- folder.delete();
- }
-
- /**
- * This test creates a table without specifying a namespace. In this case, it puts the table into the default namespace.
- */
- @Test
- public void testDefaultNamespace() throws Exception {
- String tableName = "test";
- Connector c = accumulo.getConnector("root", secret);
-
- assertTrue(c.tableNamespaceOperations().exists(Constants.DEFAULT_TABLE_NAMESPACE));
- c.tableOperations().create(tableName);
- assertTrue(c.tableOperations().exists(tableName));
- }
-
- /**
- * This test creates a new namespace "testing" and a table "testing.table1" which puts "table1" into the "testing" namespace. Then we create "testing.table2"
- * which creates "table2" and puts it into "testing" as well. Then we make sure that you can't delete a namespace with tables in it, and then we delete the
- * tables and delete the namespace.
- */
- @Test
- public void testCreateAndDeleteNamespace() throws Exception {
- String namespace = "testing";
- String tableName1 = namespace + ".table1";
- String tableName2 = namespace + ".table2";
-
- Connector c = accumulo.getConnector("root", secret);
-
- c.tableNamespaceOperations().create(namespace);
- assertTrue(c.tableNamespaceOperations().exists(namespace));
-
- c.tableOperations().create(tableName1);
- assertTrue(c.tableOperations().exists(tableName1));
-
- c.tableOperations().create(tableName2);
- assertTrue(c.tableOperations().exists(tableName2));
-
- // deleting
- try {
- // can't delete a namespace with tables in it
- c.tableNamespaceOperations().delete(namespace);
- fail();
- } catch (TableNamespaceNotEmptyException e) {
- // ignore, supposed to happen
- }
- assertTrue(c.tableNamespaceOperations().exists(namespace));
- assertTrue(c.tableOperations().exists(tableName1));
- assertTrue(c.tableOperations().exists(tableName2));
-
- c.tableOperations().delete(tableName2);
- assertTrue(!c.tableOperations().exists(tableName2));
- assertTrue(c.tableNamespaceOperations().exists(namespace));
-
- c.tableOperations().delete(tableName1);
- assertTrue(!c.tableOperations().exists(tableName1));
- c.tableNamespaceOperations().delete(namespace);
- assertTrue(!c.tableNamespaceOperations().exists(namespace));
- }
-
- /**
- * This test creates a namespace, modifies it's properties, and checks to make sure that those properties are applied to its tables. To do something on a
- * namespace-wide level, use TableNamespaceOperations.
- *
- * Checks to make sure namespace-level properties are overridden by table-level properties.
- *
- * Checks to see if the default namespace's properties work as well.
- */
-
- @Test
- public void testNamespaceProperties() throws Exception {
- String namespace = "propchange";
- String tableName1 = namespace + ".table1";
- String tableName2 = namespace + ".table2";
-
- String propKey = Property.TABLE_SCAN_MAXMEM.getKey();
- String propVal = "42K";
-
- Connector c = accumulo.getConnector("root", secret);
-
- c.tableNamespaceOperations().create(namespace);
- c.tableOperations().create(tableName1);
- c.tableNamespaceOperations().setProperty(namespace, propKey, propVal);
-
- // check the namespace has the property
- assertTrue(checkTableNamespaceHasProp(c, namespace, propKey, propVal));
-
- // check that the table gets it from the namespace
- assertTrue(checkTableHasProp(c, tableName1, propKey, propVal));
-
- // test a second table to be sure the first wasn't magical
- // (also, changed the order, the namespace has the property already)
- c.tableOperations().create(tableName2);
- assertTrue(checkTableHasProp(c, tableName2, propKey, propVal));
-
- // test that table properties override namespace properties
- String propKey2 = Property.TABLE_FILE_MAX.getKey();
- String propVal2 = "42";
- String tablePropVal = "13";
-
- c.tableOperations().setProperty(tableName2, propKey2, tablePropVal);
- c.tableNamespaceOperations().setProperty("propchange", propKey2, propVal2);
-
- assertTrue(checkTableHasProp(c, tableName2, propKey2, tablePropVal));
-
- // now check that you can change the default namespace's properties
- propVal = "13K";
- String tableName = "some_table";
- c.tableOperations().create(tableName);
- c.tableNamespaceOperations().setProperty(Constants.DEFAULT_TABLE_NAMESPACE, propKey, propVal);
-
- assertTrue(checkTableHasProp(c, tableName, propKey, propVal));
-
- // test the properties server-side by configuring an iterator.
- // should not show anything with column-family = 'a'
- String tableName3 = namespace + ".table3";
- c.tableOperations().create(tableName3);
-
- IteratorSetting setting = new IteratorSetting(250, "thing", SimpleFilter.class.getName());
- c.tableNamespaceOperations().attachIterator(namespace, setting);
-
- BatchWriter bw = c.createBatchWriter(tableName3, new BatchWriterConfig());
- Mutation m = new Mutation("r");
- m.put("a", "b", new Value("abcde".getBytes()));
- bw.addMutation(m);
- bw.flush();
- bw.close();
-
- Scanner s = c.createScanner(tableName3, Authorizations.EMPTY);
- assertTrue(!s.iterator().hasNext());
- }
-
- /**
- * This test renames and clones two separate table into different namespaces. different namespace.
- *
- */
- @Test
- public void testRenameAndCloneTableToNewNamespace() throws Exception {
- String namespace1 = "renamed";
- String namespace2 = "cloned";
- String tableName = "table";
- String tableName1 = "renamed.table1";
- String tableName2 = "cloned.table2";
-
- Connector c = accumulo.getConnector("root", secret);
-
- c.tableOperations().create(tableName);
- c.tableNamespaceOperations().create(namespace1);
- c.tableNamespaceOperations().create(namespace2);
-
- c.tableOperations().rename(tableName, tableName1);
-
- assertTrue(c.tableOperations().exists(tableName1));
- assertTrue(!c.tableOperations().exists(tableName));
-
- c.tableOperations().clone(tableName1, tableName2, false, null, null);
-
- assertTrue(c.tableOperations().exists(tableName1));
- assertTrue(c.tableOperations().exists(tableName2));
- return;
- }
-
- /**
- * This test renames a table namespace and ensures that its tables are still correct
- */
- @Test
- public void testNamespaceRename() throws Exception {
- String namespace1 = "n1";
- String namespace2 = "n2";
- String table = "t";
-
- Connector c = accumulo.getConnector("root", secret);
- Instance instance = c.getInstance();
-
- c.tableNamespaceOperations().create(namespace1);
- c.tableOperations().create(namespace1 + "." + table);
-
- c.tableNamespaceOperations().rename(namespace1, namespace2);
-
- assertTrue(!c.tableNamespaceOperations().exists(namespace1));
- assertTrue(c.tableNamespaceOperations().exists(namespace2));
- assertTrue(c.tableOperations().exists(namespace2 + "." + table));
- String tid = Tables.getTableId(instance, namespace2 + "." + table);
- String tnid = Tables.getNamespace(instance, tid);
- String tnamespace = TableNamespaces.getNamespaceName(instance, tnid);
- assertTrue(namespace2.equals(tnamespace));
- }
-
- /**
- * This test clones a table to a different namespace and ensures it's properties are correct
- */
- @Test
- public void testCloneTableProperties() throws Exception {
- String n1 = "namespace1";
- String n2 = "namespace2";
- String t1 = n1 + ".table";
- String t2 = n2 + ".table";
-
- String propKey = Property.TABLE_FILE_MAX.getKey();
- String propVal1 = "55";
- String propVal2 = "66";
-
- Connector c = accumulo.getConnector("root", secret);
-
- c.tableNamespaceOperations().create(n1);
- c.tableOperations().create(t1);
-
- c.tableOperations().removeProperty(t1, Property.TABLE_FILE_MAX.getKey());
- c.tableNamespaceOperations().setProperty(n1, propKey, propVal1);
-
- assertTrue(checkTableHasProp(c, t1, propKey, propVal1));
-
- c.tableNamespaceOperations().create(n2);
- c.tableNamespaceOperations().setProperty(n2, propKey, propVal2);
- c.tableOperations().clone(t1, t2, true, null, null);
- c.tableOperations().removeProperty(t2, propKey);
-
- assertTrue(checkTableHasProp(c, t2, propKey, propVal2));
-
- c.tableNamespaceOperations().delete(n1, true);
- c.tableNamespaceOperations().delete(n2, true);
- }
-
- /**
- * This tests adding iterators to a namespace, listing them, and removing them as well as adding and removing constraints
- */
- @Test
- public void testNamespaceIteratorsAndConstraints() throws Exception {
- Connector c = accumulo.getConnector("root", secret);
-
- String namespace = "iterator";
- String tableName = namespace + ".table";
- String iter = "thing";
-
- c.tableNamespaceOperations().create(namespace);
- c.tableOperations().create(tableName);
-
- IteratorSetting setting = new IteratorSetting(250, iter, SimpleFilter.class.getName());
- HashSet<IteratorScope> scope = new HashSet<IteratorScope>();
- scope.add(IteratorScope.scan);
- c.tableNamespaceOperations().attachIterator(namespace, setting, EnumSet.copyOf(scope));
-
- BatchWriter bw = c.createBatchWriter(tableName, new BatchWriterConfig());
- Mutation m = new Mutation("r");
- m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
- bw.addMutation(m);
- bw.flush();
-
- Scanner s = c.createScanner(tableName, Authorizations.EMPTY);
- assertTrue(!s.iterator().hasNext());
-
- assertTrue(c.tableNamespaceOperations().listIterators(namespace).containsKey(iter));
- c.tableNamespaceOperations().removeIterator(namespace, iter, EnumSet.copyOf(scope));
-
- c.tableNamespaceOperations().addConstraint(namespace, NumericValueConstraint.class.getName());
- // doesn't take effect immediately, needs time to propagate
- UtilWaitThread.sleep(250);
-
- m = new Mutation("rowy");
- m.put("a", "b", new Value("abcde".getBytes(Constants.UTF8)));
- try {
- bw.addMutation(m);
- bw.flush();
- bw.close();
- fail();
- } catch (MutationsRejectedException e) {
- // supposed to be thrown
- }
- int num = c.tableNamespaceOperations().listConstraints(namespace).get(NumericValueConstraint.class.getName());
- c.tableNamespaceOperations().removeConstraint(namespace, num);
- }
-
- /**
- * Tests that when a table moves to a new namespace that it's properties inherit from the new namespace and not the old one
- */
- @Test
- public void testRenameToNewNamespaceProperties() throws Exception {
- Connector c = accumulo.getConnector("root", secret);
-
- String namespace1 = "moveToNewNamespace1";
- String namespace2 = "moveToNewNamespace2";
- String tableName1 = namespace1 + ".table";
- String tableName2 = namespace2 + ".table";
-
- String propKey = Property.TABLE_FILE_MAX.getKey();
- String propVal = "42";
-
- c.tableNamespaceOperations().create(namespace1);
- c.tableNamespaceOperations().create(namespace2);
- c.tableOperations().create(tableName1);
-
- c.tableNamespaceOperations().setProperty(namespace1, propKey, propVal);
- boolean hasProp = false;
- for (Entry<String,String> p : c.tableOperations().getProperties(tableName1)) {
- if (p.getKey().equals(propKey) && p.getValue().equals(propVal)) {
- hasProp = true;
- }
- }
- assertTrue(hasProp);
-
- c.tableOperations().rename(tableName1, tableName2);
-
- hasProp = false;
- for (Entry<String,String> p : c.tableOperations().getProperties(tableName2)) {
- if (p.getKey().equals(propKey) && p.getValue().equals(propVal)) {
- hasProp = true;
- }
- }
- assertTrue(!hasProp);
- }
-
- /**
- * Tests new Namespace permissions as well as modifications to Table permissions because of namespaces. Checks each permission to first make sure the user
- * doesn't have permission to perform the action, then root grants them the permission and we check to make sure they could perform the action.
- */
- @Test
- public void testPermissions() throws Exception {
- Connector c = accumulo.getConnector("root", secret);
-
- PasswordToken pass = new PasswordToken(secret);
-
- String n1 = "spaceOfTheName";
-
- String user1 = "dude";
-
- c.tableNamespaceOperations().create(n1);
- c.tableOperations().create(n1 + ".table1");
-
- c.securityOperations().createLocalUser(user1, pass);
-
- Connector user1Con = accumulo.getConnector(user1, secret);
-
- try {
- user1Con.tableOperations().create(n1 + ".table2");
- fail();
- } catch (AccumuloSecurityException e) {
- // supposed to happen
- }
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.CREATE_TABLE);
- user1Con.tableOperations().create(n1 + ".table2");
- assertTrue(c.tableOperations().list().contains(n1 + ".table2"));
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.CREATE_TABLE);
-
- try {
- user1Con.tableOperations().delete(n1 + ".table1");
- fail();
- } catch (AccumuloSecurityException e) {
- // should happen
- }
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.DROP_TABLE);
- user1Con.tableOperations().delete(n1 + ".table1");
- assertTrue(!c.tableOperations().list().contains(n1 + ".table1"));
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.DROP_TABLE);
-
- c.tableOperations().create(n1 + ".t");
- BatchWriter bw = c.createBatchWriter(n1 + ".t", null);
- Mutation m = new Mutation("row");
- m.put("cf", "cq", "value");
- bw.addMutation(m);
- bw.close();
-
- Iterator<Entry<Key,Value>> i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
- try {
- i.next();
- fail();
- } catch (RuntimeException e) {
- // yup
- }
-
- m = new Mutation("user1");
- m.put("cf", "cq", "turtles");
- bw = user1Con.createBatchWriter(n1 + ".t", null);
- try {
- bw.addMutation(m);
- bw.close();
- fail();
- } catch (MutationsRejectedException e) {
- // good
- }
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.READ);
- i = user1Con.createScanner(n1 + ".t", new Authorizations()).iterator();
- assertTrue(i.hasNext());
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.READ);
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.WRITE);
- m = new Mutation("user1");
- m.put("cf", "cq", "turtles");
- bw = user1Con.createBatchWriter(n1 + ".t", null);
- bw.addMutation(m);
- bw.close();
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.WRITE);
-
- try {
- user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_TABLE);
- user1Con.tableOperations().setProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey(), "42");
- user1Con.tableOperations().removeProperty(n1 + ".t", Property.TABLE_FILE_MAX.getKey());
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_TABLE);
-
- try {
- user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "55");
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_NAMESPACE);
- user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "42");
- user1Con.tableNamespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.ALTER_NAMESPACE);
-
- String user2 = "guy";
- c.securityOperations().createLocalUser(user2, pass);
- try {
- user1Con.securityOperations().grantTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantTableNamespacePermission(user1, n1, TableNamespacePermission.GRANT);
- user1Con.securityOperations().grantTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
- user1Con.securityOperations().revokeTableNamespacePermission(user2, n1, TableNamespacePermission.ALTER_NAMESPACE);
- c.securityOperations().revokeTableNamespacePermission(user1, n1, TableNamespacePermission.GRANT);
-
- String n2 = "namespace2";
- try {
- user1Con.tableNamespaceOperations().create(n2);
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
- user1Con.tableNamespaceOperations().create(n2);
- c.securityOperations().revokeSystemPermission(user1, SystemPermission.CREATE_NAMESPACE);
-
- try {
- user1Con.tableNamespaceOperations().delete(n2);
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
- user1Con.tableNamespaceOperations().delete(n2);
- c.securityOperations().revokeSystemPermission(user1, SystemPermission.DROP_NAMESPACE);
-
- try {
- user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
- fail();
- } catch (AccumuloSecurityException e) {}
-
- c.securityOperations().grantSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
- user1Con.tableNamespaceOperations().setProperty(n1, Property.TABLE_FILE_MAX.getKey(), "33");
- user1Con.tableNamespaceOperations().removeProperty(n1, Property.TABLE_FILE_MAX.getKey());
- c.securityOperations().revokeSystemPermission(user1, SystemPermission.ALTER_NAMESPACE);
- }
-
- /**
- * This test makes sure that system-level iterators and constraints are ignored by the system namespace so that the metadata and root tables aren't affected
- */
- @Test
- public void excludeSystemIterConst() throws Exception {
- Connector c = accumulo.getConnector("root", secret);
-
- c.instanceOperations().setProperty("table.iterator.scan.sum", "20," + SimpleFilter.class.getName());
- assertTrue(c.instanceOperations().getSystemConfiguration().containsValue("20," + SimpleFilter.class.getName()));
-
- assertTrue(checkTableNamespaceHasProp(c, Constants.DEFAULT_TABLE_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
- assertTrue(!checkTableNamespaceHasProp(c, Constants.SYSTEM_TABLE_NAMESPACE, "table.iterator.scan.sum", "20," + SimpleFilter.class.getName()));
- c.instanceOperations().removeProperty("table.iterator.scan.sum");
-
- c.instanceOperations().setProperty("table.constraint.42", NumericValueConstraint.class.getName());
- assertTrue(c.instanceOperations().getSystemConfiguration().containsValue(NumericValueConstraint.class.getName()));
-
- assertTrue(checkTableNamespaceHasProp(c, Constants.DEFAULT_TABLE_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
- assertTrue(!checkTableNamespaceHasProp(c, Constants.SYSTEM_TABLE_NAMESPACE, "table.constraint.42", NumericValueConstraint.class.getName()));
- c.instanceOperations().removeProperty("table.constraint.42");
- }
-
- private boolean checkTableHasProp(Connector c, String t, String propKey, String propVal) throws AccumuloException, TableNotFoundException {
- for (Entry<String,String> e : c.tableOperations().getProperties(t)) {
- if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
- return true;
- }
- }
- return false;
- }
-
- private boolean checkTableNamespaceHasProp(Connector c, String n, String propKey, String propVal) throws AccumuloException, TableNamespaceNotFoundException {
- for (Entry<String,String> e : c.tableNamespaceOperations().getProperties(n)) {
- if (e.getKey().equals(propKey) && e.getValue().equals(propVal)) {
- return true;
- }
- }
- return false;
- }
-
- public static class SimpleFilter extends Filter {
- @Override
- public boolean accept(Key k, Value v) {
- if (k.getColumnFamily().toString().equals("a"))
- return false;
- return true;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
----------------------------------------------------------------------
diff --git a/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java b/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
index b05ad18..f835015 100644
--- a/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
+++ b/test/src/test/java/org/apache/accumulo/test/functional/PermissionsIT.java
@@ -32,11 +32,11 @@ import org.apache.accumulo.core.client.BatchWriter;
import org.apache.accumulo.core.client.BatchWriterConfig;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.MutationsRejectedException;
+import org.apache.accumulo.core.client.NamespaceExistsException;
+import org.apache.accumulo.core.client.NamespaceNotEmptyException;
+import org.apache.accumulo.core.client.NamespaceNotFoundException;
import org.apache.accumulo.core.client.Scanner;
import org.apache.accumulo.core.client.TableExistsException;
-import org.apache.accumulo.core.client.TableNamespaceExistsException;
-import org.apache.accumulo.core.client.TableNamespaceNotEmptyException;
-import org.apache.accumulo.core.client.TableNamespaceNotFoundException;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.security.SecurityErrorCode;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
@@ -108,9 +108,9 @@ public class PermissionsIT extends SimpleMacIT {
}
private static void testMissingSystemPermission(String tableNamePrefix, Connector root_conn, Connector test_user_conn, SystemPermission perm)
- throws AccumuloException, TableExistsException, AccumuloSecurityException, TableNotFoundException, TableNamespaceExistsException,
- TableNamespaceNotFoundException, TableNamespaceNotEmptyException {
- String tableName, user, password = "password", tableNamespace;
+ throws AccumuloException, TableExistsException, AccumuloSecurityException, TableNotFoundException, NamespaceExistsException, NamespaceNotFoundException,
+ NamespaceNotEmptyException {
+ String tableName, user, password = "password", namespace;
log.debug("Confirming that the lack of the " + perm + " permission properly restricts the user");
// test permission prior to granting it
@@ -204,53 +204,53 @@ public class PermissionsIT extends SimpleMacIT {
// test for system permission would go here
break;
case CREATE_NAMESPACE:
- tableNamespace = "__CREATE_TABLE_NAMESPACE WITHOUT_PERM_TEST__";
+ namespace = "__CREATE_NAMESPACE_WITHOUT_PERM_TEST__";
try {
- test_user_conn.tableNamespaceOperations().create(tableNamespace);
- throw new IllegalStateException("Should NOT be able to create a table namespace");
+ test_user_conn.namespaceOperations().create(namespace);
+ throw new IllegalStateException("Should NOT be able to create a namespace");
} catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || root_conn.tableNamespaceOperations().list().contains(tableNamespace))
+ if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || root_conn.namespaceOperations().list().contains(namespace))
throw e;
}
break;
case DROP_NAMESPACE:
- tableNamespace = "__DROP_TABLE_NAMESPACE_WITHOUT_PERM_TEST__";
- root_conn.tableNamespaceOperations().create(tableNamespace);
+ namespace = "__DROP_NAMESPACE_WITHOUT_PERM_TEST__";
+ root_conn.namespaceOperations().create(namespace);
try {
- test_user_conn.tableNamespaceOperations().delete(tableNamespace);
- throw new IllegalStateException("Should NOT be able to delete a table namespace");
+ test_user_conn.namespaceOperations().delete(namespace);
+ throw new IllegalStateException("Should NOT be able to delete a namespace");
} catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.tableNamespaceOperations().list().contains(tableNamespace))
+ if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.namespaceOperations().list().contains(namespace))
throw e;
}
break;
case ALTER_NAMESPACE:
- tableNamespace = "__ALTER_TABLE_NAMESPACE_WITHOUT_PERM_TEST__";
- root_conn.tableNamespaceOperations().create(tableNamespace);
+ namespace = "__ALTER_NAMESPACE_WITHOUT_PERM_TEST__";
+ root_conn.namespaceOperations().create(namespace);
try {
- test_user_conn.tableNamespaceOperations().setProperty(tableNamespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
- throw new IllegalStateException("Should NOT be able to set a table namespace property");
+ test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
+ throw new IllegalStateException("Should NOT be able to set a namespace property");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED
- || map(root_conn.tableNamespaceOperations().getProperties(tableNamespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
+ || map(root_conn.namespaceOperations().getProperties(namespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
- root_conn.tableNamespaceOperations().setProperty(tableNamespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
+ root_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
try {
- test_user_conn.tableNamespaceOperations().removeProperty(tableNamespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
- throw new IllegalStateException("Should NOT be able to remove a table namespace property");
+ test_user_conn.namespaceOperations().removeProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
+ throw new IllegalStateException("Should NOT be able to remove a namespace property");
} catch (AccumuloSecurityException e) {
if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED
- || !map(root_conn.tableNamespaceOperations().getProperties(tableNamespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
+ || !map(root_conn.namespaceOperations().getProperties(namespace)).get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw e;
}
- String tableNamespace2 = tableNamespace + "2";
+ String namespace2 = namespace + "2";
try {
- test_user_conn.tableNamespaceOperations().rename(tableNamespace, tableNamespace2);
- throw new IllegalStateException("Should NOT be able to rename a table namespace");
+ test_user_conn.namespaceOperations().rename(namespace, namespace2);
+ throw new IllegalStateException("Should NOT be able to rename a namespace");
} catch (AccumuloSecurityException e) {
- if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.tableNamespaceOperations().list().contains(tableNamespace)
- || root_conn.tableNamespaceOperations().list().contains(tableNamespace2))
+ if (e.getSecurityErrorCode() != SecurityErrorCode.PERMISSION_DENIED || !root_conn.namespaceOperations().list().contains(namespace)
+ || root_conn.namespaceOperations().list().contains(namespace2))
throw e;
}
break;
@@ -260,9 +260,9 @@ public class PermissionsIT extends SimpleMacIT {
}
private static void testGrantedSystemPermission(String tableNamePrefix, Connector root_conn, Connector test_user_conn, SystemPermission perm)
- throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, TableNamespaceExistsException,
- TableNamespaceNotFoundException, TableNamespaceNotEmptyException {
- String tableName, user, password = "password", tableNamespace;
+ throws AccumuloException, AccumuloSecurityException, TableNotFoundException, TableExistsException, NamespaceExistsException, NamespaceNotFoundException,
+ NamespaceNotEmptyException {
+ String tableName, user, password = "password", namespace;
log.debug("Confirming that the presence of the " + perm + " permission properly permits the user");
// test permission after granting it
@@ -320,32 +320,32 @@ public class PermissionsIT extends SimpleMacIT {
// test for system permission would go here
break;
case CREATE_NAMESPACE:
- tableNamespace = "__CREATE_TABLE_NAMESPACE_WITH_PERM_TEST__";
- test_user_conn.tableNamespaceOperations().create(tableNamespace);
- if (!root_conn.tableNamespaceOperations().list().contains(tableNamespace))
- throw new IllegalStateException("Should be able to create a table namespace");
+ namespace = "__CREATE_NAMESPACE_WITH_PERM_TEST__";
+ test_user_conn.namespaceOperations().create(namespace);
+ if (!root_conn.namespaceOperations().list().contains(namespace))
+ throw new IllegalStateException("Should be able to create a namespace");
break;
case DROP_NAMESPACE:
- tableNamespace = "__DROP_TABLE_NAMESPACE_WITH_PERM_TEST__";
- root_conn.tableNamespaceOperations().create(tableNamespace);
- test_user_conn.tableNamespaceOperations().delete(tableNamespace);
- if (root_conn.tableNamespaceOperations().list().contains(tableNamespace))
- throw new IllegalStateException("Should be able to delete a table namespace");
+ namespace = "__DROP_NAMESPACE_WITH_PERM_TEST__";
+ root_conn.namespaceOperations().create(namespace);
+ test_user_conn.namespaceOperations().delete(namespace);
+ if (root_conn.namespaceOperations().list().contains(namespace))
+ throw new IllegalStateException("Should be able to delete a namespace");
break;
case ALTER_NAMESPACE:
- tableNamespace = "__ALTER_TABLE_NAMESPACE_WITH_PERM_TEST__";
- String tableNamespace2 = tableNamespace + "2";
- root_conn.tableNamespaceOperations().create(tableNamespace);
- test_user_conn.tableNamespaceOperations().setProperty(tableNamespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
- Map<String,String> propies = map(root_conn.tableNamespaceOperations().getProperties(tableNamespace));
+ namespace = "__ALTER_NAMESPACE_WITH_PERM_TEST__";
+ String namespace2 = namespace + "2";
+ root_conn.namespaceOperations().create(namespace);
+ test_user_conn.namespaceOperations().setProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey(), "003.14159%");
+ Map<String,String> propies = map(root_conn.namespaceOperations().getProperties(namespace));
if (!propies.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to set a table property");
- test_user_conn.tableNamespaceOperations().removeProperty(tableNamespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
- propies = map(root_conn.tableNamespaceOperations().getProperties(tableNamespace));
+ test_user_conn.namespaceOperations().removeProperty(namespace, Property.TABLE_BLOOM_ERRORRATE.getKey());
+ propies = map(root_conn.namespaceOperations().getProperties(namespace));
if (propies.get(Property.TABLE_BLOOM_ERRORRATE.getKey()).equals("003.14159%"))
throw new IllegalStateException("Should be able to remove a table property");
- test_user_conn.tableNamespaceOperations().rename(tableNamespace, tableNamespace2);
- if (root_conn.tableNamespaceOperations().list().contains(tableNamespace) || !root_conn.tableNamespaceOperations().list().contains(tableNamespace2))
+ test_user_conn.namespaceOperations().rename(namespace, namespace2);
+ if (root_conn.namespaceOperations().list().contains(namespace) || !root_conn.namespaceOperations().list().contains(namespace2))
throw new IllegalStateException("Should be able to rename a table");
break;
default:
http://git-wip-us.apache.org/repos/asf/accumulo/blob/ea8ec193/test/system/randomwalk/conf/modules/Concurrent.xml
----------------------------------------------------------------------
diff --git a/test/system/randomwalk/conf/modules/Concurrent.xml b/test/system/randomwalk/conf/modules/Concurrent.xml
index 3768878..dbe3d70 100644
--- a/test/system/randomwalk/conf/modules/Concurrent.xml
+++ b/test/system/randomwalk/conf/modules/Concurrent.xml
@@ -49,10 +49,10 @@
<edge id="ct.StartAll" weight="1000"/>
<edge id="ct.Shutdown" weight="10"/>
<edge id="ct.Config" weight="1000"/>
- <edge id="ct.CreateTableNamespace" weight="1000"/>
- <edge id="ct.DeleteTableNamespace" weight="100"/>
- <edge id="ct.RenameTableNamespace" weight="100"/>
- <edge id="ct.OfflineTableNamespace" weight="100"/>
+ <edge id="ct.CreateNamespace" weight="1000"/>
+ <edge id="ct.DeleteNamespace" weight="100"/>
+ <edge id="ct.RenameNamespace" weight="100"/>
+ <edge id="ct.OfflineNamespace" weight="100"/>
<edge id="ct.Apocalypse" weight="10"/>
<edge id="END" weight="1"/>
</node>
@@ -167,19 +167,19 @@
<edge id="ct.StartAll" weight="1"/>
</node>
-<node id="ct.CreateTableNamespace">
+<node id="ct.CreateNamespace">
<edge id="ct.StartAll" weight="1"/>
</node>
-<node id="ct.DeleteTableNamespace">
+<node id="ct.DeleteNamespace">
<edge id="ct.StartAll" weight="1"/>
</node>
-<node id="ct.RenameTableNamespace">
+<node id="ct.RenameNamespace">
<edge id="ct.StartAll" weight="1"/>
</node>
-<node id="ct.OfflineTableNamespace">
+<node id="ct.OfflineNamespace">
<edge id="ct.StartAll" weight="1"/>
</node>