Search in sources :

Example 6 with CertifiableTestCacheListener

use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.

the class CqDataDUnitTest method testCQWithEviction.

/**
   * Test for CQ when entries are evicted from region.
   * 
   * @throws Exception
   */
@Test
public void testCQWithEviction() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM client = host.getVM(2);
    final int evictionThreshold = 1;
    server1.invoke(new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            factory.setDataPolicy(DataPolicy.REPLICATE);
            // factory.setMirrorType(MirrorType.NONE);
            // setting the eviction attributes.
            EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(evictionThreshold, EvictionAction.OVERFLOW_TO_DISK);
            factory.setEvictionAttributes(evictAttrs);
            for (int i = 0; i < cqDUnitTest.regions.length; i++) {
                Region region = createRegion(cqDUnitTest.regions[i], factory.createRegionAttributes());
                // Set CacheListener.
                region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
            }
            Wait.pause(2000);
            try {
                cqDUnitTest.startBridgeServer(0, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    });
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    cqDUnitTest.createClient(client, port1, host0);
    // Create CQs.
    cqDUnitTest.createCQ(client, "testCQWithEviction_0", cqDUnitTest.cqs[0]);
    final int size = 10;
    // CREATE VALUES.
    cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
    cqDUnitTest.executeCQ(client, "testCQWithEviction_0", false, "CqException");
    Wait.pause(1 * 1000);
    // Update VALUES.
    cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
    for (int i = 1; i <= size; i++) {
        cqDUnitTest.waitForUpdated(client, "testCQWithEviction_0", cqDUnitTest.KEY + i);
    }
    cqDUnitTest.validateCQ(client, "testCQWithEviction_0", cqDUnitTest.noTest, 0, 10, 0);
    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server1);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) CacheException(org.apache.geode.cache.CacheException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with CertifiableTestCacheListener

use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.

the class CQListGIIDUnitTest method registerInterestListCQ.

public static void registerInterestListCQ(String regionName, int keySize) {
    // Get CQ Service.
    Region region = null;
    try {
        region = cache.getRegion("root").getSubregion(regionName);
        region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
    } catch (Exception e) {
        fail("Failed to get Region.", e);
    }
    try {
        List list = new ArrayList();
        for (int i = 1; i <= keySize; i++) {
            list.add(KEY + i);
        }
        region.registerInterest(list);
    } catch (Exception ex) {
        fail("Failed to Register InterestList", ex);
    }
}
Also used : CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 8 with CertifiableTestCacheListener

use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.

the class DestroyEntryPropagationDUnitTest method createServerCache.

private static Integer createServerCache() throws Exception {
    new DestroyEntryPropagationDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setNotifyBySubscription(true);
    server.start();
    return new Integer(server.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 9 with CertifiableTestCacheListener

use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.

the class DestroyEntryPropagationDUnitTest method createClientCache.

private static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
    int PORT1 = port1.intValue();
    int PORT2 = port2.intValue();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new DestroyEntryPropagationDUnitTest().createCache(props);
    CacheServerTestUtil.disableShufflingOfEndpoints();
    Pool p;
    try {
        p = PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(4).create("EntryPropagationDUnitTestPool");
    } finally {
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setPoolName(p.getName());
    factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) Pool(org.apache.geode.cache.client.Pool) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 10 with CertifiableTestCacheListener

use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.

the class CqQueryUsingPoolDUnitTest method testRegionDestroy.

/**
   * This will test the events after region destory. The CQs on the destroy region needs to be
   * closed.
   */
@Test
public void testRegionDestroy() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    /* Init Server and Client */
    createServer(server);
    final int thePort = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    String poolName = "testRegionDestroy";
    createPool(client, poolName, host0, thePort);
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, poolName, "testRegionDestroy_0", cqs[0]);
    createCQ(client, poolName, "testRegionDestroy_1", cqs[0]);
    createCQ(client, poolName, "testRegionDestroy_2", cqs[0]);
    executeCQ(client, "testRegionDestroy_0", false, null);
    executeCQ(client, "testRegionDestroy_1", false, null);
    executeCQ(client, "testRegionDestroy_2", false, null);
    /* Init values at server. */
    final int size = 10;
    registerInterestListCQ(client, regions[0], size, false);
    createValues(server, regions[0], size);
    // Wait for client to Synch.
    waitForCreated(client, "testRegionDestroy_0", KEY + 10);
    // validate CQs.
    validateCQ(client, "testRegionDestroy_0", /* resultSize: */
    noTest, /* creates: */
    size, /* updates: */
    noTest, /* deletes; */
    noTest, /* queryInserts: */
    size, /* queryUpdates: */
    0, /* queryDeletes: */
    0, /* totalEvents: */
    size);
    // Validate InterestList.
    // CREATE
    client.invoke(new CacheSerializableRunnable("validate updates") {

        @Override
        public void run2() throws CacheException {
            // Wait for the region to become the correct size
            WaitCriterion wc = new WaitCriterion() {

                String excuse;

                @Override
                public boolean done() {
                    Region region = getRootRegion().getSubregion(regions[0]);
                    if (region == null) {
                        excuse = "Can't find region";
                        return false;
                    }
                    int sz = region.entrySet().size();
                    if (sz != size) {
                        excuse = "Region is of size " + sz + ", expected " + size;
                        return false;
                    }
                    return true;
                }

                @Override
                public String description() {
                    return excuse;
                }
            };
            Wait.waitForCriterion(wc, 30 * 1000, 250, true);
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
            for (int i = 1; i <= 10; i++) {
                ctl.waitForCreated(KEY + i);
                assertNotNull(region.getEntry(KEY + i));
            }
        }
    });
    // Destroy Region.
    server.invoke(new CacheSerializableRunnable("Destroy Region") {

        @Override
        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            region1.destroyRegion();
        }
    });
    Wait.pause(2 * 1000);
    validateCQCount(client, 0);
    closeClient(client);
    closeServer(server);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

CertifiableTestCacheListener (org.apache.geode.cache30.CertifiableTestCacheListener)23 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)19 Region (org.apache.geode.cache.Region)14 VM (org.apache.geode.test.dunit.VM)14 Host (org.apache.geode.test.dunit.Host)12 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)12 Test (org.junit.Test)12 IOException (java.io.IOException)11 CacheException (org.apache.geode.cache.CacheException)11 ArrayList (java.util.ArrayList)9 List (java.util.List)9 LocalRegion (org.apache.geode.internal.cache.LocalRegion)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 CancelException (org.apache.geode.CancelException)6 Endpoint (org.apache.geode.cache.client.internal.Endpoint)6 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)6 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)6 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)5 LinkedList (java.util.LinkedList)4