public void RoundtripContentHash() { ContentHash hash = ContentHash.Random(HashType.Vso0); ByteString byteString = hash.ToByteString(); ContentHash roundtripContentHash = byteString.ToContentHash(HashType.Vso0); roundtripContentHash.Should().Be(hash); }
public async Task EvictionCausesRedisGarbageCollection() { // Use the same context in two sessions when checking for file existence var loggingContext = new Context(Logger); // Set content hash for random file #1 because content hash cannot be null var randomHash = ContentHash.Random(); ContentHash contentHash = randomHash; await RunTestAsync( loggingContext, 1, async context => { var session = context.GetDistributedSession(0); // Insert random file #1 into session var putResult = await session.PutRandomAsync(context, HashType.Vso0, false, Config.MaxSizeQuota.Hard, Token); Assert.True(putResult.Succeeded, putResult.ErrorMessage + " " + putResult.Diagnostics); contentHash = putResult.ContentHash; var result = await session.ContentLocationStore.GetBulkAsync( context, new[] { putResult.ContentHash }, Token, UrgencyHint.Nominal); Assert.True(result.Succeeded, result.ErrorMessage + " " + result.Diagnostics); result.ContentHashesInfo.Count.Should().Be(1); result.ContentHashesInfo[0].ContentHash.Should().Be(putResult.ContentHash); result.ContentHashesInfo[0].Size.Should().Be(putResult.ContentSize); result.ContentHashesInfo[0].Locations.Count.Should().Be(1); // Put large file #2 that will evict random file #1 putResult = await session.PutRandomAsync(context, HashType.Vso0, false, Config.MaxSizeQuota.Hard, Token); Assert.True(putResult.Succeeded, putResult.ErrorMessage + " " + putResult.Diagnostics); }, implicitPin : ImplicitPin.None, enableDistributedEviction : true); // Content hash should be set to random file #1 from first session contentHash.Should().NotBe(randomHash); await RunTestAsync( loggingContext, 1, async context => { var session = context.GetDistributedSession(0); var locationsResult = await session.ContentLocationStore.GetBulkAsync( context, new[] { contentHash }, Token, UrgencyHint.Nominal); // Random file #1 should not be found Assert.True(locationsResult.Succeeded, locationsResult.ErrorMessage + " " + locationsResult.Diagnostics); locationsResult.ContentHashesInfo.Count.Should().Be(1); locationsResult.ContentHashesInfo[0].Should().NotBeNull(); locationsResult.ContentHashesInfo[0].Locations.Should().BeNullOrEmpty(); }); }