/** * Return an new sample with collected values * * @param oneSample or null if collect failed */ private JrdsSample updateSample() { JrdsSample sample = newSample(); if(isCollectRunning()) { Map<KeyType, ValueType> sampleVals = getNewSampleValues(); if(sampleVals != null && sampleVals.size() != 0 && injectSample(sample, sampleVals)) { return sample; } } return null; }
static public long fill(Probe<?, ?> p) throws IOException { long start = System.currentTimeMillis() / 1000; long end = start + 3600 * 24 * 30; // update database GaugeSource sunSource = new GaugeSource(1200, 20); GaugeSource shadeSource = new GaugeSource(300, 10); long t = start; // Keep an handle to the object, for faster run Object o = p.getMainStore().getStoreObject(); while (t <= end + 86400L) { JrdsSample sample = p.newSample(); sample.setTime(new Date(t * 1000)); sample.put("sun", sunSource.getValue()); sample.put("shade", shadeSource.getValue()); p.getMainStore().commit(sample); t += RANDOM.nextDouble() * STEP + 1; } p.getMainStore().closeStoreObject(o); return t; }
@Test public void testFill() throws Exception { @SuppressWarnings("unchecked") Probe<?, ?> p = GenerateProbe.quickProbe(testFolder); p.setStep(30); p.getPd().add("test", DsType.GAUGE); Assert.assertTrue("Probe file creation failed", p.checkStore()); Extractor e = p.getMainStore().getExtractor(); e.addSource("test", "test"); String[] dsNames = e.getNames(); Assert.assertEquals("data source test not found", "test", dsNames[0]); long start = p.getLastUpdate().getTime(); for(int i = 1; i <= 30; i++) { JrdsSample s = p.newSample(); long sampletime = i * p.getStep() * 1000 + start; sampletime = (sampletime) - (sampletime % (p.getStep() * 1000)); s.setTime(new Date(sampletime)); s.put("test", i); p.getMainStore().commit(s); } ExtractInfo ei = ExtractInfo.get().make(new Date(start), new Date(start + 30 * p.getStep() * 1000)); DataProcessor dp = p.extract(ei); double[][] values = dp.getValues(); for(int i = 1; i <= 30; i++) { // Check raw values Assert.assertEquals("Wrong values stored", i, values[0][i], 1e-10); long sampletime = i * p.getStep() * 1000 + start; sampletime = (sampletime) - (sampletime % (p.getStep() * 1000)); } }