public void HttpEventCollectorSenderMetadataOverrideTest()
        {
            Func <String, List <HttpEventCollectorEventInfo>, Response> noopHandler = (token, events) =>
            {
                return(new Response());
            };

            HttpEventCollectorEventInfo.Metadata defaultmetadata = new HttpEventCollectorEventInfo.Metadata(index: "defaulttestindex",
                                                                                                            source: "defaulttestsource", sourceType: "defaulttestsourcetype", host: "defaulttesthost");

            HttpEventCollectorEventInfo.Metadata overridemetadata = new HttpEventCollectorEventInfo.Metadata(index: "overridetestindex",
                                                                                                             source: "overridetestsource", sourceType: "overridetestsourcetype", host: "overridetesthost");

            HttpEventCollectorSender httpEventCollectorSender =
                new HttpEventCollectorSender(uri, "TOKEN-GUID",
                                             defaultmetadata,
                                             HttpEventCollectorSender.SendMode.Sequential,
                                             100000,
                                             100000,
                                             3,
                                             new HttpEventCollectorSender.HttpEventCollectorMiddleware((token, events, next) => {
                Assert.True(events.Count == 3);

                // Id = id1 should have the default meta data values.
                Assert.True(events[0].Event.Id == "id1");
                Assert.True(events[0].Index == defaultmetadata.Index);
                Assert.True(events[0].Source == defaultmetadata.Source);
                Assert.True(events[0].SourceType == defaultmetadata.SourceType);
                Assert.True(events[0].Host == defaultmetadata.Host);

                // Id = id2 should have the metadataOverride values.
                Assert.True(events[1].Event.Id == "id2");
                Assert.True(events[1].Index == overridemetadata.Index);
                Assert.True(events[1].Source == overridemetadata.Source);
                Assert.True(events[1].SourceType == overridemetadata.SourceType);
                Assert.True(events[1].Host == overridemetadata.Host);

                // Id = id3 should have the default meta data values.
                Assert.True(events[2].Event.Id == "id3");
                Assert.True(events[2].Index == defaultmetadata.Index);
                Assert.True(events[2].Source == defaultmetadata.Source);
                Assert.True(events[2].SourceType == defaultmetadata.SourceType);
                Assert.True(events[2].Host == defaultmetadata.Host);

                Response response = noopHandler(token, events);
                HttpResponseMessage httpResponseMessage = new HttpResponseMessage();
                httpResponseMessage.StatusCode          = response.Code;
                byte[] buf = Encoding.UTF8.GetBytes(response.Context);
                httpResponseMessage.Content = new StringContent(response.Context);
                var task = new Task <HttpResponseMessage>(() => {
                    return(httpResponseMessage);
                });
                task.RunSynchronously();
                return(task);
            })
                                             );

            httpEventCollectorSender.Send(id: "id1");
            httpEventCollectorSender.Send(id: "id2", metadataOverride: overridemetadata);
            httpEventCollectorSender.Send(id: "id3");

            httpEventCollectorSender.FlushSync();
            httpEventCollectorSender.Dispose();
        }
コード例 #2
0
 public void OnError(Exception error)
 {
     sender.Dispose();
 }