BloomMapFile { public static void delete(FileSystem fs, String name) throws IOException { Path dir = new Path(name); Path data = new Path(dir, MapFile.DATA_FILE_NAME); Path index = new Path(dir, MapFile.INDEX_FILE_NAME); Path bloom = new Path(dir, BLOOM_FILE_NAME); fs.delete(data, true); fs.delete(index, true); fs.delete(bloom, true); fs.delete(dir, true); }  static void delete(FileSystem fs, String name); static final String BLOOM_FILE_NAME; static final int HASH_COUNT; }
@SuppressWarnings("deprecation") @Test public void testMembershipTest() throws Exception { FileSystem fs = FileSystem.getLocal(conf); Path qualifiedDirName = fs.makeQualified(TEST_DIR); conf.setInt("io.mapfile.bloom.size", 2048); BloomMapFile.Writer writer = null; BloomMapFile.Reader reader = null; try { writer = new BloomMapFile.Writer(conf, fs, qualifiedDirName.toString(), IntWritable.class, Text.class); IntWritable key = new IntWritable(); Text value = new Text(); for (int i = 0; i < 2000; i += 2) { key.set(i); value.set("00" + i); writer.append(key, value); } writer.close(); reader = new BloomMapFile.Reader(fs, qualifiedDirName.toString(), conf); int falsePos = 0; int falseNeg = 0; for (int i = 0; i < 2000; i++) { key.set(i); boolean exists = reader.probablyHasKey(key); if (i % 2 == 0) { if (!exists) falseNeg++; } else { if (exists) falsePos++; } } reader.close(); fs.delete(qualifiedDirName, true); System.out.println("False negatives: " + falseNeg); assertEquals(0, falseNeg); System.out.println("False positives: " + falsePos); assertTrue(falsePos < 2); } finally { IOUtils.cleanupWithLogger(LOG, writer, reader); } }
@Test public void testDeleteFile() { BloomMapFile.Writer writer = null; try { FileSystem fs = FileSystem.getLocal(conf); writer = new BloomMapFile.Writer(conf, TEST_FILE, MapFile.Writer.keyClass(IntWritable.class), MapFile.Writer.valueClass(Text.class)); assertNotNull("testDeleteFile error !!!", writer); writer.close(); BloomMapFile.delete(fs, TEST_FILE.toString()); } catch (Exception ex) { fail("unexpect ex in testDeleteFile !!!"); } finally { IOUtils.cleanupWithLogger(LOG, writer); } }