Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 807CE18982 for ; Wed, 20 Jan 2016 02:22:45 +0000 (UTC) Received: (qmail 58838 invoked by uid 500); 20 Jan 2016 02:22:45 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 58809 invoked by uid 500); 20 Jan 2016 02:22:45 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 58800 invoked by uid 99); 20 Jan 2016 02:22:45 -0000 Received: from Unknown (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jan 2016 02:22:45 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id D4BA3C34DC for ; Wed, 20 Jan 2016 02:22:44 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.8 X-Spam-Level: * X-Spam-Status: No, score=1.8 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RP_MATCHES_RCVD=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id bpRePYSPfFJ9 for ; Wed, 20 Jan 2016 02:22:30 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 7F3B643F87 for ; Wed, 20 Jan 2016 02:22:10 +0000 (UTC) Received: (qmail 53716 invoked by uid 99); 20 Jan 2016 02:22:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 Jan 2016 02:22:07 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DFFF9E03CD; Wed, 20 Jan 2016 02:22:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: rvs@apache.org To: commits@geode.incubator.apache.org Date: Wed, 20 Jan 2016 02:22:42 -0000 Message-Id: <8b64b69099f54f3dbcf5e53934a8e8ee@git.apache.org> In-Reply-To: <38f5b46407394391bacbec02d10d52c0@git.apache.org> References: <38f5b46407394391bacbec02d10d52c0@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [36/51] [partial] incubator-geode git commit: WAN and CQ code drop under the Pivotal SGA http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryMonitorDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryMonitorDUnitTest.java b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryMonitorDUnitTest.java new file mode 100644 index 0000000..92f2817 --- /dev/null +++ b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/query/dunit/QueryMonitorDUnitTest.java @@ -0,0 +1,1292 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.cache.query.dunit; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import com.gemstone.gemfire.cache.AttributesFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheException; +import com.gemstone.gemfire.cache.DataPolicy; +import com.gemstone.gemfire.cache.DiskStore; +import com.gemstone.gemfire.cache.DiskStoreFactory; +import com.gemstone.gemfire.cache.EvictionAction; +import com.gemstone.gemfire.cache.EvictionAttributes; +import com.gemstone.gemfire.cache.PartitionAttributesFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.client.Pool; +import com.gemstone.gemfire.cache.client.PoolFactory; +import com.gemstone.gemfire.cache.client.PoolManager; +import com.gemstone.gemfire.cache.query.IndexType; +import com.gemstone.gemfire.cache.query.Query; +import com.gemstone.gemfire.cache.query.QueryExecutionTimeoutException; +import com.gemstone.gemfire.cache.query.QueryService; +import com.gemstone.gemfire.cache.query.cq.dunit.CqQueryDUnitTest; +import com.gemstone.gemfire.cache.query.data.Portfolio; +import com.gemstone.gemfire.cache.query.internal.DefaultQuery; +import com.gemstone.gemfire.cache.query.internal.QueryMonitor; +import com.gemstone.gemfire.cache.server.CacheServer; +import com.gemstone.gemfire.cache30.ClientServerTestCase; +import com.gemstone.gemfire.distributed.internal.DistributionConfigImpl; +import com.gemstone.gemfire.cache30.CacheSerializableRunnable; +import com.gemstone.gemfire.cache30.CacheTestCase; +import com.gemstone.gemfire.internal.cache.GemFireCacheImpl; + +import dunit.AsyncInvocation; +import dunit.DistributedTestCase; +import dunit.Host; +import dunit.SerializableRunnable; +import dunit.VM; + +/** + * Tests for QueryMonitoring service. + * @author agingade + * @since 6.0 + */ +public class QueryMonitorDUnitTest extends CacheTestCase { + + private static int bridgeServerPort; + + private final String exampleRegionName = "exampleRegion"; + private final String exampleRegionName2 = "exampleRegion2"; + private final String poolName = "serverConnectionPool"; + + /* Some of the queries are commented out as they were taking less time */ + String[] queryStr = { + "SELECT ID FROM /root/exampleRegion p WHERE p.ID > 100", + //"SELECT DISTINCT * FROM /root/exampleRegion x, x.positions.values WHERE x.pk != '1000'", + //"SELECT DISTINCT * FROM /root/exampleRegion x, x.positions.values WHERE x.pkid != '1'", + //"SELECT DISTINCT * FROM /root/exampleRegion p, p.positions.values WHERE p.pk > '1'", + //"SELECT DISTINCT * FROM /root/exampleRegion p, p.positions.values WHERE p.pkid != '53'", + //"SELECT DISTINCT pos FROM /root/exampleRegion p, p.positions.values pos WHERE pos.Id > 100", + //"SELECT DISTINCT pos FROM /root/exampleRegion p, p.positions.values pos WHERE pos.Id > 100 and pos.secId IN SET('YHOO', 'IBM', 'AMZN')", + //"SELECT * FROM /root/exampleRegion p WHERE p.ID > 100 and p.status = 'active' and p.ID < 100000", + "SELECT * FROM /root/exampleRegion WHERE ID > 100 and status = 'active'", + //"SELECT DISTINCT * FROM /root/exampleRegion p WHERE p.ID > 100 and p.status = 'active' and p.ID < 100000", + //"SELECT DISTINCT ID FROM /root/exampleRegion WHERE status = 'active'", + //"SELECT DISTINCT ID FROM /root/exampleRegion p WHERE p.status = 'active'", + //"SELECT DISTINCT pos FROM /root/exampleRegion p, p.positions.values pos WHERE pos.secId IN SET('YHOO', 'IBM', 'AMZN')", + //"SELECT DISTINCT proj1:p, proj2:itrX FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion p, p.positions.values pos" + //+ " WHERE pos.secId = 'YHOO') as itrX", + //"SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion p, p.positions.values pos" + //+ " WHERE pos.secId = 'YHOO') as itrX", + //"SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT p.ID FROM /root/exampleRegion x" + //+ " WHERE x.ID = p.ID) as itrX", + "SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion x, x.positions.values pos" + + " WHERE x.ID = p.ID) as itrX", + //"SELECT DISTINCT x.ID FROM /root/exampleRegion x, x.positions.values v WHERE " + //+ "v.secId = element(SELECT DISTINCT vals.secId FROM /root/exampleRegion p, p.positions.values vals WHERE vals.secId = 'YHOO')", + "SELECT DISTINCT * FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.status = 'active'", + //"SELECT DISTINCT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID", + "SELECT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID and p.status = 'active' and p2.status = 'active'", + //"SELECT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID and p.status = 'active' and p.status = p2.status", + "SELECT DISTINCT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID and p.ID > 100 and p2.ID < 100000", + //"SELECT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID and p.ID > 100 and p2.ID < 100000 or p.status = p2.status", + "SELECT p.ID FROM /root/exampleRegion p, /root/exampleRegion2 p2 WHERE p.ID = p2.ID and p.ID > 100 and p2.ID < 100000 or p.status = 'active'", + //"SELECT DISTINCT * FROM /root/exampleRegion p, positions.values pos WHERE (p.ID > 1 or p.status = 'active') or (true AND pos.secId ='IBM')", + //"SELECT DISTINCT * FROM /root/exampleRegion p, positions.values pos WHERE (p.ID > 1 or p.status = 'active') or (true AND pos.secId !='IBM')", + //"SELECT DISTINCT structset.sos, structset.key " + //+ "FROM /root/exampleRegion p, p.positions.values outerPos, " + //+ "(SELECT DISTINCT key: key, sos: pos.sharesOutstanding " + //+ "FROM /root/exampleRegion.entries pf, pf.value.positions.values pos " + //+ "where outerPos.secId != 'IBM' AND " + //+ "pf.key IN (SELECT DISTINCT * FROM pf.value.collectionHolderMap['0'].arr)) structset " + //+ "where structset.sos > 2000", + "SELECT DISTINCT * " + + "FROM /root/exampleRegion p, p.positions.values outerPos, " + + "(SELECT DISTINCT key: key, sos: pos.sharesOutstanding " + + "FROM /root/exampleRegion.entries pf, pf.value.positions.values pos " + + "where outerPos.secId != 'IBM' AND " + + "pf.key IN (SELECT DISTINCT * FROM pf.value.collectionHolderMap['0'].arr)) structset " + + "where structset.sos > 2000", + //"SELECT DISTINCT * FROM /root/exampleRegion p, p.positions.values position " + //+ "WHERE (true = null OR position.secId = 'SUN') AND true", + }; + + String[] prQueryStr = { + "SELECT ID FROM /root/exampleRegion p WHERE p.ID > 100 and p.status = 'active'", + "SELECT * FROM /root/exampleRegion WHERE ID > 100 and status = 'active'", + "SELECT DISTINCT * FROM /root/exampleRegion p WHERE p.ID > 100 and p.status = 'active' and p.ID < 100000", + "SELECT DISTINCT p.ID FROM /root/exampleRegion p WHERE p.ID > 100 and p.ID < 100000 and p.status = 'active'", + "SELECT DISTINCT * FROM /root/exampleRegion p, positions.values pos WHERE (p.ID > 1 or p.status = 'active') or (pos.secId != 'IBM')", + }; + + private int numServers; + + public QueryMonitorDUnitTest(String name) { + super(name); + } + + public void setup(int numServers) throws Exception { + super.setUp(); + Host host = Host.getHost(0); + this.numServers = numServers; + + // avoid IllegalStateException from HandShake by connecting all vms tor + // system before creating connection pools + getSystem(); + + SerializableRunnable r = new SerializableRunnable("getSystem") { + public void run() { + getSystem(); + } + }; + + for (int i=0; i 0 OR p.position1.mktValue > 0 " + + " OR pos.secId in SET ('SUN', 'IBM', 'YHOO', 'GOOG', 'MSFT', " + + " 'AOL', 'APPL', 'ORCL', 'SAP', 'DELL', 'RHAT', 'NOVL', 'HP')" + + " order by p.status, p.ID desc"; + for (int i=0; i < 500; i++) { + try { + GemFireCacheImpl.getInstance().getLogger().info("Executing query :" + qStr); + Query query = queryService.newQuery(qStr); + query.execute(); + } catch (QueryExecutionTimeoutException qet) { + getLogWriter().info("### Got Expected QueryExecutionTimeout exception. " + + qet.getMessage()); + if (qet.getMessage().contains("cancelled after exceeding max execution")){ + getLogWriter().info("### Doing a put operation"); + exampleRegion.put(""+i, new Portfolio(i)); + } + } catch (Exception e){ + fail("Exception executing query." + e.getMessage()); + } + } + getLogWriter().info("### Completed Executing queries in testCacheOpAfterQueryCancel"); + } catch (Exception ex){ + fail("Exception creating the query service", ex); + } + } + }; + + AsyncInvocation ai3 = server3.invokeAsync(executeQuery); + AsyncInvocation ai4 = server4.invokeAsync(executeQuery); + + getLogWriter().info("### Waiting for async threads to join in testCacheOpAfterQueryCancel"); + try { + DistributedTestCase.join(ai1, 5 * 60 * 1000, null); + DistributedTestCase.join(ai2, 5 * 60 * 1000, null); + DistributedTestCase.join(ai3, 5 * 60 * 1000, null); + DistributedTestCase.join(ai4, 5 * 60 * 1000, null); + } catch (Exception ex) { + fail("Async thread join failure"); + } + getLogWriter().info("### DONE Waiting for async threads to join in testCacheOpAfterQueryCancel"); + + validateQueryMonitorThreadCnt(server1, 0, 1000); + validateQueryMonitorThreadCnt(server2, 0, 1000); + validateQueryMonitorThreadCnt(server3, 0, 1000); + validateQueryMonitorThreadCnt(server4, 0, 1000); + + getLogWriter().info("### DONE validating query monitor threads testCacheOpAfterQueryCancel"); + + stopServer(server1); + stopServer(server2); + stopServer(server3); + stopServer(server4); + } + + public void validateQueryMonitorThreadCnt(VM vm, final int threadCount, final int waitTime){ + SerializableRunnable validateThreadCnt = new CacheSerializableRunnable("validateQueryMonitorThreadCnt") { + public void run2() throws CacheException { + Cache cache = getCache(); + QueryMonitor qm = ((GemFireCacheImpl)cache).getQueryMonitor(); + if (qm == null) { + fail("Didn't found query monitor."); + } + int waited = 0; + while (true) { + if (qm.getQueryMonitorThreadCount() != threadCount) { + if (waited <= waitTime) { + pause(10); + waited+=10; + continue; + } else { + fail ("Didn't found expected monitoring thread. Expected: " + threadCount + + " found :" + qm.getQueryMonitorThreadCount()); + } + } + break; + } + //((GemFireCache)cache).TEST_MAX_QUERY_EXECUTION_TIME = queryMonitorTime; + } + }; + vm.invoke(validateThreadCnt); + } + + /** + * Starts a bridge server on the given port, using the given + * deserializeValues and notifyBySubscription to serve up the + * given region. + */ + protected void startBridgeServer(int port, boolean notifyBySubscription) + throws IOException { + + Cache cache = getCache(); + CacheServer bridge = cache.addCacheServer(); + bridge.setPort(port); + bridge.setNotifyBySubscription(notifyBySubscription); + bridge.start(); + bridgeServerPort = bridge.getPort(); + } + + /** + * Stops the bridge server that serves up the given cache. + */ + protected void stopBridgeServer(Cache cache) { + CacheServer bridge = + (CacheServer) cache.getCacheServers().iterator().next(); + bridge.stop(); + assertFalse(bridge.isRunning()); + } + + private static int getCacheServerPort() { + return bridgeServerPort; + } + + private class QueryTimeoutHook implements DefaultQuery.TestHook { + long timeout; + public QueryTimeoutHook(long timeout) { + this.timeout = timeout; + } + + public void doTestHook(String description) { + if (description.equals("6")) { + try { + Thread.sleep(timeout); + } + catch (InterruptedException ie) { + Thread.currentThread().interrupt(); + } + } + } + + public void doTestHook(int spot) { + doTestHook("" + spot); + } + + } + +} + http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/snapshot/ClientSnapshotDUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/snapshot/ClientSnapshotDUnitTest.java b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/snapshot/ClientSnapshotDUnitTest.java new file mode 100644 index 0000000..9d9557c --- /dev/null +++ b/gemfire-cq/src/test/java/com/gemstone/gemfire/cache/snapshot/ClientSnapshotDUnitTest.java @@ -0,0 +1,276 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.cache.snapshot; + +import java.io.File; +import java.util.concurrent.atomic.AtomicBoolean; + +import com.examples.snapshot.MyObject; +import com.examples.snapshot.MyPdxSerializer; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.EntryEvent; +import com.gemstone.gemfire.cache.EvictionAttributes; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.RegionShortcut; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache.client.ClientRegionShortcut; +import com.gemstone.gemfire.cache.query.CqAttributesFactory; +import com.gemstone.gemfire.cache.query.CqEvent; +import com.gemstone.gemfire.cache.query.CqQuery; +import com.gemstone.gemfire.cache.server.CacheServer; +import com.gemstone.gemfire.cache.snapshot.SnapshotOptions.SnapshotFormat; +import com.gemstone.gemfire.cache.util.CacheListenerAdapter; +import com.gemstone.gemfire.cache.util.CacheWriterAdapter; +import com.gemstone.gemfire.cache.util.CqListenerAdapter; +import com.gemstone.gemfire.cache30.CacheTestCase; +import com.gemstone.gemfire.internal.AvailablePortHelper; + +import dunit.Host; +import dunit.SerializableCallable; + +public class ClientSnapshotDUnitTest extends CacheTestCase { + + private transient Region region; + + public ClientSnapshotDUnitTest(String name) { + super(name); + } + + public void testExport() throws Exception { + int count = 10000; + for (int i = 0; i < count; i++) { + region.put(i, new MyObject(i, "clienttest " + i)); + } + + SerializableCallable export = new SerializableCallable() { + @Override + public Object call() throws Exception { + File f = new File(getDiskDirs()[0], "client-export.snapshot"); + Region r = getCache().getRegion("clienttest"); + + r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); + + return f; + } + }; + + File snapshot = (File) Host.getHost(0).getVM(3).invoke(export); + + SnapshotIterator iter = SnapshotReader.read(snapshot); + try { + while (iter.hasNext()) { + iter.next(); + count--; + } + assertEquals(0, count); + } finally { + iter.close(); + } + } + + public void testImport() throws Exception { + int count = 1000; + for (int i = 0; i < count; i++) { + region.put(i, new MyObject(i, "clienttest " + i)); + } + + SerializableCallable export = new SerializableCallable() { + @Override + public Object call() throws Exception { + File f = new File(getDiskDirs()[0], "client-import.snapshot"); + Region r = getCache().getRegion("clienttest"); + + r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); + + return f; + } + }; + + Host.getHost(0).getVM(3).invoke(export); + for (int i = 0; i < count; i++) { + region.put(i, new MyObject(i, "XXX")); + } + + SerializableCallable imp = new SerializableCallable() { + @Override + public Object call() throws Exception { + final AtomicBoolean cqtest = new AtomicBoolean(false); + CqAttributesFactory af = new CqAttributesFactory(); + af.addCqListener(new CqListenerAdapter() { + @Override + public void onEvent(CqEvent aCqEvent) { + cqtest.set(true); + } + }); + + Region r = getCache().getRegion("clienttest"); + CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create()); + cq.execute(); + + File f = new File(getDiskDirs()[0], "client-import.snapshot"); + r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE); + + return cqtest.get(); + } + }; + + // add callbacks + region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter() { + @Override + public void beforeUpdate(EntryEvent event) { + fail("CacheWriter invoked during import"); + } + }); + + final AtomicBoolean cltest = new AtomicBoolean(false); + region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() { + @Override + public void afterUpdate(EntryEvent event) { + cltest.set(true); + } + }); + + boolean cqtest = (Boolean) Host.getHost(0).getVM(3).invoke(imp); + assertEquals("CacheListener invoked during import", false, cltest.get()); + assertEquals("CqListener invoked during import", false, cqtest); + + for (MyObject obj : region.values()) { + assertTrue(obj.getF2().startsWith("clienttest")); + } + } + + public void testClientCallbacks() throws Exception { + int count = 1000; + for (int i = 0; i < count; i++) { + region.put(i, new MyObject(i, "clienttest " + i)); + } + + File f = new File(getDiskDirs()[0], "client-callback.snapshot"); + region.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); + + for (int i = 0; i < count; i++) { + region.put(i, new MyObject(i, "XXX")); + } + + SerializableCallable callbacks = new SerializableCallable() { + @Override + public Object call() throws Exception { + Region r = getCache().getRegion("clienttest"); + r.registerInterestRegex(".*"); + + r.getAttributesMutator().setCacheWriter(new CacheWriterAdapter() { + @Override + public void beforeUpdate(EntryEvent event) { + fail("CacheWriter invoked during import"); + } + }); + + r.getAttributesMutator().addCacheListener(new CacheListenerAdapter() { + @Override + public void afterUpdate(EntryEvent event) { + fail("CacheListener was invoked during import"); + } + }); + + final AtomicBoolean cqtest = new AtomicBoolean(false); + CqAttributesFactory af = new CqAttributesFactory(); + af.addCqListener(new CqListenerAdapter() { + @Override + public void onEvent(CqEvent aCqEvent) { + fail("Cq was invoked during import"); + } + }); + + CqQuery cq = r.getRegionService().getQueryService().newCq("SELECT * FROM /clienttest", af.create()); + cq.execute(); + + return null; + } + }; + + Host.getHost(0).getVM(3).invoke(callbacks); + region.getSnapshotService().load(f, SnapshotFormat.GEMFIRE); + } + + public void testInvalidate() throws Exception { + SerializableCallable invalid = new SerializableCallable() { + @Override + public Object call() throws Exception { + Region r = getCache().getRegion("clienttest"); + + r.put(1, new MyObject(1, "invalidate")); + r.invalidate(1); + + File f = new File(getDiskDirs()[0], "client-invalidate.snapshot"); + r.getSnapshotService().save(f, SnapshotFormat.GEMFIRE); + r.getSnapshotService().load(f, SnapshotFormat.GEMFIRE); + + return null; + } + }; + + Host.getHost(0).getVM(3).invoke(invalid); + + assertTrue(region.containsKey(1)); + assertFalse(region.containsValueForKey(1)); + assertNull(region.get(1)); + } + + public void setUp() throws Exception { + super.setUp(); + loadCache(); + } + + @SuppressWarnings("serial") + public void loadCache() throws Exception { + CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer()); + Cache cache = getCache(cf); + + CacheServer server = cache.addCacheServer(); + final int port = AvailablePortHelper.getRandomAvailableTCPPort(); + server.setPort(port); + server.start(); + + region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("clienttest"); + + final Host host = Host.getHost(0); + SerializableCallable client = new SerializableCallable() { + @Override + public Object call() throws Exception { + ClientCacheFactory cf = new ClientCacheFactory() + .set("log-level", getDUnitLogLevel()) + .setPdxSerializer(new MyPdxSerializer()) + .addPoolServer(getServerHostName(host), port) + .setPoolSubscriptionEnabled(true) + .setPoolPRSingleHopEnabled(false); + + ClientCache cache = getClientCache(cf); + Region r = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY_HEAP_LRU) + .setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(5)) + .create("clienttest"); + return null; + } + }; + + SerializableCallable remote = new SerializableCallable() { + @Override + public Object call() throws Exception { + CacheFactory cf = new CacheFactory().setPdxSerializer(new MyPdxSerializer()); + Cache cache = getCache(cf); + + cache.createRegionFactory(RegionShortcut.REPLICATE).create("clienttest"); + return null; + } + }; + + host.getVM(3).invoke(client); + host.getVM(2).invoke(remote); + } +} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6df75241/gemfire-cq/src/test/java/com/gemstone/gemfire/codeAnalysis/AnalyzeCQSerializablesJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-cq/src/test/java/com/gemstone/gemfire/codeAnalysis/AnalyzeCQSerializablesJUnitTest.java b/gemfire-cq/src/test/java/com/gemstone/gemfire/codeAnalysis/AnalyzeCQSerializablesJUnitTest.java new file mode 100755 index 0000000..f0fffa7 --- /dev/null +++ b/gemfire-cq/src/test/java/com/gemstone/gemfire/codeAnalysis/AnalyzeCQSerializablesJUnitTest.java @@ -0,0 +1,70 @@ +/*========================================================================= + * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved. + * This product is protected by U.S. and international copyright + * and intellectual property laws. Pivotal products are covered by + * one or more patents listed at http://www.pivotal.io/patents. + *========================================================================= + */ +package com.gemstone.gemfire.codeAnalysis; + +import static org.junit.Assert.fail; + +import java.io.File; +import java.util.List; + +import org.junit.Before; +import org.junit.experimental.categories.Category; + +import com.gemstone.gemfire.test.junit.categories.IntegrationTest; +import com.gemstone.gemfire.util.test.TestUtil; + +/** + * @author bruces + * + */ +@Category(IntegrationTest.class) +public class AnalyzeCQSerializablesJUnitTest extends AnalyzeSerializablesJUnitTest { + + @Before + public void loadClasses() throws Exception { + if (classes.size() > 0) { + return; + } + System.out.println("loadClasses starting"); + List excludedClasses = loadExcludedClasses(new File(TestUtil.getResourcePath(AnalyzeCQSerializablesJUnitTest.class, "excludedClasses.txt"))); + List openBugs = loadOpenBugs(new File(TestUtil.getResourcePath(AnalyzeCQSerializablesJUnitTest.class, "openBugs.txt"))); + excludedClasses.addAll(openBugs); + + String cp = System.getProperty("java.class.path"); + System.out.println("java classpath is " + cp); + System.out.flush(); + String[] entries = cp.split(File.pathSeparator); + String buildDirName = + "gemfire-cq"+File.separatorChar + +"build"+File.separatorChar + +"classes"+File.separatorChar + +"main"; + String buildDir = null; + + for (int i=0; i