FileSystemTracer { public static Method getMethod(ClassLoader classLoader, String clazz, String method, Class<?>... parameterTypes) { return (Method) getMethodCache().computeIfAbsent(classLoader + clazz + method, k -> { try { Class classzz = classLoader.loadClass(clazz); return classzz.getMethod(method, parameterTypes); } catch (NoSuchMethodException | ClassNotFoundException ignored) { return null; } }); } protected  FileSystemTracer(); static void setup(Instrumentation instrumentation, BiConsumer<Long, Object> eventConsumer); static ConcurrentHashMap getFieldCache(); static ConcurrentHashMap getMethodCache(); static Method getMethod(ClassLoader classLoader, String clazz, String method, Class<?>... parameterTypes); static Field getField(ClassLoader classLoader, String clazz, String field); static void initEventHandler(BiConsumer<Long, Object> eventConsumer);  }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_delete_Hdfs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { Path toDelete = new Path("/test/to_delete"); createSrcPathHdfs(toDelete); Method delete = clazzAFS.getMethod("delete", Path.class, boolean.class); delete.invoke(hdfs, toDelete, true); checkEvent(FsAction.DELETE.name(), toDelete); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_delete_DistributedFileSystem() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, ClassNotFoundException { Path toDelete = new Path("/test/to_delete"); createSrcPathDistributedFilesystem(toDelete); Method delete = clazzFS.getMethod("delete", Path.class, boolean.class); delete.invoke(dfs, toDelete, true); checkEvent(FsAction.DELETE.name(), toDelete); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_rename_deprecated() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, ClassNotFoundException { Path toRename = new Path("/test/to_rename"); Path dst = new Path("/test/to_rename_dst_deprecated"); createSrcPathDistributedFilesystem(toRename); Method rename = clazzFS.getMethod("rename", Path.class, Path.class); rename.invoke(dfs, toRename, dst); checkEvent(FsAction.RENAME.name(), dst); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_rename_Hdfs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { Path toRename = new Path("/test/to_rename"); Path dst = new Path("/test/to_rename_dst_hdfs"); createSrcPathHdfs(toRename); Method rename = clazzAFS.getMethod("renameInternal", Path.class, Path.class, boolean.class); rename.invoke(hdfs, toRename, dst, true); checkEvent(FsAction.RENAME.name(), dst); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_rename() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, ClassNotFoundException { Path toRename = new Path("/test/to_rename"); Path dst = new Path("/test/to_rename_dst"); createSrcPathDistributedFilesystem(toRename); Method rename = clazzFS.getMethod("rename", Path.class, Path.class, Options.Rename[].class); rename.invoke(dfs, toRename, dst, new Options.Rename[0]); checkEvent(FsAction.RENAME.name(), dst); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_indicate_if_event_is_failure_via_exception() throws NoSuchMethodException { Method create = clazzFS.getMethod("create", Path.class, FsPermission.class, boolean.class, int.class, short.class, long.class, Progressable.class); try { create.invoke(dfs, new Path("ssss: } catch (Exception ignore) { } checkEvent(FsAction.WRITE.name(), new Path("ssss: }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_indicate_failure_if_method_returns_boolean_false() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException { Path dst = new Path("/test/to_rename_dst_failure"); Method rename = clazzFS.getMethod("rename", Path.class, Path.class); rename.invoke(dfs, new Path("/not_existing"), dst); checkEvent(FsAction.RENAME.name(), dst, DataAccessEventProtos.FsEvent.Status.FAILURE); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_read_Hdfs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { Path toRead = new Path("/test/to_read_hdfs"); createSrcPathHdfs(toRead); Method open = clazzAFS.getMethod("open", Path.class, int.class); open.invoke(hdfs, toRead, 1024); checkEvent(FsAction.READ.name(), toRead); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_read_DistributedFileSystem() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, IOException, ClassNotFoundException { Path toRead = new Path("/test/to_read_dfs"); createSrcPathDistributedFilesystem(toRead); Method open = clazzFS.getMethod("open", Path.class, int.class); open.invoke(dfs, toRead, 1024); checkEvent(FsAction.READ.name(), toRead); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_list_hdfs() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method listStatus = clazzAFS.getMethod("listStatus", Path.class); listStatus.invoke(hdfs, pathFolder); checkEvent(FsAction.LIST_STATUS.name(), pathFolder); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_list_DistributedFileSystem() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method listStatus = clazzFS.getMethod("listStatus", Path.class); listStatus.invoke(dfs, pathFolder); checkEvent(FsAction.LIST_STATUS.name(), pathFolder); }
@Test @AgentAttachmentRule.Enforce public void FileSystemTracer_should_attach_to_get_content() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { Method getContentSummary = clazzFS.getMethod("getContentSummary", Path.class); getContentSummary.invoke(dfs, pathFolder); checkEvent(FsAction.GET_CONTENT_SUMMARY.name(), pathFolder); }