Search in sources :

Example 76 with AccumuloClient

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

the class AccumuloInputFormatIT method testMapWithBatchScanner.

@Test
public void testMapWithBatchScanner() throws Exception {
    final String TEST_TABLE_2 = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(TEST_TABLE_2);
        AccumuloOutputFormatIT.insertData(c, TEST_TABLE_2);
        assertEquals(0, MRTester.main(new String[] { TEST_TABLE_2, org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.class.getName(), "True", "False" }));
        assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_map").size());
        assertEquals(1, assertionErrors.get(TEST_TABLE_2 + "_cleanup").size());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Test(org.junit.Test)

Example 77 with AccumuloClient

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

the class AccumuloInputFormatIT method testCorrectRangeInputSplits.

@Test
public void testCorrectRangeInputSplits() throws Exception {
    Job job = Job.getInstance();
    String table = getUniqueNames(1)[0];
    Authorizations auths = new Authorizations("foo");
    Collection<Pair<Text, Text>> fetchColumns = Collections.singleton(new Pair<>(new Text("foo"), new Text("bar")));
    boolean isolated = true, localIters = true;
    Level level = Level.WARN;
    try (AccumuloClient accumuloClient = Accumulo.newClient().from(getClientProps()).build()) {
        accumuloClient.tableOperations().create(table);
        ClientInfo ci = getClientInfo();
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setZooKeeperInstance(job, ci.getInstanceName(), ci.getZooKeepers());
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setConnectorInfo(job, ci.getPrincipal(), ci.getAuthenticationToken());
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setInputTableName(job, table);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setScanAuthorizations(job, auths);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setScanIsolation(job, isolated);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setLocalIterators(job, localIters);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.fetchColumns(job, fetchColumns);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat.setLogLevel(job, level);
        org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat aif = new org.apache.accumulo.core.client.mapreduce.AccumuloInputFormat();
        List<InputSplit> splits = aif.getSplits(job);
        assertEquals(1, splits.size());
        InputSplit split = splits.get(0);
        assertEquals(org.apache.accumulo.core.client.mapreduce.RangeInputSplit.class, split.getClass());
        org.apache.accumulo.core.client.mapreduce.RangeInputSplit risplit = (org.apache.accumulo.core.client.mapreduce.RangeInputSplit) split;
        assertEquals(table, risplit.getTableName());
        assertEquals(isolated, risplit.isIsolatedScan());
        assertEquals(localIters, risplit.usesLocalIterators());
        assertEquals(fetchColumns, risplit.getFetchedColumns());
        assertEquals(level, risplit.getLogLevel());
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Authorizations(org.apache.accumulo.core.security.Authorizations) Text(org.apache.hadoop.io.Text) Level(org.apache.log4j.Level) ClientInfo(org.apache.accumulo.core.clientImpl.ClientInfo) Job(org.apache.hadoop.mapreduce.Job) InputSplit(org.apache.hadoop.mapreduce.InputSplit) Pair(org.apache.accumulo.core.util.Pair) Test(org.junit.Test)

Example 78 with AccumuloClient

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

the class AccumuloRowInputFormatIT method test.

@Test
public void test() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProps()).build()) {
        String tableName = getUniqueNames(1)[0];
        client.tableOperations().create(tableName);
        try (BatchWriter writer = client.createBatchWriter(tableName)) {
            insertList(writer, row1);
            insertList(writer, row2);
            insertList(writer, row3);
        }
        MRTester.main(new String[] { tableName });
        assertNull(e1);
        assertNull(e2);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Test(org.junit.Test)

Example 79 with AccumuloClient

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

the class MetricsIT method doWorkToGenerateMetrics.

private void doWorkToGenerateMetrics() throws Exception {
    try (AccumuloClient client = Accumulo.newClient().from(getClientProperties()).build()) {
        String tableName = this.getClass().getSimpleName();
        client.tableOperations().create(tableName);
        BatchWriterConfig config = new BatchWriterConfig().setMaxMemory(0);
        try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
            Mutation m = new Mutation("row");
            m.put("cf", "cq", new Value("value"));
            writer.addMutation(m);
        }
        client.tableOperations().flush(tableName);
        try (BatchWriter writer = client.createBatchWriter(tableName, config)) {
            Mutation m = new Mutation("row");
            m.put("cf", "cq", new Value("value"));
            writer.addMutation(m);
        }
        client.tableOperations().compact(tableName, new CompactionConfig());
        client.tableOperations().delete(tableName);
        while (client.tableOperations().exists(tableName)) {
            Thread.sleep(1000);
        }
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) Value(org.apache.accumulo.core.data.Value) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation)

Example 80 with AccumuloClient

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

the class AccumuloInputFormatIT method testSample.

@Test
public void testSample() throws Exception {
    final String TEST_TABLE_3 = getUniqueNames(1)[0];
    try (AccumuloClient c = Accumulo.newClient().from(getClientProps()).build()) {
        c.tableOperations().create(TEST_TABLE_3, new NewTableConfiguration().enableSampling(SAMPLER_CONFIG));
        BatchWriter bw = c.createBatchWriter(TEST_TABLE_3);
        for (int i = 0; i < 100; i++) {
            Mutation m = new Mutation(new Text(String.format("%09x", i + 1)));
            m.put("", "", String.format("%09x", i));
            bw.addMutation(m);
        }
        bw.close();
        MRTester.main(TEST_TABLE_3, "False", "True");
        assertEquals(38, e1Count);
        assertEquals(1, e2Count);
        e2Count = e1Count = 0;
        MRTester.main(TEST_TABLE_3, "False", "False");
        assertEquals(0, e1Count);
        assertEquals(0, e2Count);
        e2Count = e1Count = 0;
        MRTester.main(TEST_TABLE_3, "True", "True");
        assertEquals(38, e1Count);
        assertEquals(1, e2Count);
    }
}
Also used : AccumuloClient(org.apache.accumulo.core.client.AccumuloClient) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Text(org.apache.hadoop.io.Text) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) Test(org.junit.Test)

Aggregations

AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)500 Test (org.junit.Test)411 BatchWriter (org.apache.accumulo.core.client.BatchWriter)149 Text (org.apache.hadoop.io.Text)143 Mutation (org.apache.accumulo.core.data.Mutation)138 Scanner (org.apache.accumulo.core.client.Scanner)122 Value (org.apache.accumulo.core.data.Value)118 Key (org.apache.accumulo.core.data.Key)108 NewTableConfiguration (org.apache.accumulo.core.client.admin.NewTableConfiguration)91 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)64 HashMap (java.util.HashMap)61 Range (org.apache.accumulo.core.data.Range)51 TreeSet (java.util.TreeSet)50 ArrayList (java.util.ArrayList)47 Entry (java.util.Map.Entry)41 Path (org.apache.hadoop.fs.Path)39 CompactionConfig (org.apache.accumulo.core.client.admin.CompactionConfig)34 Authorizations (org.apache.accumulo.core.security.Authorizations)34 BatchScanner (org.apache.accumulo.core.client.BatchScanner)32 HashSet (java.util.HashSet)31