예제 #1
0
        public List <RouteNetworkEvent> WaitForEvents(Guid startMarker)
        {
            long timeoutMs = 1000 * 60 * 1; // Wait 1 minute, before giving up recieving route network events from topic

            // First snatch cmdId
            bool timedOut = _eventFetcher.WaitForEvents(
                start => start.WorkTaskMrid.Equals(startMarker),
                stop => stop.WorkTaskMrid.Equals(startMarker),
                timeoutMs
                ).Result;

            _eventFetcher.Dispose();

            // We got a timeout, we got nothing
            if (timedOut)
            {
                Log.Error($"Timeout wating for event with TaskMrid={startMarker}");
                return(new List <RouteNetworkEvent>());
            }

            if (_eventFetcher.Events.Count() != 1)
            {
                Log.Error($"We expected one event with TaskMrid={startMarker} but got " + _eventFetcher.Events.Count());
                return(new List <RouteNetworkEvent>());
            }


            // Snatch cmdId from that event
            Guid cmdId = _eventFetcher.Events.First().CmdId;

            // Now fetch all events with that cmdId

            timedOut = _eventFetcher.WaitForEvents(
                start => start.CmdId == cmdId,
                stop => stop.IsLastEventInCmd && stop.CmdId == cmdId,
                timeoutMs
                ).Result;

            _eventFetcher.Dispose();

            // We got a timeout, we got nothing
            if (timedOut)
            {
                Log.Error($"Timeout wating for event belonging to command with id={cmdId}");
                return(new List <RouteNetworkEvent>());
            }

            return(_eventFetcher.Events.ToList());
        }
예제 #2
0
        public void Run()
        {
            var loggerFactory = LoggerFactory.Create(builder =>
                                                     builder.AddConsole().SetMinimumLevel(LogLevel.Debug)
                                                     );

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.ControlledBy(new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Verbose))
                         .WriteTo.Console()
                         .CreateLogger();

            try {
                var routeNetworkDatastore = new RouteNetworkDatastore(PostgresConnectionString);

                var startMarker = Guid.NewGuid();
                var endMarker   = Guid.NewGuid();

                var routeNetworkBuilder = new RouteNetworkBuilder();
                routeNetworkBuilder.Run(Nodefilename, SegmentFilename, routeNetworkDatastore, startMarker, endMarker);

                var graph = routeNetworkBuilder.RouteGraph;

                using var eventFetcher = new WaitForAndFetchEvents <RouteNetworkEvent>(loggerFactory, KafkaServer, RouteNetworkTopicName);

                long timeoutMs = 1000 * 60 * 1; // Wait 1 minute, before giving up recieving route network events from topic

                bool timedOut = eventFetcher.WaitForEvents(
                    start => start.WorkTaskMrid.Equals(startMarker),
                    stop => stop.WorkTaskMrid.Equals(endMarker),
                    timeoutMs
                    ).Result;


                var events = eventFetcher.Events.ToList();

                // Check if event fetcher timed out
                if (timedOut)
                {
                    LogErrorAndThrowException($"Seeding of test network failed. Timeout ({timeoutMs} ms) exceded waiting for events to arrive on route network topic.");
                }

                // Check if GDB integrator has put the right amount of events in the route network event topic
                if (events.Count != (graph.Nodes.Count + graph.Edges.Count))
                {
                    LogErrorAndThrowException($"Seeding of test network failed. {(graph.Nodes.Count + graph.Edges.Count)} number of nodes and routes were inserted into Postgres. Expected the same amount of events inserted into the route network topic by GDB integrator, but got {events.Count} events from topic!");
                }


                bool someTestFailed = false;

                // Check that all properties we add to postgres is added to events etc.
                if (!new CheckEventProperties().Run(graph, events))
                {
                    someTestFailed = true;
                }


                // Check if event fetcher timed out
                if (someTestFailed)
                {
                    LogErrorAndThrowException($"Seeding of test network failed. Please search the log for errors resulting from integration tests.");
                }
            }
            catch (Exception ex)
            {
                Log.Error("Seeding of test network failed. Unhandled exception: " + ex.Message, ex);
                throw ex;
            }
        }