clockwerk-opensim – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 log4net.Config;
31 using NUnit.Framework;
32 using NUnit.Framework.Constraints;
33 using OpenMetaverse;
34 using OpenSim.Framework;
35 using OpenSim.Tests.Common;
36 using System.Data.Common;
37 using log4net;
38  
39 // DBMS-specific:
40 using MySql.Data.MySqlClient;
41 using OpenSim.Data.MySQL;
42  
43 using System.Data.SqlClient;
44 using OpenSim.Data.MSSQL;
45  
46 using Mono.Data.Sqlite;
47 using OpenSim.Data.SQLite;
48  
49 namespace OpenSim.Data.Tests
50 {
51 [TestFixture(Description = "Asset store tests (SQLite)")]
52 public class SQLiteAssetTests : AssetTests<SqliteConnection, SQLiteAssetData>
53 {
54 }
55  
56 [TestFixture(Description = "Asset store tests (MySQL)")]
57 public class MySqlAssetTests : AssetTests<MySqlConnection, MySQLAssetData>
58 {
59 }
60  
61 [TestFixture(Description = "Asset store tests (MS SQL Server)")]
62 public class MSSQLAssetTests : AssetTests<SqlConnection, MSSQLAssetData>
63 {
64 }
65  
66 public class AssetTests<TConn, TAssetData> : BasicDataServiceTest<TConn, TAssetData>
67 where TConn : DbConnection, new()
68 where TAssetData : AssetDataBase, new()
69 {
70 TAssetData m_db;
71  
72 public UUID uuid1 = UUID.Random();
73 public UUID uuid2 = UUID.Random();
74 public UUID uuid3 = UUID.Random();
75  
76 public string critter1 = UUID.Random().ToString();
77 public string critter2 = UUID.Random().ToString();
78 public string critter3 = UUID.Random().ToString();
79  
80 public byte[] data1 = new byte[100];
81  
82 PropertyScrambler<AssetBase> scrambler = new PropertyScrambler<AssetBase>()
83 .DontScramble(x => x.ID)
84 .DontScramble(x => x.Type)
85 .DontScramble(x => x.FullID)
86 .DontScramble(x => x.Metadata.ID)
87 .DontScramble(x => x.Metadata.CreatorID)
88 .DontScramble(x => x.Metadata.ContentType)
89 .DontScramble(x => x.Metadata.FullID)
90 .DontScramble(x => x.Data);
91  
92 protected override void InitService(object service)
93 {
94 ClearDB();
95 m_db = (TAssetData)service;
96 m_db.Initialise(m_connStr);
97 }
98  
99 private void ClearDB()
100 {
101 DropTables("assets");
102 ResetMigrations("AssetStore");
103 }
104  
105  
106 [Test]
107 public void T001_LoadEmpty()
108 {
109 TestHelpers.InMethod();
110  
111 bool[] exist = m_db.AssetsExist(new[] { uuid1, uuid2, uuid3 });
112 Assert.IsFalse(exist[0]);
113 Assert.IsFalse(exist[1]);
114 Assert.IsFalse(exist[2]);
115 }
116  
117 [Test]
118 public void T010_StoreReadVerifyAssets()
119 {
120 TestHelpers.InMethod();
121  
122 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1.ToString());
123 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, critter2.ToString());
124 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, critter3.ToString());
125 a1.Data = data1;
126 a2.Data = data1;
127 a3.Data = data1;
128  
129 scrambler.Scramble(a1);
130 scrambler.Scramble(a2);
131 scrambler.Scramble(a3);
132  
133 m_db.StoreAsset(a1);
134 m_db.StoreAsset(a2);
135 m_db.StoreAsset(a3);
136  
137 AssetBase a1a = m_db.GetAsset(uuid1);
138 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
139  
140 AssetBase a2a = m_db.GetAsset(uuid2);
141 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
142  
143 AssetBase a3a = m_db.GetAsset(uuid3);
144 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
145  
146 scrambler.Scramble(a1a);
147 scrambler.Scramble(a2a);
148 scrambler.Scramble(a3a);
149  
150 m_db.StoreAsset(a1a);
151 m_db.StoreAsset(a2a);
152 m_db.StoreAsset(a3a);
153  
154 AssetBase a1b = m_db.GetAsset(uuid1);
155 Assert.That(a1b, Constraints.PropertyCompareConstraint(a1a));
156  
157 AssetBase a2b = m_db.GetAsset(uuid2);
158 Assert.That(a2b, Constraints.PropertyCompareConstraint(a2a));
159  
160 AssetBase a3b = m_db.GetAsset(uuid3);
161 Assert.That(a3b, Constraints.PropertyCompareConstraint(a3a));
162  
163 bool[] exist = m_db.AssetsExist(new[] { uuid1, uuid2, uuid3 });
164 Assert.IsTrue(exist[0]);
165 Assert.IsTrue(exist[1]);
166 Assert.IsTrue(exist[2]);
167  
168 List<AssetMetadata> metadatas = m_db.FetchAssetMetadataSet(0, 1000);
169  
170 Assert.That(metadatas.Count >= 3, "FetchAssetMetadataSet() should have returned at least 3 assets!");
171  
172 // It is possible that the Asset table is filled with data, in which case we don't try to find "our"
173 // assets there:
174 if (metadatas.Count < 1000)
175 {
176 AssetMetadata metadata = metadatas.Find(x => x.FullID == uuid1);
177 Assert.That(metadata.Name, Is.EqualTo(a1b.Name));
178 Assert.That(metadata.Description, Is.EqualTo(a1b.Description));
179 Assert.That(metadata.Type, Is.EqualTo(a1b.Type));
180 Assert.That(metadata.Temporary, Is.EqualTo(a1b.Temporary));
181 Assert.That(metadata.FullID, Is.EqualTo(a1b.FullID));
182 }
183 }
184  
185 [Test]
186 public void T020_CheckForWeirdCreatorID()
187 {
188 TestHelpers.InMethod();
189  
190 // It is expected that eventually the CreatorID might be an arbitrary string (an URI)
191 // rather than a valid UUID (?). This test is to make sure that the database layer does not
192 // attempt to convert CreatorID to GUID, but just passes it both ways as a string.
193 AssetBase a1 = new AssetBase(uuid1, "asset one", (sbyte)AssetType.Texture, critter1);
194 AssetBase a2 = new AssetBase(uuid2, "asset two", (sbyte)AssetType.Texture, "This is not a GUID!");
195 AssetBase a3 = new AssetBase(uuid3, "asset three", (sbyte)AssetType.Texture, "");
196 a1.Data = data1;
197 a2.Data = data1;
198 a3.Data = data1;
199  
200 m_db.StoreAsset(a1);
201 m_db.StoreAsset(a2);
202 m_db.StoreAsset(a3);
203  
204 AssetBase a1a = m_db.GetAsset(uuid1);
205 Assert.That(a1a, Constraints.PropertyCompareConstraint(a1));
206  
207 AssetBase a2a = m_db.GetAsset(uuid2);
208 Assert.That(a2a, Constraints.PropertyCompareConstraint(a2));
209  
210 AssetBase a3a = m_db.GetAsset(uuid3);
211 Assert.That(a3a, Constraints.PropertyCompareConstraint(a3));
212 }
213 }
214 }