From d2d0b9877fcc6150e3a2e21283ec80ef7eda9cae Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Tue, 21 Apr 2009 15:21:27 +0000 Subject: [PATCH] * Add the ability to update profiles via the cache, so that cached profiles don't become stale * Add corresponding unit test --- .../Communications/Cache/CachedUserInfo.cs | 2 +- .../Cache/UserProfileCacheService.cs | 23 +++++++++++++++ .../Cache/UserProfileCacheServiceTests.cs | 29 +++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index 32c235a1bf..98ec2871e3 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs @@ -65,7 +65,7 @@ namespace OpenSim.Framework.Communications.Cache private readonly CommunicationsManager m_commsManager; public UserProfileData UserProfile { get { return m_userProfile; } } - private readonly UserProfileData m_userProfile; + protected internal UserProfileData m_userProfile; /// /// 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 714e279581..36fe6e359a 100644 --- a/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs +++ b/OpenSim/Framework/Communications/Cache/UserProfileCacheService.cs @@ -168,6 +168,29 @@ namespace OpenSim.Framework.Communications.Cache } } + /// + /// Update an existing profile + /// + /// + /// true if a user profile was found to update, false otherwise + public bool UpdateProfile(UserProfileData userProfile) + { + lock (m_userProfilesById) + { + CachedUserInfo userInfo = GetUserDetails(userProfile.ID); + + if (userInfo != null) + { + userInfo.m_userProfile = userProfile; + m_commsManager.UserService.UpdateUserProfile(userProfile); + + return true; + } + } + + return false; + } + /// /// Populate caches with the given user profile /// diff --git a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs index 34f5c97097..68303b044e 100644 --- a/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/Cache/UserProfileCacheServiceTests.cs @@ -29,6 +29,7 @@ using NUnit.Framework; using NUnit.Framework.SyntaxHelpers; using OpenMetaverse; using OpenSim.Data; +using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; using OpenSim.Region.Communications.Local; using OpenSim.Tests.Common.Mock; @@ -69,6 +70,34 @@ namespace OpenSim.Framework.Communications.Tests existingUserInfo = commsManager.UserProfileCacheService.GetUserDetails(firstName, lastName); Assert.That(existingUserInfo, Is.Not.Null, "User info not found by name"); } + + [Test] + public void TestUpdateProfile() + { + UUID userId = UUID.Parse("00000000-0000-0000-0000-000000000292"); + string firstName = "Inspector"; + string originalLastName = "Morse"; + string newLastName = "Gadget"; + + UserProfileData newProfile = new UserProfileData(); + newProfile.ID = userId; + newProfile.FirstName = firstName; + newProfile.SurName = newLastName; + + TestCommunicationsManager commsManager = new TestCommunicationsManager(); + UserProfileCacheService userCacheService = commsManager.UserProfileCacheService; + + // Check that we can't update info before it exists + Assert.That(userCacheService.UpdateProfile(newProfile), Is.False); + + // Check that we can update a profile once it exists + LocalUserServices lus = (LocalUserServices)commsManager.UserService; + lus.AddUser(firstName, originalLastName, "pingu", "ted@excellentadventure.com", 1000, 1000, userId); + + Assert.That(userCacheService.UpdateProfile(newProfile), Is.True); + UserProfileData retrievedProfile = userCacheService.GetUserDetails(userId).UserProfile; + Assert.That(retrievedProfile.SurName, Is.EqualTo(newLastName)); + } [Test] public void TestFetchInventory()