Search in sources :

Example 6 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ConnectionPoolDUnitTest method verifyBalanced.

public void verifyBalanced(final PoolImpl pool, int expectedServer, final int expectedConsPerServer) {
    verifyServerCount(pool, expectedServer);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return balanced(pool, expectedConsPerServer);
        }

        public String description() {
            return "expected " + expectedConsPerServer + " but endpoints=" + outOfBalanceReport(pool);
        }
    };
    Wait.waitForCriterion(ev, 2 * 60 * 1000, 200, true);
    assertEquals("expected " + expectedConsPerServer + " but endpoints=" + outOfBalanceReport(pool), true, balanced(pool, expectedConsPerServer));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 7 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ConnectionPoolDUnitTest method test022ClientRegisterUnregisterRequests.

@Test
public void test022ClientRegisterUnregisterRequests() throws CacheException {
    final String regionName1 = this.getName() + "-1";
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM client = host.getVM(2);
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.REPLICATE);
            factory.setConcurrencyChecksEnabled(false);
            createRegion(regionName1, factory.create());
            // pause(1000);
            try {
                startBridgeServer(0);
            } catch (Exception ex) {
                org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
            }
        }
    };
    // Create server1.
    server1.invoke(createServer);
    final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    SerializableRunnable createPool = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            getLonerSystem();
            getCache();
            Region region1 = null;
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            regionFactory.setConcurrencyChecksEnabled(false);
            ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, true, -1, -1, null);
            region1 = createRegion(regionName1, regionFactory.create());
            region1.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
        }
    };
    // Create client.
    client.invoke(createPool);
    // Init values at server.
    server1.invoke(new CacheSerializableRunnable("Create values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 20; i++) {
                region1.put("key-string-" + i, "value-" + i);
            }
        }
    });
    // Put some values on the client.
    client.invoke(new CacheSerializableRunnable("Put values client") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            for (int i = 0; i < 10; i++) {
                region1.put("key-string-" + i, "client-value-" + i);
            }
        }
    });
    SerializableRunnable closePool = new CacheSerializableRunnable("Close Pool") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regionName1);
            String pName = region1.getAttributes().getPoolName();
            region1.localDestroyRegion();
            PoolImpl p = (PoolImpl) PoolManager.find(pName);
            p.destroy();
        }
    };
    client.invoke(closePool);
    SerializableRunnable validateClientRegisterUnRegister = new CacheSerializableRunnable("validate Client Register UnRegister") {

        public void run2() throws CacheException {
            for (Iterator bi = getCache().getCacheServers().iterator(); bi.hasNext(); ) {
                CacheServerImpl bsi = (CacheServerImpl) bi.next();
                final CacheClientNotifierStats ccnStats = bsi.getAcceptor().getCacheClientNotifier().getStats();
                WaitCriterion ev = new WaitCriterion() {

                    public boolean done() {
                        return ccnStats.getClientRegisterRequests() == ccnStats.getClientUnRegisterRequests();
                    }

                    public String description() {
                        return null;
                    }
                };
                Wait.waitForCriterion(ev, 62 * 1000, 200, true);
                assertEquals("HealthMonitor Client Register/UnRegister mismatch.", ccnStats.getClientRegisterRequests(), ccnStats.getClientUnRegisterRequests());
            }
        }
    };
    server1.invoke(validateClientRegisterUnRegister);
    server1.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) Endpoint(org.apache.geode.cache.client.internal.Endpoint) CacheClientNotifierStats(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifierStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Iterator(java.util.Iterator) LocalRegion(org.apache.geode.internal.cache.LocalRegion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 8 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class Bug35214DUnitTest method testNoEntryExpireDuringGII.

/**
   * make sure entries do not expire during a GII
   */
@Test
public void testNoEntryExpireDuringGII() throws Exception {
    initOtherVm();
    AsyncInvocation updater = null;
    try {
        updater = updateOtherVm();
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable e1) {
        Assert.fail("failed due to " + e1, e1);
    }
    System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
    org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 30;
    callbackFailure = false;
    try {
        AttributesFactory af = new AttributesFactory();
        af.setDataPolicy(DataPolicy.REPLICATE);
        af.setScope(Scope.DISTRIBUTED_ACK);
        af.setStatisticsEnabled(true);
        af.setEntryIdleTimeout(new ExpirationAttributes(1, ExpirationAction.INVALIDATE));
        CacheListener cl1 = new CacheListenerAdapter() {

            public void afterRegionCreate(RegionEvent re) {
                afterRegionCreateSeen = true;
            }

            public void afterInvalidate(EntryEvent e) {
                callbackAssertTrue("afterregionCreate not seen", afterRegionCreateSeen);
                // make sure region is initialized
                callbackAssertTrue("not initialized", ((LocalRegion) e.getRegion()).isInitialized());
                expirationCount++;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        af.addCacheListener(cl1);
        final Region r1 = createRootRegion("r1", af.create());
        ThreadUtils.join(updater, 60 * 1000);
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return r1.values().size() == 0;
            }

            public String description() {
                return "region never became empty";
            }
        };
        Wait.waitForCriterion(ev, 2 * 1000, 200, true);
        {
            assertEquals(0, r1.values().size());
            assertEquals(ENTRY_COUNT, r1.keySet().size());
        }
    } finally {
        org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
        System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
        assertEquals(null, System.getProperty(LocalRegion.EXPIRY_MS_PROPERTY));
    }
    assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) ExpirationAttributes(org.apache.geode.cache.ExpirationAttributes) RegionEvent(org.apache.geode.cache.RegionEvent) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 9 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class CqQueryTestListener method waitForCqsConnectedEvents.

public boolean waitForCqsConnectedEvents(final int total) {
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return (CqQueryTestListener.this.cqsConnectedCount == total);
        }

        public String description() {
            return "Did not receive expected number of calls to cqsConnected() " + CqQueryTestListener.this.cqName + " expected: " + total + " receieved: " + CqQueryTestListener.this.cqsConnectedCount;
        }
    };
    Wait.waitForCriterion(ev, MAX_TIME, 200, true);
    return true;
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 10 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class CqQueryTestListener method waitForUpdated.

public boolean waitForUpdated(final Object key) {
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return CqQueryTestListener.this.updates.contains(key);
        }

        public String description() {
            return "never got update event for CQ " + CqQueryTestListener.this.cqName;
        }
    };
    Wait.waitForCriterion(ev, MAX_TIME, 200, true);
    return true;
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Aggregations

WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)368 Test (org.junit.Test)132 Region (org.apache.geode.cache.Region)105 VM (org.apache.geode.test.dunit.VM)96 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)93 Host (org.apache.geode.test.dunit.Host)73 LocalRegion (org.apache.geode.internal.cache.LocalRegion)58 CacheException (org.apache.geode.cache.CacheException)57 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)53 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)41 IgnoredException (org.apache.geode.test.dunit.IgnoredException)40 IOException (java.io.IOException)36 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)36 Cache (org.apache.geode.cache.Cache)34 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)33 Properties (java.util.Properties)31 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)28 Iterator (java.util.Iterator)27