use of org.apache.accumulo.server.AccumuloServerContext in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testAllAssigned.
@Test
public void testAllAssigned() {
init(new AccumuloServerContext(instance, factory));
Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
Assert.assertEquals(0, assignments.size());
}
use of org.apache.accumulo.server.AccumuloServerContext in project accumulo by apache.
the class HostRegexTableLoadBalancerTest method testUnassignedWithNoTServers.
@Test
public void testUnassignedWithNoTServers() {
init(new AccumuloServerContext(instance, factory));
Map<KeyExtent, TServerInstance> assignments = new HashMap<>();
Map<KeyExtent, TServerInstance> unassigned = new HashMap<>();
for (KeyExtent ke : tableExtents.get(BAR.getTableName())) {
unassigned.put(ke, null);
}
SortedMap<TServerInstance, TabletServerStatus> current = createCurrent(15);
// Remove the BAR tablet servers from current
List<TServerInstance> removals = new ArrayList<>();
for (Entry<TServerInstance, TabletServerStatus> e : current.entrySet()) {
if (e.getKey().host().equals("192.168.0.6") || e.getKey().host().equals("192.168.0.7") || e.getKey().host().equals("192.168.0.8") || e.getKey().host().equals("192.168.0.9") || e.getKey().host().equals("192.168.0.10")) {
removals.add(e.getKey());
}
}
for (TServerInstance r : removals) {
current.remove(r);
}
this.getAssignments(Collections.unmodifiableSortedMap(allTabletServers), Collections.unmodifiableMap(unassigned), assignments);
Assert.assertEquals(unassigned.size(), assignments.size());
// Ensure assignments are correct
for (Entry<KeyExtent, TServerInstance> e : assignments.entrySet()) {
if (!tabletInBounds(e.getKey(), e.getValue())) {
Assert.fail("tablet not in bounds: " + e.getKey() + " -> " + e.getValue().host());
}
}
}
use of org.apache.accumulo.server.AccumuloServerContext in project accumulo by apache.
the class TableLoadBalancerTest method test.
@Test
public void test() throws Exception {
final Instance inst = EasyMock.createMock(Instance.class);
EasyMock.expect(inst.getInstanceID()).andReturn(UUID.nameUUIDFromBytes(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 }).toString()).anyTimes();
EasyMock.expect(inst.getZooKeepers()).andReturn("10.0.0.1:1234").anyTimes();
EasyMock.expect(inst.getZooKeepersSessionTimeOut()).andReturn(30_000).anyTimes();
EasyMock.replay(inst);
ServerConfigurationFactory confFactory = new ServerConfigurationFactory(inst) {
@Override
public TableConfiguration getTableConfiguration(Table.ID tableId) {
// create a dummy namespaceConfiguration to satisfy requireNonNull in TableConfiguration constructor
NamespaceConfiguration dummyConf = new NamespaceConfiguration(null, inst, null);
return new TableConfiguration(inst, tableId, dummyConf) {
@Override
public String get(Property property) {
// fake the get table configuration so the test doesn't try to look in zookeeper for per-table classpath stuff
return DefaultConfiguration.getInstance().get(property);
}
};
}
};
String t1Id = TABLE_ID_MAP.get("t1"), t2Id = TABLE_ID_MAP.get("t2"), t3Id = TABLE_ID_MAP.get("t3");
state = new TreeMap<>();
TServerInstance svr = mkts("10.0.0.1", "0x01020304");
state.put(svr, status(t1Id, 10, t2Id, 10, t3Id, 10));
Set<KeyExtent> migrations = Collections.emptySet();
List<TabletMigration> migrationsOut = new ArrayList<>();
TableLoadBalancer tls = new TableLoadBalancer();
tls.init(new AccumuloServerContext(inst, confFactory));
tls.balance(state, migrations, migrationsOut);
Assert.assertEquals(0, migrationsOut.size());
state.put(mkts("10.0.0.2", "0x02030405"), status());
tls = new TableLoadBalancer();
tls.init(new AccumuloServerContext(inst, confFactory));
tls.balance(state, migrations, migrationsOut);
int count = 0;
Map<Table.ID, Integer> movedByTable = new HashMap<>();
movedByTable.put(Table.ID.of(t1Id), 0);
movedByTable.put(Table.ID.of(t2Id), 0);
movedByTable.put(Table.ID.of(t3Id), 0);
for (TabletMigration migration : migrationsOut) {
if (migration.oldServer.equals(svr))
count++;
Table.ID key = migration.tablet.getTableId();
movedByTable.put(key, movedByTable.get(key) + 1);
}
Assert.assertEquals(15, count);
for (Integer moved : movedByTable.values()) {
Assert.assertEquals(5, moved.intValue());
}
}
use of org.apache.accumulo.server.AccumuloServerContext in project accumulo by apache.
the class TServerUtilsTest method startServer.
private ServerAddress startServer() throws Exception {
AccumuloServerContext ctx = new AccumuloServerContext(instance, factory);
ClientServiceHandler clientHandler = new ClientServiceHandler(ctx, null, null);
Iface rpcProxy = RpcWrapper.service(clientHandler);
Processor<Iface> processor = new Processor<>(rpcProxy);
// "localhost" explicitly to make sure we can always bind to that interface (avoids DNS misconfiguration)
String hostname = "localhost";
return TServerUtils.startServer(ctx, hostname, Property.TSERV_CLIENTPORT, processor, "TServerUtilsTest", "TServerUtilsTestThread", Property.TSERV_PORTSEARCH, Property.TSERV_MINTHREADS, Property.TSERV_THREADCHECK, Property.GENERAL_MAX_MESSAGE_SIZE);
}
use of org.apache.accumulo.server.AccumuloServerContext in project accumulo by apache.
the class WrongTabletTest method main.
public static void main(String[] args) {
final Opts opts = new Opts();
opts.parseArgs(WrongTabletTest.class.getName(), args);
final HostAndPort location = HostAndPort.fromString(opts.location);
final Instance inst = opts.getInstance();
final ServerConfigurationFactory conf = new ServerConfigurationFactory(inst);
final ClientContext context = new AccumuloServerContext(inst, conf) {
@Override
public synchronized Credentials getCredentials() {
try {
return new Credentials(opts.getPrincipal(), opts.getToken());
} catch (AccumuloSecurityException e) {
throw new RuntimeException(e);
}
}
};
try {
TabletClientService.Iface client = ThriftUtil.getTServerClient(location, context);
Mutation mutation = new Mutation(new Text("row_0003750001"));
mutation.putDelete(new Text("colf"), new Text("colq"));
client.update(Tracer.traceInfo(), context.rpcCreds(), new KeyExtent(Table.ID.of("!!"), null, new Text("row_0003750000")).toThrift(), mutation.toThrift(), TDurability.DEFAULT);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations