OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
GridConnectorsTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using System.IO;
31 using System.Reflection;
32 using System.Threading;
33 using log4net.Config;
34 using Nini.Config;
35 using NUnit.Framework;
36 using OpenMetaverse;
37 
38 using OpenSim.Framework;
39 using OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid;
40 using OpenSim.Region.Framework.Scenes;
42 using OpenSim.Tests.Common;
43 
44 namespace OpenSim.Region.CoreModules.ServiceConnectorsOut.Grid.Tests
45 {
46  [TestFixture]
48  {
49  LocalGridServicesConnector m_LocalConnector;
50 
51  [SetUp]
52  public override void SetUp()
53  {
54  base.SetUp();
55 
56  IConfigSource config = new IniConfigSource();
57  config.AddConfig("Modules");
58  config.AddConfig("GridService");
59  config.Configs["Modules"].Set("GridServices", "LocalGridServicesConnector");
60  config.Configs["GridService"].Set("LocalServiceModule", "OpenSim.Services.GridService.dll:GridService");
61  config.Configs["GridService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
62  config.Configs["GridService"].Set("Region_Test_Region_1", "DefaultRegion");
63  config.Configs["GridService"].Set("Region_Test_Region_2", "FallbackRegion");
64  config.Configs["GridService"].Set("Region_Test_Region_3", "FallbackRegion");
65  config.Configs["GridService"].Set("Region_Other_Region_4", "FallbackRegion");
66 
67  m_LocalConnector = new LocalGridServicesConnector(config);
68  }
69 
73  [Test]
74  public void TestRegisterRegion()
75  {
76  TestHelpers.InMethod();
77 // log4net.Config.XmlConfigurator.Configure();
78 
79  // Create 4 regions
80  GridRegion r1 = new GridRegion();
81  r1.RegionName = "Test Region 1";
82  r1.RegionID = new UUID(1);
83  r1.RegionLocX = 1000 * (int)Constants.RegionSize;
84  r1.RegionLocY = 1000 * (int)Constants.RegionSize;
85  r1.ExternalHostName = "127.0.0.1";
86  r1.HttpPort = 9001;
87  r1.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
88  Scene s = new Scene(new RegionInfo());
89  s.RegionInfo.RegionID = r1.RegionID;
90  m_LocalConnector.AddRegion(s);
91 
92  GridRegion r2 = new GridRegion();
93  r2.RegionName = "Test Region 2";
94  r2.RegionID = new UUID(2);
95  r2.RegionLocX = 1001 * (int)Constants.RegionSize;
96  r2.RegionLocY = 1000 * (int)Constants.RegionSize;
97  r2.ExternalHostName = "127.0.0.1";
98  r2.HttpPort = 9002;
99  r2.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
100  s = new Scene(new RegionInfo());
101  s.RegionInfo.RegionID = r2.RegionID;
102  m_LocalConnector.AddRegion(s);
103 
104  GridRegion r3 = new GridRegion();
105  r3.RegionName = "Test Region 3";
106  r3.RegionID = new UUID(3);
107  r3.RegionLocX = 1005 * (int)Constants.RegionSize;
108  r3.RegionLocY = 1000 * (int)Constants.RegionSize;
109  r3.ExternalHostName = "127.0.0.1";
110  r3.HttpPort = 9003;
111  r3.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
112  s = new Scene(new RegionInfo());
113  s.RegionInfo.RegionID = r3.RegionID;
114  m_LocalConnector.AddRegion(s);
115 
116  GridRegion r4 = new GridRegion();
117  r4.RegionName = "Other Region 4";
118  r4.RegionID = new UUID(4);
119  r4.RegionLocX = 1004 * (int)Constants.RegionSize;
120  r4.RegionLocY = 1002 * (int)Constants.RegionSize;
121  r4.ExternalHostName = "127.0.0.1";
122  r4.HttpPort = 9004;
123  r4.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
124  s = new Scene(new RegionInfo());
125  s.RegionInfo.RegionID = r4.RegionID;
126  m_LocalConnector.AddRegion(s);
127 
128  m_LocalConnector.RegisterRegion(UUID.Zero, r1);
129 
130  GridRegion result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test");
131  Assert.IsNull(result, "Retrieved GetRegionByName \"Test\" is not null");
132 
133  result = m_LocalConnector.GetRegionByName(UUID.Zero, "Test Region 1");
134  Assert.IsNotNull(result, "Retrieved GetRegionByName is null");
135  Assert.That(result.RegionName, Is.EqualTo("Test Region 1"), "Retrieved region's name does not match");
136 
137  m_LocalConnector.RegisterRegion(UUID.Zero, r2);
138  m_LocalConnector.RegisterRegion(UUID.Zero, r3);
139  m_LocalConnector.RegisterRegion(UUID.Zero, r4);
140 
141  result = m_LocalConnector.GetRegionByUUID(UUID.Zero, new UUID(1));
142  Assert.IsNotNull(result, "Retrieved GetRegionByUUID is null");
143  Assert.That(result.RegionID, Is.EqualTo(new UUID(1)), "Retrieved region's UUID does not match");
144 
145  result = m_LocalConnector.GetRegionByPosition(UUID.Zero, (int)Util.RegionToWorldLoc(1000), (int)Util.RegionToWorldLoc(1000));
146  Assert.IsNotNull(result, "Retrieved GetRegionByPosition is null");
147  Assert.That(result.RegionLocX, Is.EqualTo(1000 * (int)Constants.RegionSize), "Retrieved region's position does not match");
148 
149  List<GridRegion> results = m_LocalConnector.GetNeighbours(UUID.Zero, new UUID(1));
150  Assert.IsNotNull(results, "Retrieved neighbours list is null");
151  Assert.That(results.Count, Is.EqualTo(1), "Retrieved neighbour collection is greater than expected");
152  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved region's UUID does not match");
153 
154  results = m_LocalConnector.GetRegionsByName(UUID.Zero, "Test", 10);
155  Assert.IsNotNull(results, "Retrieved GetRegionsByName collection is null");
156  Assert.That(results.Count, Is.EqualTo(3), "Retrieved neighbour collection is less than expected");
157 
158  results = m_LocalConnector.GetRegionRange(UUID.Zero, 900 * (int)Constants.RegionSize, 1002 * (int)Constants.RegionSize,
159  900 * (int)Constants.RegionSize, 1100 * (int)Constants.RegionSize);
160  Assert.IsNotNull(results, "Retrieved GetRegionRange collection is null");
161  Assert.That(results.Count, Is.EqualTo(2), "Retrieved neighbour collection is not the number expected");
162 
163  results = m_LocalConnector.GetDefaultRegions(UUID.Zero);
164  Assert.IsNotNull(results, "Retrieved GetDefaultRegions collection is null");
165  Assert.That(results.Count, Is.EqualTo(1), "Retrieved default regions collection has not the expected size");
166  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(1)), "Retrieved default region's UUID does not match");
167 
168  results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r1.RegionLocX, r1.RegionLocY);
169  Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 1 is null");
170  Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 1 has not the expected size");
171  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions for default region are not in the expected order 2-4-3");
172  Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions for default region are not in the expected order 2-4-3");
173  Assert.That(results[2].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions for default region are not in the expected order 2-4-3");
174 
175  results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r2.RegionLocX, r2.RegionLocY);
176  Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 2 is null");
177  Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 2 has not the expected size");
178  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 2-4-3");
179  Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 2-4-3");
180  Assert.That(results[2].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 2-4-3");
181 
182  results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r3.RegionLocX, r3.RegionLocY);
183  Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 3 is null");
184  Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 3 has not the expected size");
185  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 3-4-2");
186  Assert.That(results[1].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 3-4-2");
187  Assert.That(results[2].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 3-4-2");
188 
189  results = m_LocalConnector.GetFallbackRegions(UUID.Zero, r4.RegionLocX, r4.RegionLocY);
190  Assert.IsNotNull(results, "Retrieved GetFallbackRegions collection for region 4 is null");
191  Assert.That(results.Count, Is.EqualTo(3), "Retrieved fallback regions collection for region 4 has not the expected size");
192  Assert.That(results[0].RegionID, Is.EqualTo(new UUID(4)), "Retrieved fallback regions are not in the expected order 4-3-2");
193  Assert.That(results[1].RegionID, Is.EqualTo(new UUID(3)), "Retrieved fallback regions are not in the expected order 4-3-2");
194  Assert.That(results[2].RegionID, Is.EqualTo(new UUID(2)), "Retrieved fallback regions are not in the expected order 4-3-2");
195 
196  results = m_LocalConnector.GetHyperlinks(UUID.Zero);
197  Assert.IsNotNull(results, "Retrieved GetHyperlinks list is null");
198  Assert.That(results.Count, Is.EqualTo(0), "Retrieved linked regions collection is not the number expected");
199  }
200  }
201 }
OpenSim.Framework.RegionInfo RegionInfo
Interactive OpenSim region server
Definition: OpenSim.cs:55
OpenSim.Services.Interfaces.GridRegion GridRegion
OpenSim.Services.Interfaces.GridRegion GridRegion