This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
/
RegionFactoryUnitTest.cs
130 lines (114 loc) · 4.07 KB
/
RegionFactoryUnitTest.cs
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
using System;
using System.Collections.Generic;
using System.Net.Cache;
using Apache.Geode.NetCore;
using NUnit.Framework;
namespace GemfireDotNetTest
{
public class SimpleAuthInitialize : IAuthInitialize
{
public Dictionary<string, string> GetCredentials()
{
Console.WriteLine("SimpleAuthInitialize::GetCredentials called");
var credentials = new Dictionary<string, string>();
credentials.Add("security-username", "root");
credentials.Add("security-password", "root-password");
return credentials;
}
public void Close()
{
Console.WriteLine("SimpleAuthInitialize::Close called");
}
}
public class RegionFactoryUnitTests
{
[SetUp]
public void Setup()
{
}
private const string Username1 = "rtimmons";
private const string Username2 = "scharles";
private void createPool(IGeodeCache cache, int port)
{
using (var poolManager = cache.PoolManager)
{
using (var poolFactory = poolManager.CreatePoolFactory()
.AddLocator("localhost", port))
{
using (var pool = poolFactory.CreatePool("myPool"))
{
;
}
}
}
}
private void doPutsAndGets(Region region)
{
var fullname1 = "Robert Timmons";
var fullname2 = "Sylvia Charles";
region.PutString(Username1, fullname1);
region.PutString(Username2, fullname2);
var user1 = region.GetString(Username1);
var user2 = region.GetString(Username2);
Assert.AreEqual(user1, fullname1);
Assert.AreEqual(user2, fullname2);
}
private void DoRemoves(Region region)
{
region.Remove(Username1);
region.Remove(Username2);
var hasUser1 = region.ContainsValueForKey(Username1);
var hasUser2 = region.ContainsValueForKey(Username2);
Assert.AreEqual(hasUser1, false);
Assert.AreEqual(hasUser2, false);
}
private void CreateRegionAndDoWork(IGeodeCache cache, string regionName, RegionShortcut regionType)
{
using (var regionFactory = cache.CreateRegionFactory(regionType))
{
using (var region = regionFactory.CreateRegion(regionName))
{
doPutsAndGets(region);
DoRemoves(region);
}
}
}
[Test]
public void TestRegionFactoryCreateProxyRegion()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create(client)
.SetProperty("log-level", "none")
.SetProperty("log-file", "geode_native.log"))
{
using (var cache = cacheFactory.CreateCache())
{
createPool(cache, 10334);
CreateRegionAndDoWork(cache, "exampleRegion", RegionShortcut.Proxy);
}
}
}
Assert.Pass();
}
[Test]
public void TestRegionFactoryCreateRegionWithAuthentication()
{
using (var client = new Client())
{
using (var cacheFactory = CacheFactory.Create(client)
.SetProperty("log-level", "debug")
.SetProperty("log-file", "geode_native_with_auth.log"))
{
cacheFactory.AuthInitialize = new SimpleAuthInitialize();
using (var cache = cacheFactory.CreateCache())
{
createPool(cache, 10335);
CreateRegionAndDoWork(cache, "authExampleRegion", RegionShortcut.CachingProxy);
}
}
}
Assert.Pass();
}
}
}