private Counters getEnumCounters(Enum[] keys) { Counters counters = new Counters(); for (Enum key : keys) { for (long i = 0; i < MAX_VALUE; ++i) { counters.incrCounter(key, i); } } return counters; }
private Counters getEnumCounters(String[] gNames, String[] cNames) { Counters counters = new Counters(); for (String gName : gNames) { for (String cName : cNames) { for (long i = 0; i < MAX_VALUE; ++i) { counters.incrCounter(gName, cName, i); } } } return counters; }
@SuppressWarnings("deprecation") @Test public void testCounterIteratorConcurrency() { Counters counters = new Counters(); counters.incrCounter("group1", "counter1", 1); Iterator<Group> iterator = counters.iterator(); counters.incrCounter("group2", "counter2", 1); iterator.next(); }
@SuppressWarnings("deprecation") @Test public void testGroupIteratorConcurrency() { Counters counters = new Counters(); counters.incrCounter("group1", "counter1", 1); Group group = counters.getGroup("group1"); Iterator<Counter> iterator = group.iterator(); counters.incrCounter("group1", "counter2", 1); iterator.next(); }
@Test public void testMakeCompactString() { final String GC1 = "group1.counter1:1"; final String GC2 = "group2.counter2:3"; Counters counters = new Counters(); counters.incrCounter("group1", "counter1", 1); assertEquals("group1.counter1:1", counters.makeCompactString()); counters.incrCounter("group2", "counter2", 3); String cs = counters.makeCompactString(); assertTrue("Bad compact string", cs.equals(GC1 + ',' + GC2) || cs.equals(GC2 + ',' + GC1)); }
@SuppressWarnings("deprecation") @Test public void testWriteWithLegacyNames() { Counters counters = new Counters(); counters.incrCounter(Task.Counter.MAP_INPUT_RECORDS, 1); counters.incrCounter(JobInProgress.Counter.DATA_LOCAL_MAPS, 1); counters.findCounter("FileSystemCounters", "FILE_BYTES_READ").increment(1); checkLegacyNames(counters); }
@SuppressWarnings("deprecation") @Test public void testReadWithLegacyNames() { Counters counters = new Counters(); counters.incrCounter(TaskCounter.MAP_INPUT_RECORDS, 1); counters.incrCounter(JobCounter.DATA_LOCAL_MAPS, 1); counters.findCounter("file", FileSystemCounter.BYTES_READ).increment(1); checkLegacyNames(counters); }
@Test public void testLegacyGetGroupNames() { Counters counters = new Counters(); // create 2 filesystem counter groups counters.findCounter("fs1", FileSystemCounter.BYTES_READ).increment(1); counters.findCounter("fs2", FileSystemCounter.BYTES_READ).increment(1); counters.incrCounter("group1", "counter1", 1); HashSet<String> groups = new HashSet<String>(counters.getGroupNames()); HashSet<String> expectedGroups = new HashSet<String>(); expectedGroups.add("group1"); expectedGroups.add("FileSystemCounters"); //Legacy Name expectedGroups.add("org.apache.hadoop.mapreduce.FileSystemCounter"); assertEquals(expectedGroups, groups); }
@Override public void incrCounter(String group, String counter, long amount) { if (null != counters) { counters.incrCounter(group, counter, amount); } }
public void incrCounter(Enum key, long amount) { if (counters != null) { counters.incrCounter(key, amount); } setProgressFlag(); } public void incrCounter(String group, String counter, long amount) {
@Override public void incrCounter(Enum key, long amount) { if (null != counters) { counters.incrCounter(key, amount); } }
public void incrCounter(Enum key, long amount) { if (counters != null) { counters.incrCounter(key, amount); } setProgressFlag(); } public void incrCounter(String group, String counter, long amount) {
private Counters getEnumCounters(Enum[] keys) { Counters counters = new Counters(); for (Enum key : keys) { for (long i = 0; i < MAX_VALUE; ++i) { counters.incrCounter(key, i); } } return counters; }
private Counters getEnumCounters(String[] gNames, String[] cNames) { Counters counters = new Counters(); for (String gName : gNames) { for (String cName : cNames) { for (long i = 0; i < MAX_VALUE; ++i) { counters.incrCounter(gName, cName, i); } } } return counters; }
public void incrCounter(Enum key, long amount) { if (counters != null) { counters.incrCounter(key, amount); } setProgressFlag(); } public void incrCounter(String group, String counter, long amount) {
public void incrCounter(Enum key, long amount) { if (counters != null) { counters.incrCounter(key, amount); } setProgressFlag(); } public void incrCounter(String group, String counter, long amount) {
public Counter getCounter(Enum<?> name) { try { Counters counters = new Counters(); counters.incrCounter(name, rep.getCounter(name).getValue()); return counters.findCounter(name); } catch (Exception e) { throw new RuntimeException(e); } } public Counter getCounter(String group, String name) {
@SuppressWarnings("deprecation") @Test public void testOldCounters() throws Exception { Counters c1 = new Counters(); c1.incrCounter(FileInputFormat.Counter.BYTES_READ, 100); c1.incrCounter(FileOutputFormat.Counter.BYTES_WRITTEN, 200); c1.incrCounter(TaskCounter.MAP_OUTPUT_BYTES, 100); c1.incrCounter(TaskCounter.MAP_OUTPUT_MATERIALIZED_BYTES, 100); validateFileCounters(c1, 100, 200, 100, 100); validateOldFileCounters(c1, 100, 200, 100, 100); }
public Counter getCounter(String group, String name) { try { Counters counters = new Counters(); counters.incrCounter(group, name, rep.getCounter(group, name).getValue()); return counters.findCounter(group, name); } catch (Exception e) { throw new RuntimeException(e); } } public void incrCounter(Enum<?> key, long amount) {
@Test public void testOneGroupOneCounterToJson() throws SerializationException { Counters counters = new Counters(); counters.incrCounter("SomeCounterGroupName", "SomeCounterName", 3); String json = MapRedStatsLogModule.toJson(counters); assertEquals( "[{\"groupName\":\"SomeCounterGroupName\",\"counters\":[{\"counterNa" + "me\":\"SomeCounterName\",\"value\":3}]}]", json); }