1 package de.juplo.kafka.chat.backend.persistence;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.fasterxml.jackson.databind.SerializationFeature;
5 import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
6 import de.juplo.kafka.chat.backend.domain.ChatHomeService;
7 import de.juplo.kafka.chat.backend.persistence.filestorage.FileStorageStrategy;
8 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatHomeService;
9 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
10 import lombok.extern.slf4j.Slf4j;
11 import org.junit.jupiter.api.BeforeEach;
13 import java.io.IOException;
14 import java.nio.file.Files;
15 import java.nio.file.Path;
16 import java.nio.file.Paths;
17 import java.time.Clock;
18 import java.util.function.Supplier;
22 public class InMemoryWithFileStorageStrategyIT extends AbstractStorageStrategyIT
24 final static Path path = Paths.get("target","local-json-files");
27 final ObjectMapper mapper;
28 final FileStorageStrategy storageStrategy;
31 public InMemoryWithFileStorageStrategyIT()
33 clock = Clock.systemDefaultZone();
34 mapper = new ObjectMapper();
35 mapper.registerModule(new JavaTimeModule());
36 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
37 storageStrategy = new FileStorageStrategy(
41 messageFlux -> new InMemoryChatRoomService(messageFlux),
47 protected StorageStrategy getStorageStrategy()
49 return storageStrategy;
53 protected Supplier<ChatHomeService> chatHomeServiceSupplier()
55 return () -> new InMemoryChatHomeService(getStorageStrategy().readChatrooms(), clock, 8);
59 void reset() throws Exception
61 if (Files.exists(path))
69 if (!file.equals(path))
71 log.debug("Deleting file {}", file);
77 throw new RuntimeException(e);
80 log.debug("Deleting data-directory {}", path);