Search in sources :

Example 36 with StopWatch

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;
    }
}
Also used : StopWatch(org.apache.geode.internal.util.StopWatch)

Example 37 with StopWatch

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());
}
Also used : NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) StopWatch(org.apache.geode.internal.util.StopWatch) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

StopWatch (org.apache.geode.internal.util.StopWatch)37 Test (org.junit.Test)13 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)9 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)4 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)4 File (java.io.File)3 IOException (java.io.IOException)3 Properties (java.util.Properties)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Statistics (org.apache.geode.Statistics)2 Region (org.apache.geode.cache.Region)2 FailureTracker (org.apache.geode.cache.client.internal.ServerBlackList.FailureTracker)2 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)2 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)2 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)2 MemberMXBean (org.apache.geode.management.MemberMXBean)2 CliMetaData (org.apache.geode.management.cli.CliMetaData)2 MXBeanProvider.getMemberMXBean (org.apache.geode.management.internal.cli.shell.MXBeanProvider.getMemberMXBean)2 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)2