示例#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);
        }
示例#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}");
        }
        public void load_mongo_task()
        {
            var options = BuildMongoConnectionOptions();

            _mongoStore = new MongoPersistence(options);
            _mongoStore.InitAsync(CancellationToken.None).Wait();

            task_worker(_mongoStore);
        }
        public void load_mongo_async()
        {
            var options = BuildMongoConnectionOptions();

            var store = new MongoPersistence(options);

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

            async_worker(store).GetAwaiter().GetResult();
        }
示例#5
0
        static IPersistence MongoConnect()
        {
            var options = new MongoPersistenceOptions()
            {
                UseLocalSequence           = true,
                PartitionsConnectionString = _mongo
            };
            var mongo = new MongoPersistence(options);

            mongo.InitAsync(CancellationToken.None).GetAwaiter().GetResult();
            return(mongo);
        }
        public void batcher_decorator()
        {
            var options = BuildMongoConnectionOptions();

            var store = new MongoPersistence(options);

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

            var persistenceBatcher = new PersistenceBatchAppendDecorator(store, BatchSize, FlushTimeout);

            TaskWorker.Run(persistenceBatcher, _iterations).GetAwaiter().GetResult();
            persistenceBatcher.Dispose();
        }
        public async Task <IPersistence> BuildEventStore(
            string connectionString)
        {
            var mongoStoreOptions = new MongoPersistenceOptions
            {
                PartitionsConnectionString = connectionString,
                UseLocalSequence           = true,
                PartitionsCollectionName   = PartitionCollectionName,
                SequenceCollectionName     = "event_sequence",
                DropOnInit = false
            };

            var mongoPersistence = new MongoPersistence(mongoStoreOptions);

            await mongoPersistence.InitAsync(CancellationToken.None).ConfigureAwait(false);

            return(mongoPersistence);
        }