@Override
   @Async
   public void onApplicationEvent(MockInvocationEvent event) {
      log.debug("Received a MockInvocationEvent on {} - v{}", event.getServiceName(), event.getServiceVersion());

      // Compute day string representation.
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(event.getInvocationTimestamp());

      // Computing keys based on invocation date.
      int month = calendar.get(Calendar.MONTH) + 1;
      String monthStr = (month < 10 ? "0" : "") + month;
      int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
      String dayOfMonthStr = (dayOfMonth < 10 ? "0" : "") + dayOfMonth;

      String day = calendar.get(Calendar.YEAR) + monthStr + dayOfMonthStr;
      String hourKey = String.valueOf(calendar.get(Calendar.HOUR_OF_DAY));
      String minuteKey = String.valueOf((60 * calendar.get(Calendar.HOUR_OF_DAY)) + calendar.get(Calendar.MINUTE));
      if (log.isDebugEnabled()) {
         log.debug("hourKey for statistic is {}", hourKey);
         log.debug("minuteKey for statistic is {}", minuteKey);
      }

      // First check if there's a statistic document for invocation day.
      DailyStatistic statistic = null;
      List<DailyStatistic> statistics = statisticsRepository.findByDayAndServiceNameAndServiceVersion(day,
            event.getServiceName(), event.getServiceVersion());
      if (!statistics.isEmpty()) {
         statistic = statistics.get(0);
      }

      if (statistic == null) {
         // No statistic's yet...
         log.debug("There's no statistics for {} yet. Create one.", day);
         // Initialize a new 0 filled structure.
         statistic = new DailyStatistic();
         statistic.setDay(day);
         statistic.setServiceName(event.getServiceName());
         statistic.setServiceVersion(event.getServiceVersion());
         statistic.setHourlyCount(initializeHourlyMap());
         statistic.setMinuteCount(initializeMinuteMap());
         // Now set first values before saving.
         statistic.setDailyCount(1);
         statistic.getHourlyCount().put(hourKey, 1);
         statistic.getMinuteCount().put(minuteKey, 1);
         statisticsRepository.save(statistic);
      } else {
         // Already a statistic document for this day, increment fields.
         log.debug("Found an existing statistic document for {}", day);
         statisticsRepository.incrementDailyStatistic(day, event.getServiceName(), event.getServiceVersion(), hourKey,
               minuteKey);
      }

      log.debug("Processing of MockInvocationEvent done !");
   }
@Test
   void testOnApplicationEvent() {
      Calendar today = Calendar.getInstance();
      MockInvocationEvent event = new MockInvocationEvent(this, "TestService1", "1.0", "123456789", today.getTime(),
            100);

      // Fire event a first time.
      feeder.onApplicationEvent(event);

      SimpleDateFormat formater = new SimpleDateFormat("yyyyMMdd");
      String day = formater.format(today.getTime());
      DailyStatistic stat = statisticsRepository.findByDayAndServiceNameAndServiceVersion(day, "TestService1", "1.0")
            .get(0);
      assertNotNull(stat);
      assertNotNull(stat.getId());
      assertEquals(day, stat.getDay());
      assertEquals("TestService1", stat.getServiceName());
      assertEquals("1.0", stat.getServiceVersion());
      assertEquals(1, stat.getDailyCount());
      assertEquals(1, stat.getHourlyCount().get(String.valueOf(today.get(Calendar.HOUR_OF_DAY))));

      // Fire event a second time.
      feeder.onApplicationEvent(event);

      stat = statisticsRepository.findByDayAndServiceNameAndServiceVersion(day, "TestService1", "1.0").get(0);
      assertNotNull(stat);
      assertNotNull(stat.getId());
      assertEquals(day, stat.getDay());
      assertEquals("TestService1", stat.getServiceName());
      assertEquals("1.0", stat.getServiceVersion());
      assertEquals(2, stat.getDailyCount());
      assertEquals(2, stat.getHourlyCount().get(String.valueOf(today.get(Calendar.HOUR_OF_DAY))));
   }