WriteTimelyPlugin extends CollectDPluginParent implements CollectdConfigInterface, CollectdShutdownInterface, CollectdWriteInterface { public int write(ValueList vl) { Socket socket = null; try { socket = socketPool.borrowObject(); if (socket == null) { return -1; } super.process(vl, socket.getOutputStream()); } catch (Exception e) { Collectd.logWarning(e.getMessage()); try { if (socket != null) { socket.close(); } } catch (IOException e1) { Collectd.logError(e1.getMessage()); } return -1; } finally { if (socket != null) { socketPool.returnObject(socket); } } return 0; } WriteTimelyPlugin(); int write(ValueList vl); @Override void write(String metric, OutputStream out); int shutdown(); int config(OConfigItem config);  }
@Test public void testWrite() throws Exception { Thread t = new Thread(server); t.start(); setupPlugin(); while (!server.ready()) { Thread.sleep(1000); } Assert.assertEquals(0, plugin.write(createMetric())); Thread.sleep(100); Assert.assertTrue(server.messageReceived()); plugin.shutdown(); server.shutdown(); t.join(); }