diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Server/Handlers/Simulation/Utils.cs (renamed from OpenSim/Data/MySQL/Tests/MySQLGridTest.cs) | 97 |
1 files changed, 53 insertions, 44 deletions
diff --git a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs b/OpenSim/Server/Handlers/Simulation/Utils.cs index 8272316..ed379da 100644 --- a/OpenSim/Data/MySQL/Tests/MySQLGridTest.cs +++ b/OpenSim/Server/Handlers/Simulation/Utils.cs | |||
@@ -1,4 +1,4 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://opensimulator.org/ | 2 | * Copyright (c) Contributors, http://opensimulator.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
@@ -26,69 +26,78 @@ | |||
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | 28 | using System; |
29 | using NUnit.Framework; | 29 | using System.Collections.Generic; |
30 | using OpenSim.Data.Tests; | ||
31 | using log4net; | ||
32 | using System.Reflection; | 30 | using System.Reflection; |
33 | using OpenSim.Tests.Common; | ||
34 | using MySql.Data.MySqlClient; | ||
35 | 31 | ||
36 | namespace OpenSim.Data.MySQL.Tests | 32 | using OpenMetaverse; |
33 | using OpenMetaverse.StructuredData; | ||
34 | |||
35 | using log4net; | ||
36 | |||
37 | namespace OpenSim.Server.Handlers.Simulation | ||
37 | { | 38 | { |
38 | [TestFixture, DatabaseTest] | 39 | public class Utils |
39 | public class MySQLGridTest : BasicGridTest | ||
40 | { | 40 | { |
41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 41 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
42 | 42 | ||
43 | public string file; | 43 | /// <summary> |
44 | public MySQLManager database; | 44 | /// Extract the param from an uri. |
45 | public string connect = "Server=localhost;Port=3306;Database=opensim-nunit;User ID=opensim-nunit;Password=opensim-nunit;Pooling=false;"; | 45 | /// </summary> |
46 | 46 | /// <param name="uri">Something like this: /agent/uuid/ or /agent/uuid/handle/release</param> | |
47 | [TestFixtureSetUp] | 47 | /// <param name="uri">uuid on uuid field</param> |
48 | public void Init() | 48 | /// <param name="action">optional action</param> |
49 | public static bool GetParams(string uri, out UUID uuid, out UUID regionID, out string action) | ||
49 | { | 50 | { |
50 | SuperInit(); | 51 | uuid = UUID.Zero; |
51 | // If we manage to connect to the database with the user | 52 | regionID = UUID.Zero; |
52 | // and password above it is our test database, and run | 53 | action = ""; |
53 | // these tests. If anything goes wrong, ignore these | 54 | |
54 | // tests. | 55 | uri = uri.Trim(new char[] { '/' }); |
55 | try | 56 | string[] parts = uri.Split('/'); |
57 | if (parts.Length <= 1) | ||
56 | { | 58 | { |
57 | database = new MySQLManager(connect); | 59 | return false; |
58 | db = new MySQLGridData(); | ||
59 | db.Initialise(connect); | ||
60 | } | 60 | } |
61 | catch (Exception e) | 61 | else |
62 | { | 62 | { |
63 | m_log.Error("Exception {0}", e); | 63 | if (!UUID.TryParse(parts[1], out uuid)) |
64 | Assert.Ignore(); | 64 | return false; |
65 | } | ||
66 | 65 | ||
67 | // This actually does the roll forward assembly stuff | 66 | if (parts.Length >= 3) |
68 | Assembly assem = GetType().Assembly; | 67 | UUID.TryParse(parts[2], out regionID); |
68 | if (parts.Length >= 4) | ||
69 | action = parts[3]; | ||
69 | 70 | ||
70 | using (MySqlConnection dbcon = new MySqlConnection(connect)) | 71 | return true; |
71 | { | ||
72 | dbcon.Open(); | ||
73 | Migration m = new Migration(dbcon, assem, "AssetStore"); | ||
74 | m.Update(); | ||
75 | } | 72 | } |
76 | } | 73 | } |
77 | 74 | ||
78 | [TestFixtureTearDown] | 75 | public static OSDMap GetOSDMap(string data) |
79 | public void Cleanup() | ||
80 | { | 76 | { |
81 | m_log.Warn("Cleaning up."); | 77 | OSDMap args = null; |
82 | if (db != null) | 78 | try |
83 | { | 79 | { |
84 | db.Dispose(); | 80 | OSD buffer; |
81 | // We should pay attention to the content-type, but let's assume we know it's Json | ||
82 | buffer = OSDParser.DeserializeJson(data); | ||
83 | if (buffer.Type == OSDType.Map) | ||
84 | { | ||
85 | args = (OSDMap)buffer; | ||
86 | return args; | ||
87 | } | ||
88 | else | ||
89 | { | ||
90 | // uh? | ||
91 | m_log.Debug(("[REST COMMS]: Got OSD of unexpected type " + buffer.Type.ToString())); | ||
92 | return null; | ||
93 | } | ||
85 | } | 94 | } |
86 | // if a new table is added, it has to be dropped here | 95 | catch (Exception ex) |
87 | if (database != null) | ||
88 | { | 96 | { |
89 | database.ExecuteSql("drop table migrations"); | 97 | m_log.Debug("[REST COMMS]: exception on parse of REST message " + ex.Message); |
90 | database.ExecuteSql("drop table regions"); | 98 | return null; |
91 | } | 99 | } |
92 | } | 100 | } |
101 | |||
93 | } | 102 | } |
94 | } | 103 | } |