mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-10-27 06:20:02 +00:00
Restore evicted owners from plans
- A demanded owner missing from the owner cache is restored from its planned tile (resident or prepared-plan store) instead of drafted again - Same restore path as persisted tiles; plans identical
This commit is contained in:
1 parent
0b2a606a25
commit
b4ee500c14
4 files changed
+83
No files matched your search
@@ -133,6 +133,33 @@ public class HydrologyPlannerTest {
|
||||
assertTileContentsEqual(tile, planner.plan(EARLY_OWNER_TILE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void evictedOwnerIsRestoredFromItsPlannedTileWithoutDrafting() {
|
||||
AtomicInteger samples = new AtomicInteger();
|
||||
HydrologyTerrainSampler counted = (int x, int z) -> {
|
||||
samples.incrementAndGet();
|
||||
return EARLY_OWNER_TERRAIN.sample(x, z);
|
||||
};
|
||||
HydrologyPlanner planner = new HydrologyPlanner(77L, EARLY_OWNER_SETTINGS, counted);
|
||||
HydrologyTile tile = planner.plan(EARLY_OWNER_TILE);
|
||||
CrossTileResolvedOwner original = tile.resolvedOwner();
|
||||
planner.clearOwnerDrafts();
|
||||
AtomicInteger lookups = new AtomicInteger();
|
||||
planner.usePlannedTiles(key -> {
|
||||
lookups.incrementAndGet();
|
||||
return key.equals(EARLY_OWNER_TILE) ? tile : null;
|
||||
});
|
||||
samples.set(0);
|
||||
|
||||
CrossTileResolvedOwner restored = planner.resolveIndependentOwner(EARLY_OWNER_TILE);
|
||||
|
||||
assertEquals(original, restored);
|
||||
assertEquals(0, samples.get());
|
||||
assertEquals(1, lookups.get());
|
||||
assertSame(restored, planner.resolveIndependentOwner(EARLY_OWNER_TILE));
|
||||
assertEquals(1, lookups.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void restoringPreparedTileKeepsExistingCanonicalOwner() {
|
||||
HydrologyPlanner planner = new HydrologyPlanner(77L, EARLY_OWNER_SETTINGS, EARLY_OWNER_TERRAIN);
|
||||
|
||||
@@ -38,6 +38,7 @@ import java.util.concurrent.TimeoutException;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
@@ -45,6 +46,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -615,6 +617,25 @@ public class HydrologyTileCacheTest {
|
||||
verify(planner).limitEarlyOwners(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void plannerFindsTilesThisCachePlanned() {
|
||||
HydrologyPlanner planner = mock(HydrologyPlanner.class);
|
||||
HydrologyTile tile = mock(HydrologyTile.class);
|
||||
HydrologyPlannerSettings settings = stalePrefetchSettings();
|
||||
when(planner.settings()).thenReturn(settings);
|
||||
when(planner.plan(any(HydrologyTileKey.class))).thenReturn(tile);
|
||||
HydrologyTileCache cache = new HydrologyTileCache(planner, 128);
|
||||
ArgumentCaptor<Function<HydrologyTileKey, HydrologyTile>> planned = ArgumentCaptor.forClass(Function.class);
|
||||
verify(planner).usePlannedTiles(planned.capture());
|
||||
HydrologyTileKey key = new HydrologyTileKey(3, -2);
|
||||
|
||||
assertNull(planned.getValue().apply(key));
|
||||
assertSame(tile, cache.get(key));
|
||||
assertSame(tile, planned.getValue().apply(key));
|
||||
verify(planner, times(1)).plan(key);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPregenBoundsLeaveQueuedPrefetchIntact() {
|
||||
HydrologyPlanner planner = mock(HydrologyPlanner.class);
|
||||
|
||||
Reference in new issue
Block a user