Added test GridClient, which allowed me to remove a few bugs out of the new code.
parent
ad753d784c
commit
dd3d52ae1f
|
@ -56,14 +56,14 @@ namespace OpenSim.Framework.Servers.HttpServer
|
|||
request.ContentType = "text/www-form-urlencoded";
|
||||
|
||||
MemoryStream buffer = new MemoryStream();
|
||||
|
||||
int length = 0;
|
||||
using (StreamWriter writer = new StreamWriter(buffer))
|
||||
{
|
||||
writer.WriteLine(obj);
|
||||
writer.Flush();
|
||||
length = (int)buffer.Length;
|
||||
}
|
||||
|
||||
int length = (int) buffer.Length;
|
||||
request.ContentLength = length;
|
||||
|
||||
Stream requestStream = request.GetRequestStream();
|
||||
|
|
|
@ -258,6 +258,8 @@ namespace OpenSim.Server.Base
|
|||
|
||||
public static Dictionary<string, object> ParseXmlResponse(string data)
|
||||
{
|
||||
//m_log.DebugFormat("[XXX]: received xml string: {0}", data);
|
||||
|
||||
Dictionary<string, object> ret = new Dictionary<string, object>();
|
||||
|
||||
XmlDocument doc = new XmlDocument();
|
||||
|
@ -284,7 +286,7 @@ namespace OpenSim.Server.Base
|
|||
|
||||
foreach (XmlNode part in partL)
|
||||
{
|
||||
XmlNode type = part.Attributes.GetNamedItem("Type");
|
||||
XmlNode type = part.Attributes.GetNamedItem("type");
|
||||
if (type == null || type.Value != "List")
|
||||
{
|
||||
ret[part.Name] = part.InnerText;
|
||||
|
|
|
@ -45,7 +45,7 @@ namespace OpenSim.Server.Handlers.Grid
|
|||
if (serverConfig == null)
|
||||
throw new Exception("No section 'Server' in config file");
|
||||
|
||||
string gridService = serverConfig.GetString("GridServiceModule",
|
||||
string gridService = serverConfig.GetString("LocalServiceModule",
|
||||
String.Empty);
|
||||
|
||||
if (gridService == String.Empty)
|
||||
|
|
|
@ -63,6 +63,7 @@ namespace OpenSim.Server.Handlers.Grid
|
|||
StreamReader sr = new StreamReader(requestData);
|
||||
string body = sr.ReadToEnd();
|
||||
sr.Close();
|
||||
body = body.Trim();
|
||||
|
||||
Dictionary<string, string> request =
|
||||
ServerUtils.ParseQueryString(body);
|
||||
|
@ -98,11 +99,11 @@ namespace OpenSim.Server.Handlers.Grid
|
|||
case "get_region_range":
|
||||
return GetRegionRange(request);
|
||||
|
||||
default:
|
||||
m_log.DebugFormat("[GRID HANDLER]: unknown method request {0}", method);
|
||||
return FailureResult();
|
||||
}
|
||||
|
||||
m_log.DebugFormat("[GRID HANDLER XXX]: unknown method {0} request {1}", method.Length, method);
|
||||
return FailureResult();
|
||||
|
||||
}
|
||||
|
||||
#region Method-specific handlers
|
||||
|
@ -155,11 +156,12 @@ namespace OpenSim.Server.Handlers.Grid
|
|||
|
||||
UUID regionID = UUID.Zero;
|
||||
if (request["REGIONID"] != null)
|
||||
UUID.TryParse(request["REGIONID"], out scopeID);
|
||||
UUID.TryParse(request["REGIONID"], out regionID);
|
||||
else
|
||||
m_log.WarnFormat("[GRID HANDLER]: no regionID in request to get neighbours");
|
||||
|
||||
List<GridRegion> rinfos = m_GridService.GetNeighbours(scopeID, regionID);
|
||||
//m_log.DebugFormat("[GRID HANDLER]: neighbours for region {0}: {1}", regionID, rinfos.Count);
|
||||
|
||||
Dictionary<string, object> result = new Dictionary<string, object>();
|
||||
int i = 0;
|
||||
|
@ -171,6 +173,7 @@ namespace OpenSim.Server.Handlers.Grid
|
|||
}
|
||||
|
||||
string xmlString = ServerUtils.BuildXmlResponse(result);
|
||||
//m_log.DebugFormat("[GRID HANDLER]: resp string: {0}", xmlString);
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetBytes(xmlString);
|
||||
|
||||
|
|
|
@ -97,9 +97,11 @@ namespace OpenSim.Services.Connectors
|
|||
|
||||
sendData["METHOD"] = "register";
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
m_log.DebugFormat("[GRID CONNECTOR]: queryString = {0}", reqString);
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/grid",
|
||||
ServerUtils.BuildQueryString(sendData));
|
||||
reqString);
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
|
@ -138,9 +140,10 @@ namespace OpenSim.Services.Connectors
|
|||
|
||||
sendData["METHOD"] = "get_neighbours";
|
||||
|
||||
string reqString = ServerUtils.BuildQueryString(sendData);
|
||||
string reply = SynchronousRestFormsRequester.MakeRequest("POST",
|
||||
m_ServerURI + "/grid",
|
||||
ServerUtils.BuildQueryString(sendData));
|
||||
reqString);
|
||||
|
||||
Dictionary<string, object> replyData = ServerUtils.ParseXmlResponse(reply);
|
||||
|
||||
|
@ -148,6 +151,7 @@ namespace OpenSim.Services.Connectors
|
|||
if (replyData != null)
|
||||
{
|
||||
Dictionary<string, object>.ValueCollection rinfosList = replyData.Values;
|
||||
m_log.DebugFormat("[GRID CONNECTOR]: get neighbours returned {0} elements", rinfosList.Count);
|
||||
foreach (object r in rinfosList)
|
||||
{
|
||||
if (r is Dictionary<string, object>)
|
||||
|
@ -156,8 +160,8 @@ namespace OpenSim.Services.Connectors
|
|||
rinfos.Add(rinfo);
|
||||
}
|
||||
else
|
||||
m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response",
|
||||
scopeID, regionID);
|
||||
m_log.DebugFormat("[GRID CONNECTOR]: GetNeighbours {0}, {1} received invalid response type {2}",
|
||||
scopeID, regionID, r.GetType());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -277,6 +277,15 @@ namespace OpenSim.Services.Interfaces
|
|||
|
||||
public GridRegion(Dictionary<string, object> kvp)
|
||||
{
|
||||
if (kvp["uuid"] != null)
|
||||
RegionID = new UUID((string)kvp["uuid"]);
|
||||
|
||||
if (kvp["locX"] != null)
|
||||
RegionLocX = Convert.ToInt32((string)kvp["locX"]);
|
||||
|
||||
if (kvp["locY"] != null)
|
||||
RegionLocY = Convert.ToInt32((string)kvp["locY"]);
|
||||
|
||||
if ((kvp["external_ip_address"] != null) && (kvp["external_port"] != null))
|
||||
{
|
||||
int port = 0;
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
|
||||
using OpenMetaverse;
|
||||
using log4net;
|
||||
using log4net.Appender;
|
||||
using log4net.Layout;
|
||||
|
||||
using OpenSim.Framework;
|
||||
using OpenSim.Services.Interfaces;
|
||||
using GridRegion = OpenSim.Services.Interfaces.GridRegion;
|
||||
using OpenSim.Services.Connectors;
|
||||
|
||||
namespace OpenSim.Tests.Clients.GridClient
|
||||
{
|
||||
public class GridClient
|
||||
{
|
||||
private static readonly ILog m_log =
|
||||
LogManager.GetLogger(
|
||||
MethodBase.GetCurrentMethod().DeclaringType);
|
||||
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
ConsoleAppender consoleAppender = new ConsoleAppender();
|
||||
consoleAppender.Layout =
|
||||
new PatternLayout("%date [%thread] %-5level %logger [%property{NDC}] - %message%newline");
|
||||
log4net.Config.BasicConfigurator.Configure(consoleAppender);
|
||||
|
||||
string serverURI = "http://127.0.0.1:8002";
|
||||
GridServicesConnector m_Connector = new GridServicesConnector(serverURI);
|
||||
|
||||
GridRegion r1 = CreateRegion("Test Region 1", 1000, 1000);
|
||||
GridRegion r2 = CreateRegion("Test Region 2", 1001, 1000);
|
||||
GridRegion r3 = CreateRegion("Test Region 3", 1005, 1000);
|
||||
|
||||
Console.WriteLine("[GRID CLIENT]: Registering region 1");
|
||||
bool success = m_Connector.RegisterRegion(UUID.Zero, r1);
|
||||
if (success)
|
||||
Console.WriteLine("[GRID CLIENT]: Successfully registered region 1");
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: region 1 failed to register");
|
||||
|
||||
Console.WriteLine("[GRID CLIENT]: Registering region 2");
|
||||
success = m_Connector.RegisterRegion(UUID.Zero, r2);
|
||||
if (success)
|
||||
Console.WriteLine("[GRID CLIENT]: Successfully registered region 2");
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: region 2 failed to register");
|
||||
|
||||
Console.WriteLine("[GRID CLIENT]: Registering region 3");
|
||||
success = m_Connector.RegisterRegion(UUID.Zero, r3);
|
||||
if (success)
|
||||
Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
|
||||
|
||||
|
||||
Console.WriteLine("[GRID CLIENT]: Deregistering region 3");
|
||||
success = m_Connector.DeregisterRegion(r3.RegionID);
|
||||
if (success)
|
||||
Console.WriteLine("[GRID CLIENT]: Successfully deregistered region 3");
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: region 3 failed to deregister");
|
||||
Console.WriteLine("[GRID CLIENT]: Registering region 3 again");
|
||||
success = m_Connector.RegisterRegion(UUID.Zero, r3);
|
||||
if (success)
|
||||
Console.WriteLine("[GRID CLIENT]: Successfully registered region 3");
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: region 3 failed to register");
|
||||
|
||||
Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1");
|
||||
List<GridRegion> regions = m_Connector.GetNeighbours(UUID.Zero, r1.RegionID);
|
||||
if (regions == null)
|
||||
Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 failed");
|
||||
else if (regions.Count > 0)
|
||||
{
|
||||
if (regions.Count != 1)
|
||||
Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned more neighbours than expected: " + regions.Count);
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned the right neighbour " + regions[0].RegionName);
|
||||
}
|
||||
else
|
||||
Console.WriteLine("[GRID CLIENT]: GetNeighbours of region 1 returned 0 neighbours");
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static GridRegion CreateRegion(string name, uint xcell, uint ycell)
|
||||
{
|
||||
GridRegion region = new GridRegion(xcell, ycell);
|
||||
region.RegionName = name;
|
||||
region.RegionID = UUID.Random();
|
||||
region.ExternalHostName = "127.0.0.1";
|
||||
region.HttpPort = 9000;
|
||||
region.InternalEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse("0.0.0.0"), 0);
|
||||
|
||||
return region;
|
||||
}
|
||||
}
|
||||
}
|
29
prebuild.xml
29
prebuild.xml
|
@ -3221,6 +3221,35 @@
|
|||
</Files>
|
||||
</Project>
|
||||
|
||||
<!-- Test Clients -->
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Tests.Clients.GridClient" path="OpenSim/Tests/Clients/Grid" type="Exe">
|
||||
<Configuration name="Debug">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
<Configuration name="Release">
|
||||
<Options>
|
||||
<OutputPath>../../../../bin/</OutputPath>
|
||||
</Options>
|
||||
</Configuration>
|
||||
|
||||
<ReferencePath>../../../../bin/</ReferencePath>
|
||||
<Reference name="System"/>
|
||||
<Reference name="OpenMetaverseTypes.dll"/>
|
||||
<Reference name="OpenMetaverse.dll"/>
|
||||
<Reference name="OpenSim.Framework"/>
|
||||
<Reference name="OpenSim.Services.Interfaces" />
|
||||
<Reference name="OpenSim.Services.Connectors" />
|
||||
<Reference name="Nini.dll" />
|
||||
<Reference name="log4net.dll"/>
|
||||
|
||||
<Files>
|
||||
<Match pattern="*.cs" recurse="true"/>
|
||||
</Files>
|
||||
</Project>
|
||||
|
||||
|
||||
<!-- Test assemblies -->
|
||||
<Project frameworkVersion="v3_5" name="OpenSim.Tests.Common" path="OpenSim/Tests/Common" type="Library">
|
||||
<Configuration name="Debug">
|
||||
|
|
Loading…
Reference in New Issue