GridConnectorsTests.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using log4net.Config;
  33. using NUnit.Framework;
  34. using NUnit.Framework.SyntaxHelpers;
  35. using OpenMetaverse;
  36. using OpenSim.Framework;
  37. using Nini.Config;
  38. using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
  39. using OpenSim.Region.Framework.Scenes;
  40. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  41. using OpenSim.Tests.Common;
  42. using OpenSim.Tests.Common.Setup;
  43. namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
  44. {
  45. [TestFixture]
  46. public class GridConnectorsTests
  47. {
  48. LocalGridServicesConnector m_LocalConnector;
  49. private void SetUp()
  50. {
  51. IConfigSource config = new IniConfigSource();
  52. config.AddConfig("Modules");
  53. config.AddConfig("GridService");
  54. config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
  55. config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
  56. config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll:NullRegionData");
  57. m_LocalConnector = new LocalGridServicesConnector(config);
  58. }
  59. /// <summary>
  60. /// Test saving a V0.2 OpenSim Region Archive.
  61. /// </summary>
  62. [Test]
  63. public void TestRegisterRegionV0_2()
  64. {
  65. SetUp();
  66. // Create 3 regions
  67. GridRegion r1 = new GridRegion();
  68. r1.RegionName = "Test Region 1";
  69. r1.RegionID = new UUID(1);
  70. r1.RegionLocX = 1000 * (int)Constants.RegionSize;
  71. r1.RegionLocY = 1000 * (int)Constants.RegionSize;
  72. r1.ExternalHostName = "127.0.0.1";
  73. r1.HttpPort = 9001;
  74. r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
  75. Scene s = new Scene(new RegionInfo());
  76. s.RegionInfo.RegionID = r1.RegionID;
  77. m_LocalConnector.AddRegion(s);
  78. GridRegion r2 = new GridRegion();
  79. r2.RegionName = "Test Region 2";
  80. r2.RegionID = new UUID(2);
  81. r2.RegionLocX = 1001 * (int)Constants.RegionSize;
  82. r2.RegionLocY = 1000 * (int)Constants.RegionSize;
  83. r2.ExternalHostName = "127.0.0.1";
  84. r2.HttpPort = 9002;
  85. r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
  86. s = new Scene(new RegionInfo());
  87. s.RegionInfo.RegionID = r1.RegionID;
  88. m_LocalConnector.AddRegion(s);
  89. GridRegion r3 = new GridRegion();
  90. r3.RegionName = "Test Region 3";
  91. r3.RegionID = new UUID(3);
  92. r3.RegionLocX = 1005 * (int)Constants.RegionSize;
  93. r3.RegionLocY = 1000 * (int)Constants.RegionSize;
  94. r3.ExternalHostName = "127.0.0.1";
  95. r3.HttpPort = 9003;
  96. r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
  97. s = new Scene(new RegionInfo());
  98. s.RegionInfo.RegionID = r1.RegionID;
  99. m_LocalConnector.AddRegion(s);
  100. m_LocalConnector.RegisterRegion(UUID.Zero, r1);
  101. GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test");
  102. Assert.IsNotNull(result, "Retrieved GetRegionByName is null");
  103. Assert.That(result.RegionName, Is.EqualTo("Test Region 1"), "Retrieved region's name does not match");
  104. result = m_LocalConnector.GetRegionByUUID(UUID.Zero, new UUID(1));
  105. Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null");
  106. Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match");
  107. result = m_LocalConnector.GetRegionByPosition(UUID.Zero, 1000 * (int)Constants.RegionSize, 1000 * (int)Constants.RegionSize);
  108. Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null");
  109. Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match");
  110. m_LocalConnector.RegisterRegion(UUID.Zero, r2);
  111. m_LocalConnector.RegisterRegion(UUID.Zero, r3);
  112. List<GridRegion> results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1));
  113. Assert.IsNotNull(results, "Retrieved neighbours list is null");
  114. Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected");
  115. Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved region's UUID does not match");
  116. results = m_LocalConnector.GetRegionsByName(UUID.Zero, "Test", 10);
  117. Assert.IsNotNull(results, "Retrieved GetRegionsByName list is null");
  118. Assert.That(results.Count, Is.EqualTo(3), "Retrieved neighbour collection is less than expected");
  119. results = m_LocalConnector.GetRegionRange(UUID.Zero, 900 * (int)Constants.RegionSize, 1002 * (int)Constants.RegionSize,
  120. 900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize);
  121. Assert.IsNotNull(results, "Retrieved GetRegionRange list is null");
  122. Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected");
  123. }
  124. }
  125. }