Exemple #1
0
  public void tearDown() throws Exception {

    super.tearDown();
    if (junitThread != null) {
      while (junitThread.isAlive()) {
        junitThread.interrupt();
        Thread.yield();
      }
      junitThread = null;
    }
  }
Exemple #2
0
  /**
   * Checks that the given key (or both key and data if data is non-null) is locked in the primary
   * database. The primary record should be locked whenever a secondary cursor is positioned to
   * point to that primary record. [#15573]
   */
  private void assertPriLocked(
      final Database priDb, final DatabaseEntry key, final DatabaseEntry data) {

    /*
     * Whether the record is locked transactionally or not in the current
     * thread, we should not be able to write lock the record
     * non-transactionally in another thread.
     */
    final StringBuffer error = new StringBuffer();
    junitThread =
        new JUnitThread("primary-locker") {
          public void testBody() throws DatabaseException {
            try {
              if (data != null) {
                priDb.getSearchBoth(null, key, data, LockMode.RMW);
              } else {
                DatabaseEntry myData = new DatabaseEntry();
                priDb.get(null, key, myData, LockMode.RMW);
              }
              error.append("Expected DeadlockException");
            } catch (DeadlockException expected) {
            }
          }
        };

    junitThread.start();
    Throwable t = null;
    try {
      junitThread.finishTest();
    } catch (Throwable e) {
      t = e;
    } finally {
      junitThread = null;
    }

    if (t != null) {
      t.printStackTrace();
      fail(t.toString());
    }
    if (error.length() > 0) {
      fail(error.toString());
    }
  }