use of java.util.concurrent.FutureTask in project double-espresso by JakeWharton.
the class AppNotIdleExceptionTest method testAppIdleException.
public void testAppIdleException() throws Exception {
final AtomicBoolean continueBeingBusy = new AtomicBoolean(true);
try {
final Handler handler = new Handler(Looper.getMainLooper());
Runnable runnable = new Runnable() {
@Override
public void run() {
if (!continueBeingBusy.get()) {
return;
} else {
handler.post(this);
}
}
};
FutureTask<Void> task = new FutureTask<Void>(runnable, null);
handler.post(task);
// Will Make sure that the first post is sent before we do a lookup.
task.get();
// Request the "hello world!" text by clicking on the request button.
onView(withId(R.id.request_button)).perform(click());
fail("Espresso failed to throw AppNotIdleException");
} catch (AppNotIdleException e) {
// Do Nothing. Test pass.
continueBeingBusy.getAndSet(false);
}
}
use of java.util.concurrent.FutureTask in project geode by apache.
the class IndexManager method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
sb.append(ind).append(getLineSeparator());
}
return sb.toString();
}
use of java.util.concurrent.FutureTask in project geode by apache.
the class IndexManager method processAction.
/**
* @param opCode one of IndexProtocol.OTHER_OP, BEFORE_UPDATE_OP, AFTER_UPDATE_OP.
*/
private void processAction(RegionEntry entry, int action, int opCode) throws QueryException {
final long startPA = getCachePerfStats().startIndexUpdate();
DefaultQuery.setPdxReadSerialized(this.region.getCache(), true);
TXStateProxy tx = null;
if (!((InternalCache) this.region.getCache()).isClient()) {
tx = ((TXManagerImpl) this.region.getCache().getCacheTransactionManager()).internalSuspend();
}
try {
// creation thread
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook is set.");
}
// ConcurrentIndexInitOnOverflowRegionDUnitTest
testHook.hook(6);
}
long start = 0;
boolean indexLockAcquired = false;
switch(action) {
case ADD_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in ADD_ENTRY.");
}
testHook.hook(5);
}
// this action is only called after update
assert opCode == IndexProtocol.OTHER_OP;
// Asif The behaviour can arise if an index creation has already
// acted upon a newly added entry , but by the time callback
// occurs , the index is added to the map & thus
// the add operation will now have an effect of update.
// so we need to remove the mapping even if it is an Add action
// as otherwise the new results will get added into the
// old results instead of replacement
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
// apply IMQ on it
if (!index.containsEntry(entry)) {
if (logger.isDebugEnabled()) {
logger.debug("Adding to index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.addIndexMapping(entry);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
}
break;
}
case UPDATE_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in UPDATE_ENTRY.");
}
testHook.hook(5);
// QueryDataInconsistencyDUnitTest
testHook.hook(9);
}
// this action is only called with opCode AFTER_UPDATE_OP
assert opCode == IndexProtocol.AFTER_UPDATE_OP;
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
if (logger.isDebugEnabled()) {
logger.debug("Updating index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.addIndexMapping(entry);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
break;
}
case REMOVE_ENTRY:
{
if (IndexManager.testHook != null) {
if (logger.isDebugEnabled()) {
logger.debug("IndexManager TestHook in REMOVE_ENTRY.");
}
testHook.hook(5);
testHook.hook(10);
}
Iterator iter = this.indexes.values().iterator();
while (iter.hasNext()) {
Object ind = iter.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
IndexProtocol index = (IndexProtocol) ind;
if (((AbstractIndex) index).isPopulated() && index.getType() != IndexType.PRIMARY_KEY) {
AbstractIndex abstractIndex = (AbstractIndex) index;
if (logger.isDebugEnabled()) {
logger.debug("Removing from index: {}{} value: {}", index.getName(), this.region.getFullPath(), entry.getKey());
}
start = ((AbstractIndex) index).updateIndexUpdateStats();
index.removeIndexMapping(entry, opCode);
((AbstractIndex) index).updateIndexUpdateStats(start);
}
}
break;
}
default:
{
throw new IndexMaintenanceException(LocalizedStrings.IndexManager_INVALID_ACTION.toLocalizedString());
}
}
} finally {
DefaultQuery.setPdxReadSerialized(this.region.getCache(), false);
if (tx != null) {
((TXManagerImpl) this.region.getCache().getCacheTransactionManager()).internalResume(tx);
}
getCachePerfStats().endIndexUpdate(startPA);
}
}
use of java.util.concurrent.FutureTask in project geode by apache.
the class IndexManager method getIndexes.
/*
* private static int getMatchLevel(String fromClause, String iFromClause) { if
* (fromClause.equals(iFromClause)) return 0; if (fromClause.startsWith(iFromClause)) { int cnt =
* -1; int index = fromClause.indexOf(',', iFromClause.length() + 1); while (index > 0) { cnt--;
* index = fromClause.indexOf(',', index + 1); } return cnt; } else if
* (iFromClause.startsWith(fromClause)) { int cnt = 1; int index = iFromClause.indexOf(',',
* fromClause.length() + 1); while (index > 0) { cnt++; index = iFromClause.indexOf(',', index +
* 1); } return cnt; } //No compatible return Integer.MAX_VALUE; }
*/
/**
* Get a collection of all the indexes. If the IndexType is specified returns only the matching
* indexes.
*
* @param indexType the type of indexes to get. Currently must be Indexable.FUNCTIONAL_SORTED
* @return the collection of indexes for the specified region and type
*/
public Collection getIndexes(IndexType indexType) {
ArrayList list = new ArrayList();
Iterator it = this.indexes.values().iterator();
while (it.hasNext()) {
Object ind = it.next();
// the index is in create phase.
if (ind instanceof FutureTask) {
continue;
}
Index index = (Index) ind;
// Check if indexType needs to be matched.
if (indexType == null || index.getType() == indexType) {
// No type check.
list.add(index);
}
}
return list;
}
use of java.util.concurrent.FutureTask in project android_frameworks_base by crdroidandroid.
the class MtpManagerTest method testCancelEvent.
public void testCancelEvent() throws Exception {
final CancellationSignal signal = new CancellationSignal();
final FutureTask<Boolean> future = new FutureTask<Boolean>(new Callable<Boolean>() {
@Override
public Boolean call() throws IOException {
try {
while (true) {
mManager.readEvent(mUsbDevice.getDeviceId(), signal);
}
} catch (OperationCanceledException exception) {
return true;
}
}
});
final Thread thread = new Thread(future);
thread.start();
SystemClock.sleep(TIMEOUT_MS);
signal.cancel();
assertTrue(future.get(TIMEOUT_MS, TimeUnit.MILLISECONDS));
}
Aggregations