Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Enterprise Library Test Guide - Willy .Net
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
<strong>Test</strong>ing for Performance and Scalability 185<br />
it reaches the maximum number of elements in the cache. (This number varied from<br />
900 to 2,000.) When the maximum number was reached, the test resets the count and<br />
begins again.<br />
To generate keys, you can either modify the test script or use data binding.<br />
Modifying the <strong>Test</strong> Script to Generate Keys<br />
You can modify the test script to include code that generates a unique key value for<br />
each cache item. In this approach, a static integer named KeyValue stores the key<br />
value. The maximum value that can be generated is controlled by another variable<br />
named MaxElements. If the key is higher than MaxElements, it is reset to 1. Because<br />
the script runs in multithreaded scenarios, the code locks the steps that generate the<br />
keys. This is shown in the following example.<br />
private static int KeyValue=0;<br />
private static object lockn = new object();<br />
private const int MaxElements=2000<br />
String KeyValueString;<br />
lock (lockn)<br />
{<br />
KeyValueString = KeyValue.ToString();<br />
KeyValue++;<br />
if (KeyValue > MaxElements)<br />
KeyValue = 1;<br />
}<br />
For more information, see Using the <strong>Test</strong> Script.<br />
Using Data Binding to Generate Keys<br />
Data binding allows you to use either a database or a .csv file to serve as the data<br />
source for the keys. The first row of the table or file should contain the name of the<br />
items that will go into the cache. For example, “Key” would be an appropriate name.<br />
The other rows contain the values for the keys. For more information, see Using Data<br />
Binding.<br />
Creating the <strong>Test</strong> Code<br />
The test code implements the scenarios. There are two versions of the test code<br />
shown here. One version is for <strong>Enterprise</strong> <strong>Library</strong> and the other version is for ASP.<br />
NET. Only the Add and Read scenarios were used to establish a baseline, so the .NET<br />
Framework code implements only those two cases. During the baseline tests, the<br />
<strong>Enterprise</strong> <strong>Library</strong> tests were performed both with and without scavenging. The code<br />
for <strong>Enterprise</strong> <strong>Library</strong> 1.1 differs from the code for <strong>Enterprise</strong> <strong>Library</strong>–January 2006,<br />
but it is not shown here.<br />
Table 3 lists the Caching Application Block test code.