コード例 #1
0
        public CosmosDbFhirStorageTestsFixture()
        {
            _cosmosDataStoreConfiguration = new CosmosDataStoreConfiguration
            {
                Host                  = Environment.GetEnvironmentVariable("CosmosDb:Host") ?? CosmosDbLocalEmulator.Host,
                Key                   = Environment.GetEnvironmentVariable("CosmosDb:Key") ?? CosmosDbLocalEmulator.Key,
                DatabaseId            = Environment.GetEnvironmentVariable("CosmosDb:DatabaseId") ?? "FhirTests",
                AllowDatabaseCreation = true,
                PreferredLocations    = Environment.GetEnvironmentVariable("CosmosDb:PreferredLocations")?.Split(';', StringSplitOptions.RemoveEmptyEntries),
            };

            _cosmosCollectionConfiguration = new CosmosCollectionConfiguration
            {
                CollectionId = Guid.NewGuid().ToString(),
            };

            var fhirStoredProcs = typeof(IFhirStoredProcedure).Assembly
                                  .GetTypes()
                                  .Where(x => !x.IsAbstract && typeof(IFhirStoredProcedure).IsAssignableFrom(x))
                                  .ToArray()
                                  .Select(type => (IFhirStoredProcedure)Activator.CreateInstance(type));

            var optionsMonitor = Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >();

            optionsMonitor.Get(CosmosDb.Constants.CollectionConfigurationName).Returns(_cosmosCollectionConfiguration);

            var updaters = new IFhirCollectionUpdater[]
            {
                new FhirCollectionSettingsUpdater(_cosmosDataStoreConfiguration, optionsMonitor, NullLogger <FhirCollectionSettingsUpdater> .Instance),
                new FhirStoredProcedureInstaller(fhirStoredProcs),
            };

            var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <IDocumentClient> > >(), NullLogger <CosmosDbDistributedLock> .Instance);

            var upgradeManager = new FhirCollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, optionsMonitor, dbLock, NullLogger <FhirCollectionUpgradeManager> .Instance);
            IDocumentClientTestProvider testProvider = new DocumentClientReadWriteTestProvider();

            var documentClientInitializer = new DocumentClientInitializer(testProvider, NullLogger <DocumentClientInitializer> .Instance);

            _documentClient = documentClientInitializer.CreateDocumentClient(_cosmosDataStoreConfiguration);
            var fhirCollectionInitializer = new CollectionInitializer(_cosmosCollectionConfiguration.CollectionId, _cosmosDataStoreConfiguration, _cosmosCollectionConfiguration.InitialCollectionThroughput, upgradeManager, NullLogger <CollectionInitializer> .Instance);

            documentClientInitializer.InitializeDataStore(_documentClient, _cosmosDataStoreConfiguration, new List <ICollectionInitializer> {
                fhirCollectionInitializer
            }).GetAwaiter().GetResult();

            var cosmosDocumentQueryFactory = new FhirCosmosDocumentQueryFactory(Substitute.For <IFhirRequestContextAccessor>(), NullFhirDocumentQueryLogger.Instance);
            var fhirRequestContextAccessor = new FhirRequestContextAccessor();

            Value = new CosmosFhirDataStore(
                new NonDisposingScope(_documentClient),
                _cosmosDataStoreConfiguration,
                cosmosDocumentQueryFactory,
                new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration),
                fhirRequestContextAccessor,
                optionsMonitor,
                NullLogger <CosmosFhirDataStore> .Instance);
        }
コード例 #2
0
        public FhirCosmosSearchService(
            ISearchOptionsFactory searchOptionsFactory,
            CosmosFhirDataStore fhirDataStore,
            IQueryBuilder queryBuilder)
            : base(searchOptionsFactory, fhirDataStore)
        {
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));
            EnsureArg.IsNotNull(queryBuilder, nameof(queryBuilder));

            _fhirDataStore = fhirDataStore;
            _queryBuilder  = queryBuilder;
        }
コード例 #3
0
 public CosmosFhirDataStoreTests()
 {
     _cosmosQueryFactory = Substitute.For <ICosmosQueryFactory>();
     _dataStore          = new CosmosFhirDataStore(
         Substitute.For <IScoped <Container> >(),
         _cosmosDataStoreConfiguration,
         Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >(),
         _cosmosQueryFactory,
         new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration),
         NullLogger <CosmosFhirDataStore> .Instance,
         Options.Create(new CoreFeatureConfiguration()));
 }
コード例 #4
0
 public CosmosFhirDataStoreTests()
 {
     _cosmosQueryFactory = Substitute.For <ICosmosQueryFactory>();
     _dataStore          = new CosmosFhirDataStore(
         Substitute.For <IScoped <Container> >(),
         _cosmosDataStoreConfiguration,
         Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >(),
         _cosmosQueryFactory,
         new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration, Substitute.For <RequestContextAccessor <IFhirRequestContext> >()),
         NullLogger <CosmosFhirDataStore> .Instance,
         Options.Create(new CoreFeatureConfiguration()),
         new Lazy <ISupportedSearchParameterDefinitionManager>(Substitute.For <ISupportedSearchParameterDefinitionManager>()));
 }
コード例 #5
0
        public FhirCosmosSearchService(
            ISearchOptionsFactory searchOptionsFactory,
            CosmosFhirDataStore fhirDataStore,
            IQueryBuilder queryBuilder,
            IBundleFactory bundleFactory,
            IModelInfoProvider modelInfoProvider)
            : base(searchOptionsFactory, bundleFactory, fhirDataStore, modelInfoProvider)
        {
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));
            EnsureArg.IsNotNull(queryBuilder, nameof(queryBuilder));

            _fhirDataStore = fhirDataStore;
            _queryBuilder  = queryBuilder;
        }
コード例 #6
0
        public FhirCosmosSearchService(
            ISearchOptionsFactory searchOptionsFactory,
            CosmosFhirDataStore fhirDataStore,
            IQueryBuilder queryBuilder,
            ISearchParameterDefinitionManager searchParameterDefinitionManager,
            IFhirRequestContextAccessor requestContextAccessor)
            : base(searchOptionsFactory, fhirDataStore)
        {
            EnsureArg.IsNotNull(fhirDataStore, nameof(fhirDataStore));
            EnsureArg.IsNotNull(queryBuilder, nameof(queryBuilder));
            EnsureArg.IsNotNull(searchParameterDefinitionManager, nameof(searchParameterDefinitionManager));
            EnsureArg.IsNotNull(requestContextAccessor, nameof(requestContextAccessor));

            _fhirDataStore               = fhirDataStore;
            _queryBuilder                = queryBuilder;
            _requestContextAccessor      = requestContextAccessor;
            _resourceTypeSearchParameter = searchParameterDefinitionManager.GetSearchParameter(KnownResourceTypes.Resource, SearchParameterNames.ResourceType);
        }
コード例 #7
0
        public CosmosFhirDataStoreTests()
        {
            _container          = Substitute.For <Container>().CreateMockScope();
            _cosmosQueryFactory = Substitute.For <ICosmosQueryFactory>();
            var fhirRequestContext = Substitute.For <IFhirRequestContext>();

            fhirRequestContext.ExecutingBatchOrTransaction.Returns(true);
            var requestContextAccessor = Substitute.For <RequestContextAccessor <IFhirRequestContext> >();

            requestContextAccessor.RequestContext.Returns(fhirRequestContext);
            _dataStore = new CosmosFhirDataStore(
                _container,
                _cosmosDataStoreConfiguration,
                Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >(),
                _cosmosQueryFactory,
                new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration, requestContextAccessor),
                NullLogger <CosmosFhirDataStore> .Instance,
                Options.Create(new CoreFeatureConfiguration()),
                new Lazy <ISupportedSearchParameterDefinitionManager>(Substitute.For <ISupportedSearchParameterDefinitionManager>()));
        }
コード例 #8
0
        public async Task InitializeAsync()
        {
            var fhirStoredProcs = typeof(IStoredProcedure).Assembly
                                  .GetTypes()
                                  .Where(x => !x.IsAbstract && typeof(IStoredProcedure).IsAssignableFrom(x))
                                  .ToArray()
                                  .Select(type => (IStoredProcedure)Activator.CreateInstance(type));

            var optionsMonitor = Substitute.For <IOptionsMonitor <CosmosCollectionConfiguration> >();

            optionsMonitor.Get(CosmosDb.Constants.CollectionConfigurationName).Returns(_cosmosCollectionConfiguration);

            _fhirRequestContextAccessor.RequestContext.CorrelationId.Returns(Guid.NewGuid().ToString());
            _fhirRequestContextAccessor.RequestContext.RouteName.Returns("routeName");

            _searchParameterDefinitionManager = new SearchParameterDefinitionManager(ModelInfoProvider.Instance, _mediator, () => _searchService.CreateMockScope(), NullLogger <SearchParameterDefinitionManager> .Instance);
            await _searchParameterDefinitionManager.StartAsync(CancellationToken.None);

            _supportedSearchParameterDefinitionManager = new SupportedSearchParameterDefinitionManager(_searchParameterDefinitionManager);
            var searchableSearchParameterDefinitionManager = new SearchableSearchParameterDefinitionManager(_searchParameterDefinitionManager, _fhirRequestContextAccessor);

            _filebasedSearchParameterStatusDataStore = new FilebasedSearchParameterStatusDataStore(_searchParameterDefinitionManager, ModelInfoProvider.Instance);

            IMediator mediator = Substitute.For <IMediator>();

            var updaters = new ICollectionUpdater[]
            {
                new FhirCollectionSettingsUpdater(_cosmosDataStoreConfiguration, optionsMonitor, NullLogger <FhirCollectionSettingsUpdater> .Instance),
                new StoredProcedureInstaller(fhirStoredProcs),
                new CosmosDbSearchParameterStatusInitializer(
                    () => _filebasedSearchParameterStatusDataStore,
                    new CosmosQueryFactory(
                        new CosmosResponseProcessor(_fhirRequestContextAccessor, mediator, Substitute.For <ICosmosQueryLogger>(), NullLogger <CosmosResponseProcessor> .Instance),
                        NullFhirCosmosQueryLogger.Instance),
                    _cosmosDataStoreConfiguration),
            };

            var dbLock = new CosmosDbDistributedLockFactory(Substitute.For <Func <IScoped <Container> > >(), NullLogger <CosmosDbDistributedLock> .Instance);

            var upgradeManager = new CollectionUpgradeManager(updaters, _cosmosDataStoreConfiguration, optionsMonitor, dbLock, NullLogger <CollectionUpgradeManager> .Instance);
            ICosmosClientTestProvider testProvider = new CosmosClientReadWriteTestProvider();

            var cosmosResponseProcessor = Substitute.For <ICosmosResponseProcessor>();

            var responseProcessor           = new CosmosResponseProcessor(_fhirRequestContextAccessor, mediator, Substitute.For <ICosmosQueryLogger>(), NullLogger <CosmosResponseProcessor> .Instance);
            var handler                     = new FhirCosmosResponseHandler(() => new NonDisposingScope(_container), _cosmosDataStoreConfiguration, _fhirRequestContextAccessor, responseProcessor);
            var retryExceptionPolicyFactory = new RetryExceptionPolicyFactory(_cosmosDataStoreConfiguration, _fhirRequestContextAccessor);
            var documentClientInitializer   = new FhirCosmosClientInitializer(testProvider, () => new[] { handler }, retryExceptionPolicyFactory, NullLogger <FhirCosmosClientInitializer> .Instance);

            _cosmosClient = documentClientInitializer.CreateCosmosClient(_cosmosDataStoreConfiguration);
            var fhirCollectionInitializer = new CollectionInitializer(_cosmosCollectionConfiguration, _cosmosDataStoreConfiguration, upgradeManager, retryExceptionPolicyFactory, testProvider, NullLogger <CollectionInitializer> .Instance);

            // Cosmos DB emulators throws errors when multiple collections are initialized concurrently.
            // Use the semaphore to only allow one initialization at a time.
            await CollectionInitializationSemaphore.WaitAsync();

            try
            {
                await documentClientInitializer.InitializeDataStore(_cosmosClient, _cosmosDataStoreConfiguration, new List <ICollectionInitializer> {
                    fhirCollectionInitializer
                });

                _container = documentClientInitializer.CreateFhirContainer(_cosmosClient, _cosmosDataStoreConfiguration.DatabaseId, _cosmosCollectionConfiguration.CollectionId);
            }
            finally
            {
                CollectionInitializationSemaphore.Release();
            }

            var cosmosDocumentQueryFactory = new CosmosQueryFactory(cosmosResponseProcessor, NullFhirCosmosQueryLogger.Instance);

            var documentClient = new NonDisposingScope(_container);

            _searchParameterStatusDataStore = new CosmosDbSearchParameterStatusDataStore(
                () => documentClient,
                _cosmosDataStoreConfiguration,
                cosmosDocumentQueryFactory);

            IOptions <CoreFeatureConfiguration> options = Options.Create(new CoreFeatureConfiguration());

            _fhirDataStore = new CosmosFhirDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                cosmosDocumentQueryFactory,
                retryExceptionPolicyFactory,
                NullLogger <CosmosFhirDataStore> .Instance,
                options,
                new Lazy <ISupportedSearchParameterDefinitionManager>(_supportedSearchParameterDefinitionManager),
                ModelInfoProvider.Instance);

            _fhirOperationDataStore = new CosmosFhirOperationDataStore(
                documentClient,
                _cosmosDataStoreConfiguration,
                optionsMonitor,
                retryExceptionPolicyFactory,
                new CosmosQueryFactory(responseProcessor, new NullFhirCosmosQueryLogger()),
                NullLogger <CosmosFhirOperationDataStore> .Instance);

            var searchParameterExpressionParser = new SearchParameterExpressionParser(new ReferenceSearchValueParser(_fhirRequestContextAccessor));
            var expressionParser     = new ExpressionParser(() => searchableSearchParameterDefinitionManager, searchParameterExpressionParser);
            var searchOptionsFactory = new SearchOptionsFactory(expressionParser, () => searchableSearchParameterDefinitionManager, options, _fhirRequestContextAccessor, Substitute.For <ISortingValidator>(), NullLogger <SearchOptionsFactory> .Instance);

            ICosmosDbCollectionPhysicalPartitionInfo cosmosDbPhysicalPartitionInfo = Substitute.For <ICosmosDbCollectionPhysicalPartitionInfo>();

            cosmosDbPhysicalPartitionInfo.PhysicalPartitionCount.Returns(1);

            _searchService = new FhirCosmosSearchService(
                searchOptionsFactory,
                _fhirDataStore,
                new QueryBuilder(),
                _fhirRequestContextAccessor,
                _cosmosDataStoreConfiguration,
                cosmosDbPhysicalPartitionInfo,
                new QueryPartitionStatisticsCache(),
                Enumerable.Empty <ICosmosExpressionRewriter>(),
                NullLogger <FhirCosmosSearchService> .Instance);

            await _searchParameterDefinitionManager.EnsureInitializedAsync(CancellationToken.None);

            ISearchParameterSupportResolver searchParameterSupportResolver = Substitute.For <ISearchParameterSupportResolver>();

            searchParameterSupportResolver.IsSearchParameterSupported(Arg.Any <SearchParameterInfo>()).Returns((true, false));

            _searchParameterStatusManager = new SearchParameterStatusManager(
                _searchParameterStatusDataStore,
                _searchParameterDefinitionManager,
                searchParameterSupportResolver,
                mediator,
                NullLogger <SearchParameterStatusManager> .Instance);

            _fhirStorageTestHelper = new CosmosDbFhirStorageTestHelper(_container);
        }