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.persistence.storage.files.FilesStorageStrategy;
7 import de.juplo.kafka.chat.backend.persistence.inmemory.InMemoryChatRoomService;
8 import lombok.extern.slf4j.Slf4j;
9 import org.junit.jupiter.api.BeforeEach;
11 import java.io.IOException;
12 import java.nio.file.Files;
13 import java.nio.file.Path;
14 import java.nio.file.Paths;
15 import java.time.Clock;
19 public class InMemoryWithFilesStorageIT extends AbstractInMemoryStorageIT
21 final static Path path = Paths.get("target","files");
23 final ObjectMapper mapper;
24 final FilesStorageStrategy storageStrategy;
27 public InMemoryWithFilesStorageIT()
29 super(Clock.systemDefaultZone());
30 mapper = new ObjectMapper();
31 mapper.registerModule(new JavaTimeModule());
32 mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
33 storageStrategy = new FilesStorageStrategy(
38 messageFlux -> new InMemoryChatRoomService(messageFlux),
44 protected StorageStrategy getStorageStrategy()
46 return storageStrategy;
50 void reset() throws Exception
52 if (Files.exists(path))
60 if (!file.equals(path))
62 log.debug("Deleting file {}", file);
68 throw new RuntimeException(e);
71 log.debug("Deleting data-directory {}", path);