use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class MasterRepairsDualAssignmentIT method test.
@Test
public void test() throws Exception {
// make some tablets, spread 'em around
Connector c = getConnector();
ClientContext context = new ClientContext(c.getInstance(), new Credentials("root", new PasswordToken(ROOT_PASSWORD)), getClientConfig());
String table = this.getUniqueNames(1)[0];
c.securityOperations().grantTablePermission("root", MetadataTable.NAME, TablePermission.WRITE);
c.securityOperations().grantTablePermission("root", RootTable.NAME, TablePermission.WRITE);
c.tableOperations().create(table);
SortedSet<Text> partitions = new TreeSet<>();
for (String part : "a b c d e f g h i j k l m n o p q r s t u v w x y z".split(" ")) {
partitions.add(new Text(part));
}
c.tableOperations().addSplits(table, partitions);
// scan the metadata table and get the two table location states
Set<TServerInstance> states = new HashSet<>();
Set<TabletLocationState> oldLocations = new HashSet<>();
MetaDataStateStore store = new MetaDataStateStore(context, null);
while (states.size() < 2) {
UtilWaitThread.sleep(250);
oldLocations.clear();
for (TabletLocationState tls : store) {
if (tls.current != null) {
states.add(tls.current);
oldLocations.add(tls);
}
}
}
assertEquals(2, states.size());
// Kill a tablet server... we don't care which one... wait for everything to be reassigned
cluster.killProcess(ServerType.TABLET_SERVER, cluster.getProcesses().get(ServerType.TABLET_SERVER).iterator().next());
Set<TServerInstance> replStates = new HashSet<>();
// Find out which tablet server remains
while (true) {
UtilWaitThread.sleep(1000);
states.clear();
replStates.clear();
boolean allAssigned = true;
for (TabletLocationState tls : store) {
if (tls != null && tls.current != null) {
states.add(tls.current);
} else if (tls != null && tls.extent.equals(new KeyExtent(ReplicationTable.ID, null, null))) {
replStates.add(tls.current);
} else {
allAssigned = false;
}
}
System.out.println(states + " size " + states.size() + " allAssigned " + allAssigned);
if (states.size() != 2 && allAssigned)
break;
}
assertEquals(1, replStates.size());
assertEquals(1, states.size());
// pick an assigned tablet and assign it to the old tablet
TabletLocationState moved = null;
for (TabletLocationState old : oldLocations) {
if (!states.contains(old.current)) {
moved = old;
}
}
assertNotEquals(null, moved);
// throw a mutation in as if we were the dying tablet
BatchWriter bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
Mutation assignment = new Mutation(moved.extent.getMetadataEntry());
moved.current.putLocation(assignment);
bw.addMutation(assignment);
bw.close();
// wait for the master to fix the problem
waitForCleanStore(store);
// now jam up the metadata table
bw = c.createBatchWriter(MetadataTable.NAME, new BatchWriterConfig());
assignment = new Mutation(new KeyExtent(MetadataTable.ID, null, null).getMetadataEntry());
moved.current.putLocation(assignment);
bw.addMutation(assignment);
bw.close();
waitForCleanStore(new RootTabletStateStore(context, null));
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class MetaConstraintRetryIT method test.
// a test for ACCUMULO-3096
@Test(expected = ConstraintViolationException.class)
public void test() throws Exception {
getConnector().securityOperations().grantTablePermission(getAdminPrincipal(), MetadataTable.NAME, TablePermission.WRITE);
Credentials credentials = new Credentials(getAdminPrincipal(), getAdminToken());
ClientContext context = new ClientContext(getConnector().getInstance(), credentials, cluster.getClientConfig());
Writer w = new Writer(context, MetadataTable.ID);
KeyExtent extent = new KeyExtent(Table.ID.of("5"), null, null);
Mutation m = new Mutation(extent.getMetadataEntry());
// unknown columns should cause contraint violation
m.put("badcolfam", "badcolqual", "3");
try {
MetadataTableUtil.update(w, null, m);
} catch (RuntimeException e) {
if (e.getCause().getClass().equals(ConstraintViolationException.class)) {
throw (ConstraintViolationException) e.getCause();
}
}
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class ReplicationTableUtilTest method properPathInRow.
@Test
public void properPathInRow() throws Exception {
Writer writer = EasyMock.createNiceMock(Writer.class);
writer.update(EasyMock.anyObject(Mutation.class));
final List<Mutation> mutations = new ArrayList<>();
// Mock a Writer to just add the mutation to a list
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() {
mutations.add(((Mutation) EasyMock.getCurrentArguments()[0]));
return null;
}
});
EasyMock.replay(writer);
Credentials creds = new Credentials("root", new PasswordToken(""));
ClientContext context = EasyMock.createMock(ClientContext.class);
EasyMock.expect(context.getCredentials()).andReturn(creds).anyTimes();
EasyMock.replay(context);
// Magic hook to create a Writer
ReplicationTableUtil.addWriter(creds, writer);
// Example file seen coming out of LogEntry
UUID uuid = UUID.randomUUID();
String myFile = "file:////home/user/accumulo/wal/server+port/" + uuid;
long createdTime = System.currentTimeMillis();
ReplicationTableUtil.updateFiles(context, new KeyExtent(Table.ID.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
verify(writer);
Assert.assertEquals(1, mutations.size());
Mutation m = mutations.get(0);
Assert.assertEquals(MetadataSchema.ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
List<ColumnUpdate> updates = m.getUpdates();
Assert.assertEquals(1, updates.size());
ColumnUpdate update = updates.get(0);
Assert.assertEquals(MetadataSchema.ReplicationSection.COLF, new Text(update.getColumnFamily()));
Assert.assertEquals("1", new Text(update.getColumnQualifier()).toString());
Assert.assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class AccumuloReplicaSystem method getContextForPeer.
protected ClientContext getContextForPeer(AccumuloConfiguration localConf, ReplicationTarget target, String principal, AuthenticationToken token) {
requireNonNull(localConf);
requireNonNull(target);
requireNonNull(principal);
requireNonNull(token);
return new ClientContext(getPeerInstance(target), new Credentials(principal, token), localConf);
}
use of org.apache.accumulo.core.client.impl.ClientContext in project accumulo by apache.
the class ReplicationProcessorTest method noPeerConfigurationThrowsAnException.
@Test(expected = IllegalArgumentException.class)
public void noPeerConfigurationThrowsAnException() {
Instance inst = EasyMock.createMock(Instance.class);
VolumeManager fs = EasyMock.createMock(VolumeManager.class);
Credentials creds = new Credentials("foo", new PasswordToken("bar"));
ClientContext context = new ClientContext(inst, creds, ClientConfiguration.create());
Map<String, String> data = new HashMap<>();
ConfigurationCopy conf = new ConfigurationCopy(data);
ReplicationProcessor proc = new ReplicationProcessor(context, conf, fs);
proc.getPeerType("foo");
}
Aggregations