Beispiel #1
0
        private static CosmosContainerCore GetMockedContainer(string containerName = null)
        {
            Mock <CosmosContainerCore> mockedContainer = MockCosmosUtil.CreateMockContainer(containerName: containerName);

            mockedContainer.Setup(c => c.ClientContext).Returns(ChangeFeedProcessorCoreTests.GetMockedClientContext());
            return(mockedContainer.Object);
        }
Beispiel #2
0
        public async Task StopAsync()
        {
            Mock <DocumentServiceLeaseStore> leaseStore = new Mock <DocumentServiceLeaseStore>();

            leaseStore.Setup(l => l.IsInitializedAsync()).ReturnsAsync(true);

            Mock <DocumentServiceLeaseContainer> leaseContainer = new Mock <DocumentServiceLeaseContainer>();

            leaseContainer.Setup(l => l.GetOwnedLeasesAsync()).Returns(Task.FromResult(Enumerable.Empty <DocumentServiceLease>()));
            leaseContainer.Setup(l => l.GetAllLeasesAsync()).Returns(Task.FromResult((IReadOnlyList <DocumentServiceLease>)Enumerable.Empty <DocumentServiceLease>()));

            Mock <DocumentServiceLeaseStoreManager> leaseStoreManager = new Mock <DocumentServiceLeaseStoreManager>();

            leaseStoreManager.Setup(l => l.LeaseContainer).Returns(leaseContainer.Object);
            leaseStoreManager.Setup(l => l.LeaseManager).Returns(Mock.Of <DocumentServiceLeaseManager>);
            leaseStoreManager.Setup(l => l.LeaseStore).Returns(leaseStore.Object);
            leaseStoreManager.Setup(l => l.LeaseCheckpointer).Returns(Mock.Of <DocumentServiceLeaseCheckpointer>);
            ChangeFeedProcessorCore <MyDocument> processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory <MyDocument> > factory, out Mock <ChangeFeedObserver <MyDocument> > observer);

            processor.ApplyBuildConfiguration(
                leaseStoreManager.Object,
                null,
                "something",
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));

            await processor.StartAsync();

            await processor.StopAsync();

            Mock.Get(leaseContainer.Object)
            .Verify(store => store.GetAllLeasesAsync(), Times.Once);
        }
Beispiel #3
0
        private static ContainerInternal GetMockedContainer(string containerName = null)
        {
            Mock <ContainerInternal> mockedContainer = MockCosmosUtil.CreateMockContainer(containerName: containerName);

            mockedContainer.Setup(c => c.ClientContext).Returns(ChangeFeedProcessorCoreTests.GetMockedClientContext());
            Mock <DatabaseInternal> mockedDatabase = MockCosmosUtil.CreateMockDatabase();

            mockedContainer.Setup(c => c.Database).Returns(mockedDatabase.Object);
            return(mockedContainer.Object);
        }
Beispiel #4
0
        public async Task ObserverIsCreated()
        {
            IEnumerable <DocumentServiceLease> ownedLeases = new List <DocumentServiceLease>()
            {
                new DocumentServiceLeaseCore()
                {
                    LeaseId    = "0",
                    LeaseToken = "0"
                }
            };

            Mock <DocumentServiceLeaseStore> leaseStore = new Mock <DocumentServiceLeaseStore>();

            leaseStore.Setup(l => l.IsInitializedAsync()).ReturnsAsync(true);

            Mock <DocumentServiceLeaseContainer> leaseContainer = new Mock <DocumentServiceLeaseContainer>();

            leaseContainer.Setup(l => l.GetOwnedLeasesAsync()).Returns(Task.FromResult(ownedLeases));

            Mock <DocumentServiceLeaseStoreManager> leaseStoreManager = new Mock <DocumentServiceLeaseStoreManager>();

            leaseStoreManager.Setup(l => l.LeaseContainer).Returns(leaseContainer.Object);
            leaseStoreManager.Setup(l => l.LeaseManager).Returns(Mock.Of <DocumentServiceLeaseManager>);
            leaseStoreManager.Setup(l => l.LeaseStore).Returns(leaseStore.Object);
            leaseStoreManager.Setup(l => l.LeaseCheckpointer).Returns(Mock.Of <DocumentServiceLeaseCheckpointer>);
            ChangeFeedProcessorCore processor = null;

            try
            {
                processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory> factory, out Mock <ChangeFeedObserver> observer);
                processor.ApplyBuildConfiguration(
                    leaseStoreManager.Object,
                    null,
                    "instanceName",
                    new ChangeFeedLeaseOptions(),
                    new ChangeFeedProcessorOptions(),
                    ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));

                await processor.StartAsync();

                Mock.Get(factory.Object)
                .Verify(mock => mock.CreateObserver(), Times.Once);

                Mock.Get(observer.Object)
                .Verify(mock => mock.OpenAsync(It.Is <string>((lt) => lt == ownedLeases.First().CurrentLeaseToken)), Times.Once);
            }
            finally
            {
                if (processor != null)
                {
                    await processor.StopAsync();
                }
            }
        }
Beispiel #5
0
        public void ApplyBuildConfiguration_ValidContainerStore()
        {
            ChangeFeedProcessorCore processor = ChangeFeedProcessorCoreTests.CreateProcessor(out _, out _);

            processor.ApplyBuildConfiguration(
                null,
                ChangeFeedProcessorCoreTests.GetMockedContainer("leases"),
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));
        }
Beispiel #6
0
        public void ApplyBuildConfiguration_ValidCustomStore()
        {
            ChangeFeedProcessorCore processor = ChangeFeedProcessorCoreTests.CreateProcessor(out _, out _);

            processor.ApplyBuildConfiguration(
                Mock.Of <DocumentServiceLeaseStoreManager>(),
                null,
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));
        }
        public void ApplyBuildConfiguration_ValidatesNullMonitoredContainer()
        {
            ChangeFeedProcessorCore <MyDocument> processor = ChangeFeedProcessorCoreTests.CreateProcessor(out _, out _);

            processor.ApplyBuildConfiguration(
                Mock.Of <DocumentServiceLeaseStoreManager>(),
                null,
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                null);
        }
Beispiel #8
0
        public void ApplyBuildConfiguration_ValidContainerStore()
        {
            ChangeFeedProcessorCore <MyDocument> processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory <MyDocument> > factory, out Mock <ChangeFeedObserver <MyDocument> > observer);

            processor.ApplyBuildConfiguration(
                null,
                ChangeFeedProcessorCoreTests.GetMockedContainer("leases"),
                "something",
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));
        }
Beispiel #9
0
        public void ApplyBuildConfiguration_ValidatesNullMonitoredContainer()
        {
            var processor = ChangeFeedProcessorCoreTests.CreateProcessor(out Mock <ChangeFeedObserverFactory <MyDocument> > factory, out Mock <ChangeFeedObserver <MyDocument> > observer);

            processor.ApplyBuildConfiguration(
                Mock.Of <DocumentServiceLeaseStoreManager>(),
                null,
                "something",
                "instanceName",
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                null);
        }
        public void ApplyBuildConfiguration_ValidatesNullInstance()
        {
            ChangeFeedProcessorCore <MyDocument> processor = ChangeFeedProcessorCoreTests.CreateProcessor(out _, out _);

            processor.ApplyBuildConfiguration(
                Mock.Of <DocumentServiceLeaseStoreManager>(),
                null,
                "something",
                null,
                new ChangeFeedLeaseOptions(),
                new ChangeFeedProcessorOptions(),
                ChangeFeedProcessorCoreTests.GetMockedContainer("monitored"));
        }