示例#1
0
        private async Task CreateLargeItemStreamWithBulk(int appxItemSize)
        {
            List <Task <ResponseMessage> > tasks = new List <Task <ResponseMessage> >();

            for (int i = 0; i < 3; i++)
            {
                ToDoActivity item = CosmosItemBulkTests.CreateItem(i.ToString());

                if (i == 1)
                {
                    item.description = new string('x', appxItemSize);
                }
                tasks.Add(CosmosItemBulkTests.ExecuteCreateStreamAsync(this.container, item));
            }

            await Task.WhenAll(tasks);

            for (int i = 0; i < 3; i++)
            {
                Task <ResponseMessage> task   = tasks[i];
                ResponseMessage        result = await task;
                if (i == 0 || i == 2)
                {
                    Assert.IsTrue(result.Headers.RequestCharge > 0);
                    Assert.IsNotNull(result.Headers.Session);
                    Assert.IsNotNull(result.Headers.ActivityId);
                    Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
                    Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
                }
                else
                {
                    Assert.AreEqual(HttpStatusCode.RequestEntityTooLarge, result.StatusCode);
                }
            }
        }
示例#2
0
        public async Task ValidateRequestOptions()
        {
            async Task ExecuteAndValidateCreateItemAsync(int i)
            {
                try
                {
                    await CosmosItemBulkTests.ExecuteCreateStreamAsync(
                        this.container,
                        CosmosItemBulkTests.CreateItem(i.ToString()),
                        new ItemRequestOptions()
                    {
                        Properties = new Dictionary <string, object>()
                        {
                            { "test", "test" }
                        },
                        DedicatedGatewayRequestOptions = new DedicatedGatewayRequestOptions {
                            MaxIntegratedCacheStaleness = TimeSpan.FromMinutes(3)
                        },
                        SessionToken = Guid.NewGuid().ToString(),
                        PreTriggers  = new List <string>()
                        {
                            "preTrigger"
                        },
                        PostTriggers = new List <string>()
                        {
                            "postTrigger"
                        }
                    });

                    Assert.Fail("Request should have failed");
                }
                catch (InvalidOperationException)
                {
                }
            }

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(ExecuteAndValidateCreateItemAsync(i));
            }

            await Task.WhenAll(tasks);
        }
示例#3
0
        public async Task PatchItem_WithBulk()
        {
            List <ToDoActivity> createdDocuments = new List <ToDoActivity>();
            // Create the items
            List <Task <ItemResponse <ToDoActivity> > > tasks = new List <Task <ItemResponse <ToDoActivity> > >();

            for (int i = 0; i < 100; i++)
            {
                ToDoActivity createdDocument = CosmosItemBulkTests.CreateItem(i.ToString());
                createdDocuments.Add(createdDocument);
                tasks.Add(CosmosItemBulkTests.ExecuteCreateAsync(this.container, createdDocument));
            }

            await Task.WhenAll(tasks);

            List <PatchOperation> patch = new List <PatchOperation>()
            {
                PatchOperation.Add("/description", "patched")
            };
            List <Task <ItemResponse <ToDoActivity> > > patchTasks = new List <Task <ItemResponse <ToDoActivity> > >();

            // Patch the items
            foreach (ToDoActivity createdDocument in createdDocuments)
            {
                patchTasks.Add(CosmosItemBulkTests.ExecutePatchAsync((ContainerInternal)this.container, createdDocument, patch));
            }

            await Task.WhenAll(patchTasks);

            for (int i = 0; i < 100; i++)
            {
                Task <ItemResponse <ToDoActivity> > task   = patchTasks[i];
                ItemResponse <ToDoActivity>         result = await task;
                Assert.IsTrue(result.Headers.RequestCharge > 0);
                Assert.IsNotNull(result.Headers.Session);
                Assert.IsNotNull(result.Headers.ActivityId);
                Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
                Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
                Assert.AreEqual("patched", result.Resource.description);
            }
        }
示例#4
0
        public async Task UpsertItem_WithBulk()
        {
            List <Task <ItemResponse <ToDoActivity> > > tasks = new List <Task <ItemResponse <ToDoActivity> > >();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(CosmosItemBulkTests.ExecuteUpsertAsync(this.container, CosmosItemBulkTests.CreateItem(i.ToString())));
            }

            await Task.WhenAll(tasks);

            for (int i = 0; i < 100; i++)
            {
                Task <ItemResponse <ToDoActivity> > task   = tasks[i];
                ItemResponse <ToDoActivity>         result = await task;
                Assert.IsTrue(result.Headers.RequestCharge > 0);
                Assert.IsNotNull(result.Headers.Session);
                Assert.IsNotNull(result.Headers.ActivityId);
                Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
                Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
            }
        }
示例#5
0
        public async Task CreateItemStream_WithBulk()
        {
            List <Task <ResponseMessage> > tasks = new List <Task <ResponseMessage> >();

            for (int i = 0; i < 100; i++)
            {
                tasks.Add(CosmosItemBulkTests.ExecuteCreateStreamAsync(this.container, CosmosItemBulkTests.CreateItem(i.ToString())));
            }

            await Task.WhenAll(tasks);

            for (int i = 0; i < 100; i++)
            {
                Task <ResponseMessage> task   = tasks[i];
                ResponseMessage        result = await task;
                Assert.AreEqual(HttpStatusCode.Created, result.StatusCode);
                Assert.IsTrue(result.Headers.RequestCharge > 0);
                Assert.IsNotNull(result.Headers.Session);
                Assert.IsNotNull(result.Headers.ActivityId);
                Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
                ToDoActivity document = TestCommon.SerializerCore.FromStream <ToDoActivity>(result.Content);
                Assert.AreEqual(i.ToString(), document.id);
            }
        }
示例#6
0
        public async Task ReplaceItem_WithBulk()
        {
            List <ToDoActivity> createdDocuments = new List <ToDoActivity>();
            // Create the items
            List <Task <ItemResponse <ToDoActivity> > > tasks = new List <Task <ItemResponse <ToDoActivity> > >();

            for (int i = 0; i < 100; i++)
            {
                ToDoActivity createdDocument = CosmosItemBulkTests.CreateItem(i.ToString());
                createdDocuments.Add(createdDocument);
                tasks.Add(CosmosItemBulkTests.ExecuteCreateAsync(this.container, createdDocument));
            }

            await Task.WhenAll(tasks);

            List <Task <ItemResponse <ToDoActivity> > > replaceTasks = new List <Task <ItemResponse <ToDoActivity> > >();

            // Replace the items
            foreach (ToDoActivity createdDocument in createdDocuments)
            {
                replaceTasks.Add(CosmosItemBulkTests.ExecuteReplaceAsync(this.container, createdDocument));
            }

            await Task.WhenAll(replaceTasks);

            for (int i = 0; i < 100; i++)
            {
                Task <ItemResponse <ToDoActivity> > task   = replaceTasks[i];
                ItemResponse <ToDoActivity>         result = await task;
                Assert.IsTrue(result.Headers.RequestCharge > 0);
                Assert.IsNotNull(result.Headers.Session);
                Assert.IsNotNull(result.Headers.ActivityId);
                Assert.IsFalse(string.IsNullOrEmpty(result.Diagnostics.ToString()));
                Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            }
        }