コード例 #1
0
ファイル: ContendedLockTest.java プロジェクト: truward/Tupl
  @Test
  public void timedOutUpdate() throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();
    byte[] value2 = "world!!!".getBytes();

    ix.store(null, key, value1);

    Transaction txn = mDb.newTransaction();
    ix.store(txn, key, value2);

    fastAssertArrayEquals(value2, ix.load(Transaction.BOGUS, key));

    try {
      ix.load(null, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    Transaction txn2 = mDb.newTransaction();
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.UPGRADABLE_READ);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.REPEATABLE_READ);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.READ_COMMITTED);
    try {
      ix.load(txn2, key);
      fail();
    } catch (LockTimeoutException e) {
    }

    txn2.lockMode(LockMode.READ_UNCOMMITTED);
    fastAssertArrayEquals(value2, ix.load(txn2, key));

    txn2.lockMode(LockMode.UNSAFE);
    fastAssertArrayEquals(value2, ix.load(txn2, key));

    txn.commit();

    fastAssertArrayEquals(value2, ix.load(null, key));
  }
コード例 #2
0
  /**
   * @throws NoSuchRecordFieldException
   * @throws IOException
   */
  @Test
  public void testComputedField() throws NoSuchRecordFieldException, IOException {
    List<Panel> panelList = database.getPanels();

    for (Panel panel : panelList) {
      List<Field> fieldList = panel.getFields();

      for (Iterator<Record> recordIterator = panel.recordIterator(); recordIterator.hasNext(); ) {
        Record record = recordIterator.next();
        Iterator<Field> fieldIterator = fieldList.iterator();

        while (fieldIterator.hasNext()) {
          Field field = fieldIterator.next();

          if (field.getInitialization() != null) {
            assertTrue(field.getInitialization() != null);

            if (field.isComputedField()) {
              assertTrue(field.isComputedField());
              assertTrue(record.getValueAsString(field.getNumber()) == null);
            } else {
              assertFalse(field.isComputedField());
              assertTrue(record.getValueAsString(field.getNumber()) != null);
            }
          } else {
            if (field.getLink() == null || field.getLink().getType() == LinkType.DATA_LINK) {
              assertTrue(record.getValueAsString(field.getNumber()) != null);
            }
          }
        }
      }
    }
  }
コード例 #3
0
ファイル: ContendedLockTest.java プロジェクト: truward/Tupl
  @Test
  public void delayedUpdate() throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();

    ix.store(null, key, value1);

    int i = 0;
    Updater u = start(ix, key, ("world-" + (i++)).getBytes());

    fastAssertArrayEquals(u.mValue, ix.load(null, key));

    u = start(ix, key, ("world-" + (i++)).getBytes());
    Transaction txn2 = mDb.newTransaction();
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.UPGRADABLE_READ);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.REPEATABLE_READ);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();

    u = start(ix, key, ("world-" + (i++)).getBytes());
    txn2.lockMode(LockMode.READ_COMMITTED);
    fastAssertArrayEquals(u.mValue, ix.load(txn2, key));
    txn2.reset();
  }
コード例 #4
0
  @After
  public void tearDown() throws Exception {

    // Roll back transaction so changes to database are undone
    db.endTransaction(false);

    db = null;
    dbProjects = null;
  }
コード例 #5
0
ファイル: ContendedLockTest.java プロジェクト: truward/Tupl
  private void delayedDelete(boolean noGhost) throws Exception {
    View ix = openIndex("foo");

    byte[] key = "hello".getBytes();
    byte[] value1 = "world".getBytes();

    ix.store(null, key, value1);

    Updater u = start(ix, key, null, noGhost);

    assertEquals(null, ix.load(null, key));

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    Transaction txn2 = mDb.newTransaction();
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.UPGRADABLE_READ);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.REPEATABLE_READ);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();

    ix.store(null, key, value1);
    u = start(ix, key, null, noGhost);
    txn2.lockMode(LockMode.READ_COMMITTED);
    assertEquals(null, ix.load(txn2, key));
    txn2.reset();
  }
コード例 #6
0
  @Before
  public void setUp() throws Exception {

    // Delete all projects from the database
    db = new Database();
    db.startTransaction();

    db.getProjectsDAO().dropTable();
    db.getProjectsDAO().createTable();
    List<Project> projects = db.getProjectsDAO().getAll();

    //		for (Project p : projects) {
    //			db.getProjectsDAO().delete(p);
    //		}

    db.endTransaction(true);

    // Prepare database for test case
    db = new Database();
    db.startTransaction();
    dbProjects = db.getProjectsDAO();
  }
コード例 #7
0
  @BeforeClass
  public static void setUpBeforeClass() throws Exception {

    // Load database driver
    Database.initialize();
  }
コード例 #8
0
 /** @throws IOException */
 @After
 public void tearDown() throws IOException {
   database.close();
 }
コード例 #9
0
 /**
  * @throws IOException
  * @throws DataPerfectLibException
  */
 @Before
 public void setUp() throws IOException, DataPerfectLibException {
   database = new Database(new File("src/test/resources/DP26G/TUTORIAL_DATABASES/UD/ud.str"));
   database.open();
 }