private async Task <Container> CreateNonPartitionedContainerAsync( Microsoft.Azure.Cosmos.IndexingPolicy indexingPolicy = null) { string containerName = Guid.NewGuid().ToString() + "container"; await NonPartitionedContainerHelper.CreateNonPartitionedContainer( this.database, containerName, indexingPolicy == null?null : JsonConvert.SerializeObject(indexingPolicy)); return(this.database.GetContainer(containerName)); }
private async Task <ContainerResponse> CreatePartitionedContainer( int throughput, string partitionKey = "/id", Microsoft.Azure.Cosmos.IndexingPolicy indexingPolicy = null) { // Assert that database exists (race deletes are possible when used concurrently) ResponseMessage responseMessage = await this.database.ReadStreamAsync(); Assert.AreEqual(HttpStatusCode.OK, responseMessage.StatusCode); ContainerResponse containerResponse = await this.database.CreateContainerAsync( new ContainerProperties { Id = Guid.NewGuid().ToString() + "container", IndexingPolicy = indexingPolicy ?? new Cosmos.IndexingPolicy { IncludedPaths = new Collection <Cosmos.IncludedPath> { new Cosmos.IncludedPath { Path = "/*", Indexes = new Collection <Cosmos.Index> { Cosmos.Index.Range(Cosmos.DataType.Number), Cosmos.Index.Range(Cosmos.DataType.String), } } } }, PartitionKey = partitionKey == null ? null : new PartitionKeyDefinition { Paths = new Collection <string> { partitionKey }, Kind = PartitionKind.Hash } }, // This throughput needs to be about half the max with multi master // otherwise it will create about twice as many partitions. throughput); Assert.IsNotNull(containerResponse); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); Assert.IsNotNull(containerResponse.Resource); Assert.IsNotNull(containerResponse.Resource.ResourceId); return(containerResponse); }
private async Task <Container> CreateMultiPartitionContainer( string partitionKey = "/id", Microsoft.Azure.Cosmos.IndexingPolicy indexingPolicy = null) { ContainerResponse containerResponse = await this.CreatePartitionedContainer( throughput : 25000, partitionKey : partitionKey, indexingPolicy : indexingPolicy); IReadOnlyList <PartitionKeyRange> ranges = await this.GetPartitionKeyRanges(containerResponse); Assert.IsTrue( ranges.Count() > 1, $"{nameof(CreateMultiPartitionContainer)} failed to create a container with more than 1 physical partition."); return(containerResponse); }
private async Task <Container> CreateSinglePartitionContainer( string partitionKey = "/id", Microsoft.Azure.Cosmos.IndexingPolicy indexingPolicy = null) { ContainerResponse containerResponse = await this.CreatePartitionedContainer( throughput : 4000, partitionKey : partitionKey, indexingPolicy : indexingPolicy); Assert.IsNotNull(containerResponse); Assert.AreEqual(HttpStatusCode.Created, containerResponse.StatusCode); Assert.IsNotNull(containerResponse.Resource); Assert.IsNotNull(containerResponse.Resource.ResourceId); IReadOnlyList <PartitionKeyRange> ranges = await this.GetPartitionKeyRanges(containerResponse); Assert.AreEqual(1, ranges.Count()); return(containerResponse); }