Ejemplo n.º 1
0
        public void BreaksIfHandlerSucceedsTest([Values(true, false)]bool highestFirst)
        {
            var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true);
            handlerMock1.Setup(foo => foo.Priority).Returns(2);

            var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock<ISyncEvent>();

            var underTest = new SyncEventManager();
            if (highestFirst) {
                underTest.AddEventHandler(handlerMock1.Object);
                underTest.AddEventHandler(handlerMock2.Object);
            } else {
                underTest.AddEventHandler(handlerMock2.Object);
                underTest.AddEventHandler(handlerMock1.Object);
            }

            underTest.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
        }
Ejemplo n.º 2
0
        private ObservableHandler RunQueue(Mock <ISession> session, Mock <IMetaDataStorage> storage)
        {
            var manager = new SyncEventManager();

            var observer = new ObservableHandler();

            manager.AddEventHandler(observer);

            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            var changes = new ContentChanges(session.Object, storage.Object, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage.Object);

            manager.AddEventHandler(transformer);

            var accumulator = new ContentChangeEventAccumulator(session.Object, queue);

            manager.AddEventHandler(accumulator);

            queue.RunStartSyncEvent();

            return(observer);
        }
Ejemplo n.º 3
0
        public void DeleteWorksCorrectlyTest()
        {
            var handlerMock1 = new Mock <SyncEventHandler>();

            handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false);
            handlerMock1.Setup(foo => foo.Priority).Returns(1);

            var handlerMock2 = new Mock <SyncEventHandler>();

            handlerMock2.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false);
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var handlerMock3 = new Mock <SyncEventHandler>();

            handlerMock3.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false);
            handlerMock3.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock <ISyncEvent>();

            SyncEventManager manager = new SyncEventManager();

            manager.AddEventHandler(handlerMock1.Object);
            manager.AddEventHandler(handlerMock2.Object);
            manager.AddEventHandler(handlerMock3.Object);
            manager.RemoveEventHandler(handlerMock2.Object);
            manager.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
            handlerMock3.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
        }
Ejemplo n.º 4
0
        public void FirstInsertedHandlerWithSamePrioWinsTest()
        {
            var handlerMock1 = new Mock <SyncEventHandler>()
            {
                CallBase = true
            };

            handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true);
            handlerMock1.Setup(foo => foo.Priority).Returns(1);

            var handlerMock2 = new Mock <SyncEventHandler>()
            {
                CallBase = true
            };

            handlerMock2.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true);
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock <ISyncEvent>();

            var underTest = new SyncEventManager();

            underTest.AddEventHandler(handlerMock1.Object);
            underTest.AddEventHandler(handlerMock2.Object);
            underTest.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public RepoBase(RepoInfo repoInfo, IActivityListener activityListener)
        {
            EventManager = new SyncEventManager();
            EventManager.AddEventHandler(new DebugLoggingHandler());
            EventManager.AddEventHandler(new GenericSyncEventHandler <RepoConfigChangedEvent>(0, RepoInfoChanged));
            Queue     = new SyncEventQueue(EventManager);
            RepoInfo  = repoInfo;
            LocalPath = repoInfo.TargetDirectory;
            Name      = repoInfo.Name;
            RemoteUrl = repoInfo.Address;

            this.activityListener = activityListener;

            if (repoInfo.IsSuspended)
            {
                Status = SyncStatus.Suspend;
            }

            // Folder lock.
            // Disabled for now. Can be an interesting feature, but should be made opt-in, as
            // most users would be surprised to see this file appear.
            // folderLock = new FolderLock(LocalPath);

            Watcher = new Watcher(LocalPath);
            Watcher.EnableRaisingEvents = true;


            // Main loop syncing every X seconds.
            remote_timer.Elapsed += delegate
            {
                // Synchronize.
                SyncInBackground();
            };
            remote_timer.AutoReset = true;
            Logger.Info("Repo " + repoInfo.Name + " - Set poll interval to " + repoInfo.PollInterval + "ms");
            remote_timer.Interval = repoInfo.PollInterval;

            //Partial sync interval..
            local_timer.Elapsed += delegate
            {
                // Run partial sync.
                SyncInBackground(false);
            };
            local_timer.AutoReset = false;
            local_timer.Interval  = delay_interval;
        }
Ejemplo n.º 6
0
        public void AddHandlerTest()
        {
            var handlerMock = new Mock<SyncEventHandler>();
            var mockedEvent = Mock.Of<ISyncEvent>();

            var underTest = new SyncEventManager();
            underTest.AddEventHandler(handlerMock.Object);
            underTest.Handle(mockedEvent);

            handlerMock.Verify(foo => foo.Handle(mockedEvent), Times.Once());
        }
Ejemplo n.º 7
0
        public void AddHandlerTest()
        {
            var handlerMock = new Mock <SyncEventHandler>();
            var mockedEvent = Mock.Of <ISyncEvent>();

            var underTest = new SyncEventManager();

            underTest.AddEventHandler(handlerMock.Object);
            underTest.Handle(mockedEvent);

            handlerMock.Verify(foo => foo.Handle(mockedEvent), Times.Once());
        }
Ejemplo n.º 8
0
        public void AddHandlerTest()
        {
            var handlerMock = new Mock <SyncEventHandler>();
            var eventMock   = new Mock <ISyncEvent>();

            SyncEventManager manager = new SyncEventManager();

            manager.AddEventHandler(handlerMock.Object);
            manager.Handle(eventMock.Object);

            handlerMock.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
        }
Ejemplo n.º 9
0
        public void ContinueIfHandlerNotSucceedsTest()
        {
            var handlerMock1 = new Mock <SyncEventHandler>();

            handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(false);
            handlerMock1.Setup(foo => foo.Priority).Returns(2);

            var handlerMock2 = new Mock <SyncEventHandler>();

            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock <ISyncEvent>();

            SyncEventManager manager = new SyncEventManager();

            manager.AddEventHandler(handlerMock1.Object);
            manager.AddEventHandler(handlerMock2.Object);
            manager.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
        }
Ejemplo n.º 10
0
        public void BreaksIfHandlerSucceedsTest([Values(true, false)] bool highestFirst)
        {
            var handlerMock1 = new Mock <SyncEventHandler>()
            {
                CallBase = true
            };

            handlerMock1.Setup(foo => foo.Handle(It.IsAny <ISyncEvent>())).Returns(true);
            handlerMock1.Setup(foo => foo.Priority).Returns(2);

            var handlerMock2 = new Mock <SyncEventHandler>()
            {
                CallBase = true
            };

            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock <ISyncEvent>();

            var underTest = new SyncEventManager();

            if (highestFirst)
            {
                underTest.AddEventHandler(handlerMock1.Object);
                underTest.AddEventHandler(handlerMock2.Object);
            }
            else
            {
                underTest.AddEventHandler(handlerMock2.Object);
                underTest.AddEventHandler(handlerMock1.Object);
            }

            underTest.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
        }
        public void DropAllFSEventsIfConfigured([Values(true, false)] bool dropAll)
        {
            var manager = new SyncEventManager();
            var handler = new Mock <SyncEventHandler>()
            {
                CallBase = true
            };

            handler.Setup(h => h.Priority).Returns(EventHandlerPriorities.CRITICAL);
            var underTest = new SingleStepEventQueue(manager);

            manager.AddEventHandler(handler.Object);

            underTest.DropAllLocalFileSystemEvents = dropAll;
            underTest.AddEvent(Mock.Of <IFSEvent>());
            underTest.AddEvent(Mock.Of <ISyncEvent>());
            underTest.Run();

            handler.Verify(h => h.Handle(It.IsAny <IFSEvent>()), dropAll ? Times.Never() : Times.Once());
            handler.Verify(h => h.Handle(It.IsAny <ISyncEvent>()), dropAll ? Times.Once() : Times.Exactly(2));
        }
Ejemplo n.º 12
0
        private ObservableHandler RunQueue(Mock<ISession> session, Mock<IMetaDataStorage> storage) {
            var manager = new SyncEventManager();

            var observer = new ObservableHandler();
            manager.AddEventHandler(observer);

            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            var changes = new ContentChanges(session.Object, storage.Object, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage.Object);
            manager.AddEventHandler(transformer);

            var accumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(accumulator);

            queue.RunStartSyncEvent();

            return observer;
        }
Ejemplo n.º 13
0
        private SingleStepEventQueue CreateQueue(Mock<ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null) {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of<ISessionFactory>(), Mock.Of<IAuthenticationProvider>());
            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);
            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);
            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);
            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);
            manager.AddEventHandler(watcher);

            var localDetection = new LocalSituationDetection();
            var remoteDetection = new RemoteSituationDetection();
            var transmissionManager = new TransmissionManager();
            var activityAggregator = new ActivityListenerAggregator(Mock.Of<IActivityListener>(), transmissionManager);

            var ignoreFolderFilter = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, Mock.Of<IFileTransmissionStorage>(), activityAggregator, filterAggregator);
            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();
            remoteFolder.Setup(r => r.Path).Returns(this.remoteRoot);
            var localFolder = new Mock<IDirectoryInfo>();
            localFolder.Setup(f => f.FullName).Returns(this.localRoot);
            var generator = new CrawlEventGenerator(storage, fsFactory);
            var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator, ignoreStorage);
            var notifier = new CrawlEventNotifier(queue);
            var crawler = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of<IActivityListener>());
            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter<PermissionDeniedEvent, ConfigChangedEvent>();
            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);
            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);
            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);
            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
            var failedOperationsFilder = new FailedOperationsFilter(queue);
            manager.AddEventHandler(failedOperationsFilder);
            */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, new SymlinkFilter());
            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();
            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);
            manager.AddEventHandler(movedOrRenamed);

            return queue;
        }
Ejemplo n.º 14
0
        public void FirstInsertedHandlerWithSamePrioWinsTest()
        {
            var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true);
            handlerMock1.Setup(foo => foo.Priority).Returns(1);

            var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock2.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(true);
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock<ISyncEvent>();

            var underTest = new SyncEventManager();
            underTest.AddEventHandler(handlerMock1.Object);
            underTest.AddEventHandler(handlerMock2.Object);
            underTest.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
        }
Ejemplo n.º 15
0
        public void DeleteWorksCorrectlyTest()
        {
            var handlerMock1 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false);
            handlerMock1.Setup(foo => foo.Priority).Returns(1);

            var handlerMock2 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock2.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false);
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var handlerMock3 = new Mock<SyncEventHandler>() { CallBase = true };
            handlerMock3.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false);
            handlerMock3.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock<ISyncEvent>();

            var underTest = new SyncEventManager();
            underTest.AddEventHandler(handlerMock1.Object);
            underTest.AddEventHandler(handlerMock2.Object);
            underTest.AddEventHandler(handlerMock3.Object);
            underTest.RemoveEventHandler(handlerMock2.Object);
            underTest.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Never());
            handlerMock3.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
        }
Ejemplo n.º 16
0
        public void ContinueIfHandlerNotSucceedsTest()
        {
            var handlerMock1 = new Mock<SyncEventHandler>();
            handlerMock1.Setup(foo => foo.Handle(It.IsAny<ISyncEvent>())).Returns(false);
            handlerMock1.Setup(foo => foo.Priority).Returns(2);

            var handlerMock2 = new Mock<SyncEventHandler>();
            handlerMock2.Setup(foo => foo.Priority).Returns(1);

            var eventMock = new Mock<ISyncEvent>();

            SyncEventManager manager = new SyncEventManager();
            manager.AddEventHandler(handlerMock1.Object);
            manager.AddEventHandler(handlerMock2.Object);
            manager.Handle(eventMock.Object);

            handlerMock1.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
            handlerMock2.Verify(foo => foo.Handle(eventMock.Object), Times.Once());
        }
Ejemplo n.º 17
0
        private SingleStepEventQueue CreateQueue(Mock <ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null)
        {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of <ISessionFactory>(), Mock.Of <IAuthenticationProvider>());

            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);

            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);

            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);

            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);

            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);

            manager.AddEventHandler(watcher);

            var localDetection      = new LocalSituationDetection();
            var remoteDetection     = new RemoteSituationDetection();
            var transmissionManager = new ActiveActivitiesManager();
            var activityAggregator  = new ActivityListenerAggregator(Mock.Of <IActivityListener>(), transmissionManager);

            var ignoreFolderFilter      = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter  = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter   = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator        = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, activityAggregator, filterAggregator, isServerAbleToUpdateModificationDate: true);

            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();

            var localFolder = new Mock <IDirectoryInfo>();
            var generator   = new CrawlEventGenerator(storage, fsFactory);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator);
            var notifier    = new CrawlEventNotifier(queue);
            var crawler     = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of <IActivityListener>());

            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter <PermissionDeniedEvent, ConfigChangedEvent>();

            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);

            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);

            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);

            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
             * var failedOperationsFilder = new FailedOperationsFilter(queue);
             * manager.AddEventHandler(failedOperationsFilder);
             */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter);

            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();

            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);

            manager.AddEventHandler(movedOrRenamed);

            return(queue);
        }
        public void DropAllFSEventsIfConfigured([Values(true, false)]bool dropAll) {
            var manager = new SyncEventManager();
            var handler = new Mock<SyncEventHandler>() { CallBase = true };
            handler.Setup(h => h.Priority).Returns(EventHandlerPriorities.CRITICAL);
            var underTest = new SingleStepEventQueue(manager);
            manager.AddEventHandler(handler.Object);

            underTest.DropAllLocalFileSystemEvents = dropAll;
            underTest.AddEvent(Mock.Of<IFSEvent>());
            underTest.AddEvent(Mock.Of<ISyncEvent>());
            underTest.Run();

            handler.Verify(h => h.Handle(It.IsAny<IFSEvent>()), dropAll ? Times.Never() : Times.Once());
            handler.Verify(h => h.Handle(It.IsAny<ISyncEvent>()), dropAll ? Times.Once() : Times.Exactly(2));
        }