Ejemplo n.º 1
0
        public void Success()
        {
            var result = PushFileResult.PushSucceeded();

            result.Succeeded.Should().BeTrue();

            result.ToString().Should().Contain("Success");
        }
Ejemplo n.º 2
0
        public void Reject_Succeeded_Is_Succeeded()
        {
            var ringCopyResult        = PushFileResult.Rejected(RejectionReason.OlderThanLastEvictedContent);
            var outsideRingCopyResult = PushFileResult.PushSucceeded();
            var result = new ProactiveCopyResult(ringCopyResult, outsideRingCopyResult, retries: 0);

            // Even if one of the operations is successful, the overall operation is successful.
            result.Succeeded.Should().BeTrue();
            result.ToString().Should().Contain(ringCopyResult.Status.ToString());
        }
Ejemplo n.º 3
0
        public void Unavailable_Success_Is_Succeeded()
        {
            var ringCopyResult        = PushFileResult.ServerUnavailable();
            var outsideRingCopyResult = PushFileResult.PushSucceeded();
            var result = new ProactiveCopyResult(ringCopyResult, outsideRingCopyResult, retries: 0);

            result.Succeeded.Should().BeTrue();
            ringCopyResult.Succeeded.Should().BeFalse();
            outsideRingCopyResult.Succeeded.Should().BeTrue();
            result.ToString().Should().Contain("Success");
            result.ToString().Should().Contain("Unavailable");
        }
Ejemplo n.º 4
0
        public void Diabled_Succeeded_Is_Succeeded()
        {
            var ringCopyResult        = PushFileResult.Disabled();
            var outsideRingCopyResult = PushFileResult.PushSucceeded();
            var result = new ProactiveCopyResult(ringCopyResult, outsideRingCopyResult, retries: 0);

            result.Succeeded.Should().BeTrue();

            ringCopyResult.Succeeded.Should().BeFalse();
            outsideRingCopyResult.Succeeded.Should().BeTrue();
            result.ToString().Should().Contain("Success");
            result.ToString().Should().Contain("Disabled");
        }
Ejemplo n.º 5
0
        public void Error_Succeeded_Is_Succeeded()
        {
            var myDiagnostics         = "My diagnostics";
            var myErrorMessage        = "My error message";
            var ringCopyResult        = new PushFileResult(myErrorMessage, myDiagnostics);
            var outsideRingCopyResult = PushFileResult.PushSucceeded();
            var result = new ProactiveCopyResult(ringCopyResult, outsideRingCopyResult, retries: 0);

            // Even if one of the operations is successful, the overall operation is successful.
            result.Succeeded.Should().BeTrue();
            result.ToString().Should().NotContain(myDiagnostics, "The final error should not have an error message. Only error status");
            result.ToString().Should().NotContain(myErrorMessage, "The final error should not have an error message. Only error status");
            result.ToString().Should().Contain(ringCopyResult.Status.ToString());
        }
Ejemplo n.º 6
0
        public virtual async Task <PushFileResult> PushFileAsync(OperationContext context, ContentHash hash, Stream stream, MachineLocation targetMachine, CopyOptions options)
        {
            var tempFile = AbsolutePath.CreateRandomFileName(WorkingDirectory);

            using (var file = File.OpenWrite(tempFile.Path))
            {
                await stream.CopyToAsync(file);
            }

            var result = await PushHandlersByLocation[targetMachine].HandlePushFileAsync(context, hash, tempFile, CancellationToken.None);

            File.Delete(tempFile.Path);

            return(result ? PushFileResult.PushSucceeded(result.ContentSize) : new PushFileResult(result));
        }
Ejemplo n.º 7
0
        public async Task <PushFileResult> PushFileAsync(OperationContext context, ContentHash hash, Func <Task <Result <Stream> > > source, MachineLocation targetMachine)
        {
            var tempFile     = AbsolutePath.CreateRandomFileName(WorkingDirectory);
            var streamResult = await source();

            using var stream = streamResult.Value;
            using (var file = File.OpenWrite(tempFile.Path))
            {
                await stream.CopyToAsync(file);
            }

            var result = await PushHandlersByLocation[targetMachine].HandlePushFileAsync(context, hash, tempFile, CancellationToken.None);

            File.Delete(tempFile.Path);

            return(result ? PushFileResult.PushSucceeded() : new PushFileResult(result));
        }
Ejemplo n.º 8
0
        public virtual async Task <PushFileResult> PushFileAsync(OperationContext context, ContentHash hash, Stream stream, MachineLocation targetMachine, CopyOptions options)
        {
            var result = await PushHandlersByLocation[targetMachine].HandlePushFileAsync(context, hash, new FileSource(stream), CancellationToken.None);

            return(result ? PushFileResult.PushSucceeded(result.ContentSize) : new PushFileResult(result));
        }