{"action":"created","issue":{"url":"https://api.github.com/repos/EventStore/EventStore/issues/712","labels_url":"https://api.github.com/repos/EventStore/EventStore/issues/712/labels{/name}","comments_url":"https://api.github.com/repos/EventStore/EventStore/issues/712/comments","events_url":"https://api.github.com/repos/EventStore/EventStore/issues/712/events","html_url":"https://github.com/EventStore/EventStore/issues/712","id":109357788,"number":712,"title":"Projections not starting","user":{"login":"lappkast","id":3328039,"avatar_url":"https://avatars.githubusercontent.com/u/3328039?v=3","gravatar_id":"","url":"https://api.github.com/users/lappkast","html_url":"https://github.com/lappkast","followers_url":"https://api.github.com/users/lappkast/followers","following_url":"https://api.github.com/users/lappkast/following{/other_user}","gists_url":"https://api.github.com/users/lappkast/gists{/gist_id}","starred_url":"https://api.github.com/users/lappkast/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lappkast/subscriptions","organizations_url":"https://api.github.com/users/lappkast/orgs","repos_url":"https://api.github.com/users/lappkast/repos","events_url":"https://api.github.com/users/lappkast/events{/privacy}","received_events_url":"https://api.github.com/users/lappkast/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-10-01T18:36:09Z","updated_at":"2015-10-09T09:48:56Z","closed_at":null,"body":"We're trying to make projections run with the embedded event store, but it seems that projections don't properly start. I'm specifically looking for the by_category projection.\r\n\r\n``` fsharp\r\n\r\n  /// Execute f in a context where you can bind to the event store\r\n  let withEmbeddedEs f =\r\n    let node =\r\n      EmbeddedVNodeBuilder.AsSingleNode()\r\n                          .OnDefaultEndpoints()\r\n                          .RunInMemory()\r\n                          .RunProjections(ProjectionsMode.All)\r\n                          .WithWorkerThreads(16)\r\n                          .Build()\r\n\r\n    try\r\n      printfn \"starting embedded EventStore\"\r\n      node.Start()\r\n      f ()\r\n    finally\r\n      printfn \"stopping embedded EventStore\"\r\n      use stopped = new AutoResetEvent(false)\r\n      node.MainBus.Subscribe(\r\n        new AdHocHandler<SystemMessage.BecomeShutdown>(\r\n          fun m -> stopped.Set() |> ignore))\r\n      node.Stop() |> ignore\r\n      if not (stopped.WaitOne(20000)) then\r\n        Tests.failtest \"couldn't stop ES within 20000 ms\"\r\n      else\r\n        printfn \"stopped embedded EventStore\"\r\n\r\n  let withRealEs f = f ()\r\n\r\n  let withConnection factory (f : Connection -> 'a) =\r\n    factory <| fun _ ->\r\n      let conn =\r\n        ConnectionSettings.configureStart()\r\n        |> ConnectionSettings.keepReconnecting\r\n        |> ConnectionSettings.configureEnd\r\n          (Uri \"tcp://admin:changeit@localhost:1113\")\r\n          (SystemData.UserCredentials(\"admin\", \"changeit\"))\r\n      EsAction.run conn Conn.connect |> Hopac.Job.Global.run\r\n      try \r\n        let ctx =\r\n          { logger = ConsoleLogger()\r\n            ep = IPEndPoint(IPAddress.Loopback, 2113)\r\n            timeout = TimeSpan.FromSeconds 8.\r\n            creds   = SystemData.UserCredentials(\"admin\", \"changeit\") }\r\n        f conn\r\n      finally EsAction.run conn Conn.close |> Hopac.Job.Global.run\r\n\r\nlet fewTimes f =\r\n  let rec fewTimes' i =\r\n    try\r\n      f () \r\n    with e ->\r\n      if i = 100 then raise e\r\n      else\r\n        System.Threading.Thread.Sleep(200)\r\n        fewTimes' (i + 1)\r\n  fewTimes' 0\r\n\r\ntestCase \"by_category projection works\" <| fun _ ->\r\n      let event = \"\"\"{\"teen-factor\":\"high\",\"cast\":{\"Brenda\":\"Shannon Doherty\",\"Dylan\":\"Luke Perry\"}}\"\"\"\r\n      let metaBytes = Encoding.UTF8.GetBytes \"\"\"{\"director\":\"Donna's dad\",\"budget\":\"immense\"}\"\"\"\r\n      let events = Seq.ofList [EventData(Guid.NewGuid(), \"omgEvent\", true, Encoding.UTF8.GetBytes event, metaBytes)]\r\n\r\n      Impl.withConnection Impl.withEmbeddedEs <| fun conn ->\r\n        let wr =\r\n          conn.AppendToStream(\"beverlyHills-90210\", NoStream, events)\r\n          |> Job.Global.run\r\n        \r\n        fewTimes (fun _ ->\r\n          conn.ReadEvent(\"$ce-beverlyHills\", LastInStream, ResolveLinks)\r\n          |> Job.Global.run\r\n          |> fun readResult ->\r\n            if readResult.Event.HasValue then\r\n              let projectedEvent = readResult.Event.Value.OriginalEvent.Data |> Encoding.UTF8.GetString\r\n              Assert.Equal(\"should have projected event\", projectedEvent, event)\r\n            else\r\n              Tests.failtest (sprintf \"No event result returned %O\" readResult.Status))\r\n```\r\n\r\nThe wrapped API looks like this:\r\n\r\n``` fsharp\r\n          member x.ReadEvent(stream, eventVersion, resolveLinks) =\r\n            let (EventVersion eventVersion) = eventVersion\r\n            y.ReadEventAsync(stream, eventVersion,\r\n                             (match resolveLinks with ResolveLinks r -> r),\r\n                             creds)\r\n            |> Task.awaitJob\r\n```\r\n\r\nThe call to `conn.ReadEvent(\"$ce-beverlyHills\", LastInStream, ResolveLinks)` never returns any data – it seems projections are not starting."},"comment":{"url":"https://api.github.com/repos/EventStore/EventStore/issues/comments/146816592","html_url":"https://github.com/EventStore/EventStore/issues/712#issuecomment-146816592","issue_url":"https://api.github.com/repos/EventStore/EventStore/issues/712","id":146816592,"user":{"login":"haf","id":193115,"avatar_url":"https://avatars.githubusercontent.com/u/193115?v=3","gravatar_id":"","url":"https://api.github.com/users/haf","html_url":"https://github.com/haf","followers_url":"https://api.github.com/users/haf/followers","following_url":"https://api.github.com/users/haf/following{/other_user}","gists_url":"https://api.github.com/users/haf/gists{/gist_id}","starred_url":"https://api.github.com/users/haf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/haf/subscriptions","organizations_url":"https://api.github.com/users/haf/orgs","repos_url":"https://api.github.com/users/haf/repos","events_url":"https://api.github.com/users/haf/events{/privacy}","received_events_url":"https://api.github.com/users/haf/received_events","type":"User","site_admin":false},"created_at":"2015-10-09T09:48:56Z","updated_at":"2015-10-09T09:48:56Z","body":"That description could entail both mine and yours, because it's not talking about the order of operations, only about the expected future.\r\n\r\nNone the less, in my wrapper, this was named \"catchup\", so here's a new repro with the right overload call:\r\n\r\n``` csharp\r\nusing NUnit.Framework;\r\nusing System;\r\nusing System.Net;\r\nusing System.Net.Sockets;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.IO;\r\nusing System.Text;\r\nusing System.Threading;\r\nusing System.Threading.Tasks;\r\nusing EventStore.ClientAPI;\r\nusing EventStore.ClientAPI.Common.Log;\r\nusing EventStore.ClientAPI.SystemData;\r\nusing EventStore.ClientAPI.Projections;\r\nusing Newtonsoft.Json;\r\nusing Newtonsoft.Json.Linq;\r\n\r\nnamespace EventStoreTests\r\n{\r\n    public class ESFixture\r\n    {\r\n        [Test]\r\n        public async Task SubscribeAndGetCategoryCatchUpData ()\r\n        {\r\n            await EnableCategoryProjections ();\r\n\r\n            var conn = EventStoreConnection.Create (new Uri (\"tcp://admin:changeit@localhost:1113\"), \"myConn\");\r\n            await conn.ConnectAsync ();\r\n            var stream = GenName ();\r\n\r\n            Console.WriteLine (\"Writing event to mycat-{0}\", stream);\r\n\r\n            await conn.AppendToStreamAsync (\"mycat-\" + stream, -1, new[] {\r\n                new EventData (Guid.NewGuid (), \"myType\", true, GenData (), GenData())\r\n            });\r\n\r\n            var mre = new ManualResetEvent (false);\r\n\r\n            conn.SubscribeToStreamFrom (\r\n                \"$ce-mycat\",\r\n                null,\r\n                true,\r\n                (sub, evt) => {\r\n                    Console.WriteLine(\"Got expected event, because this is a catchup subscription\");\r\n                    mre.Set ();\r\n                },\r\n                liveSub => Console.WriteLine(\"went live\"),\r\n                (sub, reason, ex) => {});\r\n            \r\n            Assert.That (mre.WaitOne (TimeSpan.FromSeconds (8.0)), Is.True,\r\n                         \"Should receive category subscription\");\r\n        }\r\n\r\n        async Task EnableCategoryProjections() {\r\n            Console.WriteLine (\"Enable Category Projections\");\r\n\r\n            var creds = new UserCredentials(\"admin\", \"changeit\");\r\n            var pm = new ProjectionsManager(\r\n                new ConsoleLogger(),\r\n                new IPEndPoint(IPAddress.Loopback, 2113),\r\n                new TimeSpan(1, 0, 0));\r\n\r\n            var byCategoryProjectionStatus =\r\n                ((JObject)JsonConvert.DeserializeObject(\r\n                    pm.GetStatusAsync(\"$by_category\", creds).Result))[\"status\"]\r\n                    .ToString();\r\n\r\n            var streamByCategoryProjectionStatus =\r\n                ((JObject)JsonConvert.DeserializeObject(\r\n                    pm.GetStatusAsync(\"$stream_by_category\", creds).Result))[\"status\"]\r\n                    .ToString();\r\n\r\n            Console.WriteLine (\"Enable Category Projections: byCategoryProjectionStatus: {0}\", byCategoryProjectionStatus);\r\n\r\n            if (byCategoryProjectionStatus == \"Stopped\")\r\n                await pm.EnableAsync (\"$by_category\", creds);\r\n\r\n            Console.WriteLine (\"Enable Category Projections: streamByCategoryProjectionStatus: {0}\", streamByCategoryProjectionStatus);\r\n\r\n            if (streamByCategoryProjectionStatus == \"Stopped\")\r\n                await pm.EnableAsync (\"$stream_by_category\", creds);\r\n        }\r\n\r\n        string GenName() {\r\n            return Path.GetFileNameWithoutExtension (Path.GetRandomFileName ());\r\n        }\r\n\r\n        byte[] GenData() {\r\n            var str =\r\n                new string[] { GenName (), GenName (), GenName () }\r\n                    .Aggregate (\"\", (acc, t) => acc + t);\r\n            return Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new {\r\n                Name = GenName(),\r\n                ThisIsGreat = str\r\n            }));\r\n        }\r\n\r\n    }\r\n}\r\n```"}}