0

我正在使用 RavenDB 开发应用程序。我有针对嵌入式内存数据库的自动化测试。当我引用 Raven build 2033-Unstable 时,所有测试都运行良好。我升级到 build 2067-Unstable(现在是 2069),现在通过 TeamCity(7.1 build 23907)运行时,每个 NUnit 测试都出现异常。通过 R# 或 NUnit GUI 运行时,所有测试都运行良好。

我收到的例外似乎是NullReferenceExceptionRaven 的内部人员Raven.Bundles.Versioning.Triggers.VersioningPutTrigger.AllowPut(String key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Bundles\Versioning\Triggers\VersioningPutTrigger.cs:line 22。我什至没有使用Versioning捆绑包。

这是完整的堆栈跟踪:

Test(s) failed. Autofac.Core.DependencyResolutionException : An exception was thrown while executing a resolve operation. See the InnerException for details.
  ----> System.NullReferenceException : Object reference not set to an instance of an object.
   at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
   at AppCenter.Tests.Fixture.Resolve[TService]() in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Tests\Fixture.cs:line 40
   at AppCenter.Tests.Fixture.get_Raven() in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Tests\Fixture.cs:line 22
   at AppCenter.Tests.Fixture.Store[T](T entity) in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Tests\Fixture.cs:line 50
   at AppCenter.Tests.AppAdmin.ApplicationEditTests.TestLoad() in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Tests\AppAdmin\ApplicationEditTests.cs:line 20
--NullReferenceException
   at Raven.Bundles.Versioning.Triggers.VersioningPutTrigger.AllowPut(String key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Bundles\Versioning\Triggers\VersioningPutTrigger.cs:line 22
   at Raven.Database.DocumentDatabase.<>c__DisplayClass42.<AssertPutOperationNotVetoed>b__3f(AbstractPutTrigger trigger) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 601
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
   at Raven.Database.DocumentDatabase.AssertPutOperationNotVetoed(String key, RavenJObject metadata, RavenJObject document, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 600
   at Raven.Database.DocumentDatabase.<>c__DisplayClass3a.<Put>b__33(IStorageActionsAccessor actions) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 551
   at Raven.Storage.Managed.TransactionalStorage.ExecuteBatch(Action`1 action) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Storage\Managed\TransactionalStorage.cs:line 131
   at Raven.Storage.Managed.TransactionalStorage.Batch(Action`1 action) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Storage\Managed\TransactionalStorage.cs:line 112
   at Raven.Database.DocumentDatabase.Put(String key, Nullable`1 etag, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 543
   at Raven.Bundles.Encryption.Settings.EncryptionSettingsManager.VerifyEncryptionKey(DocumentDatabase database, EncryptionSettings settings) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Bundles\Encryption\Settings\EncryptionSettingsManager.cs:line 114
   at Raven.Database.Extensions.EnumerableExtensions.Apply[T](IEnumerable`1 self, Action`1 action) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\Extensions\EnumerableExtensions.cs:line 18
   at Raven.Database.DocumentDatabase.InitializeTriggersExceptIndexCodecs() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 221
   at Raven.Database.DocumentDatabase..ctor(InMemoryRavenConfiguration configuration) in c:\Builds\RavenDB-Unstable-v1.2\Raven.Database\DocumentDatabase.cs:line 200
   at Raven.Client.Embedded.EmbeddableDocumentStore.InitializeInternal() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Client.Embedded\EmbeddableDocumentStore.cs:line 208
   at Raven.Client.Document.DocumentStore.Initialize() in c:\Builds\RavenDB-Unstable-v1.2\Raven.Client.Lightweight\Document\DocumentStore.cs:line 431
   at AppCenter.Config.RavenModule.Initialize(DocumentStoreBase store) in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Framework\Config\RavenModule.cs:line 32
   at AppCenter.Tests.RavenInMemoryModule.<Load>b__1(IActivatingEventArgs`1 a) in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Tests\RavenInMemoryModule.cs:line 25
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass6.<OnActivating>b__5(Object s, ActivatingEventArgs`1 e)
   at Autofac.Core.Registration.ComponentRegistration.RaiseActivating(IComponentContext context, IEnumerable`1 parameters, Object& instance)
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
   at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator)
   at Autofac.Core.Resolving.InstanceLookup.Execute()
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
   at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Execute()
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
   at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
   at AppCenter.Config.RavenModule.<Load>b__1(IComponentContext c) in c:\TeamCity\buildAgent\work\994e66c6c107022f\AppCenter.Framework\Config\RavenModule.cs:line 19
   at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
   at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
   at Autofac.Core.Lifetime.LifetimeScope.GetOrCreateAndShare(Guid id, Func`1 creator)
   at Autofac.Core.Resolving.InstanceLookup.Execute()
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Builder.RegistrationBuilder.<>c__DisplayClass1`1.<ForDelegate>b__0(IComponentContext c, IEnumerable`1 p)
   at Autofac.Core.Activators.Delegate.DelegateActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters)
   at Autofac.Core.Resolving.InstanceLookup.Execute()
   at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable`1 parameters)
   at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable`1 parameters)

我正在使用 Autofac 将其连接起来,该代码如下所示:

    protected override void Load(ContainerBuilder builder)
    {
        builder.Register(c => new EmbeddableDocumentStore
                              {
                                  RunInMemory = true,
                                  Configuration =
                                      {
                                          PluginsDirectory = GetPluginsDirectory()
                                      }
                              })
            .OnActivating(a => RavenModule.Initialize(a.Instance))
            .As<IDocumentStore>()
            .Named<IDocumentStore>("test")
            .InstancePerLifetimeScope();
    }

    private static string GetPluginsDirectory()
    {
        return Path.GetDirectoryName(typeof (UniqueConstraintsPutTrigger).Assembly.Location);
    }

    public static void Initialize(DocumentStoreBase store)
    {
        store.RegisterListener(new UniqueConstraintsStoreListener());
        store.Initialize();
        IndexCreation.CreateIndexes(typeof (RavenModule).Assembly, store);
        RequireTrigger(store, typeof (UniqueConstraintsPutTrigger));
    }

    private static void RequireTrigger(IDocumentStore store, Type triggerType)
    {
        var installedTriggerNames = store.DatabaseCommands.GetStatistics().Triggers.Select(t => t.Name);

        if (!installedTriggerNames.Contains(triggerType.ToString()))
        {
            throw new Exception(string.Format(
                "The required trigger '{0}' was not detected. Verify the bundle '{1}' been installed into the" +
                " server's plugins directory.",
                triggerType, Path.GetFileName(triggerType.Assembly.Location)));
        }
    }
4

1 回答 1

3

解决了。将 设置为PluginsDirectory与所有其他 DLL 相同的文件夹,尤其是Raven.Database.dll,会导致该 DLL 中嵌入的所有插件也被无意加载。并非所有的 Raven 插件都可以一起工作,因此加载它们都会导致异常。通过创建一个单独的Plugins目录并将其复制Raven.Bundles.UniqueConstraints.dll到该目录中,可以使异常停止发生。

我仍然不明白为什么它只是从构建服务器失败;似乎它也应该在本地失败。

于 2012-08-24T14:35:57.910 回答