aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-rw-r--r--OpenSim/Framework/ACL.cs32
-rw-r--r--OpenSim/Framework/Communications/Services/LoginService.cs26
-rw-r--r--OpenSim/Framework/Tests/ACLTest.cs98
-rw-r--r--OpenSim/Framework/Tests/CacheTests.cs75
-rw-r--r--OpenSim/Framework/Util.cs21
5 files changed, 206 insertions, 46 deletions
diff --git a/OpenSim/Framework/ACL.cs b/OpenSim/Framework/ACL.cs
index 3b1c0f0..f76e8b7 100644
--- a/OpenSim/Framework/ACL.cs
+++ b/OpenSim/Framework/ACL.cs
@@ -248,35 +248,5 @@ namespace OpenSim.Framework
248 248
249 #endregion 249 #endregion
250 250
251 #region Tests 251
252
253 /// <summary>
254 /// ACL Test class
255 /// </summary>
256 internal class ACLTester
257 {
258 public ACLTester()
259 {
260 ACL acl = new ACL();
261
262 Role Guests = new Role("Guests");
263 acl.AddRole(Guests);
264
265 Role[] parents = new Role[0];
266 parents[0] = Guests;
267
268 Role JoeGuest = new Role("JoeGuest", parents);
269 acl.AddRole(JoeGuest);
270
271 Resource CanBuild = new Resource("CanBuild");
272 acl.AddResource(CanBuild);
273
274
275 acl.GrantPermission("Guests", "CanBuild");
276
277 acl.HasPermission("JoeGuest", "CanBuild");
278 }
279 }
280
281 #endregion
282} \ No newline at end of file 252} \ No newline at end of file
diff --git a/OpenSim/Framework/Communications/Services/LoginService.cs b/OpenSim/Framework/Communications/Services/LoginService.cs
index 922cd49..b652299 100644
--- a/OpenSim/Framework/Communications/Services/LoginService.cs
+++ b/OpenSim/Framework/Communications/Services/LoginService.cs
@@ -1031,30 +1031,26 @@ namespace OpenSim.Framework.Communications.Services
1031 return true; 1031 return true;
1032 } 1032 }
1033 1033
1034 // StartLocation not available, send him to a nearby region instead 1034 // Get the default region handle
1035 // regionInfo = m_gridService.RequestClosestRegion(""); 1035 ulong defaultHandle = Utils.UIntsToLong(m_defaultHomeX * Constants.RegionSize, m_defaultHomeY * Constants.RegionSize);
1036 //m_log.InfoFormat("[LOGIN]: StartLocation not available sending to region {0}", regionInfo.regionName);
1037 1036
1038 // Send him to default region instead 1037 // If we haven't already tried the default region, reset regionInfo
1039 ulong defaultHandle = (((ulong)m_defaultHomeX * Constants.RegionSize) << 32) | 1038 if (regionInfo != null && defaultHandle != regionInfo.RegionHandle)
1040 ((ulong)m_defaultHomeY * Constants.RegionSize); 1039 regionInfo = null;
1041 1040
1042 if ((regionInfo != null) && (defaultHandle == regionInfo.RegionHandle)) 1041 if (regionInfo == null)
1043 { 1042 {
1044 m_log.ErrorFormat("[LOGIN]: Not trying the default region since this is the same as the selected region"); 1043 m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
1045 return false; 1044 regionInfo = GetRegionInfo(defaultHandle);
1046 } 1045 }
1047 1046
1048 m_log.Error("[LOGIN]: Sending user to default region " + defaultHandle + " instead");
1049 regionInfo = GetRegionInfo(defaultHandle);
1050
1051 if (regionInfo == null) 1047 if (regionInfo == null)
1052 { 1048 {
1053 m_log.ErrorFormat("[LOGIN]: No default region available. Aborting."); 1049 m_log.ErrorFormat("[LOGIN]: Sending user to any region");
1054 return false; 1050 regionInfo = RequestClosestRegion(String.Empty);
1055 } 1051 }
1056 1052
1057 theUser.CurrentAgent.Position = new Vector3(128, 128, 0); 1053 theUser.CurrentAgent.Position = new Vector3(128f, 128f, 0f);
1058 response.StartLocation = "safe"; 1054 response.StartLocation = "safe";
1059 1055
1060 return PrepareLoginToRegion(regionInfo, theUser, response, client); 1056 return PrepareLoginToRegion(regionInfo, theUser, response, client);
diff --git a/OpenSim/Framework/Tests/ACLTest.cs b/OpenSim/Framework/Tests/ACLTest.cs
new file mode 100644
index 0000000..d11f307
--- /dev/null
+++ b/OpenSim/Framework/Tests/ACLTest.cs
@@ -0,0 +1,98 @@
1using System;
2using NUnit.Framework;
3using System.Collections.Generic;
4
5
6namespace OpenSim.Framework.Tests
7{
8 [TestFixture]
9 public class ACLTest
10 {
11 #region Tests
12
13 /// <summary>
14 /// ACL Test class
15 /// </summary>
16 [Test]
17 public void ACLTest01()
18 {
19 ACL acl = new ACL();
20
21 Role Guests = new Role("Guests");
22 acl.AddRole(Guests);
23
24 Role[] parents = new Role[1];
25 parents[0] = Guests;
26
27 Role JoeGuest = new Role("JoeGuest", parents);
28 acl.AddRole(JoeGuest);
29
30 Resource CanBuild = new Resource("CanBuild");
31 acl.AddResource(CanBuild);
32
33
34 acl.GrantPermission("Guests", "CanBuild");
35
36 Permission perm = acl.HasPermission("JoeGuest", "CanBuild");
37 Assert.That(perm == Permission.Allow, "JoeGuest should have permission to build");
38 perm = Permission.None;
39 try
40 {
41 perm = acl.HasPermission("unknownGuest", "CanBuild");
42
43 }
44 catch (KeyNotFoundException)
45 {
46
47
48 }
49 catch (Exception)
50 {
51 Assert.That(false,"Exception thrown should have been KeyNotFoundException");
52 }
53 Assert.That(perm == Permission.None,"Permission None should be set because exception should have been thrown");
54
55 }
56
57 [Test]
58 public void KnownButPermissionDenyAndPermissionNoneUserTest()
59 {
60 ACL acl = new ACL();
61
62 Role Guests = new Role("Guests");
63 acl.AddRole(Guests);
64 Role Administrators = new Role("Administrators");
65 acl.AddRole(Administrators);
66 Role[] Guestparents = new Role[1];
67 Role[] Adminparents = new Role[1];
68
69 Guestparents[0] = Guests;
70 Adminparents[0] = Administrators;
71
72 Role JoeGuest = new Role("JoeGuest", Guestparents);
73 acl.AddRole(JoeGuest);
74
75 Resource CanBuild = new Resource("CanBuild");
76 acl.AddResource(CanBuild);
77
78 Resource CanScript = new Resource("CanScript");
79 acl.AddResource(CanScript);
80
81 Resource CanRestart = new Resource("CanRestart");
82 acl.AddResource(CanRestart);
83
84 acl.GrantPermission("Guests", "CanBuild");
85 acl.DenyPermission("Guests", "CanRestart");
86
87 acl.GrantPermission("Administrators", "CanScript");
88
89 acl.GrantPermission("Administrators", "CanRestart");
90 Permission setPermission = acl.HasPermission("JoeGuest", "CanRestart");
91 Assert.That(setPermission == Permission.Deny, "Guests Should not be able to restart");
92 Assert.That(acl.HasPermission("JoeGuest", "CanScript") == Permission.None,
93 "No Explicit Permissions set so should be Permission.None");
94 }
95
96 #endregion
97 }
98}
diff --git a/OpenSim/Framework/Tests/CacheTests.cs b/OpenSim/Framework/Tests/CacheTests.cs
new file mode 100644
index 0000000..8e97232
--- /dev/null
+++ b/OpenSim/Framework/Tests/CacheTests.cs
@@ -0,0 +1,75 @@
1using System;
2using NUnit.Framework;
3using OpenMetaverse;
4
5namespace OpenSim.Framework.Tests
6{
7 [TestFixture]
8 public class CacheTests
9 {
10 private Cache cache;
11 private UUID cacheItemUUID;
12 [SetUp]
13 public void Build()
14 {
15 cache = new Cache();
16 cacheItemUUID = UUID.Random();
17 MemoryCacheItem cachedItem = new MemoryCacheItem(cacheItemUUID.ToString(),DateTime.Now + TimeSpan.FromDays(1));
18 byte[] foo = new byte[1];
19 foo[0] = 255;
20 cachedItem.Store(foo);
21 cache.Store(cacheItemUUID.ToString(), cachedItem);
22 }
23 [Test]
24 public void TestRetreive()
25 {
26 CacheItemBase citem = (CacheItemBase)cache.Get(cacheItemUUID.ToString());
27 byte[] data = (byte[]) citem.Retrieve();
28 Assert.That(data.Length == 1, "Cached Item should have one byte element");
29 Assert.That(data[0] == 255, "Cached Item element should be 255");
30 }
31
32 [Test]
33 public void TestNotInCache()
34 {
35 UUID randomNotIn = UUID.Random();
36 while (randomNotIn == cacheItemUUID)
37 {
38 randomNotIn = UUID.Random();
39 }
40 object citem = cache.Get(randomNotIn.ToString());
41 Assert.That(citem == null, "Item should not be in Cache" );
42 }
43
44 //NOTE: Test Case disabled until Cache is fixed
45 [Test]
46 public void TestTTLExpiredEntry()
47 {
48 UUID ImmediateExpiryUUID = UUID.Random();
49 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(-1));
50 byte[] foo = new byte[1];
51 foo[0] = 1;
52 cachedItem.Store(foo);
53 cache.Store(cacheItemUUID.ToString(), cachedItem);
54
55 object citem = cache.Get(cacheItemUUID.ToString());
56 //Assert.That(citem == null, "Item should not be in Cache because the expiry time was before now");
57 }
58
59 //NOTE: Test Case disabled until Cache is fixed
60 [Test]
61 public void ExpireItemManually()
62 {
63 UUID ImmediateExpiryUUID = UUID.Random();
64 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(1));
65 byte[] foo = new byte[1];
66 foo[0] = 1;
67 cachedItem.Store(foo);
68 cache.Store(cacheItemUUID.ToString(), cachedItem);
69 cache.Invalidate(ImmediateExpiryUUID.ToString());
70 object citem = cache.Get(cacheItemUUID.ToString());
71 //Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it");
72 }
73
74 }
75}
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 10f38ab..87ba5a8 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -1330,6 +1330,27 @@ namespace OpenSim.Framework
1330 m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2); 1330 m_ThreadPool = new SmartThreadPool(2000, maxThreads, 2);
1331 } 1331 }
1332 1332
1333 public static int FireAndForgetCount()
1334 {
1335 const int MAX_SYSTEM_THREADS = 200;
1336
1337 switch (FireAndForgetMethod)
1338 {
1339 case FireAndForgetMethod.UnsafeQueueUserWorkItem:
1340 case FireAndForgetMethod.QueueUserWorkItem:
1341 case FireAndForgetMethod.BeginInvoke:
1342 int workerThreads, iocpThreads;
1343 ThreadPool.GetAvailableThreads(out workerThreads, out iocpThreads);
1344 return workerThreads;
1345 case FireAndForgetMethod.SmartThreadPool:
1346 return m_ThreadPool.MaxThreads - m_ThreadPool.InUseThreads;
1347 case FireAndForgetMethod.Thread:
1348 return MAX_SYSTEM_THREADS - System.Diagnostics.Process.GetCurrentProcess().Threads.Count;
1349 default:
1350 throw new NotImplementedException();
1351 }
1352 }
1353
1333 public static void FireAndForget(System.Threading.WaitCallback callback, object obj) 1354 public static void FireAndForget(System.Threading.WaitCallback callback, object obj)
1334 { 1355 {
1335 switch (FireAndForgetMethod) 1356 switch (FireAndForgetMethod)