Skip to content

Commit 7b529dc

Browse files
committed
Established basic test for evaluating thresholds on TopicMappingService
This unit test and its corresponding `LoadTestingViewModel` allows a variable number of attributes to be set on a `Topic` which correspond to upwards of 20 properties on the `LoadTestingViewModel`. The number of properties to be mapped and the number of times to map the `Topic` are both variables to be set. These allow us to help identify and optimize the threshold to be used in the `TopicMappingService` for when to utilize the `AttributeDictionary`.
1 parent 3ecfa06 commit 7b529dc

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

OnTopic.Tests/TopicMappingServiceTest.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,59 @@ public TopicMappingServiceTest(TopicInfrastructureFixture<StubTopicRepository> f
6464

6565
}
6666

67+
/*==========================================================================================================================
68+
| TEST: MAP: LOAD TESTING: EVALUATE THRESHOLD
69+
\-------------------------------------------------------------------------------------------------------------------------*/
70+
/// <summary>
71+
/// Establishes a <see cref="TopicMappingService"/> and tests creating and mapping <see cref="Topic"/> instances in bulk,
72+
/// as a quick-and-easy way of assessing performance.
73+
/// </summary>
74+
/// <remarks>
75+
/// <para>
76+
/// The <see cref="TopicMappingService"/> includes functionality to map properties to attributes via a constructor that
77+
/// accepts a <see cref="AttributeDictionary"/>. This introduces some overhead which is not cost effective if there are
78+
/// not any attributes that map to properties. For larger numbers of mapped attributes, however, the <see cref="
79+
/// AttributeDictionary"/> can reduce the mapping time considerably, while also giving more control over the model
80+
/// construction to the model developer. This test is intended to help identify and optimize that threshold based on
81+
/// improvements to the underlying <see cref="AttributeDictionary"/>, <see cref="TopicMappingService.MapAsync(Topic?,
82+
/// AssociationTypes)"/>, and <see cref="AttributeCollection.AsAttributeDictionary(bool)"/> convenience method.
83+
/// </para>
84+
/// <para>
85+
/// This is only intended to be enabled when needed for specialized performance testing.
86+
/// </para>
87+
/// </remarks>
88+
[Fact]
89+
public async Task Map_Bulk_EvaluateThreshold() {
90+
91+
/*------------------------------------------------------------------------------------------------------------------------
92+
| Establish variables
93+
\-----------------------------------------------------------------------------------------------------------------------*/
94+
var runs = 0; // The number of mapping operations to perform
95+
var propertyCount = 10; // The number of property values to set on the LoadTestingModel
96+
97+
/*------------------------------------------------------------------------------------------------------------------------
98+
| Establish data model
99+
\-----------------------------------------------------------------------------------------------------------------------*/
100+
var topic = new Topic("Test", "ContentList", null);
101+
102+
for (var i = 0; i <= propertyCount; i++) {
103+
topic.Attributes.SetInteger("Property"+i, i);
104+
}
105+
106+
/*------------------------------------------------------------------------------------------------------------------------
107+
| Run load testing
108+
\-----------------------------------------------------------------------------------------------------------------------*/
109+
for (var i = 0; i < runs; i++) {
110+
await _mappingService.MapAsync<LoadTestingViewModel>(topic).ConfigureAwait(false);
111+
}
112+
113+
/*------------------------------------------------------------------------------------------------------------------------
114+
| Always assume the test passed
115+
\-----------------------------------------------------------------------------------------------------------------------*/
116+
Assert.True(true);
117+
118+
}
119+
67120
/*==========================================================================================================================
68121
| TEST: MAP: LOAD TESTING: EVALUATE TIME
69122
\-------------------------------------------------------------------------------------------------------------------------*/
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*==============================================================================================================================
2+
| Author Ignia, LLC
3+
| Client Ignia, LLC
4+
| Project Topics Library
5+
\=============================================================================================================================*/
6+
using OnTopic.Attributes;
7+
using OnTopic.Mapping;
8+
9+
namespace OnTopic.Tests.ViewModels {
10+
11+
/*============================================================================================================================
12+
| VIEW MODEL: LOAD TESTING
13+
\---------------------------------------------------------------------------------------------------------------------------*/
14+
/// <summary>
15+
/// Provides a simple view model with a series of properties that can be used for load testing the <see cref="
16+
/// TopicMappingService"/>.
17+
/// </summary>
18+
/// <remarks>
19+
/// This is a sample class intended for test purposes only; it is not designed for use in a production environment.
20+
/// </remarks>
21+
public class LoadTestingViewModel: KeyOnlyTopicViewModel {
22+
23+
/*==========================================================================================================================
24+
| CONSTRUCTOR
25+
\-------------------------------------------------------------------------------------------------------------------------*/
26+
/// <summary>
27+
/// Initializes a new <see cref="LoadTestingViewModel"/> with an <paramref name="attributes"/> dictionary.
28+
/// </summary>
29+
/// <param name="attributes">An <see cref="AttributeDictionary"/> of attribute values.</param>
30+
public LoadTestingViewModel(AttributeDictionary attributes) {
31+
Contract.Requires(attributes);
32+
Property0 = attributes.GetInteger("Property0");
33+
Property1 = attributes.GetInteger("Property1");
34+
Property2 = attributes.GetInteger("Property2");
35+
Property3 = attributes.GetInteger("Property3");
36+
Property4 = attributes.GetInteger("Property4");
37+
Property5 = attributes.GetInteger("Property5");
38+
Property6 = attributes.GetInteger("Property6");
39+
Property7 = attributes.GetInteger("Property7");
40+
Property8 = attributes.GetInteger("Property8");
41+
Property9 = attributes.GetInteger("Property9");
42+
Property10 = attributes.GetInteger("Property10");
43+
Property11 = attributes.GetInteger("Property11");
44+
Property12 = attributes.GetInteger("Property12");
45+
Property13 = attributes.GetInteger("Property13");
46+
Property14 = attributes.GetInteger("Property14");
47+
Property15 = attributes.GetInteger("Property15");
48+
Property16 = attributes.GetInteger("Property16");
49+
Property17 = attributes.GetInteger("Property17");
50+
Property18 = attributes.GetInteger("Property18");
51+
Property19 = attributes.GetInteger("Property19");
52+
Property20 = attributes.GetInteger("Property20");
53+
}
54+
55+
/// <summary>
56+
/// Initializes a new <see cref="PageTopicViewModel"/> with no parameters.
57+
/// </summary>
58+
public LoadTestingViewModel() { }
59+
60+
/*==========================================================================================================================
61+
| PROPERTIES
62+
\-------------------------------------------------------------------------------------------------------------------------*/
63+
public int? Property0 { get; init; }
64+
public int? Property1 { get; init; }
65+
public int? Property2 { get; init; }
66+
public int? Property3 { get; init; }
67+
public int? Property4 { get; init; }
68+
public int? Property5 { get; init; }
69+
public int? Property6 { get; init; }
70+
public int? Property7 { get; init; }
71+
public int? Property8 { get; init; }
72+
public int? Property9 { get; init; }
73+
public int? Property10 { get; init; }
74+
public int? Property11 { get; init; }
75+
public int? Property12 { get; init; }
76+
public int? Property13 { get; init; }
77+
public int? Property14 { get; init; }
78+
public int? Property15 { get; init; }
79+
public int? Property16 { get; init; }
80+
public int? Property17 { get; init; }
81+
public int? Property18 { get; init; }
82+
public int? Property19 { get; init; }
83+
public int? Property20 { get; init; }
84+
85+
} //Class
86+
} //Namespace

0 commit comments

Comments
 (0)