From 5d176c691527e3fe4bc529ff8947f3b3648970bd Mon Sep 17 00:00:00 2001
From: Valery Kharseko <vharseko@3a-systems.ru>
Date: Thu, 10 Sep 2026 11:58:57 +0000
Subject: [PATCH] [#916] Keep an update that lands during a ServerState save out of the saved flag (#948)

---
 opendj-server-legacy/src/test/java/org/opends/server/replication/common/ServerStateTest.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 deletions(-)

diff --git a/opendj-server-legacy/src/test/java/org/opends/server/replication/common/ServerStateTest.java b/opendj-server-legacy/src/test/java/org/opends/server/replication/common/ServerStateTest.java
index a532060..29237bf 100644
--- a/opendj-server-legacy/src/test/java/org/opends/server/replication/common/ServerStateTest.java
+++ b/opendj-server-legacy/src/test/java/org/opends/server/replication/common/ServerStateTest.java
@@ -13,6 +13,7 @@
  *
  * Copyright 2006-2010 Sun Microsystems, Inc.
  * Portions Copyright 2013-2016 ForgeRock AS.
+ * Portions Copyright 2026 3A Systems, LLC.
  */
 package org.opends.server.replication.common;
 
@@ -139,4 +140,47 @@
     assertTrue(state.removeCSN(csn1Server1));
     assertNull(state.getCSN(1));
   }
+
+  /**
+   * An update that does not change the state must leave the saved status alone:
+   * the status is only cleared for a change that has actually been applied.
+   */
+  @Test
+  public void updateThatChangesNothingKeepsTheStateSaved() throws Exception
+  {
+    final ServerState state = new ServerState();
+    final CSN csn = new CSN(TimeThread.getTime(), 1, 1);
+    assertTrue(state.update(csn));
+
+    state.setSaved(true);
+    assertFalse(state.update(csn), "the very same CSN is not a meaningful update");
+    assertTrue(state.isSaved(), "a duplicate CSN must not clear the saved status");
+
+    final CSN olderCSN = new CSN(csn.getTime() - 1, csn.getSeqnum(), csn.getServerId());
+    assertFalse(state.update(olderCSN), "an older CSN is not a meaningful update");
+    assertTrue(state.isSaved(), "an older CSN must not clear the saved status");
+
+    assertFalse(state.update((CSN) null));
+    assertTrue(state.isSaved(), "a null CSN must not clear the saved status");
+  }
+
+  /**
+   * Emptying the state is a change like any other: it must not leave the state
+   * looking like what persistent storage holds. Emptying one that is already
+   * empty changes nothing, and must leave the saved status alone.
+   */
+  @Test
+  public void clearMarksTheStateUnsaved() throws Exception
+  {
+    final ServerState state = new ServerState();
+    assertTrue(state.update(new CSN(TimeThread.getTime(), 1, 1)));
+    state.setSaved(true);
+
+    state.clear();
+    assertFalse(state.isSaved(), "clearing the state must not leave it marked as saved");
+
+    state.setSaved(true);
+    state.clear();
+    assertTrue(state.isSaved(), "clearing an already empty state must not clear the saved status");
+  }
 }

--
Gitblit v1.10.0