Package org.apache.accumulo.core.client.admin

Examples of org.apache.accumulo.core.client.admin.TableOperations


public class MetaSplitIT extends SimpleMacIT {

  @Test(expected = AccumuloException.class)
  public void testRootTableSplit() throws Exception {
    TableOperations opts = getConnector().tableOperations();
    SortedSet<Text> splits = new TreeSet<Text>();
    splits.add(new Text("5"));
    opts.addSplits(RootTable.NAME, splits);
  }
View Full Code Here


    opts.addSplits(RootTable.NAME, splits);
  }

  @Test
  public void testRootTableMerge() throws Exception {
    TableOperations opts = getConnector().tableOperations();
    opts.merge(RootTable.NAME, null, null);
  }
View Full Code Here

    opts.addSplits(MetadataTable.NAME, splits);
  }

  @Test(timeout = 60000)
  public void testMetadataTableSplit() throws Exception {
    TableOperations opts = getConnector().tableOperations();
    for (int i = 1; i <= 10; i++) {
      opts.create("" + i);
    }
    opts.merge(MetadataTable.NAME, new Text("01"), new Text("02"));
    assertEquals(1, opts.listSplits(MetadataTable.NAME).size());
    addSplits(opts, "4 5 6 7 8".split(" "));
    assertEquals(6, opts.listSplits(MetadataTable.NAME).size());
    opts.merge(MetadataTable.NAME, new Text("6"), new Text("9"));
    assertEquals(4, opts.listSplits(MetadataTable.NAME).size());
    addSplits(opts, "44 55 66 77 88".split(" "));
    assertEquals(9, opts.listSplits(MetadataTable.NAME).size());
    opts.merge(MetadataTable.NAME, new Text("5"), new Text("7"));
    assertEquals(6, opts.listSplits(MetadataTable.NAME).size());
    opts.merge(MetadataTable.NAME, null, null);
    assertEquals(0, opts.listSplits(MetadataTable.NAME).size());
  }
View Full Code Here

  }

  @Test(timeout= 60 * 1000)
  public void testBulkImportFailure() throws Exception {
    String tableName = getUniqueNames(1)[0];
    TableOperations to = getConnector().tableOperations();
    to.create(tableName);
    File bulk = new File(rootPath() + "/bulk");
    System.out.println("bulk: " + bulk);
    assertTrue(bulk.mkdirs());
    File err = new File(rootPath() + "/err");
    assertTrue(err.mkdirs());
    File bogus = new File(bulk + "/bogus.rf");
    assertTrue(bogus.createNewFile());
    to.importDirectory(tableName, bulk.toString(), err.toString(), false);
    assertEquals(1, err.list().length);
  }
View Full Code Here

  }

  @Test(timeout = 30 * 1000)
  public void createMergeClonedTable() throws Exception {
    String originalTable = makeTableName();
    TableOperations tops = connector.tableOperations();

    TreeSet<Text> splits = Sets.newTreeSet(Arrays.asList(new Text("a"), new Text("b"), new Text("c"), new Text("d")));

    tops.create(originalTable);
    tops.addSplits(originalTable, splits);

    BatchWriter bw = connector.createBatchWriter(originalTable, new BatchWriterConfig());
    for (Text row : splits) {
      Mutation m = new Mutation(row);
      for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
          m.put(Integer.toString(i), Integer.toString(j), Integer.toString(i + j));
        }
      }

      bw.addMutation(m);
    }

    bw.close();

    String clonedTable = makeTableName();

    tops.clone(originalTable, clonedTable, true, null, null);
    tops.merge(clonedTable, null, new Text("b"));

    Map<String,Integer> rowCounts = Maps.newHashMap();
    Scanner s = connector.createScanner(clonedTable, new Authorizations());
    for (Entry<Key,Value> entry : s) {
      final Key key = entry.getKey();
      String row = key.getRow().toString();
      String cf = key.getColumnFamily().toString(), cq = key.getColumnQualifier().toString();
      String value = entry.getValue().toString();

      if (rowCounts.containsKey(row)) {
        rowCounts.put(row, rowCounts.get(row) + 1);
      } else {
        rowCounts.put(row, 1);
      }

      Assert.assertEquals(Integer.parseInt(cf) + Integer.parseInt(cq), Integer.parseInt(value));
    }

    Collection<Text> clonedSplits = tops.listSplits(clonedTable);
    Set<Text> expectedSplits = Sets.newHashSet(new Text("b"), new Text("c"), new Text("d"));
    for (Text clonedSplit : clonedSplits) {
      Assert.assertTrue("Encountered unexpected split on the cloned table: " + clonedSplit, expectedSplits.remove(clonedSplit));
    }

View Full Code Here

  @Test
  public void testImport() throws Throwable {
    ImportTestFilesAndData dataAndFiles = prepareTestFiles();
    Instance instance = new MockInstance("foo");
    Connector connector = instance.getConnector("user", new PasswordToken(new byte[0]));
    TableOperations tableOperations = connector.tableOperations();
    tableOperations.create("a_table");
    tableOperations.importDirectory("a_table", dataAndFiles.importPath.toString(), dataAndFiles.failurePath.toString(), false);
    Scanner scanner = connector.createScanner("a_table", new Authorizations());
    Iterator<Entry<Key,Value>> iterator = scanner.iterator();
    for (int i = 0; i < 5; i++) {
      Assert.assertTrue(iterator.hasNext());
      Entry<Key,Value> kv = iterator.next();
View Full Code Here

  @Test(expected = TableNotFoundException.class)
  public void testFailsWithNoTable() throws Throwable {
    Instance instance = new MockInstance("foo");
    Connector connector = instance.getConnector("user", new PasswordToken(new byte[0]));
    TableOperations tableOperations = connector.tableOperations();
    ImportTestFilesAndData testFiles = prepareTestFiles();
    tableOperations.importDirectory("doesnt_exist_table", testFiles.importPath.toString(), testFiles.failurePath.toString(), false);
  }
View Full Code Here

  @Test(expected = IOException.class)
  public void testFailsWithNonEmptyFailureDirectory() throws Throwable {
    Instance instance = new MockInstance("foo");
    Connector connector = instance.getConnector("user", new PasswordToken(new byte[0]));
    TableOperations tableOperations = connector.tableOperations();
    ImportTestFilesAndData testFiles = prepareTestFiles();
    FileSystem fs = testFiles.failurePath.getFileSystem(new Configuration());
    fs.open(testFiles.failurePath.suffix("/something")).close();
    tableOperations.importDirectory("doesnt_exist_table", testFiles.importPath.toString(), testFiles.failurePath.toString(), false);
  }
View Full Code Here

  @Test
  public void testDeleteRows() throws Exception {
    Instance instance = new MockInstance("rows");
    Connector connector = instance.getConnector("user", new PasswordToken("foo".getBytes()));
    TableOperations to = connector.tableOperations();
    to.create("test");
    BatchWriter bw = connector.createBatchWriter("test", new BatchWriterConfig());
    for (int r = 0; r < 20; r++) {
      Mutation m = new Mutation("" + r);
      for (int c = 0; c < 5; c++) {
        m.put(new Text("cf"), new Text("" + c), new Value(("" + c).getBytes()));
      }
      bw.addMutation(m);
    }
    bw.flush();
    to.deleteRows("test", new Text("1"), new Text("2"));
    Scanner s = connector.createScanner("test", Authorizations.EMPTY);
    int oneCnt = 0;
    for (Entry<Key,Value> entry : s) {
      char rowStart = entry.getKey().getRow().toString().charAt(0);
      Assert.assertTrue(rowStart != '2');
View Full Code Here

  @Test
  public void testDeleteRowsWithNullKeys() throws Exception {
    Instance instance = new MockInstance("rows");
    Connector connector = instance.getConnector("user", new PasswordToken("foo"));
    TableOperations to = connector.tableOperations();
    to.create("test2");
    BatchWriter bw = connector.createBatchWriter("test2", new BatchWriterConfig());
    for (int r = 0; r < 30; r++) {
      Mutation m = new Mutation(Integer.toString(r));
      for (int c = 0; c < 5; c++) {
        m.put(new Text("cf"), new Text(Integer.toString(c)), new Value(Integer.toString(c).getBytes()));
      }
      bw.addMutation(m);
    }
    bw.flush();

    // test null end
    // will remove rows 4 through 9 (6 * 5 = 30 entries)
    to.deleteRows("test2", new Text("30"), null);
    Scanner s = connector.createScanner("test2", Authorizations.EMPTY);
    int rowCnt = 0;
    for (Entry<Key,Value> entry : s) {
      String rowId = entry.getKey().getRow().toString();
      Assert.assertFalse(rowId.startsWith("30"));
      rowCnt++;
    }
    s.close();
    Assert.assertEquals(120, rowCnt);

    // test null start
    // will remove 0-1, 10-19, 2
    to.deleteRows("test2", null, new Text("2"));
    s = connector.createScanner("test2", Authorizations.EMPTY);
    rowCnt = 0;
    for (Entry<Key,Value> entry : s) {
      char rowStart = entry.getKey().getRow().toString().charAt(0);
      Assert.assertTrue(rowStart >= '2');
      rowCnt++;
    }
    s.close();
    Assert.assertEquals(55, rowCnt);

    // test null start and end
    // deletes everything still left
    to.deleteRows("test2", null, null);
    s = connector.createScanner("test2", Authorizations.EMPTY);
    rowCnt = 0;
    for (@SuppressWarnings("unused")
    Entry<Key,Value> entry : s) {
      rowCnt++;
    }
    s.close();
    to.delete("test2");
    Assert.assertEquals(0, rowCnt);

  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.admin.TableOperations

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.