Search in sources :

Example 1 with LimitExceededException

use of org.apache.hadoop.mapreduce.counters.LimitExceededException in project hadoop by apache.

the class TestCounters method testResetOnDeserialize.

@Test
public void testResetOnDeserialize() throws IOException {
    // Allow only one counterGroup
    Configuration conf = new Configuration();
    conf.setInt(MRJobConfig.COUNTER_GROUPS_MAX_KEY, 1);
    Limits.init(conf);
    Counters countersWithOneGroup = new Counters();
    countersWithOneGroup.findCounter("firstOf1Allowed", "First group");
    boolean caughtExpectedException = false;
    try {
        countersWithOneGroup.findCounter("secondIsTooMany", "Second group");
    } catch (LimitExceededException _) {
        caughtExpectedException = true;
    }
    assertTrue("Did not throw expected exception", caughtExpectedException);
    Counters countersWithZeroGroups = new Counters();
    DataOutputBuffer out = new DataOutputBuffer();
    countersWithZeroGroups.write(out);
    DataInputBuffer in = new DataInputBuffer();
    in.reset(out.getData(), out.getLength());
    countersWithOneGroup.readFields(in);
    // After reset one should be able to add a group
    countersWithOneGroup.findCounter("firstGroupAfterReset", "After reset " + "limit should be set back to zero");
}
Also used : DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) Configuration(org.apache.hadoop.conf.Configuration) DataOutputBuffer(org.apache.hadoop.io.DataOutputBuffer) LimitExceededException(org.apache.hadoop.mapreduce.counters.LimitExceededException) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)1 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)1 DataOutputBuffer (org.apache.hadoop.io.DataOutputBuffer)1 LimitExceededException (org.apache.hadoop.mapreduce.counters.LimitExceededException)1 Test (org.junit.Test)1