コード例 #1
0
        private async Task TestSuccessfulPutStreamAndGet(IContentStoreInternal store, byte[] content)
        {
            ContentHash actualContentHash = content.CalculateHash(ContentHashType);

            using (var contentStream = new MemoryStream(content))
            {
                var context = new Context(Logger);
                var result  = await store.PutStreamAsync(context, contentStream, actualContentHash);

                ContentHash hashFromPut = result.ContentHash;
                long        sizeFromPut = result.ContentSize;

                Assert.True(actualContentHash.Equals(hashFromPut));
                Assert.Equal(content.Length, sizeFromPut);

                // Get the content from the store
                using (var pinContext = store.CreatePinContext())
                {
                    var r2 = await store.PinAsync(context, hashFromPut, pinContext);

                    r2.ShouldBeSuccess();
                    var r3 = await store.OpenStreamAsync(context, hashFromPut);

                    r3.ShouldBeSuccess();
                    byte[] bytes = await r3.Stream.GetBytes();

                    Assert.True(content.SequenceEqual(bytes));
                }
            }
        }
コード例 #2
0
        private async Task TestSuccessfulPutAbsolutePathAndGet(IContentStoreInternal store, byte[] content, FileRealizationMode ingressModes)
        {
            using (var tempDirectory = new DisposableDirectory(FileSystem))
            {
                AbsolutePath pathToFile = CreateRandomFile(tempDirectory.Path, content);

                using (var contentStream = new MemoryStream(content))
                {
                    ContentHash actualContentHash = await contentStream.HasLength().CalculateHashAsync(ContentHashType);

                    var context = new Context(Logger);
                    var result  = await store.PutFileAsync(context, pathToFile, ingressModes, ContentHashType);

                    ContentHash hashFromPut = result.ContentHash;
                    long        sizeFromPut = result.ContentSize;

                    Assert.True(actualContentHash.Equals(hashFromPut));
                    Assert.Equal(content.Length, sizeFromPut);

                    // Get the content from the store
                    using (var pinContext = store.CreatePinContext())
                    {
                        var r2 = await store.PinAsync(context, hashFromPut, pinContext);

                        r2.ShouldBeSuccess();
                        var r3 = await store.OpenStreamAsync(context, hashFromPut);

                        var bytes = await r3.Stream.GetBytes();

                        Assert.True(content.SequenceEqual(bytes));
                    }
                }
            }
        }
コード例 #3
0
 /// <inheritdoc />
 protected override Task <PinResult> PinCoreAsync(OperationContext operationContext, ContentHash contentHash, UrgencyHint urgencyHint, Counter retryCounter)
 {
     return(Store.PinAsync(operationContext, contentHash, _pinContext));
 }