Search in sources :

Example 56 with WaitCriterion

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

the class ClientServerMiscDUnitTest method verifyInvalidatesOnBothRegions.

public static void verifyInvalidatesOnBothRegions() {
    try {
        Cache cache = new ClientServerMiscDUnitTest().getCache();
        final Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
        final Region r2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
        assertNotNull(r1);
        assertNotNull(r2);
        WaitCriterion wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r1.getEntry(k1).getValue();
                return val == null;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 90 * 1000, 1000, true);
        // assertNull(r1.getEntry(k1).getValue());
        wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r1.getEntry(k1).getValue();
                return val == null;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 90 * 1000, 1000, true);
        // assertNull(r1.getEntry(k2).getValue());
        wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r1.getEntry(k2).getValue();
                return val == null;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 90 * 1000, 1000, true);
        // assertNull(r2.getEntry(k1).getValue());
        wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r2.getEntry(k1).getValue();
                return val == null;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 90 * 1000, 1000, true);
        // assertNull(r2.getEntry(k2).getValue());
        wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r2.getEntry(k2).getValue();
                return val == null;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 90 * 1000, 1000, true);
    } catch (Exception ex) {
        Assert.fail("failed while verifyInvalidatesOnBothRegions()", ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) GemFireIOException(org.apache.geode.GemFireIOException) GemFireConfigException(org.apache.geode.GemFireConfigException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache)

Example 57 with WaitCriterion

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

the class ClientServerMiscDUnitTest method _createClientCache.

public static Pool _createClientCache(String h, boolean empty, int... ports) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    Cache cache = new ClientServerMiscDUnitTest().createCacheV(props);
    ClientServerMiscDUnitTest.static_cache = cache;
    PoolFactory poolFactory = PoolManager.createFactory();
    PoolImpl p = (PoolImpl) addServers(poolFactory, h, ports).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerMiscDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    if (empty) {
        factory.setDataPolicy(DataPolicy.EMPTY);
    }
    factory.setPoolName(p.getName());
    attrs = factory.create();
    Region region1 = cache.createRegion(REGION_NAME1, attrs);
    Region region2 = cache.createRegion(REGION_NAME2, attrs);
    Region prRegion = cache.createRegion(PR_REGION_NAME, attrs);
    assertNotNull(region1);
    assertNotNull(region2);
    assertNotNull(prRegion);
    pool = p;
    // conn = pool.acquireConnection();
    // assertNotNull(conn);
    // TODO does this WaitCriterion actually help?
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            try {
                conn = pool.acquireConnection();
                if (conn == null) {
                    excuse = "acquireConnection returned null?";
                    return false;
                }
                return true;
            } catch (NoAvailableServersException e) {
                excuse = "Cannot find a server: " + e;
                return false;
            }
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
    return p;
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Cache(org.apache.geode.cache.Cache)

Example 58 with WaitCriterion

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

the class ConflationDUnitTest method assertCounterSizes.

/**
   * assert the counters size are as expected (2)
   *
   */
public static void assertCounterSizes() {
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterCreate == 2;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
    ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterUpdate == 2;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
    ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterDestroy == 2;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 59 with WaitCriterion

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

the class ConnectionProxyJUnitTest method verifyAckSend.

private void verifyAckSend(long timeToWait, final boolean expectedAckSend) {
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return expectedAckSend == seo.getAckSend();
        }

        public String description() {
            return "ack flag never became " + expectedAckSend;
        }
    };
    Wait.waitForCriterion(wc, timeToWait, 1000, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 60 with WaitCriterion

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

the class ConnectionProxyJUnitTest method verifyExpiry.

private void verifyExpiry(long timeToWait) {
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return 0 == proxy.getThreadIdToSequenceIdMap().size();
        }

        public String description() {
            return "Entry never expired";
        }
    };
    Wait.waitForCriterion(wc, timeToWait * 2, 200, 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