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

Valery Kharseko
yesterday 772caa6e6fcd20030404923d0bba443ea0b0fe03
[#744] Fix flaky ChangelogBackendTestCase: keep generated CSN batches monotonic (#745)
1 files modified
9 ■■■■ changed files
opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java 9 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/ChangelogBackendTestCase.java
@@ -145,6 +145,9 @@
  private final List<LDAPReplicationDomain> domains = new ArrayList<>();
  private final Map<ReplicaId, ReplicationBroker> brokers = new HashMap<>();
  /** Time of the last CSN built by {@link #generateCSNs(int, ReplicaId)}, to keep batches monotonic. */
  private long lastGeneratedCsnTime;
  @BeforeClass
  @Override
  public void setUp() throws Exception
@@ -1252,7 +1255,10 @@
  private CSN[] generateCSNs(int numberOfCsns, ReplicaId replicaId)
  {
    long startTime = TimeThread.getTime();
    // TimeThread only refreshes its cached time every 200 ms, so two batches generated within one
    // tick would collide and be filtered out by the changelog as breaking the key ordering.
    // Start after the previous batch to keep CSNs monotonically increasing, like CSNGenerator does.
    long startTime = Math.max(TimeThread.getTime(), lastGeneratedCsnTime + 1);
    CSN[] csns = new CSN[numberOfCsns];
    for (int i = 0; i < numberOfCsns; i++)
@@ -1260,6 +1266,7 @@
      // seqNum must be greater than 0, so start at 1
      csns[i] = new CSN(startTime + i, i + 1, replicaId.getServerId());
    }
    lastGeneratedCsnTime = csns[numberOfCsns - 1].getTime();
    return csns;
  }