Package org.apache.accumulo.core.client

Examples of org.apache.accumulo.core.client.Connector


    // create a batchwriter to remove the delete flags for successful
    // deletes; Need separate writer for the root tablet.
    BatchWriter writer = null;
    BatchWriter rootWriter = null;
    if (!offline) {
      Connector c;
      try {
        c = instance.getConnector(SecurityConstants.SYSTEM_PRINCIPAL, SecurityConstants.getSystemToken());
        writer = c.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
        rootWriter = c.createBatchWriter(Constants.METADATA_TABLE_NAME, new BatchWriterConfig());
      } catch (Exception e) {
        log.error("Unable to create writer to remove file from the !METADATA table", e);
      }
    }
    // when deleting a dir and all files in that dir, only need to delete the dir
View Full Code Here


public class MockTableOperationsTest {
 
  @Test
  public void testCreateUseVersions() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    Instance instance = new MockInstance("topstest");
    Connector conn = instance.getConnector("user", new PasswordToken("pass"));
    String t = "tableName1";
   
    {
      conn.tableOperations().create(t, false, TimeType.LOGICAL);
     
      writeVersionable(conn, t, 3);
      assertVersionable(conn, t, 3);
     
      IteratorSetting settings = new IteratorSetting(20, VersioningIterator.class);
      conn.tableOperations().attachIterator(t, settings);
     
      assertVersionable(conn, t, 1);
     
      conn.tableOperations().delete(t);
    }
   
    {
      conn.tableOperations().create(t, true, TimeType.MILLIS);
     
      try {
        IteratorSetting settings = new IteratorSetting(20, VersioningIterator.class);
        conn.tableOperations().attachIterator(t, settings);
        Assert.fail();
      } catch (AccumuloException ex) {}
     
      writeVersionable(conn, t, 3);
      assertVersionable(conn, t, 1);
     
      conn.tableOperations().delete(t);
    }
  }
View Full Code Here

  }
 
  @Test
  public void testTableNotFound() throws AccumuloException, AccumuloSecurityException, TableExistsException, TableNotFoundException {
    Instance instance = new MockInstance("topstest");
    Connector conn = instance.getConnector("user", new PasswordToken("pass"));
    String t = "tableName";
    try {
      conn.tableOperations().attachIterator(t, null);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().checkIteratorConflicts(t, null, EnumSet.allOf(IteratorScope.class));
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().delete(t);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().getIteratorSetting(t, null, null);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().getProperties(t);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().listSplits(t);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().listIterators(t);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().removeIterator(t, null, null);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    try {
      conn.tableOperations().rename(t, t);
      Assert.fail();
    } catch (TableNotFoundException e) {}
    conn.tableOperations().create(t);
    try {
      conn.tableOperations().create(t);
      Assert.fail();
    } catch (TableExistsException e) {}
    try {
      conn.tableOperations().rename(t, t);
      Assert.fail();
    } catch (TableExistsException e) {}
  }
View Full Code Here

 
  public static void main(String[] args) throws Exception {
    Opts opts = new Opts();
    opts.parseArgs(PrintEvents.class.getName(), args);
   
    Connector conn = opts.getConnector();
   
    printEvents(conn, opts.tableId, opts.endRow, opts.time);
  }
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();
      Pair<Key,Value> expected = dataAndFiles.keyVals.get(i);
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", Constants.NO_AUTHS);
    int oneCnt = 0;
    for (Entry<Key,Value> entry : s) {
      char rowStart = entry.getKey().getRow().toString().charAt(0);
      Assert.assertTrue(rowStart != '2');
      oneCnt += rowStart == '1' ? 1 : 0;
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", Constants.NO_AUTHS);
    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", Constants.NO_AUTHS);
    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", Constants.NO_AUTHS);
    rowCnt = 0;
    for (@SuppressWarnings("unused")
    Entry<Key,Value> entry : s) {
      rowCnt++;
    }
View Full Code Here


  @Test
  public void testTableIdMap() throws Exception {
    Instance inst = new MockInstance("testTableIdMap");
    Connector conn = inst.getConnector("root", new PasswordToken(""));
    TableOperations tops = conn.tableOperations();
    tops.create("foo");

    // Should get a table ID, not the table name
    Assert.assertNotEquals("foo", tops.tableIdMap().get("foo"));
  }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.Connector

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.