@Test public void copyBufferToStorage() throws IOException, SerializationException, BusinessException { storageData = new StorageData(); storageData.setName("Test"); DefaultData defaultData = mock(DefaultData.class); Timestamp timestamp = mock(Timestamp.class); when(defaultData.getTimeStamp()).thenReturn(timestamp); when(buffer.getOldestElement()).thenReturn(defaultData); List<DefaultData> data = Collections.singletonList(mock(DefaultData.class)); Collection<AbstractDataProcessor> processors = Collections.singleton(mock(AbstractDataProcessor.class)); Long platformId = 10L; List<Long> platformIdents = Collections.singletonList(platformId); storageManager = spy(storageManager); when(storageDataDao.getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any())).thenReturn(data); storageManager.copyBufferToStorage(storageData, platformIdents, processors, false); verify(storageDataDao, times(1)).getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any()); verify(storageManager, times(1)).writeToStorage(storageData, data, processors, true); storageManager.copyBufferToStorage(storageData, platformIdents, processors, true); verify(storageDataDao, times(2)).getAllDefaultDataForAgent(eq(platformId), Matchers.<Date> any(), Matchers.<Date> any()); verify(storageManager, times(2)).writeToStorage(storageData, data, processors, true); assertThat(storageManager.isStorageClosed(storageData), is(true)); }
public void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize) throws BusinessException, IOException, SerializationException { if (!isStorageExisting(storageData)) { this.createStorage(storageData); } StorageData local = getLocalStorageDataObject(storageData); if (!isStorageOpen(local)) { this.openStorage(local); } DefaultData oldestBufferElement = buffer.getOldestElement(); if (null != oldestBufferElement) { Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null; for (AbstractDataProcessor dataProcessor : dataProcessors) { if (dataProcessor instanceof TimeFrameDataProcessor) { TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor; if (timeFrameDataProcessor.getFromDate().after(fromDate)) { fromDate = timeFrameDataProcessor.getFromDate(); } toDate = timeFrameDataProcessor.getToDate(); break; } } for (Long platformId : platformIdents) { List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true); } } if (autoFinalize) { this.closeStorage(local); } updateExistingStorageSize(local); }
CmrStorageManager extends StorageManager implements ApplicationListener<ContextClosedEvent> { public void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize) throws BusinessException, IOException, SerializationException { if (!isStorageExisting(storageData)) { this.createStorage(storageData); } StorageData local = getLocalStorageDataObject(storageData); if (!isStorageOpen(local)) { this.openStorage(local); } DefaultData oldestBufferElement = buffer.getOldestElement(); if (null != oldestBufferElement) { Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null; for (AbstractDataProcessor dataProcessor : dataProcessors) { if (dataProcessor instanceof TimeFrameDataProcessor) { TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor; if (timeFrameDataProcessor.getFromDate().after(fromDate)) { fromDate = timeFrameDataProcessor.getFromDate(); } toDate = timeFrameDataProcessor.getToDate(); break; } } for (Long platformId : platformIdents) { List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true); } } if (autoFinalize) { this.closeStorage(local); } updateExistingStorageSize(local); } }
CmrStorageManager extends StorageManager implements ApplicationListener<ContextClosedEvent> { public void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize) throws BusinessException, IOException, SerializationException { if (!isStorageExisting(storageData)) { this.createStorage(storageData); } StorageData local = getLocalStorageDataObject(storageData); if (!isStorageOpen(local)) { this.openStorage(local); } DefaultData oldestBufferElement = buffer.getOldestElement(); if (null != oldestBufferElement) { Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null; for (AbstractDataProcessor dataProcessor : dataProcessors) { if (dataProcessor instanceof TimeFrameDataProcessor) { TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor; if (timeFrameDataProcessor.getFromDate().after(fromDate)) { fromDate = timeFrameDataProcessor.getFromDate(); } toDate = timeFrameDataProcessor.getToDate(); break; } } for (Long platformId : platformIdents) { List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true); } } if (autoFinalize) { this.closeStorage(local); } updateExistingStorageSize(local); }  }
CmrStorageManager extends StorageManager implements ApplicationListener<ContextClosedEvent> { public void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize) throws BusinessException, IOException, SerializationException { if (!isStorageExisting(storageData)) { this.createStorage(storageData); } StorageData local = getLocalStorageDataObject(storageData); if (!isStorageOpen(local)) { this.openStorage(local); } DefaultData oldestBufferElement = buffer.getOldestElement(); if (null != oldestBufferElement) { Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null; for (AbstractDataProcessor dataProcessor : dataProcessors) { if (dataProcessor instanceof TimeFrameDataProcessor) { TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor; if (timeFrameDataProcessor.getFromDate().after(fromDate)) { fromDate = timeFrameDataProcessor.getFromDate(); } toDate = timeFrameDataProcessor.getToDate(); break; } } for (Long platformId : platformIdents) { List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true); } } if (autoFinalize) { this.closeStorage(local); } updateExistingStorageSize(local); }  void createStorage(StorageData storageData); StorageWriter openStorage(StorageData storageData); void closeStorage(StorageData storageData); void deleteStorage(StorageData storageData); StorageData getRecordingStorage(); RecordingProperties getRecordingProperties(); RecordingState getRecordingState(); WritingStatus getRecordingStatus(); void startOrScheduleRecording(StorageData storageData, RecordingProperties recordingProperties); void stopRecording(); void record(DefaultData dataToRecord); void writeToStorage(StorageData storageData, Collection<? extends DefaultData> dataToWrite, Collection<AbstractDataProcessor> dataProcessors, boolean synchronously); void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize); void copyDataToStorage(StorageData storageData, Collection<Long> elementIds, long platformIdent, Set<Long> traceIds, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize); StorageData getStorageData(String id); List<StorageData> getExistingStorages(); List<StorageData> getOpenedStorages(); List<StorageData> getReadableStorages(); boolean isStorageOpen(StorageData storageData); boolean isStorageExisting(StorageData storageData); boolean isStorageClosed(StorageData storageData); long getStorageQueuedWriteTaskCount(StorageData storageData); @Override Path getStoragePath(IStorageData storageData); Map<String, Long> getFilesHttpLocation(StorageData storageData, final String extension); void addLabelToStorage(StorageData storageData, AbstractStorageLabel<?> storageLabel, boolean doOverwrite); boolean removeLabelFromStorage(StorageData storageData, AbstractStorageLabel<?> storageLabel); void updateStorageData(StorageData storageData); Map<StorageData, String> getWritersStatus(); void unpackUploadedStorage(final IStorageData packedStorageData); void createStorageFromUploadedDir(final IStorageData localStorageData); String getCachedStorageDataFileLocation(StorageData storageData, int hash); @PostConstruct void postConstruct(); @Override void onApplicationEvent(ContextClosedEvent event); @Override String toString(); }
CmrStorageManager extends StorageManager implements ApplicationListener<ContextClosedEvent> { public void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize) throws BusinessException, IOException, SerializationException { if (!isStorageExisting(storageData)) { this.createStorage(storageData); } StorageData local = getLocalStorageDataObject(storageData); if (!isStorageOpen(local)) { this.openStorage(local); } DefaultData oldestBufferElement = buffer.getOldestElement(); if (null != oldestBufferElement) { Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null; for (AbstractDataProcessor dataProcessor : dataProcessors) { if (dataProcessor instanceof TimeFrameDataProcessor) { TimeFrameDataProcessor timeFrameDataProcessor = (TimeFrameDataProcessor) dataProcessor; if (timeFrameDataProcessor.getFromDate().after(fromDate)) { fromDate = timeFrameDataProcessor.getFromDate(); } toDate = timeFrameDataProcessor.getToDate(); break; } } for (Long platformId : platformIdents) { List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true); } } if (autoFinalize) { this.closeStorage(local); } updateExistingStorageSize(local); }  void createStorage(StorageData storageData); StorageWriter openStorage(StorageData storageData); void closeStorage(StorageData storageData); void deleteStorage(StorageData storageData); StorageData getRecordingStorage(); RecordingProperties getRecordingProperties(); RecordingState getRecordingState(); WritingStatus getRecordingStatus(); void startOrScheduleRecording(StorageData storageData, RecordingProperties recordingProperties); void stopRecording(); void record(DefaultData dataToRecord); void writeToStorage(StorageData storageData, Collection<? extends DefaultData> dataToWrite, Collection<AbstractDataProcessor> dataProcessors, boolean synchronously); void copyBufferToStorage(StorageData storageData, List<Long> platformIdents, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize); void copyDataToStorage(StorageData storageData, Collection<Long> elementIds, long platformIdent, Set<Long> traceIds, Collection<AbstractDataProcessor> dataProcessors, boolean autoFinalize); StorageData getStorageData(String id); List<StorageData> getExistingStorages(); List<StorageData> getOpenedStorages(); List<StorageData> getReadableStorages(); boolean isStorageOpen(StorageData storageData); boolean isStorageExisting(StorageData storageData); boolean isStorageClosed(StorageData storageData); long getStorageQueuedWriteTaskCount(StorageData storageData); @Override Path getStoragePath(IStorageData storageData); Map<String, Long> getFilesHttpLocation(StorageData storageData, final String extension); void addLabelToStorage(StorageData storageData, AbstractStorageLabel<?> storageLabel, boolean doOverwrite); boolean removeLabelFromStorage(StorageData storageData, AbstractStorageLabel<?> storageLabel); void updateStorageData(StorageData storageData); Map<StorageData, String> getWritersStatus(); void unpackUploadedStorage(final IStorageData packedStorageData); void createStorageFromUploadedDir(final IStorageData localStorageData); String getCachedStorageDataFileLocation(StorageData storageData, int hash); @PostConstruct void postConstruct(); @Override void onApplicationEvent(ContextClosedEvent event); @Override String toString();  }