コード例 #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(ctx => {
                var log = ctx.GetService <ILogger <Startup> >();
                //RESEARCH: Should this be in a hosted service instead?
                var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode()
                                  .DisableExternalTls()
                                  .DisableInternalTls()
                                  .WithInternalHttpOn(new IPEndPoint(IPAddress.Loopback, 1112))
                                  .WithInternalTcpOn(new IPEndPoint(IPAddress.Loopback, 1113))
                                  .DisableDnsDiscovery()
                                  .WithGossipSeeds(new IPEndPoint[] {
                    new IPEndPoint(IPAddress.Loopback, 2112),
                    new IPEndPoint(IPAddress.Loopback, 3112)
                })
                                  .EnableTrustedAuth()
                                  .RunInMemory();
                Node = nodeBuilder.Build();
                Node.StartAsync(true).Wait();

                var conn = EmbeddedEventStoreConnection.Create(Node,
                                                               ConnectionSettings.Create()
                                                               .SetDefaultUserCredentials(new UserCredentials("admin", "changeit"))
                                                               .Build());
                conn.ConnectAsync().Wait(TimeSpan.FromSeconds(30));

                return(conn);
            });

            services.AddRazorPages();
            services.AddServerSideBlazor();
            services.AddSingleton <WeatherForecastService>();
        }
コード例 #2
0
        public static ClusterVNode Start()
        {
            var node = EmbeddedVNodeBuilder
                       .AsSingleNode()
                       .OnDefaultEndpoints()
                       .NoStatsOnPublicInterface()
                       .NoAdminOnPublicInterface()
                       .RunProjections(ProjectionsMode.All)
                       .Build();

            var taskCompletionSource = new TaskCompletionSource <object>();

            node.NodeStatusChanged += (sender, args) =>
            {
                if (args.NewVNodeState == VNodeState.Master)
                {
                    taskCompletionSource.SetResult(new object());
                }
            };

            node.Start();

            taskCompletionSource.Task.Wait(TimeSpan.FromSeconds(30));

            return(node);
        }
コード例 #3
0
        public static void Start()
        {
            var node = EmbeddedVNodeBuilder.
                       AsSingleNode().
                       OnDefaultEndpoints().
                       RunInMemory().
                       Build();

            node.Start();
            var tcs = new TaskCompletionSource <object>();

            node.NodeStatusChanged += (sender, args) =>
            {
                if (args.NewVNodeState == VNodeState.Master)
                {
                    tcs.SetResult(null);
                }
            };
            tcs.Task.Wait();
            Node        = node;
            Credentials = new UserCredentials("admin", "changeit");
            var connection = EmbeddedEventStoreConnection.Create(Node);

            // This does not work, because ... ††† JEZUS †††
            //var connection = EventStoreConnection.Create(
            //    ConnectionSettings.Create().SetDefaultUserCredentials(Credentials).UseDebugLogger(),
            //    new IPEndPoint(Opts.InternalIpDefault, Opts.ExternalTcpPortDefault));
            connection.ConnectAsync().Wait();
            Connection = connection;
        }
コード例 #4
0
        public void Establish()
        {
            s_eventStoreNodeStarted     = false;
            s_eventStoreClientConnected = false;

            var noneIp = new IPEndPoint(IPAddress.None, 0);

            s_eventStoreNode = EmbeddedVNodeBuilder
                               .AsSingleNode()
                               .RunInMemory()
                               .WithExternalTcpOn(noneIp)
                               .WithInternalTcpOn(noneIp)
                               .WithExternalHttpOn(noneIp)
                               .WithInternalHttpOn(noneIp)
                               .Build();
            s_eventStoreNode.NodeStatusChanged +=
                (sender, e) => { if (e.NewVNodeState == VNodeState.Master)
                                 {
                                     s_eventStoreNodeStarted = true;
                                 }
            };
            s_eventStoreNode.Start();

            s_eventStore            = EmbeddedEventStoreConnection.Create(s_eventStoreNode);
            s_eventStore.Connected += (sender, e) => { s_eventStoreClientConnected = true; };
            s_eventStore.ConnectAsync().Wait();

            s_eventStoreMessageStore = new EventStoreMessageStore(s_eventStore);

            EnsureEventStoreNodeHasStartedAndTheClientHasConnected();
        }
コード例 #5
0
        public TestRegistry()
        {
            var          noIp = new IPEndPoint(IPAddress.None, 0);
            ClusterVNode node = EmbeddedVNodeBuilder
                                .AsSingleNode()
                                .WithInternalTcpOn(noIp)
                                .WithInternalHttpOn(noIp)
                                .RunInMemory()
                                .Build();
            var connection = EmbeddedEventStoreConnection.Create(node);

            For <ClusterVNode>()
            .Singleton()
            .Use(node);

            For <IEventStoreConnection>()
            .Singleton()
            .Use(connection);

            For <EventStoreUnitOfWork>()
            .HybridHttpOrThreadLocalScoped()
            .Use <TestUnitOfWork>()
            .Ctor <IEventEmitter>()
            .Is(c => c.GetInstance <IEventEmitter>())
            ;

            //For<IEventRepository>()
            //    .Use(c => c.GetInstance<TestUnitOfWork>().EventRepository)
            //    ;
            For <NHibernateUnitOfWork>()
            .HybridHttpOrThreadLocalScoped()
            .Use <NHibernateUnitOfWork>();
        }
コード例 #6
0
        private void CreateEmbeddedServer()
        {
            EmbeddedVNodeBuilder builder;

            builder = EmbeddedVNodeBuilder.AsSingleNode();
            builder.RunProjections(ProjectionsMode.All);
            builder.OnDefaultEndpoints();
            if (_runneroptions.RunInMemory)
            {
                builder.RunInMemory();
            }
            else
            {
                string combinedPath;
                if (Path.IsPathRooted(_runneroptions.DataDirectory))
                {
                    combinedPath = _runneroptions.DataDirectory;
                }
                else
                {
                    combinedPath = Path.Combine(Assembly.GetExecutingAssembly().GetExecutingFolder(), _runneroptions.DataDirectory);
                }
                builder.RunOnDisk(combinedPath);
            }
            _embeddednode = builder.Build();
            _embeddednode.Start();
        }
コード例 #7
0
        public ResolvedEventtDispatcherTests()
        {
            var source = new TaskCompletionSource <bool>();

            _nodeStarted = source.Task;

            var notListening = new IPEndPoint(IPAddress.None, 0);

            _node = EmbeddedVNodeBuilder.AsSingleNode()
                    .WithInternalTcpOn(notListening)
                    .WithExternalTcpOn(notListening)
                    .WithInternalHttpOn(notListening)
                    .WithExternalHttpOn(notListening);

            _node.NodeStatusChanged += (_, e) =>
            {
                if (e.NewVNodeState != VNodeState.Master)
                {
                    return;
                }

                source.SetResult(true);
            };

            _node.Start();

            _connection = EmbeddedEventStoreConnection.Create(_node);
        }
コード例 #8
0
        private void Bootstrap()
        {
            // GetEventStore runs on the client on default tcp port 1113. Thus, the in memory cannot run on the same.
            _node =
                EmbeddedVNodeBuilder.AsSingleNode()
                .RunInMemory()
                .WithInternalTcpOn(new IPEndPoint(IPAddress.Loopback, 1114))
                .WithExternalTcpOn(new IPEndPoint(IPAddress.Loopback, 1115))
                .WithInternalHttpOn(new IPEndPoint(IPAddress.Loopback, 2114))
                .WithExternalHttpOn(new IPEndPoint(IPAddress.Loopback, 2115))
                .Build();

            bool isNodeMaster = false;

            _node.NodeStatusChanged += (sender, args) => isNodeMaster = args.NewVNodeState == VNodeState.Master;
            _node.Start();

            var stopwatch = new Stopwatch();

            stopwatch.Start();
            while (!isNodeMaster)
            {
                if (stopwatch.Elapsed.Seconds > 20)
                {
                    throw new EventStoreConnectionException("In memory node failed to become master within the time limit");
                }
                Thread.Sleep(1);
            }
            stopwatch.Stop();
        }
コード例 #9
0
        public async Task Setup()
        {
            _userCredentials = new UserCredentials("admin", "changeit");

            _connectionSettings = ConnectionSettings.Create()
                                  .UseDebugLogger()
                                  .SetDefaultUserCredentials(_userCredentials)
                                  .KeepRetrying()
                                  .Build();


            _loggerFactory = new LoggerFactory();

            _clusterVNode = EmbeddedVNodeBuilder
                            .AsSingleNode()
                            .RunInMemory()
                            .RunProjections(ProjectionType.All)
                            .StartStandardProjections()
                            .WithWorkerThreads(1)
                            .Build();

            await _clusterVNode.StartAsync(true);

            await CreateSubscriptionGroups();
        }
コード例 #10
0
        public EventStoreFixture()
        {
            _node = EmbeddedVNodeBuilder
                    .AsSingleNode()
                    .OnDefaultEndpoints()
                    .RunInMemory()
                    .DisableDnsDiscovery()
                    .DisableHTTPCaching()
                    //.DisableScavengeMerging()
                    .DoNotVerifyDbHashes()
                    .Build();

            _node.StartAndWaitUntilReady().Wait();

            var conns = ConnectionSettings.Create()
                        .SetDefaultUserCredentials(new EventStore.ClientAPI.SystemData.UserCredentials("admin", "changeit"))
                        .Build();

            var eventStoreConnection = EmbeddedEventStoreConnection.Create(_node, conns);

            StreamStoreConnection = new EventStoreConnectionWrapper(eventStoreConnection);

            EventSerializer   = new JsonMessageSerializer();
            StreamNameBuilder = new PrefixedCamelCaseStreamNameBuilder("masterdata");

            _repo = new StreamStoreRepository(StreamNameBuilder, StreamStoreConnection, EventSerializer);
        }
コード例 #11
0
        public static void Run()
        {
            var clusterVNode = EmbeddedVNodeBuilder
                               .AsSingleNode()
                               .RunInMemory()
                               .WithWorkerThreads(1)
                               .Build();

            clusterVNode.StartAsync(true).Wait();


            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Debug)
                         .WriteTo.Console()
                         .CreateLogger();

            var loggerFactory = new LoggerFactory().AddSerilog(Log.Logger);

            var eventTypeProvider = new DefaultEventTypeProvider <EventCountAggregate>(() => new[] { typeof(EventCountOne), typeof(EventCountTwo) });;

            var eventCountActor = EventStoreEmbeddedStatefulActorBuilder <EventCountStatefulActor, EventCountAggregate, DemoSystemRegistry>
                                  .Create(clusterVNode, Do.GetConnectionSettings(), ActorConfiguration.Default, loggerFactory)
                                  .WithReadAllFromStartCache(
                eventTypeProvider: eventTypeProvider,
                getCatchupEventStoreCacheConfigurationBuilder: builder => builder.KeepAppliedEventsOnAggregate = true)
                                  .Build();

            Do.Run(eventCountActor);
        }
コード例 #12
0
        public GetEventStoreAggregateRepositoryTests()
        {
            _id = "aggregate-" + Guid.NewGuid().ToString("n");
            var source = new TaskCompletionSource <bool>();

            _eventStoreInitialized = source.Task;
            var notListening = new IPEndPoint(IPAddress.None, 0);

            _node = EmbeddedVNodeBuilder
                    .AsSingleNode()
                    .WithExternalTcpOn(notListening)
                    .WithInternalTcpOn(notListening)
                    .WithExternalHttpOn(notListening)
                    .WithInternalHttpOn(notListening)
                    .RunProjections(ProjectionsMode.All);
            _node.NodeStatusChanged += (_, e) =>
            {
                if (e.NewVNodeState != VNodeState.Master)
                {
                    return;
                }
                source.SetResult(true);
            };
            _connection = EmbeddedEventStoreConnection.Create(_node);
            _sut        = new GetEventStoreAggregateRepository(_connection, new DefaultGetEventStoreJsonSerializer());

            _node.Start();
        }
        public an_evenstore_connection()
        {
            _node = EmbeddedVNodeBuilder.AsSingleNode().OnDefaultEndpoints().RunInMemory().Build();
            _node.StartAndWaitUntilReady().Wait();

            Connection = EmbeddedEventStoreConnection.Create(_node);
            Connection.ConnectAsync().Wait();
        }
コード例 #14
0
        private void StartEmbeddedEventStore()
        {
            var timeout = TimeSpan.FromSeconds(10);

            var internalTcpPort  = _uri.Port - 1;
            var externalTcpPort  = _uri.Port;
            var externalHttpPort = externalTcpPort + 1000;
            var internalHttpPort = internalTcpPort + 1000;

            var builder = EmbeddedVNodeBuilder.AsSingleNode()
                          //Getting OOM exception on TC builds.
                          // This link seems to suggest that we can se the chunksize to something smaller (https://groups.google.com/forum/#!topic/event-store/bER82NC1wDY)
                          .WithTfChunkSize(10 * 1024 * 1024)
                          .RunInMemory()
                          .RunProjections(ProjectionsMode.All)
                          .NoStatsOnPublicInterface()
                          .WithInternalTcpOn(new IPEndPoint(IPAddress.Loopback, internalTcpPort))
                          .WithExternalTcpOn(new IPEndPoint(IPAddress.Loopback, externalTcpPort))
                          .WithInternalHttpOn(new IPEndPoint(IPAddress.Loopback, internalHttpPort))
                          .WithExternalHttpOn(new IPEndPoint(IPAddress.Loopback, externalHttpPort))
                          .AddExternalHttpPrefix($"http://localhost:{externalHttpPort}/")
                          .AddExternalHttpPrefix($"http://127.0.0.1:{externalHttpPort}/")
                          .WithExternalHeartbeatTimeout(TimeSpan.FromMinutes(5))
                          .RunInMemory();

            var clusterVNode = builder.Build();

            var startedEvent = new ManualResetEventSlim(false);

            EventHandler <VNodeStatusChangeArgs> clusterVNodeOnNodeStatusChanged = (sender, args) =>
            {
                if (args.NewVNodeState != VNodeState.Master)
                {
                    return;
                }

                // This sets up the handler for the web UI. Needed if we want to browse the streams
                clusterVNode.ExternalHttpService.SetupController(new ClusterWebUiController(clusterVNode.MainQueue, new NodeSubsystems[0]));

                startedEvent.Set();
            };

            clusterVNode.NodeStatusChanged += clusterVNodeOnNodeStatusChanged;

            try
            {
                clusterVNode.Start();

                if (!startedEvent.Wait(timeout))
                {
                    throw new TimeoutException($"EventStore hasn't started in {timeout} seconds.");
                }
            }
            finally
            {
                clusterVNode.NodeStatusChanged -= clusterVNodeOnNodeStatusChanged;
            }
        }
        static IEventStoreConnection CreateInMemoryEventStoreConnection()
        {
            var node = EmbeddedVNodeBuilder.AsSingleNode().OnDefaultEndpoints().RunInMemory().Build();

            node.StartAndWaitUntilReady().Wait();
            var connection = EmbeddedEventStoreConnection.Create(node);

            connection.ConnectAsync().Wait();
            return(connection);
        }
コード例 #16
0
 private ClusterVNode InitNode()
 {
     return(EmbeddedVNodeBuilder.AsSingleNode()
            .RunInMemory()
            .WithExternalTcpOn(tcp)
            .WithExternalHttpOn(http)
            .RunProjections(ProjectionType.All)
            .StartStandardProjections()
            .Build());
 }
コード例 #17
0
        private static ClusterVNode CreateInMemoryEventStoreNode()
        {
            var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode()
                              .OnDefaultEndpoints()
                              .RunInMemory();
            var node = nodeBuilder.Build();

            node.StartAndWaitUntilReady().Wait();
            return(node);
        }
コード例 #18
0
 private static void StartEmbeddedEventStore()
 {
     if (EnableEmbeddedEventStore)
     {
         var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode().OnDefaultEndpoints().RunInMemory();
         nodeBuilder.WithStatsPeriod(TimeSpan.FromSeconds(1));
         EventStoreNode = nodeBuilder.Build();
         EventStoreNode.StartAndWaitUntilReady().Wait();
     }
 }
コード例 #19
0
        public async Task Start()
        {
            var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode()
                              .OnDefaultEndpoints()
                              //.WithServerCertificate(null)
                              .RunProjections(ProjectionType.System)
                              .RunInMemory();

            this.node = nodeBuilder.Build();

            await node.StartAsync(true);
        }
コード例 #20
0
        public OrderTests()
        {
            node = EmbeddedVNodeBuilder
                   .AsSingleNode()
                   .OnDefaultEndpoints()
                   .RunInMemory();

            connectionSettingsBuilder = ConnectionSettings
                                        .Create()
                                        .SetDefaultUserCredentials(new UserCredentials("admin", "changeit"))
                                        .KeepReconnecting();
        }
コード例 #21
0
        static StaticData()
        {
            _clusterVNode = EmbeddedVNodeBuilder
                            .AsSingleNode()
                            .RunInMemory()
                            .RunProjections(ProjectionType.All)
                            .StartStandardProjections()
                            .WithWorkerThreads(1)
                            .Build();

            _clusterVNode.StartAsync(true).Wait();
        }
コード例 #22
0
        public async Task SetUp()
        {
            var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode().RunInMemory().OnDefaultEndpoints();

            var node = nodeBuilder.Build();
            await node.StartAsync(true);

            var connection = EmbeddedEventStoreConnection.Create(node);
            await connection.ConnectAsync();

            EventStoreConnection = connection;
        }
コード例 #23
0
        public void Start()
        {
            Node = EmbeddedVNodeBuilder.AsSingleNode().RunInMemory()
                   .AdvertiseExternalTCPPortAs(TcpEndPoint)
                   .AdvertiseExternalHttpPortAs(HttpEndPoint)
                   .AddExternalHttpPrefix($"http://127.0.0.1:{HttpEndPoint}/").
                   WithStatsStorage(StatsStorage.None).Build();
            var started = new ManualResetEvent(false);

            Node.MainBus.Subscribe(new AdHocHandler <SystemMessage.BecomeMaster>(m => started.Set()));
            Node.Start();

            started.WaitOne();
        }
コード例 #24
0
 public EventStoreSnapshotSpec()
     : base(SpecConfig, "EventStoreSnapshotSpec")
 {
     Node = EmbeddedVNodeBuilder
            .AsSingleNode()
            .RunInMemory()
            .WithInternalTcpOn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4566))
            .WithExternalTcpOn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 4567))
            .WithInternalHttpOn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5566))
            .WithExternalHttpOn(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5567))
            .Build();
     Node.Start();
     Initialize();
 }
コード例 #25
0
        public EmbeddedEventStoreFixture()
        {
            _node = EmbeddedVNodeBuilder
                    .AsSingleNode()
                    .OnDefaultEndpoints()
                    .RunInMemory()
                    .DisableDnsDiscovery()
                    .DisableHTTPCaching()
                    //.DisableScavengeMerging()
                    .DoNotVerifyDbHashes()
                    .Build();
            _node.StartAndWaitUntilReady().Wait();

            Connection = EmbeddedEventStoreConnection.Create(_node);
        }
コード例 #26
0
        public void CreateEventStore()
        {
            lock (lockObject)
            {
                if (EmbeddedEventStore == null)
                {
                    var nodeBuilder = EmbeddedVNodeBuilder.AsSingleNode()
                                      .WithExternalTcpOn(new IPEndPoint(IPAddress.Loopback, 1113))
                                      .RunInMemory();

                    var node = nodeBuilder.Build();
                    node.StartAndWaitUntilReady().GetAwaiter().GetResult();
                    EmbeddedEventStore = node;
                }
            }
        }
コード例 #27
0
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new ConsoleLogFactory();

            var nodeBuilder = EmbeddedVNodeBuilder
                              .AsSingleNode()
                              .OnDefaultEndpoints()
                              .RunInMemory();
            var node = nodeBuilder.Build();

            node.StartAndWaitUntilReady().Wait();
            var testConnection = EmbeddedEventStoreConnection.Create(node);

            Plugins.Add(new MetadataFeature());
            Plugins.Add(new EventStoreFeature(testConnection, typeof(TestAppHost).Assembly));
        }
コード例 #28
0
        public static IDisposable StartEventStore()
        {
            var noEndpoint   = new IPEndPoint(IPAddress.None, 0);
            var nodeEndpoint = new IPEndPoint(IPAddress.Loopback, 1113);
            var node         =
                EmbeddedVNodeBuilder.AsSingleNode()
                .RunInMemory()
                .WithExternalTcpOn(nodeEndpoint)
                .WithInternalTcpOn(noEndpoint)
                .WithExternalHttpOn(noEndpoint)
                .WithInternalHttpOn(noEndpoint)
                .RunProjections(global::EventStore.Common.Options.ProjectionType.All)
                .Build();

            node.Start();

            return(new NodeStopper(node));
        }
コード例 #29
0
        static TestActorBuilderBusRegistrationMvcTestBed()
        {
            UserCredentials = new UserCredentials("admin", "changeit");

            ConnectionSettings = ConnectionSettings.Create()
                                 .UseDebugLogger()
                                 .SetDefaultUserCredentials(UserCredentials)
                                 .KeepRetrying()
                                 .Build();

            ClusterVNode = EmbeddedVNodeBuilder
                           .AsSingleNode()
                           .RunInMemory()
                           .RunProjections(ProjectionType.All)
                           .StartStandardProjections()
                           .WithWorkerThreads(1)
                           .Build();
        }
コード例 #30
0
        public static void Run()
        {
            var clusterVNode = EmbeddedVNodeBuilder
                               .AsSingleNode()
                               .RunInMemory()
                               .StartStandardProjections()
                               .WithWorkerThreads(1)
                               .Build();

            clusterVNode.StartAsync(true).Wait();

            CreateSubscriptionGroups(clusterVNode).Wait();

            var eventCountActorOne = EventStoreEmbeddedStatelessActorBuilder <EventCountStatelessActor, DemoSystemRegistry>
                                     .Create(clusterVNode, Do.GetConnectionSettings(), ActorConfiguration.Default)
                                     .WithBus <IEventStoreBus>((actor, bus) =>
            {
                actor.SubscribeToPersistentSubscriptionStream(StaticData.PersistentStreamOne, StaticData.GroupIdOne);
            })
                                     .Build();

            var eventCountActorTwo = EventStoreEmbeddedStatelessActorBuilder <EventCountStatelessActor, DemoSystemRegistry>
                                     .Create(clusterVNode, Do.GetConnectionSettings(), ActorConfiguration.Default)
                                     .WithBus <IEventStoreBus>((actor, bus) =>
            {
                actor.SubscribeToPersistentSubscriptionStream(StaticData.PersistentStreamOne, StaticData.GroupIdOne);
            })
                                     .Build();

            var position = 0;

            while (true)
            {
                if (position == 0)
                {
                    Console.WriteLine("Press enter to generate random event...");
                }

                Console.ReadLine();

                Console.WriteLine($"Generating {nameof(EventCountOne)} for stream {StaticData.PersistentStreamOne}");
                eventCountActorOne.EmitEventStore(new EventCountOne(position++, StaticData.PersistentStreamOne, Guid.NewGuid())).Wait();
            }
        }