@Test public void testSimpleCalls() throws Exception { FileSystem fs = Mockito.mock(FileSystem.class); Mockito.when(fs.getFileStatus(Mockito.any(Path.class))).thenReturn(new FileStatus(0, false, 0, 0, 0, new Path("/"))); Limiter limiter = new CountBasedLimiter(2); ThrottledFileSystem throttledFileSystem = new ThrottledFileSystem(fs, limiter, "testService"); Assert.assertNotNull(throttledFileSystem.getFileStatus(new Path("/myFile"))); Assert.assertNotNull(throttledFileSystem.getFileStatus(new Path("/myFile"))); try { throttledFileSystem.getFileStatus(new Path("/myFile")); Assert.fail(); } catch (NotEnoughPermitsException expected) { } }
@Override public FileStatus getFileStatus(Path path) throws IOException { this.acquirePermit("getFileStatus " + path); return super.getFileStatus(path); }
ThrottledFileSystem extends FileSystemInstrumentation { @Override public FileStatus getFileStatus(Path path) throws IOException { this.acquirePermit("getFileStatus " + path); return super.getFileStatus(path); } }
ThrottledFileSystem extends FileSystemInstrumentation { @Override public FileStatus getFileStatus(Path path) throws IOException { this.acquirePermit("getFileStatus " + path); return super.getFileStatus(path); } ThrottledFileSystem(FileSystem fs, Limiter limiter, String serviceName); }
ThrottledFileSystem extends FileSystemInstrumentation { @Override public FileStatus getFileStatus(Path path) throws IOException { this.acquirePermit("getFileStatus " + path); return super.getFileStatus(path); } ThrottledFileSystem(FileSystem fs, Limiter limiter, String serviceName); @Override boolean delete(Path path); @Override boolean delete(Path path, boolean recursive); @Override boolean exists(Path path); @Override FileStatus getFileStatus(Path path); @Override FileStatus[] globStatus(Path pathPattern); @Override FileStatus[] listStatus(Path path); @Override FileStatus[] listStatus(Path path, PathFilter filter); @Override boolean mkdirs(Path path, FsPermission permission); @Override boolean rename(Path path0, Path path1); @Override FSDataOutputStream append(Path path, int bufferSize, Progressable progress); @Override FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize,
      short replication, long blockSize, Progressable progress); @Override FSDataInputStream open(Path path, int bufferSize); String getServiceName(); @Override void close(); }
ThrottledFileSystem extends FileSystemInstrumentation { @Override public FileStatus getFileStatus(Path path) throws IOException { this.acquirePermit("getFileStatus " + path); return super.getFileStatus(path); } ThrottledFileSystem(FileSystem fs, Limiter limiter, String serviceName); @Override boolean delete(Path path); @Override boolean delete(Path path, boolean recursive); @Override boolean exists(Path path); @Override FileStatus getFileStatus(Path path); @Override FileStatus[] globStatus(Path pathPattern); @Override FileStatus[] listStatus(Path path); @Override FileStatus[] listStatus(Path path, PathFilter filter); @Override boolean mkdirs(Path path, FsPermission permission); @Override boolean rename(Path path0, Path path1); @Override FSDataOutputStream append(Path path, int bufferSize, Progressable progress); @Override FSDataOutputStream create(Path path, FsPermission permission, boolean overwrite, int bufferSize,
      short replication, long blockSize, Progressable progress); @Override FSDataInputStream open(Path path, int bufferSize); String getServiceName(); @Override void close(); static final int LISTING_FILES_PER_PERMIT; }