本文整理汇总了Java中com.twitter.hbc.core.StatsReporter.getStatsTracker方法的典型用法代码示例。如果您正苦于以下问题:Java StatsReporter.getStatsTracker方法的具体用法?Java StatsReporter.getStatsTracker怎么用?Java StatsReporter.getStatsTracker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twitter.hbc.core.StatsReporter
的用法示例。
在下文中一共展示了StatsReporter.getStatsTracker方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run_should_create_and_start_metrics_reporter
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void run_should_create_and_start_metrics_reporter() {
HosebirdReader tr = mock(HosebirdReader.class);
when(tr.parseConfigFile(anyString())).thenReturn(this.config);
Metrics metrics = mock(Metrics.class);
when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenReturn(metrics);
Client client = mock(Client.class);
when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenReturn(client);
tr.setLogger(this.logger);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
String[] args = {"FILE"};
tr.run(args);
verify(metrics).createAndStartStatsDReporter(any(MetricRegistry.class), eq("G_HOST"), eq(1111), eq("G_PREFIX"), eq(2));
}
示例2: readAndSend_should_log_if_taking_from_the_buffer_throws
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void readAndSend_should_log_if_taking_from_the_buffer_throws() {
try {
reset(this.logger);
Producer<String, String> producer = mock(Producer.class);
HosebirdReader tr = mock(ConcreteHosebirdReader.class);
tr.setLogger(this.logger);
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue<String> buffer = mock(LinkedBlockingQueue.class);
when(buffer.take()).thenThrow(new InterruptedException("ERROR"));
when(tr.getBufferQueue(anyInt())).thenReturn(buffer);
ReadAndSendPredicate readAndSendPredicate = mock(ReadAndSendPredicate.class);
when(readAndSendPredicate.process()).thenReturn(true).thenReturn(false);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.readAndSend(buffer, "TOPIC", producer, readAndSendPredicate);
verify(this.logger).error("Error reading from buffer queue: {}", "ERROR");
} catch(Exception e) {
assert(false);
}
}
示例3: should_add_metric_when_message_is_read_from_buffer
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void should_add_metric_when_message_is_read_from_buffer() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
Meter meter = mock(Meter.class);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.read = meter;
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue<String> buffer = new LinkedBlockingQueue<>(2);
buffer.add("1");
Producer producer = mock(KafkaProducer.class);
ReadAndSendPredicate predicate = mock(ReadAndSendPredicate.class);
when(predicate.process()).thenReturn(true).thenReturn(false);
tr.readAndSend(buffer, "TOPIC", producer, predicate);
verify(meter).mark();
}
示例4: should_add_metric_when_message_is_sent_to_kafka
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void should_add_metric_when_message_is_sent_to_kafka() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
Meter meter = mock(Meter.class);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.read = mock(Meter.class);
tr.metrics.sent = meter;
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue<String> buffer = new LinkedBlockingQueue<>(2);
buffer.add("1");
Producer producer = mock(KafkaProducer.class);
ReadAndSendPredicate predicate = mock(ReadAndSendPredicate.class);
when(predicate.process()).thenReturn(true).thenReturn(false);
tr.readAndSend(buffer, "TOPIC", producer, predicate);
ArgumentCaptor<Callback> c = ArgumentCaptor.forClass(Callback.class);
verify(producer, times(1)).send(any(ProducerRecord.class), c.capture());
c.getValue().onCompletion(null, null);
verify(meter).mark();
}
示例5: should_add_metric_when_errors_sending_message_to_kafka
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void should_add_metric_when_errors_sending_message_to_kafka() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
Meter meter = mock(Meter.class);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.read = mock(Meter.class);
tr.metrics.sent = mock(Meter.class);
tr.metrics.sendError = meter;
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue<String> buffer = new LinkedBlockingQueue<>(2);
buffer.add("1");
Producer producer = mock(KafkaProducer.class);
ReadAndSendPredicate predicate = mock(ReadAndSendPredicate.class);
when(predicate.process()).thenReturn(true).thenReturn(false);
tr.readAndSend(buffer, "TOPIC", producer, predicate);
ArgumentCaptor<Callback> c = ArgumentCaptor.forClass(Callback.class);
verify(producer, times(1)).send(any(ProducerRecord.class), c.capture());
c.getValue().onCompletion(null, new Exception("ERROR"));
verify(meter).mark();
}
示例6: should_add_metric_when_read_from_buffer_errors
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void should_add_metric_when_read_from_buffer_errors() {
try {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
Meter meter = mock(Meter.class);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.readError = meter;
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue<String> buffer = mock(LinkedBlockingQueue.class);
when(buffer.take()).thenThrow(new InterruptedException("ERROR"));
Producer producer = mock(KafkaProducer.class);
ReadAndSendPredicate predicate = mock(ReadAndSendPredicate.class);
when(predicate.process()).thenReturn(true).thenReturn(false);
tr.readAndSend(buffer, "TOPIC", producer, predicate);
verify(meter).mark();
} catch(Exception e) {
assertNull(e);
}
}
示例7: should_create_gauges_for_gnip_client_stats
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
public void should_create_gauges_for_gnip_client_stats() {
StatsReporter stats = new StatsReporter();
stats.incrNum200s();
stats.incrNum400s();
stats.incrNum500s();
stats.incrNumMessages();
stats.incrNumDisconnects();
stats.incrNumConnects();
stats.incrNumConnectionFailures();
stats.incrNumClientEventsDropped();
stats.incrNumMessagesDropped();
Metrics m = new Metrics(stats.getStatsTracker());
assertEquals(1, m.num200s.getValue().intValue());
assertEquals(1, m.num400s.getValue().intValue());
assertEquals(1, m.num500s.getValue().intValue());
assertEquals(1, m.messages.getValue().longValue());
assertEquals(1, m.disconnects.getValue().intValue());
assertEquals(1, m.connections.getValue().intValue());
assertEquals(1, m.connectionFailures.getValue().intValue());
assertEquals(1, m.clientEventsDropped.getValue().longValue());
assertEquals(1, m.messagesDropped.getValue().longValue());
}
示例8: testStatsReporter
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
public void testStatsReporter() {
StatsReporter statsReporter = new StatsReporter();
StatsReporter.StatsTracker stats = statsReporter.getStatsTracker();
assertEquals(stats.getNum200s(), 0);
statsReporter.incrNum200s();
statsReporter.incrNum200s();
statsReporter.incrNum200s();
assertEquals(stats.getNum200s(), 3);
assertEquals(stats.getNumMessages(), 0);
statsReporter.incrNumMessages();
statsReporter.incrNumMessages();
assertEquals(stats.getNumMessages(), 2);
}
示例9: shutdownhook_should_send_all_messages_in_buffer_to_kafka
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shutdownhook_should_send_all_messages_in_buffer_to_kafka() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.shutdown = mock(Meter.class);
tr.metrics.read = mock(Meter.class);
doCallRealMethod().when(tr).addShutdownHook(any(Client.class), any(LinkedBlockingQueue.class), anyString(), any(Producer.class));
doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue buffer = new LinkedBlockingQueue(5);
buffer.add("1");
buffer.add("2");
buffer.add("3");
buffer.add("4");
buffer.add("5");
KafkaProducer<String, String> producer = mock(KafkaProducer.class);
tr.addShutdownHook(client, buffer, "TOPIC", producer);
ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
verify(tr).runtimeAddShutdownHook(threadCaptor.capture());
Thread thread = threadCaptor.getValue();
thread.run();
try {
thread.join();
} catch(Exception e) {
assertNull(e);
}
assertEquals(0, buffer.size());
verify(producer, times(5)).send(any(ProducerRecord.class), any(Callback.class));
verify(client).stop();
}
示例10: shutdownhook_should_end_if_exception_thrown
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shutdownhook_should_end_if_exception_thrown() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.shutdown = mock(Meter.class);
doCallRealMethod().when(tr).addShutdownHook(any(Client.class), any(LinkedBlockingQueue.class), anyString(), any(Producer.class));
doThrow(new RuntimeException("ERROR")).when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
LinkedBlockingQueue buffer = new LinkedBlockingQueue(1);
buffer.add("1");
KafkaProducer<String, String> producer = mock(KafkaProducer.class);
tr.addShutdownHook(client, buffer, "TOPIC", producer);
ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
verify(tr).runtimeAddShutdownHook(threadCaptor.capture());
Thread thread = threadCaptor.getValue();
try {
thread.run();
} catch(Exception e) {
assertEquals("ERROR", e.getMessage());
}
verify(producer, times(0)).send(any(ProducerRecord.class), any(Callback.class));
assertEquals(1, buffer.size());
}
示例11: shutdownhook_should_set_retry_to_false
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shutdownhook_should_set_retry_to_false() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.shutdown = mock(Meter.class);
doCallRealMethod().when(tr).addShutdownHook(any(Client.class), any(LinkedBlockingQueue.class), anyString(), any(Producer.class));
LinkedBlockingQueue buffer = new LinkedBlockingQueue(1);
buffer.add("1");
KafkaProducer<String, String> producer = mock(KafkaProducer.class);
tr.addShutdownHook(client, buffer, "TOPIC", producer);
ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
verify(tr).runtimeAddShutdownHook(threadCaptor.capture());
Thread thread = threadCaptor.getValue();
thread.run();
try {
thread.join();
} catch(Exception e) {
assertNull(e);
}
verify(tr).setRetry(false);
}
示例12: shutdownhook_should_close_kafka_producer
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shutdownhook_should_close_kafka_producer() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.shutdown = mock(Meter.class);
doCallRealMethod().when(tr).addShutdownHook(any(Client.class), any(LinkedBlockingQueue.class), anyString(), any(Producer.class));
LinkedBlockingQueue buffer = new LinkedBlockingQueue(1);
buffer.add("1");
KafkaProducer<String, String> producer = mock(KafkaProducer.class);
tr.addShutdownHook(client, buffer, "TOPIC", producer);
ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
verify(tr).runtimeAddShutdownHook(threadCaptor.capture());
Thread thread = threadCaptor.getValue();
thread.run();
try {
thread.join();
} catch(Exception e) {
assertNull(e);
}
verify(producer).close();
}
示例13: shutdownhook_should_mark_metric
import com.twitter.hbc.core.StatsReporter; //导入方法依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void shutdownhook_should_mark_metric() {
HosebirdReader tr = mock(HosebirdReader.class);
tr.setLogger(this.logger);
Meter meter = mock(Meter.class);
StatsReporter stats = new StatsReporter();
tr.metrics = new Metrics(stats.getStatsTracker());
tr.metrics.shutdown = meter;
doCallRealMethod().when(tr).addShutdownHook(any(Client.class), any(LinkedBlockingQueue.class), anyString(), any(Producer.class));
LinkedBlockingQueue buffer = new LinkedBlockingQueue(1);
buffer.add("1");
KafkaProducer<String, String> producer = mock(KafkaProducer.class);
tr.addShutdownHook(client, buffer, "TOPIC", producer);
ArgumentCaptor<Thread> threadCaptor = ArgumentCaptor.forClass(Thread.class);
verify(tr).runtimeAddShutdownHook(threadCaptor.capture());
Thread thread = threadCaptor.getValue();
thread.run();
try {
thread.join();
} catch(Exception e) {
assertNull(e);
}
verify(meter).mark();
}