@Test public void testStore() throws Exception { em.getTransaction().begin(); RecordKeys recordKeys = new RecordKeysBuilder() .setKeyName("recordKeyName") .setKeyValue("node_table_flow").build(); List<RecordKeys> recordKeysList= new ArrayList<RecordKeys>(); recordKeysList.add(recordKeys); String timeStamp = ""+System.currentTimeMillis(); TSDRMetricRecordBuilder tsdrMetricBuilder = new TSDRMetricRecordBuilder(); TSDRMetricRecord tsdrMetrics = tsdrMetricBuilder.setMetricName("METRIC_NAME") .setMetricValue(new BigDecimal(Double.parseDouble("64"))) .setNodeID("openflow:dummy") .setRecordKeys(recordKeysList) .setTimeStamp(Long.parseLong(timeStamp)) .setTSDRDataCategory(DataCategory.FLOWSTATS).build(); tsdrH2PersistenceService.store( tsdrMetrics); em.getTransaction().commit(); List<TSDRMetricRecord>metricList = tsdrJpaService.getMetricsFilteredByCategory(DataCategory.FLOWSTATS.name(),0,Long.MAX_VALUE); Assert.assertEquals(1, metricList.size()); Assert.assertEquals("METRIC_NAME", metricList.get(0).getMetricName()); Assert.assertEquals(64.0,metricList.get(0).getMetricValue().doubleValue(),0.02); Assert.assertEquals("openflow:dummy",metricList.get(0).getNodeID()); String mID = FormatUtil.getTSDRMetricKey(metricList.get(0)); Assert.assertEquals("[NID=openflow:dummy][DC=FLOWSTATS][MN=METRIC_NAME][RK=recordKeyName:node_table_flow]",mID);; Assert.assertEquals(timeStamp, metricList.get(0).getTimeStamp().toString()); Assert.assertEquals(DataCategory.FLOWSTATS.toString(), (metricList.get(0)).getTSDRDataCategory().toString()); }
@Override public void store(TSDRMetricRecord metrics){ Preconditions.checkArgument(metrics != null); DataCategory dc =metrics.getTSDRDataCategory(); Preconditions.checkArgument(dc != null); if(jpaService != null) { Metric metric = getEntityFromModel(metrics); jpaService.add(metric); }else{ log.error(metrics.getMetricName() + " could not be saved as the JPA Service is null."); } }
TsdrH2PersistenceServiceImpl implements
    TsdrPersistenceService { @Override public void store(TSDRMetricRecord metrics){ Preconditions.checkArgument(metrics != null); DataCategory dc =metrics.getTSDRDataCategory(); Preconditions.checkArgument(dc != null); if(jpaService != null) { Metric metric = getEntityFromModel(metrics); jpaService.add(metric); }else{ log.error(metrics.getMetricName() + " could not be saved as the JPA Service is null."); } } }
TsdrH2PersistenceServiceImpl implements
    TsdrPersistenceService { @Override public void store(TSDRMetricRecord metrics){ Preconditions.checkArgument(metrics != null); DataCategory dc =metrics.getTSDRDataCategory(); Preconditions.checkArgument(dc != null); if(jpaService != null) { Metric metric = getEntityFromModel(metrics); jpaService.add(metric); }else{ log.error(metrics.getMetricName() + " could not be saved as the JPA Service is null."); } } TsdrH2PersistenceServiceImpl(); }
TsdrH2PersistenceServiceImpl implements
    TsdrPersistenceService { @Override public void store(TSDRMetricRecord metrics){ Preconditions.checkArgument(metrics != null); DataCategory dc =metrics.getTSDRDataCategory(); Preconditions.checkArgument(dc != null); if(jpaService != null) { Metric metric = getEntityFromModel(metrics); jpaService.add(metric); }else{ log.error(metrics.getMetricName() + " could not be saved as the JPA Service is null."); } } TsdrH2PersistenceServiceImpl(); @Override void store(TSDRMetricRecord metrics); @Override void store(List<TSDRRecord> metricList); @Override void start(int timeout); @Override void stop(int timeout); @Override List<TSDRMetricRecord> getTSDRMetricRecords(String metricsCategory, long startDateTime, long endDateTime); @Override void purgeTSDRRecords(DataCategory category, Long retention_time); @Override void purgeAllTSDRRecords(Long retentionTime); Metric getEntityFromModel(TSDRMetricRecord data); Metric getEntityFromModel(TSDRLogRecord data); TsdrJpaServiceImpl getJpaService(); void setJpaService(TsdrJpaServiceImpl jpaService); @Override void store(TSDRLogRecord logRecord); @Override List<TSDRLogRecord> getTSDRLogRecords(String category, long startTime, long endTime); }
TsdrH2PersistenceServiceImpl implements
    TsdrPersistenceService { @Override public void store(TSDRMetricRecord metrics){ Preconditions.checkArgument(metrics != null); DataCategory dc =metrics.getTSDRDataCategory(); Preconditions.checkArgument(dc != null); if(jpaService != null) { Metric metric = getEntityFromModel(metrics); jpaService.add(metric); }else{ log.error(metrics.getMetricName() + " could not be saved as the JPA Service is null."); } } TsdrH2PersistenceServiceImpl(); @Override void store(TSDRMetricRecord metrics); @Override void store(List<TSDRRecord> metricList); @Override void start(int timeout); @Override void stop(int timeout); @Override List<TSDRMetricRecord> getTSDRMetricRecords(String metricsCategory, long startDateTime, long endDateTime); @Override void purgeTSDRRecords(DataCategory category, Long retention_time); @Override void purgeAllTSDRRecords(Long retentionTime); Metric getEntityFromModel(TSDRMetricRecord data); Metric getEntityFromModel(TSDRLogRecord data); TsdrJpaServiceImpl getJpaService(); void setJpaService(TsdrJpaServiceImpl jpaService); @Override void store(TSDRLogRecord logRecord); @Override List<TSDRLogRecord> getTSDRLogRecords(String category, long startTime, long endTime);  }