/** * {@inheritDoc} */ @Override public boolean canGenerateFor(DefaultData defaultData) { return null != defaultData.getTimeStamp(); }
/** * Is the default data's time stamp in the time frame of this processor. * * @param defaultData * {@link DefaultData} to check. * @return true if it is in the time frame. */ private boolean isInTimeframe(DefaultData defaultData) { if (null != fromDate) { if (fromDate.after(defaultData.getTimeStamp())) { return false; } } if (null != toDate) { if (toDate.before(defaultData.getTimeStamp())) { return false; } } return true; }
/** * {@inheritDoc} */ @Override public Object getKey(E element) { if (null == element.getTimeStamp()) { return null; } long key = getKey(element.getTimeStamp()); createdKeysMap.put(Long.valueOf(key), Boolean.TRUE); if (key < minCreatedKey) { minCreatedKey = key; } if (key > maxCreatedKey) { maxCreatedKey = key; } return key; }
if (oldestData > defaultData.getTimeStamp().getTime()) { if (oldestDataTimestamp.compareAndSet(oldestData, defaultData.getTimeStamp().getTime())) { break; if (newestData < defaultData.getTimeStamp().getTime()) { if (newestDataTimestamp.compareAndSet(newestData, defaultData.getTimeStamp().getTime())) { break;
/** * {@inheritDoc} */ @Override public int compare(DefaultData o1, DefaultData o2) { switch (this) { case TIMESTAMP: return ObjectUtils.compare(o1.getTimeStamp(), o2.getTimeStamp()); case ID: return Longs.compare(o1.getId(), o2.getId()); default: return 0; } } }
/** * {@inheritDoc} */ @Override public DetailsTable generate(DefaultData defaultData, RepositoryDefinition repositoryDefinition, Composite parent, FormToolkit toolkit) { DetailsTable table = new DetailsTable(parent, toolkit, "General Info", 1); // time stamp if (null != defaultData.getTimeStamp()) { table.addContentRow("Timestamp:", InspectIT.getDefault().getImage(InspectITImages.IMG_CALENDAR), new DetailsCellContent[] { new DetailsCellContent(NumberFormatter.formatTime(defaultData.getTimeStamp().getTime())) }); } return table; }
/** * Creates the influx {@link Builder} for the given data type. * * @param data * Data carrier * @return Builder that can be used to create influx Points. */ @Override public Collection<Builder> createBuilders(E data) { Builder builder = Point.measurement(getSeriesName()); builder.time(data.getTimeStamp().getTime(), TimeUnit.MILLISECONDS); this.addTags(data, builder); this.addFields(data, builder); return Collections.singletonList(builder); }
/** * {@inheritDoc} */ @Override public DefaultData getLastDataObject(DefaultData template) { StorageIndexQuery query = storageIndexQueryProvider.createNewStorageIndexQuery(); query.setMinId(template.getId()); ArrayList<Class<?>> searchClasses = new ArrayList<>(); searchClasses.add(template.getClass()); query.setObjectClasses(searchClasses); query.setPlatformIdent(template.getPlatformIdent()); query.setSensorTypeIdent(template.getSensorTypeIdent()); List<DefaultData> resultList = super.executeQuery(query); if (CollectionUtils.isNotEmpty(resultList)) { Iterator<DefaultData> it = resultList.iterator(); DefaultData lastObject = it.next(); while (it.hasNext()) { DefaultData next = it.next(); if (next.getTimeStamp().after(lastObject.getTimeStamp())) { lastObject = next; } } return lastObject; } else { return null; } }
/** * Test that {@link TimeFrameDataProcessor} only passed the data that belongs to the given time * frame. */ @Test public void testTimeframeProcessor() { DefaultData defaultData = mock(DefaultData.class); long time = 10000000; long past = time - 1000; long future = time + 1000; AbstractDataProcessor dataProcessor = mock(AbstractDataProcessor.class); List<AbstractDataProcessor> chainedProcessors = new ArrayList<>(); chainedProcessors.add(dataProcessor); TimeFrameDataProcessor timeFrameDataProcessor = new TimeFrameDataProcessor(new Date(past), new Date(future), chainedProcessors); assertThat(timeFrameDataProcessor.canBeProcessed(defaultData), is(true)); Mockito.when(defaultData.getTimeStamp()).thenReturn(new Timestamp(time)); timeFrameDataProcessor.process(defaultData); Mockito.when(defaultData.getTimeStamp()).thenReturn(new Timestamp(past)); timeFrameDataProcessor.process(defaultData); Mockito.when(defaultData.getTimeStamp()).thenReturn(new Timestamp(future)); timeFrameDataProcessor.process(defaultData); verify(dataProcessor, times(3)).process(defaultData); Mockito.when(defaultData.getTimeStamp()).thenReturn(new Timestamp(past - 1000)); timeFrameDataProcessor.process(defaultData); Mockito.when(defaultData.getTimeStamp()).thenReturn(new Timestamp(future + 1000)); timeFrameDataProcessor.process(defaultData); verify(dataProcessor, times(3)).process(defaultData); }
/** * All aggregated values must lie in between from and to. */ @Test public void aggregatedValuesBetweenFromTo() { List<? extends DefaultData> resultList = null; Sensitivity sensitivity = SamplingRateControl.Sensitivity.VERY_COARSE; // from time is Mon Sep 15 10:50:12 CEST 2008 Date fromDate = new Date(1221468612000L); // to time is Mon Sep 15 12:00:00 CEST 2008 Date toDate = new Date(1221472800000L); resultList = mode.adjustSamplingRate(dataObjects, fromDate, toDate, sensitivity.getValue(), new ClassLoadingInformationDataAggregator()); for (DefaultData defaultData : resultList) { long dataTime = defaultData.getTimeStamp().getTime(); assertThat(dataTime, is(greaterThanOrEqualTo(fromDate.getTime()))); assertThat(dataTime, is(lessThanOrEqualTo(toDate.getTime()))); } }
/** * Test that get will work even when branch can not generate key for the element if ID is * correctly set. * * @throws IndexingException */ @Test public void getWithNoKey() throws IndexingException { IBufferTreeComponent<DefaultData> rootBranch = new Branch<>(new BufferBranchIndexer<>(new TimestampIndexer<>())); DefaultData defaultData = mock(DefaultData.class); when(defaultData.getId()).thenReturn(1L); when(defaultData.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); rootBranch.put(defaultData); when(defaultData.getTimeStamp()).thenReturn(null); // test get assertThat(rootBranch.get(defaultData), is(equalTo(defaultData))); // then get and remove assertThat(rootBranch.getAndRemove(defaultData), is(equalTo(defaultData))); // confirm it is removed assertThat(rootBranch.get(defaultData), is(nullValue())); }
/** * 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)); }
JmxSensorValueData jmxData = (JmxSensorValueData) data; if (map.containsKey(jmxData.getJmxSensorDefinitionDataIdentId())) { if (map.get(jmxData.getJmxSensorDefinitionDataIdentId()).getTimeStamp().getTime() < data.getTimeStamp().getTime()) { map.put(jmxData.getJmxSensorDefinitionDataIdentId(), (JmxSensorValueData) data);
when(data.getTimeStamp()).thenReturn(new Timestamp(System.currentTimeMillis())); Object key1 = indexer.getKey(data); when(data.getTimeStamp()).thenReturn(new Timestamp(System.currentTimeMillis() + (20 * 60 * 1000))); // 20 Object key2 = indexer.getKey(data);
when(defaultData1.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); when(defaultData1.isQueryComplied(indexQuery)).thenReturn(true); rootBranch.put(defaultData1); when(defaultData2.getTimeStamp()).thenReturn(plusHour); when(defaultData2.isQueryComplied(indexQuery)).thenReturn(true); rootBranch.put(defaultData2); assertThat(results.size(), is(equalTo(1))); for (DefaultData result : results) { assertThat(result.getTimeStamp().getTime(), is(greaterThanOrEqualTo(minusHour.getTime()))); assertThat(result.getTimeStamp().getTime(), is(lessThanOrEqualTo(plusHour.getTime()))); assertThat(resultsForkJoin.size(), is(equalTo(1))); for (DefaultData result : resultsForkJoin) { assertThat(result.getTimeStamp().getTime(), is(greaterThanOrEqualTo(minusHour.getTime()))); assertThat(result.getTimeStamp().getTime(), is(lessThanOrEqualTo(plusHour.getTime())));
when(defaultData1.getTimeStamp()).thenReturn(new Timestamp(new Date().getTime())); IStorageDescriptor storageDescriptor1 = rootBranch.put(defaultData1); storageDescriptor1.setPositionAndSize(0L, 100L); when(defaultData2.getTimeStamp()).thenReturn(plusHour); IStorageDescriptor storageDescriptor2 = rootBranch.put(defaultData2); storageDescriptor2.setPositionAndSize(0L, 200L);
/** * {@inheritDoc} */ @Override @MethodLog public CmrStatusData getCmrStatusData() { // cmr status data should always report in bytes! CmrStatusData cmrStatusData = new CmrStatusData(); cmrStatusData.setCurrentBufferSize(buffer.getCurrentSize()); cmrStatusData.setMaxBufferSize(buffer.getMaxSize()); DefaultData oldestElement = buffer.getOldestElement(); if (null != oldestElement) { cmrStatusData.setBufferOldestElementDate(new Date(oldestElement.getTimeStamp().getTime())); } DefaultData newestElement = buffer.getNewestElement(); if (null != newestElement) { cmrStatusData.setBufferNewestElementDate(new Date(newestElement.getTimeStamp().getTime())); } cmrStatusData.setStorageDataSpaceLeft(storageManager.getBytesHardDriveOccupancyLeft()); cmrStatusData.setStorageMaxDataSpace(storageManager.getMaxBytesHardDriveOccupancy()); cmrStatusData.setWarnSpaceLeftActive(storageManager.isSpaceWarnActive()); cmrStatusData.setCanWriteMore(storageManager.canWriteMore()); cmrStatusData.setUpTime(System.currentTimeMillis() - timeStarted); cmrStatusData.setDateStarted(dateStarted); cmrStatusData.setDatabaseSize(getDatabaseSize()); for (IExternalService service : services) { cmrStatusData.getExternalServiceStatusMap().put(service.getServiceType(), service.getServiceStatus()); } return cmrStatusData; }
Date fromDate = new Date(oldestBufferElement.getTimeStamp().getTime()); Date toDate = null;