Connection scheduler.
Inheritance: SyncEventHandler, IConnectionScheduler
Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CmisSync.Lib.Queueing.ConnectionScheduler"/> class by copy all members.
 /// </summary>
 /// <param name="original">Original Instance.</param>
 protected ConnectionScheduler(ConnectionScheduler original) : this(original.RepoInfo, original.Queue, original.SessionFactory, original.AuthProvider, original.Interval)
 {
 }
        public void LoginRetryAfterConfigHasBeenChanged() {
            var waitHandle = new AutoResetEvent(false);
            var newSession = new Mock<ISession>();
            newSession.SetupCreateOperationContext();
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d))
                    .Returns(this.session.Object);
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var underTest = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                underTest.Start();
                waitHandle.WaitOne();
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                    .Returns(newSession.Object);
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.True);
                waitHandle.WaitOne(this.interval);
                waitHandle.WaitOne(this.interval);
                waitHandle.WaitOne(this.interval);
                waitHandle.WaitOne(this.interval);
                waitHandle.WaitOne(this.interval);
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == newSession.Object)), Times.Between(1, 5, Range.Inclusive));
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Between(2, 6, Range.Inclusive));
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Between(1, 5, Range.Inclusive));
            newSession.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Between(1, 5, Range.Inclusive));
        }
        public void LoginBlockedWithLockedUntilFutureDate() {
            var waitHandle = new AutoResetEvent(false);
            var now = DateTime.UtcNow;
            long seconds = 5;
            var exception = Mock.Of<CmisPermissionDeniedException>(e => e.Data == EventsTests.PermissionDeniedEventCalculatesBlockingUntilTest.CreateHeader(now.AddSeconds(seconds).ToString()));
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d)).Throws(exception);
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                scheduler.Start();
                waitHandle.WaitOne();
                this.queue.VerifyThatNoOtherEventIsAddedThan<PermissionDeniedEvent>();
                this.queue.Verify(q => q.AddEvent(It.Is<PermissionDeniedEvent>(e => e.IsBlockedUntil != null)));
                this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                    .Callback<IDictionary<string, string>, object, object, object>(
                        (d, x, y, z) => this.VerifyConnectionProperties(d)).Returns(this.session.Object);
                Assert.That(waitHandle.WaitOne(5 * this.interval), Is.False);
                Assert.That(waitHandle.WaitOne(((int)seconds * 1000) + 1000), Is.True);
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(2));
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Once());
        }
        public void LoginRetryOccursIfFirstLoginFailed() {
            var waitHandle = new AutoResetEvent(false);
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d)).Throws(new CmisRuntimeException("Some generic exception"));
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                scheduler.Start();
                waitHandle.WaitOne();
                this.queue.Verify(q => q.AddEvent(It.IsAny<ExceptionEvent>()), Times.Once());
                this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                    .Callback<IDictionary<string, string>, object, object, object>(
                        (d, x, y, z) => this.VerifyConnectionProperties(d)).Returns(this.session.Object);
                waitHandle.WaitOne();
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(2));
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Once());
        }
        public void LoginRetryAfterPermissionDeniedExceptionOccuredAndConfigHasBeenChanged() {
            var waitHandle = new AutoResetEvent(false);
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d)).Throws<CmisPermissionDeniedException>();
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var underTest = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                underTest.Start();
                waitHandle.WaitOne();
                this.queue.Verify(q => q.AddEvent(It.IsAny<PermissionDeniedEvent>()), Times.Once());
                this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                    .Callback<IDictionary<string, string>, object, object, object>(
                        (d, x, y, z) => this.VerifyConnectionProperties(d)).Returns(this.session.Object);
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.Verify(q => q.AddEvent(It.IsAny<PermissionDeniedEvent>()), Times.Once());
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(1));
                underTest.Handle(new RepoConfigChangedEvent(this.repoInfo));
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.True);
                this.queue.Verify(q => q.AddEvent(It.IsAny<PermissionDeniedEvent>()), Times.Once());
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(2));
                this.queue.Verify(q => q.AddEvent(It.IsAny<SuccessfulLoginEvent>()), Times.Once());
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(2));
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Once());
        }
        public void CreateConnectionAndNoRetryIsExecuted() {
            var waitHandle = new AutoResetEvent(false);
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d))
                    .Returns(this.session.Object);
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                scheduler.Start();
                waitHandle.WaitOne();
                this.queue.VerifyThatNoOtherEventIsAddedThan<SuccessfulLoginEvent>();
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
                Assert.That(waitHandle.WaitOne(3 * this.interval), Is.False);
                this.queue.VerifyThatNoOtherEventIsAddedThan<SuccessfulLoginEvent>();
                this.queue.Verify(q => q.AddEvent(It.Is<SuccessfulLoginEvent>(l => l.Session == this.session.Object)), Times.Once());
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsNotNull<IOperationContext>(), Times.Once());
        }
        public void LoginFailsWithProxyAuthRequiredException() {
            var waitHandle = new AutoResetEvent(false);
            this.sessionFactory.Setup(f => f.CreateSession(It.IsAny<IDictionary<string, string>>(), null, this.authProvider.Object, null))
                .Callback<IDictionary<string, string>, object, object, object>(
                    (d, x, y, z) => this.VerifyConnectionProperties(d)).Throws(new CmisRuntimeException("Proxy Authentication Required"));
            this.queue.Setup(q => q.AddEvent(It.IsAny<ISyncEvent>())).Callback(() => waitHandle.Set());
            using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
                scheduler.Start();
                waitHandle.WaitOne();
                this.queue.VerifyThatNoOtherEventIsAddedThan<ProxyAuthRequiredEvent>();
                this.queue.Verify(q => q.AddEvent(It.IsAny<ProxyAuthRequiredEvent>()));
            }

            this.session.VerifySet(s => s.DefaultContext = It.IsAny<IOperationContext>(), Times.Never());
        }
 public void ConstructorTakesCustomInterval() {
     using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
         Assert.That(scheduler.Interval, Is.EqualTo(this.interval));
     }
 }
 public void DisposingWithoutHavingFinished() {
     using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object, this.interval)) {
         scheduler.Start();
     }
 }
 public void ConstructorSetsDefaultInterval() {
     using (var scheduler = new ConnectionScheduler(this.repoInfo, this.queue.Object, this.sessionFactory.Object, this.authProvider.Object)) {
         Assert.That(scheduler.Interval, Is.GreaterThan(0));
     }
 }
Beispiel #11
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;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CmisSync.Lib.Queueing.ConnectionScheduler"/> class by copy all members.
 /// </summary>
 /// <param name="original">Original Instance.</param>
 protected ConnectionScheduler(ConnectionScheduler original) : this(original.RepoInfo, original.Queue, original.SessionFactory, original.AuthProvider, original.Interval) {
 }
 public InMemoryConnectionScheduler(ConnectionScheduler original, SessionFactory sessionFactory) : base(original) {
     this.SessionFactory = sessionFactory;
 }
 public BlockingSingleConnectionScheduler(ConnectionScheduler original) : base(original) {
 }