Exemple #1
0
        public void Stream_Write_Should_Fail_As_Soon_As_Expiration_Date_Is_Reached()
        {
            //cancel transfer in order to release lock
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            //make source file rather big (400MB)
            File.WriteAllBytes(SourceFile.FullName, new byte[1024 * 1024 * 400]);
            GC.Collect();

            //make the transfer expire
            ThreadPool.QueueUserWorkItem(s =>
            {
                Thread.Sleep(50);
                SystemTime.Now = () => Token.ExpirationTime.Value.AddSeconds(1);
            });

            //start streaming the file
            try
            {
                provider.WriteFile(SourceFile.FullName, TargetFile.FullName, false);
                Assert.Fail("Expected status exception due to expiration.");
            }
            catch (TransferStatusException expected)
            {
            }

            //make sure the file is unlocked
            EnsureTargetFileIsUnlocked();
        }
Exemple #2
0
        public void Cancelling_Transfer_Before_Writing_Any_Data_Should_Retain_File_That_Would_Have_Overwritten()
        {
            Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, "");
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            TargetFile.Refresh();
            Assert.IsTrue(TargetFile.Exists);
            Assert.AreEqual(2048, TargetFile.Length);
        }
Exemple #3
0
        public void Cancelling_Transfer_While_Uploading_Should_Delete_Partial_File()
        {
            Token = UploadHandler.RequestUploadToken(TargetFilePath, true, SourceFile.Length, "");

            var block = CreateBufferedBlocks().First();

            UploadHandler.WriteBlock(block);
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            TargetFile.Refresh();
            Assert.IsFalse(TargetFile.Exists);
        }
Exemple #4
0
        public void New_Token_Is_Being_Granted_After_Expiration()
        {
            SystemTime.Now = () => Token.ExpirationTime.Value.AddSeconds(1);

            //make sure the scheduler can readjust
            Thread.CurrentThread.Join(500);

            var token = UploadHandler.RequestUploadToken(TargetFilePath, false, SourceFile.Length, "");

            Assert.AreNotSame(token, Token);
            UploadHandler.CancelTransfer(token.TransferId, AbortReason.ClientAbort);
        }
        public void Transfer_Should_Be_Denied_If_Upload_Is_Already_Running()
        {
            try
            {
                Token = UploadHandler.RequestUploadToken(TargetFilePath, true, 5000, "");
                Assert.Fail("Got upload token while download is running.");
            }
            catch (ResourceLockedException expected)
            {
            }
            finally
            {
                UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);
            }

            //after the canceling, it should work
            InitToken();
        }
        public void Writing_A_Single_Empty_Block_Should_Create_File()
        {
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            //get token for empty file
            Token = UploadHandler.RequestUploadToken(TargetFilePath, false, 0, "");

            TargetFile.Refresh();
            Assert.IsFalse(TargetFile.Exists);

            var block = new BufferedDataBlock {
                TransferTokenId = Token.TransferId, BlockLength = 0, BlockNumber = 0, Data = new byte[0], IsLastBlock = true
            };

            UploadHandler.WriteBlock(block);

            TargetFile.Refresh();
            Assert.IsTrue(TargetFile.Exists);
        }
        public void Uploading_An_Empty_File_Should_Create_The_File()
        {
            UploadHandler.CancelTransfer(Token.TransferId, AbortReason.ClientAbort);

            SourceFile.Delete();
            using (var fs = SourceFile.Create())
            {
                fs.Close();
            }

            SourceFile.Refresh();
            Assert.AreEqual(0, SourceFile.Length);

            TargetFile.Refresh();
            Assert.IsFalse(TargetFile.Exists);

            using (var fs = SourceFile.OpenRead())
            {
                UploadHandler.WriteFile(TargetFilePath, fs, true, 0, "");
            }

            TargetFile.Refresh();
            Assert.IsTrue(TargetFile.Exists);
        }