Search in sources :

Example 36 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class PutAllCSDUnitTest method testRAVersionsOnClientsWithNotificationsOnly.

/**
   * basically same test as testVersionsOnClientsWithNotificationsOnly but also do a removeAll
   */
// GEODE-1419
@Category(FlakyTest.class)
@Test
public void testRAVersionsOnClientsWithNotificationsOnly() {
    final String title = "testRAVersionsInClients";
    disconnectAllFromDS();
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client1 = host.getVM(2);
    VM client2 = host.getVM(3);
    final String regionName = getUniqueName();
    final String serverHost = NetworkUtils.getServerHostName(server1.getHost());
    // set notifyBySubscription=true to test register interest
    final int serverPort1 = createBridgeServer(server1, regionName, 0, true, 0, null);
    final int serverPort2 = createBridgeServer(server2, regionName, 0, true, 0, null);
    // set queueRedundency=1
    createBridgeClient(client1, regionName, serverHost, new int[] { serverPort1 }, 0, 59000, true);
    createBridgeClient(client2, regionName, serverHost, new int[] { serverPort2 }, 0, 59000, true);
    server1.invoke(addExceptionTag1(expectedExceptions));
    server2.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(addExceptionTag1(expectedExceptions));
    client2.invoke(addExceptionTag1(expectedExceptions));
    client1.invoke(new CacheSerializableRunnable(title + "client1 putAll+removeAll") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            doPutAll(regionName, "key-", numberOfEntries * 2);
            assertEquals(numberOfEntries * 2, region.size());
            doRemoveAll(regionName, "key-", numberOfEntries);
            assertEquals(numberOfEntries, region.size());
        }
    });
    client2.invoke(new CacheSerializableRunnable(title + "client2 versions collection") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            region.registerInterest("ALL_KEYS");
            assertEquals(numberOfEntries, region.size());
            LogWriterUtils.getLogWriter().info("client2 registerInterest ALL_KEYS at " + region.getFullPath());
        }
    });
    client1RAVersions = (List<VersionTag>) client1.invoke(new SerializableCallable(title + "client1 versions collection") {

        @Override
        public Object call() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            assertEquals(numberOfEntries, region.size());
            List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
            RegionMap entries = ((LocalRegion) region).entries;
            assertEquals(numberOfEntries * 2, entries.size());
            for (Object key : entries.keySet()) {
                RegionEntry internalRegionEntry = entries.getEntry(key);
                VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
                LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
                versions.add(tag);
            }
            return versions;
        }
    });
    client2RAVersions = (List<VersionTag>) client2.invoke(new SerializableCallable(title + "client2 versions collection") {

        @Override
        public Object call() throws CacheException {
            Region region = getRootRegion().getSubregion(regionName);
            assertEquals(numberOfEntries, region.size());
            List<VersionTag> versions = new ArrayList<VersionTag>(numberOfEntries * 2);
            RegionMap entries = ((LocalRegion) region).entries;
            assertEquals(numberOfEntries * 2, entries.size());
            for (Object key : entries.keySet()) {
                RegionEntry internalRegionEntry = entries.getEntry(key);
                VersionTag tag = internalRegionEntry.getVersionStamp().asVersionTag();
                LogWriterUtils.getLogWriter().info("Entry version tag on client for " + key + ": " + tag);
                versions.add(tag);
            }
            return versions;
        }
    });
    assertEquals(numberOfEntries * 2, client1RAVersions.size());
    LogWriterUtils.getLogWriter().info(Arrays.toString(client1RAVersions.toArray()));
    LogWriterUtils.getLogWriter().info(Arrays.toString(client2RAVersions.toArray()));
    for (VersionTag tag : client1RAVersions) {
        if (!client2RAVersions.contains(tag)) {
            fail("client 2 does not have the tag contained in client 1" + tag);
        }
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) VersionTag(org.apache.geode.internal.cache.versions.VersionTag) Region(org.apache.geode.cache.Region) List(java.util.List) ArrayList(java.util.ArrayList) Category(org.junit.experimental.categories.Category) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 37 with CacheException

use of org.apache.geode.cache.CacheException 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)

Example 38 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class QueryMonitorDUnitTest method testQueryMonitorRegionWithEviction.

/**
   * Tests query execution from client to server (multiple server) with eviction to disk.
   */
@Ignore("TODO:BUG46770WORKAROUND: test is disabled")
@Test
public void testQueryMonitorRegionWithEviction() throws CacheException {
    final Host host = Host.getHost(0);
    VM server1 = host.getVM(0);
    VM server2 = host.getVM(1);
    VM client1 = host.getVM(2);
    VM client2 = host.getVM(3);
    final int numberOfEntries = 100;
    String serverHostName = NetworkUtils.getServerHostName(host);
    // Start server
    int serverPort1 = server1.invoke("Create BridgeServer", // All the queries taking more
    () -> configServer(20, "testQueryMonitorRegionWithEviction"));
    // than 20ms should be
    // canceled by Query monitor.
    server1.invoke("createRegion", () -> createRegion(true, "server1_testQueryMonitorRegionWithEviction"));
    int serverPort2 = server2.invoke("Create BridgeServer", // All the queries taking more
    () -> configServer(20, "testQueryMonitorRegionWithEviction"));
    // than 20ms should be
    // canceled by Query monitor.
    server2.invoke("createRegion", () -> createRegion(true, "server2_testQueryMonitorRegionWithEviction"));
    // Initialize server regions.
    server1.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            bulkInsertPorfolio(101, numberOfEntries);
        }
    });
    // Initialize server regions.
    server2.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            bulkInsertPorfolio((numberOfEntries + 100), (numberOfEntries + numberOfEntries + 100));
        }
    });
    // Initialize Client1 and create client regions.
    client1.invoke("Init client", () -> configClient(serverHostName, serverPort1));
    client1.invoke("createRegion", () -> createRegion());
    // Initialize Client2 and create client regions.
    client2.invoke("Init client", () -> configClient(serverHostName, serverPort2));
    client2.invoke("createRegion", () -> createRegion());
    // Execute client queries
    client1.invoke("Execute Queries", () -> executeQueriesFromClient(20));
    client2.invoke("Execute Queries", () -> executeQueriesFromClient(20));
    stopServer(server1);
    stopServer(server2);
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) Ignore(org.junit.Ignore) 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)

Example 39 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class QueryIndexUpdateRIDUnitTest method getSRRegisterInterestList.

private SerializableRunnable getSRRegisterInterestList(final String regionName, final int keySize, final int policy, final int start) {
    SerializableRunnable sr = new CacheSerializableRunnable("Register InterestList") {

        public void run2() throws CacheException {
            // Get Query Service.
            Region region = null;
            try {
                if ("root".equals(regionName)) {
                    region = getRootRegion();
                } else {
                    region = getRootRegion().getSubregion(regionName);
                }
                region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
            } catch (Exception cqe) {
                AssertionError err = new AssertionError("Failed to get Region.");
                err.initCause(cqe);
                throw err;
            }
            try {
                switch(policy) {
                    case REGEX:
                        region.registerInterestRegex(REGULAR_EXPRESSION);
                        break;
                    case KEYS:
                        List list = new ArrayList();
                        for (int i = start != 0 ? start : 1; i <= keySize; i++) {
                            list.add(KEY + i);
                        }
                        region.registerInterest(list);
                        break;
                    default:
                        region.registerInterest("ALL_KEYS");
                }
            } catch (Exception ex) {
                AssertionError err = new AssertionError("Failed to Register InterestList");
                err.initCause(ex);
                throw err;
            }
        }
    };
    return sr;
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CertifiableTestCacheListener(org.apache.geode.cache30.CertifiableTestCacheListener) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) ArrayList(java.util.ArrayList) Region(org.apache.geode.cache.Region) ArrayList(java.util.ArrayList) List(java.util.List) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 40 with CacheException

use of org.apache.geode.cache.CacheException in project geode by apache.

the class QueryIndexUpdateRIDUnitTest method createClient.

/* Create Client */
public void createClient(VM client, final int[] serverPorts, final String serverHost, final String redundancyLevel, final String poolName) {
    SerializableRunnable createQService = new CacheSerializableRunnable("Create Client") {

        public void run2() throws CacheException {
            LogWriterUtils.getLogWriter().info("### Create Client. ###");
            // Initialize CQ Service.
            try {
                getCache().getQueryService();
            } catch (Exception cqe) {
                Assert.fail("Failed to getCQService.", cqe);
            }
            AttributesFactory regionFactory = new AttributesFactory();
            regionFactory.setScope(Scope.LOCAL);
            if (poolName != null) {
                regionFactory.setPoolName(poolName);
            } else {
                if (redundancyLevel != null) {
                    ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, Integer.parseInt(redundancyLevel), -1, null);
                } else {
                    ClientServerTestCase.configureConnectionPool(regionFactory, serverHost, serverPorts, true, -1, -1, null);
                }
            }
            createRootRegion(regionFactory.createRegionAttributes());
            LogWriterUtils.getLogWriter().info("### Successfully Created Root Region on Client");
        }
    };
    client.invoke(createQService);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Aggregations

CacheException (org.apache.geode.cache.CacheException)638 Test (org.junit.Test)445 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)407 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)376 VM (org.apache.geode.test.dunit.VM)375 Region (org.apache.geode.cache.Region)351 Host (org.apache.geode.test.dunit.Host)330 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)201 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)191 IOException (java.io.IOException)124 LocalRegion (org.apache.geode.internal.cache.LocalRegion)118 QueryService (org.apache.geode.cache.query.QueryService)107 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)85 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)85 SelectResults (org.apache.geode.cache.query.SelectResults)80 IgnoredException (org.apache.geode.test.dunit.IgnoredException)72 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)64 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)61 Cache (org.apache.geode.cache.Cache)59