예제 #1
0
 public void testWriteInterMineObject() throws Exception {
   InterMineObject o =
       (InterMineObject) DynamicUtil.createObject(Collections.singleton(InterMineObject.class));
   try {
     writer.store(o);
   } finally {
     writer.delete(o);
   }
 }
예제 #2
0
 public void testWriteBigDepartment() throws Exception {
   InterMineObject o = new BigDepartment();
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Department.class);
     if (!(o instanceof BigDepartment)) {
       fail("Expected a BigDepartment back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #3
0
 public void testWriteCleaner() throws Exception {
   InterMineObject o = new Cleaner();
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof Cleaner)) {
       fail("Expected a Cleaner back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #4
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) {
    }
  }
예제 #5
0
 public void testWriteCloneable() throws Exception {
   InterMineObject o =
       (InterMineObject)
           DynamicUtil.createObject(
               new HashSet(Arrays.asList(new Class[] {Employee.class, Cloneable.class})));
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof Cloneable)) {
       fail("Expected a Cloneable back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #6
0
 public void testWriteDynamicObject2() throws Exception {
   InterMineObject o =
       (InterMineObject)
           DynamicUtil.createObject(
               new HashSet(Arrays.asList(new Class[] {ImportantPerson.class, Employee.class})));
   try {
     writer.store(o);
     o = writer.getObjectById(o.getId(), Employee.class);
     if (!(o instanceof ImportantPerson)) {
       fail("Expected an ImportantPerson back");
     }
     if (!(o instanceof Employee)) {
       fail("Expected an Employee back");
     }
   } finally {
     writer.delete(o);
   }
 }
예제 #7
0
 public void testClob() throws Exception {
   Clob clob = writer.createClob();
   writer.replaceClob(clob, "Monkey");
   ClobAccess ca = new ClobAccess(writer, clob);
   assertEquals("Monkey", ca.toString());
   StringBuilder longString = new StringBuilder();
   for (int i = 0; i < 10000; i++) {
     longString.append("Lots of monkeys. ");
   }
   writer.replaceClob(clob, longString.toString());
   assertEquals("Monkey", ca.toString());
   ca = new ClobAccess(writer, clob);
   assertEquals(170000, ca.length());
   assertEquals(longString.toString(), ca.toString());
   assertEquals('L', ca.charAt(1700));
   assertEquals('L', ca.charAt(16983));
   ClobAccess sub = ca.subSequence(85000, 85016);
   assertEquals("Lots of monkeys.", sub.toString());
   assertEquals(16, sub.length());
 }
예제 #8
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());
  }
예제 #9
0
  public void testAddToCollection() throws Exception {
    Company c1 = (Company) DynamicUtil.createObject(Collections.singleton(Company.class));
    Contractor c2 = new Contractor();
    c1.setName("Michael");
    c2.setName("Albert");

    try {
      writer.store(c1);
      writer.store(c2);

      Company c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(0, c3.getContractors().size());

      writer.addToCollection(c1.getId(), Company.class, "contractors", c2.getId());

      c3 = (Company) writer.getObjectById(c1.getId(), Company.class);
      assertEquals(1, c3.getContractors().size());
      assertTrue(c3.getContractors().iterator().next() instanceof Contractor);
      assertEquals(c2.getId(), ((Contractor) c3.getContractors().iterator().next()).getId());
    } finally {
      writer.delete(c1);
      writer.delete(c2);
    }
  }
예제 #10
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);
    }
  }
예제 #11
0
  public void testWriteBatchingAndGetObject() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.beginTransaction();
      writer.store(address1);
      assertNotNull(writer.getObjectById(address1.getId(), Address.class));
    } finally {
      if (writer.isInTransaction()) {
        writer.abortTransaction();
      }
    }
  }
예제 #12
0
 public void setUp() throws Exception {
   super.setUp();
   if (writer.isInTransaction()) {
     writer.abortTransaction();
   }
 }
예제 #13
0
 public static void oneTimeSetUp() throws Exception {
   os = writer;
   ObjectStoreAbstractImplTestCase.oneTimeSetUp();
   realOs = writer.getObjectStore();
 }
예제 #14
0
  public void testTransactionsAndCaches() throws Exception {
    Address address1 = new Address();
    address1.setAddress("Address 1");
    Address address2 = new Address();
    address2.setAddress("Address 2");

    writer.flushObjectById();
    realOs.flushObjectById();

    try {
      writer.store(address1);
      Integer id = address1.getId();
      address2.setId(id);

      assertNull(realOs.pilferObjectById(id));
      assertNull(writer.pilferObjectById(id));

      assertNotNull("Looked for id " + id, realOs.getObjectById(id, Address.class));
      assertNull(writer.pilferObjectById(id));
      assertNotNull(realOs.pilferObjectById(id));
      realOs.flushObjectById();

      assertNotNull(writer.getObjectById(id, Address.class));
      assertNotNull(writer.pilferObjectById(id));
      assertNull(realOs.pilferObjectById(id));
      assertNotNull(realOs.getObjectById(id, Address.class));

      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.delete(address2);
      assertNull(writer.getObjectById(id, Address.class));
      assertNull(realOs.getObjectById(id, Address.class));

      writer.store(address1);
      writer.beginTransaction();
      writer.store(address2);
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 1", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.commitTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.beginTransaction();
      writer.delete(address1);
      assertNull(writer.getObjectById(id, Address.class));
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());

      writer.abortTransaction();
      assertNotNull(writer.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) writer.getObjectById(id, Address.class)).getAddress());
      assertNotNull(realOs.getObjectById(id, Address.class));
      assertEquals("Address 2", ((Address) realOs.getObjectById(id, Address.class)).getAddress());
    } finally {
      writer.delete(address1);
    }
  }