GraphiteRabbitMQ implements GraphiteSender { @Override public void connect() throws IllegalStateException, IOException { if (isConnected()) { throw new IllegalStateException("Already connected"); } try { connection = connectionFactory.newConnection(); } catch (TimeoutException e) { throw new IllegalStateException(e); } channel = connection.createChannel(); } GraphiteRabbitMQ(final ConnectionFactory connectionFactory, final String exchange);  GraphiteRabbitMQ(
            final String rabbitHost,
            final Integer rabbitPort,
            final String rabbitUsername,
            final String rabbitPassword,
            final String exchange);  GraphiteRabbitMQ(
            final String rabbitHost,
            final Integer rabbitPort,
            final String rabbitUsername,
            final String rabbitPassword,
            final String exchange,
            final Integer rabbitConnectionTimeoutMS,
            final Integer rabbitSocketTimeoutMS,
            final Integer rabbitRequestedHeartbeatInSeconds); @Override void connect(); @Override boolean isConnected(); @Override void send(String name, String value, long timestamp); @Override void flush(); @Override void close(); @Override int getFailures(); String sanitize(String s);  }
@Test public void shouldConnectToGraphiteServer() throws Exception { graphite.connect(); verify(connectionFactory, atMost(1)).newConnection(); verify(connection, atMost(1)).createChannel(); }
@Test public void shouldNotConnectToGraphiteServerMoreThenOnce() throws Exception { graphite.connect(); try { graphite.connect(); failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException e) { assertThat(e.getMessage()).isEqualTo("Already connected"); } }
@Test public void shouldFailWhenGraphiteHostUnavailable() { ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost("some-unknown-host"); try (GraphiteRabbitMQ unavailableGraphite = new GraphiteRabbitMQ(connectionFactory, "graphite")) { unavailableGraphite.connect(); failBecauseExceptionWasNotThrown(UnknownHostException.class); } catch (Exception e) { assertThat(e.getMessage()).contains("some-unknown-host"); } }