示例#1
0
        private async Task CompareReplication()
        {
            await client.OpenAsync().ConfigureAwait(false);

            var random = new Random((int)DateTime.Now.Ticks);
            var doc    = new SampleDocument
            {
                prop1  = Guid.NewGuid().ToString(),
                prop2  = random.Next(100),
                prop3  = Guid.NewGuid().ToString(),
                prop4  = random.Next(100),
                prop5  = DateTime.UtcNow.ToLongTimeString(),
                prop6  = random.Next(100),
                prop7  = Guid.NewGuid().ToString(),
                prop8  = random.Next(100),
                prop9  = Guid.NewGuid().ToString(),
                prop10 = random.Next(100),
                prop11 = Guid.NewGuid().ToString(),
                prop12 = random.Next(100),
                prop13 = Guid.NewGuid().ToString(),
                prop14 = random.Next(100),
                prop15 = Guid.NewGuid().ToString(),
                prop16 = random.Next(100)
            };

            //doc.Id = Guid.NewGuid().ToString();
            //var strongWriteResults = await this.CreateSampleDocument(database, collection, doc, ConsistencyLevel.Strong);
            doc.Id = Guid.NewGuid().ToString();
            var sessionWriteResults = await this.CreateSampleDocument(database, collection, doc, ConsistencyLevel.Session);

            doc.Id = Guid.NewGuid().ToString();
            var eventualWriteResults = await this.CreateSampleDocument(database, collection, doc, ConsistencyLevel.Eventual);

            doc.Id = Guid.NewGuid().ToString();
            var boundedWriteResults = await this.CreateSampleDocument(database, collection, doc, ConsistencyLevel.BoundedStaleness);

            //var strongReadResults = await this.ReadSampleDocument(strongWriteResults.Resource.Id, ConsistencyLevel.Strong);
            var sessionReadResults = await this.ReadSampleDocument(sessionWriteResults.Resource.Id, ConsistencyLevel.Session);

            var eventualReadResults = await this.ReadSampleDocument(eventualWriteResults.Resource.Id, ConsistencyLevel.Eventual);

            var boundedReadResults = await this.ReadSampleDocument(boundedWriteResults.Resource.Id, ConsistencyLevel.BoundedStaleness);

            //PrintDetails(strongWriteResults, "Strong write");
            PrintDetails(sessionWriteResults, "Session write");
            PrintDetails(eventualWriteResults, "Eventual write");
            PrintDetails(boundedWriteResults, "Bounded write");

            //PrintDetails(strongReadResults, "Strong read");
            PrintDetails(sessionReadResults, "Session read");
            PrintDetails(eventualReadResults, "Eventual read");
            PrintDetails(boundedReadResults, "Bounded read");
        }
示例#2
0
        private async Task <ResourceResponse <Document> > CreateSampleDocument(string databaseName, string collectionName, SampleDocument sample, ConsistencyLevel level)
        {
            var options = new RequestOptions()
            {
                ConsistencyLevel = level
            };

            var result = await client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri(databaseName, collectionName), sample, options);

            return(result);
        }