@Test(timeout=30000L)
public void testNodeAttributesFetchInterval()
    throws IOException, InterruptedException {

  Set<NodeAttribute> expectedAttributes1 = new HashSet<>();
  expectedAttributes1.add(NodeAttribute
      .newInstance("test.io", "host",
          NodeAttributeType.STRING, "host1"));
  Configuration conf = new Configuration();
  // Set fetch interval to 1s for testing
  conf.setLong(
      YarnConfiguration.NM_NODE_ATTRIBUTES_PROVIDER_FETCH_INTERVAL_MS, 1000);
  ConfigurationNodeAttributesProvider spyProvider =
      Mockito.spy(nodeAttributesProvider);
  Mockito.when(spyProvider.parseAttributes(Mockito.any()))
      .thenReturn(expectedAttributes1);
  spyProvider.init(conf);
  spyProvider.start();
  // Verify init value is honored.
  Assert.assertEquals(expectedAttributes1, spyProvider.getDescriptors());
  // Configuration provider provides a different set of attributes.
  Set<NodeAttribute> expectedAttributes2 = new HashSet<>();
  expectedAttributes2.add(NodeAttribute
      .newInstance("test.io", "os",
          NodeAttributeType.STRING, "windows"));
  Mockito.when(spyProvider.parseAttributes(Mockito.any()))
      .thenReturn(expectedAttributes2);
  // Since we set fetch interval to 1s, it needs to wait for 1s until
  // the updated attributes is updated to the provider. So we are expecting
  // to see some old values for a short window.
  ArrayList<String> keysMet = new ArrayList<>();
  int numOfOldValue = 0;
  int numOfNewValue = 0;
  // Run 5 times in 500ms interval
  int times=5;
  while(times>0) {
    Set<NodeAttribute> current = spyProvider.getDescriptors();
    Assert.assertEquals(1, current.size());
    String attributeName =
        current.iterator().next().getAttributeKey().getAttributeName();
    if ("host".equals(attributeName)){
      numOfOldValue++;
    } else if ("os".equals(attributeName)) {
      numOfNewValue++;
    }
    Thread.sleep(500);
    times--;
  }
  // We should either see the old value or the new value.
  Assert.assertEquals(5, numOfNewValue + numOfOldValue);
  // Both values should be more than 0.
  Assert.assertTrue(numOfOldValue > 0);
  Assert.assertTrue(numOfNewValue > 0);
}