コード例 #1
0
  public static void testGetAfterPut3(int numtx) throws IOException, CommitUnsuccessfulException {

    int newValue = 0;
    for (newValue = 0; newValue < numtx; newValue++) {
      // Begin
      TransactionState transactionState = transactionManager.beginTransaction(100);

      // Put
      Put lv_put = new Put(Bytes.toBytes("Alto"));
      lv_put.add(FAMILY, QUAL_A, Bytes.toBytes("Palo"));
      lv_put.add(FAMILY, QUAL_B, Bytes.toBytes("Alto"));
      table.put(transactionState, lv_put);

      // Get
      Result row1_A =
          table.get(transactionState, new Get(Bytes.toBytes("Alto")).addColumn(FAMILY, QUAL_A));
      System.out.println(
          "Transactional Get result before put is committed:" + row1_A.size() + ":" + row1_A);

      // Get
      Result row1_B = table.get(new Get(Bytes.toBytes("Alto")).addColumn(FAMILY, QUAL_A));
      System.out.println(
          "Normal Get result before put is committed:" + row1_B.size() + ":" + row1_B);

      // End
      transactionManager.tryCommit(transactionState);

      // Begin
      transactionState = transactionManager.beginTransaction(101);
      // Get
      Result row1_C = table.get(new Get(Bytes.toBytes("Alto")).addColumn(FAMILY, QUAL_A));
      System.out.println("Get after put was commited. Result: " + row1_C);

      // Get
      row1_A =
          table.get(transactionState, new Get(Bytes.toBytes("Alto")).addColumn(FAMILY, QUAL_A));
      System.out.println("Transactional Get after put was commited. Result : " + row1_A);

      // End
      transactionManager.tryCommit(transactionState);
      try {
        transactionState.completeRequest();
      } catch (Exception e) {
        System.out.println("\nCAUGHT\n");
      }
    }
  }
コード例 #2
0
  public static void testGetAfterPut2(int numtx) throws IOException, CommitUnsuccessfulException {

    PrintWriter out = new PrintWriter(new File("TWorkTest.txt"));

    out.println("\nTransactionWithWorkTest ENTRY");

    double begin_latency = 0;
    double end_latency = 0;
    double put_latency = 0;
    double get_latency = 0;
    double delete_latency = 0;
    double abort_latency = 0;
    int newValue = 0;

    double hput_latency = 0;
    double hget_latency = 0;
    double hdelete_latency = 0;

    for (newValue = 0; newValue < numtx; newValue++) {
      // Begin
      long ts1 = System.nanoTime();
      TransactionState transactionState = transactionManager.beginTransaction();
      long ts2 = System.nanoTime();
      long latency = ts2 - ts1;
      double latency2 = (double) latency / 1000000000;

      begin_latency = begin_latency + latency2;

      // Put
      ts1 = System.nanoTime();
      table.put(transactionState, new Put(ROW1).add(FAMILY, QUAL_A, Bytes.toBytes(newValue)));
      ts2 = System.nanoTime();
      latency = ts2 - ts1;
      latency2 = (double) latency / 1000000000;

      put_latency = put_latency + latency2;

      // Abort
      System.nanoTime();
      transactionManager.abort(transactionState);
      try {
        transactionState.completeRequest();
      } catch (Exception e) {
        System.out.println("\nCAUGHT\n");
      }
      ts2 = System.nanoTime();
      latency = ts2 - ts1;
      latency2 = (double) latency / 1000000000;

      abort_latency = abort_latency + latency2;

      transactionState = transactionManager.beginTransaction();
      table.put(transactionState, new Put(ROW1).add(FAMILY, QUAL_A, Bytes.toBytes(newValue)));

      // End
      ts1 = System.nanoTime();
      transactionManager.tryCommit(transactionState);
      try {
        transactionState.completeRequest();
      } catch (Exception e) {
        System.out.println("\nCAUGHT\n");
      }
      ts2 = System.nanoTime();
      latency = ts2 - ts1;
      latency2 = (double) latency / 1000000000;

      end_latency = end_latency + latency2;

      transactionState = transactionManager.beginTransaction();
      table.put(transactionState, new Put(ROW1).add(FAMILY, QUAL_A, Bytes.toBytes(newValue)));

      // Get
      ts1 = System.nanoTime();
      Result row1_A = table.get(new Get(ROW1).addColumn(FAMILY, QUAL_A));
      ts2 = System.nanoTime();
      latency = ts2 - ts1;
      latency2 = (double) latency / 1000000000;

      get_latency = get_latency + latency2;

      transactionManager.tryCommit(transactionState);
      try {
        transactionState.completeRequest();
      } catch (Exception e) {
        System.out.println("\nCAUGHT\n");
      }

      int expected = Bytes.toInt(row1_A.getValue(FAMILY, QUAL_A));
      if (newValue != expected)
        System.out.println(
            "\ntestGetAfterPut : Assert 1 FAILED : expected "
                + expected
                + "newValue "
                + newValue
                + "\n");

      transactionState = transactionManager.beginTransaction();
      table.put(transactionState, new Put(ROW1).add(FAMILY, QUAL_A, Bytes.toBytes(newValue)));

      // Delete
      ts1 = System.nanoTime();
      table.delete(transactionState, new Delete(ROW1).deleteColumns(FAMILY, QUAL_A));
      ts2 = System.nanoTime();
      latency = ts2 - ts1;
      latency2 = (double) latency / 1000000000;

      delete_latency = delete_latency + latency2;

      transactionManager.tryCommit(transactionState);
      try {
        transactionState.completeRequest();
      } catch (Exception e) {
        System.out.println("\nCAUGHT\n");
      }
    }

    out.println("\nAverage Begin latency : " + (double) (begin_latency / newValue));
    out.println("Average End latency  : " + (double) (end_latency / newValue));
    out.println("Average Abort latency : " + (double) (abort_latency / newValue));
    out.println("Average Put latency  : " + (double) (put_latency / newValue));
    out.println("Average Get latency  : " + (double) (get_latency / newValue));
    out.println("Average Delete latency : " + (double) (delete_latency / newValue));
    out.println("Average HPut latency  : " + (double) (hput_latency / newValue));
    out.println("Average HGet latency  : " + (double) (hget_latency / newValue));
    out.println("\ntestGetAfterPut EXIT");
    out.close();
  }