Beispiel #1
0
        public void TestDoesContentExist()
        {
            ImageSource    source = new ImageSource(false, false, true, ImageSource.storeRoot);
            FileImageStore store  = new FileImageStore("file:.\\TestRoot");

            Verify.IsTrue(store.DoesContentExist(ImageSource.sourceFile, TimeSpan.MaxValue), "Tag Test should Exist");
            Verify.IsFalse(store.DoesContentExist("Test1", TimeSpan.MaxValue), "Tag Test1 should not Exist");
            source.Delete();
        }
Beispiel #2
0
        public void TestDeleteContent()
        {
            ImageSource    source = new ImageSource(false, false, true, ImageSource.storeRoot);
            FileImageStore store  = new FileImageStore("file:.\\TestRoot");

            Verify.IsTrue(File.Exists(Path.Combine(ImageSource.storeRoot, ImageSource.sourceFile)));
            store.DeleteContent(ImageSource.sourceFile, TimeSpan.MaxValue);
            Verify.IsFalse(File.Exists(Path.Combine(ImageSource.storeRoot, ImageSource.sourceFile)));
            source.Delete();
        }
Beispiel #3
0
        public void TestParallelUploads()
        {
            // Initialize parameters.
            string             sourceOneTag           = "TestSource1";
            ImageSource        source                 = new ImageSource(true, false, true, ImageSource.source);
            ImageSource        root                   = new ImageSource(false, false, false, ImageSource.storeRoot);
            ImageSource        sourceOne              = new ImageSource(true, false, true, sourceOneTag);
            AutoResetEvent     operationFinishedEvent = new AutoResetEvent(false);
            AutoResetEvent     operationToStartEvent  = new AutoResetEvent(false);
            DelegateParameters param                  = new DelegateParameters()
            {
                operationFinishedEvent = operationFinishedEvent, operationToStartEvent = operationToStartEvent, result = false
            };

            // Start the other thread.
            Thread thread = new Thread(FileImageStoreTest.UploadDelegate);

            thread.Start(param);

            // Initialize parameters of this thread.
            FileImageStore store         = new FileImageStore("file:.\\TestRoot");
            string         sourceOnePath = Path.Combine(sourceOneTag, ImageSource.sourceFile);

            // Wait for the other thread to start.
            operationToStartEvent.WaitOne();
            Thread.Sleep(100);
            // Start upload
            bool result = true;

            try
            {
                store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            }
            catch (Exception)
            {
                result = false;
            }

            // Wait for the other upload to complete.
            operationFinishedEvent.WaitOne();
            // Ensure only one of the uploads passes.
            Verify.IsTrue(result != param.result, String.Format("Result from other thread is {0}, this thread is {1}", result, param.result));
            Verify.IsTrue(File.Exists(sourceOnePath));

            // Ensure that you can upload.
            store.UploadContent(ImageSource.sourceFile, sourceOnePath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent, true);
            Verify.IsTrue(File.Exists(sourceOnePath));
            sourceOne.Delete();
            source.Delete();
            root.Delete();
        }
Beispiel #4
0
        public void TestDownloadContent()
        {
            ImageSource    root   = new ImageSource(false, true, true, ImageSource.storeRoot);
            ImageSource    source = new ImageSource(false, false, false, ImageSource.source);
            FileImageStore store  = new FileImageStore("file:.\\TestRoot");

            store.DownloadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent);
            store.DownloadContent(ImageSource.sourceFile, Path.Combine(ImageSource.source, ImageSource.sourceFile), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent);
            Verify.IsTrue(File.Exists(Path.Combine(ImageSource.source, ImageSource.sourceFile)));
            store.DownloadContent(ImageSource.sourceDir, Path.Combine(ImageSource.source, ImageSource.sourceDir), TimeSpan.MaxValue, CopyFlag.CopyIfDifferent);
            Verify.IsTrue(File.Exists(Path.Combine(ImageSource.source, ImageSource.sourceDir, ImageSource.sourceFile)));
            root.Delete();
            source.Delete();
        }
Beispiel #5
0
        public void TestParallelUploadsAndDownloads()
        {
            // Initialize parameters.
            string             destinationLocation = "TestDest";
            ImageSource        source                 = new ImageSource(true, false, true, ImageSource.source);
            ImageSource        root                   = new ImageSource(false, false, false, ImageSource.storeRoot);
            ImageSource        destiantion            = new ImageSource(false, false, false, destinationLocation);
            AutoResetEvent     operationFinishedEvent = new AutoResetEvent(false);
            AutoResetEvent     operationToStartEvent  = new AutoResetEvent(false);
            DelegateParameters param                  = new DelegateParameters()
            {
                operationFinishedEvent = operationFinishedEvent, operationToStartEvent = operationToStartEvent, result = false
            };

            // Start the delegate thread.
            Thread thread = new Thread(FileImageStoreTest.UploadDelegate);

            thread.Start(param);
            // Wait for the other thread to start and sleep a little so that the other thread has started.
            operationToStartEvent.WaitOne();
            // Verify you cant download.
            FileImageStore store           = new FileImageStore("file:.\\TestRoot");
            string         destinationPath = Path.Combine(destinationLocation, ImageSource.sourceFile);

            while (!File.Exists("TestRoot\\Test"))
            {
                Thread.Sleep(100);
            }

            Verify.Throws <FabricTransientException>(
                () => store.DownloadContent(ImageSource.sourceFile, destinationPath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent),
                "Download should have failed because of parallel upload.");

            // Once the upload in the other thread is complete this one should complete too.
            operationFinishedEvent.WaitOne();
            store.DownloadContent(ImageSource.sourceFile, destinationPath, TimeSpan.MaxValue, CopyFlag.CopyIfDifferent);
            Verify.IsTrue(File.Exists(destinationPath));
            destiantion.Delete();
            source.Delete();
            root.Delete();
        }