public async Task TestGarbageCollect() { var configuration = new RocksDbContentMetadataDatabaseConfiguration(_workingDirectory.Path) { CleanOnInitialize = false, }; var context = new Context(Logger); var ctx = new OperationContext(context); var keys = Enumerable.Range(0, 10).Select(i => (ShortHash)ContentHash.Random()).ToArray(); void setBlob(RocksDbContentMetadataDatabase db, ShortHash key) { db.PutBlob(key, key.ToByteArray()); } KeyCheckResult checkBlob(RocksDbContentMetadataDatabase db, ShortHash key) { if (db.TryGetBlob(key, out var blob)) { if (ByteArrayComparer.ArraysEqual(blob, key.ToByteArray())) { return(KeyCheckResult.Valid); } else { return(KeyCheckResult.Different); } } else { return(KeyCheckResult.Missing); } } { var db = new RocksDbContentMetadataDatabase(Clock, configuration); await db.StartupAsync(ctx).ShouldBeSuccess(); db.SetGlobalEntry("test", "hello"); setBlob(db, keys[0]); checkBlob(db, keys[0]).Should().Be(KeyCheckResult.Valid); await db.GarbageCollectAsync(ctx, force : true).ShouldBeSuccess(); setBlob(db, keys[1]); checkBlob(db, keys[0]).Should().Be(KeyCheckResult.Valid); checkBlob(db, keys[1]).Should().Be(KeyCheckResult.Valid); await db.GarbageCollectAsync(ctx, force : true).ShouldBeSuccess(); checkBlob(db, keys[0]).Should().Be(KeyCheckResult.Missing); checkBlob(db, keys[1]).Should().Be(KeyCheckResult.Valid); await db.ShutdownAsync(ctx).ShouldBeSuccess(); } { var db = new RocksDbContentMetadataDatabase(Clock, configuration); await db.StartupAsync(ctx).ShouldBeSuccess(); db.TryGetGlobalEntry("test", out var readValue); readValue.Should().Be("hello"); setBlob(db, keys[2]); checkBlob(db, keys[0]).Should().Be(KeyCheckResult.Missing); checkBlob(db, keys[1]).Should().Be(KeyCheckResult.Valid); checkBlob(db, keys[2]).Should().Be(KeyCheckResult.Valid); await db.GarbageCollectAsync(ctx, force : true).ShouldBeSuccess(); checkBlob(db, keys[0]).Should().Be(KeyCheckResult.Missing); checkBlob(db, keys[1]).Should().Be(KeyCheckResult.Missing); checkBlob(db, keys[2]).Should().Be(KeyCheckResult.Valid); await db.ShutdownAsync(ctx).ShouldBeSuccess(); } }