Search in sources :

Example 1 with VM

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

the class CqQueryDUnitTest method testCqCloseAndExecuteWithInitialResults.

@Test
public void testCqCloseAndExecuteWithInitialResults() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    createServer(server);
    final int thePort = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    createClient(client, thePort, host0);
    /* CQ Test with initial Values. */
    int size = 5;
    createValuesWithShort(server, regions[0], size);
    Wait.pause(1 * 500);
    // Create CQs.
    executeAndCloseAndExecuteIRMultipleTimes(client, "testCQResultSet_0", shortTypeCQs[0]);
    closeClient(client);
    closeServer(server);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 2 with VM

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

the class CqQueryDUnitTest 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(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, "testRegionDestroy_0", cqs[0]);
    createCQ(client, "testRegionDestroy_1", cqs[0]);
    createCQ(client, "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);
    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") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            Set keys = region.entrySet();
            assertEquals("Mismatch, number of keys in local region is not equal to the interest list size", size, keys.size());
            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") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            region1.destroyRegion();
        }
    });
    Wait.pause(4 * 1000);
    validateCQCount(client, 0);
    closeClient(client);
    closeServer(server);
}
Also used : Set(java.util.Set) 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) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) 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)

Example 3 with VM

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

the class CqQueryDUnitTest method testCQFailOver.

/**
   * Test for CQ Fail over.
   * 
   * @throws Exception
   */
@Test
public void testCQFailOver() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    createServer(server1);
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    // Create client.
    // Properties props = new Properties();
    // Create client with redundancyLevel -1
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    createClient(client, new int[] { port1, ports[0] }, host0, "-1");
    int numCQs = 1;
    for (int i = 0; i < numCQs; i++) {
        // Create CQs.
        createCQ(client, "testCQFailOver_" + i, cqs[i]);
        executeCQ(client, "testCQFailOver_" + i, false, null);
    }
    Wait.pause(1 * 1000);
    // CREATE.
    createValues(server1, regions[0], 10);
    createValues(server1, regions[1], 10);
    waitForCreated(client, "testCQFailOver_0", KEY + 10);
    Wait.pause(1 * 1000);
    createServer(server2, ports[0]);
    final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    System.out.println("### Port on which server1 running : " + port1 + " Server2 running : " + thePort2);
    Wait.pause(3 * 1000);
    // Extra pause - added after downmerging trunk r17050
    Wait.pause(5 * 1000);
    // UPDATE - 1.
    createValues(server1, regions[0], 10);
    createValues(server1, regions[1], 10);
    waitForUpdated(client, "testCQFailOver_0", KEY + 10);
    int[] resultsCnt = new int[] { 10, 1, 2 };
    for (int i = 0; i < numCQs; i++) {
        validateCQ(client, "testCQFailOver_" + i, noTest, resultsCnt[i], resultsCnt[i], noTest);
    }
    // Close server1.
    closeServer(server1);
    // Fail over should happen.
    Wait.pause(3 * 1000);
    for (int i = 0; i < numCQs; i++) {
        validateCQ(client, "testCQFailOver_" + i, noTest, resultsCnt[i], resultsCnt[i], noTest);
    }
    // UPDATE - 2
    this.clearCQListenerEvents(client, "testCQFailOver_0");
    createValues(server2, regions[0], 10);
    createValues(server2, regions[1], 10);
    for (int i = 1; i <= 10; i++) {
        waitForUpdated(client, "testCQFailOver_0", KEY + i);
    }
    for (int i = 0; i < numCQs; i++) {
        validateCQ(client, "testCQFailOver_" + i, noTest, resultsCnt[i], resultsCnt[i] * 2, noTest);
    }
    // Close.
    closeClient(client);
    closeServer(server2);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 4 with VM

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

the class CqQueryDUnitTest method testInterestListAndCQs.

/**
   * Test for InterestList and CQ registered from same clients.
   * 
   * @throws Exception
   */
@Test
public void testInterestListAndCQs() 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(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    createClient(client, thePort, host0);
    /* Create CQs. */
    createCQ(client, "testInterestListAndCQs_0", cqs[0]);
    validateCQCount(client, 1);
    /* Init values at server. */
    final int size = 10;
    executeCQ(client, "testInterestListAndCQs_0", false, null);
    registerInterestListCQ(client, regions[0], size);
    createValues(server, regions[0], size);
    for (int i = 1; i <= 10; i++) {
        waitForCreated(client, "testInterestListAndCQs_0", KEY + i);
    }
    // validate CQs.
    validateCQ(client, "testInterestListAndCQs_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") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            Set keys = region.entrySet();
            assertEquals("Mismatch, number of keys in local region is not equal to the interest list size", size, keys.size());
            CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
            for (int i = 1; i <= 10; i++) {
                ctl.waitForCreated(KEY + i);
                assertNotNull(region.getEntry(KEY + i));
            }
        }
    });
    // UPDATE
    createValues(server, regions[0], size);
    // Wait for client to Synch.
    for (int i = 1; i <= 10; i++) {
        waitForUpdated(client, "testInterestListAndCQs_0", KEY + i);
    }
    client.invoke(new CacheSerializableRunnable("validate updates") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            Set keys = region.entrySet();
            assertEquals("Mismatch, number of keys in local region is not equal to the interest list size", size, keys.size());
            CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
            for (int i = 1; i <= 10; i++) {
                ctl.waitForUpdated(KEY + i);
                assertNotNull(region.getEntry(KEY + i));
            }
        }
    });
    // INVALIDATE
    server.invoke(new CacheSerializableRunnable("Invalidate values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 1; i <= size; i++) {
                region1.invalidate(KEY + i);
            }
        }
    });
    waitForInvalidated(client, "testInterestListAndCQs_0", KEY + 10);
    client.invoke(new CacheSerializableRunnable("validate invalidates") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            Set keys = region.entrySet();
            assertEquals("Mismatch, number of keys in local region is not equal to the interest list size", size, keys.size());
            CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
            for (int i = 1; i <= 10; i++) {
                ctl.waitForInvalidated(KEY + i);
                assertNotNull(region.getEntry(KEY + i));
            }
        }
    });
    validateCQ(client, "testInterestListAndCQs_0", /* resultSize: */
    noTest, /* creates: */
    size, /* updates: */
    size, /* deletes; */
    noTest, /* queryInserts: */
    size, /* queryUpdates: */
    size, /* queryDeletes: */
    size, /* totalEvents: */
    size * 3);
    // DESTROY - this should not have any effect on CQ, as the events are
    // already destroyed from invalidate events.
    server.invoke(new CacheSerializableRunnable("Invalidate values") {

        public void run2() throws CacheException {
            Region region1 = getRootRegion().getSubregion(regions[0]);
            for (int i = 1; i <= size; i++) {
                region1.destroy(KEY + i);
            }
        }
    });
    // Wait for destroyed.
    client.invoke(new CacheSerializableRunnable("validate destroys") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regions[0]);
            assertNotNull(region);
            CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
            for (int i = 1; i <= 10; i++) {
                ctl.waitForDestroyed(KEY + i);
            }
        }
    });
    validateCQ(client, "testInterestListAndCQs_0", /* resultSize: */
    noTest, /* creates: */
    size, /* updates: */
    size, /* deletes; */
    noTest, /* queryInserts: */
    size, /* queryUpdates: */
    size, /* queryDeletes: */
    size, /* totalEvents: */
    size * 3);
    closeClient(client);
    closeServer(server);
}
Also used : Set(java.util.Set) 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) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) 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)

Example 5 with VM

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

the class CqQueryDUnitTest method testGetCQsForARegionName.

/**
   * Test getCQs for a regions
   */
@Test
public void testGetCQsForARegionName() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    createServer(server);
    final int thePort = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    createClient(client, thePort, host0);
    // Create CQs.
    createCQ(client, "testQuery_3", cqs[3]);
    executeCQ(client, "testQuery_3", true, null);
    createCQ(client, "testQuery_4", cqs[4]);
    executeCQ(client, "testQuery_4", true, null);
    createCQ(client, "testQuery_5", cqs[5]);
    executeCQ(client, "testQuery_5", true, null);
    createCQ(client, "testQuery_6", cqs[6]);
    executeCQ(client, "testQuery_6", true, null);
    // with regions[1]
    createCQ(client, "testQuery_7", cqs[7]);
    executeCQ(client, "testQuery_7", true, null);
    createCQ(client, "testQuery_8", cqs[8]);
    executeCQ(client, "testQuery_8", true, null);
    client.invoke(new CacheSerializableRunnable("Client disableCQs()") {

        public void run2() throws CacheException {
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
                CqQuery[] cq = cqService.getCqs("/root/" + regions[0]);
                assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[0], cq);
                getCache().getLogger().info("cqs for region: /root/" + regions[0] + " : " + cq.length);
                // closing on of the cqs.
                cq[0].close();
                cq = cqService.getCqs("/root/" + regions[0]);
                assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[0], cq);
                getCache().getLogger().info("cqs for region: /root/" + regions[0] + " after closeing one of the cqs : " + cq.length);
                cq = cqService.getCqs("/root/" + regions[1]);
                getCache().getLogger().info("cqs for region: /root/" + regions[1] + " : " + cq.length);
                assertNotNull("CQservice should not return null for cqs on this region : /root/" + regions[1], cq);
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService", cqe);
            }
        }
    });
    // Close.
    closeClient(client);
    closeServer(server);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) CqExistsException(org.apache.geode.cache.query.CqExistsException) RegionNotFoundException(org.apache.geode.cache.query.RegionNotFoundException) CqClosedException(org.apache.geode.cache.query.CqClosedException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

VM (org.apache.geode.test.dunit.VM)1674 Test (org.junit.Test)1356 Host (org.apache.geode.test.dunit.Host)1314 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1283 Region (org.apache.geode.cache.Region)568 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)453 CacheException (org.apache.geode.cache.CacheException)428 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)407 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)326 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)312 AttributesFactory (org.apache.geode.cache.AttributesFactory)304 Cache (org.apache.geode.cache.Cache)265 IgnoredException (org.apache.geode.test.dunit.IgnoredException)254 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)216 IOException (java.io.IOException)204 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)186 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)178 LocalRegion (org.apache.geode.internal.cache.LocalRegion)162 ArrayList (java.util.ArrayList)140 Properties (java.util.Properties)135