Search in sources :

Example 1 with ActiveScan

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);
}
Also used : ActiveScan(org.apache.accumulo.proxy.thrift.ActiveScan) ArrayList(java.util.ArrayList) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) TableNotFoundException(org.apache.accumulo.proxy.thrift.TableNotFoundException) MutationsRejectedException(org.apache.accumulo.proxy.thrift.MutationsRejectedException) NamespaceNotEmptyException(org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException) AccumuloSecurityException(org.apache.accumulo.proxy.thrift.AccumuloSecurityException) TException(org.apache.thrift.TException) NamespaceExistsException(org.apache.accumulo.proxy.thrift.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.proxy.thrift.NamespaceNotFoundException) TApplicationException(org.apache.thrift.TApplicationException) TableExistsException(org.apache.accumulo.proxy.thrift.TableExistsException) IteratorSetting(org.apache.accumulo.proxy.thrift.IteratorSetting) IteratorScope(org.apache.accumulo.proxy.thrift.IteratorScope) Client(org.apache.accumulo.proxy.thrift.AccumuloProxy.Client) SlowIterator(org.apache.accumulo.test.functional.SlowIterator) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Client (org.apache.accumulo.proxy.thrift.AccumuloProxy.Client)1 AccumuloSecurityException (org.apache.accumulo.proxy.thrift.AccumuloSecurityException)1 ActiveScan (org.apache.accumulo.proxy.thrift.ActiveScan)1 IteratorScope (org.apache.accumulo.proxy.thrift.IteratorScope)1 IteratorSetting (org.apache.accumulo.proxy.thrift.IteratorSetting)1 MutationsRejectedException (org.apache.accumulo.proxy.thrift.MutationsRejectedException)1 NamespaceExistsException (org.apache.accumulo.proxy.thrift.NamespaceExistsException)1 NamespaceNotEmptyException (org.apache.accumulo.proxy.thrift.NamespaceNotEmptyException)1 NamespaceNotFoundException (org.apache.accumulo.proxy.thrift.NamespaceNotFoundException)1 TableExistsException (org.apache.accumulo.proxy.thrift.TableExistsException)1 TableNotFoundException (org.apache.accumulo.proxy.thrift.TableNotFoundException)1 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)1 SlowIterator (org.apache.accumulo.test.functional.SlowIterator)1 TApplicationException (org.apache.thrift.TApplicationException)1 TException (org.apache.thrift.TException)1 Test (org.junit.Test)1