package cmpt;

import java.util.ArrayList;
import java.util.Iterator;

import org.apache.accumulo.core.client.ConditionalWriter;
import org.apache.accumulo.core.client.ConditionalWriter.Result;
import org.apache.accumulo.core.client.ConditionalWriter.Status;
import org.apache.accumulo.core.client.ConditionalWriterConfig;
import org.apache.accumulo.core.client.Connector;
import org.apache.accumulo.core.client.TableNotFoundException;
import org.apache.accumulo.core.client.ZooKeeperInstance;
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
import org.apache.accumulo.core.conf.Property;
import org.apache.accumulo.core.data.Condition;
import org.apache.accumulo.core.data.ConditionalMutation;
import org.apache.commons.configuration.PropertiesConfiguration;

public class Test1 {

  public static void runPerfTest(Connector conn, String tableName) throws Exception {

    try{
      conn.tableOperations().delete(tableName);
    } catch(TableNotFoundException e){}

    conn.tableOperations().create(tableName);
    conn.tableOperations().setProperty(tableName,Property.TABLE_BLOCKCACHE_ENABLED.getKey(), "true");


    ConditionalWriter cw = conn.createConditionalWriter(tableName, new ConditionalWriterConfig());

    timeX(cw, null);

    for(int i = 1; i< 20; i++) {
      timeX(cw, (long)i);
    }

    conn.tableOperations().flush(tableName, null, null, true);

    for(int i = 20; i< 40; i++) {
      timeX(cw, (long)i);
    }



  }

  private static void timeX(ConditionalWriter cw, Long seq) throws Exception {
    ArrayList<ConditionalMutation> cmuts = new ArrayList<>();

    for(int i = 0; i < 10000; i++) {
      Condition cond = new Condition("meta", "seq");
      if(seq != null) {
        cond.setValue(""+seq);
      }

      ConditionalMutation cm = new ConditionalMutation(String.format("r%07d", i), cond);
      cm.put("meta", "seq", seq == null ? "1" : (seq +1)+"");
      cmuts.add(cm);
    }


    long t1 = System.currentTimeMillis();

    int count = 0;
    Iterator<Result> results = cw.write(cmuts.iterator());
    while(results.hasNext()) {
      Result result = results.next();

      if(Status.ACCEPTED != result.getStatus()) {throw new RuntimeException();}
      count++;
    }

    if(cmuts.size() != count) {throw new RuntimeException();}
    long t2 = System.currentTimeMillis();

    System.out.println(t2 - t1);
  }

  public static void main(String[] args) throws Exception  {
    PropertiesConfiguration config = new PropertiesConfiguration(args[0]);
    ZooKeeperInstance zki = new ZooKeeperInstance(config);
    Connector conn = zki.getConnector(config.getString("user.name"), new PasswordToken(config.getString("user.password")));
    runPerfTest(conn, "foo");
  }
}

@@ -1317,24 +1317,60 @@
 )i);%0A    %7D%0A%0A
+    System.out.println(%22Flushing%22);%0A
     conn.tab
@@ -2365,24 +2365,25 @@
 eMillis();%0A%0A
+%0A
     System.o
@@ -2394,18 +2394,103 @@
 rint
-ln(t2 - t1
+f(%22time: %25d ms  rate : %256.2f conditionalMutations/sec %5Cn%22, (t2 - t1), 10000 / ((t2 -t1)/1000.0)
 );%0A 

Format output