public File createRrdFile() throws Exception { String rrdFileBase = "foo"; m_fileAnticipator.initialize(); // This is so the RrdUtils.getExtension() call in the strategy works // Properties properties = new Properties(); // properties.setProperty("org.opennms.rrd.fileExtension", rrdExtension); // RrdConfig.getInstance().setProperties(properties); List<RrdDataSource> dataSources = new ArrayList<RrdDataSource>(); dataSources.add(new RrdDataSource("bar", "GAUGE", 3000, "U", "U")); List<String> rraList = new ArrayList<String>(); rraList.add("RRA:AVERAGE:0.5:1:2016"); File tempDir = m_fileAnticipator.getTempDir(); // Create an '/rrd/snmp/1' directory in the temp directory so that the // RRDs created by the test will have a realistic path File rrdDir = m_fileAnticipator.tempDir( m_fileAnticipator.tempDir(m_fileAnticipator.tempDir(tempDir, "rrd"), "snmp"), "1"); RrdDefinition def = m_strategy.createDefinition( "hello!", rrdDir.getAbsolutePath(), rrdFileBase, 300, dataSources, rraList); m_strategy.createFile(def, null); return m_fileAnticipator.expecting(rrdDir, rrdFileBase + RRD_EXTENSION); }
@Test public void testCreate() throws Exception { File rrdFile = createRrdFile(); String openedFile = m_strategy.openFile(rrdFile.getAbsolutePath()); // m_strategy.updateFile(openedFile, "huh?", "N:1,234234"); m_strategy.closeFile(openedFile); }
@Test public void testUpdate() throws Exception { File rrdFile = createRrdFile(); String openedFile = m_strategy.openFile(rrdFile.getAbsolutePath()); long currentTimeInSeconds = (long) (new Date().getTime() / 100); m_strategy.updateFile( openedFile, "huh?", String.valueOf(currentTimeInSeconds - 9) + ":1.234234"); m_strategy.updateFile( openedFile, "oh ", String.valueOf(currentTimeInSeconds - 8) + ":1.234234"); m_strategy.updateFile( openedFile, "ok ", String.valueOf(currentTimeInSeconds - 7) + ":1.234234"); // Sleep in between updates so that we don't underrun the 1-second step size Thread.sleep(5000); currentTimeInSeconds = (long) (new Date().getTime() / 100); m_strategy.updateFile( openedFile, "lol ", String.valueOf(currentTimeInSeconds - 6) + ":1.234234"); m_strategy.updateFile( openedFile, "lolz", String.valueOf(currentTimeInSeconds - 5) + ":1.234234"); m_strategy.updateFile( openedFile, "lolz", String.valueOf(currentTimeInSeconds - 4) + ":1.234234"); m_strategy.updateFile( openedFile, "zzzz", String.valueOf(currentTimeInSeconds - 3) + ":1.234234"); m_strategy.closeFile(openedFile); Thread.sleep(1000); }