use of org.apache.accumulo.proxy.thrift.ActiveScan in project accumulo by apache.
the class SimpleProxyBase method attachIteratorsWithScans.
@Test
public void attachIteratorsWithScans() throws Exception {
if (client.tableExists(creds, "slow")) {
client.deleteTable(creds, "slow");
}
// create a table that's very slow, so we can look for scans
client.createTable(creds, "slow", true, TimeType.MILLIS);
IteratorSetting setting = new IteratorSetting(100, "slow", SlowIterator.class.getName(), Collections.singletonMap("sleepTime", "250"));
client.attachIterator(creds, "slow", setting, EnumSet.allOf(IteratorScope.class));
// Should take 10 seconds to read every record
for (int i = 0; i < 40; i++) {
client.updateAndFlush(creds, "slow", mutation("row" + i, "cf", "cq", "value"));
}
// scan
Thread t = new Thread() {
@Override
public void run() {
String scanner;
TestProxyClient proxyClient2 = null;
try {
if (isKerberosEnabled()) {
UserGroupInformation.loginUserFromKeytab(clientPrincipal, clientKeytab.getAbsolutePath());
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory, proxyPrimary, UserGroupInformation.getCurrentUser());
} else {
proxyClient2 = new TestProxyClient(hostname, proxyPort, factory);
}
Client client2 = proxyClient2.proxy();
scanner = client2.createScanner(creds, "slow", null);
client2.nextK(scanner, 10);
client2.closeScanner(scanner);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (null != proxyClient2) {
proxyClient2.close();
}
}
}
};
t.start();
// look for the scan many times
List<ActiveScan> scans = new ArrayList<>();
for (int i = 0; i < 100 && scans.isEmpty(); i++) {
for (String tserver : client.getTabletServers(creds)) {
List<ActiveScan> scansForServer = client.getActiveScans(creds, tserver);
for (ActiveScan scan : scansForServer) {
if (clientPrincipal.equals(scan.getUser())) {
scans.add(scan);
}
}
if (!scans.isEmpty())
break;
sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
}
}
t.join();
assertFalse("Expected to find scans, but found none", scans.isEmpty());
boolean found = false;
Map<String, String> map = null;
for (int i = 0; i < scans.size() && !found; i++) {
ActiveScan scan = scans.get(i);
if (clientPrincipal.equals(scan.getUser())) {
assertTrue(ScanState.RUNNING.equals(scan.getState()) || ScanState.QUEUED.equals(scan.getState()));
assertEquals(ScanType.SINGLE, scan.getType());
assertEquals("slow", scan.getTable());
map = client.tableIdMap(creds);
assertEquals(map.get("slow"), scan.getExtent().tableId);
assertTrue(scan.getExtent().endRow == null);
assertTrue(scan.getExtent().prevEndRow == null);
found = true;
}
}
assertTrue("Could not find a scan against the 'slow' table", found);
}
Aggregations