Esempio n. 1
0
        public void Should_not_perform_file_delete_if_it_is_being_synced()
        {
            var filename = FileHeader.Canonize("file.bin");

            var client = NewAsyncClient();
            var rfs    = GetFileSystem();

            client.UploadAsync("file.bin", new MemoryStream(new byte[] { 1, 2, 3, 4, 5 })).Wait();

            rfs.Files.IndicateFileToDelete(filename, null);

            rfs.Storage.Batch(accessor =>
                              accessor.SetConfigurationValue(RavenFileNameHelper.SyncLockNameForFile(filename),
                                                             LockFileTests.SynchronizationConfig(DateTime.UtcNow)));

            rfs.Files.CleanupDeletedFilesAsync().Wait();

            DeleteFileOperation deleteFile = null;

            rfs.Storage.Batch(accessor =>
                              deleteFile = accessor.GetConfigurationValue <DeleteFileOperation>(RavenFileNameHelper.DeleteOperationConfigNameForFile(RavenFileNameHelper.DeletingFileName(filename))));

            Assert.Equal(RavenFileNameHelper.DeletingFileName(filename), deleteFile.CurrentFileName);
            Assert.Equal(filename, deleteFile.OriginalFileName);
        }
Esempio n. 2
0
        public void Should_not_delete_downloading_file_if_synchronization_retry_is_being_performed()
        {
            const string fileName            = "file.bin";
            var          downloadingFileName = RavenFileNameHelper.DownloadingFileName(fileName);

            var client = NewAsyncClient();
            var rfs    = GetFileSystem();

            client.UploadAsync(fileName, new RandomStream(1)).Wait();

            client.UploadAsync(downloadingFileName, new RandomStream(1)).Wait();

            rfs.Files.IndicateFileToDelete(downloadingFileName, null);

            rfs.Storage.Batch(accessor =>
                              accessor.SetConfigurationValue(RavenFileNameHelper.SyncLockNameForFile(fileName), LockFileTests.SynchronizationConfig(DateTime.UtcNow)));

            rfs.Files.CleanupDeletedFilesAsync().Wait();

            DeleteFileOperation deleteFile = null;

            rfs.Storage.Batch(accessor =>
                              deleteFile = accessor.GetConfigurationValue <DeleteFileOperation>(RavenFileNameHelper.DeleteOperationConfigNameForFile(RavenFileNameHelper.DeletingFileName(downloadingFileName))));

            Assert.Equal(RavenFileNameHelper.DeletingFileName(downloadingFileName), deleteFile.CurrentFileName);
            Assert.Equal(downloadingFileName, deleteFile.OriginalFileName);
        }
Esempio n. 3
0
        public async Task Make_sure_that_locks_are_released_after_synchronization_when_two_files_synchronized_simultaneously()
        {
            var sourceClient      = NewAsyncClient(0);
            var destinationClient = NewAsyncClient(1);

            var source1Content = new RandomStream(10000);

            await sourceClient.UploadAsync("test1.bin", source1Content);

            var source2Content = new RandomStream(10000);

            await sourceClient.UploadAsync("test2.bin", source2Content);

            await sourceClient.Synchronization.SetDestinationsAsync(destinationClient.ToSynchronizationDestination());

            await sourceClient.Synchronization.SynchronizeAsync();

            var configs = await destinationClient.Configuration.GetKeyNamesAsync();

            Assert.DoesNotContain(RavenFileNameHelper.SyncLockNameForFile("test1.bin"), configs);
            Assert.DoesNotContain(RavenFileNameHelper.SyncLockNameForFile("test2.bin"), configs);

            // also make sure that results exist
            Assert.Contains(RavenFileNameHelper.SyncResultNameForFile("test1.bin"), configs);
            Assert.Contains(RavenFileNameHelper.SyncResultNameForFile("test2.bin"), configs);
        }
Esempio n. 4
0
        private static void ZeroTimeoutTest(IAsyncFilesCommands destinationClient, Action action)
        {
            destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.MinValue)).Wait();

            destinationClient.Configuration.SetKeyAsync(SynchronizationConstants.RavenSynchronizationLockTimeout, TimeSpan.FromSeconds(0)).Wait();

            Assert.DoesNotThrow(() => action());
        }
Esempio n. 5
0
        public void UnlockByDeletingSyncConfiguration(string fileName, IStorageActionsAccessor accessor)
        {
            accessor.DeleteConfig(RavenFileNameHelper.SyncLockNameForFile(fileName));

            if (log.IsDebugEnabled)
            {
                log.Debug("File '{0}' was unlocked", fileName);
            }
        }
Esempio n. 6
0
        public void LockByCreatingSyncConfiguration(string fileName, ServerInfo sourceServer, IStorageActionsAccessor accessor)
        {
            var syncLock = new SynchronizationLock
            {
                SourceServer = sourceServer,
                FileLockedAt = DateTime.UtcNow
            };

            accessor.SetConfig(RavenFileNameHelper.SyncLockNameForFile(fileName), JsonExtensions.ToJObject(syncLock));

            log.Debug("File '{0}' was locked", fileName);
        }
Esempio n. 7
0
        public async void Should_refuse_to_synchronize_file_while_sync_configuration_exists()
        {
            IAsyncFilesCommands destinationClient;
            IAsyncFilesCommands sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.UtcNow));

            var synchronizationReport = SyncTestUtils.ResolveConflictAndSynchronize(sourceClient, destinationClient, "test.bin");

            Assert.Equal(string.Format("File {0} is being synced", FileHeader.Canonize("test.bin")), synchronizationReport.Exception.Message);
        }
Esempio n. 8
0
        public async void Should_refuse_to_synchronize_file_while_sync_configuration_exists()
        {
            RavenFileSystemClient destinationClient;
            RavenFileSystemClient sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await destinationClient.Config.SetConfig(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.UtcNow));

            var synchronizationReport = SyncTestUtils.ResolveConflictAndSynchronize(sourceClient, destinationClient, "test.bin");

            Assert.Equal("File test.bin is being synced", synchronizationReport.Exception.Message);
        }
Esempio n. 9
0
        public async Task Should_refuse_to_upload_file_while_sync_configuration_exists()
        {
            IAsyncFilesCommands destinationClient;
            IAsyncFilesCommands sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.UtcNow));

            var innerException = SyncTestUtils.ExecuteAndGetInnerException(async() => await destinationClient.UploadAsync("test.bin", new MemoryStream()));

            Assert.IsType(typeof(SynchronizationException), innerException.GetBaseException());
            Assert.Equal(string.Format("File {0} is being synced", FileHeader.Canonize("test.bin")), innerException.GetBaseException().Message);
        }
Esempio n. 10
0
        public async Task Should_refuse_to_delete_file_while_sync_configuration_exists()
        {
            RavenFileSystemClient destinationClient;
            RavenFileSystemClient sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await destinationClient.Config.SetConfig(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.UtcNow));

            var innerException = SyncTestUtils.ExecuteAndGetInnerException(async() => await destinationClient.DeleteAsync("test.bin"));

            Assert.IsType(typeof(SynchronizationException), innerException.GetBaseException());
            Assert.Equal("File test.bin is being synced", innerException.GetBaseException().Message);
        }
Esempio n. 11
0
        public async Task Should_refuse_to_update_metadata_while_sync_configuration_exists()
        {
            IAsyncFilesCommands destinationClient;
            IAsyncFilesCommands sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await destinationClient.Configuration.SetKeyAsync(RavenFileNameHelper.SyncLockNameForFile("test.bin"), SynchronizationConfig(DateTime.UtcNow));

            var innerException = SyncTestUtils.ExecuteAndGetInnerException(async() => await destinationClient.UpdateMetadataAsync("test.bin", new RavenJObject()));

            Assert.IsType(typeof(SynchronizationException), innerException.GetBaseException());
            Assert.Equal("File test.bin is being synced", innerException.GetBaseException().Message);
        }
Esempio n. 12
0
        public bool TimeoutExceeded(string fileName, IStorageActionsAccessor accessor)
        {
            SynchronizationLock syncLock;

            try
            {
                syncLock = accessor.GetConfig(RavenFileNameHelper.SyncLockNameForFile(fileName)).JsonDeserialization <SynchronizationLock>();
            }
            catch (FileNotFoundException)
            {
                return(true);
            }

            return(DateTime.UtcNow - syncLock.FileLockedAt > SynchronizationTimeout(accessor));
        }
Esempio n. 13
0
        public async Task Should_delete_sync_configuration_after_synchronization()
        {
            IAsyncFilesCommands destinationClient;
            IAsyncFilesCommands sourceClient;

            UploadFilesSynchronously(out sourceClient, out destinationClient);

            await sourceClient.Synchronization.StartAsync("test.bin", destinationClient);

            var config = await destinationClient.Configuration.GetKeyAsync <SynchronizationLock>(RavenFileNameHelper.SyncLockNameForFile("test.bin"));

            Assert.Null(config);
        }