Search in sources :

Example 46 with WaitCriterion

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

the class ConcurrentMapOpsDUnitTest method dotestConcOps.

private void dotestConcOps(final boolean emptyClient) {
    Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(2);
    int port1 = createRegionsAndStartServer(server);
    createClientRegion(client, port1, emptyClient, -1);
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            r.registerInterestRegex(".*");
            pr.registerInterestRegex(".*");
            return null;
        }
    });
    server.invoke(new SerializableCallable() {

        public Object call() {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            r.put("key0", "value");
            pr.put("key0", "value");
            assertNull(r.putIfAbsent("keyForNull", null));
            assertNull(pr.putIfAbsent("keyForNull", null));
            assertEquals("value", r.putIfAbsent("key0", null));
            assertEquals("value", pr.putIfAbsent("key0", null));
            assertTrue(r.containsKey("keyForNull"));
            assertTrue(pr.containsKey("keyForNull"));
            assertFalse(r.containsValueForKey("keyForNull"));
            assertFalse(pr.containsValueForKey("keyForNull"));
            r.put("key0", "value");
            pr.put("key0", "value");
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            WaitCriterion wc = new WaitCriterion() {

                AssertionError e = null;

                public boolean done() {
                    try {
                        if (!emptyClient) {
                            assertTrue(r.containsKey("key0"));
                            assertTrue(pr.containsKey("key0"));
                            assertTrue(r.containsKey("keyForNull"));
                            assertTrue(pr.containsKey("keyForNull"));
                            assertFalse(r.containsValueForKey("keyForNull"));
                            assertFalse(pr.containsValueForKey("keyForNull"));
                        }
                        assertEquals("value", r.putIfAbsent("key0", null));
                        assertEquals("value", pr.putIfAbsent("key0", null));
                        assertNull(r.putIfAbsent("keyForNull", null));
                        assertNull(pr.putIfAbsent("keyForNull", null));
                        assertNull(r.putIfAbsent("clientNullKey", null));
                        assertNull(pr.putIfAbsent("clientNullKey", null));
                    } catch (AssertionError ex) {
                        r.getCache().getLoggerI18n().fine("SWAP:caught ", ex);
                        e = ex;
                        return false;
                    }
                    return true;
                }

                public String description() {
                    return "timeout " + e;
                }
            };
            Wait.waitForCriterion(wc, 30000, 1000, true);
            return null;
        }
    });
    server.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            assertTrue(r.containsKey("clientNullKey"));
            assertTrue(pr.containsKey("clientNullKey"));
            assertFalse(r.containsValueForKey("clientNullKey"));
            assertFalse(pr.containsValueForKey("clientNullKey"));
            assertNotNull(r.replace("key0", "value2"));
            assertNotNull(pr.replace("key0", "value2"));
            assertTrue(r.replace("keyForNull", null, "newValue"));
            assertTrue(pr.replace("keyForNull", null, "newValue"));
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            WaitCriterion wc = new WaitCriterion() {

                AssertionError e = null;

                public boolean done() {
                    try {
                        assertEquals("value2", r.putIfAbsent("key0", null));
                        assertEquals("value2", pr.putIfAbsent("key0", null));
                        assertEquals("newValue", r.putIfAbsent("keyForNull", null));
                        assertEquals("newValue", pr.putIfAbsent("keyForNull", null));
                        // replace from client
                        assertEquals("value2", r.replace("key0", "value"));
                        assertEquals("value2", pr.replace("key0", "value"));
                        assertNull(r.replace("NoKeyOnServer", "value"));
                        assertNull(r.replace("NoKeyOnServer", "value"));
                        assertTrue(r.replace("clientNullKey", null, "newValue"));
                        assertTrue(pr.replace("clientNullKey", null, "newValue"));
                    } catch (AssertionError ex) {
                        e = ex;
                        return false;
                    }
                    return true;
                }

                public String description() {
                    return "timeout " + e.getMessage();
                }
            };
            Wait.waitForCriterion(wc, 30000, 1000, true);
            return null;
        }
    });
    server.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            final Region r = getCache().getRegion(REP_REG_NAME);
            final Region pr = getCache().getRegion(PR_REG_NAME);
            assertEquals("newValue", r.get("clientNullKey"));
            assertEquals("newValue", pr.get("clientNullKey"));
            return null;
        }
    });
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) InvalidDeltaException(org.apache.geode.InvalidDeltaException) IOException(java.io.IOException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Example 47 with WaitCriterion

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

the class FixedPRSinglehopDUnitTest method verifyMetadata.

private void verifyMetadata(final int totalBuckets, int currentRedundancy) {
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return (regionMetaData.size() == 1);
        }

        public String description() {
            return "expected no metadata to be refreshed";
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    wc = new WaitCriterion() {

        public boolean done() {
            return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == totalBuckets);
        }

        public String description() {
            return "expected no metadata to be refreshed.  Expected " + totalBuckets + " entries but found " + prMetaData.getBucketServerLocationsMap_TEST_ONLY();
        }
    };
    Wait.waitForCriterion(wc, 60000, 1000, true);
    System.out.println("metadata is " + prMetaData);
    System.out.println("metadata bucket locations map is " + prMetaData.getBucketServerLocationsMap_TEST_ONLY());
    for (Map.Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals("list has wrong contents: " + entry.getValue(), currentRedundancy, ((List) entry.getValue()).size());
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor) Map(java.util.Map)

Example 48 with WaitCriterion

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

the class SingleHopGetAllPutAllDUnitTest method verifyMetadata.

private static void verifyMetadata() {
    Region region = cache.getRegion(PartitionedRegionName);
    ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
    cms.getClientPRMetadata((LocalRegion) region);
    final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return (regionMetaData.size() == 1);
        }

        public String description() {
            return "Region metadat size is not 1. Exisitng size of regionMetaData is " + regionMetaData.size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    assertTrue(regionMetaData.containsKey(region.getFullPath()));
    final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
    wc = new WaitCriterion() {

        public boolean done() {
            return (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 13);
        }

        public String description() {
            return "Bucket server location map size is not 13. Exisitng size is :" + prMetaData.getBucketServerLocationsMap_TEST_ONLY().size();
        }
    };
    Wait.waitForCriterion(wc, 5000, 200, true);
    for (Entry entry : prMetaData.getBucketServerLocationsMap_TEST_ONLY().entrySet()) {
        assertEquals(2, ((List) entry.getValue()).size());
    }
}
Also used : Entry(java.util.Map.Entry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClientMetadataService(org.apache.geode.cache.client.internal.ClientMetadataService) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) ClientPartitionAdvisor(org.apache.geode.cache.client.internal.ClientPartitionAdvisor)

Example 49 with WaitCriterion

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

the class TestFunction method executeHA.

public void executeHA(FunctionContext context) {
    RegionFunctionContext rcontext = (RegionFunctionContext) context;
    Region region = rcontext.getDataSet();
    region.getCache().getLogger().fine("executeHA#execute( " + rcontext + " )");
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            return false;
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 10000, 500, false);
    rcontext.getResultSender().lastResult((Serializable) rcontext.getArguments());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext)

Example 50 with WaitCriterion

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

the class HASlowReceiverDUnitTest method checkRedundancyLevel.

public static void checkRedundancyLevel(final Integer redundantServers) {
    WaitCriterion wc = new WaitCriterion() {

        public boolean done() {
            return pool.getRedundantNames().size() == redundantServers.intValue();
        }

        public String description() {
            return "Expected redundant count (" + pool.getRedundantNames().size() + ") to become " + redundantServers.intValue();
        }
    };
    Wait.waitForCriterion(wc, 200 * 1000, 1000, 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