Search in sources :

Example 76 with Connector

use of org.apache.accumulo.core.client.Connector in project accumulo by apache.

the class ReplicationTableUtilTest method setsCombinerOnMetadataCorrectly.

@Test
public void setsCombinerOnMetadataCorrectly() throws Exception {
    Connector conn = createMock(Connector.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(conn.tableOperations()).andReturn(tops);
    expect(tops.listIterators(myMetadataTable)).andReturn(iterators);
    tops.attachIterator(myMetadataTable, combiner);
    expectLastCall().once();
    expect(tops.getProperties(myMetadataTable)).andReturn(Collections.emptyList());
    tops.setProperty(myMetadataTable, Property.TABLE_FORMATTER_CLASS.getKey(), ReplicationTableUtil.STATUS_FORMATTER_CLASS_NAME);
    expectLastCall().once();
    replay(conn, tops);
    ReplicationTableUtil.configureMetadataTable(conn, myMetadataTable);
    verify(conn, tops);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) 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 77 with Connector

use of org.apache.accumulo.core.client.Connector in project accumulo by apache.

the class MockConnectorTest method testAggregation.

@Test
public void testAggregation() throws Exception {
    MockInstance mockInstance = new MockInstance();
    Connector c = mockInstance.getConnector("root", new PasswordToken(""));
    String table = "perDayCounts";
    c.tableOperations().create(table);
    IteratorSetting is = new IteratorSetting(10, "String Summation", SummingCombiner.class);
    Combiner.setColumns(is, Collections.singletonList(new IteratorSetting.Column("day")));
    SummingCombiner.setEncodingType(is, SummingCombiner.Type.STRING);
    c.tableOperations().attachIterator(table, is);
    String[][] keys = { { "foo", "day", "20080101" }, { "foo", "day", "20080101" }, { "foo", "day", "20080103" }, { "bar", "day", "20080101" }, { "bar", "day", "20080101" } };
    BatchWriter bw = c.createBatchWriter("perDayCounts", new BatchWriterConfig());
    for (String[] elt : keys) {
        Mutation m = new Mutation(new Text(elt[0]));
        m.put(new Text(elt[1]), new Text(elt[2]), new Value("1".getBytes()));
        bw.addMutation(m);
    }
    bw.close();
    Scanner s = c.createScanner("perDayCounts", Authorizations.EMPTY);
    Iterator<Entry<Key, Value>> iterator = s.iterator();
    assertTrue(iterator.hasNext());
    checkEntry(iterator.next(), "bar", "day", "20080101", "2");
    assertTrue(iterator.hasNext());
    checkEntry(iterator.next(), "foo", "day", "20080101", "2");
    assertTrue(iterator.hasNext());
    checkEntry(iterator.next(), "foo", "day", "20080103", "1");
    assertFalse(iterator.hasNext());
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) Text(org.apache.hadoop.io.Text) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Entry(java.util.Map.Entry) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Example 78 with Connector

use of org.apache.accumulo.core.client.Connector in project accumulo by apache.

the class MockConnectorTest method testMockMultiTableBatchWriter.

@Test
public void testMockMultiTableBatchWriter() throws Exception {
    Connector c = new MockConnector("root", new MockInstance());
    c.tableOperations().create("a");
    c.tableOperations().create("b");
    MultiTableBatchWriter bw = c.createMultiTableBatchWriter(new BatchWriterConfig());
    Mutation m1 = new Mutation("r1");
    m1.put("cf1", "cq1", 1, "v1");
    BatchWriter b = bw.getBatchWriter("a");
    b.addMutation(m1);
    b.flush();
    b = bw.getBatchWriter("b");
    b.addMutation(m1);
    b.flush();
    Scanner scanner = c.createScanner("a", Authorizations.EMPTY);
    int count = Iterators.size(scanner.iterator());
    assertEquals(1, count);
    scanner = c.createScanner("b", Authorizations.EMPTY);
    count = Iterators.size(scanner.iterator());
    assertEquals(1, count);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Scanner(org.apache.accumulo.core.client.Scanner) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) Mutation(org.apache.accumulo.core.data.Mutation) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Test(org.junit.Test)

Example 79 with Connector

use of org.apache.accumulo.core.client.Connector in project accumulo by apache.

the class MockConnectorTest method testSunnyDay.

@Test
public void testSunnyDay() throws Exception {
    Connector c = new MockConnector("root", new MockInstance());
    c.tableOperations().create("test");
    BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
    for (int i = 0; i < 100; i++) {
        int r = random.nextInt();
        Mutation m = new Mutation(asText(r));
        m.put(asText(random.nextInt()), asText(random.nextInt()), new Value(Integer.toHexString(r).getBytes()));
        bw.addMutation(m);
    }
    bw.close();
    BatchScanner s = c.createBatchScanner("test", Authorizations.EMPTY, 2);
    s.setRanges(Collections.singletonList(new Range()));
    Key key = null;
    int count = 0;
    for (Entry<Key, Value> entry : s) {
        if (key != null)
            assertTrue(key.compareTo(entry.getKey()) < 0);
        assertEquals(entry.getKey().getRow(), new Text(entry.getValue().get()));
        key = entry.getKey();
        count++;
    }
    assertEquals(100, count);
}
Also used : Connector(org.apache.accumulo.core.client.Connector) BatchScanner(org.apache.accumulo.core.client.BatchScanner) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) MultiTableBatchWriter(org.apache.accumulo.core.client.MultiTableBatchWriter) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 80 with Connector

use of org.apache.accumulo.core.client.Connector in project accumulo by apache.

the class MockConnectorTest method testChangeAuths.

@Test
public void testChangeAuths() throws Exception {
    Connector c = new MockConnector("root", new MockInstance());
    c.securityOperations().createLocalUser("greg", new PasswordToken(new byte[0]));
    assertTrue(c.securityOperations().getUserAuthorizations("greg").isEmpty());
    c.securityOperations().changeUserAuthorizations("greg", new Authorizations("A".getBytes()));
    assertTrue(c.securityOperations().getUserAuthorizations("greg").contains("A".getBytes()));
    c.securityOperations().changeUserAuthorizations("greg", new Authorizations("X", "Y", "Z"));
    assertTrue(c.securityOperations().getUserAuthorizations("greg").contains("X".getBytes()));
    assertFalse(c.securityOperations().getUserAuthorizations("greg").contains("A".getBytes()));
}
Also used : Connector(org.apache.accumulo.core.client.Connector) PasswordToken(org.apache.accumulo.core.client.security.tokens.PasswordToken) Authorizations(org.apache.accumulo.core.security.Authorizations) Test(org.junit.Test)

Aggregations

Connector (org.apache.accumulo.core.client.Connector)622 Test (org.junit.Test)415 BatchWriter (org.apache.accumulo.core.client.BatchWriter)171 Value (org.apache.accumulo.core.data.Value)162 Text (org.apache.hadoop.io.Text)160 Scanner (org.apache.accumulo.core.client.Scanner)158 Mutation (org.apache.accumulo.core.data.Mutation)152 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)143 Key (org.apache.accumulo.core.data.Key)139 PasswordToken (org.apache.accumulo.core.client.security.tokens.PasswordToken)101 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)87 AccumuloException (org.apache.accumulo.core.client.AccumuloException)83 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)75 Range (org.apache.accumulo.core.data.Range)74 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)65 Authorizations (org.apache.accumulo.core.security.Authorizations)60 HashSet (java.util.HashSet)57 Instance (org.apache.accumulo.core.client.Instance)55 ArrayList (java.util.ArrayList)53 Entry (java.util.Map.Entry)53