Пример #1
0
            public static CurratedDocsPayload CreateFromCurratedDocs(string name)
            {
                if (name == null)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                try
                {
                    string path = $"TestJsons/{name}.json";
                    string json = TextFileConcatenation.ReadMultipartFile(path);
                    json = JsonTestUtils.RandomSampleJson(json, seed: 42, maxNumberOfItems: 100);

                    ReadOnlyMemory <byte> text   = Encoding.UTF8.GetBytes(json);
                    ReadOnlyMemory <byte> binary = JsonTestUtils.ConvertTextToBinary(json);

                    return(new CurratedDocsPayload(
                               name: name,
                               text: text,
                               binary: binary));
                }
                catch (Exception)
                {
                    // initializer can not throw exception:
                    return(default);
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ItemBenchmark"/> class.
        /// </summary>
        public EndToEnd()
        {
            if (string.IsNullOrEmpty(this.accountEndpoint) && string.IsNullOrEmpty(this.accountKey))
            {
                return;
            }

            CosmosClientBuilder clientBuilder = new CosmosClientBuilder(
                accountEndpoint: this.accountEndpoint,
                authKeyOrResourceToken: this.accountKey);

            this.client = clientBuilder.Build();
            Database          db = this.client.CreateDatabaseIfNotExistsAsync("BenchmarkDB").Result;
            ContainerResponse containerResponse = db.CreateContainerIfNotExistsAsync(
                id: "BenchmarkContainer",
                partitionKeyPath: "/id",
                throughput: 10000).Result;

            this.container = containerResponse;

            if (containerResponse.StatusCode == HttpStatusCode.Created)
            {
                string path = $"TestJsons/NutritionData.json";
                string json = TextFileConcatenation.ReadMultipartFile(path);
                json = JsonTestUtils.RandomSampleJson(json, seed: 42, maxNumberOfItems: 1000);

                CosmosArray cosmosArray = CosmosArray.Parse(json);
                foreach (CosmosElement document in cosmosArray)
                {
                    ItemResponse <CosmosElement> itemResponse = this.container.CreateItemAsync(document).Result;
                }
            }
        }
        private static string SampleJsonFromFile(string filename)
        {
            string path = string.Format("TestJsons/{0}", filename);
            string json = TextFileConcatenation.ReadMultipartFile(path);

            IEnumerable <object> documents = null;

            try
            {
                try
                {
                    documents = JsonConvert.DeserializeObject <List <object> >(json);
                }
                catch (JsonSerializationException)
                {
                    documents = new List <object>
                    {
                        JsonConvert.DeserializeObject <object>(json)
                    };
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"Failed to get JSON payload: {json.Substring(0, 128)} {ex}");
            }

            documents = documents.OrderBy(x => Guid.NewGuid()).Take(100);

            json = JsonConvert.SerializeObject(documents);
            return(json);
        }
        private void PerformanceBenchmarkCuratedJson(string path)
        {
            path = string.Format("TestJsons/{0}", path);
            string    json = TextFileConcatenation.ReadMultipartFile(path);
            const int numberOfIterations = 1;

            JsonPerfMeasurement.MeasurePerf(json, path, numberOfIterations);
        }
        // Checks to see if we can go from a JsonReader to a NewtonsoftWriter and get back the original document and visa versa
        private void RoundTripTestCuratedJson(string path)
        {
            path = string.Format("TestJsons/{0}", path);
            string json = TextFileConcatenation.ReadMultipartFile(path);

#if true
            json = JsonTestUtils.RandomSampleJson(json, seed: 42, maxNumberOfItems: 100);
#endif
            JsonRoundTripsTests.MultiSerializationRoundTrip(json);
        }
Пример #6
0
        private static void VerifyNavigatorWithCurratedDoc(string path, bool performExtraChecks = true)
        {
            path = string.Format("TestJsons/{0}", path);
            string json = TextFileConcatenation.ReadMultipartFile(path);

#if true
            json = JsonTestUtils.RandomSampleJson(json, maxNumberOfItems: 1);
#endif

            JsonNavigatorTests.VerifyNavigator(json, performExtraChecks);
        }
        private static IEnumerable <object> GetDocumentsFromCurratedDoc(string path)
        {
            path = string.Format("TestJsons/{0}", path);
            string        json = TextFileConcatenation.ReadMultipartFile(path);
            List <object> documents;

            try
            {
                documents = JsonConvert.DeserializeObject <List <object> >(json);
            }
            catch (JsonSerializationException)
            {
                documents = new List <object>();
                documents.Add(JsonConvert.DeserializeObject <object>(json));
            }

            return(documents);
        }
Пример #8
0
            public static CurratedDocsPayload CreateFromCurratedDocs(string name)
            {
                if (name == null)
                {
                    throw new ArgumentNullException(nameof(name));
                }

                string path = $"TestJsons/{name}.json";
                string json = TextFileConcatenation.ReadMultipartFile(path);

                json = JsonTestUtils.RandomSampleJson(json, seed: 42, maxNumberOfItems: 50);

                ReadOnlyMemory <byte>     text          = Encoding.UTF8.GetBytes(json);
                ReadOnlyMemory <byte>     binary        = JsonTestUtils.ConvertTextToBinary(json);
                IReadOnlyList <JsonToken> tokensToWrite = Utils.Tokenize(text);

                return(new CurratedDocsPayload(
                           text: text,
                           binary: binary,
                           tokensToWrite: tokensToWrite));
            }
        private static ReadOnlyMemory <byte> GetPayload(string filename)
        {
            string path = string.Format("TestJsons/{0}", filename);
            string json = TextFileConcatenation.ReadMultipartFile(path);

            IEnumerable <object> documents = null;

            try
            {
                try
                {
                    documents = JsonConvert.DeserializeObject <List <object> >(json);
                }
                catch (JsonSerializationException)
                {
                    documents = new List <object>
                    {
                        JsonConvert.DeserializeObject <object>(json)
                    };
                }
            }
            catch (Exception ex)
            {
                Assert.Fail($"Failed to get JSON payload: {json.Substring(0, 128)} {ex}");
            }

            documents = documents.OrderBy(x => Guid.NewGuid()).Take(100);

            json = JsonConvert.SerializeObject(documents);

            IJsonReader jsonReader = Microsoft.Azure.Cosmos.Json.JsonReader.Create(Encoding.UTF8.GetBytes(json));
            IJsonWriter jsonWriter = Microsoft.Azure.Cosmos.Json.JsonWriter.Create(JsonSerializationFormat.Binary);

            jsonWriter.WriteAll(jsonReader);
            return(jsonWriter.GetResult());
        }