use of org.jrobin.core.Sample in project opennms by OpenNMS.
the class JRobinConverterTest method createMockSineRrds.
private void createMockSineRrds(final RrdBackendFactory factory) throws RrdException, IOException {
final long start = (m_baseTime - (SECONDS_PER_DAY * 56L));
initializeRrd(m_sineFull, new String[] { "a", "b" }, new String[] { "1:4032", "12:1488", "288:366" });
initializeRrd(m_sineSourceA, new String[] { "a" }, new String[] { "1:8928", "12:8784" });
initializeRrd(m_sineSourceB, new String[] { "b" }, new String[] { "1:8928", "12:8784" });
final RrdDb sineFull;
final RrdDb sineSourceA;
final RrdDb sineSourceB;
if (factory == null) {
sineFull = new RrdDb(m_sineFull);
sineSourceA = new RrdDb(m_sineSourceA);
sineSourceB = new RrdDb(m_sineSourceB);
} else {
sineFull = new RrdDb(m_sineFull.getAbsolutePath(), factory);
sineSourceA = new RrdDb(m_sineSourceA.getAbsolutePath(), factory);
sineSourceB = new RrdDb(m_sineSourceB.getAbsolutePath(), factory);
}
Function bigSine = new Sin(start, 15, -10, SECONDS_PER_DAY * 7L);
Function smallSine = new Sin(start, 7, 5, SECONDS_PER_DAY * 2L);
Function bigSineCounter = new Counter(0, bigSine);
Function smallSineCounter = new Counter(0, smallSine);
long timestamp = start - 300L;
for (; timestamp <= (m_baseTime - (SECONDS_PER_DAY * 28L)); timestamp += 300L) {
Sample sampleA = sineSourceA.createSample(timestamp);
sampleA.setValue("a", bigSineCounter.evaluate(timestamp));
sampleA.update();
Sample sampleB = sineSourceB.createSample(timestamp);
sampleB.setValue("b", Double.NaN);
sampleB.update();
}
for (; timestamp <= m_baseTime; timestamp += 300L) {
Sample sampleA = sineFull.createSample(timestamp);
sampleA.setValue("a", smallSineCounter.evaluate(timestamp));
sampleA.update();
Sample sampleB = sineSourceB.createSample(timestamp);
sampleB.setValue("b", Double.NaN);
sampleB.update();
}
sineFull.close();
sineSourceA.close();
sineSourceB.close();
}
use of org.jrobin.core.Sample in project opennms by OpenNMS.
the class JRobinRrdStrategyTest method testSampleSetFloatingPointValueGood.
@Test
public void testSampleSetFloatingPointValueGood() throws Exception {
File rrdFile = createRrdFile();
RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
Sample sample = openedFile.createSample();
sample.set("N:1.234");
m_strategy.closeFile(openedFile);
double[] values = sample.getValues();
assertEquals("values list size", 1, values.length);
assertEquals("values item 0", 1.234, values[0], 0.0);
}
use of org.jrobin.core.Sample in project opennms by OpenNMS.
the class JRobinRrdStrategyTest method testSampleSetFloatingPointValueWithExtraJunk.
/**
* This test fails because of
* <a href="http://bugzilla.opennms.org/show_bug.cgi?id=2272">bug #2272</a>
* in org.jrobin.core.Sample.
*/
@Test
@Ignore("fails due to bug 2272")
public void testSampleSetFloatingPointValueWithExtraJunk() throws Exception {
File rrdFile = createRrdFile();
RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
Sample sample = openedFile.createSample();
ThrowableAnticipator ta = new ThrowableAnticipator();
ta.anticipate(new Exception("Some exception that complains about bogus data"));
try {
sample.set("N:1.234 extra junk");
} catch (Throwable t) {
ta.throwableReceived(t);
} finally {
m_strategy.closeFile(openedFile);
}
ta.verifyAnticipated();
}
use of org.jrobin.core.Sample in project opennms by OpenNMS.
the class JRobinRrdStrategyTest method testSampleSetFloatingPointValueWithComma.
/**
* This test fails because of
* <a href="http://bugzilla.opennms.org/show_bug.cgi?id=2272">bug #2272</a>
* in org.jrobin.core.Sample.
*/
@Test
@Ignore("fails due to bug 2272")
public void testSampleSetFloatingPointValueWithComma() throws Exception {
File rrdFile = createRrdFile();
RrdDb openedFile = m_strategy.openFile(rrdFile.getAbsolutePath());
Sample sample = openedFile.createSample();
sample.set("N:1,234");
m_strategy.closeFile(openedFile);
double[] values = sample.getValues();
assertEquals("values list size", 1, values.length);
assertEquals("values item 0", 1.234, values[0], 0.0);
}
Aggregations