Contains factory methods for building connections to an Event Store server.
Esempio n. 1
0
        public static void Configure(Configure args)
        {
            //set connection etc fluent API

            _name = args._name;
            _connection = new EventStoreConnection(new IPEndPoint(args._address, args._port));
        }
 public ViewBuilderService(EventStoreConnection eventStoreConnection, IEventStoreSerializer serializer,  IDocumentStore store, IModelUpdateNotifier updateNotifier)
 {
     _eventStoreConnection = eventStoreConnection;
     _serializer = serializer;
     _store = store;
     _updateNotifier = updateNotifier;
 }
        /// <summary>
        /// Constructs a new <see cref="EventStoreTransaction"/>
        /// </summary>
        /// <param name="transactionId">The transaction id of the transaction</param>
        /// <param name="connection">The connection the transaction is hooked to</param>
        internal EventStoreTransaction(long transactionId, EventStoreConnection connection)
        {
            Ensure.Nonnegative(transactionId, "transactionId");

            TransactionId = transactionId;
            _connection = connection;
        }
 public Event_Publisher(EventStoreConnection eventStoreConnection, string storeId)
 {
     _eventStoreConnection = eventStoreConnection;
     _storeId = storeId;
     _fileName = "checkpoint_" + _storeId;
     _batch = 100;
 }
Esempio n. 5
0
 public void which_supposed_to_be_system_should_succees__but_on_your_own_risk()
 {
     const string stream = "$which_supposed_to_be_system_should_succees__but_on_your_own_risk";
     using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var create = connection.CreateStreamAsync(stream, new byte[0]);
         Assert.DoesNotThrow(create.Wait);
     }
 }
Esempio n. 6
0
 public void which_does_not_exist_should_be_successfull()
 {
     const string stream = "which_does_not_exist_should_be_successfull";
     using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var create = connection.CreateStreamAsync(stream, new byte[0]);
         Assert.DoesNotThrow(create.Wait);
     }
 }
Esempio n. 7
0
 public static void Enable(EventStoreConnection store, string[] commandArgs)
 {
     var names = GetProjectionNames(commandArgs);
     foreach (var name in names)
     {
         Log("Enabling {0}...", name);
         store.Projections.Enable(name);
         Log("{0} enabled", name);
     }
 }
Esempio n. 8
0
 public static void Delete(EventStoreConnection store, string[] commandArgs)
 {
     var names = GetProjectionNames(commandArgs);
     foreach (var name in names)
     {
         Log("Deleting {0}...", name);
         store.Projections.Delete(name);
         Log("{0} deleted", name);
     }
 }
Esempio n. 9
0
 public void which_does_not_exist_should_fail()
 {
     const string stream = "which_does_not_exist_should_fail";
     using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.Any);
         Assert.Inconclusive();
         //Assert.That(() => delete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
     }
 }
Esempio n. 10
0
        public void which_already_exists_should_success_when_passed_empty_stream_expected_version()
        {
            const string stream = "which_already_exists_should_success_when_passed_empty_stream_expected_version";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);
            }
        }
Esempio n. 11
0
        public void should_append_with_correct_exp_ver_to_existing_stream()
        {
            const string stream = "should_append_with_correct_exp_ver_to_existing_stream";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = store.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var append = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, new[] { new TestEvent() });
                Assert.DoesNotThrow(append.Wait);
            }
        }
Esempio n. 12
0
        private static void Execute(EventStoreConnection store, string[] args)
        {
            var command = args[0].Trim().ToLower();
            var commandArgs = args.Skip(1).ToArray();

            Action<EventStoreConnection, string[]> executor;

            if(Commands.TryGetValue(command, out executor))
                executor(store, commandArgs);
            else
                Log("{0} is not a recognized command", args[0]);
        }
 public static int Count(EventStoreConnection store, string stream)
 {
     var result = 0;
     while (true)
     {
         var slice = store.ReadStreamEventsForward(stream, result, SliceSize, false);
         result += slice.Events.Length;
         if (slice.IsEndOfStream)
             break;
     }
     return result;
 }
Esempio n. 14
0
        public void with_invalid_expected_version_should_fail()
        {
            const string stream = "with_invalid_expected_version_should_fail";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, 1);
                Assert.That(() => delete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
            }
        }
Esempio n. 15
0
        public void can_append_multiple_events_at_once()
        {
            const string stream = "can_append_multiple_events_at_once";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = store.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var events = Enumerable.Range(0, 100).Select(i => new TestEvent(i.ToString(), i.ToString()));
                var append = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, events);
                Assert.DoesNotThrow(append.Wait);
            }
        }
Esempio n. 16
0
        public void which_already_exists_should_fail()
        {
            const string stream = "which_already_exists_should_fail";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var initialCreate = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(initialCreate.Wait);

                var secondCreate = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.Inconclusive();
                //Assert.That(() => secondCreate.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
            }
        }
Esempio n. 17
0
        public void should_create_stream_with_no_stream_exp_ver_on_first_write_if_does_not_exist()
        {
            const string stream = "should_create_stream_with_no_stream_exp_ver_on_first_write_if_does_not_exist";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var append = store.AppendToStreamAsync(stream, ExpectedVersion.NoStream, new[] {new TestEvent()});
                Assert.DoesNotThrow(append.Wait);

                var read = store.ReadEventStreamForwardAsync(stream, 0, 2);
                Assert.DoesNotThrow(read.Wait);
                Assert.That(read.Result.Events.Length, Is.EqualTo(2));
            }
        }
Esempio n. 18
0
        public void which_was_allready_deleted_should_fail()
        {
            const string stream = "which_was_allready_deleted_should_fail";
            using (var connection = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var create = connection.CreateStreamAsync(stream, new byte[0]);
                Assert.DoesNotThrow(create.Wait);

                var delete = connection.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);

                var secondDelete = connection.DeleteStreamAsync(stream, ExpectedVersion.Any);
                Assert.That(() => secondDelete.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
            }
        }
Esempio n. 19
0
        public static void Create(EventStoreConnection store, string[] commandArgs)
        {
            if (commandArgs.Length < 2)
            {
                Log("Invalid argument value (projection type)");
                return;
            }

            var type = commandArgs[0].Trim().ToLower();
            string pname;
            var query = GetQuery(commandArgs.Skip(1).ToArray(), out pname);

            if(query == null || (type != "onetime" && string.IsNullOrEmpty(pname)))
            {
                Log("Invalid arguments");
                return;
            }

            switch (type)
            {
                case "onetime":
                    Log("Creating onetime projection...");
                    store.Projections.CreateOneTime(query);
                    Log("Created");
                    break;
                case "adhoc":
                    Log("Creating adhoc projection {0}...", pname);
                    store.Projections.CreateAdHoc(pname, query);
                    Log("Created");
                    break;
                case "continuous":
                    Log("Creating continuous projection {0}...", pname);
                    store.Projections.CreateContinuous(pname, query);
                    Log("Created");
                    break;
                case "persistent":
                    Log("Creating persistent projection {0}...", pname);
                    store.Projections.CreatePersistent(pname, query);
                    Log("Created");
                    break;
                default:
                    Log("projection type not recognized");
                    break;
            }
        }
Esempio n. 20
0
        public void write_to_and_delete()
        {
            var endpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113);

            using (var connection = new EventStoreConnection(endpoint))
            {
                var ev     = new TestEvent("Some data");
                var stream = string.Format("test-delete-{0}", Guid.NewGuid());

                var appendTask = connection.AppendToStreamAsync(stream, -2, new[] { ev });
                appendTask.Wait();
                Assert.IsTrue(appendTask.Result.IsSuccessful, "Failed to append data to stream.");

                var data = connection.ReadEventStream(stream, 0, int.MaxValue);

                var lastEventVersion = data.Events[data.Events.Length - 1].EventNumber;

                var deleteTask = connection.DeleteStreamAsync(stream, lastEventVersion);
                deleteTask.Wait();
                Assert.IsTrue(deleteTask.Result.IsSuccessful, "Failed to delete stream.");
            }
        }
        public override void SetUp()
        {
            base.SetUp();
            _node = new MiniNode(PathName);
            _node.Start();

            _firstEvent = TestEvent.NewTestEvent();

            _connection = EventStoreConnection.Create();
            _connection.Connect(_node.TcpEndPoint);

            _connection.AppendToStream("test-stream",
                                       ExpectedVersion.NoStream,
                                       _firstEvent,
                                       TestEvent.NewTestEvent(),
                                       TestEvent.NewTestEvent());

            using (var transaction = _connection.StartTransaction("test-stream", 3))
            {
                transaction.Commit();
            }
        }
Esempio n. 22
0
        public IEventStoreConnection CreateConnectionWithConnectionString(
            bool useSsl,
            string configureSettings = default,
            int port            = 2113,
            bool useDnsEndPoint = false)
        {
            var settings = configureSettings ?? DefaultConfigureSettingsForConnectionString;
            var host     = useDnsEndPoint ? "localhost" : IPAddress.Loopback.ToString();

            if (useSsl)
            {
                settings += "UseSslConnection=true;ValidateServer=false;";
            }
            else
            {
                settings += "UseSslConnection=false;";
            }

            var gossipSeeds       = GetGossipSeedEndPointsExceptFor(-1, port, useDnsEndPoint);
            var gossipSeedsString = "";

            for (var i = 0; i < gossipSeeds.Length; i++)
            {
                if (i > 0)
                {
                    gossipSeedsString += ",";
                }
                gossipSeedsString += host + ":" + gossipSeeds[i].GetPort();
            }

            settings += "CustomHttpMessageHandler=SkipCertificateValidation;";

            var connectionString = $"GossipSeeds={gossipSeedsString};{settings}";

            return(EventStoreConnection.Create(connectionString));
        }
Esempio n. 23
0
        public IEventStoreConnection CreateConnectionWithGossipSeeds(
            Func <ConnectionSettingsBuilder, ConnectionSettingsBuilder> configureSettings = default,
            int port                = 2113,
            bool useDnsEndPoint     = false,
            int maxDiscoverAttempts = 1)
        {
            var settings = (configureSettings ?? DefaultConfigureSettings)(DefaultBuilder)
                           .Build();
            var gossipSeeds     = GetGossipSeedEndPointsExceptFor(-1, port, useDnsEndPoint);
            var clusterSettings = new ClusterSettingsBuilder()
                                  .DiscoverClusterViaGossipSeeds()
                                  .SetGossipSeedEndPoints(true, gossipSeeds);

            if (maxDiscoverAttempts == -1)
            {
                clusterSettings = clusterSettings.KeepDiscovering();
            }
            else
            {
                clusterSettings = clusterSettings.SetMaxDiscoverAttempts(maxDiscoverAttempts);
            }

            return(EventStoreConnection.Create(settings, clusterSettings.Build()));
        }
Esempio n. 24
0
        public void should_create_stream_if_commits_no_events_to_empty_stream()
        {
            const string stream = "should_create_stream_if_commits_no_events_to_empty_stream";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var start = store.StartTransactionAsync(stream, ExpectedVersion.NoStream);
                Assert.DoesNotThrow(start.Wait);
                var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
                Assert.DoesNotThrow(commit.Wait);

                var streamCreated = store.ReadEventStreamForwardAsync(stream, 0, 1);
                Assert.DoesNotThrow(streamCreated.Wait);

                Assert.That(streamCreated.Result.Events.Length, Is.EqualTo(1));//stream created event
            }
        }
Esempio n. 25
0
 public void should_validate_expectations_on_commit()
 {
     const string stream = "should_validate_expectations_on_commit";
     using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var start = store.StartTransactionAsync(stream, 100500);
         Assert.DoesNotThrow(start.Wait);
         var write = store.TransactionalWriteAsync(start.Result.TransactionId, stream, new[] { new TestEvent() });
         Assert.DoesNotThrow(write.Wait);
         var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
         Assert.That(() => commit.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<WrongExpectedVersionException>());
     }
 }
Esempio n. 26
0
 public void should_start_on_non_existing_stream_with_exp_ver_any_and_create_stream_on_commit()
 {
     const string stream = "should_start_on_non_existing_stream_with_exp_ver_any_and_create_stream_on_commit";
     using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
     {
         var start = store.StartTransactionAsync(stream, ExpectedVersion.Any);
         Assert.DoesNotThrow(start.Wait);
         var write = store.TransactionalWriteAsync(start.Result.TransactionId, stream, new[] {new TestEvent()});
         Assert.DoesNotThrow(write.Wait);
         var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
         Assert.DoesNotThrow(commit.Wait);
     }
 }
Esempio n. 27
0
        public void should_commit_when_writing_with_exp_ver_any_even_while_somene_is_writing_in_parallel()
        {
            const string stream = "should_commit_when_writing_with_exp_ver_any_even_while_somene_is_writing_in_parallel";

            var transWritesCompleted = new AutoResetEvent(false);
            var writesToSameStreamCompleted = new AutoResetEvent(false);

            var totalTranWrites = 500;
            var totalPlainWrites = 500;

            //excplicitly creating stream
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                store.CreateStream(stream, new byte[0]);

            //500 events during transaction
            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                {
                    var transaction = store.StartTransaction(stream, ExpectedVersion.Any);
                    var writes = new List<Task>();
                    for (int i = 0; i < totalTranWrites; i++)
                    {
                        if (i % 10 == 0)
                            writes.RemoveAll(write => write.IsCompleted);

                        writes.Add(store.TransactionalWriteAsync(transaction.TransactionId,
                                                                 transaction.Stream,
                                                                 new[] { new TestEvent((i + 1).ToString(), "trans write") }));
                    }

                    Task.WaitAll(writes.ToArray());
                    store.CommitTransaction(transaction.TransactionId, transaction.Stream);

                    transWritesCompleted.Set();
                }
            });

            //500 events to same stream in parallel
            ThreadPool.QueueUserWorkItem(_ =>
            {
                using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                {
                    var writes = new List<Task>();
                    for (int i = 0; i < totalPlainWrites; i++)
                    {
                        if (i % 10 == 0)
                            writes.RemoveAll(write => write.IsCompleted);

                        writes.Add(store.AppendToStreamAsync(stream,
                                                             ExpectedVersion.Any,
                                                             new[] {new TestEvent((i + 1).ToString(), "plain write")}));
                    }

                    Task.WaitAll(writes.ToArray());

                    writesToSameStreamCompleted.Set();
                }
            });

            transWritesCompleted.WaitOne();
            writesToSameStreamCompleted.WaitOne();

            //check all written
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var slice = store.ReadEventStreamForward(stream, 0, totalTranWrites + totalPlainWrites + 1);
                Assert.That(slice.Events.Length, Is.EqualTo(totalTranWrites + totalPlainWrites + 1));

                Assert.That(slice.Events.Count(ent => Encoding.UTF8.GetString(ent.Metadata) == "trans write"), Is.EqualTo(totalTranWrites));
                Assert.That(slice.Events.Count(ent => Encoding.UTF8.GetString(ent.Metadata) == "plain write"), Is.EqualTo(totalPlainWrites));
            }
        }
Esempio n. 28
0
        public void should_not_fail_to_commit_if_started_with_wrong_ver_but_committing_with_correct_ver()
        {
            const string stream = "should_not_fail_to_commit_if_started_with_wrong_ver_but_committing_with_correct_ver";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                store.CreateStream(stream, new byte[0]);

            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var start = store.StartTransactionAsync(stream, 1);
                Assert.DoesNotThrow(start.Wait);

                var append = store.AppendToStreamAsync(stream, ExpectedVersion.EmptyStream, new[] { new TestEvent() });
                Assert.DoesNotThrow(append.Wait);

                var write = store.TransactionalWriteAsync(start.Result.TransactionId, start.Result.Stream, new[] { new TestEvent() });
                Assert.DoesNotThrow(write.Wait);

                var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
                Assert.DoesNotThrow(commit.Wait);
            }
        }
Esempio n. 29
0
        public void should_fail_to_commit_if_started_with_correct_ver_but_on_commit_stream_was_deleted()
        {
            const string stream = "should_fail_to_commit_if_started_with_correct_ver_but_on_commit_stream_was_deleted";
            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
                store.CreateStream(stream, new byte[0]);

            using (var store = new EventStoreConnection(MiniNode.Instance.TcpEndPoint))
            {
                var start = store.StartTransactionAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(start.Wait);

                var write = store.TransactionalWriteAsync(start.Result.TransactionId, start.Result.Stream, new[] { new TestEvent() });
                Assert.DoesNotThrow(write.Wait);

                var delete = store.DeleteStreamAsync(stream, ExpectedVersion.EmptyStream);
                Assert.DoesNotThrow(delete.Wait);

                var commit = store.CommitTransactionAsync(start.Result.TransactionId, start.Result.Stream);
                Assert.That(() => commit.Wait(), Throws.Exception.TypeOf<AggregateException>().With.InnerException.TypeOf<StreamDeletedException>());
            }
        }
Esempio n. 30
0
 public EventStoreWrapper(EventStoreConnection eventStoreConnection, Func<Dictionary<string, object>> writeMetaData)
 {
     this.eventStoreConnection = eventStoreConnection;
     this.writeMetaData = writeMetaData;
 }
Esempio n. 31
0
 public static void Configure(Configure args)
 {
     _name       = args._name;
     _connection = new EventStoreConnection(new IPEndPoint(args._address, args._port));
 }
Esempio n. 32
0
 public StreamWriter(EventStoreConnection store, string stream, int version)
 {
     _store = store;
     _stream = stream;
     _version = version;
 }
Esempio n. 33
0
 public TransactionalWriter(EventStoreConnection store, string stream)
 {
     _store = store;
     _stream = stream;
 }
 public void SetUp()
 {
     _connection = EventStoreConnection.Create();
     _connection.Connect(IntegrationTestTcpEndPoint);
     _repo = new GetEventStoreRepository(_connection);
 }