Search in sources :

Example 21 with CqAttributesFactory

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

the class DeltaToRegionRelationCQRegistrationDUnitTest method registerCqThroughPool.

/*
   * register cq from pool
   */
public static void registerCqThroughPool(String name, String Cquery, Boolean cqWithIR) {
    QueryService cqService = null;
    // get cq service
    try {
        cqService = p.getQueryService();
    } catch (Exception cqe) {
        cqe.printStackTrace();
        fail("Failed to getCqService.");
    }
    // Create CQ Attributes.
    // do not attach any listiner lets see its response
    CqAttributesFactory cqf = new CqAttributesFactory();
    CqAttributes cqa = cqf.create();
    // Create and Execute CQ.
    try {
        CqQuery cq1 = cqService.newCq(name, Cquery, cqa);
        assertTrue("newCq() state mismatch", cq1.getState().isStopped());
        if (cqWithIR)
            cq1.executeWithInitialResults();
        else
            cq1.execute();
    } catch (Exception ex) {
        fail("Failed to create CQ " + cqName1, ex);
    }
    CqQuery cQuery = cqService.getCq(name);
    if (cQuery == null) {
        fail("Failed to get CqQuery for CQ : " + cqName1);
    }
}
Also used : QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery)

Example 22 with CqAttributesFactory

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

the class HelperTestCase method createDummyCqAttributes.

private CqAttributes createDummyCqAttributes() {
    // Create CQ Attributes.
    CqAttributesFactory cqAf = new CqAttributesFactory();
    // Initialize and set CqListener.
    CqListener[] cqListeners = { new CqListener() {

        @Override
        public void close() {
        }

        @Override
        public void onEvent(CqEvent aCqEvent) {
        }

        @Override
        public void onError(CqEvent aCqEvent) {
        }
    } };
    cqAf.initCqListeners(cqListeners);
    CqAttributes cqa = cqAf.create();
    return cqa;
}
Also used : CqEvent(org.apache.geode.cache.query.CqEvent) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqListener(org.apache.geode.cache.query.CqListener) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory)

Example 23 with CqAttributesFactory

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

the class CqQueryDUnitTest method createCQ.

public void createCQ(VM vm, final String cqName, final String queryStr, final boolean isBridgeMemberTest) {
    vm.invoke(new CacheSerializableRunnable("Create CQ :" + cqName) {

        public void run2() throws CacheException {
            // pause(60 * 1000);
            // getLogWriter().info("### DEBUG CREATE CQ START ####");
            // pause(20 * 1000);
            LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Create CQ Attributes.
            CqAttributesFactory cqf = new CqAttributesFactory();
            CqListener[] cqListeners = { new CqQueryTestListener(LogWriterUtils.getLogWriter()) };
            // ((CqQueryTestListener)cqListeners[0]).cqName = cqName;
            // if (isBridgeMemberTest) {
            // testListenerForBridgeMembershipTest = (CqQueryTestListener)cqListeners[0];
            // }
            cqf.initCqListeners(cqListeners);
            CqAttributes cqa = cqf.create();
            // Create CQ.
            try {
                CqQuery cq1 = cqService.newCq(cqName, queryStr, cqa);
                assertTrue("newCq() state mismatch", cq1.getState().isStopped());
            } catch (Exception ex) {
                AssertionError err = new AssertionError("Failed to create CQ " + cqName + " . ");
                err.initCause(ex);
                LogWriterUtils.getLogWriter().info("CqService is :" + cqService, err);
                throw err;
            }
        }
    });
}
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) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) 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 24 with CqAttributesFactory

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

the class CqQueryUsingPoolDUnitTest method createAndExecCQNoName.

/* Register CQs with no name, execute, and close */
public void createAndExecCQNoName(VM vm, final String poolName, final String queryStr) {
    vm.invoke(new CacheSerializableRunnable("Create CQ with no name:") {

        @Override
        public void run2() throws CacheException {
            // pause(60 * 1000);
            LogWriterUtils.getLogWriter().info("### DEBUG CREATE CQ START ####");
            // pause(20 * 1000);
            LogWriterUtils.getLogWriter().info("### Create CQ with no name. ###");
            // Get CQ Service.
            QueryService qService = null;
            CqQuery cq1 = null;
            String cqName = null;
            try {
                qService = (PoolManager.find(poolName)).getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            SelectResults cqResults = null;
            for (int i = 0; i < 20; ++i) {
                // Create CQ Attributes.
                CqAttributesFactory cqf = new CqAttributesFactory();
                CqListener[] cqListeners = { new CqQueryTestListener(LogWriterUtils.getLogWriter()) };
                cqf.initCqListeners(cqListeners);
                CqAttributes cqa = cqf.create();
                // Create CQ with no name and execute with initial results.
                try {
                    cq1 = qService.newCq(queryStr, cqa);
                    ((CqQueryTestListener) cqListeners[0]).cqName = cq1.getName();
                } catch (Exception ex) {
                    LogWriterUtils.getLogWriter().info("CQService is :" + qService);
                    Assert.fail("Failed to create CQ with no name" + " . ", ex);
                }
                if (cq1 == null) {
                    LogWriterUtils.getLogWriter().info("Failed to get CqQuery object for CQ with no name.");
                } else {
                    cqName = cq1.getName();
                    LogWriterUtils.getLogWriter().info("Created CQ with no name, generated CQ name: " + cqName + " CQ state:" + cq1.getState());
                    assertTrue("Create CQ with no name illegal state", cq1.getState().isStopped());
                }
                if (i % 2 == 0) {
                    try {
                        cqResults = cq1.executeWithInitialResults();
                    } catch (Exception ex) {
                        LogWriterUtils.getLogWriter().info("CqService is :" + qService);
                        Assert.fail("Failed to execute CQ with initial results, cq name: " + cqName + " . ", ex);
                    }
                    LogWriterUtils.getLogWriter().info("initial result size = " + cqResults.size());
                    LogWriterUtils.getLogWriter().info("CQ state after execute with initial results = " + cq1.getState());
                    assertTrue("executeWithInitialResults() state mismatch", cq1.getState().isRunning());
                } else {
                    try {
                        cq1.execute();
                    } catch (Exception ex) {
                        LogWriterUtils.getLogWriter().info("CQService is :" + qService);
                        Assert.fail("Failed to execute CQ " + cqName + " . ", ex);
                    }
                    LogWriterUtils.getLogWriter().info("CQ state after execute = " + cq1.getState());
                    assertTrue("execute() state mismatch", cq1.getState().isRunning());
                }
                // Close the CQ
                try {
                    cq1.close();
                } catch (Exception ex) {
                    LogWriterUtils.getLogWriter().info("CqService is :" + qService);
                    Assert.fail("Failed to close CQ " + cqName + " . ", ex);
                }
                assertTrue("closeCq() state mismatch", cq1.getState().isClosed());
            }
        }
    });
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) 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) CqAttributes(org.apache.geode.cache.query.CqAttributes) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CqQuery(org.apache.geode.cache.query.CqQuery) CqExistsException(org.apache.geode.cache.query.CqExistsException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RMIException(org.apache.geode.test.dunit.RMIException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 25 with CqAttributesFactory

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

the class CqPerfUsingPoolDUnitTest method testCQPerf.

/**
   * Tests the cq performance.
   * 
   * @throws Exception
   */
@Ignore("perf")
@Test
public void testCQPerf() throws Exception {
    final Host host = Host.getHost(0);
    VM server = host.getVM(0);
    VM client = host.getVM(1);
    cqDUnitTest.createServer(server);
    final int port = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(server.getHost());
    // Create client.
    cqDUnitTest.createClient(client, port, host0);
    final String cqName = "testCQPerf_0";
    client.invoke(new CacheSerializableRunnable("Create CQ :" + cqName) {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create CQ. ###" + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCQService.");
            }
            // Create CQ Attributes.
            CqAttributesFactory cqf = new CqAttributesFactory();
            CqListener[] cqListeners = { new CqTimeTestListener(LogWriterUtils.getLogWriter()) };
            ((CqTimeTestListener) cqListeners[0]).cqName = cqName;
            cqf.initCqListeners(cqListeners);
            CqAttributes cqa = cqf.create();
            // Create and Execute CQ.
            try {
                CqQuery cq1 = cqService.newCq(cqName, cqDUnitTest.cqs[0], cqa);
                assertTrue("newCq() state mismatch", cq1.getState().isStopped());
                cq1.execute();
            } catch (Exception ex) {
                LogWriterUtils.getLogWriter().info("CqService is :" + cqService);
                ex.printStackTrace();
                AssertionError err = new AssertionError("Failed to create CQ " + cqName + " . ");
                err.initCause(ex);
                throw err;
            }
        }
    });
    final int size = 50;
    // Create values.
    cqDUnitTest.createValuesWithTime(client, cqDUnitTest.regions[0], size);
    Wait.pause(5000);
    // Update values
    cqDUnitTest.createValuesWithTime(client, cqDUnitTest.regions[0], size);
    client.invoke(new CacheSerializableRunnable("Validate CQs") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Validating CQ. ### " + cqName);
            // Get CQ Service.
            QueryService cqService = null;
            try {
                cqService = getCache().getQueryService();
            } catch (Exception cqe) {
                cqe.printStackTrace();
                fail("Failed to getCqService.");
            }
            CqQuery cQuery = cqService.getCq(cqName);
            if (cQuery == null) {
                fail("Failed to get CqQuery for CQ : " + cqName);
            }
        // CqAttributes cqAttr = cQuery.getCqAttributes();
        // CqListener cqListeners[] = cqAttr.getCqListeners();
        // CqTimeTestListener listener = (CqTimeTestListener) cqListeners[0];
        // Wait for all the create to arrive.
        // for (int i=1; i <= size; i++) {
        // listener.waitForCreated(cqDUnitTest.KEY+i);
        // }
        // Wait for all the update to arrive.
        // for (int i=1; i <= size; i++) {
        // listener.waitForUpdated(cqDUnitTest.KEY+i);
        // }
        // getLogWriter().info("### Time taken for Creation of " + size + " events is :" +
        // listener.getTotalQueryCreateTime());
        // getLogWriter().info("### Time taken for Update of " + size + " events is :" +
        // listener.getTotalQueryUpdateTime());
        }
    });
    Wait.pause(10 * 60 * 1000);
    // Close.
    cqDUnitTest.closeClient(client);
    cqDUnitTest.closeServer(server);
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) CacheException(org.apache.geode.cache.CacheException) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) DefaultQueryService(org.apache.geode.cache.query.internal.DefaultQueryService) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) VM(org.apache.geode.test.dunit.VM) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqQuery(org.apache.geode.cache.query.CqQuery) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CqAttributesFactory (org.apache.geode.cache.query.CqAttributesFactory)36 CqAttributes (org.apache.geode.cache.query.CqAttributes)31 CqQuery (org.apache.geode.cache.query.CqQuery)30 QueryService (org.apache.geode.cache.query.QueryService)29 CacheException (org.apache.geode.cache.CacheException)16 Test (org.junit.Test)16 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)15 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)15 Region (org.apache.geode.cache.Region)11 CqEvent (org.apache.geode.cache.query.CqEvent)11 CqExistsException (org.apache.geode.cache.query.CqExistsException)10 CqListener (org.apache.geode.cache.query.CqListener)10 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)8 Host (org.apache.geode.test.dunit.Host)8 VM (org.apache.geode.test.dunit.VM)8 IOException (java.io.IOException)7 CqException (org.apache.geode.cache.query.CqException)7 SelectResults (org.apache.geode.cache.query.SelectResults)7 DefaultQueryService (org.apache.geode.cache.query.internal.DefaultQueryService)7 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)7