Start() public method

public Start ( CancellationToken token ) : Task
token System.Threading.CancellationToken
return Task
Esempio n. 1
0
        public void messages_for_one_batch_should_have_one_write()
        {
            var storage = new InMemoryEventStorage();
            var writer = new EventStorageWriter(10, TimeSpan.FromMinutes(1), storage);

            var task1 = writer.Store(new CommitForStorage("foo", "stream1",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));
            var task2 = writer.Store(new CommitForStorage("foo", "stream2",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));
            writer.Start(_token.Token);

            Task.WhenAll(task1, task2).Wait(1000);

            Assert.AreEqual(1, storage.WriteCount);
        }
Esempio n. 2
0
        public void should_be_able_to_write_max_commits_in_one_batch()
        {
            var storage = new InMemoryEventStorage();
            var writer = new EventStorageWriter(3000, TimeSpan.FromMinutes(5), storage,3000);
            var listOfTasks = new List<Task>();

            for(var i=0;i<3000;i++)
            {
                listOfTasks.Add(writer.Store(new CommitForStorage("foo", "stream1",
                                              new EventForStorage(Guid.NewGuid(), i+1, DateTime.Now, "type", null, "body"))));
            }

            writer.Start(_token.Token);

            Task.WhenAll(listOfTasks).Wait();

            Assert.That(storage.WriteCount,Is.EqualTo(1),"The commits are written in multiple batches.");
        }
Esempio n. 3
0
        public void Start(ResConfiguration config)
        {
            Logger.Info("[ResHost] Starting...Geronimo....");
            _cancellationToken = new CancellationTokenSource();
            var eventStorage = getEventStorage(config.ConnectionStringName);
            var storageWriter = new EventStorageWriter(config.Writer.BufferSize, config.Writer.TimeoutBeforeDrop,
                eventStorage, config.Writer.BatchSize);
            storageWriter.Start(_cancellationToken.Token);
            var storageReader = new EventStorageReader(config.Reader.BufferSize, config.Reader.TimeoutBeforeDrop,
                eventStorage, config.Reader.BatchSize);

            _publishEndpoint = new PublishEndpoint(storageWriter, config);
            _publishEndpoint.Start(_cancellationToken.Token);

            _queryEndpoint = new QueryEndpoint(storageReader, config);
            _queryEndpoint.Start(_cancellationToken.Token);

            var queueStorage = getQueueStorage(config.ConnectionStringName, eventStorage);
            _queueEndpoint = new QueueEndpoint(queueStorage, config);
            _queueEndpoint.Start(_cancellationToken.Token);

            Logger.Info("[ResHost] Started. All systems go...");
        }
Esempio n. 4
0
        public void should_drop_commits_older_than_timeout()
        {
            var storage = new InMemoryEventStorage();
            var writer = new EventStorageWriter(10, TimeSpan.FromMilliseconds(1), storage, 2);

            var task1 = writer.Store(new CommitForStorage("foo", "stream1",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));
            var task2 = writer.Store(new CommitForStorage("foo", "stream2",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));

            Task.Delay(1).Wait();

            writer.Start(_token.Token);

            try
            {
                Task.WhenAll(task1, task2).Wait(1000);
            }
            catch (AggregateException e)
            {
                throw e.Flatten().InnerException;
            }
        }
Esempio n. 5
0
        public void storage_exception_should_get_sent_to_task()
        {
            var storage = A.Fake<EventStorage>();
            A.CallTo(storage).Throws(() => new EventStorageException("Damn", null));

            var writer = new EventStorageWriter(10, TimeSpan.FromMinutes(1), storage, 2);

            var task1 = writer.Store(new CommitForStorage("foo", "stream1",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));
            writer.Start(_token.Token);

            try
            {
                task1.Wait(1000);
            }
            catch (AggregateException e)
            {
                throw e.Flatten().InnerException;
            }
        }
Esempio n. 6
0
        public void should_store_messages()
        {
            var storage = new InMemoryEventStorage();
            var writer = new EventStorageWriter(10, TimeSpan.FromMinutes(1), storage);

            writer.Start(_token.Token);

            var task1 = writer.Store(new CommitForStorage("foo", "stream1",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));
            var task2 = writer.Store(new CommitForStorage("foo", "stream2",
                                              new EventForStorage(Guid.NewGuid(), 1, DateTime.Now, "type", null, "body")));

            Task.WhenAll(task1, task2).Wait(1000);

            var stream1Events = storage.LoadEvents("foo", "stream1");
            var stream2Events = storage.LoadEvents("foo", "stream2");

            Assert.AreEqual(1, stream1Events.Length, "stream1 should have one event.");
            Assert.AreEqual(1, stream2Events.Length, "stream2 should have one event.");
        }