use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NamespacesIT method verifyConstraintInheritance.
@Test
public void verifyConstraintInheritance() throws Exception {
String t1 = namespace + ".1";
c.namespaceOperations().create(namespace);
c.tableOperations().create(t1, new NewTableConfiguration().withoutDefaultIterators());
String constraintClassName = NumericValueConstraint.class.getName();
assertFalse(c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName));
assertFalse(c.tableOperations().listConstraints(t1).containsKey(constraintClassName));
c.namespaceOperations().addConstraint(namespace, constraintClassName);
boolean passed = false;
for (int i = 0; i < 5; i++) {
if (!c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName)) {
Thread.sleep(500);
continue;
}
if (!c.tableOperations().listConstraints(t1).containsKey(constraintClassName)) {
Thread.sleep(500);
continue;
}
passed = true;
break;
}
assertTrue("Failed to observe newly-added constraint", passed);
passed = false;
Integer namespaceNum = null;
for (int i = 0; i < 5; i++) {
namespaceNum = c.namespaceOperations().listConstraints(namespace).get(constraintClassName);
if (null == namespaceNum) {
Thread.sleep(500);
continue;
}
Integer tableNum = c.tableOperations().listConstraints(t1).get(constraintClassName);
if (null == tableNum) {
Thread.sleep(500);
continue;
}
assertEquals(namespaceNum, tableNum);
passed = true;
}
assertTrue("Failed to observe constraint in both table and namespace", passed);
Mutation m1 = new Mutation("r1");
Mutation m2 = new Mutation("r2");
Mutation m3 = new Mutation("r3");
m1.put("a", "b", new Value("abcde".getBytes(UTF_8)));
m2.put("e", "f", new Value("123".getBytes(UTF_8)));
m3.put("c", "d", new Value("zyxwv".getBytes(UTF_8)));
passed = false;
for (int i = 0; i < 5; i++) {
BatchWriter bw = c.createBatchWriter(t1, new BatchWriterConfig());
bw.addMutations(Arrays.asList(m1, m2, m3));
try {
bw.close();
Thread.sleep(500);
} catch (MutationsRejectedException e) {
passed = true;
assertEquals(1, e.getConstraintViolationSummaries().size());
assertEquals(2, e.getConstraintViolationSummaries().get(0).getNumberOfViolatingMutations());
break;
}
}
assertTrue("Failed to see mutations rejected after constraint was added", passed);
assertNotNull("Namespace constraint ID should not be null", namespaceNum);
c.namespaceOperations().removeConstraint(namespace, namespaceNum);
passed = false;
for (int i = 0; i < 5; i++) {
if (c.namespaceOperations().listConstraints(namespace).containsKey(constraintClassName)) {
Thread.sleep(500);
continue;
}
if (c.tableOperations().listConstraints(t1).containsKey(constraintClassName)) {
Thread.sleep(500);
continue;
}
passed = true;
}
assertTrue("Failed to verify that constraint was removed from namespace and table", passed);
passed = false;
for (int i = 0; i < 5; i++) {
BatchWriter bw = c.createBatchWriter(t1, new BatchWriterConfig());
try {
bw.addMutations(Arrays.asList(m1, m2, m3));
bw.close();
} catch (MutationsRejectedException e) {
Thread.sleep(500);
continue;
}
passed = true;
}
assertTrue("Failed to add mutations that should be allowed", passed);
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testSettingIteratorAndProperties.
/**
* Create iterator and setProperties method together.
*/
@Test
public void testSettingIteratorAndProperties() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
Connector conn = getConnector();
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
ntc.attachIterator(setting);
Map<String, String> props = new HashMap<>();
props.put(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop1", "val1");
props.put(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop2", "val2");
ntc.setProperties(props);
conn.tableOperations().create(tableName, ntc);
int count = 0;
for (Entry<String, String> property : conn.tableOperations().getProperties(tableName)) {
if (property.getKey().equals(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop1")) {
assertEquals(property.getValue(), "val1");
count++;
}
if (property.getKey().equals(Property.TABLE_ARBITRARY_PROP_PREFIX.getKey() + "prop2")) {
assertEquals(property.getValue(), "val2");
count++;
}
}
assertEquals(2, count);
verifyIterators(conn, tableName, new String[] { "table.iterator.scan.someName=10,foo.bar" }, true);
conn.tableOperations().removeIterator(tableName, "someName", EnumSet.of(IteratorScope.scan));
verifyIterators(conn, tableName, new String[] {}, true);
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testSetPropertiesDisjointCheck.
/**
* Verify that disjoint check works as expected with setProperties
*/
@Test(expected = IllegalArgumentException.class)
public void testSetPropertiesDisjointCheck() {
NewTableConfiguration ntc = new NewTableConfiguration();
Map<String, Set<Text>> lgroups = new HashMap<>();
lgroups.put("lg1", ImmutableSet.of(new Text("dog")));
ntc.setLocalityGroups(lgroups);
Map<String, String> props = new HashMap<>();
props.put("table.key1", "val1");
props.put("table.group.lg1", "cat");
ntc.setProperties(props);
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method tableNameOnly.
@SuppressWarnings("deprecation")
@Test
public void tableNameOnly() throws Exception {
log.info("Starting tableNameOnly");
// Create a table with the initial properties
Connector connector = getConnector();
String tableName = getUniqueNames(2)[0];
connector.tableOperations().create(tableName, new NewTableConfiguration());
String tableNameOrig = "original";
connector.tableOperations().create(tableNameOrig, true);
int countNew = numProperties(connector, tableName);
int countOrig = compareProperties(connector, tableNameOrig, tableName, null);
Assert.assertEquals("Extra properties using the new create method", countOrig, countNew);
Assert.assertTrue("Wrong TimeType", checkTimeType(connector, tableName, TimeType.MILLIS));
}
use of org.apache.accumulo.core.client.admin.NewTableConfiguration in project accumulo by apache.
the class NewTableConfigurationIT method testSettingInitialIteratorWithAdditionalIteratorOptions.
/**
* Test pre-configuring iterator with additional options.
*/
@Test
public void testSettingInitialIteratorWithAdditionalIteratorOptions() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
Connector conn = getConnector();
String tableName = getUniqueNames(2)[0];
NewTableConfiguration ntc = new NewTableConfiguration();
IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
setting.addOptions(Collections.singletonMap("key", "value"));
ntc.attachIterator(setting);
conn.tableOperations().create(tableName, ntc);
verifyIterators(conn, tableName, new String[] { "table.iterator.scan.someName=10,foo.bar", "table.iterator.scan.someName.opt.key=value" }, true);
conn.tableOperations().removeIterator(tableName, "someName", EnumSet.of(IteratorScope.scan));
verifyIterators(conn, tableName, new String[] {}, true);
}
Aggregations