예제 #1
0
  @Test
  public void libTxn_3() {
    Txn.executeRead(
        unit,
        () -> {
          assertEquals("In R, value()", 0, counter2.get());
          assertEquals("In R, get()", 0, counter2.value());
        });

    Txn.executeWrite(
        unit,
        () -> {
          counter2.inc();
          assertEquals("In W, value()", 0, counter2.value());
          assertEquals("In W, get()", 1, counter2.get());
        });

    assertEquals("Direct value()", 1, counter2.value());
    assertEquals("Direct get()", 1, counter2.get());

    Txn.executeRead(
        unit,
        () -> {
          assertEquals("In R, value()", 1, counter2.get());
          assertEquals("In R, get()", 1, counter2.value());
        });
  }
예제 #2
0
 public void map(LongWritable key, Text value, Context context)
     throws IOException, InterruptedException {
   String[] columns = value.toString().split(",");
   outkey.set(columns[2]);
   outvalue.setAmount(Integer.parseInt(columns[3]));
   outvalue.setProduct(columns[4]);
   outvalue.setTxnDate(columns[1]);
   context.write(outkey, outvalue);
 }
예제 #3
0
 /**
  * If we need to, add this manager to the list of transactions that need to be monitored because
  * of conflicts over this entry. Any existing blocking txn is sufficient.
  *
  * @see TxnMonitorTask#addSibling
  */
 private void monitor(TransactableMgr mgr) {
   Txn txn = (Txn) mgr;
   Iterator it = ((HashSet) mgrs).iterator();
   while (it.hasNext()) {
     Txn otherTxn = (Txn) it.next();
     if (otherTxn != mgr && otherTxn.monitorTask() != null) {
       otherTxn.monitorTask().addSibling(txn);
       return;
     }
   }
 }
예제 #4
0
 @Test
 public void libTxnThread_12() {
   long x1 = counter1.get();
   ThreadTxn t =
       Txn.threadTxnRead(
           unit,
           () -> {
             long z1 = counter1.get();
             assertEquals("Thread", x1, z1);
           });
   Txn.executeWrite(unit, () -> counter1.inc());
   t.run();
   long x2 = counter1.get();
   assertEquals("after", x1 + 1, x2);
 }
예제 #5
0
  @Test
  public void libTxn_4() {
    long v1 = counter1.value();
    long v2 = counter2.value();
    assertEquals(0, v1);
    assertEquals(0, v2);

    // Txn.executeWrite(unit, () -> {

    unit.begin(ReadWrite.WRITE);

    counter1.inc();
    counter2.inc();
    assertEquals("Counter out of step", counter1.get(), counter2.get());
    assertNotEquals("Counter 1 can see wrong state", counter1.get(), counter1.value());
    assertNotEquals("Counter 2 can see wrong state", counter2.get(), counter2.value());
    counter2.inc();
    assertNotEquals("Counter 1 and 2 shoudl differ", counter1.get(), counter2.get());
    unit.commit();
    unit.end();
    // }) ;
    assertEquals("Component 1 inconsistent", 1, counter1.value());
    assertEquals("Component 2 inconsistent", 2, counter2.value());

    Txn.executeRead(
        unit,
        () -> {
          assertEquals("Component 1 inconsistent (R)", 1, counter1.get());
          assertEquals("Component 2 inconsistent (R)", 2, counter2.get());
        });
  }
예제 #6
0
 @Test
 public void libTxn_7() {
   long x1 =
       Txn.executeWriteReturn(
           unit,
           () -> {
             counter2.inc();
             counter2.inc();
             return counter2.get();
           });
   long x2 =
       Txn.executeReadReturn(
           unit,
           () -> {
             return counter2.get();
           });
   assertEquals("After W and R", x1, x2);
 }
예제 #7
0
 @Test
 public void libTxnThread_11() {
   long x1 = counter1.get();
   Txn.executeWrite(
       unit,
       () -> {
         counter1.inc();
         // Read the "before" state
         ThreadTxn t =
             Txn.threadTxnRead(
                 unit,
                 () -> {
                   long z1 = counter1.get();
                   assertEquals("Thread read", x1, z1);
                 });
         counter1.inc();
         t.run();
       });
   long x2 = counter1.get();
   assertEquals("after", x1 + 2, x2);
 }
예제 #8
0
 @Test
 public void libTxn_5() {
   long x =
       Txn.executeReadReturn(
           unit,
           () -> {
             assertEquals("In R, value()", 0, counter2.get());
             assertEquals("In R, get()", 0, counter2.value());
             return counter2.get();
           });
   assertEquals("Outside R", 0, x);
 }
예제 #9
0
 @Test
 public void libTxn_6() {
   long x =
       Txn.executeWriteReturn(
           unit,
           () -> {
             counter2.inc();
             assertEquals("In W, value()", 0, counter2.value());
             assertEquals("In W, get()", 1, counter2.get());
             return counter2.get();
           });
   assertEquals("Outside W", 1, x);
 }
예제 #10
0
  @Test
  public void libTxn_1() {
    long v1 = counter1.value();
    long v2 = counter2.value();
    assertEquals(0, v1);
    assertEquals(0, v2);

    Txn.executeRead(
        unit,
        () -> {
          assertEquals(0, counter1.get());
          assertEquals(0, counter2.get());
        });
  }
예제 #11
0
 @Test
 public void libTxnThread_10() {
   long x1 = counter1.get();
   ThreadTxn t =
       Txn.threadTxnWrite(
           unit,
           () -> {
             counter1.inc();
           });
   long x2 = counter1.get();
   assertEquals("x2", x1, x2);
   t.run();
   long x3 = counter1.get();
   assertEquals("x3", x1 + 1, x3);
 }
예제 #12
0
 public void reduce(Text key, Iterable<Txn> values, Context context)
     throws IOException, InterruptedException {
   Txn max = new Txn();
   for (Txn txn : values) {
     if (max.getAmount() < txn.getAmount()) {
       max = txn;
     }
   }
   outvalue.set(
       "Max amount = "
           + max.getAmount()
           + " & product = "
           + max.getProduct()
           + " & date = "
           + max.getTxnDate());
   context.write(key, outvalue);
 }
예제 #13
0
 @Test(expected = AssertionError.class)
 public void libTxnThread_3() {
   ThreadTxn t = Txn.threadTxnWrite(unit, () -> fail(""));
   t.run();
 }
예제 #14
0
 @Test
 public void libTxnThread_2() {
   ThreadTxn t = Txn.threadTxnWrite(unit, () -> fail(""));
 }
예제 #15
0
 @Test
 public void libTxnThread_1() {
   ThreadTxn t = Txn.threadTxnRead(unit, () -> {});
   t.run();
 }