@Test
public void testDisableFetchNodeAttributes() 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 -1 to disable refresh.
  conf.setLong(
      YarnConfiguration.NM_NODE_ATTRIBUTES_PROVIDER_FETCH_INTERVAL_MS, -1);
  ConfigurationNodeAttributesProvider spyProvider =
      Mockito.spy(nodeAttributesProvider);
  Mockito.when(spyProvider.parseAttributes(Mockito.any()))
      .thenReturn(expectedAttributes1);
  spyProvider.init(conf);
  spyProvider.start();
  Assert.assertEquals(expectedAttributes1,
      spyProvider.getDescriptors());
  // The configuration added another attribute,
  // as we disabled the fetch interval, this value cannot be
  // updated to the provider.
  Set<NodeAttribute> expectedAttributes2 = new HashSet<>();
  expectedAttributes2.add(NodeAttribute
      .newInstance("test.io", "os",
          NodeAttributeType.STRING, "windows"));
  Mockito.when(spyProvider.parseAttributes(Mockito.anyString()))
      .thenReturn(expectedAttributes2);
  // Wait a few seconds until we get the value update, expecting a failure.
  try {
    GenericTestUtils.waitFor(() -> {
      Set<NodeAttribute> attributes = spyProvider.getDescriptors();
      return "os".equalsIgnoreCase(attributes
          .iterator().next().getAttributeKey().getAttributeName());
    }, 500, 1000);
  } catch (Exception e) {
    // Make sure we get the timeout exception.
    Assert.assertTrue(e instanceof TimeoutException);
    return;
  }
  Assert.fail("Expecting a failure in previous check!");
}