Skip to content

Commit

Permalink
Fix internal class visibility to works in LiteDB.Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Mar 5, 2019
1 parent 364fe07 commit faf2acb
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 169 deletions.
1 change: 0 additions & 1 deletion LiteDB.Demo/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static LiteDB.Constants;

namespace LiteDB.Demo
{
Expand Down
12 changes: 10 additions & 2 deletions LiteDB.Demo/Tests/TestFullEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ public static void Run(Stopwatch sw)
using (var db = new LiteEngine(settings))
{
Console.WriteLine("Insert...");
db.Insert("col1", GetDocs(1, 100000), BsonAutoId.Int32);
db.Insert("col2", GetDocs(1, 10000), BsonAutoId.ObjectId);

var t0 = Task.Run(() => db.Insert("col1", GetDocs(1, 100000), BsonAutoId.Int32));
//var t1 = Task.Run(() => db.Insert("col2", GetDocs(1, 10000), BsonAutoId.ObjectId));
//var t2 = Task.Run(() => db.Insert("col3", GetDocs(1, 1000), BsonAutoId.Guid));

Task.WaitAll(t0/*, t1, t2*/);
}

sw.Stop();

//using (var db = new LiteEngine(settings))
//{
// db.CheckIntegrity();
//}
}

static IEnumerable<BsonDocument> GetDocs(int start, int count)
Expand Down
89 changes: 0 additions & 89 deletions LiteDB.Demo/Tests/TestScript.cs

This file was deleted.

2 changes: 1 addition & 1 deletion LiteDB.Tests/Engine/Create_Database_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void Create_Database_With_Initial_Size()
Assert.AreEqual(initial, file.Size);

// insert minimal data
db.Execute("insert into col1 values {a:1}", null);
db.Insert("col1", new BsonDocument { ["a"] = 1 });

Assert.AreEqual(initial, file.Size);

Expand Down
6 changes: 3 additions & 3 deletions LiteDB.Tests/Engine/Index_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ public void Index_Order()
col.EnsureIndex("text");

var asc = string.Join("", col.Query()
.OrderBy("text")
.Select("text")
.OrderBy("text")
.ToDocuments()
.Select(x => x["text"].AsString));

var desc = string.Join("", col.Query()
.OrderByDescending("text")
.Select("text")
.OrderByDescending("text")
.ToDocuments()
.Select(x => x["text"].AsString));

Expand All @@ -78,7 +78,7 @@ public void Index_Order()
[TestMethod]
public void Index_With_Like()
{
using (var db = new LiteEngine())
using (var db = new LiteDatabase(new ConnectionString()))
{
db.Insert("names", new[] {
new BsonDocument { ["name"] = "marcelo" },
Expand Down
2 changes: 1 addition & 1 deletion LiteDB.Tests/Engine/Shrink_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void DoTest(LiteDatabase db, LiteCollection<Zip> col)
Assert.AreEqual(1, col.Count());

// must checkpoint
db.Checkpoint();
db.Checkpoint(CheckpointMode.Full);

// file still large than 5mb (even with only 1 document)
Assert.IsTrue(file.Size > 5 * 1024 * 1024);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//using System.Threading;
//using System.Threading.Tasks;

//namespace LiteDB.Demo
//namespace LiteDB.Tests.Internals
//{
// public class TestAesEncryption
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace LiteDB.Demo
namespace LiteDB.Tests.Internals
{
public class TestBasePage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace LiteDB.Demo
namespace LiteDB.Tests.Internals
{
public class TestDataPage
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace LiteDB.Demo
namespace LiteDB.Tests.Internals
{
public class TestDeleteEngine
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using System.Threading;
using System.Threading.Tasks;

namespace LiteDB.Demo
namespace LiteDB.Tests.Internals
{
public class TestInsertEngine
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//using System.Threading;
//using System.Threading.Tasks;

//namespace LiteDB.Demo
//namespace LiteDB.Tests.Internals
//{
// public class TestMemoryFile
// {
Expand All @@ -31,31 +31,31 @@
// public static void Run(Stopwatch sw)
// {
// File.Delete(PATH);

// var factory = new FileStreamFactory(PATH, DbFileMode.Logfile, false);
// var pool = new StreamPool(factory);
// var file = new MemoryFile(pool, null);

// Console.WriteLine("Processing... " + (N0 * N1));

// sw.Start();

// // Write documents inside data file (append)
// WriteFile(file);

// Console.WriteLine("Write: " + sw.ElapsedMilliseconds);

// // dispose - re-open test with no memory cache
// file.Dispose();
// file = new MemoryFile(pool, null);

// Thread.Sleep(2000);
// sw.Restart();

// ReadFile(file);

// Console.WriteLine("Read: " + sw.ElapsedMilliseconds);

// file.Dispose();
// pool.Dispose();

Expand Down
10 changes: 8 additions & 2 deletions LiteDB.Tests/LiteDB.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<NoWarn>1701;1702;1705;1591;0618</NoWarn>
<SignAssembly Condition="'$(OS)'=='Windows_NT'">true</SignAssembly>
<AssemblyOriginatorKeyFile>LiteDB.Tests.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<ItemGroup Condition="'$(Configuration)' == 'Release'">
<Compile Remove="Internals\**" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Engine\Index_Tests.cs" />
</ItemGroup>

<ItemGroup>
<None Remove="Sql\Scripts\All_Sql.sql" />
<None Remove="Expressions\ExprTests\Aggregate.txt" />
Expand Down
Binary file removed LiteDB.Tests/LiteDB.Tests.snk
Binary file not shown.
20 changes: 10 additions & 10 deletions LiteDB.Tests/Sql/Sql_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public BsonDocument Run(string name, Action<LiteDatabase> setup = null)
{
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream($"LiteDB.Tests.Sql.Scripts.{name}.sql");
var reader = new StreamReader(stream);
var sql = reader.ReadToEnd();

var par = new BsonDocument();

Expand All @@ -33,20 +32,21 @@ public BsonDocument Run(string name, Action<LiteDatabase> setup = null)

try
{
using (var data = db.Execute(sql, par))
while(!reader.EndOfStream)
{
while (data.NextResult()) ;
var data = db.Execute(reader, par);
}
}
catch(LiteException ex) when (ex.ErrorCode == LiteException.UNEXPECTED_TOKEN)
{
var p = (int)ex.Position;
var start = (int)Math.Max(p - 30, 1) - 1;
var end = Math.Min(p + 15, sql.Length);
var length = end - start;
var str = sql.Substring(start, length).Replace('\n', ' ').Replace('\r', ' ');

Assert.Fail($"{ex.Message} - {str}");
//var p = (int)ex.Position;
//var start = (int)Math.Max(p - 30, 1) - 1;
//var end = Math.Min(p + 15, sql.Length);
//var length = end - start;
//var str = sql.Substring(start, length).Replace('\n', ' ').Replace('\r', ' ');
//
//Assert.Fail($"{ex.Message} - {str}");
throw;
}
}

Expand Down
18 changes: 2 additions & 16 deletions LiteDB.Tests/Utils/LiteEngineExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,9 @@ namespace LiteDB.Tests
{
public static class LiteEngineExtensions
{
public static T[] ExecuteValues<T>(this LiteEngine engine, string sql, BsonDocument args = null)
public static int Insert(this LiteEngine engine, string collection, BsonDocument doc, BsonAutoId autoId = BsonAutoId.ObjectId)
{
var values = new List<T>();
var mapper = new BsonMapper();

using (var r = engine.Execute(sql, args ?? new BsonDocument()))
{
while(r.Read())
{
var doc = r.Current.AsDocument;
var key = doc.Keys.First();

values.Add(mapper.Deserialize<T>(doc[key]));
}
}

return values.ToArray();
return engine.Insert(collection, new BsonDocument[] { doc }, autoId);
}
}
}
7 changes: 3 additions & 4 deletions LiteDB.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteDB.Studio", "LiteDB.Studio\LiteDB.Studio.csproj", "{0002E0FF-C91F-4B8B-B29B-2A477E184408}"
EndProject
Global
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
Expand All @@ -31,7 +28,6 @@ Global
{74E32E43-2A57-4A38-BD8C-9108B0DCAEAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{74E32E43-2A57-4A38-BD8C-9108B0DCAEAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{74E32E43-2A57-4A38-BD8C-9108B0DCAEAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{74E32E43-2A57-4A38-BD8C-9108B0DCAEAA}.Release|Any CPU.Build.0 = Release|Any CPU
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0002E0FF-C91F-4B8B-B29B-2A477E184408}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -43,4 +39,7 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {45099B85-2AE1-434B-913A-6AD14FD3AF4A}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions LiteDB/Engine/Disk/DiskWriterQueue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ private void ExecuteQueue()

public void Dispose()
{
LOG($"disposing disk writer queue (in queue {_queue.Count} pages)", "DISK");

// stop running async task in next while check
_running = false;

Expand Down
Loading

0 comments on commit faf2acb

Please sign in to comment.