Example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor ScheduledThreadPoolExecutor.

Prototype

public ScheduledThreadPoolExecutor(int corePoolSize) 

Source Link

Document

Creates a new ScheduledThreadPoolExecutor with the given core pool size.

Usage

From source file:org.apache.hadoop.hbase.util.TestHBaseFsck.java

/**
* Test that use this should have a timeout, because this method could potentially wait forever.
*///from w  ww.  j a  va2 s  . c  o m
private void doQuarantineTest(TableName table, HBaseFsck hbck, int check, int corrupt, int fail, int quar,
        int missing) throws Exception {
    try {
        setupTable(table);
        assertEquals(ROWKEYS.length, countRows());
        TEST_UTIL.getHBaseAdmin().flush(table.getName()); // flush is async.

        // Mess it up by leaving a hole in the assignment, meta, and hdfs data
        TEST_UTIL.getHBaseAdmin().disableTable(table);

        String[] args = { "-sidelineCorruptHFiles", "-repairHoles", "-ignorePreCheckPermission",
                table.getNameAsString() };
        ExecutorService exec = new ScheduledThreadPoolExecutor(10);
        HBaseFsck res = hbck.exec(exec, args);

        HFileCorruptionChecker hfcc = res.getHFilecorruptionChecker();
        assertEquals(hfcc.getHFilesChecked(), check);
        assertEquals(hfcc.getCorrupted().size(), corrupt);
        assertEquals(hfcc.getFailures().size(), fail);
        assertEquals(hfcc.getQuarantined().size(), quar);
        assertEquals(hfcc.getMissing().size(), missing);

        // its been fixed, verify that we can enable
        HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
        admin.enableTableAsync(table);
        while (!admin.isTableEnabled(table)) {
            try {
                Thread.sleep(250);
            } catch (InterruptedException e) {
                e.printStackTrace();
                fail("Interrupted when trying to enable table " + table);
            }
        }
    } finally {
        deleteTable(table);
    }
}

From source file:org.apache.hadoop.hbase.util.TestHBaseFsck.java

/**
 * This creates a table and simulates the race situation where a concurrent compaction or split
 * has removed an hfile after the corruption checker learned about it.
 *///from w  w w. j  a v  a2 s.com
@Test(timeout = 180000)
public void testQuarantineMissingHFile() throws Exception {
    TableName table = TableName.valueOf(name.getMethodName());
    ExecutorService exec = new ScheduledThreadPoolExecutor(10);
    // inject a fault in the hfcc created.
    final FileSystem fs = FileSystem.get(conf);
    HBaseFsck hbck = new HBaseFsck(conf, exec) {
        @Override
        public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles)
                throws IOException {
            return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) {
                boolean attemptedFirstHFile = false;

                @Override
                protected void checkHFile(Path p) throws IOException {
                    if (!attemptedFirstHFile) {
                        attemptedFirstHFile = true;
                        assertTrue(fs.delete(p, true)); // make sure delete happened.
                    }
                    super.checkHFile(p);
                }
            };
        }
    };
    doQuarantineTest(table, hbck, 4, 0, 0, 0, 1); // 4 attempted, but 1 missing.
}

From source file:org.apache.hadoop.hbase.util.TestHBaseFsck.java

/**
 * This creates a table and simulates the race situation where a concurrent compaction or split
 * has removed an colfam dir before the corruption checker got to it.
 *//*from w w w. java2s  .  c o m*/
// Disabled because fails sporadically.  Is this test right?  Timing-wise, there could be no
// files in a column family on initial creation -- as suggested by Matteo.
@Ignore
@Test(timeout = 180000)
public void testQuarantineMissingFamdir() throws Exception {
    TableName table = TableName.valueOf(name.getMethodName());
    ExecutorService exec = new ScheduledThreadPoolExecutor(10);
    // inject a fault in the hfcc created.
    final FileSystem fs = FileSystem.get(conf);
    HBaseFsck hbck = new HBaseFsck(conf, exec) {
        @Override
        public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles)
                throws IOException {
            return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) {
                boolean attemptedFirstFamDir = false;

                @Override
                protected void checkColFamDir(Path p) throws IOException {
                    if (!attemptedFirstFamDir) {
                        attemptedFirstFamDir = true;
                        assertTrue(fs.delete(p, true)); // make sure delete happened.
                    }
                    super.checkColFamDir(p);
                }
            };
        }
    };
    doQuarantineTest(table, hbck, 3, 0, 0, 0, 1);
}

From source file:org.apache.hadoop.hbase.util.TestHBaseFsck.java

/**
 * This creates a table and simulates the race situation where a concurrent compaction or split
 * has removed a region dir before the corruption checker got to it.
 *///from  w w w  . j a v a 2  s .c  om
@Test(timeout = 180000)
public void testQuarantineMissingRegionDir() throws Exception {
    TableName table = TableName.valueOf(name.getMethodName());
    ExecutorService exec = new ScheduledThreadPoolExecutor(10);
    // inject a fault in the hfcc created.
    final FileSystem fs = FileSystem.get(conf);
    HBaseFsck hbck = new HBaseFsck(conf, exec) {
        @Override
        public HFileCorruptionChecker createHFileCorruptionChecker(boolean sidelineCorruptHFiles)
                throws IOException {
            return new HFileCorruptionChecker(conf, executor, sidelineCorruptHFiles) {
                boolean attemptedFirstRegionDir = false;

                @Override
                protected void checkRegionDir(Path p) throws IOException {
                    if (!attemptedFirstRegionDir) {
                        attemptedFirstRegionDir = true;
                        assertTrue(fs.delete(p, true)); // make sure delete happened.
                    }
                    super.checkRegionDir(p);
                }
            };
        }
    };
    doQuarantineTest(table, hbck, 3, 0, 0, 0, 1);
}