Search in sources :

Example 1 with NumericValueConstraint

use of org.apache.accumulo.test.constraints.NumericValueConstraint in project accumulo by apache.

the class SimpleProxyBase method testBatchWriter.

@Test
public void testBatchWriter() throws Exception {
    client.addConstraint(creds, tableName, NumericValueConstraint.class.getName());
    // zookeeper propagation time
    sleepUninterruptibly(ZOOKEEPER_PROPAGATION_TIME, TimeUnit.MILLISECONDS);
    // Take the table offline and online to force a config update
    client.offlineTable(creds, tableName, true);
    client.onlineTable(creds, tableName, true);
    WriterOptions writerOptions = new WriterOptions();
    writerOptions.setLatencyMs(10000);
    writerOptions.setMaxMemory(2);
    writerOptions.setThreads(1);
    writerOptions.setTimeoutMs(100000);
    Map<String, Integer> constraints = client.listConstraints(creds, tableName);
    while (!constraints.containsKey(NumericValueConstraint.class.getName())) {
        log.info("Constraints don't contain NumericValueConstraint");
        Thread.sleep(2000);
        constraints = client.listConstraints(creds, tableName);
    }
    boolean success = false;
    for (int i = 0; i < 15; i++) {
        String batchWriter = client.createWriter(creds, tableName, writerOptions);
        client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
        client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
        try {
            client.flush(batchWriter);
            log.debug("Constraint failed to fire. Waiting and retrying");
            Thread.sleep(5000);
            continue;
        } catch (MutationsRejectedException ex) {
        }
        try {
            client.closeWriter(batchWriter);
            log.debug("Constraint failed to fire. Waiting and retrying");
            Thread.sleep(5000);
            continue;
        } catch (MutationsRejectedException e) {
        }
        success = true;
        break;
    }
    if (!success) {
        fail("constraint did not fire");
    }
    client.removeConstraint(creds, tableName, 2);
    // Take the table offline and online to force a config update
    client.offlineTable(creds, tableName, true);
    client.onlineTable(creds, tableName, true);
    constraints = client.listConstraints(creds, tableName);
    while (constraints.containsKey(NumericValueConstraint.class.getName())) {
        log.info("Constraints still contains NumericValueConstraint");
        Thread.sleep(2000);
        constraints = client.listConstraints(creds, tableName);
    }
    assertScan(new String[][] {}, tableName);
    sleepUninterruptibly(ZOOKEEPER_PROPAGATION_TIME, TimeUnit.MILLISECONDS);
    writerOptions = new WriterOptions();
    writerOptions.setLatencyMs(10000);
    writerOptions.setMaxMemory(3000);
    writerOptions.setThreads(1);
    writerOptions.setTimeoutMs(100000);
    success = false;
    for (int i = 0; i < 15; i++) {
        try {
            String batchWriter = client.createWriter(creds, tableName, writerOptions);
            client.update(batchWriter, mutation("row1", "cf", "cq", "x"));
            client.flush(batchWriter);
            client.closeWriter(batchWriter);
            success = true;
            break;
        } catch (MutationsRejectedException e) {
            log.info("Mutations were rejected, assuming constraint is still active", e);
            Thread.sleep(5000);
        }
    }
    if (!success) {
        fail("Failed to successfully write data after constraint was removed");
    }
    assertScan(new String[][] { { "row1", "cf", "cq", "x" } }, tableName);
    client.deleteTable(creds, tableName);
}
Also used : ConditionalWriterOptions(org.apache.accumulo.proxy.thrift.ConditionalWriterOptions) WriterOptions(org.apache.accumulo.proxy.thrift.WriterOptions) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) NumericValueConstraint(org.apache.accumulo.test.constraints.NumericValueConstraint) MutationsRejectedException(org.apache.accumulo.proxy.thrift.MutationsRejectedException) Test(org.junit.Test)

Aggregations

ConditionalWriterOptions (org.apache.accumulo.proxy.thrift.ConditionalWriterOptions)1 MutationsRejectedException (org.apache.accumulo.proxy.thrift.MutationsRejectedException)1 WriterOptions (org.apache.accumulo.proxy.thrift.WriterOptions)1 NumericValueConstraint (org.apache.accumulo.test.constraints.NumericValueConstraint)1 Test (org.junit.Test)1