public async Task Setup()
 {
     HypermediaProcessor = new Mock <IHypermediaProcessor>(MockBehavior.Strict);
     HypermediaProcessor.Setup(_ => _.Supports(It.IsAny <IResponse>()))
     .Returns <IResponse>(_ => _.Headers["Content-Type"].Contains("application/ld+json") ? Level.FullSupport : Level.None);
     IriTemplateExpansionStrategy = new Mock <IIriTemplateExpansionStrategy>(MockBehavior.Strict);
     HttpCall = new Mock <IHttpInfrastructure>(MockBehavior.Strict);
     HttpCall.Setup(_ => _.HttpCall(It.IsAny <Uri>(), It.IsAny <IHttpOptions>(), It.IsAny <CancellationToken>()))
     .ReturnsAsync(Return.Ok());
     Client = new HydraClient(
         new[] { HypermediaProcessor.Object },
         IriTemplateExpansionStrategy.Object,
         LinksPolicy.Strict,
         HttpCall.Object.HttpCall);
     ScenarioSetup();
     await TheTest();
 }
        // request function, thread function
        private void SendRequestThreadEntry()
        {
            Logger.LogInfo(LogId, "HydraBenchmark", "Start send request thread");
            //IHydraClient client = new HydraClient("HydraBenchmark.ini");
            IHydraClient client = new HydraClient(Path.Combine(workingDir, "HydraClientExampleManaged.ini"), Path.Combine(workingDir, "HydraCluster.ini"));

            while (true)
            {
                HydraPutRequest putRequest = this.reqStream.GetOne();

                while (!this.outgoingRequestPool.WaitOne(30000))
                {
                    Logger.LogWarning(LogId, "HydraBenchmark", "Max outgoing in 30 seconds!");
                }
                DateTime sentTime = DateTime.Now;

                AsyncCallback callback = ar =>
                {
                    this.outgoingRequestPool.Release();
                    HydraPutResponse putResponse = client.EndPut(ar);
                    this.latencyCounter.Set((Int64)(DateTime.Now - sentTime).TotalMilliseconds);
                    IncreaseResponseAnalyser(putResponse.hydraResponseCode).Increment();
                };

                try
                {
                    client.BeginPut(putRequest, callback, null);
                    this.sendCounter.Increment();
                }
                catch (Exception e)
                {
                    try
                    {
                        this.outgoingRequestPool.Release();//here has some bugs, but I don't know why, so I just catch it.
                        this.failSendCounter.Increment();
                    }
                    catch { }
                    Logger.LogError(LogId, "HydraBenchmark", "BeginPut with exception: {0}", e);
                }
            }
        }
        // request function, thread function
        private void SendRequestThreadEntry()
        {
            Logger.LogInfo(LogId, "HydraBenchmark", "Start send request thread");
            //IHydraClient client = new HydraClient("HydraBenchmark.ini");
            IHydraClient client = new HydraClient(Path.Combine(workingDir, "HydraClientExampleManaged.ini"), Path.Combine(workingDir, "HydraCluster.ini"));
            while (true)
            {
                HydraPutRequest putRequest = this.reqStream.GetOne();

                while (!this.outgoingRequestPool.WaitOne(30000))
                {
                    Logger.LogWarning(LogId, "HydraBenchmark", "Max outgoing in 30 seconds!");
                }
                DateTime sentTime = DateTime.Now;

                AsyncCallback callback = ar =>
                {
                    this.outgoingRequestPool.Release();
                    HydraPutResponse putResponse = client.EndPut(ar);
                    this.latencyCounter.Set((Int64)(DateTime.Now - sentTime).TotalMilliseconds);
                    IncreaseResponseAnalyser(putResponse.hydraResponseCode).Increment();
                };

                try
                {
                    client.BeginPut(putRequest, callback, null);
                    this.sendCounter.Increment();
                }
                catch (Exception e)
                {
                    try
                    {
                        this.outgoingRequestPool.Release();//here has some bugs, but I don't know why, so I just catch it.
                        this.failSendCounter.Increment();
                    }
                    catch { }
                    Logger.LogError(LogId, "HydraBenchmark", "BeginPut with exception: {0}", e);
                }
            }
        }