LoadTestPlugins.cs
27.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
/************************************************************************************************
* All code in this file is under the MS-RL License (https://opensource.org/licenses/MS-RL) *
* By using the code in this file in any way, you agree to the above license terms. *
* Copyright (C) LIGHTS IN LINE AB (https://www.lightsinline.se) *
* Repository, Wiki, Issue tracker and more at https://git.lightsinline.se/products/VSTT-Plugins *
* *
* Contributors *
* LIGHTS IN LINE AB *
* SWEDBANK AB *
* SKATTEVERKET *
************************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using System.ComponentModel;
using System.IO;
using System.Collections.Specialized;
using System.Net;
namespace LIL_VSTT_Plugins
{
/// <summary>
/// LoadTest Context Copy
/// </summary>
[DisplayName("LoadTest Context Copy")]
[Description("(C) Copyright 2011 LIGHTS IN LINE AB\r\nKopierar context parametrar satta i loadtestet till alla test context i test mixen.")]
public class LoadTestPluginCopier : ILoadTestPlugin
{
//store the load test object.
LoadTest mLoadTest;
public void Initialize(LoadTest loadTest)
{
mLoadTest = loadTest;
//connect to the TestStarting event.
mLoadTest.TestStarting += new EventHandler<TestStartingEventArgs>(mLoadTest_TestStarting);
}
void mLoadTest_TestStarting(object sender, TestStartingEventArgs e)
{
//When the test starts, copy the load test context parameters to
//the test context parameters
foreach (string key in mLoadTest.Context.Keys)
{
e.TestContextProperties.Add(key, mLoadTest.Context[key]);
}
}
}
/// <summary>
/// LoadTest Context Copy
/// </summary>
[DisplayName("Personnummer Generator")]
[Description("(C) Copyright 2017 LIGHTS IN LINE AB\r\nGenererar personnummer och sätter dem som parameter till testernas context.")]
public class LoadTestPnumGen : ILoadTestPlugin
{
//store the load test object.
LoadTest mLoadTest;
public void Initialize(LoadTest loadTest)
{
mLoadTest = loadTest;
//connect to the TestStarting event.
mLoadTest.TestStarting += new EventHandler<TestStartingEventArgs>(mLoadTest_TestStarting);
}
void mLoadTest_TestStarting(object sender, TestStartingEventArgs e)
{
//TODO
}
}
/// <summary>
/// Service Manager Plugin
/// </summary>
[DisplayName("Service Manager Config")]
[Description("(C) Copyright 2015 LIGHTS IN LINE AB\r\nSätter config värden i Service Manager instansen för hela loadtestet. Finns även som WebTestPlugin som enbart slår på det webtestet.")]
public class ServiceManagerPlugin : ILoadTestPlugin
{
[DisplayName("Enable Expect 100 Behaviour"), DefaultValue(false)]
[Description(".Net 4.5 default is true, plugin default is false")]
public bool exp100 { get; set; }
[DisplayName("Connection Pool Idle Time (s)"), DefaultValue(100)]
public int maxIdle { get; set; }
[DisplayName("DNS Refresh Timeout (s)"), DefaultValue(120)]
public int DnsRefreshTimeout { get; set; }
[DisplayName("Enable DNS Round Robin"), DefaultValue(false)]
public bool EnableDnsRoundRobin { get; set; }
[Category("Transport Control")]
[DisplayName("TCP Keep Alive"), DefaultValue(false)]
public bool keepAlive { get; set; }
[Category("Transport Control")]
[DisplayName("TCP Keep Alive Timeout (ms)"), DefaultValue(5000)]
public int timeOut { get; set; }
[Category("Transport Control")]
[DisplayName("TCP Keep Alive Interval"), DefaultValue(1000)]
public int interVal { get; set; }
[Category("Transport Control")]
[DisplayName("Use Nagle Algorithm"), DefaultValue(false)]
public bool useNagle { get; set; }
[Category("Secure Sockets")]
[DisplayName("Enable TLS 1.2"), DefaultValue(true)]
[Description(".Net 4.5 default is false, plugin default is true")]
public bool useTls12 { get; set; }
[Category("Secure Sockets")]
[DisplayName("Enable TLS 1.1"), DefaultValue(true)]
[Description(".Net 4.5 default is false, plugin default is true")]
public bool useTls11 { get; set; }
[Category("Secure Sockets")]
[DisplayName("Enable TLS 1.0"), DefaultValue(true)]
public bool useTls10 { get; set; }
[Category("Secure Sockets")]
[DisplayName("Enable SSL 3.0"), DefaultValue(false)]
public bool useSsl3 { get; set; }
[Category("Secure Sockets")]
[DisplayName("Enable CRL checks"), DefaultValue(false)]
public bool useCrl { get; set; }
public void Initialize(LoadTest loadTest)
{
ServicePointManager.Expect100Continue = exp100;
ServicePointManager.MaxServicePointIdleTime = maxIdle * 1000;
ServicePointManager.DnsRefreshTimeout = DnsRefreshTimeout * 1000;
ServicePointManager.EnableDnsRoundRobin = EnableDnsRoundRobin;
ServicePointManager.SetTcpKeepAlive(keepAlive, timeOut, interVal);
ServicePointManager.UseNagleAlgorithm = useNagle;
//if (useTls12) System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
if (useSsl3) ServicePointManager.SecurityProtocol |= SecurityProtocolType.Ssl3;
else ServicePointManager.SecurityProtocol &= SecurityProtocolType.Ssl3;
if (useTls10) ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls;
else ServicePointManager.SecurityProtocol &= SecurityProtocolType.Tls;
if (useTls11) ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls11;
else ServicePointManager.SecurityProtocol &= SecurityProtocolType.Tls11;
if (useTls12) ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
else ServicePointManager.SecurityProtocol &= SecurityProtocolType.Tls12;
ServicePointManager.CheckCertificateRevocationList = useCrl;
}
}
[DisplayName("Set Test Context Parameters")]
[Description("(C) Copyright 2011 LIGHTS IN LINE AB\r\nSätter parametrar i testcontextet för tester i mixen hämtat från en CSV fil")]
public class SetTestParameter : ILoadTestPlugin
{
// Summary:
// Initializes the load test plug-in.
//
// Parameters:
// loadTest:
// The load test to be executed.
private string myConnectionString = "";
private string myLogFileString = "";
private string myParameterName = "";
private string myTestNames = "";
private string myScenarioNames = "";
private string myAgentNames = "";
private string myColNames = "";
private string myDebugLogFile = "";
private bool myUseRandom = true;
private bool myUseUnique = false;
private bool myUseUniqueFiles = false;
private bool myUseUniqueIteration = false;
private bool myUseUniqueTestIteration = false;
private bool myLogToFile = false;
private bool myLogAppendID = false;
private bool myLogAppendName = false;
private bool mySeqLoop = false;
private bool myHasColName = false;
private bool myUseAutoSplit = false;
private bool myIgnoreBlanks = true;
private bool myDebug = false;
private bool stop = false;
private int timeWait = 0;
private int nextAvailableRow = 0;
private StringCollection myParams = new StringCollection();
private Random random = new Random();
private Dictionary<string, int> testIterations = new Dictionary<string, int>();
private Dictionary<int, int> userRow = new Dictionary<int, int>();
private LoadTest m_loadTest;
#region guiparams
[DisplayName("Debug Mode")]
[Description("Set True in order to enable Debug Mode. Each agent will log debug messages to the given Debug Log File.")]
[DefaultValue(false)]
public bool DebugMode
{
get { return myDebug; }
set { myDebug = value; }
}
[DisplayName("Debug Log File")]
[Description("Log file path to be used for debug logging, if enabled (True)")]
[DefaultValue("C:\\Temp\\SetTestParameterDebug.log")]
public string DebugLogFile
{
get { return myDebugLogFile; }
set { myDebugLogFile = value; }
}
[DisplayName("CSV filens sökväg")]
[Description("Ange den fullständiga sökvägen till CSV filen. Observera att filen behöver finnas på alla agenterna också om du inte kör lokalt.")]
[DefaultValue("C:\\Userdata.csv")]
public string Connection_String
{
get { return myConnectionString; }
set { myConnectionString = value; }
}
[DisplayName("CSV filen har kolumnamn")]
[Description("Ange om csv filen har rubriker i form av kolumnnamn. Om du sätter True kommer kolmnens rubrik att användas som parameternamn istället.")]
[DefaultValue(false)]
public bool Has_col_name
{
get { return myHasColName; }
set { myHasColName = value; }
}
[DisplayName("CSV Autosplit per agent")]
[Description("Ange True om du vill att filen automatiskt ska splittas mellan alla aktiva agenter.")]
[DefaultValue(false)]
public bool Autosplit
{
get { return myUseAutoSplit; }
set { myUseAutoSplit = value; }
}
[DisplayName("CSV Ignorera blankskott")]
[Description("Ange False om du inte vill att rader med blankskott ignoreras (tomma/blanka rader eller samtliga kolumner tomma/blanka).")]
[DefaultValue(true)]
public bool IgnoreBlanks
{
get { return myIgnoreBlanks; }
set { myIgnoreBlanks = value; }
}
[DisplayName("Context Parameter Namn")]
[Description("Ange namnet på parametern som vi ska lägga till i TestContext, om det är flera använd CSV format.")]
[DefaultValue("UserName")]
public string Parameter_Name
{
get { return myParameterName; }
set { myParameterName = value; }
}
[DisplayName("Loggfilens namn")]
[Description("Ange den fullständiga sökvägen till logg filen. Om filen finns kommer den inte skrivas över utan läggas till i slutet.")]
[DefaultValue("C:\\Temp\\Fungerande.log")]
public string LogFilePathString
{
get { return myLogFileString; }
set { myLogFileString = value; }
}
[DisplayName("Loggfilens namn: Lägg till ID")]
[Description("Ange True om du vill att Agent ID samt VU ID läggs till automatiskt i slutet på filnamnet.")]
[DefaultValue(false)]
public bool LogFileAppendID
{
get { return myLogAppendID; }
set { myLogAppendID = value; }
}
[DisplayName("Loggfilens namn: Lägg till Namn")]
[Description("Ange True om du vill att Scenario Name samt Test Name läggs till automatiskt i slutet på filnamnet.")]
[DefaultValue(false)]
public bool LogFileAppendName
{
get { return myLogAppendName; }
set { myLogAppendName = value; }
}
[DisplayName("Välj slumpmässigt?")]
[Description("Ange True om du vill välja en slumpmässig användare. False går igenom listan sekventiellt.")]
[DefaultValue(true)]
public bool Use_Random
{
get { return myUseRandom; }
set { myUseRandom = value; }
}
[DisplayName("Välj unikt per VU?")]
[Description("Ange True om du vill att varje LoadTest VU ska ha sitt eget unika värde och återanvända detta i varje iteration. Stänger av slumpmässigt val.")]
[DefaultValue(false)]
public bool Use_Unique
{
get { return myUseUnique; }
set { myUseUnique = value; }
}
[DisplayName("Välj unikt per VU per Testdatafil?")]
[Description("Ange True om du vill att varje testdatafil (CSV) hanteras separat för varje unik VU. Pluginet kommer då komma ihåg vilka rader som delats ut separat för varje fil.")]
[DefaultValue(false)]
public bool Use_UniqueFiles
{
get { return myUseUniqueFiles; }
set { myUseUniqueFiles = value; }
}
[DisplayName("Välj unikt per Iteration?")]
[Description("Ange True om du vill att varje LoadTest VU ska ha sitt eget unika värde för varje iteration av alla tester, dvs aldrig återanvändas av någon VU i något test. Gäller före unikt per test iteration.")]
[DefaultValue(false)]
public bool Use_UniqueIteration
{
get { return myUseUniqueIteration; }
set { myUseUniqueIteration = value; }
}
[DisplayName("Välj unikt per Test Iteration?")]
[Description("Ange True om du vill att varje LoadTest VU ska ha sitt eget unika värde för varje iteration av respektive test, dvs aldrig återanvändas av någon VU som kör samma test.")]
[DefaultValue(false)]
public bool Use_UniqueTestIteration
{
get { return myUseUniqueTestIteration; }
set { myUseUniqueTestIteration = value; }
}
[DisplayName("Välj sekventiell loop?")]
[Description("Ange true om du vill börja om från början om sekventiell läsning får slut på värden. Gäller även Unik läsning. Om data tar slut kommer sista värdet ges till alla om sekventiell loop inte tillåts")]
[DefaultValue(false)]
public bool Use_Loop
{
get { return mySeqLoop; }
set { mySeqLoop = value; }
}
[DisplayName("OutOfTestDataException?")]
[Description("Ange true om du vill att ditt loadtest ska stoppas om testdata tar slut (och Sekventiell Loop är satt till false).")]
[DefaultValue(false)]
public bool ThrowException
{
get; set;
}
[DisplayName("Logga fungerande till fil?")]
[Description("Ange True om du vill att poster vars tester slutar i Pass ska loggas till fil (c:\\fungerande.log). Om filen redan finns läggs de till i slutet.")]
[DefaultValue(false)]
public bool Log_To_File
{
get { return myLogToFile; }
set { myLogToFile = value; }
}
[DisplayName("Endast dessa Tester")]
[Description("Parametrar sätts endast på tester i test mixen där namnet eller del av namnet för testet finns i denna lista. Lämna blankt för att sätta i alla tester.")]
[DefaultValue("")]
public string Test_Names
{
get { return myTestNames; }
set { myTestNames = value; }
}
[DisplayName("Endast dessa Scenarios")]
[Description("Parametrar sätts endast på Scenarion där namnet eller del av namnet för scenariot finns i denna lista. Lämna blankt för att sätta i alla scenarion.")]
[DefaultValue("")]
public string Scenario_Names
{
get { return myScenarioNames; }
set { myScenarioNames = value; }
}
[DisplayName("Endast dessa Agenter")]
[Description("Parametrar sätts endast på Agenter där namnet eller del av namnet för agenten finns i denna lista. Lämna blankt för att sätta i alla agenter.")]
[DefaultValue("")]
public string Agent_Names
{
get { return myAgentNames; }
set { myAgentNames = value; }
}
#endregion
public void Initialize(LoadTest loadTest)
{
m_loadTest = loadTest;
// Only run on specific agents if specified
if (myAgentNames.Length > 0 && !myAgentNames.ToLower().Contains(loadTest.Context.AgentName.ToLower())) return;
// Vi bör läsa in alla värden här
this.initUserArray(myConnectionString, loadTest.Context.AgentCount, loadTest.Context.AgentId);
if (myParams.Count > 0)
{
if (myUseUniqueTestIteration)
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingUniqueTestIteration);
else if (myUseUniqueIteration)
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingUniqueIteration);
else if (myUseUniqueFiles)
{
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingUniqueFiles);
m_loadTest.TestFinished += new EventHandler<TestFinishedEventArgs>(loadTestFinishedUniqueFiles);
}
else if (myUseUnique)
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingUnique);
else if (myUseRandom)
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingRandom);
else
m_loadTest.TestStarting += new EventHandler<TestStartingEventArgs>(loadTestStartingSeq);
}
if (myLogToFile)
{
m_loadTest.TestFinished += new EventHandler<TestFinishedEventArgs>(loadTestEndLogger);
}
m_loadTest.Heartbeat += new EventHandler<HeartbeatEventArgs>(loadTestHeartBeat);
}
void loadTestHeartBeat(object sender, HeartbeatEventArgs e)
{
if (stop)
{
if (timeWait > 60)
m_loadTest.Abort(new Exception("Out of test data: " + myConnectionString + " does not have more than " + myParams.Count + " accepted rows with IgnoreBlanks " + myIgnoreBlanks + "), Autosplit " + myUseAutoSplit + " and with " + m_loadTest.Context.AgentCount + " Agent(s)."));
else
timeWait++;
}
}
void loadTestEndLogger(object sender, TestFinishedEventArgs e)
{
// Log the user to logfile if the test is passed
if (e.Result.Passed && shouldRun(e))
{
string fileName = myLogFileString;
if (myLogAppendID) fileName = fileName + ".Agent" + m_loadTest.Context.AgentId + ".Vu" + e.UserContext.UserId;
if (myLogAppendName) fileName = fileName + "." + e.UserContext.ScenarioName + "." + e.TestName;
string[] allNames;
if (myHasColName) allNames = myColNames.Split(','); else allNames = myParameterName.Split(',');
string row = "";
foreach (string name in allNames)
{
if(e.UserContext.Keys.Contains(name)) {
if (row.Length == 0)
row += e.UserContext[name];
else
row += "," + e.UserContext[name];
}
}
File.AppendAllText(fileName + ".csv", row + "\r\n");
}
}
void loadTestStartingRandom(object sender, TestStartingEventArgs e)
{
setParameters(this.getRandomUser(), e);
}
void loadTestStartingSeq(object sender, TestStartingEventArgs e)
{
setParameters(this.getSeqUser(e.UserContext.CompletedTestCount), e);
}
void loadTestStartingUniqueFiles(object sender, TestStartingEventArgs e)
{
if (shouldRun(e))
{
int row = 0;
// Go single threaded
lock (userRow)
{
// Check if the user already has a row in our file, otherwise get the next one
if (userRow.ContainsKey(e.UserContext.UserId)) row = userRow[e.UserContext.UserId];
else
{
// New user, get the next row and increase the counter
row = nextAvailableRow++;
// Save the row for this user
userRow[e.UserContext.UserId] = row;
}
}
string strParams = this.getSeqUser(row);
setParameters(strParams, e);
if (myDebug) lock (myDebugLogFile) { File.AppendAllText(myDebugLogFile, DateTime.Now.ToLocalTime() + " File: " + myConnectionString + " Test: " + e.TestName + " VU: " + e.UserContext.UserId + " Row: " + row + " Value: \"" + strParams + "\"\r\n"); }
}
}
void loadTestFinishedUniqueFiles(object sender, TestFinishedEventArgs e)
{
if (shouldRun(e))
{
}
}
void loadTestStartingUnique(object sender, TestStartingEventArgs e)
{
setParameters(this.getSeqUser(e.UserContext.UserId), e);
}
void loadTestStartingUniqueIteration(object sender, TestStartingEventArgs e)
{
setParameters(this.getSeqUser(e.TestIterationNumber - 1), e);
}
void loadTestStartingUniqueTestIteration(object sender, TestStartingEventArgs e)
{
if (shouldRun(e))
{
int testIteration = getTestIterationNumber(e.TestName);
e.UserContext["TestIteration"] = testIteration;
e.TestContextProperties["TestIteration"] = testIteration;
setParameters(this.getSeqUser(testIteration - 1), e);
}
}
void setParameters(string user, TestStartingEventArgs e)
{
if (shouldRun(e))
{
// Add context parameters to the starting test
int numParams = 1;
if (myHasColName == true && myColNames.Contains(',')) numParams = countColumns(myColNames);
if (myHasColName == false && myParameterName.Contains(',')) numParams = countColumns(myParameterName);
//e.TestContextProperties.Add("LIL_LogValue", user);
//e.UserContext["LIL_LogValue"] = user;
string[] allParams = user.Split(',');
string[] allNames;
if (myHasColName) allNames = myColNames.Split(','); else allNames = myParameterName.Split(',');
for (int i = 0; i < numParams; i++)
{
e.TestContextProperties[allNames[i]] = allParams[i];
e.UserContext[allNames[i]] = allParams[i];
}
}
}
int getTestIterationNumber(string testName)
{
int num = 1;
lock (testIterations)
{
if (testIterations.ContainsKey(testName) == false)
{
testIterations[testName] = 0;
}
num = testIterations[testName] + 1;
testIterations[testName] = num;
}
return num;
}
int countColumns(string input)
{
int count = 1;
for (int i = 0; i < input.Length; i++)
{
if (input[i] == ',') count++;
}
return count;
}
bool shouldRun(TestStartingEventArgs e)
{
bool doRun = true;
if (myTestNames.Length > 0 && !myTestNames.ToLower().Contains(e.TestName.ToLower())) doRun = false;
if (myScenarioNames.Length > 0 && !myScenarioNames.ToLower().Contains(e.ScenarioName.ToLower())) doRun = false;
return doRun;
}
bool shouldRun(TestFinishedEventArgs e)
{
bool doRun = true;
if (myTestNames.Length > 0 && !myTestNames.ToLower().Contains(e.TestName.ToLower())) doRun = false;
if (myScenarioNames.Length > 0 && !myScenarioNames.ToLower().Contains(e.ScenarioName.ToLower())) doRun = false;
return doRun;
}
string getRandomUser()
{
int randomIndex = random.Next(myParams.Count - 1);
return myParams[randomIndex];
}
string getSeqUser(int seqIndex)
{
if (seqIndex < myParams.Count)
return myParams[seqIndex];
else
{
if (mySeqLoop)
return myParams[seqIndex % myParams.Count];
else {
// Handle out of testdata here
if (ThrowException)
{
foreach (LoadTestScenario s in m_loadTest.Scenarios)
{
s.CurrentLoad = 0;
}
this.stop = true;
return "OutOfData";
}
else return myParams[myParams.Count - 1];
}
}
}
bool initUserArray(string path, int agentCount, int agentId)
{
if (path.Length > 0)
{
//StreamReader re = File.OpenText(path);
StreamReader re = new StreamReader(path, System.Text.Encoding.Default);
string input = null;
int lineNum = 0;
int dataNum = 0;
char[] trim = { ' ', '\x00', '\t', '\x20' };
while ((input = re.ReadLine()) != null)
{
// Ignore blank lines and empty lines (just whitespace) or lines with only blank/empty/whitespace columns
if (myIgnoreBlanks && String.IsNullOrWhiteSpace(input.Replace(',', ' '))) continue;
lineNum++;
if (lineNum == 1 && myHasColName == true)
{
// First line is column names
myColNames = input.TrimEnd(trim);
}
else
{
if (myUseAutoSplit)
{
int ifAgentId = 0;
if (dataNum >= agentCount) ifAgentId = (dataNum % agentCount) + 1;
else ifAgentId = dataNum + 1;
if (ifAgentId == agentId)
{
myParams.Add(input.TrimEnd(trim));
}
dataNum++;
}
else
{
myParams.Add(input.TrimEnd(trim));
}
}
}
re.Close();
return true;
}
else {
return false;
}
}
}
}