use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.
the class SystemCredentialsTest method testSystemCredentials.
@Test
public void testSystemCredentials() {
Credentials a = SystemCredentials.get(instanceId, siteConfig);
Credentials b = SystemCredentials.get(instanceId, siteConfig);
assertEquals(a, b);
}
use of org.apache.accumulo.core.clientImpl.Credentials 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(() -> {
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(TableId.of("1"), null, null), myFile, StatusUtil.fileCreated(createdTime));
verify(writer);
assertEquals(1, mutations.size());
Mutation m = mutations.get(0);
assertEquals(ReplicationSection.getRowPrefix() + "file:/home/user/accumulo/wal/server+port/" + uuid, new Text(m.getRow()).toString());
List<ColumnUpdate> updates = m.getUpdates();
assertEquals(1, updates.size());
ColumnUpdate update = updates.get(0);
assertEquals(ReplicationSection.COLF, new Text(update.getColumnFamily()));
assertEquals("1", new Text(update.getColumnQualifier()).toString());
assertEquals(StatusUtil.fileCreatedValue(createdTime), new Value(update.getValue()));
}
use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.
the class CredentialsTest method testEqualsAndHashCode.
@Test
public void testEqualsAndHashCode() {
Credentials nullNullCreds = new Credentials(null, null);
Credentials abcNullCreds = new Credentials("abc", new NullToken());
Credentials cbaNullCreds = new Credentials("cba", new NullToken());
Credentials abcBlahCreds = new Credentials("abc", new PasswordToken("blah"));
// check hash codes
assertEquals(0, nullNullCreds.hashCode());
assertEquals("abc".hashCode(), abcNullCreds.hashCode());
assertEquals(abcNullCreds.hashCode(), abcBlahCreds.hashCode());
assertNotEquals(abcNullCreds.hashCode(), cbaNullCreds.hashCode());
// identity
assertEquals(abcNullCreds, abcNullCreds);
assertEquals(new Credentials("abc", new NullToken()), abcNullCreds);
// equal, but different token constructors
assertEquals(new Credentials("abc", new PasswordToken("abc".getBytes(UTF_8))), new Credentials("abc", new PasswordToken("abc")));
// test not equals
assertNotEquals(nullNullCreds, abcBlahCreds);
assertNotEquals(nullNullCreds, abcNullCreds);
assertNotEquals(abcNullCreds, abcBlahCreds);
}
use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.
the class CredentialsTest method testCredentialsSerialization.
@Test
public void testCredentialsSerialization() {
Credentials creds = new Credentials("a:b-c", new PasswordToken("d-e-f".getBytes(UTF_8)));
String serialized = creds.serialize();
Credentials result = Credentials.deserialize(serialized);
assertEquals(creds, result);
assertEquals("a:b-c", result.getPrincipal());
assertEquals(new PasswordToken("d-e-f"), result.getToken());
Credentials nullNullCreds = new Credentials(null, null);
serialized = nullNullCreds.serialize();
result = Credentials.deserialize(serialized);
assertNull(result.getPrincipal());
assertNull(result.getToken());
}
use of org.apache.accumulo.core.clientImpl.Credentials in project accumulo by apache.
the class SimpleBalancerFairnessIT method simpleBalancerFairness.
@Test
public void simpleBalancerFairness() throws Exception {
try (AccumuloClient c = Accumulo.newClient().from(getClientProperties()).build()) {
c.tableOperations().create("test_ingest");
c.tableOperations().setProperty("test_ingest", Property.TABLE_SPLIT_THRESHOLD.getKey(), "1K");
c.tableOperations().create("unused");
TreeSet<Text> splits = TestIngest.getSplitPoints(0, 10000000, NUM_SPLITS);
log.info("Creating {} splits", splits.size());
c.tableOperations().addSplits("unused", splits);
List<String> tservers = c.instanceOperations().getTabletServers();
TestIngest.IngestParams params = new TestIngest.IngestParams(getClientProperties());
params.rows = 5000;
TestIngest.ingest(c, params);
c.tableOperations().flush("test_ingest", null, null, false);
sleepUninterruptibly(45, TimeUnit.SECONDS);
Credentials creds = new Credentials("root", new PasswordToken(ROOT_PASSWORD));
ManagerMonitorInfo stats = null;
int unassignedTablets = 1;
for (int i = 0; unassignedTablets > 0 && i < 20; i++) {
ManagerClientService.Iface client = null;
while (true) {
try {
client = ManagerClient.getConnectionWithRetry((ClientContext) c);
stats = client.getManagerStats(TraceUtil.traceInfo(), creds.toThrift(c.instanceOperations().getInstanceId()));
break;
} catch (ThriftNotActiveServiceException e) {
// Let it loop, fetching a new location
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
} finally {
if (client != null)
ManagerClient.close(client, (ClientContext) c);
}
}
unassignedTablets = stats.getUnassignedTablets();
if (unassignedTablets > 0) {
log.info("Found {} unassigned tablets, sleeping 3 seconds for tablet assignment", unassignedTablets);
Thread.sleep(3000);
}
}
assertEquals("Unassigned tablets were not assigned within 60 seconds", 0, unassignedTablets);
// Compute online tablets per tserver
List<Integer> counts = new ArrayList<>();
for (TabletServerStatus server : stats.tServerInfo) {
int count = 0;
for (TableInfo table : server.tableMap.values()) {
count += table.onlineTablets;
}
counts.add(count);
}
assertTrue("Expected to have at least two TabletServers", counts.size() > 1);
for (int i = 1; i < counts.size(); i++) {
int diff = Math.abs(counts.get(0) - counts.get(i));
assertTrue("Expected difference in tablets to be less than or equal to " + counts.size() + " but was " + diff + ". Counts " + counts, diff <= tservers.size());
}
}
}
Aggregations