GraphiteSenderProvider implements Provider<GraphiteSender> { @Override public GraphiteSender get() { HostAndPort hostAndPort = configuration.getAddress(); String host = hostAndPort.getHost(); int port = hostAndPort.getPortOrDefault(2003); switch (configuration.getProtocol()) { case PICKLE: return new PickledGraphite( host, port, SocketFactory.getDefault(), configuration.getCharset(), configuration.getPickleBatchSize()); case TCP: return new Graphite(host, port, SocketFactory.getDefault(), configuration.getCharset()); case UDP: return new GraphiteUDP(host, port); default: throw new IllegalArgumentException("Unknown Graphite protocol \"" + configuration.getProtocol() + "\""); } } @Inject  GraphiteSenderProvider(MetricsGraphiteReporterConfiguration configuration); @Override GraphiteSender get();  }
@Test public void getReturnsGraphite() throws Exception { final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() { @Override public GraphiteProtocol getProtocol() { return GraphiteProtocol.TCP; } }; final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration); final GraphiteSender graphiteSender = provider.get(); assertTrue(graphiteSender instanceof Graphite); assertFalse(graphiteSender.isConnected()); }
@Test public void getReturnsGraphiteUDP() throws Exception { final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() { @Override public GraphiteProtocol getProtocol() { return GraphiteProtocol.UDP; } }; final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration); final GraphiteSender graphiteSender = provider.get(); assertTrue(graphiteSender instanceof GraphiteUDP); assertFalse(graphiteSender.isConnected()); }
@Test public void getReturnsGraphitePickledGraphite() throws Exception { final MetricsGraphiteReporterConfiguration configuration = new MetricsGraphiteReporterConfiguration() { @Override public GraphiteProtocol getProtocol() { return GraphiteProtocol.PICKLE; } }; final GraphiteSenderProvider provider = new GraphiteSenderProvider(configuration); final GraphiteSender graphiteSender = provider.get(); assertTrue(graphiteSender instanceof PickledGraphite); assertFalse(graphiteSender.isConnected()); }