aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clarke Casey2009-04-21 15:21:27 +0000
committerJustin Clarke Casey2009-04-21 15:21:27 +0000
commitd2d0b9877fcc6150e3a2e21283ec80ef7eda9cae (patch)
tree9e311f1de83af5c33f07f85b8ebb36911fabdc41 /OpenSim
parentFrom: Alan Webb <alan_webb@us.ibm.com> (diff)
downloadopensim-SC-d2d0b9877fcc6150e3a2e21283ec80ef7eda9cae.zip
opensim-SC-d2d0b9877fcc6150e3a2e21283ec80ef7eda9cae.tar.gz
opensim-SC-d2d0b9877fcc6150e3a2e21283ec80ef7eda9cae.tar.bz2
opensim-SC-d2d0b9877fcc6150e3a2e21283ec80ef7eda9cae.tar.xz
* Add the ability to update profiles via the cache, so that cached profiles don't become stale
* Add corresponding unit test
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Framework/Communications/Cache/CachedUserInfo.cs2
-rw-r--r--OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs23
-rw-r--r--OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs29
3 files changed, 53 insertions, 1 deletions
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
index 32c235a..98ec287 100644
--- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
+++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs
@@ -65,7 +65,7 @@ namespace OpenSim.Framework.Communications.Cache
65 private readonly CommunicationsManager m_commsManager; 65 private readonly CommunicationsManager m_commsManager;
66 66
67 public UserProfileData UserProfile { get { return m_userProfile; } } 67 public UserProfileData UserProfile { get { return m_userProfile; } }
68 private readonly UserProfileData m_userProfile; 68 protected internal UserProfileData m_userProfile;
69 69
70 /// <summary> 70 /// <summary>
71 /// Have we received the user's inventory from the inventory service? 71 /// Have we received the user's inventory from the inventory service?
diff --git a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
index 714e279..36fe6e3 100644
--- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
+++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs
@@ -169,6 +169,29 @@ namespace OpenSim.Framework.Communications.Cache
169 } 169 }
170 170
171 /// <summary> 171 /// <summary>
172 /// Update an existing profile
173 /// </summary>
174 /// <param name="userProfile"></param>
175 /// <returns>true if a user profile was found to update, false otherwise</returns>
176 public bool UpdateProfile(UserProfileData userProfile)
177 {
178 lock (m_userProfilesById)
179 {
180 CachedUserInfo userInfo = GetUserDetails(userProfile.ID);
181
182 if (userInfo != null)
183 {
184 userInfo.m_userProfile = userProfile;
185 m_commsManager.UserService.UpdateUserProfile(userProfile);
186
187 return true;
188 }
189 }
190
191 return false;
192 }
193
194 /// <summary>
172 /// Populate caches with the given user profile 195 /// Populate caches with the given user profile
173 /// </summary> 196 /// </summary>
174 /// <param name="userProfile"></param> 197 /// <param name="userProfile"></param>
diff --git a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs
index 34f5c97..68303b0 100644
--- a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs
+++ b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs
@@ -29,6 +29,7 @@ using NUnit.Framework;
29using NUnit.Framework.SyntaxHelpers; 29using NUnit.Framework.SyntaxHelpers;
30using OpenMetaverse; 30using OpenMetaverse;
31using OpenSim.Data; 31using OpenSim.Data;
32using OpenSim.Framework;
32using OpenSim.Framework.Communications.Cache; 33using OpenSim.Framework.Communications.Cache;
33using OpenSim.Region.Communications.Local; 34using OpenSim.Region.Communications.Local;
34using OpenSim.Tests.Common.Mock; 35using OpenSim.Tests.Common.Mock;
@@ -69,6 +70,34 @@ namespace OpenSim.Framework.Communications.Tests
69 existingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName); 70 existingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName);
70 Assert.That(existingUserInfo, Is.Not.Null, "User info not found by name"); 71 Assert.That(existingUserInfo, Is.Not.Null, "User info not found by name");
71 } 72 }
73
74 [Test]
75 public void TestUpdateProfile()
76 {
77 UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000292");
78 string firstName = "Inspector";
79 string originalLastName = "Morse";
80 string newLastName = "Gadget";
81
82 UserProfileData newProfile = new UserProfileData();
83 newProfile.ID = userId;
84 newProfile.FirstName = firstName;
85 newProfile.SurName = newLastName;
86
87 TestCommunicationsManager commsManager = new TestCommunicationsManager();
88 UserProfileCacheService userCacheService = commsManager.UserProfileCacheService;
89
90 // Check that we can't update info before it exists
91 Assert.That(userCacheService.UpdateProfile(newProfile), Is.False);
92
93 // Check that we can update a profile once it exists
94 LocalUserServices lus = (LocalUserServices)commsManager.UserService;
95 lus.AddUser(firstName, originalLastName, "pingu", "ted@excellentadventure.com", 1000, 1000, userId);
96
97 Assert.That(userCacheService.UpdateProfile(newProfile), Is.True);
98 UserProfileData retrievedProfile = userCacheService.GetUserDetails(userId).UserProfile;
99 Assert.That(retrievedProfile.SurName, Is.EqualTo(newLastName));
100 }
72 101
73 [Test] 102 [Test]
74 public void TestFetchInventory() 103 public void TestFetchInventory()