Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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();
        }