hello-stephen commented on code in PR #65758:
URL: https://github.com/apache/doris/pull/65758#discussion_r4695702823


##########
fe/fe-core/src/test/java/org/apache/doris/journal/bdbje/BDBEnvironmentTest.java:
##########
@@ -689,34 +704,36 @@ public void testReadTxnIsNotMatched() throws Exception {
                     continue;
                 }
 
-                Assertions.assertEquals(1, 
entryPair.first.getDatabaseNames().size());
-                Database followerDb = 
entryPair.first.openDatabase(beginDbName);
-                DatabaseEntry readValue = new DatabaseEntry();
-                Assertions.assertEquals(OperationStatus.SUCCESS, 
followerDb.get(null, key, readValue, LockMode.DEFAULT));
-                Assertions.assertEquals(new String(value.getData()), new 
String(readValue.getData()));
+                assertDatabaseValueEventually(entryPair.first, beginDbName, 
key, value);
             }
 
+            long count = masterDb.count();
+            DatabaseEntry localCommitKey = new DatabaseEntry(new byte[]{1, 2, 
3});
+            DatabaseEntry localCommitValue = new DatabaseEntry(new byte[]{4, 
5, 6});
+
+            ReplicatedEnvironment replicatedEnvironment = 
masterPair.first.getReplicatedEnvironment();
             Field envImplField = 
ReplicatedEnvironment.class.getDeclaredField("repEnvironmentImpl");
             envImplField.setAccessible(true);
-            RepImpl impl = (RepImpl) 
envImplField.get(masterPair.first.getReplicatedEnvironment());
+            RepImpl impl = (RepImpl) envImplField.get(replicatedEnvironment);
             Assertions.assertNotNull(impl);
 
-            new Expectations(impl) {{
-                    // Below method will replicate log item to followers.
-                    impl.registerVLSN(withNotNull());
-                    // Below method will wait until the logs are replicated.
-                    impl.postLogCommitHook(withNotNull(), withNotNull());
-                    result = new InsufficientAcksException("mocked");
-                }};
-
-            long count = masterDb.count();
-            final Database oldMasterDb = masterDb;
-            Assertions.assertThrows(InsufficientAcksException.class, () -> {
-                // Since this key is not replicated to any replicas, it should 
not be read.
-                DatabaseEntry k = new DatabaseEntry(new byte[]{1, 2, 3});
-                DatabaseEntry v = new DatabaseEntry(new byte[]{4, 5, 6});
-                oldMasterDb.put(null, k, v);
-            });
+            Field environmentImplField = 
com.sleepycat.je.Environment.class.getDeclaredField("environmentImpl");
+            environmentImplField.setAccessible(true);
+            RepImpl implSpy = Mockito.spy(impl);
+            Mockito.doThrow(new InsufficientAcksException("mocked"))
+                    .when(implSpy).postLogCommitHook(Mockito.any(), 
Mockito.any());

Review Comment:
   [P2] Preserve the unreplicated transaction setup
   
   The previous mock also suppressed `registerVLSN`, but this replacement only 
throws from `postLogCommitHook`. Both followers remain live during the write, 
so [JE's normal registration 
path](https://github.com/apache/doris-thirdparty/blob/7bf75a7475fab88711ba01ab4a549c70a1c13269/src/main/java/com/sleepycat/je/rep/impl/RepImpl.java#L778-L795)
 can make the transaction available to the feeders before shutdown even though 
the injected exception fires. The reopened-master count/value assertions then 
pass without creating the unmatched local transaction that 
`BDBJEJournal.isReplicaTxnAreMatched` cites this test to demonstrate. Preserve 
deterministic replication suppression for this write, or otherwise establish 
that it has not reached a majority before restarting the old master.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to