예제 #1
0
        public void SetUp()
        {
            MongoFlatMapper.EnableFlatMapping(true);
            MongoDbTestConnectionProvider.ReadModelDb.Drop();

            var mngr = new IdentityManager(new CounterService(MongoDbTestConnectionProvider.ReadModelDb));

            mngr.RegisterIdentitiesFromAssembly(typeof(DocumentDescriptorId).Assembly);

            MongoFlatIdSerializerHelper.Initialize(mngr);

            EventStoreIdentityCustomBsonTypeMapper.Register <DocumentDescriptorId>();
            EventStoreIdentityCustomBsonTypeMapper.Register <DocumentId>();
            StringValueCustomBsonTypeMapper.Register <BlobId>();
            StringValueCustomBsonTypeMapper.Register <DocumentHandle>();
            StringValueCustomBsonTypeMapper.Register <FileHash>();

            _writer = new DocumentWriter(MongoDbTestConnectionProvider.ReadModelDb);
            var _documentDescriptorCollection = new MongoReaderForProjections <DocumentDescriptorReadModel, DocumentDescriptorId>
                                                (
                new MongoStorageFactory(MongoDbTestConnectionProvider.ReadModelDb,
                                        new RebuildContext(true)));
            var _documentDeletedCollection = new CollectionWrapper <DocumentDeletedReadModel, String>
                                             (
                new MongoStorageFactory(MongoDbTestConnectionProvider.ReadModelDb,
                                        new RebuildContext(true)), null);

            _sut = new DocumentProjection(_writer, _documentDescriptorCollection, _documentDeletedCollection);
        }
        public void Global_initialization_of_all_tests()
        {
            //Nunit3 fix for test adapter of visual studio, it uses visual studio test directory
            Environment.CurrentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

            MongoRegistration.ConfigureMongoForJarvisFramework(
                "NEventStore.Persistence.MongoDB"
                );
            MongoFlatMapper.EnableFlatMapping(true);
            MongoRegistration.RegisterAssembly(GetType().Assembly);
            var overrideTestDb = Environment.GetEnvironmentVariable("TEST_MONGODB");

            if (String.IsNullOrEmpty(overrideTestDb))
            {
                return;
            }

            Console.WriteLine("Mongodb database is overriden with TEST_MONGODB environment variable:" + overrideTestDb);
            var overrideTestDbQueryString = Environment.GetEnvironmentVariable("TEST_MONGODB_QUERYSTRING");
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

            connectionStringsSection.ConnectionStrings["eventstore"].ConnectionString = overrideTestDb.TrimEnd('/') + "/jarvis-framework-es-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["saga"].ConnectionString       = overrideTestDb.TrimEnd('/') + "/jarvis-framework-saga-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["readmodel"].ConnectionString  = overrideTestDb.TrimEnd('/') + "/jarvis-framework-readmodel-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["system"].ConnectionString     = overrideTestDb.TrimEnd('/') + "/jarvis-framework-system-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["engine"].ConnectionString     = overrideTestDb.TrimEnd('/') + "/jarvis-framework-engine-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["rebus"].ConnectionString      = overrideTestDb.TrimEnd('/') + "/jarvis-rebus-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["log"].ConnectionString        = overrideTestDb.TrimEnd('/') + "/jarvis-log-test" + overrideTestDbQueryString;

            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");

            TestLogger.GlobalEnabled = false;
        }
예제 #3
0
        public void Global_initialization_of_all_tests()
        {
            MongoRegistration.RegisterMongoConversions(
                "NEventStore.Persistence.MongoDB"
                );
            MongoFlatMapper.EnableFlatMapping(true);
            MongoRegistration.RegisterAssembly(GetType().Assembly);
            var overrideTestDb = Environment.GetEnvironmentVariable("TEST_MONGODB");

            if (String.IsNullOrEmpty(overrideTestDb))
            {
                return;
            }

            Console.WriteLine("Mongodb database is overriden with TEST_MONGODB environment variable:" + overrideTestDb);
            var overrideTestDbQueryString = Environment.GetEnvironmentVariable("TEST_MONGODB_QUERYSTRING");
            var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

            connectionStringsSection.ConnectionStrings["eventstore"].ConnectionString = overrideTestDb.TrimEnd('/') + "/jarvis-framework-es-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["saga"].ConnectionString       = overrideTestDb.TrimEnd('/') + "/jarvis-framework-saga-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["readmodel"].ConnectionString  = overrideTestDb.TrimEnd('/') + "/jarvis-framework-readmodel-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["system"].ConnectionString     = overrideTestDb.TrimEnd('/') + "/jarvis-framework-system-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["engine"].ConnectionString     = overrideTestDb.TrimEnd('/') + "/jarvis-framework-engine-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["rebus"].ConnectionString      = overrideTestDb.TrimEnd('/') + "/jarvis-rebus-test" + overrideTestDbQueryString;
            connectionStringsSection.ConnectionStrings["log"].ConnectionString        = overrideTestDb.TrimEnd('/') + "/jarvis-log-test" + overrideTestDbQueryString;

            config.Save();
            ConfigurationManager.RefreshSection("connectionStrings");
        }
예제 #4
0
        public virtual void TestFixtureSetUp()
        {
            _logger = NSubstitute.Substitute.For <ILog>();
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;;
            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            _identityConverter = new IdentityManager(new CounterService(_db));
            _identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);

            ProjectionEngineConfig config = new ProjectionEngineConfig()
            {
                EventStoreConnectionString = _eventStoreConnectionString
            };
            CommitEnhancer commitEnhancer = new CommitEnhancer(_identityConverter);

            sut = new EventUnwinder(config, NullLogger.Instance);

            _unwindedEventCollection = _db.GetCollection <UnwindedDomainEvent>("UnwindedEvents");
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(_identityConverter);
        }
예제 #5
0
        public void SetUp()
        {
            var config = new DocumentStoreTestConfiguration(_engineVersion);

            MongoDbTestConnectionProvider.DropTestsTenant();
            config.SetTestAddress(TestConfig.TestHostServiceAddress);
            _documentStoreService = new DocumentStoreBootstrapper();
            _documentStoreService.Start(config);
            _documentStoreClient = new DocumentStoreServiceClient(
                TestConfig.ServerAddress,
                TestConfig.Tenant
                );
            _tenant = ContainerAccessor.Instance.Resolve <TenantManager>().GetTenant(new TenantId(TestConfig.Tenant));

            //Issue: https://github.com/ProximoSrl/Jarvis.DocumentStore/issues/26
            //you need to resolve the IReader that in turns resolves the ProjectionEngine, becauase if you
            //directly resolve the ITriggerProjectionsUpdate, projection engine will be resolved multiple times.
            _tenant.Container.Resolve <IReader <StreamReadModel, Int64> >();
            _projections = _tenant.Container.Resolve <ITriggerProjectionsUpdate>();

            _documentDescriptorCollection = MongoDbTestConnectionProvider.ReadModelDb.GetCollection <DocumentDescriptorReadModel>("rm.DocumentDescriptor");
            _documentCollection           = MongoDbTestConnectionProvider.ReadModelDb.GetCollection <DocumentReadModel>("rm.Document");
            _commitCollection             = MongoDbTestConnectionProvider.ReadModelDb.GetCollection <BsonDocument>("Commits");
            _blobStore = _tenant.Container.Resolve <IBlobStore>();

            MongoFlatMapper.EnableFlatMapping(true);
        }
        public virtual void TestFixtureSetUp()
        {
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;

            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            ProjectionEngineConfig config = new ProjectionEngineConfig();

            config.EventStoreConnectionString = _eventStoreConnectionString;
            config.Slots      = new string[] { "*" };
            config.TenantId   = new TenantId("A");
            config.BucketInfo = new List <BucketInfo>();
            config.BucketInfo.Add(new BucketInfo()
            {
                Slots = new[] { "*" }, BufferSize = 10000
            });

            _identityConverter = new IdentityManager(new CounterService(_db));
            _identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);
            ConfigureEventStore();
            CommitEnhancer commitEnhancer = new CommitEnhancer(_identityConverter);

            _eventUnwinder = new EventUnwinder(config, new TestLogger(LoggerLevel.Info));

            _unwindedEventCollection = _db.GetCollection <UnwindedDomainEvent>("UnwindedEvents");
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(_identityConverter);

            var rebuildContext = new RebuildContext(NitroEnabled);

            _storageFactory = new MongoStorageFactory(_db, rebuildContext);

            _reader1 = new MongoReader <SampleReadModel, string>(_db);
            _reader2 = new MongoReader <SampleReadModel2, string>(_db);
            _reader3 = new MongoReader <SampleReadModel3, string>(_db);

            //now configure RebuildProjectionEngine
            _tracker = new ConcurrentCheckpointTracker(_db);


            var projections = BuildProjections().ToArray();

            _tracker.SetUp(projections, 1, false);
            ProjectionEventInspector inspector = new ProjectionEventInspector();

            inspector.AddAssembly(Assembly.GetExecutingAssembly());
            sut        = new RebuildProjectionEngine(_eventUnwinder, _tracker, projections, rebuildContext, config, inspector);
            sut.Logger = new TestLogger(LoggerLevel.Debug);

            _checkpointCollection = _db.GetCollection <Checkpoint>("checkpoints");
        }
예제 #7
0
        public virtual void TestFixtureSetUp()
        {
            _eventStoreConnectionString = ConfigurationManager.ConnectionStrings["eventstore"].ConnectionString;
            var url    = new MongoUrl(_eventStoreConnectionString);
            var client = new MongoClient(url);

            _db = client.GetDatabase(url.DatabaseName);
            _db.Drop();

            var identityConverter = new IdentityManager(new CounterService(_db));

            identityConverter.RegisterIdentitiesFromAssembly(typeof(SampleAggregateId).Assembly);
            MongoFlatMapper.EnableFlatMapping(true);
            MongoFlatIdSerializerHelper.Initialize(identityConverter);
        }
예제 #8
0
        private static int Main(string[] args)
        {
            var lastErrorFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "_lastError.txt");

            if (File.Exists(lastErrorFileName))
            {
                File.Delete(lastErrorFileName);
            }
            try
            {
                MongoRegistration.RegisterMongoConversions(
                    "NEventStore.Persistence.MongoDB"
                    );

                MongoFlatMapper.EnableFlatMapping(true);

                CommandsExtensions.EnableDiagnostics = true;
                Native.DisableWindowsErrorReporting();
                MongoFlatMapper.EnableFlatMapping(true); //before any chanche that the driver scan any type.
                Int32 executionExitCode;
                if (args.Length == 1 && (args[0] == "install" || args[0] == "uninstall"))
                {
                    executionExitCode = (Int32)StartForInstallOrUninstall();
                }
                else
                {
                    executionExitCode = (Int32)StandardDocumentStoreStart();
                }
                return(executionExitCode);
            }
            catch (Exception ex)
            {
                File.WriteAllText(lastErrorFileName, ex.ToString());
                throw;
            }
        }
예제 #9
0
        public void This_is_run_before_ANY_tests()
        {
            var overrideTestDb = Environment.GetEnvironmentVariable("TEST_MONGODB");

            if (!String.IsNullOrEmpty(overrideTestDb))
            {
                var overrideTestDbQueryString = Environment.GetEnvironmentVariable("TEST_MONGODB_QUERYSTRING");
                var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");

                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "log", "ds-tests-logs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.quartz", "ds-tests-quartz");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.queue", "ds-tests-queues");

                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.log.host", "ds-logs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.quartz.host", "ds-quartz");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "ds.queue.host", "ds-queues");

                //<!-- Tenant 1-->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.originals", "ds-tests-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.descriptors", "ds-tests-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.artifacts", "ds-tests-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.system", "ds-tests");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.events", "ds-tests");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tests.readmodel", "ds-tests");

                //<!-- Tenant DOCS -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.originals", "ds-docs-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.descriptors", "ds-docs-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.artifacts", "ds-docs-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.system", "ds-docs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.events", "ds-docs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "docs.readmodel", "ds-docs");

                //<!-- Tenant DEMO -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.originals", "ds-demo-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.descriptors", "ds-demo-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.artifacts", "ds-demo-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.system", "ds-demo");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.events", "ds-demo");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "demo.readmodel", "ds-demo");

                //<!-- Tenant Tickets -->
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.originals", "ds-tickets-ori-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.descriptors", "ds-tickets-descriptors");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.artifacts", "ds-tickets-art-fs");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.system", "ds-tickets");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.events", "ds-tickets");
                RewriteConnection(overrideTestDb, overrideTestDbQueryString, connectionStringsSection, "tickets.readmodel", "ds-tickets");

                config.Save();
                ConfigurationManager.RefreshSection("connectionStrings");
            }
            try
            {
                var mngr = new IdentityManager(new CounterService(MongoDbTestConnectionProvider.ReadModelDb));
                mngr.RegisterIdentitiesFromAssembly(typeof(DocumentDescriptorId).Assembly);
                mngr.RegisterIdentitiesFromAssembly(typeof(TenantId).Assembly);
                mngr.RegisterIdentitiesFromAssembly(typeof(QueuedJobId).Assembly);

                MongoFlatIdSerializerHelper.Initialize(mngr);
                //BsonSerializer.RegisterSerializationProvider(new EventStoreIdentitySerializationProvider());
                //BsonSerializer.RegisterSerializationProvider(new StringValueSerializationProvider());
                MongoFlatMapper.EnableFlatMapping(true);
            }
            catch (ReflectionTypeLoadException rle)
            {
                foreach (var ex in rle.LoaderExceptions)
                {
                    Console.WriteLine("Exception In typeloading: " + ex.Message);
                }
                Console.WriteLine("Exception in Global Setup: " + rle.ToString());
                throw;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception in Global Setup: " + ex.ToString());
                throw;
            }
        }
예제 #10
0
        private static void RunShell()
        {
            MongoFlatMapper.EnableFlatMapping();
            ConfigurationServiceClient.AppDomainInitializer(
                (message, isError, exception) =>
            {
                if (isError)
                {
                    Console.Error.WriteLine(message + "\n" + exception);
                }
                else
                {
                    Console.WriteLine(message);
                }
            },
                "JARVIS_CONFIG_SERVICE",
                null,
                new FileInfo("defaultParameters.config"),
                missingParametersAction: ConfigurationManagerMissingParametersAction.Blank);

            var commands = new Dictionary <String, Func <Boolean> >();

            commands.Add("Check oprhaned blob", () =>
            {
                CheckOrphanedBlobs.PerformCheck(DateTime.UtcNow);
                return(false);
            });
            commands.Add("Check tika scheduled job", () =>
            {
                CheckQueuedTikaScheduledJobs.PerformCheck();
                return(false);
            });

            commands.Add("Start sync artifacts job", () =>
            {
                FullArtifactSyncJob.StartSync();
                return(false);
            });

            Menu(commands.Keys.ToList());
            CommandLoop(c =>
            {
                int menuSelection = 0;
                if (Int32.TryParse(c, out menuSelection))
                {
                    var func = commands.ElementAtOrDefault(menuSelection);
                    Console.WriteLine("Selected {0}", func.Key);
                    func.Value();
                }
                else
                {
                    if (String.Equals(c, "q", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }

                    Console.WriteLine("Comando non valido! Premere un tasto per continuare");
                    Console.ReadKey();
                }
                Menu(commands.Keys.ToList());
                return(false);
            });
        }
 public void TestFixtureSetUp()
 {
     MongoFlatMapper.EnableFlatMapping(true);
 }
예제 #12
0
        private static void RunShell()
        {
            MongoFlatMapper.EnableFlatMapping();

            if (ConsoleHelper.AskYesNoQuestion("Do you want to use Configuration Service? You should say N if doing tasks like migration that does not require configuration service"))
            {
                ConfigurationServiceClient.AppDomainInitializer(
                    (message, isError, exception) =>
                {
                    if (isError)
                    {
                        Console.Error.WriteLine(message + "\n" + exception);
                    }
                    else
                    {
                        Console.WriteLine(message);
                    }
                },
                    "JARVIS_CONFIG_SERVICE",
                    null,
                    new FileInfo("defaultParameters.config"),
                    missingParametersAction: ConfigurationManagerMissingParametersAction.Blank);
            }
            IWindsorContainer _container = new WindsorContainer();

            _container.AddFacility <LoggingFacility>(f => f
                                                     .LogUsing(LoggerImplementation.ExtendedLog4net)
                                                     .WithConfig("log4net.config"));
            _loggerFactory = _container.Resolve <ILoggerFactory>();

            var commands = new Dictionary <String, Func <Boolean> >();

            commands.Add("Check oprhaned blob", () =>
            {
                CheckOrphanedBlobs.PerformCheck(DateTime.UtcNow);
                return(false);
            });

            commands.Add("Check tika scheduled job", () =>
            {
                CheckQueuedTikaScheduledJobs.PerformCheck();
                return(false);
            });

            commands.Add("Start sync artifacts job", () =>
            {
                FullArtifactSyncJob.StartSync();
                return(false);
            });

            commands.Add("Copy blob from GridFs to FileSystemFs", () =>
            {
                var startFromBeginning = ConsoleHelper.AskYesNoQuestion("Do you want to start from the beginning of the stream?");
                BlobStoreSync command  = new BlobStoreSync(_loggerFactory.Create(typeof(BlobStoreSync)));
                command.SyncAllTenants(BlobStoreType.GridFs, BlobStoreType.FileSystem, startFromBeginning);
                return(false);
            });

            commands.Add("Copy blob from FileSystemFs to GridFs", () =>
            {
                var startFromBeginning = ConsoleHelper.AskYesNoQuestion("Do you want to start from the beginning of the stream?");
                BlobStoreSync command  = new BlobStoreSync(_loggerFactory.Create(typeof(BlobStoreSync)));
                command.SyncAllTenants(BlobStoreType.FileSystem, BlobStoreType.GridFs, startFromBeginning);
                return(false);
            });

            Menu(commands.Keys.ToList());
            CommandLoop(c =>
            {
                int menuSelection = 0;
                if (Int32.TryParse(c, out menuSelection))
                {
                    var func = commands.ElementAtOrDefault(menuSelection);
                    Console.WriteLine("Selected {0}", func.Key);
                    func.Value();
                }
                else
                {
                    if (String.Equals(c, "q", StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }

                    Console.WriteLine("Comando non valido! Premere un tasto per continuare");
                    Console.ReadKey();
                }
                Menu(commands.Keys.ToList());
                return(false);
            });
        }
예제 #13
0
 public void OneTimeSetUp()
 {
     MongoFlatMapper.EnableFlatMapping(true);
 }