Search in sources :

Example 1 with VolumeCheckResult

use of org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult in project hadoop by apache.

the class TestDatasetVolumeChecker method data.

/**
   * Run each test case for each possible value of {@link VolumeCheckResult}.
   * Including "null" for 'throw exception'.
   * @return
   */
@Parameters(name = "{0}")
public static Collection<Object[]> data() {
    List<Object[]> values = new ArrayList<>();
    for (VolumeCheckResult result : VolumeCheckResult.values()) {
        values.add(new Object[] { result });
    }
    values.add(new Object[] { null });
    return values;
}
Also used : ArrayList(java.util.ArrayList) VolumeCheckResult(org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult) Parameters(org.junit.runners.Parameterized.Parameters)

Example 2 with VolumeCheckResult

use of org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult in project hadoop by apache.

the class TestStorageLocationChecker method makeSlowLocations.

/**
   * Return a list of storage locations - one per argument - whose check()
   * method takes at least the specified number of milliseconds to complete.
   */
private List<StorageLocation> makeSlowLocations(long... args) throws IOException {
    final List<StorageLocation> locations = new ArrayList<>(args.length);
    final AtomicInteger index = new AtomicInteger(0);
    for (final long checkDelayMs : args) {
        final StorageLocation location = mock(StorageLocation.class);
        when(location.toString()).thenReturn("/" + index.incrementAndGet());
        when(location.check(any(StorageLocation.CheckContext.class))).thenAnswer(new Answer<VolumeCheckResult>() {

            @Override
            public VolumeCheckResult answer(InvocationOnMock invocation) throws Throwable {
                Thread.sleep(checkDelayMs);
                return VolumeCheckResult.HEALTHY;
            }
        });
        locations.add(location);
    }
    return locations;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) VolumeCheckResult(org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation)

Example 3 with VolumeCheckResult

use of org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult in project hadoop by apache.

the class TestStorageLocationChecker method makeMockLocations.

/**
   * Return a list of storage locations - one per argument - which return
   * health check results corresponding to the supplied arguments.
   */
private List<StorageLocation> makeMockLocations(VolumeCheckResult... args) throws IOException {
    final List<StorageLocation> locations = new ArrayList<>(args.length);
    final AtomicInteger index = new AtomicInteger(0);
    for (VolumeCheckResult result : args) {
        final StorageLocation location = mock(StorageLocation.class);
        when(location.toString()).thenReturn("/" + index.incrementAndGet());
        when(location.check(any(StorageLocation.CheckContext.class))).thenReturn(result);
        locations.add(location);
    }
    return locations;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ArrayList(java.util.ArrayList) VolumeCheckResult(org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult) StorageLocation(org.apache.hadoop.hdfs.server.datanode.StorageLocation)

Aggregations

ArrayList (java.util.ArrayList)3 VolumeCheckResult (org.apache.hadoop.hdfs.server.datanode.checker.VolumeCheckResult)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 StorageLocation (org.apache.hadoop.hdfs.server.datanode.StorageLocation)2 Parameters (org.junit.runners.Parameterized.Parameters)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1