Java Code Examples for org.apache.hadoop.hbase.Stoppable

The following examples show how to use org.apache.hadoop.hbase.Stoppable. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: phoenix   Source File: TestParalleWriterIndexCommitter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter(VersionInfo.getVersion());
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example 2
Source Project: phoenix   Source File: TestParalleIndexWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter(VersionInfo.getVersion());
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example 3
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter();
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example 4
Source Project: hbase   Source File: HFileCleaner.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * For creating customized HFileCleaner.
 * @param name name of the chore being run
 * @param period the period of time to sleep between each run
 * @param stopper the stopper
 * @param conf configuration to use
 * @param fs handle to the FS
 * @param directory directory to be cleaned
 * @param confKey configuration key for the classes to instantiate
 * @param pool the thread pool used to scan directories
 * @param params params could be used in subclass of BaseHFileCleanerDelegate
 */
public HFileCleaner(String name, int period, Stoppable stopper, Configuration conf, FileSystem fs,
  Path directory, String confKey, DirScanPool pool, Map<String, Object> params) {
  super(name, period, stopper, conf, fs, directory, confKey, pool, params);
  throttlePoint =
    conf.getInt(HFILE_DELETE_THROTTLE_THRESHOLD, DEFAULT_HFILE_DELETE_THROTTLE_THRESHOLD);
  largeQueueInitSize =
    conf.getInt(LARGE_HFILE_QUEUE_INIT_SIZE, DEFAULT_LARGE_HFILE_QUEUE_INIT_SIZE);
  smallQueueInitSize =
    conf.getInt(SMALL_HFILE_QUEUE_INIT_SIZE, DEFAULT_SMALL_HFILE_QUEUE_INIT_SIZE);
  largeFileQueue = new StealJobQueue<>(largeQueueInitSize, smallQueueInitSize, COMPARATOR);
  smallFileQueue = largeFileQueue.getStealFromQueue();
  largeFileDeleteThreadNumber =
    conf.getInt(LARGE_HFILE_DELETE_THREAD_NUMBER, DEFAULT_LARGE_HFILE_DELETE_THREAD_NUMBER);
  smallFileDeleteThreadNumber =
    conf.getInt(SMALL_HFILE_DELETE_THREAD_NUMBER, DEFAULT_SMALL_HFILE_DELETE_THREAD_NUMBER);
  cleanerThreadTimeoutMsec =
    conf.getLong(HFILE_DELETE_THREAD_TIMEOUT_MSEC, DEFAULT_HFILE_DELETE_THREAD_TIMEOUT_MSEC);
  cleanerThreadCheckIntervalMsec = conf.getLong(HFILE_DELETE_THREAD_CHECK_INTERVAL_MSEC,
    DEFAULT_HFILE_DELETE_THREAD_CHECK_INTERVAL_MSEC);
  startHFileDeleteThreads();
}
 
Example 5
Source Project: phoenix   Source File: TestParalleWriterIndexCommitter.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, Table> emptyMap());
  TrackingParallelWriterIndexCommitter writer = new TrackingParallelWriterIndexCommitter(VersionInfo.getVersion());
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  RegionCoprocessorEnvironment e =Mockito.mock(RegionCoprocessorEnvironment.class);
  Configuration conf =new Configuration();
  Mockito.when(e.getConfiguration()).thenReturn(conf);
  Mockito.when(e.getSharedData()).thenReturn(new ConcurrentHashMap<String,Object>());
  // create a simple writer
  writer.setup(factory, exec, mockStop, e);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockStop);
}
 
Example 6
Source Project: hbase   Source File: TestSnapshotCleanerChore.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotCleanerWithSomeTtlExpired() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  List<SnapshotProtos.SnapshotDescription> snapshotDescriptionList = new ArrayList<>();
  snapshotDescriptionList.add(getSnapshotDescription(10, "snapshot01", "table01", 1));
  snapshotDescriptionList.add(getSnapshotDescription(5, "snapshot02", "table02", 2));
  snapshotDescriptionList.add(getSnapshotDescription(30, "snapshot01", "table01",
          EnvironmentEdgeManager.currentTime()));
  snapshotDescriptionList.add(getSnapshotDescription(0, "snapshot02", "table02",
          EnvironmentEdgeManager.currentTime()));
  snapshotDescriptionList.add(getSnapshotDescription(40, "snapshot03", "table03",
          EnvironmentEdgeManager.currentTime()));
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenReturn(snapshotDescriptionList);
  try {
    LOG.info("5 Snapshots are completed. TTL is expired for 2 them. Going to delete them");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(2)).deleteSnapshot(Mockito.any());
}
 
Example 7
Source Project: hbase   Source File: TestSnapshotCleanerChore.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotCleanerWithReadIOE() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = new HBaseTestingUtility().getConfiguration();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenThrow(IOException.class);
  try {
    LOG.info("While getting completed Snapshots, IOException would occur. Hence, No Snapshot"
            + " should be deleted");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(0)).deleteSnapshot(Mockito.any());
}
 
Example 8
Source Project: hbase   Source File: TestSnapshotCleanerChore.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testSnapshotChoreWithTtlOutOfRange() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  List<SnapshotProtos.SnapshotDescription> snapshotDescriptionList = new ArrayList<>();
  snapshotDescriptionList.add(getSnapshotDescription(Long.MAX_VALUE, "snapshot01", "table01", 1));
  snapshotDescriptionList.add(getSnapshotDescription(5, "snapshot02", "table02", 2));
  Mockito.when(snapshotManager.getCompletedSnapshots()).thenReturn(snapshotDescriptionList);
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  try {
    LOG.info("Snapshot Chore is disabled. No cleanup performed for Expired Snapshots");
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(1)).getCompletedSnapshots();
}
 
Example 9
@Test
public void testCorrectlyCleansUpResources() throws Exception{
  ExecutorService exec = Executors.newFixedThreadPool(1);
  FakeTableFactory factory = new FakeTableFactory(
      Collections.<ImmutableBytesPtr, HTableInterface> emptyMap());
  ParallelWriterIndexCommitter writer = new ParallelWriterIndexCommitter();
  Abortable mockAbort = Mockito.mock(Abortable.class);
  Stoppable mockStop = Mockito.mock(Stoppable.class);
  // create a simple writer
  writer.setup(factory, exec, mockAbort, mockStop, 1);
  // stop the writer
  writer.stop(this.test.getTableNameString() + " finished");
  assertTrue("Factory didn't get shutdown after writer#stop!", factory.shutdown);
  assertTrue("ExectorService isn't terminated after writer#stop!", exec.isShutdown());
  Mockito.verifyZeroInteractions(mockAbort, mockStop);
}
 
Example 10
Source Project: hbase   Source File: TestCleanerChore.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testStoppedCleanerDoesNotDeleteFiles() 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, POOL);

  // also create a file in the top level directory
  Path topFile = new Path(testDir, "topFile");
  fs.create(topFile).close();
  assertTrue("Test file didn't get created.", fs.exists(topFile));

  // stop the chore
  stop.stop("testing stop");

  // run the chore
  chore.chore();

  // test that the file still exists
  assertTrue("File got deleted while chore was stopped", fs.exists(topFile));
}
 
Example 11
Source Project: hbase   Source File: TestMasterRegionWALCleaner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void postSetUp() throws IOException {
  Configuration conf = htu.getConfiguration();
  conf.setLong(TimeToLiveMasterLocalStoreWALCleaner.TTL_CONF_KEY, TTL_MS);
  Path testDir = htu.getDataTestDir();
  FileSystem fs = testDir.getFileSystem(conf);
  globalWALArchiveDir = new Path(testDir, HConstants.HREGION_OLDLOGDIR_NAME);
  logCleaner = new LogCleaner(1000, new Stoppable() {

    private volatile boolean stopped = false;

    @Override
    public void stop(String why) {
      stopped = true;
    }

    @Override
    public boolean isStopped() {
      return stopped;
    }
  }, conf, fs, globalWALArchiveDir, cleanerPool);
  choreService.scheduleChore(logCleaner);
}
 
Example 12
Source Project: hbase   Source File: TestMasterRegionCompaction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void postSetUp() throws IOException {
  Configuration conf = htu.getConfiguration();
  conf.setLong(TimeToLiveMasterLocalStoreHFileCleaner.TTL_CONF_KEY, 5000);
  Path testDir = htu.getDataTestDir();
  FileSystem fs = testDir.getFileSystem(conf);
  Path globalArchivePath = HFileArchiveUtil.getArchivePath(conf);
  hfileCleaner = new HFileCleaner(500, new Stoppable() {

    private volatile boolean stopped = false;

    @Override
    public void stop(String why) {
      stopped = true;
    }

    @Override
    public boolean isStopped() {
      return stopped;
    }
  }, conf, fs, globalArchivePath, cleanerPool);
  choreService.scheduleChore(hfileCleaner);
}
 
Example 13
Source Project: hbase   Source File: TestServerNonceManager.java    License: Apache License 2.0 6 votes vote down vote up
@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();
}
 
Example 14
Source Project: phoenix   Source File: StoreFailuresInCachePolicy.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setup(Stoppable parent, RegionCoprocessorEnvironment env) {
  this.region = env.getRegion();
  this.delegate = new KillServerOnFailurePolicy();
  this.delegate.setup(parent, env);

}
 
Example 15
/**
 * Setup <tt>this</tt>.
 * <p>
 * Exposed for TESTING
 */
void setup(HTableFactory factory, ExecutorService pool, Abortable abortable, Stoppable stop, int cacheSize) {
    this.pool = new WaitForCompletionTaskRunner(pool);
    this.factory = new CachingHTableFactory(factory, cacheSize);
    this.abortable = new CapturingAbortable(abortable);
    this.stopped = stop;
}
 
Example 16
/**
 * Setup <tt>this</tt>.
 * <p>
 * Exposed for TESTING
 */
public void setup(HTableFactory factory, ExecutorService pool,Stoppable stop, RegionCoprocessorEnvironment env) {
    this.retryingFactory = factory;
    this.noRetriesFactory = IndexWriterUtils.getNoRetriesHTableFactory(env);
    this.pool = new QuickFailingTaskRunner(pool);
    this.stopped = stop;
    this.env = env;
}
 
Example 17
Source Project: hbase   Source File: RegionsRecoveryChore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Construct RegionsRecoveryChore with provided params
 *
 * @param stopper When {@link Stoppable#isStopped()} is true, this chore will cancel and cleanup
 * @param configuration The configuration params to be used
 * @param hMaster HMaster instance to initiate RegionTableRegions
 */
RegionsRecoveryChore(final Stoppable stopper, final Configuration configuration,
    final HMaster hMaster) {

  super(REGIONS_RECOVERY_CHORE_NAME, stopper, configuration.getInt(
    HConstants.REGIONS_RECOVERY_INTERVAL, HConstants.DEFAULT_REGIONS_RECOVERY_INTERVAL));
  this.hMaster = hMaster;
  this.storeFileRefCountThreshold = configuration.getInt(
    HConstants.STORE_FILE_REF_COUNT_THRESHOLD,
    HConstants.DEFAULT_STORE_FILE_REF_COUNT_THRESHOLD);

}
 
Example 18
/**
 * Setup <tt>this</tt>.
 * <p>
 * Exposed for TESTING
 */
void setup(HTableFactory factory, ExecutorService pool, Abortable abortable, Stoppable stop,
    int cacheSize) {
  this.factory = new CachingHTableFactory(factory, cacheSize);
  this.pool = new QuickFailingTaskRunner(pool);
  this.stopped = stop;
}
 
Example 19
Source Project: hbase   Source File: LogCleaner.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param period the period of time to sleep between each run
 * @param stopper the stopper
 * @param conf configuration to use
 * @param fs handle to the FS
 * @param oldLogDir the path to the archived logs
 * @param pool the thread pool used to scan directories
 */
public LogCleaner(final int period, final Stoppable stopper, Configuration conf, FileSystem fs,
  Path oldLogDir, DirScanPool pool) {
  super("LogsCleaner", period, stopper, conf, fs, oldLogDir, HBASE_MASTER_LOGCLEANER_PLUGINS,
    pool);
  this.pendingDelete = new LinkedBlockingQueue<>();
  int size = conf.getInt(OLD_WALS_CLEANER_THREAD_SIZE, DEFAULT_OLD_WALS_CLEANER_THREAD_SIZE);
  this.oldWALsCleaner = createOldWalsCleaner(size);
  this.cleanerThreadTimeoutMsec = conf.getLong(OLD_WALS_CLEANER_THREAD_TIMEOUT_MSEC,
    DEFAULT_OLD_WALS_CLEANER_THREAD_TIMEOUT_MSEC);
}
 
Example 20
Source Project: hbase   Source File: CleanerChore.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param name name of the chore being run
 * @param sleepPeriod the period of time to sleep between each run
 * @param s the stopper
 * @param conf configuration to use
 * @param fs handle to the FS
 * @param oldFileDir the path to the archived files
 * @param confKey configuration key for the classes to instantiate
 * @param pool the thread pool used to scan directories
 * @param params members could be used in cleaner
 */
public CleanerChore(String name, final int sleepPeriod, final Stoppable s, Configuration conf,
  FileSystem fs, Path oldFileDir, String confKey, DirScanPool pool, Map<String, Object> params) {
  super(name, s, sleepPeriod);

  Preconditions.checkNotNull(pool, "Chore's pool can not be null");
  this.pool = pool;
  this.fs = fs;
  this.oldFileDir = oldFileDir;
  this.conf = conf;
  this.params = params;
  initCleanerChain(confKey);
}
 
Example 21
Source Project: hbase   Source File: ReplicationBarrierCleaner.java    License: Apache License 2.0 5 votes vote down vote up
public ReplicationBarrierCleaner(Configuration conf, Stoppable stopper, Connection conn,
    ReplicationPeerManager peerManager) {
  super("ReplicationBarrierCleaner", stopper, conf.getInt(REPLICATION_BARRIER_CLEANER_INTERVAL,
    DEFAULT_REPLICATION_BARRIER_CLEANER_INTERVAL));
  this.conn = conn;
  this.peerManager = peerManager;
}
 
Example 22
Source Project: hbase   Source File: HRegionServer.java    License: Apache License 2.0 5 votes vote down vote up
CompactionChecker(final HRegionServer h, final int sleepTime, final Stoppable stopper) {
  super("CompactionChecker", stopper, sleepTime);
  this.instance = h;
  LOG.info(this.getName() + " runs every " + Duration.ofMillis(sleepTime));

  /* MajorCompactPriority is configurable.
   * If not set, the compaction will use default priority.
   */
  this.majorCompactPriority = this.instance.conf.
      getInt("hbase.regionserver.compactionChecker.majorCompactPriority",
          DEFAULT_PRIORITY);
}
 
Example 23
Source Project: hbase   Source File: HRegionServer.java    License: Apache License 2.0 5 votes vote down vote up
static MovedRegionsCleaner create(HRegionServer rs){
  Stoppable stoppable = new Stoppable() {
    private volatile boolean isStopped = false;
    @Override public void stop(String why) { isStopped = true;}
    @Override public boolean isStopped() {return isStopped;}
  };

  return new MovedRegionsCleaner(rs, stoppable);
}
 
Example 24
Source Project: hbase   Source File: ShutdownHook.java    License: Apache License 2.0 5 votes vote down vote up
ShutdownHookThread(final Configuration conf, final Stoppable stop,
    final Thread threadToJoin, final Runnable fsShutdownHook) {
  super("Shutdownhook:" + threadToJoin.getName());
  this.stop = stop;
  this.threadToJoin = threadToJoin;
  this.conf = conf;
  this.fsShutdownHook = fsShutdownHook;
}
 
Example 25
Source Project: hbase   Source File: ServerNonceManager.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a scheduled chore that is used to clean up old nonces.
 * @param stoppable Stoppable for the chore.
 * @return ScheduledChore; the scheduled chore is not started.
 */
public ScheduledChore createCleanupScheduledChore(Stoppable stoppable) {
  // By default, it will run every 6 minutes (30 / 5).
  return new ScheduledChore("nonceCleaner", stoppable, deleteNonceGracePeriod / 5) {
    @Override
    protected void chore() {
      cleanUpOldNonces();
    }
  };
}
 
Example 26
Source Project: hbase   Source File: CompactedHFilesDischarger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param period the period of time to sleep between each run
 * @param stopper the stopper
 * @param regionServerServices the region server that starts this chore
 */
public CompactedHFilesDischarger(final int period, final Stoppable stopper,
    final RegionServerServices regionServerServices) {
  // Need to add the config classes
  super("CompactedHFilesCleaner", stopper, period);
  this.regionServerServices = regionServerServices;
}
 
Example 27
Source Project: hbase   Source File: CompactedHFilesDischarger.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param period the period of time to sleep between each run
 * @param stopper the stopper
 * @param regionServerServices the region server that starts this chore
 * @param useExecutor true if to use the region server's executor service, false otherwise
 */
@VisibleForTesting
public CompactedHFilesDischarger(final int period, final Stoppable stopper,
    final RegionServerServices regionServerServices, boolean useExecutor) {
  // Need to add the config classes
  this(period, stopper, regionServerServices);
  this.useExecutor = useExecutor;
}
 
Example 28
@Override
public void setup(Stoppable parent, RegionCoprocessorEnvironment env) {
  this.region = env.getRegion();
  this.delegate = new KillServerOnFailurePolicy();
  this.delegate.setup(parent, env);

}
 
Example 29
Source Project: hbase   Source File: TestSnapshotCleanerChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSnapshotCleanerWithoutAnyCompletedSnapshot() throws IOException {
  snapshotManager = Mockito.mock(SnapshotManager.class);
  Stoppable stopper = new StoppableImplementation();
  Configuration conf = getSnapshotCleanerConf();
  SnapshotCleanerChore snapshotCleanerChore =
          new SnapshotCleanerChore(stopper, conf, snapshotManager);
  try {
    snapshotCleanerChore.chore();
  } finally {
    stopper.stop("Stopping Test Stopper");
  }
  Mockito.verify(snapshotManager, Mockito.times(0)).deleteSnapshot(Mockito.any());
}
 
Example 30
Source Project: hbase   Source File: TestCleanerChore.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testSavesFilesOnRequest() 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, NeverDelete.class.getName());

  AllValidPaths chore =
    new AllValidPaths("test-file-cleaner", stop, conf, fs, testDir, confKey, POOL);

  // create the directory layout in the directory to clean
  Path parent = new Path(testDir, "parent");
  Path file = new Path(parent, "someFile");
  fs.mkdirs(parent);
  // 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 were preserved
  assertTrue("File shouldn't have been deleted", fs.exists(file));
  assertTrue("directory shouldn't have been deleted", fs.exists(parent));
}