Search in sources :

Example 1 with OpType

use of org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType in project hadoop by apache.

the class TestDFSOpsCountStatistics method verifyStatistics.

/**
   * We have the expected ops count in {@link #expectedOpsCountMap}, and this
   * method is to verify that its ops count is the same as the one in
   * {@link #statistics}.
   */
private void verifyStatistics() {
    for (OpType opType : OpType.values()) {
        assertNotNull(expectedOpsCountMap.get(opType));
        assertNotNull(statistics.getLong(opType.getSymbol()));
        assertEquals("Not expected count for operation " + opType.getSymbol(), expectedOpsCountMap.get(opType).longValue(), statistics.getLong(opType.getSymbol()).longValue());
    }
}
Also used : OpType(org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType)

Example 2 with OpType

use of org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType in project hadoop by apache.

the class TestDFSOpsCountStatistics method testOpTypeSymbolsAreUnique.

/**
   * This is to test the the {@link OpType} symbols are unique.
   */
@Test
public void testOpTypeSymbolsAreUnique() {
    final Set<String> opTypeSymbols = new HashSet<>();
    for (OpType opType : OpType.values()) {
        assertFalse(opTypeSymbols.contains(opType.getSymbol()));
        opTypeSymbols.add(opType.getSymbol());
    }
    assertEquals(OpType.values().length, opTypeSymbols.size());
}
Also used : OpType(org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with OpType

use of org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType in project hadoop by apache.

the class TestDFSOpsCountStatistics method incrementOpsCountByRandomNumbers.

/**
   * This is helper method to increment the statistics by random data.
   */
private void incrementOpsCountByRandomNumbers() {
    for (OpType opType : OpType.values()) {
        final Long randomCount = RandomUtils.nextLong(0, 100);
        expectedOpsCountMap.get(opType).addAndGet(randomCount);
        for (long i = 0; i < randomCount; i++) {
            statistics.incrementOpCounter(opType);
        }
    }
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) OpType(org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType)

Example 4 with OpType

use of org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType in project hadoop by apache.

the class TestDFSOpsCountStatistics method testGetLongStatistics.

@Test
public void testGetLongStatistics() {
    // number of the iter.hasNext()
    short iterations = 0;
    final Iterator<LongStatistic> iter = statistics.getLongStatistics();
    while (iter.hasNext()) {
        final LongStatistic longStat = iter.next();
        assertNotNull(longStat);
        final OpType opType = OpType.fromSymbol(longStat.getName());
        assertNotNull(opType);
        assertTrue(expectedOpsCountMap.containsKey(opType));
        assertEquals(expectedOpsCountMap.get(opType).longValue(), longStat.getValue());
        iterations++;
    }
    // check that all the OpType enum entries are iterated via iter
    assertEquals(OpType.values().length, iterations);
}
Also used : LongStatistic(org.apache.hadoop.fs.StorageStatistics.LongStatistic) OpType(org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType) Test(org.junit.Test)

Example 5 with OpType

use of org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType in project hadoop by apache.

the class TestDFSOpsCountStatistics method testReset.

@Test
public void testReset() {
    statistics.reset();
    for (OpType opType : OpType.values()) {
        expectedOpsCountMap.get(opType).set(0);
    }
    final Iterator<LongStatistic> iter = statistics.getLongStatistics();
    while (iter.hasNext()) {
        final LongStatistic longStat = iter.next();
        assertEquals(0, longStat.getValue());
    }
    incrementOpsCountByRandomNumbers();
    verifyStatistics();
}
Also used : LongStatistic(org.apache.hadoop.fs.StorageStatistics.LongStatistic) OpType(org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType) Test(org.junit.Test)

Aggregations

OpType (org.apache.hadoop.hdfs.DFSOpsCountStatistics.OpType)5 Test (org.junit.Test)3 LongStatistic (org.apache.hadoop.fs.StorageStatistics.LongStatistic)2 HashSet (java.util.HashSet)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1