Exemple #1
0
        private IPersistence Create()
        {
            var mongo = Environment.GetEnvironmentVariable("NSTORE_MONGODB");

            if (string.IsNullOrWhiteSpace(mongo))
            {
                throw new TestMisconfiguredException("NSTORE_MONGODB environment variable not set");
            }

            _id = Interlocked.Increment(ref _staticId);

            _options = new MongoStoreOptions
            {
                PartitionsConnectionString = mongo,
                UseLocalSequence           = true,
                PartitionsCollectionName   = "partitions_" + GetType().Name + "_" + _id,
                SequenceCollectionName     = "seq_" + _id,
                DropOnInit = true
            };
            _mongoPersistence = new MongoPersistence(_options);

            _mongoPersistence.InitAsync(CancellationToken.None).Wait();

            return(_mongoPersistence);
        }
Exemple #2
0
        static IPersistence BuildStore(string store)
        {
            Console.WriteLine($"Selected store is {store}");

            switch (store.ToLowerInvariant())
            {
            case "memory":
            {
                var network = new ReliableNetworkSimulator(2, 10);
                return(new InMemoryPersistence(network, ObjectSerializer.Clone));
            }

            case "mongo":
            {
                var options = new MongoStoreOptions
                {
                    PartitionsConnectionString = Mongo,
                    UseLocalSequence           = true,
                    PartitionsCollectionName   = "partitions",
                    SequenceCollectionName     = "seq",
                    DropOnInit = true,
                    Serializer = new MongoCustomSerializer(),
                    CustomizePartitionSettings = settings =>
                    {
                        settings.MaxConnectionPoolSize = 5000;
                    }
                };
                var mongo = new MongoPersistence(options);
                mongo.InitAsync(CancellationToken.None).GetAwaiter().GetResult();
                return(mongo);
            }
            }

            throw new Exception($"Invalid store {store}");
        }
Exemple #3
0
        public static IServiceCollection AddInfrastructure(this IServiceCollection services, Action <MongoStoreOptions> setupDatabaseAction)
        {
            services.AddAutoMapper(Assembly.GetExecutingAssembly());

            var dbOptions = new MongoStoreOptions();

            setupDatabaseAction(dbOptions);

            services.AddMongoBoardToInfrastructure <TaskBoard, MongoTaskBoard>(dbOptions);
            services.AddMongoListToInfrastructure <TaskList, MongoTaskList>(dbOptions);
            services.AddMongoCardToInfrastructure <TaskCard, MongoTaskCard>(dbOptions);

            return(services);
        }
Exemple #4
0
        private static IServiceCollection AddMongoCardToInfrastructure <TCard, TMongoCard>(
            this IServiceCollection services,
            MongoStoreOptions mongoStoreOptions)
            where TCard : TaskCard
            where TMongoCard : MongoTaskCard
        {
            var taskCardsCollection = MongoStoreUtil.FromConnectionString <TMongoCard>(mongoStoreOptions.ConnectionString, mongoStoreOptions.TaskCardsCollection);

            services.AddSingleton(x => taskCardsCollection);

            services.AddTransient(typeof(ICreateTaskCardEntity <TCard>), typeof(TaskCardStore <TCard, TMongoCard>));
            services.AddTransient(typeof(IUpdateTaskCardEntity <TCard>), typeof(TaskCardStore <TCard, TMongoCard>));
            services.AddTransient(typeof(IDeleteTaskCardEntity <TCard>), typeof(TaskCardStore <TCard, TMongoCard>));
            services.AddTransient(typeof(IGetTaskCardEntity <TCard>), typeof(TaskCardStore <TCard, TMongoCard>));

            return(services);
        }
Exemple #5
0
        private static IServiceCollection AddMongoListToInfrastructure <TList, TMongoList>(
            this IServiceCollection services,
            MongoStoreOptions mongoStoreOptions)
            where TList : TaskList
            where TMongoList : MongoTaskList
        {
            var taskListsCollection = MongoStoreUtil.FromConnectionString <TMongoList>(mongoStoreOptions.ConnectionString, mongoStoreOptions.TaskListsCollection);

            services.AddSingleton(x => taskListsCollection);

            services.AddTransient(typeof(ICreateTaskListEntity <TList>), typeof(TaskListStore <TList, TMongoList>));
            services.AddTransient(typeof(IUpdateTaskListEntity <TList>), typeof(TaskListStore <TList, TMongoList>));
            services.AddTransient(typeof(IDeleteTaskListEntity <TList>), typeof(TaskListStore <TList, TMongoList>));
            services.AddTransient(typeof(IGetTaskListEntity <TList>), typeof(TaskListStore <TList, TMongoList>));

            return(services);
        }
        private static MongoStoreOptions BuildMongoConnectionOptions()
        {
            var id = Interlocked.Increment(ref Id);

            var options = new MongoStoreOptions
            {
                PartitionsConnectionString = Mongo,
                UseLocalSequence           = true,
                PartitionsCollectionName   = "partitions_" + id,
                SequenceCollectionName     = "seq_" + id,
                DropOnInit = true,
                CustomizePartitionSettings = settings =>
                {
                    settings.MaxConnectionPoolSize = 20000;
                    settings.WaitQueueSize         = 40000;
                }
            };

            return(options);
        }
Exemple #7
0
        public IRawStore Create()
        {
            _id = Interlocked.Increment(ref StaticId);

            _options = new MongoStoreOptions
            {
                PartitionsConnectionString = Mongo,
                UseLocalSequence           = true,
                PartitionsCollectionName   = "partitions_" + _id,
                SequenceCollectionName     = "seq_" + _id,
                DropOnInit = true
            };
            _mongoRawStore = new MongoRawStore(_options);

            Console.WriteLine($"Setup {_id} {GetType().Name}");

            _mongoRawStore.InitAsync()
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();

            return(_mongoRawStore);
        }