예제 #1
0
  /** Test that transactions can be aborted */
  public void testAbortTransactions() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 3");
    Address address2 = new Address();
    address2.setAddress("Address 4");

    Query q = new Query();
    QueryClass qcAddress = new QueryClass(Address.class);
    QueryField qf = new QueryField(qcAddress, "address");
    ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR);
    cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%")));
    q.addToSelect(qcAddress);
    q.addFrom(qcAddress);
    q.addToOrderBy(qf);
    q.setConstraint(cs1);

    Results res = writer.execute(q);
    assertEquals(res.toString(), 0, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());

    writer.beginTransaction();
    assertTrue(writer.isInTransaction());

    writer.store(address1);
    writer.store(address2);

    // TODO: These lines now fail, because we do not allow querying on writers with uncommitted
    // data. The writer should relax this restriction.
    res = writer.execute(q);
    assertEquals(2, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());

    writer.abortTransaction();
    assertFalse(writer.isInTransaction());

    // Should be nothing there unless we commit

    res = writer.execute(q);
    assertEquals(res.toString(), 0, res.size());

    res = realOs.execute(q);
    assertEquals(res.toString(), 0, res.size());
  }
예제 #2
0
  public void testFailFast() throws Exception {
    Query q1 = new Query();
    QueryClass qc1 = new QueryClass(Employee.class);
    q1.addFrom(qc1);
    q1.addToSelect(qc1);

    Results r1 = writer.execute(q1);
    writer.store(data.get("EmployeeA1"));
    try {
      r1.iterator().hasNext();
      fail("Expected: ConcurrentModificationException");
    } catch (ConcurrentModificationException e) {
    }
  }
예제 #3
0
  /** Test that transactions do actually commit and that isInTransaction() works. */
  public void testCommitTransactions() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");
    Address address2 = new Address();
    address2.setAddress("Address 2");

    Query q = new Query();
    QueryClass qcAddress = new QueryClass(Address.class);
    QueryField qf = new QueryField(qcAddress, "address");
    ConstraintSet cs1 = new ConstraintSet(ConstraintOp.OR);
    cs1.addConstraint(new SimpleConstraint(qf, ConstraintOp.MATCHES, new QueryValue("Address%")));
    q.addToSelect(qcAddress);
    q.addFrom(qcAddress);
    q.addToOrderBy(qf);
    q.setConstraint(cs1);

    try {
      writer.beginTransaction();
      assertTrue(writer.isInTransaction());

      writer.store(address1);
      writer.store(address2);

      // Should be nothing in OS until we commit
      Results res = realOs.execute(q);
      assertEquals(0, res.size());

      // However, they should be in the WRITER.
      // TODO: These lines now fail, because we do not allow querying on writers with uncommitted
      // data. The writer should relax this restriction.
      res = writer.execute(q);
      assertEquals(2, res.size());

      writer.commitTransaction();
      assertFalse(writer.isInTransaction());
      res = realOs.execute(q);
      assertEquals(2, res.size());
      assertEquals(address1, (Address) ((ResultsRow) res.get(0)).get(0));
      assertEquals(address2, (Address) ((ResultsRow) res.get(1)).get(0));

    } finally {
      writer.delete(address1);
      writer.delete(address2);
    }
  }