forked from ServiceStack/ServiceStack.Redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiThreadedCacheClientManagerIntegrationTests.cs
More file actions
67 lines (56 loc) · 1.62 KB
/
Copy pathMultiThreadedCacheClientManagerIntegrationTests.cs
File metadata and controls
67 lines (56 loc) · 1.62 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
using System;
using Northwind.Common.DataModel;
using NUnit.Framework;
using ServiceStack.Text;
namespace ServiceStack.Redis.Tests.Integration
{
[TestFixture]
public class MultiThreadedCacheClientManagerIntegrationTests
: IntegrationTestBase
{
private static string testData;
[TestFixtureSetUp]
public void onBeforeTestFixture()
{
NorthwindData.LoadData(false);
testData = TypeSerializer.SerializeToString(NorthwindData.Customers);
}
[Test]
public void Pool_can_support_64_threads_using_the_client_simultaneously()
{
RunSimultaneously(CreateAndStartPoolManager, UseClient);
}
[Test]
public void Basic_can_support_64_threads_using_the_client_simultaneously()
{
RunSimultaneously(CreateAndStartBasicCacheManager, UseClient);
}
private static void UseClient(IRedisClientsManager manager, int clientNo)
{
var cacheManager = (IRedisClientCacheManager)manager;
var host = "";
try
{
using (var client = cacheManager.GetReadOnlyCacheClient())
{
host = ((IRedisClient)client).Host;
Log("Client '{0}' is using '{1}'", clientNo, host);
var testClientKey = "test:" + host + ":" + clientNo;
client.Set(testClientKey, testData);
var result = client.Get<string>(testClientKey) ?? "";
Log("\t{0} => {1} len {2} {3} len", testClientKey,
testData.Length, testData.Length == result.Length ? "==" : "!=", result.Length);
}
}
catch (NullReferenceException ex)
{
Log("NullReferenceException StackTrace: \n" + ex.StackTrace);
}
catch (Exception ex)
{
Log("\t[ERROR@{0}]: {1} => {2}",
host, ex.GetType().Name, ex.Message);
}
}
}
}