mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
03.47.2014 78efb0c4e9d5c04bc43cb55549762c026e098e05
JEChangeNumberIndexDBTest.java:
Fixed an infinite loop after r10071 (Why did it not fail when ran locally?) + extracted method assertOnlyNewestRecordIsLeft().
testClean() this test is still failing in CLI mode, or when you add a dependency towards method testTrim(). I haven't fully grasped yet why is that.
1 files modified
49 ■■■■■ changed files
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDBTest.java 49 ●●●●● patch | view | raw | blame | history
opends/tests/unit-tests-testng/src/server/org/opends/server/replication/server/changelog/je/JEChangeNumberIndexDBTest.java
@@ -114,13 +114,11 @@
      cnIndexDB.startTrimmingThread();
      // Check the db is cleared.
      while (!cnIndexDB.isEmpty())
      while (cnIndexDB.count() > 1)
      {
        Thread.sleep(200);
        Thread.yield();
      }
      assertNull(cnIndexDB.getOldestRecord());
      assertNull(cnIndexDB.getNewestRecord());
      assertEquals(cnIndexDB.count(), 0);
      assertOnlyNewestRecordIsLeft(cnIndexDB, 3);
    }
    finally
    {
@@ -145,11 +143,11 @@
  private JEChangeNumberIndexDB newCNIndexDB(ReplicationServer rs) throws Exception
  {
    File testRoot = createCleanDir();
    ReplicationDbEnv dbEnv = new ReplicationDbEnv(testRoot.getPath(), rs);
    JEChangeNumberIndexDB result = new JEChangeNumberIndexDB(rs, dbEnv);
    assertTrue(result.isEmpty());
    return result;
    final File testRoot = createCleanDir();
    final ReplicationDbEnv dbEnv = new ReplicationDbEnv(testRoot.getPath(), rs);
    final JEChangeNumberIndexDB cnIndexDB = new JEChangeNumberIndexDB(rs, dbEnv);
    assertTrue(cnIndexDB.isEmpty());
    return cnIndexDB;
  }
  private File createCleanDir() throws IOException
@@ -219,17 +217,8 @@
      cursor = cnIndexDB.getCursorFrom(cn3);
      assertCursorReadsInOrder(cursor, cn3);
      // check only the last record is left
      cnIndexDB.clear(null);
      final ChangeNumberIndexRecord oldest = cnIndexDB.getOldestRecord();
      final ChangeNumberIndexRecord newest = cnIndexDB.getNewestRecord();
      assertEquals(oldest.getChangeNumber(), 3);
      assertEquals(oldest.getChangeNumber(), newest.getChangeNumber());
      assertEquals(oldest.getPreviousCookie(), newest.getPreviousCookie());
      assertEquals(oldest.getBaseDN(), newest.getBaseDN());
      assertEquals(oldest.getCSN(), newest.getCSN());
      assertEquals(cnIndexDB.count(), 1);
      assertFalse(cnIndexDB.isEmpty());
      assertOnlyNewestRecordIsLeft(cnIndexDB, 3);
      // Check the db is cleared.
      cnIndexDB.clear();
@@ -240,10 +229,30 @@
    }
    finally
    {
      if (cnIndexDB != null)
        cnIndexDB.shutdown();
      remove(replicationServer);
    }
  }
  /**
   * The newest record is no longer cleared to ensure persistence to the last
   * generated change number across server restarts.
   */
  private void assertOnlyNewestRecordIsLeft(JEChangeNumberIndexDB cnIndexDB,
      int newestChangeNumber) throws ChangelogException
  {
    assertEquals(cnIndexDB.count(), 1);
    assertFalse(cnIndexDB.isEmpty());
    final ChangeNumberIndexRecord oldest = cnIndexDB.getOldestRecord();
    final ChangeNumberIndexRecord newest = cnIndexDB.getNewestRecord();
    assertEquals(oldest.getChangeNumber(), newestChangeNumber);
    assertEquals(oldest.getChangeNumber(), newest.getChangeNumber());
    assertEquals(oldest.getPreviousCookie(), newest.getPreviousCookie());
    assertEquals(oldest.getBaseDN(), newest.getBaseDN());
    assertEquals(oldest.getCSN(), newest.getCSN());
  }
  private ReplicationServer newReplicationServer() throws Exception
  {
    TestCaseUtils.startServer();