private void CreateNode()
 {
     _projections = new ProjectionsSubsystem(1, runProjections: RunProjections.All);
     _node = new MiniNode(
         PathName, inMemDb: true, skipInitializeStandardUsersCheck: false, subsystems: new ISubsystem[] {_projections});
     _node.Start();
 }
 private void CreateNode()
 {
     var projectionWorkerThreadCount = GivenWorkerThreadCount();
     _projections = new ProjectionsSubsystem(projectionWorkerThreadCount, runProjections: ProjectionType.All, developmentMode: false);
     _node = new MiniNode(
         PathName, inMemDb: true, skipInitializeStandardUsersCheck: false, subsystems: new ISubsystem[] {_projections});
     _node.Start();
 }
        public static void Start()
        {
            var node = new MiniNode(Path.Combine(Path.GetTempPath(), "EventStore"), 1113, 1114, 2113, skipInitializeStandardUsersCheck: false);
            node.Start();
            Node = node;
            Credentials = new UserCredentials("admin", "changeit");
            var connection = EventStoreConnection.Create(
                ConnectionSettings.Create().SetDefaultUserCredentials(Credentials),
                node.TcpEndPoint);
            connection.Connect();
            Connection = connection;

        }
        public void everything_should_go_fine()
        {
            var miniNode = new MiniNode(PathName);
            miniNode.Start();

            var tcpPort = miniNode.TcpEndPoint.Port;
            var tcpSecPort = miniNode.TcpSecEndPoint.Port;
            var httpPort = miniNode.HttpEndPoint.Port;
            const int cnt = 50;
            var countdown = new CountdownEvent(cnt);

            // --- first part of events
            WriteEvents(cnt, miniNode, countdown);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Too long writing first part of events.");
            countdown.Reset();

            // -- set up truncation
            var truncatePosition = miniNode.Db.Config.WriterCheckpoint.ReadNonFlushed();
            miniNode.Db.Config.TruncateCheckpoint.Write(truncatePosition);
            miniNode.Db.Config.TruncateCheckpoint.Flush();

            // --- second part of events
            WriteEvents(cnt, miniNode, countdown);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Too long writing second part of events.");
            countdown.Reset();

            miniNode.Shutdown(keepDb: true, keepPorts: true);

            // --- first restart and truncation
            miniNode = new MiniNode(PathName, tcpPort, tcpSecPort, httpPort);
            
            miniNode.Start();
            Assert.AreEqual(-1, miniNode.Db.Config.TruncateCheckpoint.Read());
            Assert.That(miniNode.Db.Config.WriterCheckpoint.Read(), Is.GreaterThanOrEqualTo(truncatePosition));

            // -- third part of events
            WriteEvents(cnt, miniNode, countdown);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Too long writing third part of events.");
            countdown.Reset();

            miniNode.Shutdown(keepDb: true, keepPorts: true);

            // -- second restart
            miniNode = new MiniNode(PathName, tcpPort, tcpSecPort, httpPort);
            Assert.AreEqual(-1, miniNode.Db.Config.TruncateCheckpoint.Read());
            miniNode.Start();

            // -- if we get here -- then everything is ok
            miniNode.Shutdown();
        }
        public void with_truncate_position_in_completed_chunk_everything_should_go_fine()
        {
            const int chunkSize = 1024*1024;
            const int cachedSize = chunkSize*3;

            var miniNode = new MiniNode(PathName, chunkSize: chunkSize, cachedChunkSize: cachedSize, inMemDb: false);
            miniNode.Start();

            var tcpPort = miniNode.TcpEndPoint.Port;
            var tcpSecPort = miniNode.TcpSecEndPoint.Port;
            var httpPort = miniNode.ExtHttpEndPoint.Port;
            const int cnt = 1;
            var countdown = new CountdownEvent(cnt);

            // --- first part of events
            WriteEvents(cnt, miniNode, countdown, MiniNode.ChunkSize / 5 * 3);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Took too long writing first part of events.");
            countdown.Reset();

            // -- set up truncation
            var truncatePosition = miniNode.Db.Config.WriterCheckpoint.ReadNonFlushed();
            miniNode.Db.Config.TruncateCheckpoint.Write(truncatePosition);
            miniNode.Db.Config.TruncateCheckpoint.Flush();

            // --- second part of events
            WriteEvents(cnt, miniNode, countdown, MiniNode.ChunkSize / 2);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Took too long writing second part of events.");
            countdown.Reset();

            miniNode.Shutdown(keepDb: true, keepPorts: true);

            // --- first restart and truncation
            miniNode = new MiniNode(PathName, tcpPort, tcpSecPort, httpPort, chunkSize: chunkSize, cachedChunkSize: cachedSize, inMemDb: false);

            miniNode.Start();
            Assert.AreEqual(-1, miniNode.Db.Config.TruncateCheckpoint.Read());
            Assert.That(miniNode.Db.Config.WriterCheckpoint.Read(), Is.GreaterThanOrEqualTo(truncatePosition));

            // -- third part of events
            WriteEvents(cnt, miniNode, countdown, MiniNode.ChunkSize / 5);
            Assert.IsTrue(countdown.Wait(TimeSpan.FromSeconds(10)), "Took too long writing third part of events.");
            countdown.Reset();

            // -- if we get here -- then everything is ok
            miniNode.Shutdown();
        }
 public void SetUp()
 {
     if (!UseExternalEventStore)
     {
         var projections = new ProjectionsSubsystem(1, RunProjections.All);
         Node = new MiniNode(PathName, skipInitializeStandardUsersCheck: false, inMemDb:true, subsystems: new ISubsystem[] { projections });
         Node.Start();
         TcpEndPoint = Node.TcpEndPoint;
         HttpEndPoint = Node.HttpEndPoint;
     }
     else
     {
         TcpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"),1113);
         HttpEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"),2113);
     }
     ReceiverAddress = new Address("comp1", "store1");
     SenderAddress = new Address("comp2", "store1");
     ConnectionConfiguration = new ConnectionConfiguration(ConnectionSettings.Create().SetDefaultUserCredentials(AdminCredentials), null, TcpEndPoint, HttpEndPoint, "");
     Thread.Sleep(5000);
 }
        public override void TestFixtureSetUp()
        {
            base.TestFixtureSetUp();
#if DEBUG
            QueueStatsCollector.InitializeIdleDetection();
#else 
            throw new NotSupportedException("These tests require DEBUG conditional");
#endif
            _projections = new ProjectionsSubsystem(1, runProjections: RunProjections.All);
            _node = new MiniNode(
                PathName, inMemDb: true, skipInitializeStandardUsersCheck: false,
                subsystems: new ISubsystem[] {_projections});
            _node.Start();

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

            _manager = new ProjectionsManager(new ConsoleLogger(), _node.HttpEndPoint);
            if (GivenStandardProjectionsRunning())
                EnableStandardProjections();
            QueueStatsCollector.WaitIdle();
            Given();
            When();
        }
 private static void WriteEvents(int cnt, MiniNode miniNode, CountdownEvent countdown, int dataSize = 4000)
 {
     for (int i = 0; i < cnt; ++i)
     {
         miniNode.Node.MainQueue.Publish(
             new ClientMessage.WriteEvents(Guid.NewGuid(), Guid.NewGuid(),
                                           new CallbackEnvelope(m =>
                                           {
                                               Assert.IsInstanceOf<ClientMessage.WriteEventsCompleted>(m);
                                               var msg = (ClientMessage.WriteEventsCompleted) m;
                                               Assert.AreEqual(OperationResult.Success, msg.Result);
                                               countdown.Signal();
                                           }),
                                           true,
                                           "test-stream",
                                           ExpectedVersion.Any,
                                           new[]
                                           {
                                               new Event(Guid.NewGuid(), "test-event-type", false, new byte[dataSize], null)
                                           },
                                           null));
     }
 }
 protected override IEventStoreConnection BuildConnection(MiniNode node)
 {
     return EmbeddedEventStoreConnection.Create(node.Node);
 }