public void setting_metadata_for_deleted_stream_throws_stream_deleted_exception()
        {
            _connection.DeleteStreamAsync(_stream, ExpectedVersion.NoStream, hardDelete: true).Wait();

            var metadataBytes = Guid.NewGuid().ToByteArray();

            Assert.That(() => _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.EmptyStream, metadataBytes).Wait(),
                        Throws.Exception.InstanceOf <AggregateException>()
                        .With.InnerException.InstanceOf <StreamDeletedException>());
        }
Пример #2
0
        public async Task setting_metadata_for_deleted_stream_throws_stream_deleted_exception()
        {
            const string stream = "setting_metadata_for_deleted_stream_throws_stream_deleted_exception";

            await _connection.DeleteStreamAsync(stream, ExpectedVersion.NoStream, hardDelete : true);

            var metadataBytes = Guid.NewGuid().ToByteArray();
            await AssertEx.ThrowsAsync <StreamDeletedException>(
                () => _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadataBytes));
        }
Пример #3
0
        public async Task soft_deleted_stream_returns_no_stream_and_no_events_on_read()
        {
            const string stream = "soft_deleted_stream_returns_no_stream_and_no_events_on_read";

            Assert.AreEqual(1,
                            (await _conn.AppendToStreamAsync(stream, ExpectedVersion.NoStream, TestEvent.NewTestEvent(),
                                                             TestEvent.NewTestEvent())).NextExpectedVersion);
            await _conn.DeleteStreamAsync(stream, 1);

            var res = await _conn.ReadStreamEventsForwardAsync(stream, 0, 100, false);

            Assert.AreEqual(SliceReadStatus.StreamNotFound, res.Status);
            Assert.AreEqual(0, res.Events.Length);
            Assert.AreEqual(1, res.LastEventNumber);
        }
Пример #4
0
        public async Task SoftDelete(TId selector)
        {
            var id = selector.ToString();
            var expectedVersion = await GetLastEventNumber(id);

            await connection.DeleteStreamAsync(id, expectedVersion);
        }
Пример #5
0
        public static async Task DeleteStreamsByCategory(IEventStoreConnection conn, string category, bool hardDelete = false)
        {
            IEnumerable <string> streamIds = await GetStreamIdsByCategoryBy(conn, category);

            if (!streamIds.Any())
            {
                Console.WriteLine("INFO: No stream was found. Exitting.");
                return;
            }

            Console.WriteLine($"[{streamIds.Count()}] streams for category [{category}] will be deleted. Are you sure? (press any key to confirm or ctrl-c to exit)");
            Console.ReadLine();

            foreach (var id in streamIds)
            {
                try
                {
                    await conn.DeleteStreamAsync(id, ExpectedVersion.Any, hardDelete);

                    Console.WriteLine($"DEBUG: [{id}]");
                }
                catch (StreamDeletedException e)
                {
                    Console.WriteLine($"INFO: Stream [{e.Stream} is already deleted. Skipped]");
                }
            }

            Console.WriteLine("INFO: Success");
        }
Пример #6
0
        async Task SagaConsumeContext <TSaga> .SetCompleted()
        {
            await _connection.DeleteStreamAsync(Saga.StreamName, Saga.ExpectedVersion, false);

            IsCompleted = true;

            this.LogRemoved();
        }
Пример #7
0
        public async Task Delete(TId selector)
        {
            var id         = selector.ToString();
            var eventsTail = await connection.ReadStreamEventsBackwardAsync(id, 0, 1, false);

            var expectedVersion = eventsTail.LastEventNumber;
            await connection.DeleteStreamAsync(id, expectedVersion);
        }
        public Task Delete(T aggregate)
        {
            var streamName      = AggregateIdToStreamName(typeof(T), aggregate.Id);
            var newEvents       = aggregate.GetUncommittedChanges().Cast <object>().ToList();
            var originalVersion = aggregate.Version - newEvents.Count;
            var expectedVersion = originalVersion < 0 ? ExpectedVersion.NoStream : originalVersion;

            return(_eventStoreConnection.DeleteStreamAsync(streamName, expectedVersion));
        }
Пример #9
0
 public async Task DeleteAggregateAsync <TIdentity, TAggregate>(
     TIdentity id,
     AggregateConfiguration <TIdentity, TAggregate> configuration,
     long expectedVersion,
     CancellationToken cancellationToken = default
     ) where TAggregate : Aggregate <TIdentity, TAggregate>
 {
     var stream = _streamNameResolver.Stream(id, configuration);
     await _connection.DeleteStreamAsync(stream, expectedVersion);
 }
        public void ThrowsOnGetDeletedAggregate()
        {
            var aggregateId = SaveTestAggregateWithoutCustomHeaders(_repo, 10);

            var streamName = $"testWoftamAggregate-{aggregateId.ToString("N")}";

            _connection.DeleteStreamAsync(streamName, 10).Wait();

            // Assert.Throws<AggregateDeletedException>(() => _repo.GetById<TestAggregate>(aggregateId));
            //Looks like an api change
            Assert.Throws <AggregateNotFoundException>(() => _repo.GetById <TestWoftamAggregate>(aggregateId));
        }
Пример #11
0
        async Task SagaConsumeContext <TSaga> .SetCompleted()
        {
            await _connection.DeleteStreamAsync(Saga.StreamName, Saga.ExpectedVersion, false);

            IsCompleted = true;
            if (Log.IsDebugEnabled)
            {
                Log.DebugFormat("SAGA:{0}:{1} Removed {2}", TypeMetadataCache <TSaga> .ShortName,
                                TypeMetadataCache <TMessage> .ShortName,
                                Saga.CorrelationId);
            }
        }
Пример #12
0
        public void getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion()
        {
            var metadata = StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));

            _connection.SetStreamMetadataAsync(_stream, ExpectedVersion.EmptyStream, metadata).Wait();

            _connection.DeleteStreamAsync(_stream, ExpectedVersion.EmptyStream, hardDelete: true).Wait();

            var meta = _connection.GetStreamMetadataAsync(_stream).Result;

            Assert.AreEqual(_stream, meta.Stream);
            Assert.AreEqual(true, meta.IsStreamDeleted);
            Assert.AreEqual(EventNumber.DeletedStream, meta.MetastreamVersion);
            Assert.AreEqual(null, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(null, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(null, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(null, meta.StreamMetadata.CacheControl);
            Assert.AreEqual(null, meta.StreamMetadata.Acl);
        }
        public async Task getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion()
        {
            const string stream =
                "getting_metadata_for_deleted_stream_returns_empty_stream_metadata_and_signals_stream_deletion";

            var metadata =
                StreamMetadata.Create(17, TimeSpan.FromSeconds(0xDEADBEEF), 10, TimeSpan.FromSeconds(0xABACABA));
            await _connection.SetStreamMetadataAsync(stream, ExpectedVersion.NoStream, metadata);

            await _connection.DeleteStreamAsync(stream, ExpectedVersion.NoStream, hardDelete : true);

            var meta = await _connection.GetStreamMetadataAsync(stream);

            Assert.AreEqual(stream, meta.Stream);
            Assert.AreEqual(true, meta.IsStreamDeleted);
            Assert.AreEqual(EventNumber.DeletedStream, meta.MetastreamVersion);
            Assert.AreEqual(null, meta.StreamMetadata.MaxCount);
            Assert.AreEqual(null, meta.StreamMetadata.MaxAge);
            Assert.AreEqual(null, meta.StreamMetadata.TruncateBefore);
            Assert.AreEqual(null, meta.StreamMetadata.CacheControl);
            Assert.AreEqual(null, meta.StreamMetadata.Acl);
        }
        public static void DeleteAllStreams(this IEventStoreConnection connection)
        {
            var slice = connection.
                        ReadAllEventsForwardAsync(
                Position.Start, Int32.MaxValue, false, EmbeddedEventStore.Credentials);

            slice.Wait();
            var streams = slice.Result.
                          Events.
                          Select(_ => _.OriginalStreamId).
                          Where(StreamNameIsNotReserved).
                          Distinct();

            foreach (var stream in streams)
            {
                var streamStatusSlice = connection.ReadStreamEventsForwardAsync(stream, 0, 1, false);
                streamStatusSlice.Wait();
                if (streamStatusSlice.Result.Status != SliceReadStatus.StreamDeleted &&
                    streamStatusSlice.Result.Status != SliceReadStatus.StreamNotFound)
                {
                    connection.DeleteStreamAsync(stream, ExpectedVersion.Any, EmbeddedEventStore.Credentials).Wait();
                }
            }
        }
Пример #15
0
 public void Dispose()
 {
     connection.DeleteStreamAsync(stream, ExpectedVersion.Any).Wait();
     connection.Dispose();
 }
 public Task DeleteEventsAsync(IIdentity id, CancellationToken cancellationToken)
 {
     return(_connection.DeleteStreamAsync(id.Value, ExpectedVersion.Any));
 }
Пример #17
0
 public Task DeleteStreamAsync(string streamName)
 {
     return(connection.DeleteStreamAsync(streamName, ExpectedVersion.Any));
 }
 public Task <DeleteResult> Delete(string streamId, int expectedVersion)
 {
     return(_eventStoreConnection.DeleteStreamAsync(streamId, expectedVersion));
 }
Пример #19
0
        public Task DeleteStreamAsync(string streamName)
        {
            Guard.NotNullOrEmpty(streamName, nameof(streamName));

            return(connection.DeleteStreamAsync(GetStreamName(streamName), ExpectedVersion.Any));
        }
 protected void DeleteStream(string streamId, string login, string password)
 {
     Connection.DeleteStreamAsync(streamId, ExpectedVersion.Any, true,
                                  login == null && password == null ? null : new UserCredentials(login, password)).Wait();
 }
Пример #21
0
        public override void DeleteAggregate <TAggregate>(string correlationId, bool hard)
        {
            var streamName = AggregateToStreamName(typeof(TAggregate), correlationId);

            _connection.DeleteStreamAsync(streamName, ExpectedVersion.Any, hard).Wait();
        }
 public async Task DeleteStreamAsync(string streamName, int expectedVersion, bool hardDelete = false)
 {
     await connection.DeleteStreamAsync(streamName, expectedVersion, hardDelete).ConfigureAwait(false);
 }
Пример #23
0
 public override Task DeleteAggregateAsync <TAggregate, TIdentity>(
     TIdentity id,
     CancellationToken cancellationToken)
 {
     return(_connection.DeleteStreamAsync(id.Value, ExpectedVersion.Any));
 }
Пример #24
0
        public async Task InitializeAsync()
        {
            _eventStoreContainer = "es" + Guid.NewGuid().ToString("N");

            var address = Environment.OSVersion.Platform == PlatformID.Unix
                ? new Uri("unix:///var/run/docker.sock")
                : new Uri("npipe://./pipe/docker_engine");

            var config = new DockerClientConfiguration(address);

            _client = config.CreateClient();

            var images =
                await _client.Images.ListImagesAsync(new ImagesListParameters { MatchName = EventStoreImage });

            if (images.Count == 0)
            {
                Console.WriteLine("[docker] no image found - pulling latest");

                await _client.Images.CreateImageAsync(
                    new ImagesCreateParameters { FromImage = EventStoreImage, Tag = "latest" }, null,
                    IgnoreProgress.Forever);
            }

            Console.WriteLine("[docker] creating container " + _eventStoreContainer);

            var port = 1113;

            await _client.Containers.CreateContainerAsync(
                new CreateContainerParameters
            {
                Image      = EventStoreImage,
                Name       = _eventStoreContainer,
                Tty        = true,
                HostConfig = new HostConfig
                {
                    PortBindings = new Dictionary <string, IList <PortBinding> >
                    {
                        {
                            "1113/tcp",
                            new List <PortBinding>
                            {
                                new PortBinding
                                {
                                    HostPort = $"{port}"
                                }
                            }
                        }
                    }
                }
            });

            Console.WriteLine("[docker] starting container " + _eventStoreContainer);

            await _client.Containers.StartContainerAsync(_eventStoreContainer, new ContainerStartParameters { });

            var endpoint = new Uri($"tcp://127.0.0.1:{port}");

            var settings = ConnectionSettings
                           .Create()
                           .KeepReconnecting()
                           .KeepRetrying()
                           .SetDefaultUserCredentials(new UserCredentials("admin", "changeit"));

            var connectionName =
                $"M={Environment.MachineName},P={Process.GetCurrentProcess().Id},T={DateTimeOffset.UtcNow.Ticks}";

            EventStoreConnection = EventStore.ClientAPI.EventStoreConnection.Create(settings, endpoint, connectionName);

            Console.WriteLine("[docker] connecting to EventStore");

            await EventStoreConnection.ConnectAsync();

            // Fix for EventStore throwing NotAuthenticatedException
            // because of not being ready but accepting connections
            var connected = false;

            while (!connected)
            {
                try
                {
                    await EventStoreConnection.DeleteStreamAsync("stream", -1);

                    connected = true;
                }
                catch (NotAuthenticatedException ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Пример #25
0
 /// <inheritdoc />
 protected override async Task TruncateStreamStore(IStream stream, int version)
 {
     await _connection.DeleteStreamAsync(stream.Key, version);
 }
Пример #26
0
 protected Task DeleteStream(string streamId, string login, string password)
 {
     return(Connection.DeleteStreamAsync(streamId, ExpectedVersion.Any, true,
                                         login == null && password == null ? null : new UserCredentials(login, password)));
 }
Пример #27
0
 protected Task HardDeleteStream(string stream)
 {
     return(_conn.DeleteStreamAsync(stream, ExpectedVersion.Any, true, _admin));
 }
Пример #28
0
 protected void HardDeleteStream(string stream)
 {
     _conn.DeleteStreamAsync(stream, ExpectedVersion.Any, true, _admin).Wait();
 }
Пример #29
0
 public Task DeleteEventsAsync <TAggregate, TIdentity>(IIdentity id, CancellationToken cancellationToken)
     where TAggregate : IAggregateRoot <TIdentity>
     where TIdentity : IIdentity
 {
     return(_connection.DeleteStreamAsync(_eventStoreStreamNameFactory.GetStreamName(typeof(TAggregate), id), ExpectedVersion.Any));
 }