feat(render #53): EntityClassificationCache.InvalidateEntity + tests
Idempotent removal of a cached entry by entity id. Tests #4 and #5 from spec section 7.1 lock in the contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
694815c499
commit
aea4460eae
2 changed files with 32 additions and 0 deletions
|
|
@ -62,4 +62,13 @@ internal sealed class EntityClassificationCache
|
||||||
Batches = batches,
|
Batches = batches,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Remove the cache entry for <paramref name="entityId"/>. No-op if the
|
||||||
|
/// id isn't cached.
|
||||||
|
/// </summary>
|
||||||
|
public void InvalidateEntity(uint entityId)
|
||||||
|
{
|
||||||
|
_entries.Remove(entityId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,29 @@ public class EntityClassificationCacheTests
|
||||||
Assert.Equal(0x105u, entry.Batches[5].BindlessTextureHandle);
|
Assert.Equal(0x105u, entry.Batches[5].BindlessTextureHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InvalidateEntity_RemovesEntry()
|
||||||
|
{
|
||||||
|
var cache = new EntityClassificationCache();
|
||||||
|
cache.Populate(100, 0u, new[] { MakeCachedBatch(1, 0, 6, 0xAA) });
|
||||||
|
Assert.True(cache.TryGet(100, out _));
|
||||||
|
|
||||||
|
cache.InvalidateEntity(100);
|
||||||
|
|
||||||
|
Assert.False(cache.TryGet(100, out var entry));
|
||||||
|
Assert.Null(entry);
|
||||||
|
Assert.Equal(0, cache.Count);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void InvalidateEntity_OnMissingId_NoThrow()
|
||||||
|
{
|
||||||
|
var cache = new EntityClassificationCache();
|
||||||
|
var ex = Record.Exception(() => cache.InvalidateEntity(99999));
|
||||||
|
Assert.Null(ex);
|
||||||
|
Assert.Equal(0, cache.Count);
|
||||||
|
}
|
||||||
|
|
||||||
private static CachedBatch MakeCachedBatch(
|
private static CachedBatch MakeCachedBatch(
|
||||||
uint ibo, uint firstIndex, int indexCount, ulong texHandle)
|
uint ibo, uint firstIndex, int indexCount, ulong texHandle)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue