Java Code Examples for org.apache.hadoop.util.FakeTimer

The following examples show how to use org.apache.hadoop.util.FakeTimer. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hadoop-ozone   Source File: TestHddsVolumeChecker.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Test {@link HddsVolumeChecker#checkAllVolumes} propagates
 * checks for all volumes to the delegate checker.
 *
 * @throws Exception
 */
@Test
public void testCheckAllVolumes() throws Exception {
  LOG.info("Executing {}", testName.getMethodName());

  final List<HddsVolume> volumes = makeVolumes(
      NUM_VOLUMES, expectedVolumeHealth);
  final HddsVolumeChecker checker =
      new HddsVolumeChecker(new OzoneConfiguration(), new FakeTimer());
  checker.setDelegateChecker(new DummyChecker());

  Set<HddsVolume> failedVolumes = checker.checkAllVolumes(volumes);
  LOG.info("Got back {} failed volumes", failedVolumes.size());

  if (expectedVolumeHealth == null || expectedVolumeHealth == FAILED) {
    assertThat(failedVolumes.size(), is(NUM_VOLUMES));
  } else {
    assertTrue(failedVolumes.isEmpty());
  }

  // Ensure each volume's check() method was called exactly once.
  for (HddsVolume volume : volumes) {
    verify(volume, times(1)).check(anyObject());
  }
}
 
Example 2
Source Project: hadoop   Source File: TestGroupsCaching.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheEntriesExpire() throws Exception {
  conf.setLong(
    CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS, 1);
  FakeTimer timer = new FakeTimer();
  final Groups groups = new Groups(conf, timer);
  groups.cacheGroupsAdd(Arrays.asList(myGroups));
  groups.refresh();
  FakeGroupMapping.clearBlackList();

  // We make an entry
  groups.getGroups("me");
  int startingRequestCount = FakeGroupMapping.getRequestCount();

  timer.advance(20 * 1000);

  // Cache entry has expired so it results in a new fetch
  groups.getGroups("me");
  assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
}
 
Example 3
Source Project: big-c   Source File: TestGroupsCaching.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCacheEntriesExpire() throws Exception {
  conf.setLong(
    CommonConfigurationKeys.HADOOP_SECURITY_GROUPS_CACHE_SECS, 1);
  FakeTimer timer = new FakeTimer();
  final Groups groups = new Groups(conf, timer);
  groups.cacheGroupsAdd(Arrays.asList(myGroups));
  groups.refresh();
  FakeGroupMapping.clearBlackList();

  // We make an entry
  groups.getGroups("me");
  int startingRequestCount = FakeGroupMapping.getRequestCount();

  timer.advance(20 * 1000);

  // Cache entry has expired so it results in a new fetch
  groups.getGroups("me");
  assertEquals(startingRequestCount + 1, FakeGroupMapping.getRequestCount());
}
 
Example 4
Source Project: hadoop-ozone   Source File: TestHddsVolumeChecker.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test {@link HddsVolumeChecker#checkVolume} propagates the
 * check to the delegate checker.
 *
 * @throws Exception
 */
@Test
public void testCheckOneVolume() throws Exception {
  LOG.info("Executing {}", testName.getMethodName());
  final HddsVolume volume = makeVolumes(1, expectedVolumeHealth).get(0);
  final HddsVolumeChecker checker =
      new HddsVolumeChecker(new OzoneConfiguration(), new FakeTimer());
  checker.setDelegateChecker(new DummyChecker());
  final AtomicLong numCallbackInvocations = new AtomicLong(0);

  /**
   * Request a check and ensure it triggered {@link HddsVolume#check}.
   */
  boolean result =
      checker.checkVolume(volume, (healthyVolumes, failedVolumes) -> {
        numCallbackInvocations.incrementAndGet();
        if (expectedVolumeHealth != null &&
            expectedVolumeHealth != FAILED) {
          assertThat(healthyVolumes.size(), is(1));
          assertThat(failedVolumes.size(), is(0));
        } else {
          assertThat(healthyVolumes.size(), is(0));
          assertThat(failedVolumes.size(), is(1));
        }
      });

  GenericTestUtils.waitFor(() -> numCallbackInvocations.get() > 0, 5, 10000);

  // Ensure that the check was invoked at least once.
  verify(volume, times(1)).check(anyObject());
  if (result) {
    assertThat(numCallbackInvocations.get(), is(1L));
  }
}