Search in sources :

Example 21 with FakeTimer

use of org.apache.hadoop.util.FakeTimer in project hadoop by apache.

the class TestDatasetVolumeCheckerFailures method testTimeout.

/**
   * Test timeout in {@link DatasetVolumeChecker#checkAllVolumes}.
   * @throws Exception
   */
@Test(timeout = 60000)
public void testTimeout() throws Exception {
    // Add a volume whose check routine hangs forever.
    final List<FsVolumeSpi> volumes = Collections.singletonList(makeHungVolume());
    final FsDatasetSpi<FsVolumeSpi> dataset = TestDatasetVolumeChecker.makeDataset(volumes);
    // Create a disk checker with a very low timeout.
    conf.setTimeDuration(DFSConfigKeys.DFS_DATANODE_DISK_CHECK_TIMEOUT_KEY, 1, TimeUnit.SECONDS);
    final DatasetVolumeChecker checker = new DatasetVolumeChecker(conf, new FakeTimer());
    // Ensure that the hung volume is detected as failed.
    Set<FsVolumeSpi> failedVolumes = checker.checkAllVolumes(dataset);
    assertThat(failedVolumes.size(), is(1));
}
Also used : FakeTimer(org.apache.hadoop.util.FakeTimer) Test(org.junit.Test)

Example 22 with FakeTimer

use of org.apache.hadoop.util.FakeTimer in project hadoop by apache.

the class TestDatasetVolumeCheckerFailures method commonInit.

@Before
public void commonInit() {
    timer = new FakeTimer();
    conf = new HdfsConfiguration();
    conf.setTimeDuration(DFSConfigKeys.DFS_DATANODE_DISK_CHECK_MIN_GAP_KEY, MIN_DISK_CHECK_GAP_MS, TimeUnit.MILLISECONDS);
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) FakeTimer(org.apache.hadoop.util.FakeTimer) Before(org.junit.Before)

Example 23 with FakeTimer

use of org.apache.hadoop.util.FakeTimer in project hadoop by apache.

the class TestDatasetVolumeCheckerTimeout method testDiskCheckTimeout.

@Test(timeout = 1000)
public void testDiskCheckTimeout() throws Exception {
    LOG.info("Executing {}", testName.getMethodName());
    final FsVolumeSpi volume = makeSlowVolume();
    final DatasetVolumeChecker checker = new DatasetVolumeChecker(conf, new FakeTimer());
    final AtomicLong numCallbackInvocations = new AtomicLong(0);
    lock.lock();
    /**
     * Request a check and ensure it triggered {@link FsVolumeSpi#check}.
     */
    boolean result = checker.checkVolume(volume, new DatasetVolumeChecker.Callback() {

        @Override
        public void call(Set<FsVolumeSpi> healthyVolumes, Set<FsVolumeSpi> failedVolumes) {
            numCallbackInvocations.incrementAndGet();
            // Assert that the disk check registers a failed volume due to
            // timeout
            assertThat(healthyVolumes.size(), is(0));
            assertThat(failedVolumes.size(), is(1));
        }
    });
    // Wait for the callback
    Thread.sleep(DISK_CHECK_TIME);
    // Release lock
    lock.unlock();
    // Ensure that the check was invoked only once.
    verify(volume, times(1)).check(anyObject());
    assertThat(numCallbackInvocations.get(), is(1L));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) FsVolumeSpi(org.apache.hadoop.hdfs.server.datanode.fsdataset.FsVolumeSpi) FakeTimer(org.apache.hadoop.util.FakeTimer) Test(org.junit.Test)

Example 24 with FakeTimer

use of org.apache.hadoop.util.FakeTimer in project hadoop by apache.

the class TestStorageLocationChecker method testAllLocationsHealthy.

/**
   * Verify that all healthy locations are correctly handled and that the
   * check routine is invoked as expected.
   * @throws Exception
   */
@Test(timeout = 30000)
public void testAllLocationsHealthy() throws Exception {
    final List<StorageLocation> locations = makeMockLocations(HEALTHY, HEALTHY, HEALTHY);
    final Configuration conf = new HdfsConfiguration();
    conf.setInt(DFS_DATANODE_FAILED_VOLUMES_TOLERATED_KEY, 0);
    StorageLocationChecker checker = new StorageLocationChecker(conf, new FakeTimer());
    List<StorageLocation> filteredLocations = checker.check(conf, locations);
    // All locations should be healthy.
    assertThat(filteredLocations.size(), is(3));
    // Ensure that the check method was invoked for each location.
    for (StorageLocation location : locations) {
        verify(location).check(any(StorageLocation.CheckContext.class));
    }
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) FakeTimer(org.apache.hadoop.util.FakeTimer) Test(org.junit.Test)

Example 25 with FakeTimer

use of org.apache.hadoop.util.FakeTimer in project hadoop by apache.

the class TestStorageLocationChecker method testBadConfiguration.

/**
   * Test handling all storage locations are failed.
   *
   * @throws Exception
   */
@Test(timeout = 30000)
public void testBadConfiguration() throws Exception {
    final List<StorageLocation> locations = makeMockLocations(HEALTHY, HEALTHY, HEALTHY);
    final Configuration conf = new HdfsConfiguration();
    conf.setInt(DFS_DATANODE_FAILED_VOLUMES_TOLERATED_KEY, 3);
    thrown.expect(IOException.class);
    thrown.expectMessage("Invalid value configured");
    StorageLocationChecker checker = new StorageLocationChecker(conf, new FakeTimer());
    checker.check(conf, locations);
}
Also used : HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) Configuration(org.apache.hadoop.conf.Configuration) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation) HdfsConfiguration(org.apache.hadoop.hdfs.HdfsConfiguration) FakeTimer(org.apache.hadoop.util.FakeTimer) Test(org.junit.Test)

Aggregations

FakeTimer (org.apache.hadoop.util.FakeTimer)33 Test (org.junit.Test)30 Groups (org.apache.hadoop.security.Groups)10 HdfsConfiguration (org.apache.hadoop.hdfs.HdfsConfiguration)9 Configuration (org.apache.hadoop.conf.Configuration)8 StorageLocation (org.apache.hadoop.hdfs.server.datanode.StorageLocation)6 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)5 IOException (java.io.IOException)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3 TimeoutException (java.util.concurrent.TimeoutException)2 LogCapturer (org.apache.hadoop.test.GenericTestUtils.LogCapturer)2 Before (org.junit.Before)2 Optional (com.google.common.base.Optional)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1