Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ayende/ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed May 4, 2013
2 parents 5ed1eb6 + b4f9bf0 commit 5229070
Show file tree
Hide file tree
Showing 180 changed files with 99,486 additions and 98,975 deletions.
10 changes: 10 additions & 0 deletions Raven.Client.Lightweight/Document/RavenClientEnlistment.cs
Expand Up @@ -63,6 +63,16 @@ public void Prepare(PreparingEnlistment preparingEnlistment)
catch (Exception e)
{
logger.ErrorException("Could not prepare distributed transaction", e);
try
{
session.Rollback(PromotableRavenClientEnlistment.GetLocalOrDistributedTransactionId(transaction));
DeleteFile();
}
catch (Exception e2)
{
logger.ErrorException("Could not roll back transaction after prepare failed", e2);
}

preparingEnlistment.ForceRollback(e);
return;
}
Expand Down
Expand Up @@ -11,7 +11,10 @@ public class DatabaseCountDocumentDeleteTrigger : AbstractDeleteTrigger
{
public override void AfterDelete(string key, Abstractions.Data.TransactionInformation transactionInformation)
{
DocQuotaConfiguration.GetConfiguration(Database).AfterDelete();
using (Database.DisableAllTriggersForCurrentThread())
{
DocQuotaConfiguration.GetConfiguration(Database).AfterDelete();
}
}
}
}
Expand Up @@ -9,7 +9,10 @@ public class DatabaseSizeAttachmentDeleteTrigger : AbstractAttachmentDeleteTrigg
{
public override void AfterDelete(string key)
{
SizeQuotaConfiguration.GetConfiguration(Database).AfterDelete();
using (Database.DisableAllTriggersForCurrentThread())
{
SizeQuotaConfiguration.GetConfiguration(Database).AfterDelete();
}
}
}
}
Expand Up @@ -9,7 +9,10 @@ public class DatabaseSizeDocumentDeleteTrigger : AbstractDeleteTrigger
{
public override void AfterDelete(string key, Abstractions.Data.TransactionInformation transactionInformation)
{
SizeQuotaConfiguration.GetConfiguration(Database).AfterDelete();
using (Database.DisableAllTriggersForCurrentThread())
{
SizeQuotaConfiguration.GetConfiguration(Database).AfterDelete();
}
}
}
}
Expand Up @@ -271,19 +271,19 @@ private string TrimEdges(StringBuilder buffer, int startOffset, int endOffset, o
localStart = startOffset;
}

if (endOffset != buffer.Length && buffer[endOffset] != ' ')
{
while (buffer[localEnd] != ' ' && localEnd != localStart && localEnd > minEnd)
{
localEnd--;
}
if (endOffset + 1 < buffer.Length && buffer[endOffset + 1] != ' ')
{
while (buffer[localEnd] != ' ' && localEnd != localStart && localEnd > minEnd)
{
localEnd--;
}

if (localEnd == localStart)
{
localEnd = endOffset;
localStart = startOffset;
}
}
if (localEnd == localStart)
{
localEnd = endOffset;
localStart = startOffset;
}
}

retStartOffset = localStart;
return buffer.ToString(localStart, localEnd - localStart);
Expand Down
@@ -0,0 +1,28 @@
using System;
using System.Linq;
using ICSharpCode.NRefactory.CSharp;
using Raven.Database.Linq.PrivateExtensions;

namespace Raven.Database.Linq.Ast
{
[CLSCompliant(false)]
public class TransformGroupByExtensionMethodTransformer : DepthFirstAstVisitor<object,object>
{
public override object VisitInvocationExpression(InvocationExpression invocationExpression, object data)
{
var memberReferenceExpression = invocationExpression.Target as MemberReferenceExpression;
if (memberReferenceExpression != null && memberReferenceExpression.MemberName == "GroupBy")
{
var newInvocation = new InvocationExpression(
new MemberReferenceExpression(
new TypeReferenceExpression(new SimpleType(typeof (LinqOnDynamic).FullName)),
memberReferenceExpression.MemberName),
invocationExpression.Arguments.Select(x => x.Clone())
);
invocationExpression.ReplaceWith(newInvocation);
}

return base.VisitInvocationExpression(invocationExpression, data);
}
}
}
20 changes: 16 additions & 4 deletions Raven.Database/Linq/DynamicViewCompiler.cs
Expand Up @@ -355,7 +355,7 @@ private static LambdaExpression GetLambdaExpression(InvocationExpression invocat

private void ValidateMapReduceFields(List<string> mapFields)
{
mapFields.Remove("__document_id");
mapFields.Remove(Constants.DocumentIdFieldName);
var reduceFields = captureSelectNewFieldNamesVisitor.FieldNames;
if (reduceFields.SetEquals(mapFields) == false)
{
Expand Down Expand Up @@ -425,12 +425,24 @@ private bool AddDocumentIdFieldToLambdaIfCreatingNewObject(LambdaExpression lamb
return false;

var initializers = objectCreateExpression.Initializers;

var identifierExpression = new IdentifierExpression(lambdaExpression.Parameters.First().Name);

if (initializers.OfType<NamedExpression>().Any(x => x.Name == Constants.DocumentIdFieldName))
return false;

var parameter = lambdaExpression.Parameters.First();
var identifier = parameter.Name;

// Support getting the __document_id from IGrouping parameter
var castExpression = parameter.Parent.Parent.Parent as CastExpression;
if (castExpression != null)
{
var simpleType = castExpression.Type as SimpleType;
if (simpleType != null && simpleType.Identifier == "Func<IGrouping<dynamic,dynamic>, dynamic>")
{
identifier += ".Key";
}
}

var identifierExpression = new IdentifierExpression(identifier);
objectCreateExpression.Initializers.Add(new NamedExpression
{
Name = Constants.DocumentIdFieldName,
Expand Down
5 changes: 5 additions & 0 deletions Raven.Database/Linq/PrivateExtensions/LinqOnDynamic.cs
Expand Up @@ -42,6 +42,11 @@ IEnumerator IEnumerable.GetEnumerator()
return Enumerable.GroupBy(source, keySelector).Select(inner => new WrapperGrouping(inner));
}

public static IEnumerable<IGrouping<dynamic, dynamic>> GroupBy(this IEnumerable<dynamic> source, Func<dynamic, dynamic> keySelector, Func<dynamic, dynamic> resultSelector)
{
return Enumerable.GroupBy(source, keySelector, resultSelector).Select(inner => new WrapperGrouping(inner));
}

private static IEnumerable<dynamic> Select(this object self)
{
if (self == null || self is DynamicNullObject)
Expand Down
1 change: 1 addition & 0 deletions Raven.Database/Raven.Database.csproj
Expand Up @@ -238,6 +238,7 @@
<Compile Include="Indexing\RavenPerFieldAnalyzerWrapper.cs" />
<Compile Include="Indexing\Spatial\RecursivePrefixTreeStrategyThatSupportsWithin.cs" />
<Compile Include="Json\ScriptsCache.cs" />
<Compile Include="Linq\Ast\TransformGroupByExtensionMethodTransformer.cs" />
<Compile Include="Linq\Ast\ThrowOnInvalidMethodCallsForTransformResults.cs" />
<Compile Include="Linq\Ast\TransformObsoleteMethods.cs" />
<Compile Include="Linq\CodeVerifier.cs" />
Expand Down
19 changes: 19 additions & 0 deletions Raven.Tests.Helpers/RavenTestBase.cs
Expand Up @@ -29,6 +29,7 @@
using Raven.Json.Linq;
using Raven.Server;
using Xunit;
using Xunit.Sdk;

namespace Raven.Tests.Helpers
{
Expand Down Expand Up @@ -356,5 +357,23 @@ protected static void PrintServerErrors(ServerError[] serverErrors)
else
Console.WriteLine("No server errors");
}

protected void AssertNoIndexErrors(IDocumentStore documentStore)
{
var embeddableDocumentStore = documentStore as EmbeddableDocumentStore;
var errors = embeddableDocumentStore != null
? embeddableDocumentStore.DocumentDatabase.Statistics.Errors
: documentStore.DatabaseCommands.GetStatistics().Errors;

try
{
Assert.Empty(errors);
}
catch (EmptyException)
{
Console.WriteLine(errors.First().Error);
throw;
}
}
}
}
148 changes: 74 additions & 74 deletions Raven.Tests.Silverlight/Statistics.cs
@@ -1,75 +1,75 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Raven.Abstractions.Indexing;
using Raven.Client.Document;
using Raven.Client.Extensions;
using Raven.Tests.Document;

namespace Raven.Tests.Silverlight
{
public class Statistics : RavenTestBase
{
[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForTheDefaultDatabase()
{
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
var getStats = documentStore.AsyncDatabaseCommands
.GetStatisticsAsync();
yield return getStats;

Assert.IsNotNull(getStats.Result);
}
}

[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForADatabase()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

yield return documentStore.AsyncDatabaseCommands.ForDatabase(dbname).PutIndexAsync("test", new IndexDefinition
{
Map = "from doc in docs select new { doc.Name}"
}, true);

var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;

var stats = getStats.Result;
Assert.AreEqual(0, stats.CountOfDocuments);
Assert.IsTrue(stats.CountOfIndexes > 0);
}
}

[Asynchronous]
public IEnumerable<Task> StatisticsShouldNotBeCached()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;

Assert.AreEqual(0, getStats.Result.CountOfDocuments);

using (var session = documentStore.OpenAsyncSession(dbname))
{
session.Store(new Company {Name = "Change the Stats, Inc."});
yield return session.SaveChangesAsync();
}

var verifyStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return verifyStats;

Assert.AreEqual(1, verifyStats.Result.CountOfDocuments);
}
}
}
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Raven.Abstractions.Indexing;
using Raven.Client.Document;
using Raven.Client.Extensions;
using Raven.Tests.Document;

namespace Raven.Tests.Silverlight
{
public class Statistics : RavenTestBase
{
[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForTheDefaultDatabase()
{
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
var getStats = documentStore.AsyncDatabaseCommands
.GetStatisticsAsync();
yield return getStats;

Assert.IsNotNull(getStats.Result);
}
}

[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForADatabase()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

yield return documentStore.AsyncDatabaseCommands.ForDatabase(dbname).PutIndexAsync("test", new IndexDefinition
{
Map = "from doc in docs select new { doc.Name}"
}, true);

var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;

var stats = getStats.Result;
Assert.AreEqual(0, stats.CountOfDocuments);
Assert.IsTrue(stats.CountOfIndexes > 0);
}
}

[Asynchronous]
public IEnumerable<Task> StatisticsShouldNotBeCached()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;

Assert.AreEqual(0, getStats.Result.CountOfDocuments);

using (var session = documentStore.OpenAsyncSession(dbname))
{
session.Store(new Company {Name = "Change the Stats, Inc."});
yield return session.SaveChangesAsync();
}

var verifyStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return verifyStats;

Assert.AreEqual(1, verifyStats.Result.CountOfDocuments);
}
}
}
}

0 comments on commit 5229070

Please sign in to comment.