public static void event(Call call, String event, Object data) {
    if (call == null) {
      Log.i(TAG, "Non-call EVENT: %s, %s", event, data);
      return;
    }
    synchronized (mCallEventRecords) {
      if (!mCallEventRecordMap.containsKey(call)) {
        // First remove the oldest entry if no new ones exist.
        if (mCallEventRecords.remainingCapacity() == 0) {
          CallEventRecord record = mCallEventRecords.poll();
          if (record != null) {
            mCallEventRecordMap.remove(record.getCall());
          }
        }

        // Now add a new entry
        CallEventRecord newRecord = new CallEventRecord(call);
        mCallEventRecords.add(newRecord);
        mCallEventRecordMap.put(call, newRecord);
      }

      CallEventRecord record = mCallEventRecordMap.get(call);
      record.addEvent(event, data);
    }
  }
  @Test
  public void testLocalStreamFileMoved() throws Exception {
    CollectorReaderStatsExposer prMetrics =
        new CollectorReaderStatsExposer(
            testStream, "c1", partitionId.toString(), consumerNumber, fsUri);
    preader =
        new PartitionReader(
            partitionId,
            null,
            conf,
            fs,
            collectorDir,
            streamsLocalDir,
            buffer,
            testStream,
            CollectorStreamReader.getDateFromCollectorFile(files[0]),
            1000,
            1000,
            prMetrics,
            null);

    Assert.assertEquals(preader.getReader().getClass().getName(), CollectorReader.class.getName());
    preader.init();
    Assert.assertTrue(buffer.isEmpty());
    Assert.assertEquals(
        ((CollectorReader) preader.getReader()).getReader().getClass().getName(),
        LocalStreamCollectorReader.class.getName());

    preader.start(null);
    while (buffer.remainingCapacity() > 0) {
      Thread.sleep(10);
    }
    fs.delete(databusFiles[0], true);
    fs.delete(databusFiles[1], true);
    fs.delete(databusFiles[2], true);
    databusFiles[4] =
        TestUtil.moveFileToStreamLocal(
            fs, testStream, collectorName, cluster, collectorDir, files[4]);
    databusFiles[5] =
        TestUtil.moveFileToStreamLocal(
            fs, testStream, collectorName, cluster, collectorDir, files[5]);

    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[0]),
        1,
        0,
        100,
        partitionId,
        buffer,
        true,
        null);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[1]),
        2,
        0,
        50,
        partitionId,
        buffer,
        true,
        null);

    while (buffer.remainingCapacity() > 0) {
      Thread.sleep(10);
    }
    Assert.assertEquals(
        ((CollectorReader) preader.getReader()).getReader().getClass().getName(),
        LocalStreamCollectorReader.class.getName());
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[1]),
        2,
        50,
        50,
        partitionId,
        buffer,
        true,
        null);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[3]),
        4,
        0,
        100,
        partitionId,
        buffer,
        true,
        null);

    while (buffer.remainingCapacity() > 0) {
      Thread.sleep(10);
    }
    Assert.assertEquals(
        ((CollectorReader) preader.getReader()).getReader().getClass().getName(),
        LocalStreamCollectorReader.class.getName());
    fs.delete(databusFiles[3], true);
    fs.delete(databusFiles[4], true);
    fs.delete(databusFiles[5], true);
    databusFiles[6] =
        TestUtil.copyFileToStreamLocal(
            fs, testStream, collectorName, cluster, collectorDir, files[6]);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[4]),
        5,
        0,
        100,
        partitionId,
        buffer,
        true,
        null);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[5]),
        6,
        0,
        50,
        partitionId,
        buffer,
        true,
        null);
    Assert.assertEquals(
        ((CollectorReader) preader.getReader()).getReader().getClass().getName(),
        LocalStreamCollectorReader.class.getName());
    while (buffer.remainingCapacity() > 0) {
      Thread.sleep(10);
    }
    fs.delete(databusFiles[6], true);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[5]),
        6,
        50,
        50,
        partitionId,
        buffer,
        true,
        null);
    TestUtil.assertBuffer(
        LocalStreamCollectorReader.getDatabusStreamFile(collectorName, files[6]),
        7,
        0,
        100,
        partitionId,
        buffer,
        true,
        null);
    TestUtil.assertBuffer(
        CollectorStreamReader.getCollectorFile(files[7]),
        8,
        0,
        100,
        partitionId,
        buffer,
        true,
        null);
    Assert.assertEquals(
        ((CollectorReader) preader.getReader()).getReader().getClass().getName(),
        CollectorStreamReader.class.getName());
    Assert.assertTrue(buffer.isEmpty());
    preader.close();
    preader.join();
    Assert.assertEquals(prMetrics.getHandledExceptions(), 0);
    Assert.assertEquals(prMetrics.getMessagesReadFromSource(), 700);
    Assert.assertEquals(prMetrics.getMessagesAddedToBuffer(), 700);
    Assert.assertEquals(prMetrics.getWaitTimeUnitsNewFile(), 0);
    Assert.assertEquals(prMetrics.getWaitTimeInSameFile(), 0);
    Assert.assertEquals(prMetrics.getSwitchesFromCollectorToLocal(), 0);
    Assert.assertEquals(prMetrics.getSwitchesFromLocalToCollector(), 1);
    Assert.assertTrue(prMetrics.getCumulativeNanosForFetchMessage() > 0);
    Assert.assertEquals(
        prMetrics.getLatestMinuteAlreadyRead(),
        CollectorStreamReader.getDateFromCollectorFile(files[6]).getTime());
  }
 @Override
 public int remainingCapacity() {
   return queue.remainingCapacity();
 }