Search in sources :

Example 6 with Stoppable

use of org.apache.hadoop.hbase.Stoppable in project hbase by apache.

the class TestCleanerChore method testDeleteFileWithCleanerDisabled.

@Test
public void testDeleteFileWithCleanerDisabled() throws Exception {
    Stoppable stop = new StoppableImplementation();
    Configuration conf = UTIL.getConfiguration();
    Path testDir = UTIL.getDataTestDir();
    FileSystem fs = UTIL.getTestFileSystem();
    String confKey = "hbase.test.cleaner.delegates";
    conf.set(confKey, AlwaysDelete.class.getName());
    AllValidPaths chore = new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey);
    // Disable cleaner
    chore.setEnabled(false);
    // create the directory layout in the directory to clean
    Path parent = new Path(testDir, "parent");
    Path child = new Path(parent, "child");
    Path file = new Path(child, "someFile");
    fs.mkdirs(child);
    // touch a new file
    fs.create(file).close();
    assertTrue("Test file didn't get created.", fs.exists(file));
    // run the chore
    chore.chore();
    // verify all the files exist
    assertTrue("File got deleted with cleaner disabled", fs.exists(file));
    assertTrue("Directory got deleted", fs.exists(child));
    assertTrue("Directory got deleted", fs.exists(parent));
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) StoppableImplementation(org.apache.hadoop.hbase.util.StoppableImplementation) FileSystem(org.apache.hadoop.fs.FileSystem) Stoppable(org.apache.hadoop.hbase.Stoppable) Test(org.junit.Test)

Example 7 with Stoppable

use of org.apache.hadoop.hbase.Stoppable in project hbase by apache.

the class TestCleanerChore method testDoesNotCheckDirectories.

/**
   * Test to make sure that we don't attempt to ask the delegate whether or not we should preserve a
   * directory.
   * @throws Exception on failure
   */
@Test
public void testDoesNotCheckDirectories() throws Exception {
    Stoppable stop = new StoppableImplementation();
    Configuration conf = UTIL.getConfiguration();
    Path testDir = UTIL.getDataTestDir();
    FileSystem fs = UTIL.getTestFileSystem();
    String confKey = "hbase.test.cleaner.delegates";
    conf.set(confKey, AlwaysDelete.class.getName());
    AllValidPaths chore = new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey);
    // spy on the delegate to ensure that we don't check for directories
    AlwaysDelete delegate = (AlwaysDelete) chore.cleanersChain.get(0);
    AlwaysDelete spy = Mockito.spy(delegate);
    chore.cleanersChain.set(0, spy);
    // create the directory layout in the directory to clean
    Path parent = new Path(testDir, "parent");
    Path file = new Path(parent, "someFile");
    fs.mkdirs(parent);
    assertTrue("Test parent didn't get created.", fs.exists(parent));
    // touch a new file
    fs.create(file).close();
    assertTrue("Test file didn't get created.", fs.exists(file));
    FileStatus fStat = fs.getFileStatus(parent);
    chore.chore();
    // make sure we never checked the directory
    Mockito.verify(spy, Mockito.never()).isFileDeletable(fStat);
    Mockito.reset(spy);
}
Also used : Path(org.apache.hadoop.fs.Path) FileStatus(org.apache.hadoop.fs.FileStatus) Configuration(org.apache.hadoop.conf.Configuration) StoppableImplementation(org.apache.hadoop.hbase.util.StoppableImplementation) FileSystem(org.apache.hadoop.fs.FileSystem) Stoppable(org.apache.hadoop.hbase.Stoppable) Test(org.junit.Test)

Example 8 with Stoppable

use of org.apache.hadoop.hbase.Stoppable in project hbase by apache.

the class TestEndToEndSplitTransaction method testFromClientSideWhileSplitting.

/**
   * Tests that the client sees meta table changes as atomic during splits
   */
@Test
public void testFromClientSideWhileSplitting() throws Throwable {
    LOG.info("Starting testFromClientSideWhileSplitting");
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final byte[] FAMILY = Bytes.toBytes("family");
    //SplitTransaction will update the meta table by offlining the parent region, and adding info
    //for daughters.
    Table table = TEST_UTIL.createTable(tableName, FAMILY);
    Stoppable stopper = new StoppableImplementation();
    RegionSplitter regionSplitter = new RegionSplitter(table);
    RegionChecker regionChecker = new RegionChecker(CONF, stopper, tableName);
    final ChoreService choreService = new ChoreService("TEST_SERVER");
    choreService.scheduleChore(regionChecker);
    regionSplitter.start();
    //wait until the splitter is finished
    regionSplitter.join();
    stopper.stop(null);
    if (regionChecker.ex != null) {
        throw new AssertionError("regionChecker", regionChecker.ex);
    }
    if (regionSplitter.ex != null) {
        throw new AssertionError("regionSplitter", regionSplitter.ex);
    }
    //one final check
    regionChecker.verify();
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ChoreService(org.apache.hadoop.hbase.ChoreService) StoppableImplementation(org.apache.hadoop.hbase.util.StoppableImplementation) Stoppable(org.apache.hadoop.hbase.Stoppable) Test(org.junit.Test)

Example 9 with Stoppable

use of org.apache.hadoop.hbase.Stoppable in project hbase by apache.

the class TestServerNonceManager method createStoppable.

private Stoppable createStoppable() {
    Stoppable s = Mockito.mock(Stoppable.class);
    Mockito.when(s.isStopped()).thenReturn(false);
    return s;
}
Also used : Stoppable(org.apache.hadoop.hbase.Stoppable)

Example 10 with Stoppable

use of org.apache.hadoop.hbase.Stoppable in project hbase by apache.

the class TestServerNonceManager method testStopWaiting.

@Test
public void testStopWaiting() throws Exception {
    final ServerNonceManager nm = createManager();
    nm.setConflictWaitIterationMs(1);
    Stoppable stoppingStoppable = createStoppable();
    Mockito.when(stoppingStoppable.isStopped()).thenAnswer(new Answer<Boolean>() {

        AtomicInteger answer = new AtomicInteger(3);

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return 0 < answer.decrementAndGet();
        }
    });
    nm.startOperation(NO_NONCE, 1, createStoppable());
    TestRunnable tr = new TestRunnable(nm, 1, null, stoppingStoppable);
    Thread t = tr.start();
    waitForThreadToBlockOrExit(t);
    // thread must eventually throw
    t.join();
    tr.propagateError();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Stoppable(org.apache.hadoop.hbase.Stoppable) Test(org.junit.Test)

Aggregations

Stoppable (org.apache.hadoop.hbase.Stoppable)20 Test (org.junit.Test)19 Configuration (org.apache.hadoop.conf.Configuration)17 StoppableImplementation (org.apache.hadoop.hbase.util.StoppableImplementation)11 FileSystem (org.apache.hadoop.fs.FileSystem)10 Path (org.apache.hadoop.fs.Path)10 InvocationOnMock (org.mockito.invocation.InvocationOnMock)8 ExecutorService (java.util.concurrent.ExecutorService)7 Abortable (org.apache.hadoop.hbase.Abortable)7 RegionCoprocessorEnvironment (org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment)7 StubAbortable (org.apache.phoenix.hbase.index.StubAbortable)7 HashMap (java.util.HashMap)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)5 Mutation (org.apache.hadoop.hbase.client.Mutation)5 Put (org.apache.hadoop.hbase.client.Put)5 ImmutableBytesPtr (org.apache.phoenix.hbase.index.util.ImmutableBytesPtr)5 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 FileStatus (org.apache.hadoop.fs.FileStatus)3