public TimelineWriteResponse putDomain(TimelineDomain domain,
      UserGroupInformation callerUgi) throws IOException {
    LOG.debug("putDomain(domain={}, callerUgi={})", domain, callerUgi);

    TimelineWriteResponse response = null;
    try {
      boolean isStorageUp = checkRetryWithSleep();
      if (isStorageUp) {
        synchronized (writer) {
          final TimelineCollectorContext context = getTimelineEntityContext();
          response = writer.write(context, domain);
          flushBufferedTimelineEntities();
        }
      } else {
        String msg = String.format("Failed to putDomain(" +
            "domain=%s, callerUgi=%s) as Timeline Storage is Down",
            domain, callerUgi);
        throw new IOException(msg);
      }
    } catch (InterruptedException ex) {
      String msg = String.format("Interrupted while retrying to putDomain(" +
          "domain=%s, callerUgi=%s)", domain, callerUgi);
      throw new IOException(msg);
    }

    return response;
  }
@Test
  void testPutDomain() throws IOException {
    TimelineWriter writer = mock(TimelineWriter.class);
    TimelineHealth timelineHealth = new TimelineHealth(TimelineHealth.
        TimelineHealthStatus.RUNNING, "");
    when(writer.getHealthStatus()).thenReturn(timelineHealth);

    Configuration conf = new Configuration();
    conf.setInt(YarnConfiguration.TIMELINE_SERVICE_CLIENT_MAX_RETRIES, 5);
    conf.setLong(YarnConfiguration.TIMELINE_SERVICE_CLIENT_RETRY_INTERVAL_MS,
        500L);

    TimelineCollector collector = new TimelineCollectorForTest(writer);
    collector.init(conf);

    TimelineDomain domain =
        generateDomain("id", "desc", "owner", "reader1,reader2", "writer", 0L,
            1L);
    collector.putDomain(domain, UserGroupInformation.createRemoteUser("owner"));

    verify(writer, times(1))
        .write(any(TimelineCollectorContext.class), any(TimelineDomain.class));
    verify(writer, times(1)).flush();
  }