public void TestSimpleParallelHttpPostRequests()
{
var entity = new PerformanceEntity();
entity.Id = "1234567890123456789012345678901234";
entity.Key = "1234567";
entity.Revision = "1234567";
entity.Name = "Mohamad Abu Bakar";
entity.IcNumber = "1234567-12-3444";
entity.Department = "IT Department";
entity.Height = 1234;
entity.DateOfBirth = new DateTime(2015, 1, 27, 3, 33, 3);
entity.Salary = 3333;
var jsonEntity = JSON.ToJSON(entity);
var threadCount = 10;
var tasks = new Task[threadCount];
Stopwatch stopwatch = Stopwatch.StartNew();
for (int i = 0; i < threadCount; i++)
{
tasks[i] = Task.Factory.StartNew(() =>
{
int messages_sent_by_one_task = 0;
while(messages_sent_by_one_task < 100)
{
SimpleHttpPostCreateDocument(
"http://localhost:8529/_db/" + Database.TestDatabaseGeneral + "/_api/document?collection=" + Database.TestDocumentCollectionName,
jsonEntity
);
messages_sent_by_one_task++;
}
});
}
while (tasks.Any(t => !t.IsCompleted)) { }
Console.WriteLine("Elapsed time [s]: {0}", stopwatch.Elapsed.TotalMilliseconds / 1000);
}