use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.
the class TestVisibilityLabelsWithDefaultVisLabelService method testAddVisibilityLabelsOnRSRestart.
@Test(timeout = 60 * 1000)
public void testAddVisibilityLabelsOnRSRestart() throws Exception {
List<RegionServerThread> regionServerThreads = TEST_UTIL.getHBaseCluster().getRegionServerThreads();
for (RegionServerThread rsThread : regionServerThreads) {
rsThread.getRegionServer().abort("Aborting ");
}
// Start one new RS
RegionServerThread rs = TEST_UTIL.getHBaseCluster().startRegionServer();
waitForLabelsRegionAvailability(rs.getRegionServer());
final AtomicBoolean vcInitialized = new AtomicBoolean(true);
do {
PrivilegedExceptionAction<VisibilityLabelsResponse> action = new PrivilegedExceptionAction<VisibilityLabelsResponse>() {
public VisibilityLabelsResponse run() throws Exception {
String[] labels = { SECRET, CONFIDENTIAL, PRIVATE, "ABC", "XYZ" };
try (Connection conn = ConnectionFactory.createConnection(conf)) {
VisibilityLabelsResponse resp = VisibilityClient.addLabels(conn, labels);
List<RegionActionResult> results = resp.getResultList();
if (results.get(0).hasException()) {
NameBytesPair pair = results.get(0).getException();
Throwable t = ProtobufUtil.toException(pair);
LOG.debug("Got exception writing labels", t);
if (t instanceof VisibilityControllerNotReadyException) {
vcInitialized.set(false);
LOG.warn("VisibilityController was not yet initialized");
Threads.sleep(10);
} else {
vcInitialized.set(true);
}
} else
LOG.debug("new labels added: " + resp);
} catch (Throwable t) {
throw new IOException(t);
}
return null;
}
};
SUPERUSER.runAs(action);
} while (!vcInitialized.get());
// Scan the visibility label
Scan s = new Scan();
s.setAuthorizations(new Authorizations(VisibilityUtils.SYSTEM_LABEL));
int i = 0;
try (Table ht = TEST_UTIL.getConnection().getTable(LABELS_TABLE_NAME);
ResultScanner scanner = ht.getScanner(s)) {
while (true) {
Result next = scanner.next();
if (next == null) {
break;
}
i++;
}
}
// One label is the "system" label.
Assert.assertEquals("The count should be 13", 13, i);
}
use of java.util.concurrent.atomic.AtomicBoolean in project hive by apache.
the class HiveMetaStore method main.
/**
* @param args
*/
public static void main(String[] args) throws Throwable {
HiveConf.setLoadMetastoreConfig(true);
final HiveConf conf = new HiveConf(HMSHandler.class);
HiveMetastoreCli cli = new HiveMetastoreCli(conf);
cli.parse(args);
final boolean isCliVerbose = cli.isVerbose();
// NOTE: It is critical to do this prior to initializing log4j, otherwise
// any log specific settings via hiveconf will be ignored
Properties hiveconf = cli.addHiveconfToSystemProperties();
// use Hive's default log4j configuration
if (System.getProperty("log4j.configurationFile") == null) {
// before any of the other core hive classes are loaded
try {
LogUtils.initHiveLog4j();
} catch (LogInitializationException e) {
HMSHandler.LOG.warn(e.getMessage());
}
}
HiveStringUtils.startupShutdownMessage(HiveMetaStore.class, args, LOG);
try {
String msg = "Starting hive metastore on port " + cli.port;
HMSHandler.LOG.info(msg);
if (cli.isVerbose()) {
System.err.println(msg);
}
// set all properties specified on the command line
for (Map.Entry<Object, Object> item : hiveconf.entrySet()) {
conf.set((String) item.getKey(), (String) item.getValue());
}
// Add shutdown hook.
ShutdownHookManager.addShutdownHook(new Runnable() {
@Override
public void run() {
String shutdownMsg = "Shutting down hive metastore.";
HMSHandler.LOG.info(shutdownMsg);
if (isCliVerbose) {
System.err.println(shutdownMsg);
}
if (conf.getBoolVar(ConfVars.METASTORE_METRICS)) {
try {
MetricsFactory.close();
} catch (Exception e) {
LOG.error("error in Metrics deinit: " + e.getClass().getName() + " " + e.getMessage(), e);
}
}
}
});
//Start Metrics for Standalone (Remote) Mode
if (conf.getBoolVar(ConfVars.METASTORE_METRICS)) {
try {
MetricsFactory.init(conf);
} catch (Exception e) {
// log exception, but ignore inability to start
LOG.error("error in Metrics init: " + e.getClass().getName() + " " + e.getMessage(), e);
}
}
Lock startLock = new ReentrantLock();
Condition startCondition = startLock.newCondition();
AtomicBoolean startedServing = new AtomicBoolean();
startMetaStoreThreads(conf, startLock, startCondition, startedServing);
startMetaStore(cli.getPort(), ShimLoader.getHadoopThriftAuthBridge(), conf, startLock, startCondition, startedServing);
} catch (Throwable t) {
// Catch the exception, log it and rethrow it.
HMSHandler.LOG.error("Metastore Thrift Server threw an exception...", t);
throw t;
}
}
use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.
the class TestExecutorService method testExecutorService.
@Test
public void testExecutorService() throws Exception {
int maxThreads = 5;
int maxTries = 10;
int sleepInterval = 10;
Server mockedServer = mock(Server.class);
when(mockedServer.getConfiguration()).thenReturn(HBaseConfiguration.create());
// Start an executor service pool with max 5 threads
ExecutorService executorService = new ExecutorService("unit_test");
executorService.startExecutorService(ExecutorType.MASTER_SERVER_OPERATIONS, maxThreads);
Executor executor = executorService.getExecutor(ExecutorType.MASTER_SERVER_OPERATIONS);
ThreadPoolExecutor pool = executor.threadPoolExecutor;
// Assert no threads yet
assertEquals(0, pool.getPoolSize());
AtomicBoolean lock = new AtomicBoolean(true);
AtomicInteger counter = new AtomicInteger(0);
// Submit maxThreads executors.
for (int i = 0; i < maxThreads; i++) {
executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
}
// The TestEventHandler will increment counter when it starts.
int tries = 0;
while (counter.get() < maxThreads && tries < maxTries) {
LOG.info("Waiting for all event handlers to start...");
Thread.sleep(sleepInterval);
tries++;
}
// Assert that pool is at max threads.
assertEquals(maxThreads, counter.get());
assertEquals(maxThreads, pool.getPoolSize());
ExecutorStatus status = executor.getStatus();
assertTrue(status.queuedEvents.isEmpty());
assertEquals(5, status.running.size());
checkStatusDump(status);
// Now interrupt the running Executor
synchronized (lock) {
lock.set(false);
lock.notifyAll();
}
// Executor increments counter again on way out so.... test that happened.
while (counter.get() < (maxThreads * 2) && tries < maxTries) {
System.out.println("Waiting for all event handlers to finish...");
Thread.sleep(sleepInterval);
tries++;
}
assertEquals(maxThreads * 2, counter.get());
assertEquals(maxThreads, pool.getPoolSize());
// Make sure we don't get RejectedExecutionException.
for (int i = 0; i < (2 * maxThreads); i++) {
executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
}
// Now interrupt the running Executor
synchronized (lock) {
lock.set(false);
lock.notifyAll();
}
// Make sure threads are still around even after their timetolive expires.
Thread.sleep(ExecutorService.Executor.keepAliveTimeInMillis * 2);
assertEquals(maxThreads, pool.getPoolSize());
executorService.shutdown();
assertEquals(0, executorService.getAllExecutorStatuses().size());
// Test that submit doesn't throw NPEs
executorService.submit(new TestEventHandler(mockedServer, EventType.M_SERVER_SHUTDOWN, lock, counter));
}
use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.
the class TestTaskMonitor method testTasksGetAbortedOnLeak.
@Test
public void testTasksGetAbortedOnLeak() throws InterruptedException {
final TaskMonitor tm = new TaskMonitor();
assertTrue("Task monitor should start empty", tm.getTasks().isEmpty());
final AtomicBoolean threadSuccess = new AtomicBoolean(false);
// Make a task in some other thread and leak it
Thread t = new Thread() {
@Override
public void run() {
MonitoredTask task = tm.createStatus("Test task");
assertEquals(MonitoredTask.State.RUNNING, task.getState());
threadSuccess.set(true);
}
};
t.start();
t.join();
// Make sure the thread saw the correct state
assertTrue(threadSuccess.get());
// Make sure the leaked reference gets cleared
System.gc();
System.gc();
System.gc();
// Now it should be aborted
MonitoredTask taskFromTm = tm.getTasks().get(0);
assertEquals(MonitoredTask.State.ABORTED, taskFromTm.getState());
}
use of java.util.concurrent.atomic.AtomicBoolean in project hbase by apache.
the class TestHRegion method testParallelAppendWithMemStoreFlush.
/**
* Test case to check append function with memstore flushing
* @throws Exception
*/
@Test
public void testParallelAppendWithMemStoreFlush() throws Exception {
byte[] family = Appender.family;
this.region = initHRegion(tableName, method, CONF, family);
final HRegion region = this.region;
final AtomicBoolean appendDone = new AtomicBoolean(false);
Runnable flusher = new Runnable() {
@Override
public void run() {
while (!appendDone.get()) {
try {
region.flush(true);
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
// After all append finished, the value will append to threadNum *
// appendCounter Appender.CHAR
int threadNum = 20;
int appendCounter = 100;
byte[] expected = new byte[threadNum * appendCounter];
for (int i = 0; i < threadNum * appendCounter; i++) {
System.arraycopy(Appender.CHAR, 0, expected, i, 1);
}
Thread[] appenders = new Thread[threadNum];
Thread flushThread = new Thread(flusher);
for (int i = 0; i < threadNum; i++) {
appenders[i] = new Thread(new Appender(this.region, appendCounter));
appenders[i].start();
}
flushThread.start();
for (int i = 0; i < threadNum; i++) {
appenders[i].join();
}
appendDone.set(true);
flushThread.join();
Get get = new Get(Appender.appendRow);
get.addColumn(Appender.family, Appender.qualifier);
get.setMaxVersions(1);
Result res = this.region.get(get);
List<Cell> kvs = res.getColumnCells(Appender.family, Appender.qualifier);
// we just got the latest version
assertEquals(kvs.size(), 1);
Cell kv = kvs.get(0);
byte[] appendResult = new byte[kv.getValueLength()];
System.arraycopy(kv.getValueArray(), kv.getValueOffset(), appendResult, 0, kv.getValueLength());
assertArrayEquals(expected, appendResult);
this.region = null;
}
Aggregations