public async Task GetTriggersBackgroundSealingByEndOfSession()
        {
            var context        = new Context(Logger);
            var cacheNamespace = Guid.NewGuid().ToString();

            // Each of the caches created below must use the same testDirectory in order to share local content.
            // And they must not run concurrently because the local content store requires exclusive access.
            // This is just for testing purposes; in production, "local" (not in the backing store) content
            // will live in CASaaS which allows concurrent access and can find and serve content from peers.
            using (var testDirectory = new DisposableDirectory(FileSystem))
            {
                // Add a value and its content to a write-never store. This will not upload the content but the content will still be available locally.
                StrongFingerprint strongFingerprint = StrongFingerprint.Random();
                ContentHashList   contentHashList   = null;
                await RunTestAsync(
                    context,
                    async (writeNeverCache, writeNeverSession) =>
                {
                    strongFingerprint = await CreateRandomStrongFingerprintAsync(context, true, writeNeverSession);
                    var initialValue  = await CreateRandomContentHashListWithDeterminismAsync(context, true, writeNeverSession);
                    contentHashList   = initialValue.ContentHashList;

                    var addOrGetResult = await writeNeverSession.AddOrGetContentHashListAsync(
                        context, strongFingerprint, initialValue, Token).ConfigureAwait(false);
                    addOrGetResult.Succeeded.Should().BeTrue();
                    addOrGetResult.ContentHashListWithDeterminism.ContentHashList.Should().BeNull();
                },
                    () => CreateCache(testDirectory, cacheNamespace, FileSystem, Logger, BackingOption.WriteNever, ItemStorageOption));

                contentHashList.Should().NotBeNull();

                // Get the unbacked value to trigger a background sealing
                await RunTestAsync(
                    context,
                    async (writeBehindCache, writeBehindSession) =>
                {
                    var getResult =
                        await writeBehindSession.GetContentHashListAsync(context, strongFingerprint, Token).ConfigureAwait(false);
                    getResult.Succeeded.Should().BeTrue();
                    getResult.ContentHashListWithDeterminism.ContentHashList.Should().Be(contentHashList);
                    getResult.ContentHashListWithDeterminism.Determinism.IsDeterministic.Should().BeFalse();
                },
                    () => CreateCache(testDirectory, cacheNamespace, FileSystem, Logger, BackingOption.WriteBehind, ItemStorageOption));

                // Check that the previous run sealed the value as backed
                await RunTestAsync(
                    context,
                    async (writeBehindCache, writeBehindSession) =>
                {
                    var getResult =
                        await writeBehindSession.GetContentHashListAsync(context, strongFingerprint, Token).ConfigureAwait(false);
                    getResult.Succeeded.Should().BeTrue();
                    getResult.ContentHashListWithDeterminism.ContentHashList.Should().Be(contentHashList);
                    Assert.Equal(writeBehindCache.Id, getResult.ContentHashListWithDeterminism.Determinism.EffectiveGuid);
                    getResult.ContentHashListWithDeterminism.Determinism.IsDeterministic.Should().BeTrue();
                },
                    () => CreateCache(testDirectory, cacheNamespace, FileSystem, Logger, BackingOption.WriteBehind, ItemStorageOption));
            }
        }
Beispiel #2
0
        public void TestSerializeDeserializeContentHashListsNoHashes()
        {
            var chl = new ContentHashList(new ContentHash[0]);

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.Converters.Add(new ContentHashListWithDeterminismConverter());
            string serializedSelector = JsonConvert.SerializeObject(new ContentHashListWithDeterminism(chl, CacheDeterminism.None), serializerSettings);

            var deserializeObject =
                JsonConvert.DeserializeObject <ContentHashListWithDeterminism>(serializedSelector, serializerSettings);

            chl.Should().Be(deserializeObject.ContentHashList);
        }
Beispiel #3
0
        public void TestSerializeDeserializeContentHashListsNoHashesWithPayload()
        {
            byte[] payload = ThreadSafeRandom.GetBytes(RandomBytesSize);
            var    chl     = new ContentHashList(new ContentHash[0], payload);

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.Converters.Add(new ContentHashListWithDeterminismConverter());
            string serializedContentHashList = JsonConvert.SerializeObject(new ContentHashListWithDeterminism(chl, CacheDeterminism.None), serializerSettings);

            var deserializeObject =
                JsonConvert.DeserializeObject <ContentHashListWithDeterminism>(serializedContentHashList, serializerSettings);

            chl.Should().Be(deserializeObject.ContentHashList);
        }
Beispiel #4
0
        public void TestSerializeDeserializeContentHashListsNoPayload()
        {
            var contentHashes = new[]
            {
                ContentHash.Random(),
                ContentHash.Random(),
                ContentHash.Random()
            };

            var chl = new ContentHashList(contentHashes.ToArray());

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.Converters.Add(new ContentHashListWithDeterminismConverter());
            string serializedSelector = JsonConvert.SerializeObject(new ContentHashListWithDeterminism(chl, CacheDeterminism.None), serializerSettings);

            ContentHashListWithDeterminism deserializeObject =
                JsonConvert.DeserializeObject <ContentHashListWithDeterminism>(serializedSelector, serializerSettings);

            chl.Should().Be(deserializeObject.ContentHashList);
        }