HBASE-16640 TimeoutBlockingQueue#remove() should return whether the entry is removed
This commit is contained in:
parent
8c4b09dfba
commit
e782d0bbdf
|
@ -615,9 +615,10 @@ public class ProcedureExecutor<TEnvironment> {
|
|||
/**
|
||||
* Remove a chore procedure from the executor
|
||||
* @param chore the chore to remove
|
||||
* @return whether the chore is removed
|
||||
*/
|
||||
public void removeChore(final ProcedureInMemoryChore chore) {
|
||||
waitingTimeout.remove(chore);
|
||||
public boolean removeChore(final ProcedureInMemoryChore chore) {
|
||||
return waitingTimeout.remove(chore);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,15 +92,17 @@ public class TimeoutBlockingQueue<E> {
|
|||
}
|
||||
}
|
||||
|
||||
public void remove(E e) {
|
||||
public boolean remove(E e) {
|
||||
if (e == null) return false;
|
||||
lock.lock();
|
||||
try {
|
||||
for (int i = 0; i < objects.length; ++i) {
|
||||
if (objects[i] == e) {
|
||||
if (e.equals(objects[i])) {
|
||||
objects[i] = null;
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
|
|
@ -137,18 +137,21 @@ public class TestTimeoutBlockingQueue {
|
|||
TimeoutBlockingQueue<TestObject> queue =
|
||||
new TimeoutBlockingQueue<TestObject>(2, new TestObjectTimeoutRetriever());
|
||||
|
||||
TestObject[] objs = new TestObject[5];
|
||||
for (int i = 0; i < objs.length; ++i) {
|
||||
final int effectiveLen = 5;
|
||||
TestObject[] objs = new TestObject[6];
|
||||
for (int i = 0; i < effectiveLen; ++i) {
|
||||
objs[i] = new TestObject(0, i * 10);
|
||||
queue.add(objs[i]);
|
||||
}
|
||||
objs[effectiveLen] = new TestObject(0, effectiveLen * 10);
|
||||
queue.dump();
|
||||
|
||||
for (int i = 0; i < objs.length; i += 2) {
|
||||
queue.remove(objs[i]);
|
||||
for (int i = 0; i < effectiveLen; i += 2) {
|
||||
assertTrue(queue.remove(objs[i]));
|
||||
}
|
||||
assertTrue(!queue.remove(objs[effectiveLen]));
|
||||
|
||||
for (int i = 0; i < objs.length; ++i) {
|
||||
for (int i = 0; i < effectiveLen; ++i) {
|
||||
TestObject x = queue.poll();
|
||||
assertEquals((i % 2) == 0 ? null : objs[i], x);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue