Search in sources :

Example 71 with EnumSet

use of java.util.EnumSet in project accumulo by apache.

the class StatusCombinerMacIT method testCombinerSetOnMetadata.

@Test
public void testCombinerSetOnMetadata() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        TableOperations tops = client.tableOperations();
        Map<String, EnumSet<IteratorScope>> iterators = tops.listIterators(MetadataTable.NAME);
        assertTrue(iterators.containsKey(ReplicationTableUtil.COMBINER_NAME));
        EnumSet<IteratorScope> scopes = iterators.get(ReplicationTableUtil.COMBINER_NAME);
        assertEquals(3, scopes.size());
        assertTrue(scopes.contains(IteratorScope.scan));
        assertTrue(scopes.contains(IteratorScope.minc));
        assertTrue(scopes.contains(IteratorScope.majc));
        Map<String, String> config = tops.getConfiguration(MetadataTable.NAME);
        Map<String, String> properties = Map.copyOf(config);
        for (IteratorScope scope : scopes) {
            String key = Property.TABLE_ITERATOR_PREFIX.getKey() + scope.name() + "." + ReplicationTableUtil.COMBINER_NAME + ".opt.columns";
            assertTrue("Properties did not contain key : " + key, properties.containsKey(key));
            assertEquals(ReplicationSection.COLF.toString(), properties.get(key));
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) EnumSet(java.util.EnumSet) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.Test)

Example 72 with EnumSet

use of java.util.EnumSet in project accumulo by apache.

the class ReplicationTableUtilTest method setsCombinerOnMetadataCorrectly.

@Test
public void setsCombinerOnMetadataCorrectly() throws Exception {
    AccumuloClient client = createMock(AccumuloClient.class);
    TableOperations tops = createMock(TableOperations.class);
    String myMetadataTable = "mymetadata";
    Map<String, EnumSet<IteratorScope>> iterators = new HashMap<>();
    iterators.put("vers", EnumSet.of(IteratorScope.majc, IteratorScope.minc, IteratorScope.scan));
    IteratorSetting combiner = new IteratorSetting(9, "replcombiner", StatusCombiner.class);
    Combiner.setColumns(combiner, Collections.singletonList(new Column(ReplicationSection.COLF)));
    expect(client.tableOperations()).andReturn(tops);
    expect(tops.listIterators(myMetadataTable)).andReturn(iterators);
    tops.attachIterator(myMetadataTable, combiner);
    expectLastCall().once();
    expect(tops.getConfiguration(myMetadataTable)).andReturn(Collections.emptyMap());
    tops.setProperty(myMetadataTable, Property.TABLE_FORMATTER_CLASS.getKey(), ReplicationTableUtil.STATUS_FORMATTER_CLASS_NAME);
    expectLastCall().once();
    replay(client, tops);
    ReplicationTableUtil.configureMetadataTable(client, myMetadataTable);
    verify(client, tops);
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) Column(org.apache.accumulo.core.client.IteratorSetting.Column) EnumSet(java.util.EnumSet) Test(org.junit.Test)

Example 73 with EnumSet

use of java.util.EnumSet in project accumulo by apache.

the class NewTableConfigurationIT method testNtcChaining.

/**
 * Test NewTableConfiguration chaining.
 */
@Test
public void testNtcChaining() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(2)[0];
        IteratorSetting setting = new IteratorSetting(10, "anIterator", "it.class", Collections.emptyMap());
        Map<String, Set<Text>> lgroups = new HashMap<>();
        lgroups.put("lgp", Set.of(new Text("col")));
        NewTableConfiguration ntc = new NewTableConfiguration().withoutDefaultIterators().attachIterator(setting, EnumSet.of(IteratorScope.scan)).setLocalityGroups(lgroups);
        client.tableOperations().create(tableName, ntc);
        Map<String, EnumSet<IteratorScope>> iteratorList = client.tableOperations().listIterators(tableName);
        assertEquals(1, iteratorList.size());
        verifyIterators(client, tableName, new String[] { "table.iterator.scan.anIterator=10,it.class" }, false);
        client.tableOperations().removeIterator(tableName, "anIterator", EnumSet.of(IteratorScope.scan));
        verifyIterators(client, tableName, new String[] {}, false);
        iteratorList = client.tableOperations().listIterators(tableName);
        assertEquals(0, iteratorList.size());
        int count = 0;
        for (Entry<String, String> property : client.tableOperations().getProperties(tableName)) {
            if (property.getKey().equals("table.group.lgp")) {
                assertEquals(property.getValue(), "col");
                count++;
            }
            if (property.getKey().equals("table.groups.enabled")) {
                assertEquals(property.getValue(), "lgp");
                count++;
            }
        }
        assertEquals(2, count);
        Map<String, Set<Text>> createdLocalityGroups = client.tableOperations().getLocalityGroups(tableName);
        assertEquals(1, createdLocalityGroups.size());
        assertEquals(createdLocalityGroups.get("lgp"), Set.of(new Text("col")));
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Set(java.util.Set) EnumSet(java.util.EnumSet) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) EnumSet(java.util.EnumSet) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 74 with EnumSet

use of java.util.EnumSet in project accumulo by apache.

the class NewTableConfigurationIT method testSetGroupsWithoutDefaultIterators.

/**
 * Create table with initial locality groups but no default iterators
 */
@Test
public void testSetGroupsWithoutDefaultIterators() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(2)[0];
        NewTableConfiguration ntc = new NewTableConfiguration().withoutDefaultIterators();
        Map<String, Set<Text>> lgroups = new HashMap<>();
        lgroups.put("lg1", Set.of(new Text("colF")));
        ntc.setLocalityGroups(lgroups);
        client.tableOperations().create(tableName, ntc);
        // verify groups and verify no iterators
        Map<String, Set<Text>> createdLocalityGroups = client.tableOperations().getLocalityGroups(tableName);
        assertEquals(1, createdLocalityGroups.size());
        assertEquals(createdLocalityGroups.get("lg1"), Set.of(new Text("colF")));
        Map<String, EnumSet<IteratorScope>> iterators = client.tableOperations().listIterators(tableName);
        assertEquals(0, iterators.size());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Set(java.util.Set) EnumSet(java.util.EnumSet) HashMap(java.util.HashMap) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) EnumSet(java.util.EnumSet) Text(org.apache.hadoop.io.Text) Test(org.junit.Test)

Example 75 with EnumSet

use of java.util.EnumSet in project accumulo by apache.

the class NewTableConfigurationIT method testPreconfiguredIteratorWithDefaultIterator2.

/**
 * Test pre-configuring iterator with default iterator. Configure IteratorSetting values into
 * method call.
 */
@Test
public void testPreconfiguredIteratorWithDefaultIterator2() throws AccumuloException, TableNotFoundException, AccumuloSecurityException, TableExistsException {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(2)[0];
        NewTableConfiguration ntc = new NewTableConfiguration();
        IteratorSetting setting = new IteratorSetting(10, "someName", "foo.bar");
        ntc.attachIterator(setting);
        client.tableOperations().create(tableName, ntc);
        Map<String, EnumSet<IteratorScope>> iteratorList = client.tableOperations().listIterators(tableName);
        // should count the created iterator plus the default iterator
        assertEquals(2, iteratorList.size());
        verifyIterators(client, tableName, new String[] { "table.iterator.scan.someName=10,foo.bar" }, true);
        client.tableOperations().removeIterator(tableName, "someName", EnumSet.allOf(IteratorScope.class));
        verifyIterators(client, tableName, new String[] {}, true);
        Map<String, EnumSet<IteratorScope>> iteratorList2 = client.tableOperations().listIterators(tableName);
        assertEquals(1, iteratorList2.size());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) EnumSet(java.util.EnumSet) IteratorScope(org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope) Test(org.junit.Test)

Aggregations

EnumSet (java.util.EnumSet)151 Set (java.util.Set)44 ArrayList (java.util.ArrayList)43 Map (java.util.Map)30 List (java.util.List)29 HashMap (java.util.HashMap)27 HashSet (java.util.HashSet)27 Collection (java.util.Collection)22 Test (org.junit.Test)20 Collectors (java.util.stream.Collectors)19 IOException (java.io.IOException)16 Collections (java.util.Collections)14 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)13 IteratorScope (org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope)12 TreeSet (java.util.TreeSet)11 File (java.io.File)10 Arrays (java.util.Arrays)10 LinkedHashSet (java.util.LinkedHashSet)10 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)9 TreeMap (java.util.TreeMap)8