Counter moreThan1Counter = new GenericCounter(); when(reducerContext.getCounter(AvroKeyDedupReducer.EVENT_COUNTER.MORE_THAN_1)).thenReturn(moreThan1Counter); Counter dedupedCounter = new GenericCounter(); when(reducerContext.getCounter(AvroKeyDedupReducer.EVENT_COUNTER.DEDUPED)).thenReturn(dedupedCounter); Counter recordCounter = new GenericCounter(); when(reducerContext.getCounter(AvroKeyDedupReducer.EVENT_COUNTER.RECORD_COUNT)).thenReturn(recordCounter); reducer.setup(reducerContext);
/** * Find a counter, create one if necessary * @param groupName of the counter * @param counterName name of the counter * @return the matching counter */ public C findCounter(String groupName, String counterName) { G grp = getGroup(groupName); return grp.findCounter(counterName); }
public synchronized void checkCounters(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int countersMax = getCountersMax(); if (size > countersMax) { firstViolation = new LimitExceededException("Too many counters: "+ size + " max="+ countersMax); throw firstViolation; } }
@Override public synchronized T findCounter(String counterName, String displayName) { // Take lock to avoid two threads not finding a counter and trying to add // the same counter. String saveName = Limits.filterCounterName(counterName); T counter = findCounterImpl(saveName, false); if (counter == null) { return addCounterImpl(saveName, displayName, 0); } return counter; }
public synchronized void checkGroups(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int groupsMax = getGroupsMax(); if (size > groupsMax) { firstViolation = new LimitExceededException("Too many counter groups: "+ size +" max="+ groupsMax); } }
@SuppressWarnings("rawtypes") @Test public void testFrameworkCounter() { GroupFactory groupFactory = new GroupFactoryForTest(); FrameworkGroupFactory frameworkGroupFactory = groupFactory.newFrameworkGroupFactory(JobCounter.class); Group group = (Group) frameworkGroupFactory.newGroup("JobCounter"); FrameworkCounterGroup counterGroup = (FrameworkCounterGroup) group.getUnderlyingGroup(); org.apache.hadoop.mapreduce.Counter count1 = counterGroup.findCounter(JobCounter.NUM_FAILED_MAPS.toString()); Assert.assertNotNull(count1); // Verify no exception get thrown when finding an unknown counter org.apache.hadoop.mapreduce.Counter count2 = counterGroup.findCounter("Unknown"); Assert.assertNull(count2); }
@Override public T findCounter(String counterName, boolean create) { return findCounterImpl(Limits.filterCounterName(counterName), create); }
@Override public synchronized T findCounter(String counterName, String displayName) { // Take lock to avoid two threads not finding a counter and trying to add // the same counter. String saveName = Limits.filterCounterName(counterName); T counter = findCounterImpl(saveName, false); if (counter == null) { return addCounterImpl(saveName, displayName, 0); } return counter; }
/** * Find a counter, create one if necessary * @param groupName of the counter * @param counterName name of the counter * @return the matching counter */ public C findCounter(String groupName, String counterName) { G grp = getGroup(groupName); return grp.findCounter(counterName); }
public synchronized void checkGroups(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int groupsMax = getGroupsMax(); if (size > groupsMax) { firstViolation = new LimitExceededException("Too many counter groups: "+ size +" max="+ groupsMax); } }
public synchronized void checkCounters(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int countersMax = getCountersMax(); if (size > countersMax) { firstViolation = new LimitExceededException("Too many counters: "+ size + " max="+ countersMax); throw firstViolation; } }
@SuppressWarnings("rawtypes") @Test public void testTaskCounter() { GroupFactory groupFactory = new GroupFactoryForTest(); FrameworkGroupFactory frameworkGroupFactory = groupFactory.newFrameworkGroupFactory(TaskCounter.class); Group group = (Group) frameworkGroupFactory.newGroup("TaskCounter"); FrameworkCounterGroup counterGroup = (FrameworkCounterGroup) group.getUnderlyingGroup(); org.apache.hadoop.mapreduce.Counter count1 = counterGroup.findCounter( TaskCounter.PHYSICAL_MEMORY_BYTES.toString()); Assert.assertNotNull(count1); count1.increment(10); count1.increment(10); Assert.assertEquals(20, count1.getValue()); // Verify no exception get thrown when finding an unknown counter org.apache.hadoop.mapreduce.Counter count2 = counterGroup.findCounter( TaskCounter.MAP_PHYSICAL_MEMORY_BYTES_MAX.toString()); Assert.assertNotNull(count2); count2.increment(5); count2.increment(10); Assert.assertEquals(10, count2.getValue()); }
@Override public T findCounter(String counterName, boolean create) { return findCounterImpl(Limits.filterCounterName(counterName), create); }
@Override public synchronized T findCounter(String counterName, String displayName) { // Take lock to avoid two threads not finding a counter and trying to add // the same counter. String saveName = Limits.filterCounterName(counterName); T counter = findCounterImpl(saveName, false); if (counter == null) { return addCounterImpl(saveName, displayName, 0); } return counter; }
/** * Find a counter, create one if necessary * @param groupName of the counter * @param counterName name of the counter * @return the matching counter */ public C findCounter(String groupName, String counterName) { G grp = getGroup(groupName); return grp.findCounter(counterName); }
public synchronized void checkGroups(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int groupsMax = getGroupsMax(); if (size > groupsMax) { firstViolation = new LimitExceededException("Too many counter groups: "+ size +" max="+ groupsMax); } }
public synchronized void checkCounters(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int countersMax = getCountersMax(); if (size > countersMax) { firstViolation = new LimitExceededException("Too many counters: "+ size + " max="+ countersMax); throw firstViolation; } }
@Override public synchronized T findCounter(String counterName, String displayName) { // Take lock to avoid two threads not finding a counter and trying to add // the same counter. String saveName = Limits.filterCounterName(counterName); T counter = findCounterImpl(saveName, false); if (counter == null) { return addCounterImpl(saveName, displayName, 0); } return counter; }
/** * Find a counter, create one if necessary * @param groupName of the counter * @param counterName name of the counter * @return the matching counter */ public C findCounter(String groupName, String counterName) { G grp = getGroup(groupName); return grp.findCounter(counterName); }
public synchronized void checkGroups(int size) { if (firstViolation != null) { throw new LimitExceededException(firstViolation); } int groupsMax = getGroupsMax(); if (size > groupsMax) { firstViolation = new LimitExceededException("Too many counter groups: "+ size +" max="+ groupsMax); } }