本文整理汇总了Java中com.timgroup.statsd.StatsDClient类的典型用法代码示例。如果您正苦于以下问题:Java StatsDClient类的具体用法?Java StatsDClient怎么用?Java StatsDClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StatsDClient类属于com.timgroup.statsd包,在下文中一共展示了StatsDClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testReportTime_withJSONHavingNullValueAtLocationTimestamp
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns null for selected path
*/
@Test
public void testReportTime_withJSONHavingNullValueAtLocationTimestamp() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
final JsonProcessingUtils utils = Mockito.mock(JsonProcessingUtils.class);
Mockito.when(utils.getDateTimeFieldValue(Mockito.any(JSONObject.class), Mockito.any(), Mockito.any(String.class))).thenReturn(null);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
reporter.setJsonUtils(utils);
reporter.reportTime(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.TIMESTAMP, "yyyyMMdd"), true), new JSONObject("{\"key\":\"value\"}"));
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).recordExecutionTimeToNow(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(utils).getDateTimeFieldValue(Mockito.any(JSONObject.class), Mockito.any(), Mockito.any(String.class));
}
示例2: testReportTime_withJSONExceptionTimestamp
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns null for selected path
*/
@Test
public void testReportTime_withJSONExceptionTimestamp() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
final JsonProcessingUtils utils = Mockito.mock(JsonProcessingUtils.class);
Mockito.when(utils.getDateTimeFieldValue(Mockito.any(JSONObject.class), Mockito.any(), Mockito.any(String.class))).thenThrow(new NullPointerException());
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
reporter.setJsonUtils(utils);
reporter.reportTime(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.TIMESTAMP, "yyyyMMdd"), true), new JSONObject("{\"key\":\"value\"}"));
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).recordExecutionTimeToNow(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(utils).getDateTimeFieldValue(Mockito.any(JSONObject.class), Mockito.any(), Mockito.any(String.class));
}
示例3: testReportTime_withJSONHavingNullValueAtLocation
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns null for selected path
*/
@Test
public void testReportTime_withJSONHavingNullValueAtLocation() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
final JsonProcessingUtils utils = Mockito.mock(JsonProcessingUtils.class);
Mockito.when(utils.getIntegerFieldValue(Mockito.any(), Mockito.any())).thenReturn(null);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
reporter.setJsonUtils(utils);
reporter.reportTime(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.INTEGER), true), new JSONObject("{\"key\":\"value\"}"));
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).recordExecutionTimeToNow(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(utils).getIntegerFieldValue(Mockito.any(), Mockito.any());
}
示例4: testReportTime_withJSONHavingTimestampValueAtLocationCalc
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns an integer for selected path.
* Value is reported as execution time --> computation
*/
@Test
public void testReportTime_withJSONHavingTimestampValueAtLocationCalc() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
Date expected = f.parse(f.format(now));
reporter.reportTime(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.TIMESTAMP, "yyyyMMdd")), new JSONObject("{\"key\":\""+f.format(now)+"\"}"));
Mockito.verify(client).recordExecutionTimeToNow("path.to.field", expected.getTime());
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
}
示例5: testReportTime_withJSONHavingTimestampValueAtLocationCalcAndPrefix
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns an integer for selected path.
* Value is reported as execution time --> computation (and prefix)
*/
@Test
public void testReportTime_withJSONHavingTimestampValueAtLocationCalcAndPrefix() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
Date expected = f.parse(f.format(now));
reporter.reportTime(new StatsdMetricConfig("path.to.field", new JsonContentReference(new String[]{"prefix"}, JsonContentType.STRING), StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.TIMESTAMP, "yyyyMMdd")), new JSONObject("{\"prefix\":\"pref\",\"key\":\""+f.format(now)+"\"}"));
Mockito.verify(client).recordExecutionTimeToNow("pref.path.to.field", expected.getTime());
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
}
示例6: testReportTime_withJSONHavingTimestampValueAtLocationCalcAndPrefixButNoValue
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#reportTime(StatsdMetricConfig, JSONObject)} being provided a json which returns an integer for selected path.
* Value is reported as execution time --> computation (and prefix but no value)
*/
@Test
public void testReportTime_withJSONHavingTimestampValueAtLocationCalcAndPrefixButNoValue() throws Exception {
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("path.to.field", StatsdMetricType.TIME, new JsonContentReference(new String[]{"path","field"}, JsonContentType.INTEGER), true));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
Date expected = f.parse(f.format(now));
reporter.reportTime(new StatsdMetricConfig("path.to.field", new JsonContentReference(new String[]{"prefix"}, JsonContentType.STRING), StatsdMetricType.TIME, new JsonContentReference(new String[]{"key"}, JsonContentType.TIMESTAMP, "yyyyMMdd")), new JSONObject("{\"key\":\""+f.format(now)+"\"}"));
Mockito.verify(client).recordExecutionTimeToNow("path.to.field", expected.getTime());
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
}
示例7: testExtractAndReport_withValidJSONValidConfig
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#extractAndReport(java.util.List, JSONObject)} being provided valid json and valid config
*/
@Test
public void testExtractAndReport_withValidJSONValidConfig() throws Exception{
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("timestampCalc", StatsdMetricType.TIME, new JsonContentReference(new String[]{"timecalc"}, JsonContentType.TIMESTAMP, "yyyyMMdd")));
cfg.addMetricConfig(new StatsdMetricConfig("time", StatsdMetricType.TIME, new JsonContentReference(new String[]{"time"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("gauge", StatsdMetricType.GAUGE, new JsonContentReference(new String[]{"gauge"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("diffCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"diffCounter"}, JsonContentType.INTEGER), true));
cfg.addMetricConfig(new StatsdMetricConfig("incCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"incCounter"}, JsonContentType.INTEGER), false));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
Date expected = f.parse(f.format(now));
reporter.extractAndReport(cfg.getFields(), new JSONObject("{\"timecalc\":\""+f.format(now)+"\", \"time\":123, \"gauge\":987, \"diffCounter\":231}"));
Mockito.verify(client).recordExecutionTimeToNow("timestampCalc", expected.getTime());
Mockito.verify(client).recordExecutionTime("time", Long.valueOf(123));
Mockito.verify(client).gauge("gauge", Long.valueOf(987));
Mockito.verify(client).count("diffCounter", Long.valueOf(231));
Mockito.verify(client).incrementCounter("incCounter");
}
示例8: testFilter_withNullJSON
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#filter(JSONObject)} being provided null as input
*/
@Test
public void testFilter_withNullJSON() throws Exception{
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("timestampCalc", StatsdMetricType.TIME, new JsonContentReference(new String[]{"timecalc"}, JsonContentType.TIMESTAMP, "yyyyMMdd")));
cfg.addMetricConfig(new StatsdMetricConfig("time", StatsdMetricType.TIME, new JsonContentReference(new String[]{"time"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("gauge", StatsdMetricType.GAUGE, new JsonContentReference(new String[]{"gauge"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("diffCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"diffCounter"}, JsonContentType.INTEGER), true));
cfg.addMetricConfig(new StatsdMetricConfig("incCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"incCounter"}, JsonContentType.INTEGER), false));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
reporter.filter(null);
Mockito.verify(client, Mockito.never()).recordExecutionTimeToNow(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).recordExecutionTime(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).gauge(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).count(Mockito.anyString(), Mockito.anyLong());
Mockito.verify(client, Mockito.never()).incrementCounter(Mockito.anyString());
}
示例9: testFilter_withValidJSON
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link StatsdExtractedMetricsReporter#filter(JSONObject)} being provided valid json
*/
@Test
public void testFilter_withValidJSON() throws Exception{
final StatsDClient client = Mockito.mock(StatsDClient.class);
StatsdExtractedMetricsReporterConfiguration cfg = new StatsdExtractedMetricsReporterConfiguration("host", 8125, "prefix");
cfg.addMetricConfig(new StatsdMetricConfig("timestampCalc", StatsdMetricType.TIME, new JsonContentReference(new String[]{"timecalc"}, JsonContentType.TIMESTAMP, "yyyyMMdd")));
cfg.addMetricConfig(new StatsdMetricConfig("time", StatsdMetricType.TIME, new JsonContentReference(new String[]{"time"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("gauge", StatsdMetricType.GAUGE, new JsonContentReference(new String[]{"gauge"}, JsonContentType.INTEGER)));
cfg.addMetricConfig(new StatsdMetricConfig("diffCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"diffCounter"}, JsonContentType.INTEGER), true));
cfg.addMetricConfig(new StatsdMetricConfig("incCounter", StatsdMetricType.COUNTER, new JsonContentReference(new String[]{"incCounter"}, JsonContentType.INTEGER), false));
StatsdExtractedMetricsReporter reporter = new StatsdExtractedMetricsReporter(cfg);
reporter.setStatsdClient(client);
SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
Date now = new Date();
Date expected = f.parse(f.format(now));
reporter.filter(new JSONObject("{\"timecalc\":\""+f.format(now)+"\", \"time\":123, \"gauge\":987, \"diffCounter\":231}"));
Mockito.verify(client).recordExecutionTimeToNow("timestampCalc", expected.getTime());
Mockito.verify(client).recordExecutionTime("time", Long.valueOf(123));
Mockito.verify(client).gauge("gauge", Long.valueOf(987));
Mockito.verify(client).count("diffCounter", Long.valueOf(231));
Mockito.verify(client).incrementCounter("incCounter");
}
示例10: testInvoke_withValidInputAndStatsDClientProvided
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link ElasticsearchSink#invoke(byte[])} being provided a valid array as input
*/
@Test
public void testInvoke_withValidInputAndStatsDClientProvided() throws Exception {
StatsDClient statsdClient = Mockito.mock(StatsDClient.class);
IndexResponse expected = new IndexResponse("index", "type", "id", 2, false);
final byte[] document = new byte[]{0,1,2};
IndexRequestBuilder builder2 = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder2.get()).thenReturn(expected);
IndexRequestBuilder builder = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder.setSource(document)).thenReturn(builder2);
TransportClient tc = Mockito.mock(TransportClient.class);
Mockito.when(tc.prepareIndex("index", "type")).thenReturn(builder);
ArrayList<ElasticsearchNodeAddress> transportAddresses = new ArrayList<>();
transportAddresses.add(new ElasticsearchNodeAddress("localhost", 1234));
ElasticsearchSink sink = new ElasticsearchSink("cluster", "index", "type", transportAddresses);
sink.setTransportClient(tc);
sink.setStatsDClient(statsdClient);
sink.invoke(document);
Mockito.verify(tc).prepareIndex("index", "type");
Mockito.verify(builder).setSource(document);
Mockito.verify(builder2).get();
Mockito.verify(statsdClient).incrementCounter(ElasticsearchSink.STATSD_TOTAL_DOCUMENTS_UPDATED);
Mockito.verify(statsdClient).incrementCounter(ElasticsearchSink.STATSD_TOTAL_DOCUMENTS_COUNT);
}
示例11: testInvoke_withValidInputButIndexerThrowingExceptions
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link ElasticsearchSink#invoke(byte[])} being provided valid input but
* the indexer is throwing exceptions
*/
@Test
public void testInvoke_withValidInputButIndexerThrowingExceptions() throws Exception {
StatsDClient statsdClient = Mockito.mock(StatsDClient.class);
final byte[] document = new byte[]{0,1,2};
IndexRequestBuilder builder2 = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder2.get()).thenThrow(new NullPointerException());
IndexRequestBuilder builder = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder.setSource(document)).thenReturn(builder2);
TransportClient tc = Mockito.mock(TransportClient.class);
Mockito.when(tc.prepareIndex("index", "type")).thenReturn(builder);
ArrayList<ElasticsearchNodeAddress> transportAddresses = new ArrayList<>();
transportAddresses.add(new ElasticsearchNodeAddress("localhost", 1234));
ElasticsearchSink sink = new ElasticsearchSink("cluster", "index", "type", transportAddresses);
sink.setTransportClient(tc);
sink.setStatsDClient(statsdClient);
sink.invoke(document);
Mockito.verify(tc).prepareIndex("index", "type");
Mockito.verify(builder).setSource(document);
Mockito.verify(builder2).get();
Mockito.verify(statsdClient).incrementCounter(ElasticsearchSink.STATSD_ERRORS);
Mockito.verify(statsdClient).incrementCounter(ElasticsearchSink.STATSD_TOTAL_DOCUMENTS_COUNT);
}
示例12: testInvoke_withValidInputAndNoStatsDClientProvided
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* Test case for {@link ElasticsearchSink#invoke(byte[])} being provided a valid array as input
*/
@Test
public void testInvoke_withValidInputAndNoStatsDClientProvided() throws Exception {
StatsDClient statsdClient = Mockito.mock(StatsDClient.class);
IndexResponse expected = new IndexResponse("index", "type", "id", 2, false);
final byte[] document = new byte[]{0,1,2};
IndexRequestBuilder builder2 = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder2.get()).thenReturn(expected);
IndexRequestBuilder builder = Mockito.mock(IndexRequestBuilder.class);
Mockito.when(builder.setSource(document)).thenReturn(builder2);
TransportClient tc = Mockito.mock(TransportClient.class);
Mockito.when(tc.prepareIndex("index", "type")).thenReturn(builder);
ArrayList<ElasticsearchNodeAddress> transportAddresses = new ArrayList<>();
transportAddresses.add(new ElasticsearchNodeAddress("localhost", 1234));
ElasticsearchSink sink = new ElasticsearchSink("cluster", "index", "type", transportAddresses);
sink.setTransportClient(tc);
// sink.setStatsDClient(statsdClient);
sink.invoke(document);
Mockito.verify(tc).prepareIndex("index", "type");
Mockito.verify(builder).setSource(document);
Mockito.verify(builder2).get();
Mockito.verify(statsdClient, Mockito.never()).incrementCounter(ElasticsearchSink.STATSD_TOTAL_DOCUMENTS_COUNT);
Mockito.verify(statsdClient, Mockito.never()).incrementCounter(ElasticsearchSink.STATSD_TOTAL_DOCUMENTS_UPDATED);
}
示例13: createClient
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
private StatsDClient createClient(String statsdHost, int port) {
StatsDClientErrorHandler errorHandler = new StatsDClientErrorHandler() {
@Override
public void handle(Exception exception) {
log.error("Error sending to statsd: " + ExceptionToString.format(exception));
}
};
if (statsdHost == null) {
log.fatal("Error, statsd host not set. It needs to be set in RaptureMETRICS.cfg");
return new NoOpStatsDClient();
} else {
try {
InetAddress address = InetAddress.getByName(statsdHost);
String ip = address.getHostAddress();
log.info(String.format("statsd host=%s, ip=%s", statsdHost, ip));
return createClient(ip, port, errorHandler);
} catch (UnknownHostException e) {
log.error(String.format("Error resolving statsd host ip. hostname=%s - %s", statsdHost, ExceptionToString.format(e)));
return createClient(statsdHost, port, errorHandler);
}
}
}
示例14: prepare
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
/**
* This method makes it easy to pass statsd instance during the tests
*/
public void prepare(Map<String, Object> conf, StatsDClient statsd){
topologyName = (String) Optional.fromNullable(conf.get(TOPOLOGYNAME)).or(getRequiredValue(conf, "topology.name"));
if (statsd == null) {
String statsdHost = (String) Optional.fromNullable(conf.get(HOST)).or("localhost");
Integer port = (Integer) Optional.fromNullable(conf.get(PORT)).or(8125);
String[] globalTags = (String[]) Optional.fromNullable(conf.get(TAGS)).or(new String[0]);
logger.info("Initializing the datadog statsd client for {} with value {}:{} {}", topologyName, statsdHost, port, globalTags);
this.statsd = new NonBlockingStatsDClient(
TagsHelper.getPrefix(conf),
statsdHost,
port,
globalTags
);
}
else {
this.statsd = statsd;
}
}
示例15: testRun
import com.timgroup.statsd.StatsDClient; //导入依赖的package包/类
@Test
public void testRun() throws InterruptedException {
StatsDClient mockStatsdClient = createNiceMock(StatsDClient.class);
mockStatsdClient.gauge("foo", 1);
mockStatsdClient.gauge("foo", 1);
mockStatsdClient.gauge("foo", 1);
replay(mockStatsdClient);
LivenessReporter reporter = new LivenessReporter(mockStatsdClient, "foo", 1);
Thread reporterThread = new Thread(reporter);
reporterThread.start();
Thread.sleep(3000);
reporter.stop();
verify(mockStatsdClient);
}