88 *
99 * SPDX-License-Identifier: BSD-3-Clause
1010 *******************************************************************************/
11+ // Some portions generated by Codex
1112
1213package org .eclipse .rdf4j .sail .nativerdf .wal ;
1314
@@ -41,6 +42,7 @@ void findsValueByIdViaSegmentProbe() throws Exception {
4142 // Configure NativeStore with small WAL segment size to ensure multiple segments possible
4243 NativeStoreConfig cfg = new NativeStoreConfig ("spoc,ospc,psoc" );
4344 cfg .setWalMaxSegmentBytes (64 * 1024 ); // 64 KiB
45+ cfg .setWalSyncPolicy (ValueStoreWalConfig .SyncPolicy .ALWAYS .name ());
4446 NativeStore store = (NativeStore ) new NativeStoreFactory ().getSail (cfg );
4547 store .setDataDir (dataDir );
4648 SailRepository repo = new SailRepository (store );
@@ -58,11 +60,20 @@ void findsValueByIdViaSegmentProbe() throws Exception {
5860 ValueStoreWalConfig cfgRead = ValueStoreWalConfig .builder ().walDirectory (walDir ).storeUuid (storeUuid ).build ();
5961
6062 // Build dictionary of minted values from WAL and pick a random entry
61- Map <Integer , ValueStoreWalRecord > dict ;
62- try (ValueStoreWalReader reader = ValueStoreWalReader .open (cfgRead )) {
63- dict = new ValueStoreWalRecovery ().replay (reader );
63+ Map <Integer , ValueStoreWalRecord > dict = Map .of ();
64+ boolean complete = false ;
65+ for (int attempt = 0 ; attempt < 10 && (!complete || dict .isEmpty ()); attempt ++) {
66+ try (ValueStoreWalReader reader = ValueStoreWalReader .open (cfgRead )) {
67+ ValueStoreWalRecovery .ReplayReport report = new ValueStoreWalRecovery ().replayWithReport (reader );
68+ dict = report .dictionary ();
69+ complete = report .complete ();
70+ }
71+ if (!complete || dict .isEmpty ()) {
72+ Thread .sleep (100 );
73+ }
6474 }
6575 assertThat (dict ).isNotEmpty ();
76+ assertThat (complete ).as ("WAL recovery should be complete before searching" ).isTrue ();
6677 Integer [] ids = dict .keySet ().toArray (Integer []::new );
6778 Integer pickId = ids [new Random ().nextInt (ids .length )];
6879
0 commit comments