OpenTsdbProvider implements Provider<OpenTsdb> { @Override public OpenTsdb get() { final OpenTsdbProtocol protocol = configuration.getProtocol(); switch (protocol) { case HTTP: return OpenTsdb.forService(configuration.getHttpBaseUrl().toASCIIString()) .withConnectTimeout(configuration.getHttpConnectTimeout()) .withReadTimeout(configuration.getHttpReadTimeout()) .withGzipEnabled(configuration.isHttpEnableGzip()) .create(); case TELNET: final HostAndPort address = configuration.getTelnetAddress(); final String host = address.getHost(); final int port = address.getPortOrDefault(MetricsOpenTsdbReporterConfiguration.DEFAULT_PORT); return OpenTsdbTelnet.forService(host, port).create(); default: throw new IllegalStateException("Invalid OpenTSDB protocol: " + protocol); } } @Inject  OpenTsdbProvider(MetricsOpenTsdbReporterConfiguration configuration); @Override OpenTsdb get();  }
@Test public void getHttp() { final OpenTsdbProvider provider = new OpenTsdbProvider(new MetricsOpenTsdbReporterConfiguration() { @Override public OpenTsdbProtocol getProtocol() { return OpenTsdbProtocol.HTTP; } }); final OpenTsdb openTsdb = provider.get(); assertNotNull(openTsdb); assertFalse(openTsdb instanceof OpenTsdbTelnet); }
@Test public void getTelnet() { final OpenTsdbProvider provider = new OpenTsdbProvider(new MetricsOpenTsdbReporterConfiguration() { @Override public OpenTsdbProtocol getProtocol() { return OpenTsdbProtocol.TELNET; } }); final OpenTsdb openTsdb = provider.get(); assertNotNull(openTsdb); assertTrue(openTsdb instanceof OpenTsdbTelnet); }