use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class BucketAdvisor method waitForStorage.
// seconds
public boolean waitForStorage() {
synchronized (this) {
// let's park this thread and wait for storage!
StopWatch timer = new StopWatch(true);
try {
for (; ; ) {
if (this.regionAdvisor.isBucketLocal(getBucket().getId())) {
return true;
}
getProxyBucketRegion().getPartitionedRegion().checkReadiness();
if (isClosed()) {
return false;
}
long timeLeft = BUCKET_STORAGE_WAIT - timer.elapsedTimeMillis();
if (timeLeft <= 0) {
return false;
}
if (logger.isDebugEnabled()) {
logger.debug("Waiting for bucket storage" + this);
}
// spurious wakeup ok
this.wait(timeLeft);
}
} catch (InterruptedException e) {
// abort and return null
Thread.currentThread().interrupt();
}
return false;
}
}
use of org.apache.geode.internal.util.StopWatch in project geode by apache.
the class QueueManagerJUnitTest method testWaitForPrimary.
@Test
public void testWaitForPrimary() throws Exception {
factory.addConnection(0, 0, 1);
manager = new QueueManagerImpl(pool, endpoints, source, factory, 2, 20, logger, ClientProxyMembershipID.getNewProxyMembership(ds));
manager.start(background);
manager.getAllConnections().getPrimary().destroy();
try {
manager.getAllConnections().getPrimary();
fail("Should have received NoQueueServersAvailableException");
} catch (NoSubscriptionServersAvailableException expected) {
// do thing
}
factory.addConnection(0, 0, 2);
factory.addConnection(0, 0, 3);
boolean done = false;
try {
for (StopWatch time = new StopWatch(true); !done && time.elapsedTimeMillis() < 11 * 1000; ) {
Thread.sleep(200);
try {
manager.getAllConnections();
done = true;
} catch (NoSubscriptionServersAvailableException e) {
// done = false;
}
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
assertTrue("getAllConnections still throwing NoSubscriptionServersAvailableException", done);
assertPortEquals(2, manager.getAllConnections().getPrimary());
}
Aggregations