BackupMessagesLoader { public void loadFromTemporaryBackupV2File(File file) { try ( FileInputStream fileInputStream = new FileInputStream(file); ObjectInputStream objectInputStream = new ObjectInputStream(fileInputStream) ) { List<BackupMessage> messages = (List<BackupMessage>) objectInputStream.readObject(); logger.info("Loaded {} messages from temporary v2 backup file: {}", messages.size(), file.toString()); loadMessages(messages); } catch (IOException | ClassNotFoundException e) { logger.error("Error reading temporary backup v2 files from path {}.", file.getAbsolutePath(), e); } } @Inject  BackupMessagesLoader(BrokerMessageProducer brokerMessageProducer,
                                BrokerListeners brokerListeners,
                                TopicsCache topicsCache,
                                Trackers trackers,
                                ConfigFactory config); void loadMessages(List<BackupMessage> messages); void loadFromTemporaryBackupV2File(File file); void clearTopicsAvailabilityCache();  }
@Test public void shouldReadV2MessagesFromTemporaryFile2() throws IOException { when(configFactory.getIntProperty(Configs.MESSAGES_LOCAL_STORAGE_MAX_AGE_HOURS)).thenReturn(1000000); when(producer.isTopicAvailable(cachedTopic)).thenReturn(true); when(topicsCache.getTopic(any())).thenReturn(Optional.of(cachedTopic)); BackupMessagesLoader backupMessagesLoader = new BackupMessagesLoader(producer, listeners, topicsCache, trackers, configFactory); ClassLoader classLoader = getClass().getClassLoader(); File temporaryBackup1 = new File(classLoader.getResource("backup/hermes-buffer-12345.dat-v2-old.tmp").getFile()); backupMessagesLoader.loadFromTemporaryBackupV2File(temporaryBackup1); verify(producer, times(20)).send(any(JsonMessage.class), eq(cachedTopic), any(PublishingCallback.class)); }