当前位置: 首页>>代码示例>>Java>>正文


Java StatsReporter类代码示例

本文整理汇总了Java中com.twitter.hbc.core.StatsReporter的典型用法代码示例。如果您正苦于以下问题:Java StatsReporter类的具体用法?Java StatsReporter怎么用?Java StatsReporter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


StatsReporter类属于com.twitter.hbc.core包,在下文中一共展示了StatsReporter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:18,代码来源:TestHosebirdReader.java

示例2: run_should_create_client_and_connect

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void run_should_create_client_and_connect() {
    Producer<String, String> producer = mock(Producer.class);
    HosebirdReader tr = mock(ConcreteHosebirdReader.class);
    reset(this.logger);
    tr.setLogger(this.logger);
    when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
    when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenCallRealMethod();
    when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
    when(tr.getClientBuilder()).thenReturn(this.cb);
    when(tr.parseConfigFile(anyString())).thenReturn(config);
    when(tr.getRetry()).thenReturn(true).thenReturn(false);

    when(client.isDone()).thenReturn(true);
    LinkedBlockingQueue<String> lbq = new LinkedBlockingQueue<>(10);
    String[] args = {"1"};
    tr.run(args);

    verify(client).connect();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:22,代码来源:TestHosebirdReader.java

示例3: run_should_take_from_buffer_until_client_is_done

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void run_should_take_from_buffer_until_client_is_done() {
    Producer<String, String> producer = mock(Producer.class);
    HosebirdReader tr = mock(ConcreteHosebirdReader.class);
    reset(this.logger);
    tr.setLogger(this.logger);
    when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
    when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenCallRealMethod();
    when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
    when(tr.getClientBuilder()).thenReturn(this.cb);
    doCallRealMethod().when(tr).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
    LinkedBlockingQueue<String> buffer = new LinkedBlockingQueue<>(2);
    buffer.add("1");
    buffer.add("2");
    when(tr.getBufferQueue(anyInt())).thenReturn(buffer);
    when(tr.parseConfigFile(anyString())).thenReturn(config);
    when(client.isDone()).thenReturn(false, false, true);
    when(tr.getRetry()).thenReturn(true).thenReturn(false);

    String[] args = {"1"};
    tr.run(args);

    assertEquals(0, buffer.size());
    verify(client, times(3)).isDone();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:27,代码来源:TestHosebirdReader.java

示例4: 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);
    }
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:27,代码来源:TestHosebirdReader.java

示例5: run_should_retry_if_readandsend_ends

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void run_should_retry_if_readandsend_ends() {
    HosebirdReader tr = mock(HosebirdReader.class);
    tr.setLogger(this.logger);
    when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
    when(tr.parseConfigFile(anyString())).thenReturn(config);
    Client client = mock(Client.class);
    when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenReturn(client);
    Producer<String, String> producer = mock(Producer.class);
    when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
    when(tr.getRetry()).thenReturn(true).thenReturn(true).thenReturn(false);

    String[] args = {"1"};
    tr.run(args);

    verify(tr, times(2)).readAndSend(any(LinkedBlockingQueue.class), anyString(), any(Producer.class), any(ReadAndSendPredicate.class));
    verify(tr, times(2)).logClientExitReason(any(Client.class));
    verify(client, times(2)).connect();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:21,代码来源:TestHosebirdReader.java

示例6: run_should_mark_metric_if_readandsend_ends

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void run_should_mark_metric_if_readandsend_ends() {
    HosebirdReader tr = mock(HosebirdReader.class);
    tr.setLogger(this.logger);
    when(tr.parseConfigFile(anyString())).thenReturn(config);
    when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
    Client client = mock(Client.class);
    when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenReturn(client);
    Producer<String, String> producer = mock(Producer.class);
    when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
    when(tr.getRetry()).thenReturn(true).thenReturn(true).thenReturn(false);

    String[] args = {"1"};
    tr.run(args);

    assertEquals(2, tr.metrics.disconnected.getCount());
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:19,代码来源:TestHosebirdReader.java

示例7: 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();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:21,代码来源:TestHosebirdReader.java

示例8: 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();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:26,代码来源:TestHosebirdReader.java

示例9: 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();
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:27,代码来源:TestHosebirdReader.java

示例10: 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);
    }
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:25,代码来源:TestHosebirdReader.java

示例11: 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());
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:25,代码来源:TestHosebirdReader.java

示例12: ClientBase

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth,
           HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker,
           @Nullable BlockingQueue<Event> eventsQueue) {
    this.client = Preconditions.checkNotNull(client);
    this.name = Preconditions.checkNotNull(name);

    this.endpoint = Preconditions.checkNotNull(endpoint);
    this.hosts = Preconditions.checkNotNull(hosts);
    this.auth = Preconditions.checkNotNull(auth);

    this.processor = Preconditions.checkNotNull(processor);
    this.reconnectionManager = Preconditions.checkNotNull(manager);
    this.rateTracker = Preconditions.checkNotNull(rateTracker);

    this.eventsQueue = eventsQueue;

    this.exitEvent = new AtomicReference<Event>();

    this.isRunning = new CountDownLatch(1);
    this.statsReporter = new StatsReporter();

    this.connectionEstablished = new AtomicBoolean(false);
    this.reconnect = new AtomicBoolean(false);
}
 
开发者ID:LaurentTardif,项目名称:AgileGrenoble2015,代码行数:25,代码来源:ClientBase.java

示例13: ClientBase

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth,
           HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker,
           @Nullable BlockingQueue<Event> eventsQueue) {
  this.client = Preconditions.checkNotNull(client);
  this.name = Preconditions.checkNotNull(name);

  this.endpoint = Preconditions.checkNotNull(endpoint);
  this.hosts = Preconditions.checkNotNull(hosts);
  this.auth = Preconditions.checkNotNull(auth);

  this.processor = Preconditions.checkNotNull(processor);
  this.reconnectionManager = Preconditions.checkNotNull(manager);
  this.rateTracker = Preconditions.checkNotNull(rateTracker);

  this.eventsQueue = eventsQueue;

  this.exitEvent = new AtomicReference<Event>();

  this.isRunning = new CountDownLatch(1);
  this.statsReporter = new StatsReporter();

  this.connectionEstablished = new AtomicBoolean(false);
  this.reconnect = new AtomicBoolean(false);
}
 
开发者ID:twitter,项目名称:hbc,代码行数:25,代码来源:ClientBase.java

示例14: 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);
}
 
开发者ID:twitter,项目名称:hbc,代码行数:17,代码来源:StatsReporterTest.java

示例15: getHosebirdCient_should_create_client_correctly

import com.twitter.hbc.core.StatsReporter; //导入依赖的package包/类
@Test
@SuppressWarnings("unchecked")
public void getHosebirdCient_should_create_client_correctly() {
    Producer<String, String> producer = mock(Producer.class);
    TwitterApiReader tr = mock(TwitterApiReader.class);
    reset(this.logger);
    tr.setLogger(this.logger);
    when(tr.getMetrics(any(StatsReporter.StatsTracker.class))).thenCallRealMethod();
    when(tr.getHosebirdClient(any(LinkedBlockingQueue.class), any(Config.class))).thenCallRealMethod();
    when(tr.getKafkaProducer(any(KafkaConfig.class))).thenReturn(producer);
    when(tr.getClientBuilder()).thenReturn(this.cb);
    when(tr.parseConfigFile(anyString())).thenReturn(config);
    when(tr.getRetry()).thenReturn(true).thenReturn(false);

    when(client.isDone()).thenReturn(true);
    LinkedBlockingQueue<String> lbq = new LinkedBlockingQueue<>(10);
    tr.getHosebirdClient(lbq, config);
    verify(cb).name("Twitter Api Reader");
    verify(cb).hosts(Constants.STREAM_HOST);

    ArgumentCaptor<StreamingEndpoint> se = ArgumentCaptor.forClass(StreamingEndpoint.class);
    verify(cb).endpoint(se.capture());
    assertEquals("/1.1/statuses/filter.json?delimited=length&stall_warnings=true", se.getValue().getURI());

    // Unfortunately there's not a good way of asserting that the Authentication and Processor have
    // been created with the correct parameters.

    verify(cb).retries(10);
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:30,代码来源:TestTwitterApiReader.java


注:本文中的com.twitter.hbc.core.StatsReporter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。