Exemplo n.º 1
0
        public bool PlaceReservation(Models.Reservation reservation, int eventCapacity)
        {
            long?remainingTickets = tickets_Counter.GetCurrentTicketsCount(reservation.Event_Id);

            if (remainingTickets != null)   // counter exists
            {
                // are tickets still available
                if (eventCapacity - remainingTickets >= reservation.Tickets_count)
                {
                    mapper.Insert(reservation);
                    // get tickets from pool
                    tickets_Counter.DecrementRemainingTicketsCountBy(reservation.Event_Id,
                                                                     reservation.Tickets_count);
                    Statistics.Reservation(reservation.Event_Id);
                    // Statistics.Placed(reservation.Event_Id, reservation.Tickets_count);
                }
                else
                {
                    // Console.WriteLine("Tickets count exceeded");
                    Statistics.Declined(reservation.Event_Id, reservation.Tickets_count);
                    return(false);
                }
            }
            else
            {
                Console.WriteLine("Couldn't find ticketsCounter");
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public Runner()
        {
            backend = new BackendSession(false);

            counterController     = new Controllers.Tickets_Counter(backend);
            reservationController = new Controllers.Reservation(backend);
            eventController       = new Controllers.Event(backend);

            CancellationTokenSource source = new CancellationTokenSource();

            // Get one of the events to consider
            List <Models.Event> events = eventController.GetAllEvents();

            Models.Event ev   = events.Where(e => e.Id == 2).First();
            Random       rand = new Random();

            // get initial tickets counter
            Console.WriteLine("Counter value: {0}", counterController.GetCurrentTicketsCount(ev.Id));

            // run 5 rounds
            for (int k = 0; k < 5; k++)
            {
                // in 1150 threads
                List <Thread> threads = new List <Thread>();
                for (int i = 0; i < 1000; i++)
                {
                    var clientIdOffset_ = clientIdOffset;
                    // run thread to place reservation and cancel 10% of them
                    Thread t = new Thread(() => {
                        Client c = new Client(reservationController, clientIdOffset_, ev.Id, 10, 5, 1, ev.Total_Tickets);
                        c.run();
                    });

                    clientIdOffset += 1;
                    t.Start();
                    threads.Add(t);
                }
                foreach (Thread th in threads)
                {
                    th.Join();
                }
                GetStatistics(ev.Id);
            }

            Thread.Sleep(1000);
            GetStatistics(ev.Id);
        }
Exemplo n.º 3
0
 private void GetStatistics(int eventId)
 {
     Console.WriteLine("Counter value: {0}", counterController.GetCurrentTicketsCount(eventId));
     Console.WriteLine(
         "Statistics: reservations: {0}\n" +
         "Statistics: tickets reserved: {1}\n" +
         "Statistics: reservations cancelled: {2}\n" +
         "Statistics: tickets cancelled: {3}\n" +
         "Statistics: reservations declined: {4}\n" +
         "Statistics: tickets declined: {5}\n" +
         "Statistics: not found (not yer replicated): {6}\n",
         Statistics.GetReservations(eventId),
         Statistics.GetTicketsReserved(eventId),
         Statistics.GetReservationsCancelled(eventId),
         Statistics.GetTicketsCancelled(eventId),
         Statistics.GetReservationsDeclined(eventId),
         Statistics.GetTicketsDeclined(eventId),
         Statistics.GetNotFound(eventId)
         );
 }