Search in sources :

Example 11 with SerializableRunnable

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

the class CqQueryDUnitTest method testForSupportedRegionAttributes.

/**
   * Tests execution of queries with NULL in where clause like where ID = NULL etc.
   * 
   * @throws Exception
   */
@Test
public void testForSupportedRegionAttributes() throws Exception {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client = host.getVM(2);
    // Create server with Global scope.
    SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
            // Create region with Global scope
            AttributesFactory factory1 = new AttributesFactory();
            factory1.setScope(Scope.GLOBAL);
            factory1.setMirrorType(MirrorType.KEYS_VALUES);
            createRegion(regions[0], factory1.createRegionAttributes());
            // Create region with non Global, distributed_ack scope
            AttributesFactory factory2 = new AttributesFactory();
            factory2.setScope(Scope.DISTRIBUTED_NO_ACK);
            factory2.setMirrorType(MirrorType.KEYS_VALUES);
            createRegion(regions[1], factory2.createRegionAttributes());
            Wait.pause(2000);
            try {
                startBridgeServer(port, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    };
    server1.invoke(createServer);
    server2.invoke(createServer);
    final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server1.getHost());
    final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
    // Create client.
    createClient(client, new int[] { port1, thePort2 }, host0, "-1");
    // Create CQ on region with GLOBAL SCOPE.
    createCQ(client, "testForSupportedRegionAttributes_0", cqs[0]);
    executeCQ(client, "testForSupportedRegionAttributes_0", false, null);
    int size = 5;
    createValues(server1, regions[0], size);
    for (int i = 1; i <= size; i++) {
        waitForCreated(client, "testForSupportedRegionAttributes_0", KEY + i);
    }
    // Create CQ on region with non GLOBAL, DISTRIBUTED_ACK SCOPE.
    createCQ(client, "testForSupportedRegionAttributes_1", cqs[2]);
    String errMsg = "The replicated region " + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
    final String expectedErr = "Cq not registered on primary";
    client.invoke(new CacheSerializableRunnable("Set expect") {

        public void run2() {
            getCache().getLogger().info("<ExpectedException action=add>" + expectedErr + "</ExpectedException>");
        }
    });
    try {
        executeCQ(client, "testForSupportedRegionAttributes_1", false, "CqException");
        fail("The test should have failed with exception, " + errMsg);
    } catch (Exception ex) {
    // Expected.
    } finally {
        client.invoke(new CacheSerializableRunnable("Remove expect") {

            public void run2() {
                getCache().getLogger().info("<ExpectedException action=remove>" + expectedErr + "</ExpectedException>");
            }
        });
    }
    // Close.
    closeClient(client);
    closeServer(server1);
    closeServer(server2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) 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)

Example 12 with SerializableRunnable

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

the class CqQueryDUnitTest method createServer.

public void createServer(VM server, final int thePort, final boolean eviction, final MirrorType mirrorType) {
    SerializableRunnable createServer = 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.setMirrorType(mirrorType);
            // setting the eviction attributes.
            if (eviction) {
                EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100000, EvictionAction.OVERFLOW_TO_DISK);
                factory.setEvictionAttributes(evictAttrs);
            }
            for (int i = 0; i < regions.length; i++) {
                createRegion(regions[i], factory.createRegionAttributes());
            }
            Wait.pause(2000);
            try {
                startBridgeServer(thePort, true);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            Wait.pause(2000);
        }
    };
    server.invoke(createServer);
}
Also used : EvictionAttributes(org.apache.geode.cache.EvictionAttributes) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) 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)

Example 13 with SerializableRunnable

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

the class PutAllCSDUnitTest method closeCache.

protected void closeCache(VM vm0) {
    SerializableRunnable close = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            cache.close();
        }
    };
    vm0.invoke(close);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 14 with SerializableRunnable

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

the class PutAllCSDUnitTest method closeCacheAsync.

protected void closeCacheAsync(VM vm0) {
    SerializableRunnable close = new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            cache.close();
        }
    };
    vm0.invokeAsync(close);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Cache(org.apache.geode.cache.Cache)

Example 15 with SerializableRunnable

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

the class QueryMonitorDUnitTest method testQueryExecutionLocallyAndCacheOp.

/**
   * Tests query execution on local vm.
   */
@Test
public void testQueryExecutionLocallyAndCacheOp() throws Exception {
    setup(2);
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    final int numberOfEntries = 1000;
    // Start server
    // All
    server1.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
    // the
    // queries
    // taking
    // more
    // than
    // 20ms
    // should
    // be
    // canceled
    // by
    // Query
    // monitor.
    server1.invoke("createRegion", () -> createRegion());
    // All
    server2.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
    // the
    // queries
    // taking
    // more
    // than
    // 20ms
    // should
    // be
    // canceled
    // by
    // Query
    // monitor.
    server2.invoke("createRegion", () -> createRegion());
    // Initialize server regions.
    server1.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
    // Initialize server regions.
    server2.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
    // Execute server queries
    SerializableRunnable executeQuery = new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            try {
                QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
                String qStr = "SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion x, x.positions.values pos" + " WHERE  x.ID = p.ID) as itrX";
                executeQuery(queryService, qStr);
                // Create index and Perform cache op. Bug#44307
                queryService.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/root/exampleRegion");
                queryService.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/root/exampleRegion");
                Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
                for (int i = (1 + 100); i <= (numberOfEntries + 200); i++) {
                    exampleRegion.put("" + i, new Portfolio(i));
                }
            } catch (Exception ex) {
                Assert.fail("Exception creating the query service", ex);
            }
        }
    };
    server1.invoke(executeQuery);
    server2.invoke(executeQuery);
    stopServer(server1);
    stopServer(server2);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Portfolio(org.apache.geode.cache.query.data.Portfolio) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Region(org.apache.geode.cache.Region) Host(org.apache.geode.test.dunit.Host) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) CqQueryDUnitTest(org.apache.geode.cache.query.cq.dunit.CqQueryDUnitTest) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Aggregations

SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)741 VM (org.apache.geode.test.dunit.VM)405 Test (org.junit.Test)403 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)353 Region (org.apache.geode.cache.Region)347 Host (org.apache.geode.test.dunit.Host)344 Cache (org.apache.geode.cache.Cache)274 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)259 CacheException (org.apache.geode.cache.CacheException)207 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)198 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166 LocalRegion (org.apache.geode.internal.cache.LocalRegion)160 IOException (java.io.IOException)145 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)120 Properties (java.util.Properties)66 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)66 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)65 IgnoredException (org.apache.geode.test.dunit.IgnoredException)61 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)53