Search in sources :

Example 96 with SelectResults

use of org.apache.geode.cache.query.SelectResults in project geode by apache.

the class RemoteQueryDUnitTest method testRemoteFullRegionQueries.

/**
   * Tests remote full region query execution.
   */
@Test
public void testRemoteFullRegionQueries() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int numberOfEntries = 100;
    // Start server
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
            getSystem(config);
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            createRegion(name, factory.create());
            Wait.pause(1000);
            try {
                startBridgeServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    // Initialize server region
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < numberOfEntries; i++) {
                region.put("key-" + i, new TestObject(i, "ibm"));
            }
        }
    });
    // Create client region
    final int port = vm0.invoke(() -> RemoteQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    vm1.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            getSystem(config);
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    });
    // Execute client queries
    vm1.invoke(new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            String queryString = null;
            SelectResults results = null;
            Comparator comparator = null;
            Object[] resultsArray = null;
            // value query
            queryString = "SELECT DISTINCT itr.value FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates());
            assertTrue(results.asList().get(0) instanceof TestObject);
            // key query
            queryString = "SELECT DISTINCT itr.key FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates());
            assertEquals("key-1", results.asList().get(0));
            // order by value query
            queryString = "SELECT DISTINCT * FROM " + region.getFullPath() + " WHERE id < 101 ORDER BY id";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(numberOfEntries, results.size());
            // All order-by query results are stored in a ResultsCollectionWrapper
            // wrapping a list, so the assertion below is not correct even though
            // it should be.
            // assertTrue(!results.getCollectionType().allowsDuplicates());
            assertTrue(results.getCollectionType().isOrdered());
            comparator = new IdComparator();
            resultsArray = results.toArray();
            for (int i = 0; i < resultsArray.length; i++) {
                if (i + 1 != resultsArray.length) {
                    // The id of the current element in the result set must be less
                    // than the id of the next one to pass.
                    assertTrue("The id for " + resultsArray[i] + " should be less than the id for " + resultsArray[i + 1], comparator.compare(resultsArray[i], resultsArray[i + 1]) == -1);
                }
            }
            // order by struct query
            queryString = "SELECT DISTINCT id, ticker, price FROM " + region.getFullPath() + " WHERE id < 101 ORDER BY id";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(numberOfEntries, results.size());
            // All order-by query results are stored in a ResultsCollectionWrapper
            // wrapping a list, so the assertion below is not correct even though
            // it should be.
            // assertTrue(!results.getCollectionType().allowsDuplicates());
            assertTrue(results.getCollectionType().isOrdered());
            comparator = new StructIdComparator();
            resultsArray = results.toArray();
            for (int i = 0; i < resultsArray.length; i++) {
                if (i + 1 != resultsArray.length) {
                    // The id of the current element in the result set must be less
                    // than the id of the next one to pass.
                    assertTrue("The id for " + resultsArray[i] + " should be less than the id for " + resultsArray[i + 1], comparator.compare(resultsArray[i], resultsArray[i + 1]) == -1);
                }
            }
            // size query
            queryString = "(SELECT DISTINCT * FROM " + region.getFullPath() + " WHERE id < 101).size";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            Object result = results.iterator().next();
            assertTrue(result instanceof Integer);
            int resultInt = ((Integer) result).intValue();
            assertEquals(resultInt, 100);
            // query with leading/trailing spaces
            queryString = " SELECT DISTINCT itr.key FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1' ";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertEquals("key-1", results.asList().get(0));
        }
    });
    // Stop server
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Comparator(java.util.Comparator) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 97 with SelectResults

use of org.apache.geode.cache.query.SelectResults in project geode by apache.

the class RemoteQueryDUnitTest method testRemoteBridgeClientQueries.

/**
   * Tests remote query execution using a BridgeClient as the CacheWriter and CacheLoader.
   */
// GEODE-490: random port
@Category(FlakyTest.class)
@Test
public void testRemoteBridgeClientQueries() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    final int numberOfEntries = 100;
    // Start server
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
            getSystem(config);
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            createRegion(name, factory.create());
            try {
                startBridgeServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    // Initialize server region
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < numberOfEntries; i++) {
                region.put("key-" + i, new TestObject(i, "ibm"));
            }
        }
    });
    final int port = vm0.invoke(() -> RemoteQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    // Create client region in VM1
    vm1.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            getSystem(config);
            PoolManager.createFactory().addServer(host0, port).setSubscriptionEnabled(true).create("clientPool");
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setPoolName("clientPool");
            createRegion(name, factory.create());
        }
    });
    // Create client region in VM2
    vm2.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            getSystem(config);
            PoolManager.createFactory().addServer(host0, port).setSubscriptionEnabled(true).create("clientPool");
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setPoolName("clientPool");
            createRegion(name, factory.create());
        }
    });
    // Execute client queries in VM1
    vm1.invoke(new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            String queryString = null;
            SelectResults results = null;
            queryString = "SELECT DISTINCT itr.value FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            assertTrue(results.asList().get(0) instanceof TestObject);
            queryString = "SELECT DISTINCT itr.key FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            assertEquals("key-1", results.asList().get(0));
        }
    });
    // Execute client queries in VM2
    vm2.invoke(new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            String queryString = null;
            SelectResults results = null;
            queryString = "SELECT DISTINCT itr.value FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            assertTrue(results.asList().get(0) instanceof TestObject);
            queryString = "SELECT DISTINCT itr.key FROM " + region.getFullPath() + ".entries itr where itr.key = 'key-1'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(!results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            assertEquals("key-1", results.asList().get(0));
        }
    });
    // Close client VM1
    vm1.invoke(new CacheSerializableRunnable("Close client") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.close();
            PoolManager.find("clientPool").destroy();
        }
    });
    // Close client VM2
    vm2.invoke(new CacheSerializableRunnable("Close client") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            region.close();
            PoolManager.find("clientPool").destroy();
        }
    });
    // Stop server
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 98 with SelectResults

use of org.apache.geode.cache.query.SelectResults in project geode by apache.

the class RemoteQueryDUnitTest method testRemotePredicateQueries.

/**
   * Tests remote predicate query execution.
   */
@Test
public void testRemotePredicateQueries() throws CacheException {
    final String name = this.getName();
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final int numberOfEntries = 100;
    // Start server
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(LOCATORS, "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
            InternalDistributedSystem system = getSystem(config);
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            createRegion(name, factory.create());
            Wait.pause(1000);
            try {
                startBridgeServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    // Initialize server region
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < numberOfEntries; i++) {
                region.put("key-" + i, new TestObject(i, "ibm"));
            }
        }
    });
    // Create client region
    final int port = vm0.invoke(() -> RemoteQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
    vm1.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty(MCAST_PORT, "0");
            getSystem(config);
            getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
            createRegion(name, factory.create());
        }
    });
    // Execute client queries
    vm1.invoke(new CacheSerializableRunnable("Execute queries") {

        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            String queryString = null;
            SelectResults results = null;
            queryString = "ticker = 'ibm'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(numberOfEntries, results.size());
            assertTrue(results.getClass() == ResultsBag.class);
            assertTrue(results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            queryString = "ticker = 'IBM'";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(0, results.size());
            assertTrue(results.getClass() == ResultsBag.class);
            assertTrue(results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            queryString = "price > 49";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(numberOfEntries / 2, results.size());
            assertTrue(results.getClass() == ResultsBag.class);
            assertTrue(results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            queryString = "price = 50";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(results.getClass() == ResultsBag.class);
            assertTrue(results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
            queryString = "ticker = 'ibm' and price = 50";
            try {
                results = region.query(queryString);
            } catch (Exception e) {
                Assert.fail("Failed executing " + queryString, e);
            }
            assertEquals(1, results.size());
            assertTrue(results.getClass() == ResultsBag.class);
            assertTrue(results.getCollectionType().allowsDuplicates() && !results.getCollectionType().getElementType().isStructType());
        /*
         * Non-distinct order by query not yet supported queryString = "id < 101 ORDER BY id"; try {
         * results = region.query(queryString); } catch (Exception e) { fail("Failed executing " +
         * queryString, e); } assertIndexDetailsEquals(100, results.size()); assertTrue(results
         * instanceof ResultsCollectionWrapper); IdComparator comparator = new IdComparator();
         * Object[] resultsArray = results.toArray(); for (int i=0; i<resultsArray.length; i++) { if
         * (i+1 != resultsArray.length) { // The id of the current element in the result set must be
         * less // than the id of the next one to pass. assertTrue("The id for " + resultsArray[i] +
         * " should be less than the id for " + resultsArray[i+1],
         * comparator.compare(resultsArray[i], resultsArray[i+1]) == -1); } }
         */
        }
    });
    // Stop server
    vm0.invoke(new SerializableRunnable("Stop CacheServer") {

        public void run() {
            stopBridgeServer(getCache());
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) Host(org.apache.geode.test.dunit.Host) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) AttributesFactory(org.apache.geode.cache.AttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 99 with SelectResults

use of org.apache.geode.cache.query.SelectResults in project geode by apache.

the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitAddResultsTestWithMultipleServers.

private void doCriticalMemoryHitAddResultsTestWithMultipleServers(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
    // create region on the server
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM server2 = host.getVM(1);
    final VM client = host.getVM(2);
    final int numObjects = 200;
    try {
        final int[] port = AvailablePortHelper.getRandomAvailableTCPPorts(2);
        startCacheServer(server1, port[0], criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
        startCacheServer(server2, port[1], criticalThreshold, true, -1, regionName, createPR, 0);
        startClient(client, server1, port[0], regionName);
        populateData(server2, regionName, numObjects);
        createCancelDuringAddResultsTestHook(server1);
        client.invoke(new SerializableCallable("executing query to be canceled during add results") {

            public Object call() {
                QueryService qs = null;
                try {
                    qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    SelectResults results = (SelectResults) query.execute();
                    if (hitCriticalThreshold && disabledQueryMonitorForLowMem == false) {
                        throw new CacheException("should have hit low memory") {
                        };
                    }
                } catch (Exception e) {
                    handleException(e, hitCriticalThreshold, disabledQueryMonitorForLowMem, queryTimeout);
                }
                return 0;
            }
        });
        verifyRejectedObjects(server1, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Pause for a second and then let's recover
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
        // Check to see if query execution is ok under "normal" or "healthy" conditions
        client.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {

            public void run2() {
                try {
                    QueryService qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    SelectResults results = (SelectResults) query.execute();
                    assertEquals(numObjects, results.size());
                } catch (QueryInvocationTargetException e) {
                    assertFalse(true);
                } catch (NameResolutionException e) {
                    assertFalse(true);
                } catch (TypeMismatchException e) {
                    assertFalse(true);
                } catch (FunctionDomainException e) {
                    assertFalse(true);
                }
            }
        });
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server1);
        }
    } finally {
        stopServer(server1);
        stopServer(server2);
    }
}
Also used : DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) NameResolutionException(org.apache.geode.cache.query.NameResolutionException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) QueryExecutionTimeoutException(org.apache.geode.cache.query.QueryExecutionTimeoutException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) IndexInvalidException(org.apache.geode.cache.query.IndexInvalidException) CacheException(org.apache.geode.cache.CacheException) QueryExecutionLowMemoryException(org.apache.geode.cache.query.QueryExecutionLowMemoryException) QueryException(org.apache.geode.cache.query.QueryException) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable)

Example 100 with SelectResults

use of org.apache.geode.cache.query.SelectResults in project geode by apache.

the class ResourceManagerWithQueryMonitorDUnitTest method doCriticalMemoryHitTest.

private void doCriticalMemoryHitTest(final String regionName, boolean createPR, final int criticalThreshold, final boolean disabledQueryMonitorForLowMem, final int queryTimeout, final boolean hitCriticalThreshold) throws Exception {
    // create region on the server
    final Host host = Host.getHost(0);
    final VM server = host.getVM(0);
    final VM client = host.getVM(1);
    final int numObjects = 200;
    try {
        final int port = AvailablePortHelper.getRandomAvailableTCPPort();
        startCacheServer(server, port, criticalThreshold, disabledQueryMonitorForLowMem, queryTimeout, regionName, createPR, 0);
        startClient(client, server, port, regionName);
        populateData(server, regionName, numObjects);
        doTestCriticalHeapAndQueryTimeout(server, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Pause for a second and then let's recover
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server);
        }
        // Check to see if query execution is ok under "normal" or "healthy" conditions
        client.invoke(new CacheSerializableRunnable("Executing query when system is 'Normal'") {

            public void run2() {
                try {
                    QueryService qs = getCache().getQueryService();
                    Query query = qs.newQuery("Select * From /" + regionName);
                    SelectResults results = (SelectResults) query.execute();
                    assertEquals(numObjects, results.size());
                } catch (QueryInvocationTargetException e) {
                    assertFalse(true);
                } catch (NameResolutionException e) {
                    assertFalse(true);
                } catch (TypeMismatchException e) {
                    assertFalse(true);
                } catch (FunctionDomainException e) {
                    assertFalse(true);
                }
            }
        });
        // Execute a critical heap event/ query timeout test again
        doTestCriticalHeapAndQueryTimeout(server, client, regionName, disabledQueryMonitorForLowMem, queryTimeout, hitCriticalThreshold);
        // Recover from critical heap
        if (hitCriticalThreshold) {
            vmRecoversFromCriticalHeap(server);
        }
    } finally {
        stopServer(server);
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DefaultQuery(org.apache.geode.cache.query.internal.DefaultQuery) Query(org.apache.geode.cache.query.Query) QueryService(org.apache.geode.cache.query.QueryService) FunctionDomainException(org.apache.geode.cache.query.FunctionDomainException) VM(org.apache.geode.test.dunit.VM) TypeMismatchException(org.apache.geode.cache.query.TypeMismatchException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) Host(org.apache.geode.test.dunit.Host) NameResolutionException(org.apache.geode.cache.query.NameResolutionException)

Aggregations

SelectResults (org.apache.geode.cache.query.SelectResults)577 Test (org.junit.Test)423 Query (org.apache.geode.cache.query.Query)360 Region (org.apache.geode.cache.Region)336 QueryService (org.apache.geode.cache.query.QueryService)331 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)256 Portfolio (org.apache.geode.cache.query.data.Portfolio)249 Index (org.apache.geode.cache.query.Index)133 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)112 Host (org.apache.geode.test.dunit.Host)107 VM (org.apache.geode.test.dunit.VM)107 CacheException (org.apache.geode.cache.CacheException)105 Iterator (java.util.Iterator)104 AttributesFactory (org.apache.geode.cache.AttributesFactory)101 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)92 DefaultQuery (org.apache.geode.cache.query.internal.DefaultQuery)89 Cache (org.apache.geode.cache.Cache)84 Struct (org.apache.geode.cache.query.Struct)80 LocalRegion (org.apache.geode.internal.cache.LocalRegion)67 ObjectType (org.apache.geode.cache.query.types.ObjectType)66