GridClient.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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.Text;
  30. using System.Reflection;
  31. using OpenMetaverse;
  32. using NUnit.Framework;
  33. using OpenSim.Framework;
  34. using OpenSim.Services.Interfaces;
  35. using GridRegion = OpenSim.Services.Interfaces.GridRegion;
  36. using OpenSim.Services.Connectors;
  37. namespace Robust.Tests
  38. {
  39. [TestFixture]
  40. public class GridClient
  41. {
  42. // private static readonly ILog m_log =
  43. // LogManager.GetLogger(
  44. // MethodBase.GetCurrentMethod().DeclaringType);
  45. [Test]
  46. public void Grid_001()
  47. {
  48. GridServicesConnector m_Connector = new GridServicesConnector(DemonServer.Address);
  49. GridRegion r1 = CreateRegion("Test Region 1", 1000, 1000);
  50. GridRegion r2 = CreateRegion("Test Region 2", 1001, 1000);
  51. GridRegion r3 = CreateRegion("Test Region 3", 1005, 1000);
  52. string msg = m_Connector.RegisterRegion(UUID.Zero, r1);
  53. Assert.AreEqual(msg, string.Empty, "Region 1 failed to register");
  54. msg = m_Connector.RegisterRegion(UUID.Zero, r2);
  55. Assert.AreEqual(msg, string.Empty, "Region 2 failed to register");
  56. msg = m_Connector.RegisterRegion(UUID.Zero, r3);
  57. Assert.AreEqual(msg, string.Empty, "Region 3 failed to register");
  58. bool success;
  59. success = m_Connector.DeregisterRegion(r3.RegionID);
  60. Assert.AreEqual(success, true, "Region 3 failed to deregister");
  61. msg = m_Connector.RegisterRegion(UUID.Zero, r3);
  62. Assert.AreEqual(msg, string.Empty, "Region 3 failed to re-register");
  63. List<GridRegion> regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID);
  64. Assert.AreNotEqual(regions, null, "GetNeighbours of region 1 failed");
  65. Assert.AreEqual(regions.Count, 1, "Region 1 should have 1 neighbor");
  66. Assert.AreEqual(regions[0].RegionName, "Test Region 2", "Region 1 has the wrong neighbor");
  67. GridRegion region = m_Connector.GetRegionByUUID(UUID.Zero, r2.RegionID);
  68. Assert.AreNotEqual(region, null, "GetRegionByUUID for region 2 failed");
  69. Assert.AreEqual(region.RegionName, "Test Region 2", "GetRegionByUUID of region 2 returned wrong region");
  70. region = m_Connector.GetRegionByUUID(UUID.Zero, UUID.Random());
  71. Assert.AreEqual(region, null, "Region with randon id should not exist");
  72. region = m_Connector.GetRegionByName(UUID.Zero, r3.RegionName);
  73. Assert.AreNotEqual(region, null, "GetRegionByUUID for region 3 failed");
  74. Assert.AreEqual(region.RegionName, "Test Region 3", "GetRegionByUUID of region 3 returned wrong region");
  75. region = m_Connector.GetRegionByName(UUID.Zero, "Foo");
  76. Assert.AreEqual(region, null, "Region Foo should not exist");
  77. regions = m_Connector.GetRegionsByName(UUID.Zero, "Test", 10);
  78. Assert.AreNotEqual(regions, null, "GetRegionsByName failed");
  79. Assert.AreEqual(regions.Count, 3, "GetRegionsByName should return 3");
  80. regions = m_Connector.GetRegionRange(UUID.Zero,
  81. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002),
  82. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(1002) );
  83. Assert.AreNotEqual(regions, null, "GetRegionRange failed");
  84. Assert.AreEqual(regions.Count, 2, "GetRegionRange should return 2");
  85. regions = m_Connector.GetRegionRange(UUID.Zero,
  86. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950),
  87. (int)Util.RegionToWorldLoc(900), (int)Util.RegionToWorldLoc(950) );
  88. Assert.AreNotEqual(regions, null, "GetRegionRange (bis) failed");
  89. Assert.AreEqual(regions.Count, 0, "GetRegionRange (bis) should return 0");
  90. // Deregister them all
  91. success = m_Connector.DeregisterRegion(r1.RegionID);
  92. Assert.AreEqual(success, true, "Region 1 failed to deregister");
  93. success = m_Connector.DeregisterRegion(r2.RegionID);
  94. Assert.AreEqual(success, true, "Region 2 failed to deregister");
  95. success = m_Connector.DeregisterRegion(r3.RegionID);
  96. Assert.AreEqual(success, true, "Region 3 failed to deregister");
  97. }
  98. private static GridRegion CreateRegion(string name, uint xcell, uint ycell)
  99. {
  100. GridRegion region = new GridRegion(xcell, ycell);
  101. region.RegionName = name;
  102. region.RegionID = UUID.Random();
  103. region.ExternalHostName = "127.0.0.1";
  104. region.HttpPort = 9000;
  105. region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 9000);
  106. return region;
  107. }
  108. }
  109. }