public async Task Create_WithDBSharedRUSetting_WithCollectionRUvalue_CollectionOfferAndNoDbOffer() { // Arrange var tempCollectionName = Guid.NewGuid().ToString(); var tempDbName = Guid.NewGuid().ToString(); var collectionUri = UriFactory.CreateDocumentCollectionUri(tempDbName, tempCollectionName); var databaseUri = UriFactory.CreateDatabaseUri(tempDbName); var dbOfferThroughput = 600; var cosmosCacheFactorySettings = new CosmosCacheFactorySettings { UseKeyAsPartitionKey = true, NewCollectionDefaultDTU = 500 //just so its different than default }; using (var factory = new CosmosCacheFactory(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey, tempDbName, cosmosCacheFactorySettings)) using (var client = new DocumentClient(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey)) { // Act await client.CreateDatabaseAsync(new Database { Id = tempDbName }, new RequestOptions { OfferThroughput = dbOfferThroughput //non-default }); //ensure temp collection is created factory.Create <SimpleObject>(tempCollectionName); Resource collectionResource = await client.ReadDocumentCollectionAsync(collectionUri); Resource databaseResource = await client.ReadDatabaseAsync(databaseUri); var collectionOffer = GetOffer(collectionResource, client); var collectionOfferResource = await client.ReadOfferAsync(collectionOffer.SelfLink); var collectionOfferContent = collectionOfferResource.Resource.GetPropertyValue <OfferContentV2>("content"); var databaseOffer = GetOffer(databaseResource, client); var dbOfferResource = await client.ReadOfferAsync(databaseOffer.SelfLink); var dbOfferContent = dbOfferResource.Resource.GetPropertyValue <OfferContentV2>("content"); // Assert Assert.Equal(cosmosCacheFactorySettings.NewCollectionDefaultDTU, collectionOfferContent.OfferThroughput); Assert.Equal(dbOfferThroughput, dbOfferContent.OfferThroughput); // Cleanup await factory.DocumentClient.DeleteDocumentCollectionAsync(collectionUri); await factory.DocumentClient.DeleteDatabaseAsync(databaseUri); } }
public void Create_WithMultiRegionReadWrite_DocumentClientHasTheRightSettings() { // Arrange string currentRegion = "West Europe"; var settings = new CosmosCacheFactorySettings { MultiRegionReadWrite = true, CurrentRegion = currentRegion }; using (var factory = new CosmosCacheFactory(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey, LocalClusterCosmosDb.DbName, settings)) { Assert.True(factory.DocumentClient.ConnectionPolicy.UseMultipleWriteLocations); Assert.NotEmpty(factory.DocumentClient.ConnectionPolicy.PreferredLocations); Assert.Equal(currentRegion, factory.DocumentClient.ConnectionPolicy.PreferredLocations.First()); } }
public async Task Create_WithCustomIndexingPolicySettingsForCollection_NewCollectionIsCreated() { // Arrange var tempCollectionName = Guid.NewGuid().ToString(); var settings = new CosmosCacheFactorySettings { IndexingSettings = new CosmosCacheFactoryIndexingSettings { ExcludedPaths = new[] { "/*" }, IncludedPaths = new[] { $"/{nameof(SimpleObject.Foo)}/?", $"/{nameof(SimpleObject.Value)}/?" } } }; var collectionUri = UriFactory.CreateDocumentCollectionUri(LocalClusterCosmosDb.DbName, tempCollectionName); using (var factory = new CosmosCacheFactory(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey, LocalClusterCosmosDb.DbName, settings)) using (var client = new DocumentClient(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey)) { // Act factory.Create <SimpleObject>(tempCollectionName); // Assert var actualIndexingPolicy = (await client.ReadDocumentCollectionAsync(collectionUri)) .Resource.IndexingPolicy; // _etag is excluded by default var excludedPaths = actualIndexingPolicy.ExcludedPaths.Where(x => x.Path != "/\"_etag\"/?").ToArray(); Assert.Single(excludedPaths); Assert.Contains(actualIndexingPolicy.ExcludedPaths, x => x.Path == "/*"); Assert.Equal(2, actualIndexingPolicy.IncludedPaths.Count); Assert.Contains(actualIndexingPolicy.IncludedPaths, x => x.Path == "/Foo/?"); Assert.Contains(actualIndexingPolicy.IncludedPaths, x => x.Path == "/Value/?"); // Cleanup await factory.DocumentClient.DeleteDocumentCollectionAsync(collectionUri); } }
public async Task Create_WithDBSharedRUSetting_WithoutCollectionRUvalue_CollectionOfferSetToDefaultRUsAndNoDbOffer() { // Arrange var tempCollectionName = Guid.NewGuid().ToString(); var collectionUri = UriFactory.CreateDocumentCollectionUri(LocalClusterCosmosDb.DbName, tempCollectionName); var databaseUri = UriFactory.CreateDatabaseUri(LocalClusterCosmosDb.DbName); var cosmosCacheFactorySettings = new CosmosCacheFactorySettings { UseKeyAsPartitionKey = true, UseDatabaseSharedThroughput = true }; using (var factory = new CosmosCacheFactory(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey, LocalClusterCosmosDb.DbName, cosmosCacheFactorySettings)) using (var client = new DocumentClient(LocalClusterCosmosDb.ConnectionURI, LocalClusterCosmosDb.AccessKey)) { //ensure temp collection is created factory.Create <SimpleObject>(tempCollectionName); Resource collectionResource = await client.ReadDocumentCollectionAsync(collectionUri); Resource databaseResource = await client.ReadDatabaseAsync(databaseUri); var collectionOffer = GetOffer(collectionResource, client); var collectionOfferResource = await client.ReadOfferAsync(collectionOffer.SelfLink); var collectionOfferContent = collectionOfferResource.Resource.GetPropertyValue <OfferContentV2>("content"); var databaseOffer = GetOffer(databaseResource, client); // Assert Assert.Null(databaseOffer); Assert.Equal(400, collectionOfferContent.OfferThroughput); // Cleanup await factory.DocumentClient.DeleteDocumentCollectionAsync(collectionUri); } }