ActionService { public void index(List<ActionLogMessage> messages) { index(messages, LocalDate.now()); }  void index(List<ActionLogMessage> messages); void index(ActionLogMessage message);  }
@Test void index() { ActionLogMessage message1 = message("1", "OK"); message1.context = Map.of("key", List.of("value")); message1.stats = Map.of("count", 1d); message1.correlationIds = List.of("id1", "id2"); message1.clients = List.of("client"); var stat = new PerformanceStatMessage(); stat.count = 1; stat.totalElapsed = 10L; stat.readEntries = 1; stat.writeEntries = 2; message1.performanceStats = Map.of("redis", stat); ActionLogMessage message2 = message("2", "WARN"); message2.traceLog = "trace"; LocalDate now = LocalDate.of(2016, Month.JANUARY, 15); actionService.index(List.of(message1, message2), now); ActionDocument action = actionDocument(now, message1.id); assertThat(action.timestamp).isEqualTo(message1.date); assertThat(action.result).isEqualTo(message1.result); assertThat(action.correlationIds).isEqualTo(message1.correlationIds); assertThat(action.refIds).isEqualTo(message1.refIds); assertThat(action.clients).isEqualTo(message1.clients); assertThat(action.performanceStats.get("redis")).usingRecursiveComparison().isEqualTo(message1.performanceStats.get("redis")); assertThat(action.context).containsEntry("key", List.of("value")); TraceDocument trace = traceDocument(now, message2.id); assertThat(trace.content).isEqualTo(message2.traceLog); elasticSearch.refreshIndex(indexService.indexName("action", now)); List<ActionDocument> actions = searchActionDocument(now, "context.key", "value"); assertThat(actions).hasSize(1); }
@Test void indexWithDifferentDateFormatValues() { ActionLogMessage message = message("1", "OK"); message.date = ZonedDateTime.now().withNano(0).toInstant(); actionService.index(List.of(message)); message.date = ZonedDateTime.now().withNano(123456).toInstant(); actionService.index(List.of(message)); }
@Test void bulkIndex() { List<ActionLogMessage> messages = Lists.newArrayList(); for (int i = 0; i < 6; i++) { ActionLogMessage message = message("bulk-" + i, "TRACE"); message.traceLog = "trace"; messages.add(message); } LocalDate now = LocalDate.of(2016, Month.JANUARY, 15); actionService.index(messages, now); ActionDocument action = actionDocument(now, messages.get(0).id); assertThat(action.result).isEqualTo("TRACE"); }