Skip to content

Commit

Permalink
Unit test updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tippmar-nr committed Jul 17, 2024
1 parent 6eb3026 commit 8e5560b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public override void AddMetricStats(Segment segment, TimeSpan durationOfChildren

public override void SetSpanTypeSpecificAttributes(SpanAttributeValueCollection attribVals)
{
base.SetSpanTypeSpecificAttributes(attribVals);

AttribDefs.MessagingSystemName.TrySetValue(attribVals, MessagingSystemName);
AttribDefs.MessagingDesignationName.TrySetValue(attribVals, Destination);
AttribDefs.CloudRegion.TrySetValue(attribVals, CloudRegion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class MessageBrokerSegmentDataTests
[Test]
public void IsCombinableWith_ReturnsTrue_ForIdenticalSegments()
{
var segment1 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true);
var segment2 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true);
var segment1 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true, "messagingSystem", "cloudAccountId", "cloudRegion");
var segment2 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true, "messagingSystem", "cloudAccountId", "cloudRegion");

Assert.That(segment1.IsCombinableWith(segment2), Is.True);
}
Expand Down Expand Up @@ -110,6 +110,34 @@ public void IsCombinableWith_ReturnsFalse_IfDifferentAction()
Assert.That(segment1.IsCombinableWith(segment2), Is.False);
}

[Test]
public void IsCombinableWith_ReturnsFalse_IfDifferentMessagingSystem()
{
var segment1 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true, "messagingSystem1");
var segment2 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Produce, true, "messagingSystem2");

Assert.That(segment1.IsCombinableWith(segment2), Is.False);
}

[Test]
public void IsCombinableWith_ReturnsFalse_IfDifferentCloudAccountId()
{
var segment1 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true, cloudAccountId:"cloudAccountId1");
var segment2 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Produce, true, cloudAccountId:"cloudAccountId2");

Assert.That(segment1.IsCombinableWith(segment2), Is.False);
}

[Test]
public void IsCombinableWith_ReturnsFalse_IfDifferentCloudRegion()
{
var segment1 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Consume, true, cloudRegion:"cloudRegion1");
var segment2 = MessageBrokerSegmentDataTestHelpers.CreateMessageBrokerSegmentBuilder(new TimeSpan(), TimeSpan.FromSeconds(2), 2, 1, new MethodCallData("type", "method", 1), Enumerable.Empty<KeyValuePair<string, object>>(), "vendor1", "queueA", MetricNames.MessageBrokerDestinationType.Queue, MetricNames.MessageBrokerAction.Produce, true, cloudRegion:"cloudRegion2");

Assert.That(segment1.IsCombinableWith(segment2), Is.False);
}


#endregion IsCombinableWith

#region CreateSimilar
Expand Down Expand Up @@ -152,13 +180,14 @@ public void CreateSimilar_ReturnsCorrectValues()

public static class MessageBrokerSegmentDataTestHelpers
{
public static Segment CreateMessageBrokerSegmentBuilder(TimeSpan start, TimeSpan duration, int uniqueId, int? parentId, MethodCallData methodCallData, IEnumerable<KeyValuePair<string, object>> enumerable, string vendor, string queue, MetricNames.MessageBrokerDestinationType type, MetricNames.MessageBrokerAction action, bool combinable)
public static Segment CreateMessageBrokerSegmentBuilder(TimeSpan start, TimeSpan duration, int uniqueId, int? parentId, MethodCallData methodCallData, IEnumerable<KeyValuePair<string, object>> parameters, string vendor, string destination, MetricNames.MessageBrokerDestinationType destinationType, MetricNames.MessageBrokerAction action, bool combinable, string messagingSystemName = null, string cloudAccountId = null, string cloudRegion = null)
{
var segment = new Segment(SimpleSegmentDataTestHelpers.CreateTransactionSegmentState(uniqueId, parentId), methodCallData);
segment.SetSegmentData(new MessageBrokerSegmentData(vendor, queue, type, action));
var messageBrokerSegmentData = new MessageBrokerSegmentData(vendor, destination, destinationType, action, messagingSystemName, cloudAccountId, cloudRegion);
segment.SetSegmentData(messageBrokerSegmentData);
segment.Combinable = combinable;

return new Segment(start, duration, segment, null);
return new Segment(start, duration, segment, parameters);
}
}
}

0 comments on commit 8e5560b

Please sign in to comment.