/** * Tests copy buffer action. */ @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); // first with no auto-finalize 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); // first with auto-finalize 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)); }
List<DefaultData> toWriteList = storageDataDao.getAllDefaultDataForAgent(platformId.longValue(), fromDate, toDate); this.writeToStorage(local, toWriteList, dataProcessors, true);