FileHeuristic implements Heuristic { public void compute(String applicationId, String attemptId, String containerId, DataAccessEventProtos.FsEvent fsEvent) { try { FsAction action = FsAction.valueOf(fsEvent.getAction()); switch (action) { case DELETE: deleted.forApp(applicationId, attemptId).increment(); break; case READ: read.forApp(applicationId, attemptId).increment(); break; case WRITE: written.forApp(applicationId, attemptId).increment(); break; case RENAME: renamed.forApp(applicationId, attemptId).increment(); break; case APPEND: append.forApp(applicationId, attemptId).increment(); break; case ADD_BLOCK: addBlock.forApp(applicationId, attemptId).increment(); break; case LIST_STATUS: listStatus.forApp(applicationId, attemptId).increment(); break; case GET_CONTENT_SUMMARY: getContentSummary.forApp(applicationId, attemptId).increment(); break; default: throw new IllegalArgumentException("Received a non managed FsEvent.Action " + action.name()); } } catch (IllegalArgumentException ex) { if (LOGGER.isWarnEnabled()) { LOGGER.warn("received an unexpected FsEvent.Action {}", ex.getMessage()); } } } FileHeuristic(HeuristicsResultDB db, int maxCreatedFiles); void compute(String applicationId, String attemptId, String containerId, DataAccessEventProtos.FsEvent fsEvent); @Override void onContainerCompleted(String applicationId, String attemptId, String containerId); @Override void onAppCompleted(String applicationId, String attemptId); @Override String getHelp();  }
@Test public void FileHeuristic_should_update_delete_counter_for_every_FileEvent_delete_whatever_the_container() { DataAccessEventProtos.FsEvent event = newFsEvent(FsAction.DELETE); heuristic.compute("app_1", "att_1", "cid_1", event); assertThat(heuristic.deleted.forApp("app_1", "att_1").getCount(), is(1)); heuristic.compute("app_1", "att_1", "cid_2", event); assertThat(heuristic.deleted.forApp("app_1", "att_1").getCount(), is(2)); }
@Test public void FileHeuristic_should_update_read_counter_for_every_FileEvent_read_whatever_the_container() { DataAccessEventProtos.FsEvent event = newFsEvent(FsAction.READ); heuristic.compute("app_1", "att_1", "cid_1", event); assertThat(heuristic.read.forApp("app_1", "att_1").getCount(), is(1)); heuristic.compute("app_1", "att_1", "cid_2", event); assertThat(heuristic.read.forApp("app_1", "att_1").getCount(), is(2)); }
@Test public void FileHeuristic_should_update_write_counter_for_every_FileEvent_write_whatever_the_container() { DataAccessEventProtos.FsEvent event = newFsEvent(FsAction.WRITE); heuristic.compute("app_1", "att_1", "cid_1", event); assertThat(heuristic.written.forApp("app_1", "att_1").getCount(), is(1)); heuristic.compute("app_1", "att_1", "cid_2", event); assertThat(heuristic.written.forApp("app_1", "att_1").getCount(), is(2)); }
@Test public void FileHeuristic_should_update_rename_counter_for_every_FileEvent_rename_whatever_the_container() { DataAccessEventProtos.FsEvent event = newFsEvent(FsAction.RENAME); heuristic.compute("app_1", "att_1", "cid_1", event); assertThat(heuristic.renamed.forApp("app_1", "att_1").getCount(), is(1)); heuristic.compute("app_1", "att_1", "cid_2", event); assertThat(heuristic.renamed.forApp("app_1", "att_1").getCount(), is(2)); }
@Test public void FileHeuristic_should_ignore_unknown_actions() { DataAccessEventProtos.FsEvent unknowActionEvent = newFsEvent("whatever"); heuristic.compute("app_1", "att_1", "cid_1", unknowActionEvent); assertThat(heuristic.append.forApp("app_1", "att_1").getCount(), is(0)); assertThat(heuristic.deleted.forApp("app_1", "att_1").getCount(), is(0)); assertThat(heuristic.read.forApp("app_1", "att_1").getCount(), is(0)); assertThat(heuristic.renamed.forApp("app_1", "att_1").getCount(), is(0)); assertThat(heuristic.written.forApp("app_1", "att_1").getCount(), is(0)); }