Search in sources :

Example 11 with NewTableConfiguration

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);
}
Also used : NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Mutation(org.apache.accumulo.core.data.Mutation) BatchWriter(org.apache.accumulo.core.client.BatchWriter) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) MutationsRejectedException(org.apache.accumulo.core.client.MutationsRejectedException) Test(org.junit.Test)

Example 12 with NewTableConfiguration

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Test(org.junit.Test)

Example 13 with NewTableConfiguration

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);
}
Also used : EnumSet(java.util.EnumSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 14 with NewTableConfiguration

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));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Test(org.junit.Test)

Example 15 with NewTableConfiguration

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);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Test(org.junit.Test)

Aggregations

NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)54 Test (org.junit.Test)47 Connector (org.apache.accumulo.core.client.Connector)40 HashMap (java.util.HashMap)22 Text (org.apache.hadoop.io.Text)22 BatchWriter (org.apache.accumulo.core.client.BatchWriter)20 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)18 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)17 EnumSet (java.util.EnumSet)13 Mutation (org.apache.accumulo.core.data.Mutation)13 Value (org.apache.accumulo.core.data.Value)13 Set (java.util.Set)12 ImmutableSet (com.google.common.collect.ImmutableSet)11 Scanner (org.apache.accumulo.core.client.Scanner)10 Key (org.apache.accumulo.core.data.Key)10 SummarizerConfiguration (org.apache.accumulo.core.client.summary.SummarizerConfiguration)9 Summary (org.apache.accumulo.core.client.summary.Summary)8 TreeSet (java.util.TreeSet)7 CounterSummary (org.apache.accumulo.core.client.summary.CounterSummary)7 Range (org.apache.accumulo.core.data.Range)5