aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/World
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/World')
-rw-r--r--OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs384
1 files changed, 326 insertions, 58 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
index abbaf41..0a30905 100644
--- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
+++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs
@@ -57,23 +57,25 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
57 private Guid m_lastRequestId; 57 private Guid m_lastRequestId;
58 private string m_lastErrorMessage; 58 private string m_lastErrorMessage;
59 59
60 protected SceneHelpers m_sceneHelpers;
60 protected TestScene m_scene; 61 protected TestScene m_scene;
61 protected ArchiverModule m_archiverModule; 62 protected ArchiverModule m_archiverModule;
63 protected SerialiserModule m_serialiserModule;
62 64
63 protected TaskInventoryItem m_soundItem; 65 protected TaskInventoryItem m_soundItem;
64 66
65 [SetUp] 67 [SetUp]
66 public void SetUp() 68 public void SetUp()
67 { 69 {
70 new SceneManager();
71
68 m_archiverModule = new ArchiverModule(); 72 m_archiverModule = new ArchiverModule();
69 SerialiserModule serialiserModule = new SerialiserModule(); 73 m_serialiserModule = new SerialiserModule();
70 TerrainModule terrainModule = new TerrainModule(); 74 TerrainModule terrainModule = new TerrainModule();
71 75
72 m_scene = new SceneHelpers().SetupScene(); 76 m_sceneHelpers = new SceneHelpers();
73 SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, serialiserModule, terrainModule); 77 m_scene = m_sceneHelpers.SetupScene();
74 78 SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, m_serialiserModule, terrainModule);
75 new SceneManager();
76 SceneManager.Instance.Add(m_scene);
77 } 79 }
78 80
79 private void LoadCompleted(Guid requestId, List<UUID> loadedScenes, string errorMessage) 81 private void LoadCompleted(Guid requestId, List<UUID> loadedScenes, string errorMessage)
@@ -132,26 +134,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
132 TestHelpers.InMethod(); 134 TestHelpers.InMethod();
133// log4net.Config.XmlConfigurator.Configure(); 135// log4net.Config.XmlConfigurator.Configure();
134 136
135 SceneObjectPart part1 = CreateSceneObjectPart1(); 137 SceneObjectGroup sog1;
136 SceneObjectGroup sog1 = new SceneObjectGroup(part1); 138 SceneObjectGroup sog2;
137 m_scene.AddNewSceneObject(sog1, false); 139 UUID ncAssetUuid;
138 140 CreateTestObjects(m_scene, out sog1, out sog2, out ncAssetUuid);
139 SceneObjectPart part2 = CreateSceneObjectPart2();
140
141 AssetNotecard nc = new AssetNotecard();
142 nc.BodyText = "Hello World!";
143 nc.Encode();
144 UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000");
145 UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000");
146 AssetBase ncAsset
147 = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);
148 m_scene.AssetService.Store(ncAsset);
149 SceneObjectGroup sog2 = new SceneObjectGroup(part2);
150 TaskInventoryItem ncItem
151 = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid };
152 part2.Inventory.AddInventoryItem(ncItem, true);
153
154 m_scene.AddNewSceneObject(sog2, false);
155 141
156 MemoryStream archiveWriteStream = new MemoryStream(); 142 MemoryStream archiveWriteStream = new MemoryStream();
157 m_scene.EventManager.OnOarFileSaved += SaveCompleted; 143 m_scene.EventManager.OnOarFileSaved += SaveCompleted;
@@ -215,6 +201,30 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
215 // TODO: Test presence of more files and contents of files. 201 // TODO: Test presence of more files and contents of files.
216 } 202 }
217 203
204 private void CreateTestObjects(Scene scene, out SceneObjectGroup sog1, out SceneObjectGroup sog2, out UUID ncAssetUuid)
205 {
206 SceneObjectPart part1 = CreateSceneObjectPart1();
207 sog1 = new SceneObjectGroup(part1);
208 scene.AddNewSceneObject(sog1, false);
209
210 AssetNotecard nc = new AssetNotecard();
211 nc.BodyText = "Hello World!";
212 nc.Encode();
213 ncAssetUuid = UUID.Random();
214 UUID ncItemUuid = UUID.Random();
215 AssetBase ncAsset
216 = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero);
217 m_scene.AssetService.Store(ncAsset);
218
219 TaskInventoryItem ncItem
220 = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid };
221 SceneObjectPart part2 = CreateSceneObjectPart2();
222 sog2 = new SceneObjectGroup(part2);
223 part2.Inventory.AddInventoryItem(ncItem, true);
224
225 scene.AddNewSceneObject(sog2, false);
226 }
227
218 /// <summary> 228 /// <summary>
219 /// Test saving an OpenSim Region Archive with the no assets option 229 /// Test saving an OpenSim Region Archive with the no assets option
220 /// </summary> 230 /// </summary>
@@ -392,31 +402,12 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
392 Assert.That(soundDataResourceName, Is.Not.Null); 402 Assert.That(soundDataResourceName, Is.Not.Null);
393 403
394 byte[] soundData; 404 byte[] soundData;
395 Console.WriteLine("Loading " + soundDataResourceName); 405 UUID soundUuid;
396 using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName)) 406 CreateSoundAsset(tar, assembly, soundDataResourceName, out soundData, out soundUuid);
397 { 407
398 using (BinaryReader br = new BinaryReader(resource)) 408 TaskInventoryItem item1
399 { 409 = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName };
400 // FIXME: Use the inspector instead 410 part1.Inventory.AddInventoryItem(item1, true);
401 soundData = br.ReadBytes(99999999);
402 UUID soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
403 string soundAssetFileName
404 = ArchiveConstants.ASSETS_PATH + soundUuid
405 + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV];
406 tar.WriteFile(soundAssetFileName, soundData);
407
408 /*
409 AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData);
410 scene.AssetService.Store(soundAsset);
411 asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav";
412 */
413
414 TaskInventoryItem item1
415 = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName };
416 part1.Inventory.AddInventoryItem(item1, true);
417 }
418 }
419
420 m_scene.AddNewSceneObject(object1, false); 411 m_scene.AddNewSceneObject(object1, false);
421 412
422 string object1FileName = string.Format( 413 string object1FileName = string.Format(
@@ -438,6 +429,34 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
438 429
439 Assert.That(m_lastErrorMessage, Is.Null); 430 Assert.That(m_lastErrorMessage, Is.Null);
440 431
432 TestLoadedRegion(part1, soundItemName, soundData);
433 }
434
435 private static void CreateSoundAsset(TarArchiveWriter tar, Assembly assembly, string soundDataResourceName, out byte[] soundData, out UUID soundUuid)
436 {
437 using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName))
438 {
439 using (BinaryReader br = new BinaryReader(resource))
440 {
441 // FIXME: Use the inspector instead
442 soundData = br.ReadBytes(99999999);
443 soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001");
444 string soundAssetFileName
445 = ArchiveConstants.ASSETS_PATH + soundUuid
446 + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV];
447 tar.WriteFile(soundAssetFileName, soundData);
448
449 /*
450 AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData);
451 scene.AssetService.Store(soundAsset);
452 asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav";
453 */
454 }
455 }
456 }
457
458 private void TestLoadedRegion(SceneObjectPart part1, string soundItemName, byte[] soundData)
459 {
441 SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name); 460 SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name);
442 461
443 Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); 462 Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded");
@@ -457,9 +476,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
457 Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match"); 476 Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match");
458 477
459 Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels"); 478 Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels");
460
461 // Temporary
462 Console.WriteLine("Successfully completed {0}", MethodBase.GetCurrentMethod());
463 } 479 }
464 480
465 /// <summary> 481 /// <summary>
@@ -519,11 +535,10 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
519 SerialiserModule serialiserModule = new SerialiserModule(); 535 SerialiserModule serialiserModule = new SerialiserModule();
520 TerrainModule terrainModule = new TerrainModule(); 536 TerrainModule terrainModule = new TerrainModule();
521 537
522 TestScene scene2 = new SceneHelpers().SetupScene(); 538 m_sceneHelpers = new SceneHelpers();
539 TestScene scene2 = m_sceneHelpers.SetupScene();
523 SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); 540 SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule);
524 541
525 SceneManager.Instance.Add(scene2);
526
527 // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is 542 // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is
528 // behaving correctly 543 // behaving correctly
529 UserAccountHelpers.CreateUserWithInventory(scene2, objectOwner); 544 UserAccountHelpers.CreateUserWithInventory(scene2, objectOwner);
@@ -669,7 +684,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
669 SerialiserModule serialiserModule = new SerialiserModule(); 684 SerialiserModule serialiserModule = new SerialiserModule();
670 TerrainModule terrainModule = new TerrainModule(); 685 TerrainModule terrainModule = new TerrainModule();
671 686
672 Scene scene = new SceneHelpers().SetupScene(); 687 Scene scene = m_sceneHelpers.SetupScene();
673 SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule); 688 SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule);
674 689
675 m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false); 690 m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false);
@@ -705,5 +720,258 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests
705 Assert.That(object2PartMerged.GroupPosition, Is.EqualTo(part2.GroupPosition), "object2 group position not equal after merge"); 720 Assert.That(object2PartMerged.GroupPosition, Is.EqualTo(part2.GroupPosition), "object2 group position not equal after merge");
706 } 721 }
707 } 722 }
723
724 /// <summary>
725 /// Test saving a multi-region OAR.
726 /// </summary>
727 [Test]
728 public void TestSaveMultiRegionOar()
729 {
730 TestHelpers.InMethod();
731
732 // Create test regions
733
734 int WIDTH = 2;
735 int HEIGHT = 2;
736
737 List<Scene> scenes = new List<Scene>();
738
739 // Maps (Directory in OAR file -> scene)
740 Dictionary<string, Scene> regionPaths = new Dictionary<string, Scene>();
741
742 // Maps (Scene -> expected object paths)
743 Dictionary<UUID, List<string>> expectedPaths = new Dictionary<UUID, List<string>>();
744
745 // List of expected assets
746 List<UUID> expectedAssets = new List<UUID>();
747
748 for (uint y = 0; y < HEIGHT; y++)
749 {
750 for (uint x = 0; x < WIDTH; x++)
751 {
752 Scene scene;
753 if (x == 0 && y == 0)
754 {
755 scene = m_scene; // this scene was already created in SetUp()
756 }
757 else
758 {
759 scene = m_sceneHelpers.SetupScene(string.Format("Unit test region {0}", (y * WIDTH) + x + 1), UUID.Random(), 1000 + x, 1000 + y);
760 SceneHelpers.SetupSceneModules(scene, new ArchiverModule(), m_serialiserModule, new TerrainModule());
761 }
762 scenes.Add(scene);
763
764 string dir = String.Format("{0}_{1}_{2}", x + 1, y + 1, scene.RegionInfo.RegionName.Replace(" ", "_"));
765 regionPaths[dir] = scene;
766
767 SceneObjectGroup sog1;
768 SceneObjectGroup sog2;
769 UUID ncAssetUuid;
770
771 CreateTestObjects(scene, out sog1, out sog2, out ncAssetUuid);
772
773 expectedPaths[scene.RegionInfo.RegionID] = new List<string>();
774 expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog1));
775 expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog2));
776
777 expectedAssets.Add(ncAssetUuid);
778 }
779 }
780
781
782 // Save OAR
783
784 MemoryStream archiveWriteStream = new MemoryStream();
785 m_scene.EventManager.OnOarFileSaved += SaveCompleted;
786
787 Guid requestId = new Guid("00000000-0000-0000-0000-808080808080");
788
789 Dictionary<string, Object> options = new Dictionary<string, Object>();
790 options.Add("all", true);
791
792 lock (this)
793 {
794 m_archiverModule.ArchiveRegion(archiveWriteStream, requestId, options);
795 Monitor.Wait(this, 60000);
796 }
797
798
799 // Check that the OAR contains the expected data
800
801 Assert.That(m_lastRequestId, Is.EqualTo(requestId));
802
803 byte[] archive = archiveWriteStream.ToArray();
804 MemoryStream archiveReadStream = new MemoryStream(archive);
805 TarArchiveReader tar = new TarArchiveReader(archiveReadStream);
806
807 Dictionary<UUID, List<string>> foundPaths = new Dictionary<UUID, List<string>>();
808 List<UUID> foundAssets = new List<UUID>();
809
810 foreach (Scene scene in scenes)
811 {
812 foundPaths[scene.RegionInfo.RegionID] = new List<string>();
813 }
814
815 string filePath;
816 TarArchiveReader.TarEntryType tarEntryType;
817
818 byte[] data = tar.ReadEntry(out filePath, out tarEntryType);
819 Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH));
820
821 ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty);
822 arr.LoadControlFile(filePath, data, new DearchiveScenesInfo());
823
824 Assert.That(arr.ControlFileLoaded, Is.True);
825
826 while (tar.ReadEntry(out filePath, out tarEntryType) != null)
827 {
828 if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH))
829 {
830 // Assets are shared, so this file doesn't belong to any specific region.
831 string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length);
832 if (fileName.EndsWith("_notecard.txt"))
833 foundAssets.Add(UUID.Parse(fileName.Substring(0, fileName.Length - "_notecard.txt".Length)));
834 }
835 else
836 {
837 // This file belongs to one of the regions. Find out which one.
838 Assert.IsTrue(filePath.StartsWith(ArchiveConstants.REGIONS_PATH));
839 string[] parts = filePath.Split(new Char[] { '/' }, 3);
840 Assert.AreEqual(3, parts.Length);
841 string regionDirectory = parts[1];
842 string relativePath = parts[2];
843 Scene scene = regionPaths[regionDirectory];
844
845 if (relativePath.StartsWith(ArchiveConstants.OBJECTS_PATH))
846 {
847 foundPaths[scene.RegionInfo.RegionID].Add(relativePath);
848 }
849 }
850 }
851
852 Assert.AreEqual(scenes.Count, foundPaths.Count);
853 foreach (Scene scene in scenes)
854 {
855 Assert.That(foundPaths[scene.RegionInfo.RegionID], Is.EquivalentTo(expectedPaths[scene.RegionInfo.RegionID]));
856 }
857
858 Assert.That(foundAssets, Is.EquivalentTo(expectedAssets));
859 }
860
861 /// <summary>
862 /// Test loading a multi-region OAR.
863 /// </summary>
864 [Test]
865 public void TestLoadMultiRegionOar()
866 {
867 TestHelpers.InMethod();
868
869 // Create an ArchiveScenesGroup with the regions in the OAR. This is needed to generate the control file.
870
871 int WIDTH = 2;
872 int HEIGHT = 2;
873
874 for (uint y = 0; y < HEIGHT; y++)
875 {
876 for (uint x = 0; x < WIDTH; x++)
877 {
878 Scene scene;
879 if (x == 0 && y == 0)
880 {
881 scene = m_scene; // this scene was already created in SetUp()
882 }
883 else
884 {
885 scene = m_sceneHelpers.SetupScene(string.Format("Unit test region {0}", (y * WIDTH) + x + 1), UUID.Random(), 1000 + x, 1000 + y);
886 SceneHelpers.SetupSceneModules(scene, new ArchiverModule(), m_serialiserModule, new TerrainModule());
887 }
888 }
889 }
890
891 ArchiveScenesGroup scenesGroup = new ArchiveScenesGroup();
892 SceneManager.Instance.ForEachScene(delegate(Scene scene)
893 {
894 scenesGroup.AddScene(scene);
895 });
896 scenesGroup.CalcSceneLocations();
897
898 // Generate the OAR file
899
900 MemoryStream archiveWriteStream = new MemoryStream();
901 TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream);
902
903 ArchiveWriteRequest writeRequest = new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty);
904 writeRequest.MultiRegionFormat = true;
905 tar.WriteFile(
906 ArchiveConstants.CONTROL_FILE_PATH, writeRequest.CreateControlFile(scenesGroup));
907
908 SceneObjectPart part1 = CreateSceneObjectPart1();
909 part1.SitTargetOrientation = new Quaternion(0.2f, 0.3f, 0.4f, 0.5f);
910 part1.SitTargetPosition = new Vector3(1, 2, 3);
911
912 SceneObjectGroup object1 = new SceneObjectGroup(part1);
913
914 // Let's put some inventory items into our object
915 string soundItemName = "sound-item1";
916 UUID soundItemUuid = UUID.Parse("00000000-0000-0000-0000-000000000002");
917 Type type = GetType();
918 Assembly assembly = type.Assembly;
919 string soundDataResourceName = null;
920 string[] names = assembly.GetManifestResourceNames();
921 foreach (string name in names)
922 {
923 if (name.EndsWith(".Resources.test-sound.wav"))
924 soundDataResourceName = name;
925 }
926 Assert.That(soundDataResourceName, Is.Not.Null);
927
928 byte[] soundData;
929 UUID soundUuid;
930 CreateSoundAsset(tar, assembly, soundDataResourceName, out soundData, out soundUuid);
931
932 TaskInventoryItem item1
933 = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName };
934 part1.Inventory.AddInventoryItem(item1, true);
935 m_scene.AddNewSceneObject(object1, false);
936
937 string object1FileName = string.Format(
938 "{0}_{1:000}-{2:000}-{3:000}__{4}.xml",
939 part1.Name,
940 Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z),
941 part1.UUID);
942 string path = "regions/1_1_Unit_test_region/" + ArchiveConstants.OBJECTS_PATH + object1FileName;
943 tar.WriteFile(path, SceneObjectSerializer.ToXml2Format(object1));
944
945 tar.Close();
946
947
948 // Delete the current objects, to test that they're loaded from the OAR and didn't
949 // just remain in the scene.
950 SceneManager.Instance.ForEachScene(delegate(Scene scene)
951 {
952 scene.DeleteAllSceneObjects();
953 });
954
955 // Create a "hole", to test that that the corresponding region isn't loaded from the OAR
956 SceneManager.Instance.CloseScene(SceneManager.Instance.Scenes[1]);
957
958
959 // Check thay the OAR file contains the expected data
960
961 MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray());
962
963 lock (this)
964 {
965 m_scene.EventManager.OnOarFileLoaded += LoadCompleted;
966 m_archiverModule.DearchiveRegion(archiveReadStream);
967 }
968
969 Assert.That(m_lastErrorMessage, Is.Null);
970
971 Assert.AreEqual(3, SceneManager.Instance.Scenes.Count);
972
973 TestLoadedRegion(part1, soundItemName, soundData);
974 }
975
708 } 976 }
709} 977}