Search in sources :

Example 1 with Locations

use of org.apache.accumulo.core.client.admin.Locations in project accumulo by apache.

the class LocatorIT method testBasic.

@Test
public void testBasic() throws Exception {
    Connector conn = getConnector();
    String tableName = getUniqueNames(1)[0];
    conn.tableOperations().create(tableName);
    Range r1 = new Range("m");
    Range r2 = new Range("o", "x");
    String tableId = conn.tableOperations().tableIdMap().get(tableName);
    TabletId t1 = newTabletId(tableId, null, null);
    TabletId t2 = newTabletId(tableId, "r", null);
    TabletId t3 = newTabletId(tableId, null, "r");
    ArrayList<Range> ranges = new ArrayList<>();
    HashSet<String> tservers = new HashSet<>(conn.instanceOperations().getTabletServers());
    ranges.add(r1);
    Locations ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t1)), ImmutableMap.of(t1, ImmutableSet.of(r1)));
    ranges.add(r2);
    ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t1), r2, ImmutableSet.of(t1)), ImmutableMap.of(t1, ImmutableSet.of(r1, r2)));
    TreeSet<Text> splits = new TreeSet<>();
    splits.add(new Text("r"));
    conn.tableOperations().addSplits(tableName, splits);
    ret = conn.tableOperations().locate(tableName, ranges);
    assertContains(ret, tservers, ImmutableMap.of(r1, ImmutableSet.of(t2), r2, ImmutableSet.of(t2, t3)), ImmutableMap.of(t2, ImmutableSet.of(r1, r2), t3, ImmutableSet.of(r2)));
    conn.tableOperations().offline(tableName, true);
    try {
        conn.tableOperations().locate(tableName, ranges);
        Assert.fail();
    } catch (TableOfflineException e) {
    // expected
    }
    conn.tableOperations().delete(tableName);
    try {
        conn.tableOperations().locate(tableName, ranges);
        Assert.fail();
    } catch (TableNotFoundException e) {
    // expected
    }
}
Also used : Connector(org.apache.accumulo.core.client.Connector) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) ArrayList(java.util.ArrayList) Locations(org.apache.accumulo.core.client.admin.Locations) Text(org.apache.hadoop.io.Text) Range(org.apache.accumulo.core.data.Range) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) TreeSet(java.util.TreeSet) TabletId(org.apache.accumulo.core.data.TabletId) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 Connector (org.apache.accumulo.core.client.Connector)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 TableOfflineException (org.apache.accumulo.core.client.TableOfflineException)1 Locations (org.apache.accumulo.core.client.admin.Locations)1 Range (org.apache.accumulo.core.data.Range)1 TabletId (org.apache.accumulo.core.data.TabletId)1 Text (org.apache.hadoop.io.Text)1 Test (org.junit.Test)1