You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/06/16 17:23:21 UTC

[01/23] incubator-geode git commit: Minor javadoc fixes

Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-835 a3cc50912 -> fab62c21c


Minor javadoc fixes

GatewayCancelledException said it was thrown when an Oplog is terminated.
OplogCancelledException said it was thrown when a Gateway is terminated.
DistributedMember had a non-deprecated getRoles() method.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/5e0050de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/5e0050de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/5e0050de

Branch: refs/heads/feature/GEODE-835
Commit: 5e0050de149fb1540c5dcf45257e5283cf3ff9f9
Parents: e831aa0
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Fri Jun 10 15:55:17 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Fri Jun 10 15:55:17 2016 -0700

----------------------------------------------------------------------
 .../java/com/gemstone/gemfire/distributed/DistributedMember.java   | 1 +
 .../gemstone/gemfire/distributed/GatewayCancelledException.java    | 2 +-
 .../com/gemstone/gemfire/distributed/OplogCancelledException.java  | 2 +-
 .../com/gemstone/gemfire/distributed/PoolCancelledException.java   | 2 +-
 4 files changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5e0050de/geode-core/src/main/java/com/gemstone/gemfire/distributed/DistributedMember.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/DistributedMember.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/DistributedMember.java
index 3779cdc..58c5094 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/DistributedMember.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/DistributedMember.java
@@ -44,6 +44,7 @@ public interface DistributedMember extends Comparable<DistributedMember> {
   /**
    * Returns the Roles that this member performs in the system.
    * Note that the result will contain both groups and roles.
+   * @deprecated Roles is scheduled to be removed
    */
   public Set<Role> getRoles();
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5e0050de/geode-core/src/main/java/com/gemstone/gemfire/distributed/GatewayCancelledException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/GatewayCancelledException.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/GatewayCancelledException.java
index bfe25a1..11d975f 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/GatewayCancelledException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/GatewayCancelledException.java
@@ -19,7 +19,7 @@ package com.gemstone.gemfire.distributed;
 import com.gemstone.gemfire.CancelException;
 
 /**
- * Thrown when a GemFire oplog has been terminated.
+ * Thrown when a GemFire WAN gateway has been terminated.
  * 
  * @since GemFire 6.0
  */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5e0050de/geode-core/src/main/java/com/gemstone/gemfire/distributed/OplogCancelledException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/OplogCancelledException.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/OplogCancelledException.java
index aa43f24..fa7cb58 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/OplogCancelledException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/OplogCancelledException.java
@@ -19,7 +19,7 @@ package com.gemstone.gemfire.distributed;
 import com.gemstone.gemfire.CancelException;
 
 /**
- * Thrown when a GemFire gateway has been terminated.
+ * Thrown when a GemFire operation log has been terminated.
  * 
  * @since GemFire 6.0
  */

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5e0050de/geode-core/src/main/java/com/gemstone/gemfire/distributed/PoolCancelledException.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/PoolCancelledException.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/PoolCancelledException.java
index 9eed2b7..4cbd994 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/PoolCancelledException.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/PoolCancelledException.java
@@ -19,7 +19,7 @@ package com.gemstone.gemfire.distributed;
 import com.gemstone.gemfire.CancelException;
 
 /**
- * Thrown when a GemFire pool has been cancelled.
+ * Thrown when a GemFire connection pool has been terminated.
  * 
  * @since GemFire 6.0
  */


[15/23] incubator-geode git commit: GEODE-1545: fix compile problem caused by merge

Posted by kl...@apache.org.
GEODE-1545: fix compile problem caused by merge


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0d5de3e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0d5de3e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0d5de3e3

Branch: refs/heads/feature/GEODE-835
Commit: 0d5de3e3f5e69f4de683ea289ac58d36280f7d6d
Parents: ed32cee
Author: zhouxh <gz...@pivotal.io>
Authored: Tue Jun 14 15:25:46 2016 -0700
Committer: zhouxh <gz...@pivotal.io>
Committed: Tue Jun 14 15:25:46 2016 -0700

----------------------------------------------------------------------
 .../gemfire/cache/lucene/LuceneQueriesIntegrationTest.java   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0d5de3e3/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 95f5781..587e4db 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -102,7 +102,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     expectedResults.put("A", new TestObject(value1, value1));
     expectedResults.put("B", new TestObject(value2, value2));
     expectedResults.put("C", new TestObject(value3, value3));
-    verifyQuery("field1:one@three", expectedResults);
+    verifyQuery("field1:one@three", DEFAULT_FIELD, expectedResults);
     
     // keyword analyzer, this query will only match the entry that exactly matches
     // this query string will be parsed as "one three"
@@ -182,7 +182,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     HashMap expectedResults = new HashMap();
     expectedResults.put("jsondoc1", pdx1);
     expectedResults.put("jsondoc10", pdx10);
-    verifyQuery("name:jsondoc1*", expectedResults);
+    verifyQuery("name:jsondoc1*", DEFAULT_FIELD, expectedResults);
   }
 
   @Test()
@@ -247,9 +247,9 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     verifyQueryKeys(queryWithStandardAnalyzer, expectedKeys);
   }
   
-  private void verifyQuery(String query, HashMap expectedResults) throws ParseException {
+  private void verifyQuery(String query, String DEFAULT_FIELD, HashMap expectedResults) throws ParseException {
     final LuceneQuery<String, Object> queryWithStandardAnalyzer = luceneService.createLuceneQueryFactory().create(
-      INDEX_NAME, REGION_NAME, query);
+      INDEX_NAME, REGION_NAME, query, DEFAULT_FIELD);
 
     verifyQueryKeyAndValues(queryWithStandardAnalyzer, expectedResults);
   }


[18/23] incubator-geode git commit: GEODE-1547: Added Nabarun Nag to list of committers on website's Community page, reformatted list so columns balance

Posted by kl...@apache.org.
GEODE-1547: Added Nabarun Nag to list of committers on website's Community page, reformatted list so columns balance


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/a7b6b25a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/a7b6b25a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/a7b6b25a

Branch: refs/heads/feature/GEODE-835
Commit: a7b6b25a24224dd26e9ae380574c52703394c026
Parents: 0f2bb8f
Author: Dave Barnes <db...@pivotal.io>
Authored: Wed Jun 15 09:56:37 2016 -0700
Committer: Dave Barnes <db...@pivotal.io>
Committed: Wed Jun 15 09:56:37 2016 -0700

----------------------------------------------------------------------
 geode-site/website/content/community/index.html | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/a7b6b25a/geode-site/website/content/community/index.html
----------------------------------------------------------------------
diff --git a/geode-site/website/content/community/index.html b/geode-site/website/content/community/index.html
index 5258c8b..8cc8007 100644
--- a/geode-site/website/content/community/index.html
+++ b/geode-site/website/content/community/index.html
@@ -226,6 +226,7 @@ under the License. -->
         <li>Lynn Hughes-Godfrey</li>
         <li>Mark Bretl</li>
         <li>Michael Schubert</li>
+        <li>Nabarun Nag</li>
         <li>Namrata Thanvi</li>
         <li>Neeraj Kumar</li>
         <li>Nilkanth Patel</li>
@@ -240,9 +241,9 @@ under the License. -->
         <li>Shirish Deshmukh</li>
         <li>Sonal Agarwal</li>
         <li>Soubhik Chakraborty</li>
-        <li>Sourabh Bansod</li>
 			</div>
 			<div class="col-md-2">
+        <li>Sourabh Bansod</li>
         <li>Stephane Maldini</li>
         <li>Stuart Williams</li>
         <li>Sudhir Menon</li>


[03/23] incubator-geode git commit: GEODE-11: Adding stats for lucene documents, files, and chunks

Posted by kl...@apache.org.
GEODE-11: Adding stats for lucene documents, files, and chunks

Using the new stat suppliers added with GEODE-1494 to sample useful
lucene statistics:
 * Number of documents
 * Number of files
 * Number of chunks
 * Number of bytes


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/615e643c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/615e643c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/615e643c

Branch: refs/heads/feature/GEODE-835
Commit: 615e643cf989ab709aa3880d89ad04dfffa530f0
Parents: 01848b6
Author: Dan Smith <up...@apache.org>
Authored: Wed Jun 8 14:33:15 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Jun 13 10:45:13 2016 -0700

----------------------------------------------------------------------
 .../LuceneIndexForPartitionedRegion.java        | 14 +++++--
 .../cache/lucene/internal/LuceneIndexImpl.java  | 32 ++++++++------
 .../cache/lucene/internal/LuceneIndexStats.java | 24 ++++++++++-
 .../internal/filesystem/FileSystemStats.java    | 44 ++++++++++++++++++--
 .../repository/IndexRepositoryImpl.java         | 13 ++++++
 .../LuceneIndexMaintenanceIntegrationTest.java  | 30 +++++++++++++
 .../internal/LuceneIndexStatsJUnitTest.java     | 17 ++++++--
 .../IndexRepositoryImplJUnitTest.java           | 12 ++++++
 8 files changed, 162 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
index 8fe5fac..d283e29 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexForPartitionedRegion.java
@@ -40,12 +40,9 @@ import com.gemstone.gemfire.internal.cache.PartitionedRegion;
 
 /* wrapper of IndexWriter */
 public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
-  FileSystemStats fileSystemStats;
 
   public LuceneIndexForPartitionedRegion(String indexName, String regionPath, Cache cache) {
     super(indexName, regionPath, cache);
-    final String statsName = indexName + "-" + regionPath;
-    this.fileSystemStats = new FileSystemStats(cache.getDistributedSystem(), statsName);
   }
 
   @Override
@@ -88,6 +85,9 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
       if (!chunkRegionExists(chunkRegionName)) {
         chunkRegion = createChunkRegion(regionShortCut, fileRegionName, partitionAttributes, chunkRegionName);
       }
+      fileSystemStats.setFileSupplier(() -> (int) getFileRegion().getLocalSize());
+      fileSystemStats.setChunkSupplier(() -> (int) getChunkRegion().getLocalSize());
+      fileSystemStats.setBytesSupplier(() -> getChunkRegion().getPrStats().getDataStoreBytesInUse());
 
       // we will create RegionDirectories on the fly when data comes in
       HeterogeneousLuceneSerializer mapper = new HeterogeneousLuceneSerializer(getFieldNames());
@@ -106,6 +106,14 @@ public class LuceneIndexForPartitionedRegion extends LuceneIndexImpl {
     return (PartitionedRegion) cache.getRegion(regionPath);
   }
 
+  private PartitionedRegion getFileRegion() {
+    return (PartitionedRegion) fileRegion;
+  }
+
+  private PartitionedRegion getChunkRegion() {
+    return (PartitionedRegion) chunkRegion;
+  }
+
   private AsyncEventQueueFactoryImpl createAEQFactory(final Region dataRegion) {
     AsyncEventQueueFactoryImpl factory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
     factory.setParallel(true); // parallel AEQ for PR

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java
index c75148a..acd3765 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexImpl.java
@@ -46,28 +46,28 @@ import com.gemstone.gemfire.internal.logging.LogService;
 public abstract class LuceneIndexImpl implements InternalLuceneIndex {
   protected static final Logger logger = LogService.getLogger();
   
-//  protected HashSet<String> searchableFieldNames = new HashSet<String>();
-  String[] searchableFieldNames;
-  protected RepositoryManager repositoryManager;
-  protected Analyzer analyzer;
-  
-  Region<String, File> fileRegion;
-  Region<ChunkKey, byte[]> chunkRegion;
-  LuceneIndexStats indexStats;
+  protected final String indexName;
+  protected final String regionPath;
+  protected final Cache cache;
+  protected final LuceneIndexStats indexStats;
+  protected final FileSystemStats fileSystemStats;
 
-  protected String indexName;
-  protected String regionPath;
   protected boolean hasInitialized = false;
   protected Map<String, Analyzer> fieldAnalyzers;
+  protected String[] searchableFieldNames;
+  protected RepositoryManager repositoryManager;
+  protected Analyzer analyzer;
+  protected Region<String, File> fileRegion;
+  protected Region<ChunkKey, byte[]> chunkRegion;
+
 
-  protected final Cache cache;
-  
   protected LuceneIndexImpl(String indexName, String regionPath, Cache cache) {
     this.indexName = indexName;
     this.regionPath = regionPath;
     this.cache = cache;
     final String statsName = indexName + "-" + regionPath;
     this.indexStats = new LuceneIndexStats(cache.getDistributedSystem(), statsName);
+    this.fileSystemStats = new FileSystemStats(cache.getDistributedSystem(), statsName);
   }
 
   @Override
@@ -139,6 +139,14 @@ public abstract class LuceneIndexImpl implements InternalLuceneIndex {
     this.fieldAnalyzers = fieldAnalyzers == null ? null : Collections.unmodifiableMap(fieldAnalyzers);
   }
 
+  public LuceneIndexStats getIndexStats() {
+    return indexStats;
+  }
+
+  public FileSystemStats getFileSystemStats() {
+    return fileSystemStats;
+  }
+
   protected abstract void initialize();
   
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStats.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStats.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStats.java
index 8dd34a4..ea1f35e 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStats.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStats.java
@@ -20,11 +20,14 @@ package com.gemstone.gemfire.cache.lucene.internal;
 
 import static com.gemstone.gemfire.distributed.internal.DistributionStats.getStatTime;
 
+import java.util.function.IntSupplier;
+
 import com.gemstone.gemfire.StatisticDescriptor;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.StatisticsTypeFactory;
+import com.gemstone.gemfire.internal.CopyOnWriteHashSet;
 import com.gemstone.gemfire.internal.StatisticsTypeFactoryImpl;
 
 public class LuceneIndexStats {
@@ -46,6 +49,7 @@ public class LuceneIndexStats {
   private static final int documentsId;
 
   private final Statistics stats;
+  private final CopyOnWriteHashSet<IntSupplier> documentsSuppliers = new CopyOnWriteHashSet<>();
 
   static {
     final StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
@@ -82,6 +86,7 @@ public class LuceneIndexStats {
 
   public LuceneIndexStats(StatisticsFactory f, String name) {
     this.stats = f.createAtomicStatistics(statsType, name);
+    stats.setIntSupplier(documentsId, this::computeDocumentCount);
   }
 
   /**
@@ -133,7 +138,22 @@ public class LuceneIndexStats {
     stats.incInt(commitsId, 1);
   }
 
-  public void incDocuments(int delta) {
-    stats.incInt(documentsId, delta);
+  public void addDocumentsSuppplier(IntSupplier supplier) {
+    this.documentsSuppliers.add(supplier);
+  }
+
+  public void removeDocumentsSupplier(IntSupplier supplier) {
+    this.documentsSuppliers.remove(supplier);
+  }
+
+  public int getDocuments() {
+    return this.stats.getInt(documentsId);
+  }
+
+  private int computeDocumentCount() {
+    return this.documentsSuppliers.stream()
+      .mapToInt(IntSupplier::getAsInt)
+      .sum();
   }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystemStats.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystemStats.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystemStats.java
index 1f609fd..ee66850 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystemStats.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/filesystem/FileSystemStats.java
@@ -18,6 +18,9 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal.filesystem;
 
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+
 import com.gemstone.gemfire.StatisticDescriptor;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
@@ -38,6 +41,9 @@ public class FileSystemStats {
   private static final int temporaryFileCreatesId;
   private static final int fileDeletesId;
   private static final int fileRenamesId;
+  private static final int filesId;
+  private static final int chunksId;
+  private static final int bytesId;
 
   static {
     final StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
@@ -47,10 +53,13 @@ public class FileSystemStats {
       new StatisticDescriptor[] {
         f.createLongCounter("readBytes", "Number of bytes written", "bytes"),
         f.createLongCounter("writtenBytes", "Number of bytes read", "bytes"),
-        f.createIntCounter("fileCreates", "Number files created", "files"),
-        f.createIntCounter("temporaryFileCreates", "Number temporary files created", "files"),
-        f.createIntCounter("fileDeletes", "Number files deleted", "files"),
-        f.createIntCounter("fileRenames", "Number files renamed", "files"),
+        f.createIntCounter("fileCreates", "Number of files created", "files"),
+        f.createIntCounter("temporaryFileCreates", "Number of temporary files created", "files"),
+        f.createIntCounter("fileDeletes", "Number of files deleted", "files"),
+        f.createIntCounter("fileRenames", "Number of files renamed", "files"),
+        f.createIntGauge("files", "Number of files on this member", "files"),
+        f.createIntGauge("chunks", "Number of file chunks on this member", "chunks"),
+        f.createLongGauge("bytes", "Number of bytes on this member", "bytes"),
       }
     );
 
@@ -60,6 +69,9 @@ public class FileSystemStats {
     temporaryFileCreatesId = statsType.nameToId("temporaryFileCreates");
     fileDeletesId = statsType.nameToId("fileDeletes");
     fileRenamesId = statsType.nameToId("fileRenames");
+    filesId = statsType.nameToId("files");
+    chunksId = statsType.nameToId("chunks");
+    bytesId = statsType.nameToId("bytes");
   }
 
   public FileSystemStats(StatisticsFactory f, String name) {
@@ -89,4 +101,28 @@ public class FileSystemStats {
   public void incFileRenames(final int delta) {
     stats.incInt(fileRenamesId,delta);
   }
+
+  public void setFileSupplier(IntSupplier supplier) {
+    stats.setIntSupplier(filesId, supplier);
+  }
+
+  public int getFiles() {
+    return stats.getInt(filesId);
+  }
+
+  public void setChunkSupplier(IntSupplier supplier) {
+    stats.setIntSupplier(chunksId, supplier);
+  }
+
+  public int getChunks() {
+    return stats.getInt(chunksId);
+  }
+
+  public void setBytesSupplier(LongSupplier supplier) {
+    stats.setLongSupplier(bytesId, supplier);
+  }
+
+  public long getBytes() {
+    return stats.getLong(bytesId);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
index 88631b8..110f85a 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
@@ -32,6 +32,7 @@ import org.apache.lucene.index.Term;
 import org.apache.lucene.search.*;
 
 import java.io.IOException;
+import java.util.function.IntSupplier;
 
 /**
  * A repository that writes to a single lucene index writer
@@ -56,6 +57,7 @@ public class IndexRepositoryImpl implements IndexRepository {
     searcherManager = new SearcherManager(writer, APPLY_ALL_DELETES, true, null);
     this.serializer = serializer;
     this.stats = stats;
+    stats.addDocumentsSuppplier(new DocumentCountSupplier());
   }
 
   @Override
@@ -145,4 +147,15 @@ public class IndexRepositoryImpl implements IndexRepository {
   public boolean isClosed() {
     return region.isDestroyed();
   }
+
+  private class DocumentCountSupplier implements IntSupplier {
+    @Override
+    public int getAsInt() {
+      if(isClosed()) {
+        stats.removeDocumentsSupplier(this);
+        return 0;
+      }
+      return writer.numDocs();
+    }
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index 07780ca..af8c51f 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -22,10 +22,15 @@ import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
 import static org.junit.Assert.*;
 
 import java.io.Serializable;
+import java.util.concurrent.TimeUnit;
 
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexForPartitionedRegion;
+import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexStats;
+import com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemStats;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+import com.jayway.awaitility.Awaitility;
 
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -106,6 +111,31 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
     assertEquals(3, query.search().size());
   }
 
+  @Test
+  public void statsAreUpdatedAfterACommit() throws Exception {
+    luceneService.createIndex(INDEX_NAME, REGION_NAME, "title", "description");
+
+    Region region = createRegion(REGION_NAME, RegionShortcut.PARTITION);
+    region.put("object-1", new TestObject("title 1", "hello world"));
+    region.put("object-2", new TestObject("title 2", "this will not match"));
+    region.put("object-3", new TestObject("title 3", "hello world"));
+    region.put("object-4", new TestObject("hello world", "hello world"));
+
+    LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) luceneService.getIndex(INDEX_NAME, REGION_NAME);
+    index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
+
+    FileSystemStats fileSystemStats = index.getFileSystemStats();
+    LuceneIndexStats indexStats = index.getIndexStats();
+    await(() -> assertEquals(4, indexStats.getDocuments()));
+    await(() -> assertTrue(fileSystemStats.getFiles() > 0));
+    await(() -> assertTrue(fileSystemStats.getChunks() > 0));
+    await(() -> assertTrue(fileSystemStats.getBytes() > 0));
+  }
+
+  private void await(Runnable runnable) {
+    Awaitility.await().atMost(30, TimeUnit.SECONDS).until(runnable);
+  }
+
   private static class TestObject implements Serializable {
 
     String title;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStatsJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStatsJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStatsJUnitTest.java
index 3e6d44c..05e64af 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStatsJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneIndexStatsJUnitTest.java
@@ -18,11 +18,16 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.*;
 
+import java.util.function.IntSupplier;
+
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsFactory;
 import com.gemstone.gemfire.StatisticsType;
+import com.gemstone.gemfire.distributed.internal.InternalDistributedSystemJUnitTest;
+import com.gemstone.gemfire.management.internal.cli.parser.Argument;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 import org.junit.Before;
@@ -88,9 +93,15 @@ public class LuceneIndexStatsJUnitTest {
   }
 
   @Test
-  public void shouldIncrementDocumentStat() {
-    stats.incDocuments(5);
-    verifyIncInt("documents", 5);
+  public void shouldPollSuppliersForDocumentStat() {
+    stats.addDocumentsSuppplier(() -> 5);
+    stats.addDocumentsSuppplier(() -> 3);
+
+    int documentsId = type.nameToId("documents");
+    ArgumentCaptor<IntSupplier> documentsSupplierCaptor = ArgumentCaptor.forClass(IntSupplier.class);
+    verify(statistics).setIntSupplier(eq(documentsId), documentsSupplierCaptor.capture());
+    IntSupplier documentsSuppler = documentsSupplierCaptor.getValue();
+    assertEquals(8, documentsSuppler.getAsInt());
   }
 
   private void verifyIncInt(final String statName, final int value) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/615e643c/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplJUnitTest.java
index 6004623..7d3caf8 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplJUnitTest.java
@@ -29,6 +29,7 @@ import java.util.HashSet;
 import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.IntSupplier;
 
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.index.IndexWriter;
@@ -38,6 +39,7 @@ import org.apache.lucene.queryparser.classic.QueryParser;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
 import org.mockito.Mockito;
 
 import com.gemstone.gemfire.cache.Region;
@@ -153,6 +155,16 @@ public class IndexRepositoryImplJUnitTest {
     verify(stats, times(1)).endQuery(anyLong(), eq(2));
   }
 
+  @Test
+  public void addingDocumentsShouldUpdateDocumentsStat() throws IOException {
+    repo.create("key1", new Type2("bar", 1, 2L, 3.0, 4.0f, "Grape Ape doughnut"));
+    repo.commit();
+    ArgumentCaptor<IntSupplier> captor = ArgumentCaptor.forClass(IntSupplier.class);
+    verify(stats).addDocumentsSuppplier(captor.capture());
+    IntSupplier supplier = captor.getValue();
+    assertEquals(1, supplier.getAsInt());
+  }
+
   private void updateAndRemove(Object key1, Object key2, Object key3,
       Object key4) throws IOException, ParseException {
     repo.create(key1, new Type2("bacon maple bar", 1, 2L, 3.0, 4.0f, "Grape Ape doughnut"));


[11/23] incubator-geode git commit: GEODE-1542 shared/unordered tcp/ip connection times out, initiating suspicion

Posted by kl...@apache.org.
GEODE-1542 shared/unordered tcp/ip connection times out, initiating suspicion

This disables timing out of shared/unordered TcpConduit connections.  We don't
want them to time out because we are using them to initiate suspect processing
on other members.

The ticket also pointed out a problem with the "final check" mechanism in
the health monitor.  I tracked that down to improper use of SocketCreator
to create the server-socket in GMSHealthMonitor.  It was creating sn SSL
socket if SSL is enabled but the client-side of the check uses non-SSL
sockets.  I changed the server to use non-SSL sockets as well since no
useful information is sent over the final-check TCP/IP connections & they
need to be lightweight and fast.

While looking at logs I also found that the heartbeat request sent at the
beginning of a final-check had a request-ID even though it's not waiting
for a response.  That causes processing of the response to do more work
than necessary so I changed it to remove the request-ID from the message.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/33ceb371
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/33ceb371
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/33ceb371

Branch: refs/heads/feature/GEODE-835
Commit: 33ceb371554a13c7643ddaf9488ffa83963de1e7
Parents: 4afc5b1
Author: Bruce Schuchardt <bs...@pivotal.io>
Authored: Tue Jun 14 10:46:16 2016 -0700
Committer: Bruce Schuchardt <bs...@pivotal.io>
Committed: Tue Jun 14 10:47:53 2016 -0700

----------------------------------------------------------------------
 .../membership/gms/fd/GMSHealthMonitor.java     | 75 ++++++++++----------
 .../membership/gms/membership/GMSJoinLeave.java |  8 +--
 .../gms/messages/HeartbeatRequestMessage.java   |  8 +++
 .../gemfire/internal/SocketCreator.java         | 35 +++++++--
 .../gemfire/internal/tcp/Connection.java        |  4 +-
 5 files changed, 81 insertions(+), 49 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33ceb371/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
index f27e0b8..203d9ce 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
@@ -19,6 +19,7 @@ package com.gemstone.gemfire.distributed.internal.membership.gms.fd;
 import static com.gemstone.gemfire.internal.DataSerializableFixedID.HEARTBEAT_REQUEST;
 import static com.gemstone.gemfire.internal.DataSerializableFixedID.HEARTBEAT_RESPONSE;
 import static com.gemstone.gemfire.internal.DataSerializableFixedID.SUSPECT_MEMBERS_MESSAGE;
+import static com.sun.corba.se.impl.naming.cosnaming.NamingUtils.debug;
 
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
@@ -195,7 +196,7 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
       return timeStamp;
     }
 
-    public void setTimeStamp(long timeStamp) {
+    public void setTime(long timeStamp) {
       this.timeStamp = timeStamp;
     }
   }
@@ -289,48 +290,41 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
         long uuidMSBs = in.readLong();
         GMSHealthMonitor.this.stats.incFinalCheckRequestsReceived();
         GMSHealthMonitor.this.stats.incTcpFinalCheckRequestsReceived();
-        boolean debug = logger.isDebugEnabled();
         GMSMember gmbr = (GMSMember) GMSHealthMonitor.this.localAddress.getNetMember();
         UUID myUUID = gmbr.getUUID();
         // during reconnect or rapid restart we will have a zero viewId but there may still
         // be an old ID in the membership view that we do not want to respond to
         int myVmViewId = gmbr.getVmViewId();
-        if (debug) {
-          if (playingDead) {
-            logger.debug("simulating sick member in health check");
-          } else if (vmViewId == myVmViewId
-            && uuidLSBs == myUUID.getLeastSignificantBits()
-            && uuidMSBs == myUUID.getMostSignificantBits()) {
-            logger.debug("UUID matches my own - sending OK reply");
-          } else {
-            logger.debug("GMSHealthMonitor my UUID is {},{} received is {},{}.  My viewID is {} received is {}",
-              Long.toHexString(myUUID.getMostSignificantBits()),
-              Long.toHexString(myUUID.getLeastSignificantBits()),
-              Long.toHexString(uuidMSBs), Long.toHexString(uuidLSBs),
-              myVmViewId, vmViewId);
-          }
-        }
-        if (!playingDead
-            && uuidLSBs == myUUID.getLeastSignificantBits()
-            && uuidMSBs == myUUID.getMostSignificantBits()
-            && vmViewId == myVmViewId) {
+        if (playingDead) {
+          logger.debug("HealthMonitor: simulating sick member in health check");
+        } else if (uuidLSBs == myUUID.getLeastSignificantBits()
+                   && uuidMSBs == myUUID.getMostSignificantBits()
+                   && vmViewId == myVmViewId) {
+          logger.debug("HealthMonitor: sending OK reply");
           out.write(OK);
           out.flush();
           socket.shutdownOutput();
           GMSHealthMonitor.this.stats.incFinalCheckResponsesSent();
           GMSHealthMonitor.this.stats.incTcpFinalCheckResponsesSent();
           if (debug) {
-            logger.debug("GMSHealthMonitor server socket replied OK.");
+            logger.debug("HealthMonitor: server replied OK.");
+          }
+        } else {
+          if (logger.isDebugEnabled()) {
+            logger.debug("HealthMonitor: sending ERROR reply - my UUID is {},{} received is {},{}.  My viewID is {} received is {}", 
+              Long.toHexString(myUUID.getMostSignificantBits()),
+              Long.toHexString(myUUID.getLeastSignificantBits()), 
+              Long.toHexString(uuidMSBs),
+              Long.toHexString(uuidLSBs),
+              myVmViewId, vmViewId);
           }
-        }
-        else {
           out.write(ERROR);
           out.flush();
           socket.shutdownOutput();
           GMSHealthMonitor.this.stats.incFinalCheckResponsesSent();
           GMSHealthMonitor.this.stats.incTcpFinalCheckResponsesSent();
           if (debug) {
-            logger.debug("GMSHealthMonitor server socket replied ERROR.");
+            logger.debug("HealthMonitor: server replied ERROR.");
           }
         }
       } catch (IOException e) {
@@ -376,8 +370,8 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
   private void contactedBy(InternalDistributedMember sender, long timeStamp) {
     TimeStamp cTS = new TimeStamp(timeStamp);
     cTS = memberTimeStamps.putIfAbsent(sender, cTS);
-    if (cTS != null) {
-      cTS.setTimeStamp(timeStamp);
+    if (cTS != null && cTS.getTime() < timeStamp) {
+      cTS.setTime(timeStamp);
     }
     if (suspectedMemberInView.remove(sender) != null) {
       logger.info("No longer suspecting {}", sender);
@@ -405,8 +399,6 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
 
       @Override
       public void run() {
-        // TODO GemFire used the tcp/ip connection but this is using heartbeats
-
         boolean pinged = false;
         try {
           pinged = GMSHealthMonitor.this.doCheckMember(mbr, true);
@@ -455,9 +447,12 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
     long startTime = System.currentTimeMillis();
     logger.trace("Checking member {}", member);
     final HeartbeatRequestMessage hrm = constructHeartbeatRequestMessage(member);
-    final Response pingResp = new Response();
-    if(waitForResponse) {
+    Response pingResp = null;
+    if (waitForResponse) {
+      pingResp = new Response();
       requestIdVsResponse.put(hrm.getRequestId(), pingResp);
+    } else {
+      hrm.clearRequestId();
     }
     try {
       Set<InternalDistributedMember> membersNotReceivedMsg = this.services.getMessenger().send(hrm);
@@ -484,7 +479,7 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
             logger.trace("received heartbeat from {}", member);
             this.stats.incHeartbeatsReceived();
             if (ts != null) {
-              ts.setTimeStamp(System.currentTimeMillis());
+              ts.setTime(System.currentTimeMillis());
             }
             return true;
           }
@@ -547,12 +542,13 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
         DataOutputStream out = new DataOutputStream(clientSocket.getOutputStream());
         GMSMember gmbr = (GMSMember) suspectMember.getNetMember();
         writeMemberToStream(gmbr, out);
-        clientSocket.shutdownOutput();
         this.stats.incFinalCheckRequestsSent();
         this.stats.incTcpFinalCheckRequestsSent();
-        logger.debug("Connected - reading response from suspect member {}", suspectMember);
+        logger.debug("Connected to suspect member - reading response");
         int b = in.read();
-        logger.debug("Received {}", (b == OK ? "OK" : (b == ERROR ? "ERROR" : b)), suspectMember);
+        if (logger.isDebugEnabled()) {
+          logger.debug("Received {}", (b == OK ? "OK" : (b == ERROR ? "ERROR" : "unknown response: " + b)));
+        }
         if (b >= 0) {
           this.stats.incFinalCheckResponsesReceived();
           this.stats.incTcpFinalCheckResponsesReceived();
@@ -560,7 +556,7 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
         if (b == OK) {
           TimeStamp ts = memberTimeStamps.get(suspectMember);
           if (ts != null) {
-            ts.setTimeStamp(System.currentTimeMillis());
+            ts.setTime(System.currentTimeMillis());
           }
           return true;
         } else {
@@ -659,7 +655,8 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
   ServerSocket createServerSocket(InetAddress socketAddress, int[] portRange) {
     ServerSocket serverSocket = null;
     try {
-      serverSocket = SocketCreator.getDefaultInstance().createServerSocketUsingPortRange(socketAddress, 50/*backlog*/, true/*isBindAddress*/, false/*useNIO*/, 65536/*tcpBufferSize*/, portRange);
+      serverSocket = SocketCreator.getDefaultInstance().createServerSocketUsingPortRange(socketAddress, 50/*backlog*/, 
+        true/*isBindAddress*/, false/*useNIO*/, 65536/*tcpBufferSize*/, portRange, false);
       socketPort = serverSocket.getLocalPort();
     } catch (IOException e) {
       throw new GemFireConfigException("Unable to allocate a failure detection port in the membership-port range", e);
@@ -1285,8 +1282,8 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
         //this will just send heartbeat request, it will not wait for response
         //if we will get heartbeat then it will change the timestamp, which we are 
         //checking below in case of tcp check failure..
-        GMSHealthMonitor.this.doCheckMember(mbr, false);
-        pinged = GMSHealthMonitor.this.doTCPCheckMember(mbr, port);
+        doCheckMember(mbr, false);
+        pinged = doTCPCheckMember(mbr, port);
       }
   
       if (!pinged && !isStopping) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33ceb371/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
index 8dce1a5..87fac53 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/membership/GMSJoinLeave.java
@@ -533,7 +533,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     }
 
     if (!isCoordinator && !isStopping && !services.getCancelCriterion().isCancelInProgress()) {
-      logger.debug("JoinLeave is checking to see if I should become coordinator");
+      logger.debug("Checking to see if I should become coordinator");
       NetView check = new NetView(v, v.getViewId() + 1);
       check.remove(incomingRequest.getMemberID());
       synchronized (removedMembers) {
@@ -600,7 +600,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
     }
 
     if (!isCoordinator && !isStopping && !services.getCancelCriterion().isCancelInProgress()) {
-      logger.debug("JoinLeave is checking to see if I should become coordinator");
+      logger.debug("Checking to see if I should become coordinator");
       NetView check = new NetView(v, v.getViewId() + 1);
       synchronized (removedMembers) {
         removedMembers.add(mbr);
@@ -630,7 +630,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
   }
 
   private void recordViewRequest(DistributionMessage request) {
-    logger.debug("JoinLeave is recording the request to be processed in the next membership view");
+    logger.debug("Recording the request to be processed in the next membership view");
     synchronized (viewRequests) {
       viewRequests.add(request);
       viewRequests.notifyAll();
@@ -1441,7 +1441,7 @@ public class GMSJoinLeave implements JoinLeave, MessageHandler {
       if (view != null) {
         if (view.size() > 1) {
           List<InternalDistributedMember> coords = view.getPreferredCoordinators(Collections.<InternalDistributedMember>emptySet(), localAddress, 5);
-          logger.debug("JoinLeave sending a leave request to {}", coords);
+          logger.debug("Sending my leave request to {}", coords);
           LeaveRequestMessage m = new LeaveRequestMessage(coords, this.localAddress, "this member is shutting down");
           services.getMessenger().send(m);
         } // view.size

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33ceb371/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/HeartbeatRequestMessage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/HeartbeatRequestMessage.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/HeartbeatRequestMessage.java
index 3c08e33..e0f4515 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/HeartbeatRequestMessage.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/messages/HeartbeatRequestMessage.java
@@ -41,6 +41,14 @@ public class HeartbeatRequestMessage extends HighPriorityDistributionMessage{
   public InternalDistributedMember getTarget() {
     return target;
   }
+
+  /**
+   * If no response is desired the requestId can be reset by invoking
+   * this method
+   */
+  public void clearRequestId() {
+    requestId = -1;
+  }
   
   @Override
   public int getDSFID() {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33ceb371/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
index 367d4a7..739028c 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
@@ -16,6 +16,8 @@
  */
 package com.gemstone.gemfire.internal;
 
+import static javafx.scene.input.KeyCode.L;
+
 import com.gemstone.gemfire.GemFireConfigException;
 import com.gemstone.gemfire.SystemConnectException;
 import com.gemstone.gemfire.SystemFailure;
@@ -765,16 +767,22 @@ public class SocketCreator {
    *  SSL configuration is left up to JSSE properties in java.security file.
    */
   public ServerSocket createServerSocket( int nport, int backlog, InetAddress bindAddr ) throws IOException {
-    return createServerSocket( nport, backlog, bindAddr, -1 );
+    return createServerSocket( nport, backlog, bindAddr, -1, useSSL);
   }
 
   public ServerSocket createServerSocket(int nport, int backlog,
-      InetAddress bindAddr, int socketBufferSize)
+                                         InetAddress bindAddr, int socketBufferSize)
+    throws IOException {
+    return createServerSocket(nport, backlog, bindAddr, socketBufferSize, useSSL);
+  }
+  
+  private ServerSocket createServerSocket(int nport, int backlog,
+      InetAddress bindAddr, int socketBufferSize, boolean sslConnection)
       throws IOException {
     //       rw.readLock().lockInterruptibly();
 //       try {
         printConfig();
-        if ( this.useSSL ) {
+        if ( sslConnection ) {
           if (this.sslContext == null) {
             throw new GemFireConfigException("SSL not configured correctly, Please look at previous error");
           }
@@ -830,7 +838,23 @@ public class SocketCreator {
   public ServerSocket createServerSocketUsingPortRange(InetAddress ba, int backlog,
       boolean isBindAddress, boolean useNIO, int tcpBufferSize, int[] tcpPortRange)
       throws IOException {
-    
+    return createServerSocketUsingPortRange(ba, backlog, isBindAddress, useNIO, tcpBufferSize, tcpPortRange, this.useSSL);
+  }
+
+    /**
+     * Creates or bind server socket to a random port selected
+     * from tcp-port-range which is same as membership-port-range.
+     * @param ba
+     * @param backlog
+     * @param isBindAddress
+     * @param tcpBufferSize
+     * @param sslConnection whether to connect using SSL
+     * @return Returns the new server socket.
+     * @throws IOException
+     */
+    public ServerSocket createServerSocketUsingPortRange(InetAddress ba, int backlog,
+    boolean isBindAddress, boolean useNIO, int tcpBufferSize, int[] tcpPortRange, boolean sslConnection)
+    throws IOException {
     ServerSocket socket = null;
     int localPort = 0;
     int startingPort = 0;
@@ -862,7 +886,8 @@ public class SocketCreator {
           InetSocketAddress addr = new InetSocketAddress(isBindAddress ? ba : null, localPort);
           socket.bind(addr, backlog);
         } else {
-          socket = SocketCreator.getDefaultInstance().createServerSocket(localPort, backlog, isBindAddress? ba : null, tcpBufferSize);
+          socket = SocketCreator.getDefaultInstance()
+                                .createServerSocket(localPort, backlog, isBindAddress? ba : null, tcpBufferSize, sslConnection);
         }
         break;
       } catch (java.net.SocketException ex) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/33ceb371/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/Connection.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/Connection.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/Connection.java
index 85e3511..6528877 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/Connection.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/tcp/Connection.java
@@ -569,7 +569,9 @@ public class Connection implements Runnable {
     if (isSocketClosed()) {
       return true;
     }
-    if (isSocketInUse()) {
+    if (isSocketInUse()
+        || (this.sharedResource && !this.preserveOrder)) { // shared/unordered connections are used for failure-detection
+                                                           // and are not subject to idle-timeout
       return false;
     }
     boolean isIdle = !this.accessed;


[19/23] incubator-geode git commit: GEODE-11: Support indexing values that are Strings or Numbers

Posted by kl...@apache.org.
GEODE-11: Support indexing values that are Strings or Numbers

Adding support to index values that are strings or numbers, by providing
a special field name LuceneIndex.REGION_VALUE_FIELD that indicates the
entire value should be indexed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/f59e8d0b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/f59e8d0b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/f59e8d0b

Branch: refs/heads/feature/GEODE-835
Commit: f59e8d0b22c7ebb4600b8cfa9c1e0b00d3925f05
Parents: 3de21f5
Author: Dan Smith <up...@apache.org>
Authored: Mon Jun 13 16:49:23 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Wed Jun 15 10:09:14 2016 -0700

----------------------------------------------------------------------
 .../gemfire/cache/lucene/LuceneService.java     | 16 +++++-
 .../lucene/internal/LuceneServiceImpl.java      |  6 +++
 .../HeterogeneousLuceneSerializer.java          | 22 +++++++-
 .../serializer/PrimitiveSerializer.java         | 35 +++++++++++++
 .../repository/serializer/SerializerUtil.java   | 30 +++++++++--
 .../lucene/LuceneQueriesIntegrationTest.java    | 13 +++++
 .../internal/LuceneServiceImplJUnitTest.java    | 53 ++++++++++++++++++++
 .../HeterogeneousLuceneSerializerJUnitTest.java | 21 ++++++++
 8 files changed, 188 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
index 462aa7e..974cf96 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneService.java
@@ -68,9 +68,20 @@ import com.gemstone.gemfire.cache.GemFireCache;
  */
 @Experimental
 public interface LuceneService {
-  
+
+  /**
+   * A special field name that indicates that the entire region value should
+   * be indexed. This will only work if the region value is a String or Number, in
+   * which case a lucene document will be created with a single field with this name.
+   */
+  String REGION_VALUE_FIELD = "__REGION_VALUE_FIELD";
+
   /**
    * Create a lucene index using default analyzer.
+   * @param fields The fields of the object to index. Only fields listed here will be stored
+   * in the index. Fields should map to PDX fieldNames if the object is serialized with PDX, or
+   * to java fields on the object otherwise. The special field name {{@link #REGION_VALUE_FIELD}}
+   * indicates that the entire value should be stored as a single field in the index.
    */
   public void createIndex(String indexName, String regionPath, String... fields);
   
@@ -79,7 +90,8 @@ public interface LuceneService {
    * 
    * @param indexName index name
    * @param regionPath region name
-   * @param analyzerPerField analyzer per field map
+   * @param analyzerPerField A map of fields to analyzers. See {{@link #createIndex(String, String, String...)}}
+   * for details on valid values for fields. Each field will be tokenized using the provided Analyzer.
    */
   public void createIndex(String indexName, String regionPath,
       Map<String, Analyzer> analyzerPerField);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
index 47c4d76..6bfaa78 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImpl.java
@@ -102,6 +102,9 @@ public class LuceneServiceImpl implements InternalLuceneService {
 
   @Override
   public void createIndex(String indexName, String regionPath, String... fields) {
+    if(fields == null || fields.length == 0) {
+      throw new IllegalArgumentException("At least one field must be indexed");
+    }
     StandardAnalyzer analyzer = new StandardAnalyzer();
     
     createIndex(indexName, regionPath, analyzer, null, fields);
@@ -109,6 +112,9 @@ public class LuceneServiceImpl implements InternalLuceneService {
   
   @Override
   public void createIndex(String indexName, String regionPath, Map<String, Analyzer> fieldAnalyzers) {
+    if(fieldAnalyzers == null || fieldAnalyzers.isEmpty()) {
+      throw new IllegalArgumentException("At least one field must be indexed");
+    }
     Analyzer analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(), fieldAnalyzers);
     Set<String> fieldsSet = fieldAnalyzers.keySet();
     String[] fields = (String[])fieldsSet.toArray(new String[fieldsSet.size()]);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
index d2b1db1..271f0fd 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializer.java
@@ -18,11 +18,14 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal.repository.serializer;
 
+import java.util.Arrays;
 import java.util.Map;
 
 import org.apache.logging.log4j.Logger;
 import org.apache.lucene.document.Document;
 
+import com.gemstone.gemfire.cache.lucene.LuceneIndex;
+import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.util.concurrent.CopyOnWriteWeakHashMap;
 import com.gemstone.gemfire.pdx.PdxInstance;
@@ -42,7 +45,7 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer {
    * A mapper for converting a PDX object into a document
    */
   private LuceneSerializer pdxMapper;
-  
+
   /**
    * Mappers for each individual class type that this class has seen.
    * 
@@ -55,8 +58,23 @@ public class HeterogeneousLuceneSerializer implements LuceneSerializer {
   public HeterogeneousLuceneSerializer(String[] indexedFields) {
     this.indexedFields = indexedFields;
     pdxMapper = new PdxLuceneSerializer(indexedFields);
+
+
+    addSerializersForPrimitiveValues();
   }
-  
+
+  /**
+   * Add serializers for the primitive value types (String, Number, etc.)
+   * if the user has requested that the whole value be serialized
+   */
+  private void addSerializersForPrimitiveValues() {
+    if(Arrays.asList(indexedFields).contains(LuceneService.REGION_VALUE_FIELD)) {
+      final PrimitiveSerializer primitiveSerializer = new PrimitiveSerializer();
+      SerializerUtil.supportedPrimitiveTypes().stream()
+        .forEach(type -> mappers.put(type, primitiveSerializer));
+    }
+  }
+
   @Override
   public void toDocument(Object value, Document doc) {
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PrimitiveSerializer.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PrimitiveSerializer.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PrimitiveSerializer.java
new file mode 100644
index 0000000..d096637
--- /dev/null
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/PrimitiveSerializer.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.gemstone.gemfire.cache.lucene.internal.repository.serializer;
+
+import com.gemstone.gemfire.cache.lucene.LuceneService;
+
+import org.apache.lucene.document.Document;
+
+/**
+ * A LuceneSerializer that can serialize a primitive value (String, int, long, double)
+ * by creating a document with a special field containing the value
+ */
+public class PrimitiveSerializer implements LuceneSerializer {
+
+  @Override
+  public void toDocument(final Object value, final Document doc) {
+    SerializerUtil.addField(doc, LuceneService.REGION_VALUE_FIELD, value);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/SerializerUtil.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/SerializerUtil.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/SerializerUtil.java
index 0ed9d5d..4d563c1 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/SerializerUtil.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/SerializerUtil.java
@@ -22,6 +22,10 @@ package com.gemstone.gemfire.cache.lucene.internal.repository.serializer;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Set;
 
 import org.apache.lucene.document.Document;
 import org.apache.lucene.document.DoublePoint;
@@ -44,6 +48,23 @@ import com.gemstone.gemfire.internal.util.BlobHelper;
  */
 public class SerializerUtil {
   private static final String KEY_FIELD = "_KEY";
+
+  private static final Set<Class> SUPPORTED_PRIMITIVE_TYPES;
+
+  static {
+    HashSet<Class> primitiveTypes = new HashSet<>();
+    primitiveTypes.add(String.class);
+    primitiveTypes.add(long.class);
+    primitiveTypes.add(int.class);
+    primitiveTypes.add(float.class);
+    primitiveTypes.add(double.class);
+    primitiveTypes.add(Long.class);
+    primitiveTypes.add(Integer.class);
+    primitiveTypes.add(Float.class);
+    primitiveTypes.add(Double.class);
+
+    SUPPORTED_PRIMITIVE_TYPES = Collections.unmodifiableSet(primitiveTypes);
+  }
   
   /**
    * A small buffer for converting keys to byte[] arrays.
@@ -97,10 +118,11 @@ public class SerializerUtil {
    * Return true if a field type can be written to a lucene document.
    */
   public static boolean isSupported(Class<?> type) {
-    return type == String.class || type == long.class || type == int.class 
-        || type == float.class || type == double.class
-        || type == Long.class || type == Integer.class 
-        || type == Float.class || type == Double.class; 
+    return SUPPORTED_PRIMITIVE_TYPES.contains(type);
+  }
+
+  public static Collection<Class> supportedPrimitiveTypes() {
+    return SUPPORTED_PRIMITIVE_TYPES;
   }
   
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 587e4db..674bc9c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -186,6 +186,19 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
   }
 
   @Test()
+  public void shouldAllowQueryOnRegionWithStringValue() throws ParseException {
+    luceneService.createIndex(INDEX_NAME, REGION_NAME, LuceneService.REGION_VALUE_FIELD);
+    Region region = cache.createRegionFactory(RegionShortcut.PARTITION)
+      .create(REGION_NAME);
+    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+
+    region.put("A", "one three");
+    index.waitUntilFlushed(60000);
+
+    verifyQuery("one", LuceneService.REGION_VALUE_FIELD, "A");
+  }
+
+  @Test()
   public void throwFunctionExceptionWhenGivenBadQuery() {
     LuceneService luceneService = LuceneServiceProvider.get(cache);
     luceneService.createIndex(INDEX_NAME, REGION_NAME, "text");

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
new file mode 100644
index 0000000..3f96323
--- /dev/null
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneServiceImplJUnitTest.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package com.gemstone.gemfire.cache.lucene.internal;
+
+import static org.junit.Assert.*;
+
+import java.util.Collections;
+
+import com.gemstone.gemfire.cache.lucene.LuceneService;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category(UnitTest.class)
+public class LuceneServiceImplJUnitTest {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void shouldThrowIllegalArgumentExceptionIfFieldsAreMissing() {
+    LuceneServiceImpl service = new LuceneServiceImpl();
+    thrown.expect(IllegalArgumentException.class);
+    service.createIndex("index", "region");
+  }
+
+  @Test
+  public void shouldThrowIllegalArgumentExceptionIfFieldsMapIsMissing() {
+    LuceneServiceImpl service = new LuceneServiceImpl();
+    thrown.expect(IllegalArgumentException.class);
+    service.createIndex("index", "region", Collections.emptyMap());
+  }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/f59e8d0b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java
index 3bce904..7b32ab2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/serializer/HeterogeneousLuceneSerializerJUnitTest.java
@@ -25,6 +25,7 @@ import org.apache.lucene.document.Document;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
+import com.gemstone.gemfire.cache.lucene.LuceneService;
 import com.gemstone.gemfire.pdx.PdxInstance;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
@@ -83,4 +84,24 @@ public class HeterogeneousLuceneSerializerJUnitTest {
     assertEquals(5, doc3.getField("i").numericValue());
   }
 
+  @Test
+  public void shouldIndexPrimitiveStringIfRequested() {
+    HeterogeneousLuceneSerializer mapper = new HeterogeneousLuceneSerializer(new String[] {LuceneService.REGION_VALUE_FIELD});
+    Document doc = new Document();
+    mapper.toDocument("sample value", doc);
+    assertEquals(1, doc.getFields().size());
+    assertEquals("sample value", doc.getField(LuceneService.REGION_VALUE_FIELD).stringValue());
+  }
+
+  @Test
+  public void shouldIndexPrimitiveNumberIfRequested() {
+    HeterogeneousLuceneSerializer mapper = new HeterogeneousLuceneSerializer(new String[] {LuceneService.REGION_VALUE_FIELD});
+    Document doc = new Document();
+    mapper.toDocument(53, doc);
+
+    assertEquals(1, doc.getFields().size());
+
+    assertEquals(53, doc.getField(LuceneService.REGION_VALUE_FIELD).numericValue());
+  }
+
 }


[23/23] incubator-geode git commit: Merge remote-tracking branch 'origin/develop' into feature/GEODE-835

Posted by kl...@apache.org.
Merge remote-tracking branch 'origin/develop' into feature/GEODE-835


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/fab62c21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/fab62c21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/fab62c21

Branch: refs/heads/feature/GEODE-835
Commit: fab62c21cd375da550c8e54da1bc74c7891c17d9
Parents: a3cc509 144e7d1
Author: Kirk Lund <kl...@apache.org>
Authored: Thu Jun 16 10:16:25 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Jun 16 10:16:25 2016 -0700

----------------------------------------------------------------------
 .../java/com/gemstone/gemfire/Statistics.java   | 253 ++++++++++++++
 .../gemfire/cache/PartitionResolver.java        |  17 +-
 .../internal/ParallelAsyncEventQueueImpl.java   |   4 +-
 .../gemfire/distributed/DistributedMember.java  |   1 +
 .../distributed/GatewayCancelledException.java  |   2 +-
 .../distributed/OplogCancelledException.java    |   2 +-
 .../distributed/PoolCancelledException.java     |   2 +-
 .../internal/InternalDistributedSystem.java     |  36 +-
 .../internal/membership/NetView.java            |  10 +-
 .../membership/gms/fd/GMSHealthMonitor.java     |  91 +++---
 .../membership/gms/membership/GMSJoinLeave.java |   8 +-
 .../gms/messages/HeartbeatRequestMessage.java   |   8 +
 .../internal/AbstractStatisticsFactory.java     |  65 ++--
 .../gemfire/internal/DummyStatisticsImpl.java   |  44 +++
 .../gemfire/internal/GemFireStatSampler.java    |  14 +-
 .../gemfire/internal/HostStatSampler.java       |  20 +-
 .../gemfire/internal/SocketCreator.java         |  33 +-
 .../gemfire/internal/StatSamplerStats.java      |  34 +-
 .../gemfire/internal/StatisticsImpl.java        | 143 +++++++-
 .../gemfire/internal/StatisticsTypeImpl.java    |   6 +-
 .../gemfire/internal/cache/EntryEventImpl.java  |  42 +--
 .../gemfire/internal/cache/LocalRegion.java     |   5 +-
 .../internal/cache/RemoteOperationMessage.java  |  10 +-
 .../gemfire/internal/cache/TXManagerImpl.java   |  32 +-
 .../cache/control/HeapMemoryMonitor.java        |  20 +-
 .../cache/partitioned/PartitionMessage.java     |  10 +-
 .../logging/log4j/LogWriterAppender.java        |  12 +-
 .../internal/statistics/CallbackSampler.java    |  96 ++++++
 .../internal/statistics/SampleCollector.java    |   4 +-
 .../gemfire/internal/tcp/Connection.java        |   4 +-
 .../management/MemoryThresholdsDUnitTest.java   |   6 +
 .../cache30/RolePerformanceDUnitTest.java       | 192 -----------
 .../internal/membership/NetViewJUnitTest.java   |   2 +-
 .../internal/LocalStatisticsImplJUnitTest.java  | 139 ++++++++
 .../StatArchiveWriterReaderJUnitTest.java       |  16 +-
 .../gemfire/internal/StatSamplerJUnitTest.java  |  34 +-
 .../internal/cache/EntryEventImplTest.java      | 327 ++++++++++++++++++-
 .../gemfire/internal/cache/OplogJUnitTest.java  |  51 +--
 .../cache/RemoteOperationMessageTest.java       |  31 +-
 .../internal/cache/TXManagerImplTest.java       |  73 ++++-
 .../cache/partitioned/PartitionMessageTest.java |  27 +-
 .../statistics/CallbackSamplerJUnitTest.java    |  98 ++++++
 .../internal/statistics/DummyStatistics.java    | 208 ------------
 .../sanctionedDataSerializables.txt             |  20 +-
 .../cache/lucene/LuceneQueryFactory.java        |   3 +-
 .../cache/lucene/LuceneQueryProvider.java       |   1 +
 .../gemfire/cache/lucene/LuceneService.java     |  16 +-
 .../LuceneIndexForPartitionedRegion.java        |  14 +-
 .../cache/lucene/internal/LuceneIndexImpl.java  |  32 +-
 .../cache/lucene/internal/LuceneIndexStats.java |  24 +-
 .../lucene/internal/LuceneQueryFactoryImpl.java |   4 +-
 .../cache/lucene/internal/LuceneQueryImpl.java  |   3 +-
 .../lucene/internal/LuceneServiceImpl.java      |   6 +
 .../lucene/internal/StringQueryProvider.java    |  29 +-
 .../internal/filesystem/FileSystemStats.java    |  44 ++-
 .../repository/IndexRepositoryImpl.java         |  13 +
 .../HeterogeneousLuceneSerializer.java          |  22 +-
 .../serializer/PrimitiveSerializer.java         |  35 ++
 .../repository/serializer/SerializerUtil.java   |  30 +-
 ...IndexCreationPersistenceIntegrationTest.java |  33 +-
 .../LuceneIndexMaintenanceIntegrationTest.java  |  42 ++-
 .../gemfire/cache/lucene/LuceneQueriesBase.java |  29 +-
 .../lucene/LuceneQueriesIntegrationTest.java    | 108 +++++-
 ...LuceneQueriesPersistenceIntegrationTest.java |  15 +-
 .../internal/LuceneIndexStatsJUnitTest.java     |  17 +-
 .../LuceneQueryFactoryImplJUnitTest.java        |   6 +-
 .../LuceneQueryImplIntegrationTest.java         |   5 +-
 .../internal/LuceneServiceImplJUnitTest.java    |  53 +++
 .../internal/StringQueryProviderJUnitTest.java  |  27 +-
 .../LuceneFunctionContextJUnitTest.java         |   3 +-
 .../distributed/LuceneFunctionJUnitTest.java    |   4 +-
 .../TopEntriesFunctionCollectorJUnitTest.java   |   6 +-
 .../IndexRepositoryImplJUnitTest.java           |  12 +
 .../IndexRepositoryImplPerformanceTest.java     |   2 +-
 .../HeterogeneousLuceneSerializerJUnitTest.java |  21 ++
 .../cache/lucene/test/LuceneTestUtilities.java  |  28 ++
 .../gemfire/cache/lucene/test/TestObject.java   |   7 +
 geode-site/website/content/community/index.html |   3 +-
 .../wan/parallel/ParallelGatewaySenderImpl.java |   4 +-
 ...arallelGatewaySenderOperationsDUnitTest.java |   9 +-
 gradle/dependency-versions.properties           |   2 +-
 81 files changed, 2075 insertions(+), 889 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/fab62c21/gradle/dependency-versions.properties
----------------------------------------------------------------------


[10/23] incubator-geode git commit: GEODE-1443: fix PartitionResolver javadocs

Posted by kl...@apache.org.
GEODE-1443: fix PartitionResolver javadocs

The javadocs now describes the third option of using
a callback argument as the PartitionResolver.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/4afc5b15
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/4afc5b15
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/4afc5b15

Branch: refs/heads/feature/GEODE-835
Commit: 4afc5b1531d1b10afd7f40beaa535a49abd22282
Parents: e84e885
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jun 14 10:26:50 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jun 14 10:26:50 2016 -0700

----------------------------------------------------------------------
 .../gemstone/gemfire/cache/PartitionResolver.java  | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4afc5b15/geode-core/src/main/java/com/gemstone/gemfire/cache/PartitionResolver.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/PartitionResolver.java b/geode-core/src/main/java/com/gemstone/gemfire/cache/PartitionResolver.java
index 562a42b..253a108 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/PartitionResolver.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/PartitionResolver.java
@@ -18,19 +18,24 @@ package com.gemstone.gemfire.cache;
 
 /**
  * Implementers of interface <code>PartitionResolver</code> enable custom
- * partitioning on the <code>PartitionedRegion</code>.<br>
+ * standard partitioning on the <code>PartitionedRegion</code>.<br>
+ * See <code>FixedPartitionResolver</code> to enable custom fixed partitioning.<br>
  * <p>
- * 1. The Key class can implement PartitionResolver interface to
- * enable custom partitioning OR <br>
- * 2. Configure your own PartitionResolver class in partition attributes (For
- * instance when the Key is a primitive type or String) Implement the
+ * 1. The key class can implement the PartitionResolver interface to
+ * enable custom partitioning. OR <br>
+ * 2. Configure your own PartitionResolver class in partition attributes (for
+ * instance when the key is a JDK class like Integer or String). Implement the
  * appropriate equals - For all implementations, you need to be sure to code the
  * class equals method so it properly verifies equality for the
  * PartitionResolver implementation. This might mean verifying that class names
  * are the same or that the returned routing objects are the same etc.. When you
  * initiate the partitioned region on multiple nodes, GemFire uses the equals
  * method to ensure you are using the same PartitionResolver implementation for
- * all of the nodes for the region.
+ * all of the nodes for the region. OR <br>
+ * 3. The callback argument passed to the Region operation methods can implement
+ * PartitionResolver. This implementation restricts you to using methods that accept
+ * a cache callback argument to manage the region entries. For a full list of the methods
+ * that take a callback argument, see the Region Javadocs.
  * </p>
  * <p>
  * GemFire uses the routing object's hashCode to determine where the data is


[06/23] incubator-geode git commit: GEODE-1508: fix IllegalStateException from importNewObject

Posted by kl...@apache.org.
GEODE-1508: fix IllegalStateException from importNewObject

The code in EntryEventImpl that calls importNewObject
is now careful to never call importNewObject with isSerialized false
if isUnretainedNewReferenceOk is false.
The same bug was fixed for importOldObject.
Unit tests have been added for the code in EntryEventImpl
that calls both importNewObject and importOldObject.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/d07c966b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/d07c966b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/d07c966b

Branch: refs/heads/feature/GEODE-835
Commit: d07c966bb6e0a961963433a81d2fa49c913c552d
Parents: be0f7cf
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jun 7 16:18:33 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon Jun 13 16:11:28 2016 -0700

----------------------------------------------------------------------
 .../gemfire/internal/cache/EntryEventImpl.java  |  42 +--
 .../internal/cache/EntryEventImplTest.java      | 327 ++++++++++++++++++-
 2 files changed, 331 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d07c966b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
index c4849be..f559e2a 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/EntryEventImpl.java
@@ -1150,12 +1150,10 @@ public class EntryEventImpl
       if (getCachedSerializedNewValue() != null) {
         importer.importNewBytes(getCachedSerializedNewValue(), true);
         return;
-      } else {
-      if (this.newValueBytes != null && this.newValue instanceof CachedDeserializable) {
+      } else if (this.newValueBytes != null && this.newValue instanceof CachedDeserializable) {
         importer.importNewBytes(this.newValueBytes, true);
         return;
       }
-      }
     }
     @Unretained(ENTRY_EVENT_NEW_VALUE) 
     final Object nv = getRawNewValue();
@@ -1163,22 +1161,16 @@ public class EntryEventImpl
       @Unretained(ENTRY_EVENT_NEW_VALUE)
       final StoredObject so = (StoredObject) nv;
       final boolean isSerialized = so.isSerialized();
-      if (so.hasRefCount()) {
-        if (importer.isUnretainedNewReferenceOk()) {
-          importer.importNewObject(nv, isSerialized);
-        } else {
-          if (!isSerialized || prefersSerialized) {
-            byte[] bytes = so.getValueAsHeapByteArray();
-            importer.importNewBytes(bytes, isSerialized);
-            if (isSerialized) {
-              setCachedSerializedNewValue(bytes);
-            }
-          } else {
-            importer.importNewObject(so.getValueAsDeserializedHeapObject(), true);
-          }
+      if (importer.isUnretainedNewReferenceOk()) {
+        importer.importNewObject(nv, isSerialized);
+      } else if (!isSerialized || prefersSerialized) {
+        byte[] bytes = so.getValueAsHeapByteArray();
+        importer.importNewBytes(bytes, isSerialized);
+        if (isSerialized) {
+          setCachedSerializedNewValue(bytes);
         }
       } else {
-        importer.importNewObject(nv, isSerialized);
+        importer.importNewObject(so.getValueAsDeserializedHeapObject(), true);
       }
     } else if (nv instanceof byte[]) {
       importer.importNewBytes((byte[])nv, false);
@@ -1248,18 +1240,12 @@ public class EntryEventImpl
     if (ov instanceof StoredObject) {
       final StoredObject so = (StoredObject) ov;
       final boolean isSerialized = so.isSerialized();
-      if (so.hasRefCount()) {
-        if (importer.isUnretainedOldReferenceOk()) {
-          importer.importOldObject(ov, isSerialized);
-        } else {
-          if (!isSerialized || prefersSerialized) {
-            importer.importOldBytes(so.getValueAsHeapByteArray(), isSerialized);
-          } else {
-           importer.importOldObject(so.getValueAsDeserializedHeapObject(), true);
-          }
-        }
-      } else {
+      if (importer.isUnretainedOldReferenceOk()) {
         importer.importOldObject(ov, isSerialized);
+      } else if (!isSerialized || prefersSerialized) {
+        importer.importOldBytes(so.getValueAsHeapByteArray(), isSerialized);
+      } else {
+        importer.importOldObject(so.getValueAsDeserializedHeapObject(), true);
       }
     } else if (ov instanceof byte[]) {
       importer.importOldBytes((byte[])ov, false);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d07c966b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
index 800527f..265795f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/EntryEventImplTest.java
@@ -24,33 +24,33 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
 import com.gemstone.gemfire.cache.Operation;
+import com.gemstone.gemfire.internal.cache.EntryEventImpl.NewValueImporter;
+import com.gemstone.gemfire.internal.cache.EntryEventImpl.OldValueImporter;
+import com.gemstone.gemfire.internal.offheap.StoredObject;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class EntryEventImplTest {
 
-  private String expectedRegionName;
   private String key;
-  private String value;
-  private KeyInfo keyInfo;
 
   @Before
   public void setUp() throws Exception {
-    expectedRegionName = "ExpectedFullRegionPathName";
     key = "key1";
-    value = "value1";
-    keyInfo = new KeyInfo(key, value, null);
   }
 
   @Test
   public void verifyToStringOutputHasRegionName() {
     // mock a region object
     LocalRegion region = mock(LocalRegion.class);
+    String expectedRegionName = "ExpectedFullRegionPathName";
+    String value = "value1";
+    KeyInfo keyInfo = new KeyInfo(key, value, null);
     doReturn(expectedRegionName).when(region).getFullPath();
     doReturn(keyInfo).when(region).getKeyInfo(any(), any(), any());
 
-    // create entryevent for the region
-    EntryEventImpl e = createEntryEvent(region);
+    // create entry event for the region
+    EntryEventImpl e = createEntryEvent(region, value);
     
     // The name of the region should be in the toString text
     String toStringValue = e.toString();
@@ -59,15 +59,322 @@ public class EntryEventImplTest {
     // verify that toString called getFullPath method of region object
     verify(region, times(1)).getFullPath();
   }
+  
+  @Test
+  public void verifyExportNewValueWithUnserializedStoredObject() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject newValue = mock(StoredObject.class);
+    byte[] newValueBytes = new byte[]{1,2,3};
+    when(newValue.getValueAsHeapByteArray()).thenReturn(newValueBytes);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValueBytes, false);
+  }
+
+  @Test
+  public void verifyExportNewValueWithByteArray() {
+    LocalRegion region = mock(LocalRegion.class);
+    byte[] newValue = new byte[]{1,2,3};
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValue, false);
+  }
+
+  @Test
+  public void verifyExportNewValueWithStringIgnoresNewValueBytes() {
+    LocalRegion region = mock(LocalRegion.class);
+    String newValue = "newValue";
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    when(nvImporter.prefersNewSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    byte[] newValueBytes = new byte[] {1,2};
+    e.newValueBytes = newValueBytes;
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewObject(newValue, true);
+  }
+  
+  @Test
+  public void verifyExportNewValueWithByteArrayCachedDeserializable() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable newValue = mock(CachedDeserializable.class);
+    byte[] newValueBytes = new byte[] {1,2,3};
+    when(newValue.getValue()).thenReturn(newValueBytes);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValueBytes, true);
+  }
+  
+  @Test
+  public void verifyExportNewValueWithStringCachedDeserializable() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable newValue = mock(CachedDeserializable.class);
+    Object newValueObj = "newValueObj";
+    when(newValue.getValue()).thenReturn(newValueObj);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    byte[] newValueBytes = new byte[] {1,2};
+    e.newValueBytes = newValueBytes;
+    e.setCachedSerializedNewValue(newValueBytes);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewObject(newValueObj, true);
+  }
+
+  @Test
+  public void verifyExportNewValueWithStringCachedDeserializablePrefersNewValueBytes() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable newValue = mock(CachedDeserializable.class);
+    Object newValueObj = "newValueObj";
+    when(newValue.getValue()).thenReturn(newValueObj);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    when(nvImporter.prefersNewSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    byte[] newValueBytes = new byte[] {1,2};
+    e.newValueBytes = newValueBytes;
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportNewValueWithStringCachedDeserializablePrefersCachedSerializedNewValue() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable newValue = mock(CachedDeserializable.class);
+    Object newValueObj = "newValueObj";
+    when(newValue.getValue()).thenReturn(newValueObj);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    when(nvImporter.prefersNewSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    byte[] newValueBytes = new byte[] {1,2};
+    e.setCachedSerializedNewValue(newValueBytes);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportNewValueWithSerializedStoredObjectAndImporterPrefersSerialized() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject newValue = mock(StoredObject.class);
+    when(newValue.isSerialized()).thenReturn(true);
+    byte[] newValueBytes = new byte[]{1,2,3};
+    when(newValue.getValueAsHeapByteArray()).thenReturn(newValueBytes);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    when(nvImporter.prefersNewSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewBytes(newValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportNewValueWithSerializedStoredObject() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject newValue = mock(StoredObject.class);
+    when(newValue.isSerialized()).thenReturn(true);
+    Object newValueDeserialized = "newValueDeserialized";
+    when(newValue.getValueAsDeserializedHeapObject()).thenReturn(newValueDeserialized);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewObject(newValueDeserialized, true);
+  }
+
+  @Test
+  public void verifyExportNewValueWithSerializedStoredObjectAndUnretainedNewReferenceOk() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject newValue = mock(StoredObject.class);
+    when(newValue.isSerialized()).thenReturn(true);
+    Object newValueDeserialized = "newValueDeserialized";
+    when(newValue.getValueAsDeserializedHeapObject()).thenReturn(newValueDeserialized);
+    NewValueImporter nvImporter = mock(NewValueImporter.class);
+    when(nvImporter.isUnretainedNewReferenceOk()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, newValue);
+    
+    e.exportNewValue(nvImporter);
+    
+    verify(nvImporter).importNewObject(newValue, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithUnserializedStoredObject() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject oldValue = mock(StoredObject.class);
+    byte[] oldValueBytes = new byte[]{1,2,3};
+    when(oldValue.getValueAsHeapByteArray()).thenReturn(oldValueBytes);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldBytes(oldValueBytes, false);
+  }
+
+  @Test
+  public void verifyExportOldValueWithByteArray() {
+    LocalRegion region = mock(LocalRegion.class);
+    byte[] oldValue = new byte[]{1,2,3};
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldBytes(oldValue, false);
+  }
+
+  @Test
+  public void verifyExportOldValueWithStringIgnoresOldValueBytes() {
+    LocalRegion region = mock(LocalRegion.class);
+    String oldValue = "oldValue";
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    when(ovImporter.prefersOldSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, null);
+    byte[] oldValueBytes = new byte[]{1,2,3};
+    e.setSerializedOldValue(oldValueBytes);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldObject(oldValue, true);
+  }
+
+  @Test
+  public void verifyExportOldValuePrefersOldValueBytes() {
+    LocalRegion region = mock(LocalRegion.class);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    when(ovImporter.prefersOldSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, null);
+    byte[] oldValueBytes = new byte[]{1,2,3};
+    e.setSerializedOldValue(oldValueBytes);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldBytes(oldValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithCacheDeserializableByteArray() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable oldValue = mock(CachedDeserializable.class);
+    byte[] oldValueBytes = new byte[]{1,2,3};
+    when(oldValue.getValue()).thenReturn(oldValueBytes);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldBytes(oldValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithCacheDeserializableString() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable oldValue = mock(CachedDeserializable.class);
+    Object oldValueObj = "oldValueObj";
+    when(oldValue.getValue()).thenReturn(oldValueObj);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldObject(oldValueObj, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithCacheDeserializableOk() {
+    LocalRegion region = mock(LocalRegion.class);
+    CachedDeserializable oldValue = mock(CachedDeserializable.class);
+    Object oldValueObj = "oldValueObj";
+    when(oldValue.getValue()).thenReturn(oldValueObj);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    when(ovImporter.isCachedDeserializableValueOk()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldObject(oldValue, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithSerializedStoredObjectAndImporterPrefersSerialized() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject oldValue = mock(StoredObject.class);
+    when(oldValue.isSerialized()).thenReturn(true);
+    byte[] oldValueBytes = new byte[]{1,2,3};
+    when(oldValue.getValueAsHeapByteArray()).thenReturn(oldValueBytes);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    when(ovImporter.prefersOldSerialized()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldBytes(oldValueBytes, true);
+  }
+
+  @Test
+  public void verifyExportOldValueWithSerializedStoredObject() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject oldValue = mock(StoredObject.class);
+    when(oldValue.isSerialized()).thenReturn(true);
+    Object oldValueDeserialized = "newValueDeserialized";
+    when(oldValue.getValueAsDeserializedHeapObject()).thenReturn(oldValueDeserialized);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldObject(oldValueDeserialized, true);
+  }
+
+  @Test
+  public void verifyExportOewValueWithSerializedStoredObjectAndUnretainedOldReferenceOk() {
+    LocalRegion region = mock(LocalRegion.class);
+    StoredObject oldValue = mock(StoredObject.class);
+    when(oldValue.isSerialized()).thenReturn(true);
+    Object oldValueDeserialized = "oldValueDeserialized";
+    when(oldValue.getValueAsDeserializedHeapObject()).thenReturn(oldValueDeserialized);
+    OldValueImporter ovImporter = mock(OldValueImporter.class);
+    when(ovImporter.isUnretainedOldReferenceOk()).thenReturn(true);
+    EntryEventImpl e = createEntryEvent(region, null);
+    e.setOldValue(oldValue);
+    
+    e.exportOldValue(ovImporter);
+    
+    verify(ovImporter).importOldObject(oldValue, true);
+  }
 
-  private EntryEventImpl createEntryEvent(LocalRegion l) {
+  private EntryEventImpl createEntryEvent(LocalRegion l, Object newValue) {
     // create a dummy event id
     byte[] memId = { 1,2,3 };
     EventID eventId = new EventID(memId, 11, 12, 13);
 
     // create an event
     EntryEventImpl event = EntryEventImpl.create(l, Operation.CREATE, key,
-        value, null,  false /* origin remote */, null,
+        newValue, null,  false /* origin remote */, null,
         false /* generateCallbacks */,
         eventId);
     // avoid calling invokeCallbacks


[21/23] incubator-geode git commit: GEODE-1543: Change the log level from error to info

Posted by kl...@apache.org.
GEODE-1543: Change the log level from error to info

    * When multiple peers join the cluster conncurrently, only the first one that joins will distribute the index creation and other will try to create the index locally because of the distributed message and then log an error afterwards.
    * This is an expected behaviour and hence should not be logged as error but rather as a info.

    This closes #156


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/612a9d99
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/612a9d99
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/612a9d99

Branch: refs/heads/feature/GEODE-835
Commit: 612a9d99566ac71421e5cd986c6ce6e391dedd30
Parents: f59e8d0
Author: nabarun <nn...@pivotal.io>
Authored: Wed Jun 15 15:35:30 2016 -0700
Committer: nabarun <nn...@pivotal.io>
Committed: Wed Jun 15 15:46:59 2016 -0700

----------------------------------------------------------------------
 .../java/com/gemstone/gemfire/internal/cache/LocalRegion.java   | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/612a9d99/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 8b9664f..e5897cc 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -2452,8 +2452,9 @@ public class LocalRegion extends AbstractRegion
             indexes.add(qs.createIndex(icd.getIndexName(), icd.getIndexType(), icd.getIndexExpression(), fromClause, icd.getIndexImportString(), !isOverflowToDisk));
           }
 
-        } catch (Exception ex) {
-          logger.error("Failed to create index {} on region {} with exception: {}", icd.getIndexName(), this.getFullPath(), ex);
+        }
+        catch (Exception ex) {
+          logger.info("Failed to create index {} on region {} with exception: {}", icd.getIndexName(), this.getFullPath(), ex);
 
           // Check if the region index creation is from cache.xml, in that case throw exception.
           // Other case is when bucket regions are created dynamically, in that case ignore the exception.


[20/23] incubator-geode git commit: GEODE-1542: Removing a bogus static import of javafx class

Posted by kl...@apache.org.
GEODE-1542: Removing a bogus static import of javafx class

This class picked up a bad import of a javafx class. With openjdk this
causes compile errors.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/3de21f56
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/3de21f56
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/3de21f56

Branch: refs/heads/feature/GEODE-835
Commit: 3de21f56a7381cea926be9fe33c8e1a1456c564d
Parents: a7b6b25
Author: Dan Smith <up...@apache.org>
Authored: Wed Jun 15 10:05:24 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Wed Jun 15 10:09:14 2016 -0700

----------------------------------------------------------------------
 .../src/main/java/com/gemstone/gemfire/internal/SocketCreator.java | 2 --
 1 file changed, 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/3de21f56/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
index 739028c..fded3c3 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/SocketCreator.java
@@ -16,8 +16,6 @@
  */
 package com.gemstone.gemfire.internal;
 
-import static javafx.scene.input.KeyCode.L;
-
 import com.gemstone.gemfire.GemFireConfigException;
 import com.gemstone.gemfire.SystemConnectException;
 import com.gemstone.gemfire.SystemFailure;


[17/23] incubator-geode git commit: GEODE-1470: Upgrade log4j to 2.6.1

Posted by kl...@apache.org.
GEODE-1470: Upgrade log4j to 2.6.1

* This closes #154 [klund@apache.org]


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/0f2bb8fa
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/0f2bb8fa
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/0f2bb8fa

Branch: refs/heads/feature/GEODE-835
Commit: 0f2bb8fa713d391b59cb5e3f8e8641194bb915e9
Parents: cdfb940
Author: Kevin J. Duling <kd...@pivotal.io>
Authored: Thu Jun 9 09:56:10 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Jun 14 17:23:15 2016 -0700

----------------------------------------------------------------------
 .../logging/log4j/LogWriterAppender.java        | 12 +++++++-----
 .../sanctionedDataSerializables.txt             | 20 ++++++++++----------
 gradle/dependency-versions.properties           |  2 +-
 3 files changed, 18 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0f2bb8fa/geode-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/LogWriterAppender.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/LogWriterAppender.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/LogWriterAppender.java
index 9c103ee..401ef0c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/LogWriterAppender.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/logging/log4j/LogWriterAppender.java
@@ -22,6 +22,11 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 
+import com.gemstone.gemfire.internal.logging.LogConfig;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.logging.ManagerLogWriter;
+import com.gemstone.gemfire.internal.logging.PureLogWriter;
+
 import org.apache.logging.log4j.Level;
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.LoggerContext;
@@ -29,11 +34,6 @@ import org.apache.logging.log4j.core.appender.AbstractAppender;
 import org.apache.logging.log4j.core.config.LoggerConfig;
 import org.apache.logging.log4j.core.layout.PatternLayout;
 
-import com.gemstone.gemfire.internal.logging.LogConfig;
-import com.gemstone.gemfire.internal.logging.LogService;
-import com.gemstone.gemfire.internal.logging.ManagerLogWriter;
-import com.gemstone.gemfire.internal.logging.PureLogWriter;
-
 /**
  * A Log4j Appender which will copy all output to a LogWriter.
  * 
@@ -123,6 +123,8 @@ public class LogWriterAppender extends AbstractAppender implements PropertyChang
     for (AppenderContext context : this.appenderContexts) {
       context.getLoggerContext().removePropertyChangeListener(this);
       context.getLoggerConfig().removeAppender(appenderName);
+    }
+    for (AppenderContext context : this.appenderContexts) { // do this second as log4j 2.6+ will re-add
       context.getLoggerContext().updateLoggers();
     }
     stop();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0f2bb8fa/geode-core/src/test/resources/com/gemstone/gemfire/codeAnalysis/sanctionedDataSerializables.txt
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/com/gemstone/gemfire/codeAnalysis/sanctionedDataSerializables.txt b/geode-core/src/test/resources/com/gemstone/gemfire/codeAnalysis/sanctionedDataSerializables.txt
index fdad3a8..b64293d 100644
--- a/geode-core/src/test/resources/com/gemstone/gemfire/codeAnalysis/sanctionedDataSerializables.txt
+++ b/geode-core/src/test/resources/com/gemstone/gemfire/codeAnalysis/sanctionedDataSerializables.txt
@@ -959,8 +959,8 @@ fromData,14,2a2bb7000e2a2bb8000fb50006b1
 toData,14,2a2bb700102ab400062bb80011b1
 
 com/gemstone/gemfire/internal/cache/DistributedPutAllOperation$EntryVersionsList,2
-fromData,284,2bb9002301003d1c077e07a0000704a70004033e1c10207e1020a0000704a70004033604b80012b20013b900140200990018b80012122404bd001659031cb8001753b9002503001d9900d32bb80026883605b80012b20013b90014020099001cb80012b20013122704bd001659031505b8002853b900180400bb0029591505b700023a0603360715071505a200902bb90023010036081508aa0000000000007d0000000000000003000000200000002900000037000000562a01b6000757a700572a15042bb8002ab6000757a7004915042bb8002a3a0919061909b6001db9002b0200572a1909b6000757a7002a15042bb8002a3a092bb8002688360a19091906150ab9002c0200c0002db600222a1909b6000757840701a7ff6fb1
-toData,299,033d033e2ab600089e003d1c07803d043e2ab6000b3a041904b9000c01009900271904b9000d0100c0000a3a051905c600131905c1001199000e1c1020803da70006a7ffd5b80012b20013b90014020099001fb80012b20013121505bd001659032a5359041cb8001753b9001804002b1cb9001902001d9900b32ab60008852bb8001abb001b592ab60008b7001c3a040336052ab6000b3a061906b9000c010099008a1906b9000d0100c0000a3a071907c7000d2b03b900190200a7006c1907b6001d3a081908c700132b04b90019020019072bb8001ea7005019041908b6001f360915099a00242b05b90019020084050115053609190419081509b600205719072bb8001ea700212b06b90019020019072b03b6002119071908b6002215090464852bb8001aa7ff72b1
+fromData,268,2bb9002201003d1c077e07a0000704a70004033e1c10207e1020a0000704a70004033604b80012b20013b900140200990011b8001212231cb80016b9002403001d9900ca2bb80025883605b80012b20013b900140200990015b80012b2001312261505b80027b900280400bb0029591505b700023a0603360715071505a2008e2bb90022010036081508aa000000007b00000000000000030000001e0000002700000035000000542a01b6000757a700572a15042bb8002ab6000757a7004915042bb8002a3a0919061909b6001cb9002b0200572a1909b6000757a7002a15042bb8002a3a092bb8002588360a19091906150ab9002c0200c0002db600212a1909b6000757840701a7ff71b1
+toData,289,033d033e2ab600089e003d1c07803d043e2ab6000b3a041904b9000c01009900271904b9000d0100c0000a3a051905c600131905c1001199000e1c1020803da70006a7ffd5b80012b20013b900140200990015b80012b2001312152a1cb80016b9001705002b1cb9001802001d9900b32ab60008852bb80019bb001a592ab60008b7001b3a040336052ab6000b3a061906b9000c010099008a1906b9000d0100c0000a3a071907c7000d2b03b900180200a7006c1907b6001c3a081908c700132b04b90018020019072bb8001da7005019041908b6001e360915099a00242b05b90018020084050115053609190419081509b6001f5719072bb8001da700212b06b90018020019072b03b6002019071908b6002115090464852bb80019a7ff72b1
 
 com/gemstone/gemfire/internal/cache/DistributedPutAllOperation$PutAllEntryData,1
 toData,229,2ab4000a4d2ab4000c4e2c2bb8003d2dc1003e9a00072dc700182b03b9003f02002dc0003ec0003e2bb80040a700312dc1004199001e2dc000413a042b04b9003f02001904b9004201002bb80040a7000f2b04b9003f02002d2bb800432b2ab40012b40044b9003f02002ab4000636042ab40026c6000a150407809136042ab40017c6001d15041008809136042ab40017c1004599000b150410208091360415041080809136042b1504b9003f02002ab40026c6000b2ab400262bb8003d2ab40017c6000b2ab400172bb800462ab6002899000b2ab400142bb800462ab400082bb80047b1
@@ -1048,8 +1048,8 @@ fromData,46,2a2bb7000a2a2bb9000b0100b500042bb9000b01009900182a2bb9000b0100b50007
 toData,66,2a2bb700032b2ab40004b9000502002ab40006c6000704a70004033d2b1cb9000502001c99001d2b2ab40007b9000502002ab4000601b600082ab400062bb80009b1
 
 com/gemstone/gemfire/internal/cache/FindVersionTagOperation$FindVersionTagMessage,2
-fromData,55,2a2bb700242a2bb900250100b500032a2bb900260100b500042abb002759b70028b500052ab400052bb800292a2bb9002a0100b50006b1
-toData,44,2a2bb7001f2b2ab40003b9002002002b2ab40004b9002102002ab400052bb800222b2ab40006b900230200b1
+fromData,55,2a2bb700232a2bb900240100b500032a2bb900250100b500042abb002659b70027b500052ab400052bb800282a2bb900290100b50006b1
+toData,44,2a2bb7001e2b2ab40003b9001f02002b2ab40004b9002002002ab400052bb800212b2ab40006b900220200b1
 
 com/gemstone/gemfire/internal/cache/FindVersionTagOperation$VersionTagReply,2
 fromData,17,2a2bb7000c2a2bb8000dc0000eb50002b1
@@ -1088,8 +1088,8 @@ fromData,224,2a2bb7001d2bb8001e4d014e2cc600102cb6001f9e00092c03b600204e2dc100219
 toData,234,2a2bb700302ab40010c1002199001dbb00315904b700324d2c2ab40010b60033572c2bb80034a7000e2ab40010c000312bb800342b2ab40011b9003502002b2ab40012b9003502002b2ab40013b9003502002b2ab40014b9003602002b2ab40015b9003502002b2ab40003b9003602002b2ab40016b9003602002ab4001699000b2ab400022bb800372b2ab40001c7000702a7000c2ab40001b900380100b9003902002ab40001c600422ab40001b9003a0100b9003b01004d2cb9003c010099002a2cb9003d0100c0003e4e2db9003f01002bb800402db900410100c00042b600432bb80044a7ffd3b1
 
 com/gemstone/gemfire/internal/cache/InitialImageOperation$InitialImageVersionedEntryList,2
-fromData,426,b80022b20023b9002402003d2bb9003701003e1d057e05a0000704a700040336041d077e07a0000704a700040336052a1d10087e1008a0000704a7000403b500021d10207e1020a0000704a700040336061c99001bb80022b20023123804bd002659031db8002753b90028040015049900432bb800398836071c99001cb80022b20023123a04bd002659031507b8003253b90028040003360815081507a200152a2bb8003bc00014b7001257840801a7ffea15059900ea2bb800398836071c99001cb80022b20023123c04bd002659031507b8003253b9002804002abb0003591507b70005b50004bb0003591507b700053a0803360915091507a200a12bb900370100360a150aaa0000008e00000000000000030000001d0000002b0000003e000000622ab4000401b90011020057a700662ab4000415062bb8003db90011020057a7005315062bb8003d3a0b1908190bb6002eb900110200572ab40004190bb90011020057a7002f15062bb8003d3a0b2bb8003988360c190b1908150cb900160200c0003eb600352ab40004190bb90011020057840901a7ff5ea7000e2abb000359b70001b50004b1
-toData,406,033d033e0336042ab700209a00091c05803d043e2ab40004b9000d01009e00431c07803d0436042ab40004b9001a01003a051905b9001b01009900271905b9001c0100c000173a061906c600131906c1002199000e1c1020803da70006a7ffd52ab400029900081c1008803db80022b20023b90024020099001fb80022b20023122505bd002659032a5359041cb8002753b9002804002b1cb9002902001d9900282ab7000e852bb8002a03360515052ab7000ea200132a1505b700132bb8002b840501a7ffea15049900cd2ab40004b9000d0100852bb8002abb002c592ab40004b9000d0100b7002d3a050336062ab40004b9001a01003a071907b9001b01009900951907b9001c0100c000173a081908c7000d2b03b900290200a700771908b6002e3a091909c700132b04b90029020019082bb8002fa7005b19051909b900300200c000313a0a190ac700292b05b9002902001506840601b800323a0a19051909190ab9003303005719082bb8002fa700222b06b90029020019082b03b6003419081909b60035190ab60036852bb8002aa7ff67b1
+fromData,406,b80022b20023b9002402003d2bb9003601003e1d057e05a0000704a700040336041d077e07a0000704a700040336052a1d10087e1008a0000704a7000403b500021d10207e1020a0000704a700040336061c990014b80022b2002312371db80026b900380400150499003c2bb800398836071c990015b80022b20023123a1507b80031b90038040003360815081507a200152a2bb8003bc00014b7001257840801a7ffea15059900e42bb800398836071c990015b80022b20023123c1507b80031b9003804002abb0003591507b70005b50004bb0003591507b700053a0803360915091507a200a22bb900360100360a150aaa000000008f00000000000000030000001e0000002c0000003f000000632ab4000401b90011020057a700662ab4000415062bb8003db90011020057a7005315062bb8003d3a0b1908190bb6002db900110200572ab40004190bb90011020057a7002f15062bb8003d3a0b2bb8003988360c190b1908150cb900160200c0003eb600342ab40004190bb90011020057840901a7ff5da7000e2abb000359b70001b50004b1
+toData,396,033d033e0336042ab700209a00091c05803d043e2ab40004b9000d01009e00431c07803d0436042ab40004b9001a01003a051905b9001b01009900271905b9001c0100c000173a061906c600131906c1002199000e1c1020803da70006a7ffd52ab400029900081c1008803db80022b20023b900240200990015b80022b2002312252a1cb80026b9002705002b1cb9002802001d9900282ab7000e852bb8002903360515052ab7000ea200132a1505b700132bb8002a840501a7ffea15049900cd2ab40004b9000d0100852bb80029bb002b592ab40004b9000d0100b7002c3a050336062ab40004b9001a01003a071907b9001b01009900951907b9001c0100c000173a081908c7000d2b03b900280200a700771908b6002d3a091909c700132b04b90028020019082bb8002ea7005b19051909b9002f0200c000303a0a190ac700292b05b9002802001506840601b800313a0a19051909190ab9003203005719082bb8002ea700222b06b90028020019082b03b6003319081909b60034190ab60035852bb80029a7ff67b1
 
 com/gemstone/gemfire/internal/cache/InitialImageOperation$RVVReplyMessage,2
 fromData,33,2a2bb700162bb9001701003d1c9900132bb9001701003e2a1d2bb80018b50004b1
@@ -1941,10 +1941,10 @@ fromData,145,2bb9001401003d1c99000e2abb001559b70016b5000a2a1cb500032bb9001701003
 toData,209,2b2ab40003b9000402002ab40005c600bb2ab40006b9000701003d2b1cb900080200033e1d1ca200a02ab400061db9000902003a042ab400051d3336052ab400039900112ab4000a1db9000902002bb8000b150506a0000d2b06b9000d0200a70029150505a0000d2b05b9000d0200a7001915059a000d2b03b9000d0200a7000a2b04b9000d0200150505a000181904b8000e2bb8000f1904b600102bb80011a700201904c100129900121904c00012c000122bb8000fa7000919042bb80013840301a7ff61a7000a2b03b900080200b1
 
 com/gemstone/gemfire/internal/cache/tier/sockets/VersionedObjectList,4
-fromData,570,b20002b20003b9000402003d2bb9005e01003e2a1d047e04a0000704a7000403b500291d057e05a0000704a700040336041d077e07a0000704a700040336052a1d10087e1008a0000704a7000403b5000f2a1d10107e1010a0000704a7000403b5001e1d10207e1020a0000704a700040336061c99001bb20002b20003125f04bd000659031db8004d53b9000704002ab400299900522bb800608836072abb001b591507b70021b5000d1c99001cb20002b20003126104bd000659031507b8004e53b90007040003360815081507a200172ab4000d2bb80062b9000e020057840801a7ffe815049900562bb800608836071c99001cb20002b20003126304bd000659031507b8004e53b9000704002abb001b591507b70021b500082a1507bc08b5003003360815081507a200102a15082bb70064840801a7ffefa7000e2abb001b59b7001cb5000815059900e42bb800608836071c99001cb20002b20003126504bd000659031507b8004e53b9000704002abb001b591507b70021b50010bb001b591507b700213a0803360915091507a2009b2bb9005e0100360a150aaa00000000008800000000000000030000001f0000002b0000003c0000005e2ab4001001b6001157a700602ab4001015062bb80066b6001157a7004f15062bb800663a0b1908190bb60057b9000e02
 00572ab40010190bb6001157a7002d15062bb800663a0b2bb8006088360c190b1908150cb900510200c00067b6005c2ab40010190bb6001157840901a7ff64a7000e2abb001b59b7001cb50010b1
+fromData,542,b20002b20003b9000402003d2bb9005e01003e2a1d047e04a0000704a7000403b500291d057e05a0000704a700040336041d077e07a0000704a700040336052a1d10087e1008a0000704a7000403b5000e2a1d10107e1010a0000704a7000403b5001e1d10207e1020a0000704a700040336061c990014b20002b20003125f1db8004db9006004002ab4002999004b2bb800618836072abb001b591507b70021b5000c1c990015b20002b2000312621507b8004eb90060040003360815081507a200172ab4000c2bb80063b9000d020057840801a7ffe8150499004f2bb800618836071c990015b20002b2000312641507b8004eb9006004002abb001b591507b70021b500072a1507bc08b5003003360815081507a200102a15082bb70065840801a7ffefa7000e2abb001b59b7001cb5000715059900dd2bb800618836071c990015b20002b2000312661507b8004eb9006004002abb001b591507b70021b5000fbb001b591507b700213a0803360915091507a2009b2bb9005e0100360a150aaa00000000008800000000000000030000001f0000002b0000003c0000005e2ab4000f01b6001057a700602ab4000f15062bb80067b6001057a7004f15062bb800673a0b1908190bb60057b9000d0200572ab4000f190bb6001057a7002d15062bb800673a0b2bb8006188
 360c190b1908150cb900510200c00068b6005c2ab4000f190bb6001057840901a7ff64a7000e2abb001b59b7001cb5000fb1
 fromDataPre_GFE_8_0_0_0,6,2a2bb60045b1
 toDataPre_GFE_8_0_0_0,10,2ab700012a2bb60044b1
-toData,639,03360603360703360815049900102ab4002999000915060480360615059900182ab40008b9004a01009a000c1506058036060436072ab40010b600159e00451506078036060436082ab40010b600223a091909b9002301009900291909b900240100c000253a0a190ac60015190ac1004b99001015061020803606a70006a7ffd32ab4000f99000a150610088036062ab4001e99000a15061010803606b20002b20003b90004020099002eb20002b20003124c07bd000659032a5359041506b8004d5359051cb8004e5359061db8004e53b9000704002b1506b9004f0200150499005a2ab400299900531d360915091c602ab4000db900090100a40014032ab4000db9000901001c64b8003136091509852bb800501c360a03360b150b1509a2001b2ab4000d150ab9005102002bb80052840b01840a01a7ffe41505990061150799005c1d360915091c602ab40008b900090100a40014032ab40008b9000901001c64b8003136091509852bb8005003360a1c360b03360c150c1509a200212a2ab40008150bb900510200150a840a012bb70053840c01840b01a7ffde15089900df1d360915091c602ab40010b60015a40012032ab40010b600151c64b8003136091509852bb80050bb0054591509b700553a0a03360b1c360c03360d150d1509a2009d2ab40010150cb60056
 c000253a0e190ec7000d2b03b9004f0200a70077190eb600573a0f190fc700132b04b9004f0200190e2bb80058a7005b190a190fb900590200c0005a3a101910c700292b05b9004f0200150b840b01b8004e3a10190a190f1910b9003c030057190e2bb80058a700222b06b9004f0200190e2b03b6005b190e190fb6005c1910b6005d852bb80050840d01840c01a7ff62b1
+toData,623,03360603360703360815049900102ab4002999000915060480360615059900182ab40007b9004a01009a000c1506058036060436072ab4000fb600159e00451506078036060436082ab4000fb600223a091909b9002301009900291909b900240100c000253a0a190ac60015190ac1004b99001015061020803606a70006a7ffd32ab4000e99000a150610088036062ab4001e99000a15061010803606b20002b20003b90004020099001eb20002b20003124c2a1506b8004d1cb8004e1db8004eb9001307002b1506b9004f0200150499005a2ab400299900531d360915091c602ab4000cb900080100a40014032ab4000cb9000801001c64b8003136091509852bb800501c360a03360b150b1509a2001b2ab4000c150ab9005102002bb80052840b01840a01a7ffe41505990061150799005c1d360915091c602ab40007b900080100a40014032ab40007b9000801001c64b8003136091509852bb8005003360a1c360b03360c150c1509a200212a2ab40007150bb900510200150a840a012bb70053840c01840b01a7ffde15089900df1d360915091c602ab4000fb60015a40012032ab4000fb600151c64b8003136091509852bb80050bb0054591509b700553a0a03360b1c360c03360d150d1509a2009d2ab4000f150cb60056c000253a0e190ec7000d2b03b9004f02
 00a70077190eb600573a0f190fc700132b04b9004f0200190e2bb80058a7005b190a190fb900590200c0005a3a101910c700292b05b9004f0200150b840b01b8004e3a10190a190f1910b9003c030057190e2bb80058a700222b06b9004f0200190e2b03b6005b190e190fb6005c1910b6005d852bb80050840d01840c01a7ff62b1
 
 com/gemstone/gemfire/internal/cache/tier/sockets/VersionedObjectList$Chunker,3
 fromData,10,bb000959120ab7000bbf
@@ -1976,8 +1976,8 @@ fromData,212,2a2a2bb600bdb500132bb900be01003d2a1c047e04a0000704a7000403b500972ab
 toData,239,2ab4001499000dbb00b05912b8b700b2bf2a2ab400132bb600b9033d2ab400979900071c04803d2b1cb900ba02002b2ab4000bb60035b900bb03002b2ab4000cb60035b900bb03002b2ab40025b60033b900ba02002ab40025b60099b9002b01004e2db9002c010099002b2db9002d0100c0002e3a042a1904b9002f0100c0006e2bb600b91904b9003001002bb800bca7ffd22b2ab40026b60033b900ba02002ab40026b60099b9002b01004e2db9002c01009900332db9002d0100c0002e3a042a1904b9002f0100c0006e2bb600b92b1904b900300100c0003eb6003fb900bb0300a7ffca2ab4001f2bb800bcb1
 
 com/gemstone/gemfire/internal/cache/versions/VersionTag,2
-fromData,197,2bb9002201003db20014b20015b900160200990022b20014b20015122305bd001859032ab600195359041cb8001a53b9001b0400b200242a2bb900220100b600252a2bb900260100b500101c077e9900132a2bb900270100121e7eb50006a7000f2a2bb900280100027eb500061c10107e99000d2a2bb900270100b5000a2a2bb900280100b5000d2a2bb80029b500071c047e99000c2a2a2bb6002ab5000e1c057e99001e1c10087e99000e2a2ab4000eb5000fa7000c2a2a2bb6002ab5000f2ab6002bb1
-toData,269,033e0336042ab400061213a2000a0436041d07803e2ab4000a9900081d1010803e2ab4000ec6000b1c9900071d04803e2ab4000fc6001b1d05803e2ab4000f2ab4000ea6000c1c9900081d1008803eb20014b20015b900160200990022b20014b20015121705bd001859032ab600195359041db8001a53b9001b04002b1db9001c02002b2ab40002b9001c02002b2ab40010b9001d020015049900132b2ab40006121e7eb9001c0200a7000d2b2ab40006b9001f02002ab4000a99000d2b2ab4000ab9001c02002b2ab4000db9001f02002ab400072bb800202ab4000ec600101c99000c2a2ab4000e2bb600212ab4000fc6001b2ab4000f2ab4000ea600071c9a000c2a2ab4000f2bb60021b1
+fromData,187,2bb9002101003db20014b20015b900160200990018b20014b2001512222ab600181cb80019b9001a0500b200232a2bb900210100b600242a2bb900250100b500101c077e9900132a2bb900260100121d7eb50006a7000f2a2bb900270100027eb500061c10107e99000d2a2bb900260100b5000a2a2bb900270100b5000d2a2bb80028b500071c047e99000c2a2a2bb60029b5000e1c057e99001e1c10087e99000e2a2ab4000eb5000fa7000c2a2a2bb60029b5000f2ab6002ab1
+toData,259,033e0336042ab400061213a2000a0436041d07803e2ab4000a9900081d1010803e2ab4000ec6000b1c9900071d04803e2ab4000fc6001b1d05803e2ab4000f2ab4000ea6000c1c9900081d1008803eb20014b20015b900160200990018b20014b2001512172ab600181db80019b9001a05002b1db9001b02002b2ab40002b9001b02002b2ab40010b9001c020015049900132b2ab40006121d7eb9001b0200a7000d2b2ab40006b9001e02002ab4000a99000d2b2ab4000ab9001b02002b2ab4000db9001e02002ab400072bb8001f2ab4000ec600101c99000c2a2ab4000e2bb600202ab4000fc6001b2ab4000f2ab4000ea600071c9a000c2a2ab4000f2bb60020b1
 
 com/gemstone/gemfire/internal/cache/wan/GatewaySenderAdvisor$GatewaySenderProfile,4
 fromData,282,2a2bb700082a2bb80009b5000a2a2bb9000b0100b5000c2a2bb9000d0100b5000e2a2bb9000f0100b500102a2bb9000f0100b500112a2bb9000f0100b500122a2bb9000f0100b500132a2bb9000f0100b500142a2bb9000d0100b500152a2bb9000f0100b500162a2bb80017b500042a2bb80017b500052a2bb80017b500062a2bb9000f0100b500182a2bb9000d0100b500192bb8001ab2001bb6001c9c00552bb8001dc0001e4d2cc600412cb6001fb20020b60021b6002299000d2ab20020b50023a7002c2cb6001fb20024b60021b6002299000d2ab20024b50023a700122ab20025b50023a700082a01b50023a7000e2a2bb8001dc00026b500232bb800273d1c9900162abb002859b70029b5002a2ab4002a2bb8002bb1

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0f2bb8fa/gradle/dependency-versions.properties
----------------------------------------------------------------------
diff --git a/gradle/dependency-versions.properties b/gradle/dependency-versions.properties
index b6687e5..d324cd1 100644
--- a/gradle/dependency-versions.properties
+++ b/gradle/dependency-versions.properties
@@ -72,7 +72,7 @@ json4s.version = 3.2.4
 jsr305.version = 3.0.1
 junit.version = 4.12
 JUnitParams.version = 1.0.5
-log4j.version = 2.5
+log4j.version = 2.6.1
 lucene.version = 6.0.0
 mockito-core.version = 1.10.19
 mockrunner.version = 1.0.8


[07/23] incubator-geode git commit: GEODE-1517: fix TXStateProxyImpl continue working after TXManagerImpl is closed.

Posted by kl...@apache.org.
GEODE-1517: fix TXStateProxyImpl continue working after TXManagerImpl is closed.

Holding the ReentrantLock during TXManagerImpl.close() when closing TXStateProxyImpl. Provent any TXStateProxyImpl to work further. Add a test case where it fails without the above fix and passes after the fix.

Also avoid going through synchronized failover map to check if a TXStateProxyImpl is finished, instead, use its isInProgress() call.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/6f70cd70
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/6f70cd70
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/6f70cd70

Branch: refs/heads/feature/GEODE-835
Commit: 6f70cd703139417388fbd9845dd8aefb3b3f7c30
Parents: d07c966
Author: eshu <es...@pivotal.io>
Authored: Mon Jun 13 16:44:55 2016 -0700
Committer: eshu <es...@pivotal.io>
Committed: Mon Jun 13 16:44:55 2016 -0700

----------------------------------------------------------------------
 .../internal/cache/RemoteOperationMessage.java  | 10 ++-
 .../gemfire/internal/cache/TXManagerImpl.java   | 32 ++++-----
 .../cache/partitioned/PartitionMessage.java     | 10 ++-
 .../cache/RemoteOperationMessageTest.java       | 31 +++++++--
 .../internal/cache/TXManagerImplTest.java       | 73 +++++++++++++++-----
 .../cache/partitioned/PartitionMessageTest.java | 27 ++++++--
 6 files changed, 120 insertions(+), 63 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessage.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessage.java
index 19e1dea..db5bcca 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessage.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessage.java
@@ -241,8 +241,10 @@ public abstract class RemoteOperationMessage extends DistributionMessage impleme
         sendReply = operateOnRegion(dm, r, startTime);        
       } else {
         try {
-          TXId txid = new TXId(getMemberToMasqueradeAs(), getTXUniqId());
-          if (!hasTxAlreadyFinished(tx, txMgr, txid)) {
+          if (txMgr.isClosed()) {
+            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
+            sendReply = false;
+          } else if (tx.isInProgress()) {
             sendReply = operateOnRegion(dm, r, startTime);       
           }  
         } finally {
@@ -317,10 +319,6 @@ public abstract class RemoteOperationMessage extends DistributionMessage impleme
     }
   }
 
-  boolean hasTxAlreadyFinished(TXStateProxy tx, TXManagerImpl txMgr, TXId txid) {
-    return txMgr.hasTxAlreadyFinished(tx, txid);
-  }
-
   TXManagerImpl getTXManager(GemFireCacheImpl cache) {
     return cache.getTxManager();
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TXManagerImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TXManagerImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TXManagerImpl.java
index 2608878..1ea7f71 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TXManagerImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/TXManagerImpl.java
@@ -90,7 +90,7 @@ public class TXManagerImpl implements CacheTransactionManager,
   
   private final ArrayList<TransactionListener> txListeners = new ArrayList<TransactionListener>(8);
   public TransactionWriter writer = null;
-  private boolean closed = false;
+  private volatile boolean closed = false;
 
   private final Map<TXId, TXStateProxy> hostedTXStates;
 
@@ -577,7 +577,12 @@ public class TXManagerImpl implements CacheTransactionManager,
     }
     this.closed = true;
     for (TXStateProxy proxy: this.hostedTXStates.values()) {
-      proxy.close();
+      proxy.getLock().lock();
+      try {
+        proxy.close();
+      } finally {
+        proxy.getLock().unlock();
+      }
     }
     for (TXStateProxy proxy: this.localTxMap.values()) {
       proxy.close();
@@ -646,7 +651,7 @@ public class TXManagerImpl implements CacheTransactionManager,
     }
   }
 
-  private final boolean isClosed() {
+  public final boolean isClosed() {
     return this.closed;
   }
   private final void checkClosed() {
@@ -752,10 +757,13 @@ public class TXManagerImpl implements CacheTransactionManager,
         // Inflight op could be received later than TXFailover operation.
         if (curVal == null) {
           if (!isHostedTxRecentlyCompleted(key)) {
-            this.hostedTXStates.put(key, val);
             // Failover op removed the val
             // It is possible that the same operation can be executed
             // twice by two threads, but data is consistent.
+            this.hostedTXStates.put(key, val);
+          } else {
+            //Another thread should complete the transaction
+            logger.info("{} has already finished." , val.getTxId());
           }
         } else {
           if (val != curVal) {
@@ -770,22 +778,6 @@ public class TXManagerImpl implements CacheTransactionManager,
     return true;
   }
   
-  public boolean hasTxAlreadyFinished(TXStateProxy tx, TXId txid) {
-    if (tx == null) {
-      return false;
-    }
-    if (isHostedTxRecentlyCompleted(txid)) {
-      //Should only happen when handling a later arrival of transactional op from proxy,
-      //while the transaction has failed over and already committed or rolled back.
-      //Just send back reply as a success op.
-      //The client connection should be lost from proxy, or
-      //the proxy is closed for failover to occur.
-      logger.info("TxId {} has already finished." , txid);
-      return true;
-    }
-    return false;
-  }
-  
   /**
    * Associate the remote txState with the thread processing this message. Also,
    * we acquire a lock on the txState, on which this thread operates.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessage.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessage.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessage.java
index 1b83ee3..14fce08 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessage.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessage.java
@@ -278,10 +278,6 @@ public abstract class PartitionMessage extends DistributionMessage implements
     return (ds == null || ds.isDisconnecting());
   }
   
-  boolean hasTxAlreadyFinished(TXStateProxy tx, TXManagerImpl txMgr, TXId txid) {
-    return txMgr.hasTxAlreadyFinished(tx, txid);
-  }
-  
   PartitionedRegion getPartitionedRegion() throws PRLocallyDestroyedException {
     return PartitionedRegion.getPRFromId(this.regionId);
   }
@@ -343,8 +339,10 @@ public abstract class PartitionMessage extends DistributionMessage implements
         sendReply = operateOnPartitionedRegion(dm, pr, startTime);        
       } else {
         try {
-          TXId txid = new TXId(getMemberToMasqueradeAs(), getTXUniqId());
-          if (!hasTxAlreadyFinished(tx, txMgr, txid)) {
+          if (txMgr.isClosed()) {
+            // NO DISTRIBUTED MESSAGING CAN BE DONE HERE!
+            sendReply = false;
+          } else if (tx.isInProgress()) {
             sendReply = operateOnPartitionedRegion(dm, pr, startTime);        
           }  
         } finally {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessageTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessageTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessageTest.java
index ecfc2b0..18ce2a9 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessageTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/RemoteOperationMessageTest.java
@@ -25,7 +25,6 @@ import org.mockito.internal.stubbing.answers.CallsRealMethods;
 
 import com.gemstone.gemfire.distributed.internal.DistributionManager;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.TXId;
 import com.gemstone.gemfire.internal.cache.TXManagerImpl;
 import com.gemstone.gemfire.internal.cache.TXStateProxy;
 import com.gemstone.gemfire.internal.cache.TXStateProxyImpl;
@@ -40,7 +39,6 @@ public class RemoteOperationMessageTest {
   private DistributionManager dm;
   private LocalRegion r;
   private TXManagerImpl txMgr;
-  private TXId txid;
   private long startTime = 0;
   TXStateProxy tx;
   
@@ -51,7 +49,6 @@ public class RemoteOperationMessageTest {
     msg = mock(RemoteOperationMessage.class);
     r = mock(LocalRegion.class);
     txMgr = mock(TXManagerImpl.class);
-    txid = new TXId(null, 0);
     tx = mock(TXStateProxyImpl.class);
     
     when(msg.checkCacheClosing(dm)).thenReturn(false);
@@ -59,9 +56,8 @@ public class RemoteOperationMessageTest {
     when(msg.getCache(dm)).thenReturn(cache);
     when(msg.getRegionByPath(cache)).thenReturn(r);
     when(msg.getTXManager(cache)).thenReturn(txMgr);
-    when(txMgr.hasTxAlreadyFinished(tx, txid)).thenCallRealMethod();
 
-    doAnswer(new CallsRealMethods()).when(msg).process(dm);    
+    doAnswer(new CallsRealMethods()).when(msg).process(dm);
   }
   
   @Test
@@ -75,7 +71,7 @@ public class RemoteOperationMessageTest {
   @Test
   public void messageForNotFinishedTXPerformsOnRegion() throws InterruptedException, RemoteOperationException {
     when(txMgr.masqueradeAs(msg)).thenReturn(tx);
-    when(msg.hasTxAlreadyFinished(tx, txMgr, txid)).thenCallRealMethod(); 
+    when(tx.isInProgress()).thenReturn(true);
     msg.process(dm);
 
     verify(msg, times(1)).operateOnRegion(dm, r, startTime);
@@ -84,10 +80,31 @@ public class RemoteOperationMessageTest {
   @Test
   public void messageForFinishedTXDoesNotPerformOnRegion() throws InterruptedException, RemoteOperationException {
     when(txMgr.masqueradeAs(msg)).thenReturn(tx);
-    when(msg.hasTxAlreadyFinished(tx, txMgr, txid)).thenReturn(true); 
+    when(tx.isInProgress()).thenReturn(false); 
     msg.process(dm);
 
     verify(msg, times(0)).operateOnRegion(dm, r, startTime);
   }
 
+  @Test
+  public void noNewTxProcessingAfterTXManagerImplClosed() throws RemoteOperationException {
+    txMgr = new TXManagerImpl(null, cache);
+    
+    when(msg.checkCacheClosing(dm)).thenReturn(false);
+    when(msg.checkDSClosing(dm)).thenReturn(false);
+    when(msg.getCache(dm)).thenReturn(cache);
+    when(msg.getRegionByPath(cache)).thenReturn(r);
+    when(msg.getTXManager(cache)).thenReturn(txMgr);
+
+    when(msg.canParticipateInTransaction()).thenReturn(true);
+    when(msg.canStartRemoteTransaction()).thenReturn(true);
+    
+    msg.process(dm);
+    
+    txMgr.close();
+    
+    msg.process(dm);
+
+    verify(msg, times(1)).operateOnRegion(dm, r, startTime);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/TXManagerImplTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/TXManagerImplTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/TXManagerImplTest.java
index ce24947..ae4f378 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/TXManagerImplTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/TXManagerImplTest.java
@@ -49,6 +49,7 @@ public class TXManagerImplTest {
   TXStateProxy tx1, tx2;
   DistributionManager dm;
   TXRemoteRollbackMessage rollbackMsg;
+  TXRemoteCommitMessage commitMsg;
 
   @Before
   public void setUp() {
@@ -63,9 +64,11 @@ public class TXManagerImplTest {
     notCompletedTxid = new TXId(member, 2);
     latch = new CountDownLatch(1);
     rollbackMsg = new TXRemoteRollbackMessage();
+    commitMsg = new TXRemoteCommitMessage();
     
     when(this.msg.canStartRemoteTransaction()).thenReturn(true);
     when(this.msg.canParticipateInTransaction()).thenReturn(true);
+
   }
 
   @Test
@@ -142,9 +145,9 @@ public class TXManagerImplTest {
     assertFalse(txMgr.getLock(tx, txid));
     
   }
-  
+
   @Test
-  public void getLockAfterTXStateCommitted() throws InterruptedException{  
+  public void getLockAfterTXStateCommitted() throws InterruptedException{
     TXStateProxy oldtx = txMgr.getOrSetHostedTXState(txid, msg);
     
     assertEquals(oldtx, txMgr.getHostedTXState(txid));  
@@ -157,6 +160,20 @@ public class TXManagerImplTest {
     
     Thread t1 = new Thread(new Runnable() {
       public void run() {
+        when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class));
+        TXStateProxy tx;
+        try {
+          tx = txMgr.masqueradeAs(commitMsg);
+        } catch (InterruptedException e) {
+          e.printStackTrace();
+          throw new RuntimeException(e);
+        }
+        tx.setCommitOnBehalfOfRemoteStub(true);
+        try {
+          tx.commit();
+        } finally {
+          txMgr.unmasquerade(tx);
+        }
         txMgr.removeHostedTXState(txid);
         txMgr.saveTXCommitMessageForClientFailover(txid, txCommitMsg);
       }
@@ -168,11 +185,12 @@ public class TXManagerImplTest {
     TXStateProxy curTx = txMgr.getHostedTXState(txid);
     assertNull(curTx);
     
+    assertFalse(tx.isInProgress());
     //after TXStateProxy committed, getLock will get the lock for the oldtx
     //but caller should not perform ops on this TXStateProxy
     assertTrue(txMgr.getLock(tx, txid));    
   } 
-  
+
   @Test
   public void masqueradeAsCanGetLock() throws InterruptedException{  
     TXStateProxy tx;
@@ -222,21 +240,43 @@ public class TXManagerImplTest {
   }
   
   @Test
-  public void hasTxAlreadyFinishedDetectsNoTx() {   
-    assertFalse(txMgr.hasTxAlreadyFinished(null, txid));
+  public void testTxStateWithNotFinishedTx() {
+    TXStateProxy tx = txMgr.getOrSetHostedTXState(notCompletedTxid, msg);
+    assertTrue(tx.isInProgress());
   }
-  
+
   @Test
-  public void hasTxAlreadyFinishedDetectsTxNotFinished() {
-    TXStateProxy tx = txMgr.getOrSetHostedTXState(notCompletedTxid, msg);
-    assertFalse(txMgr.hasTxAlreadyFinished(tx, notCompletedTxid));
+  public void testTxStateWithCommittedTx() throws InterruptedException {
+    when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class));
+    setupTx(); 
+    
+    TXStateProxy tx = txMgr.masqueradeAs(commitMsg);
+    try {
+      tx.commit();
+    } finally {
+      txMgr.unmasquerade(tx);
+    }
+    assertFalse(tx.isInProgress());
   }
   
   @Test
-  public void hasTxAlreadyFinishedDetectsTxFinished() throws InterruptedException {
-    TXStateProxy tx = txMgr.getOrSetHostedTXState(completedTxid, msg);    
-    txMgr.saveTXCommitMessageForClientFailover(completedTxid, txCommitMsg); 
-    assertTrue(txMgr.hasTxAlreadyFinished(tx, completedTxid));
+  public void testTxStateWithRolledBackTx() throws InterruptedException {
+    when(msg.getTXOriginatorClient()).thenReturn(mock(InternalDistributedMember.class));
+    setupTx();
+    
+    TXStateProxy tx = txMgr.masqueradeAs(rollbackMsg);
+    try {
+      tx.rollback();
+    } finally {
+      txMgr.unmasquerade(tx);
+    }
+    assertFalse(tx.isInProgress());
+  }
+
+  private void setupTx() throws InterruptedException {
+    TXStateProxy tx = txMgr.masqueradeAs(msg);
+    tx.setCommitOnBehalfOfRemoteStub(true);
+    txMgr.unmasquerade(tx);
   }
 
   @Test
@@ -251,11 +291,8 @@ public class TXManagerImplTest {
           e.printStackTrace();
           throw new RuntimeException(e);
         }
-        try {
-          msg.process(dm);
-        } finally {
-          txMgr.unmasquerade(tx1);
-        }
+
+        msg.process(dm);
 
         TXStateProxy existingTx = masqueradeToRollback();
         latch.countDown();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/6f70cd70/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessageTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessageTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessageTest.java
index bbbf714..e05e130 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessageTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/partitioned/PartitionMessageTest.java
@@ -31,7 +31,6 @@ import com.gemstone.gemfire.distributed.internal.DistributionManager;
 import com.gemstone.gemfire.internal.cache.DataLocationException;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.internal.cache.TXId;
 import com.gemstone.gemfire.internal.cache.TXManagerImpl;
 import com.gemstone.gemfire.internal.cache.TXStateProxy;
 import com.gemstone.gemfire.internal.cache.TXStateProxyImpl;
@@ -47,7 +46,6 @@ public class PartitionMessageTest {
   private DistributionManager dm;
   private PartitionedRegion pr;
   private TXManagerImpl txMgr;
-  private TXId txid;
   private long startTime = 1;
   TXStateProxy tx;
   
@@ -59,7 +57,6 @@ public class PartitionMessageTest {
     pr = mock(PartitionedRegion.class);
     txMgr = mock(TXManagerImpl.class);
     tx = mock(TXStateProxyImpl.class);
-    txid = new TXId(null, 0);
     
     when(msg.checkCacheClosing(dm)).thenReturn(false);
     when(msg.checkDSClosing(dm)).thenReturn(false);
@@ -67,9 +64,8 @@ public class PartitionMessageTest {
     when(msg.getGemFireCacheImpl()).thenReturn(cache);
     when(msg.getStartPartitionMessageProcessingTime(pr)).thenReturn(startTime);
     when(msg.getTXManagerImpl(cache)).thenReturn(txMgr);
-    when(msg.hasTxAlreadyFinished(null, txMgr, txid)).thenCallRealMethod();
     
-    doAnswer(new CallsRealMethods()).when(msg).process(dm);    
+    doAnswer(new CallsRealMethods()).when(msg).process(dm);     
   }
 
   @Test
@@ -83,6 +79,7 @@ public class PartitionMessageTest {
   @Test
   public void messageForNotFinishedTXPerformsOnRegion() throws InterruptedException, CacheException, QueryException, DataLocationException, IOException {   
     when(txMgr.masqueradeAs(msg)).thenReturn(tx);
+    when(tx.isInProgress()).thenReturn(true);
     msg.process(dm);
     
     verify(msg, times(1)).operateOnPartitionedRegion(dm, pr, startTime);
@@ -91,10 +88,28 @@ public class PartitionMessageTest {
   @Test
   public void messageForFinishedTXDoesNotPerformOnRegion() throws InterruptedException, CacheException, QueryException, DataLocationException, IOException {   
     when(txMgr.masqueradeAs(msg)).thenReturn(tx);
-    when(msg.hasTxAlreadyFinished(tx, txMgr, txid)).thenReturn(true);
+    when(tx.isInProgress()).thenReturn(false);
     msg.process(dm);
   
     verify(msg, times(0)).operateOnPartitionedRegion(dm, pr, startTime);
   }
 
+  @Test
+  public void noNewTxProcessingAfterTXManagerImplClosed() throws CacheException, QueryException, DataLocationException, InterruptedException, IOException {
+    txMgr = new TXManagerImpl(null, cache);
+    when(msg.getPartitionedRegion()).thenReturn(pr);
+    when(msg.getGemFireCacheImpl()).thenReturn(cache);
+    when(msg.getStartPartitionMessageProcessingTime(pr)).thenReturn(startTime);
+    when(msg.getTXManagerImpl(cache)).thenReturn(txMgr);
+    when(msg.canParticipateInTransaction()).thenReturn(true);
+    when(msg.canStartRemoteTransaction()).thenReturn(true);
+    
+    msg.process(dm);
+    
+    txMgr.close();
+    
+    msg.process(dm);
+
+    verify(msg, times(1)).operateOnPartitionedRegion(dm, pr, startTime);
+  }
 }


[22/23] incubator-geode git commit: GEODE-1544: Fail to initiate final check when network partition occurs

Posted by kl...@apache.org.
GEODE-1544: Fail to initiate final check when network partition occurs

Currently, suspect request is only sent to a limited number of members,
when there are more than 4 members in the distributed system. It is
possible that the recipients of suspect request is unreachable due to
network partition. This fix makes sure that the recipients of suspect
request are not the suspect members. So that suspect request will be
processed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/144e7d13
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/144e7d13
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/144e7d13

Branch: refs/heads/feature/GEODE-835
Commit: 144e7d135cdd3d73d0b291a8e3c089bf320bf400
Parents: 612a9d9
Author: Jianxia Chen <jc...@pivotal.io>
Authored: Thu Jun 16 09:49:03 2016 -0700
Committer: Jianxia Chen <jc...@pivotal.io>
Committed: Thu Jun 16 09:49:03 2016 -0700

----------------------------------------------------------------------
 .../distributed/internal/membership/NetView.java    | 10 ++++++----
 .../membership/gms/fd/GMSHealthMonitor.java         | 16 ++++------------
 .../internal/membership/NetViewJUnitTest.java       |  2 +-
 3 files changed, 11 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/144e7d13/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
index 078281a..4c33e08 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/NetView.java
@@ -338,7 +338,7 @@ public class NetView implements DataSerializableFixedID {
         if (addr.equals(localAddress)) {
           continue;// this is must to add
         }
-        if (addr.getNetMember().preferredForCoordinator()) {
+        if (addr.getNetMember().preferredForCoordinator() && !filter.contains(addr)) {
           results.add(addr);
           if (results.size() >= maxNumberDesired) {
             break;
@@ -350,9 +350,11 @@ public class NetView implements DataSerializableFixedID {
 
       results.add(localAddress);// to add local address
 
-      if (notPreferredCoordinatorList.size() > 0) {
-        int idx = RANDOM.nextInt(notPreferredCoordinatorList.size());
-        results.add(notPreferredCoordinatorList.get(idx)); // to add non preferred local address
+      if (results.size() < maxNumberDesired && notPreferredCoordinatorList.size() > 0) {
+        Iterator<InternalDistributedMember> it = notPreferredCoordinatorList.iterator();
+        while (it.hasNext() && results.size() < maxNumberDesired) {
+          results.add(it.next());
+        }
       }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/144e7d13/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
index 203d9ce..e0f22a5 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/gms/fd/GMSHealthMonitor.java
@@ -30,18 +30,7 @@ import java.net.InetAddress;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.net.SocketTimeoutException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Timer;
-import java.util.TimerTask;
+import java.util.*;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.ExecutorService;
@@ -1335,6 +1324,9 @@ public class GMSHealthMonitor implements HealthMonitor, MessageHandler {
     List<InternalDistributedMember> recipients;
     if (currentView.size() > 4) {
       HashSet<InternalDistributedMember> filter = new HashSet<InternalDistributedMember>();
+      for (Enumeration<InternalDistributedMember> e = suspectedMemberInView.keys(); e.hasMoreElements();) {
+        filter.add(e.nextElement());
+      }
       for (int i = 0; i < requests.size(); i++) {
         filter.add(requests.get(i).getSuspectMember());
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/144e7d13/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
index 5caf997..fbc4189 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/membership/NetViewJUnitTest.java
@@ -99,7 +99,7 @@ public class NetViewJUnitTest {
     
     members.get(numMembers-1).getNetMember().setPreferredForCoordinator(true);
     List<InternalDistributedMember> preferred = view.getPreferredCoordinators(Collections.<InternalDistributedMember>singleton(members.get(1)), members.get(0), 2);
-    assertEquals(3, preferred.size());
+    assertEquals(2, preferred.size());
     assertEquals(members.get(numMembers-1), preferred.get(0));
   }
   


[13/23] incubator-geode git commit: GEODE-11: Passing down defaultField to query parser

Posted by kl...@apache.org.
GEODE-11: Passing down defaultField to query parser


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/d5dae19b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/d5dae19b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/d5dae19b

Branch: refs/heads/feature/GEODE-835
Commit: d5dae19b2d595403ddc1d2344e5fa3cf0bbc32a6
Parents: 79cba4d
Author: Jason Huynh <hu...@gmail.com>
Authored: Tue Jun 14 08:13:07 2016 -0700
Committer: Jason Huynh <hu...@gmail.com>
Committed: Tue Jun 14 14:56:42 2016 -0700

----------------------------------------------------------------------
 .../cache/lucene/LuceneQueryFactory.java        |  3 +-
 .../cache/lucene/LuceneQueryProvider.java       |  1 +
 .../lucene/internal/LuceneQueryFactoryImpl.java |  4 +--
 .../cache/lucene/internal/LuceneQueryImpl.java  |  3 +-
 .../lucene/internal/StringQueryProvider.java    | 11 +++++--
 ...IndexCreationPersistenceIntegrationTest.java | 33 ++++++++++----------
 .../LuceneIndexMaintenanceIntegrationTest.java  | 14 ++++-----
 .../gemfire/cache/lucene/LuceneQueriesBase.java | 29 ++++++++++++++++-
 .../lucene/LuceneQueriesIntegrationTest.java    | 27 ++++++++--------
 ...LuceneQueriesPersistenceIntegrationTest.java | 15 +--------
 .../LuceneQueryFactoryImplJUnitTest.java        |  6 ++--
 .../LuceneQueryImplIntegrationTest.java         |  5 ++-
 .../internal/StringQueryProviderJUnitTest.java  | 19 ++++++++---
 .../LuceneFunctionContextJUnitTest.java         |  3 +-
 .../distributed/LuceneFunctionJUnitTest.java    |  4 +--
 .../TopEntriesFunctionCollectorJUnitTest.java   |  6 ++--
 .../IndexRepositoryImplPerformanceTest.java     |  2 +-
 .../cache/lucene/test/LuceneTestUtilities.java  |  1 +
 18 files changed, 109 insertions(+), 77 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
index 198961a..a7844a2 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryFactory.java
@@ -76,12 +76,13 @@ public interface LuceneQueryFactory {
    * @param regionName region name
    * @param indexName index name
    * @param queryString query string in lucene QueryParser's syntax
+   * @param defaultField default field used by the Lucene Query Parser
    * @param <K> the key type in the query results
    * @param <V> the value type in the query results
    * @return LuceneQuery object
    * @throws ParseException
    */
-  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString) 
+  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString, String defaultField)
       throws ParseException;
 
   /**

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
index ef60158..92a3a1c 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/LuceneQueryProvider.java
@@ -42,4 +42,5 @@ public interface LuceneQueryProvider extends Serializable {
    * @throws QueryException if the provider fails to construct the query object
    */
   public Query getQuery(LuceneIndex index) throws QueryException;
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
index 385b226..62b4f56 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImpl.java
@@ -48,8 +48,8 @@ public class LuceneQueryFactoryImpl implements LuceneQueryFactory {
   }
 
   @Override
-  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString) {
-    return create(indexName, regionName, new StringQueryProvider(queryString));
+  public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, String queryString, String defaultField) {
+    return create(indexName, regionName, new StringQueryProvider(queryString, defaultField));
   }
   
   public <K, V> LuceneQuery<K, V> create(String indexName, String regionName, LuceneQueryProvider provider) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
index a876b40..c6b8878 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImpl.java
@@ -42,8 +42,9 @@ public class LuceneQueryImpl<K, V> implements LuceneQuery<K, V> {
   /* the lucene Query object to be wrapped here */
   private LuceneQueryProvider query;
   private Region<K, V> region;
+  private String defaultField;
   
-  public LuceneQueryImpl(String indexName, Region<K, V> region, LuceneQueryProvider provider, String[] projectionFields, 
+  public LuceneQueryImpl(String indexName, Region<K, V> region, LuceneQueryProvider provider, String[] projectionFields,
       int limit, int pageSize) {
     this.indexName = indexName;
     this.region = region;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
index 2ccd58d..3f121ec 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
@@ -52,12 +52,15 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   // the following members hold derived objects and need not be serialized
   private transient Query luceneQuery;
 
+  private String defaultField;
+
   public StringQueryProvider() {
-    this(null);
+    this(null, null);
   }
 
-  public StringQueryProvider(String query) {
+  public StringQueryProvider(String query, String defaultField) {
     this.query = query;
+    this.defaultField = defaultField;
   }
 
   @Override
@@ -68,7 +71,7 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
       LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
       StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
       try {
-        luceneQuery = parser.parse(query, fields[0]);
+        luceneQuery = parser.parse(query, defaultField);
         if (logger.isDebugEnabled()) {
           logger.debug("User query " + query + " is parsed to be: " + luceneQuery);
         }
@@ -100,10 +103,12 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
   @Override
   public void toData(DataOutput out) throws IOException {
     DataSerializer.writeString(query, out);
+    DataSerializer.writeString(defaultField, out);
   }
 
   @Override
   public void fromData(DataInput in) throws IOException, ClassNotFoundException {
     query = DataSerializer.readString(in);
+    defaultField = DataSerializer.readString(in);
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
index 26426ca..552278e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexCreationPersistenceIntegrationTest.java
@@ -20,13 +20,22 @@ package com.gemstone.gemfire.cache.lucene;
 
 import static com.gemstone.gemfire.cache.RegionShortcut.*;
 import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
-import static junitparams.JUnitParamsRunner.$;
+import static junitparams.JUnitParamsRunner.*;
 import static org.junit.Assert.*;
 
 import java.io.File;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
 
+import com.jayway.awaitility.Awaitility;
+import junitparams.JUnitParamsRunner;
+import junitparams.Parameters;
+import org.apache.lucene.queryparser.classic.ParseException;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
@@ -36,16 +45,6 @@ import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
-import com.jayway.awaitility.Awaitility;
-
-import org.apache.lucene.queryparser.classic.ParseException;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-
-import junitparams.JUnitParamsRunner;
-import junitparams.Parameters;
 
 /**
  * Tests of lucene index creation that use persistence
@@ -109,7 +108,7 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
     LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
       .create(INDEX_NAME, REGION_NAME,
-        "field1:world");
+        "field1:world", DEFAULT_FIELD);
     assertEquals(1, query.search().size());
   }
 
@@ -127,7 +126,7 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
       .create(REGION_NAME);
     LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory()
       .create(INDEX_NAME, REGION_NAME,
-      "field1:world");
+      "field1:world", DEFAULT_FIELD);
     assertEquals(1, query.search().size());
   }
 
@@ -138,8 +137,8 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     LuceneServiceProvider.get(this.cache).createIndex(INDEX_NAME+"_2", REGION_NAME, "field2");
     Region region = cache.createRegionFactory(shortcut).create(REGION_NAME);
     region.put("key1", new TestObject());
-    verifyQueryResultSize(INDEX_NAME+"_1", REGION_NAME, "field1:world", 1);
-    verifyQueryResultSize(INDEX_NAME+"_2", REGION_NAME, "field2:field", 1);
+    verifyQueryResultSize(INDEX_NAME+"_1", REGION_NAME, "field1:world", DEFAULT_FIELD, 1);
+    verifyQueryResultSize(INDEX_NAME+"_2", REGION_NAME, "field2:field", DEFAULT_FIELD, 1);
   }
 
   @Test
@@ -160,8 +159,8 @@ public class LuceneIndexCreationPersistenceIntegrationTest extends LuceneIntegra
     });
   }
 
-  private void verifyQueryResultSize(String indexName, String regionName, String queryString, int size) throws ParseException {
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(indexName, regionName, queryString);
+  private void verifyQueryResultSize(String indexName, String regionName, String queryString, String defaultField, int size) throws ParseException {
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(indexName, regionName, queryString, defaultField);
     Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
       assertEquals(size, query.search().size());
     });

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
index af8c51f..05b6990 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneIndexMaintenanceIntegrationTest.java
@@ -24,16 +24,16 @@ import static org.junit.Assert.*;
 import java.io.Serializable;
 import java.util.concurrent.TimeUnit;
 
+import com.jayway.awaitility.Awaitility;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexForPartitionedRegion;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexStats;
 import com.gemstone.gemfire.cache.lucene.internal.filesystem.FileSystemStats;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
-import com.jayway.awaitility.Awaitility;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
 
 @Category(IntegrationTest.class)
 public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest {
@@ -52,7 +52,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 
@@ -75,7 +75,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 
@@ -99,7 +99,7 @@ public class LuceneIndexMaintenanceIntegrationTest extends LuceneIntegrationTest
 
     LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
     index.waitUntilFlushed(WAIT_FOR_FLUSH_TIME);
-    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"");
+    LuceneQuery query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "description:\"hello world\"", DEFAULT_FIELD);
     LuceneQueryResults<Integer, TestObject> results = query.search();
     assertEquals(3, results.size());
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
index 92d8e8b..26cd4aa 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesBase.java
@@ -70,6 +70,21 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
   }
 
   @Test
+  public void defaultFieldShouldPropogateCorrectlyThroughFunction() {
+    SerializableRunnableIF createIndex = () -> {
+      LuceneService luceneService = LuceneServiceProvider.get(getCache());
+      luceneService.createIndex(INDEX_NAME, REGION_NAME, "text");
+    };
+    dataStore1.invoke(() -> initDataStore(createIndex));
+    dataStore2.invoke(() -> initDataStore(createIndex));
+    accessor.invoke(() -> initAccessor(createIndex));
+    putDataInRegion(accessor);
+    assertTrue(waitForFlushBeforeExecuteTextSearch(accessor, 60000));
+    executeTextSearch(accessor, "world", "text", 3);
+    executeTextSearch(accessor, "world", "noEntriesMapped", 0);
+  }
+
+  @Test
   public void entriesFlushedToIndexAfterWaitForFlushCalled() {
     SerializableRunnableIF createIndex = () -> {
       LuceneService luceneService = LuceneServiceProvider.get(getCache());
@@ -108,7 +123,7 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
 
       LuceneService service = LuceneServiceProvider.get(cache);
       LuceneQuery<Integer, TestObject> query;
-      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world");
+      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "text:world", DEFAULT_FIELD);
       LuceneQueryResults<Integer, TestObject> results = query.search();
       assertEquals(3, results.size());
       List<LuceneResultStruct<Integer, TestObject>> page = results.getNextPage();
@@ -123,6 +138,18 @@ public abstract class LuceneQueriesBase extends LuceneDUnitTest {
     });
   }
 
+  protected void executeTextSearch(VM vm, String queryString, String defaultField, int expectedResultsSize) {
+    vm.invoke(() -> {
+      Cache cache = getCache();
+
+      LuceneService service = LuceneServiceProvider.get(cache);
+      LuceneQuery<Integer, TestObject> query;
+      query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, queryString, defaultField);
+      LuceneQueryResults<Integer, TestObject> results = query.search();
+      assertEquals(results.size(), expectedResultsSize);
+    });
+  }
+
   protected void putDataInRegion(VM vm) {
     vm.invoke(() -> {
       final Cache cache = getCache();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index c26997d..536f5c3 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -16,7 +16,8 @@
  */
 package com.gemstone.gemfire.cache.lucene;
 
-import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.verifyQueryKeys;
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
+import static javax.swing.Action.DEFAULT;
 import static org.hamcrest.Matchers.isA;
 import static org.junit.Assert.assertEquals;
 
@@ -83,28 +84,28 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     // but standard analyzer will parse value "one@three" to be "one three"
     // query will be--fields1:"one three"
     // so C will be hit by query
-    verifyQuery("field1:\"one three\"", "A", "C");
+    verifyQuery("field1:\"one three\"", DEFAULT_FIELD, "A", "C");
     
     // standard analyzer will not tokenize by '_'
     // this query string will be parsed as "one_three"
     // query will be--field1:one_three
-    verifyQuery("field1:one_three");
+    verifyQuery("field1:one_three", DEFAULT_FIELD);
     
     // standard analyzer will tokenize by '@'
     // this query string will be parsed as "one" "three"
     // query will be--field1:one field1:three
-    verifyQuery("field1:one@three", "A", "B", "C");
+    verifyQuery("field1:one@three", DEFAULT_FIELD, "A", "B", "C");
     
     // keyword analyzer, this query will only match the entry that exactly matches
     // this query string will be parsed as "one three"
     // but keyword analyzer will parse one@three to be "one three"
     // query will be--field2:one three
-    verifyQuery("field2:\"one three\"", "A");
+    verifyQuery("field2:\"one three\"", DEFAULT_FIELD, "A");
 
     // keyword analyzer without double quote. It should be the same as 
     // with double quote
     // query will be--field2:one@three
-    verifyQuery("field2:one@three", "C");
+    verifyQuery("field2:one@three", DEFAULT_FIELD, "C");
   }
 
   @Test()
@@ -130,9 +131,9 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
 
     index.waitUntilFlushed(60000);
 
-    verifyQuery("field1:one AND field2:two_four", "A");
-    verifyQuery("field1:one AND field2:two", "A");
-    verifyQuery("field1:three AND field2:four", "A");
+    verifyQuery("field1:one AND field2:two_four", DEFAULT_FIELD, "A");
+    verifyQuery("field1:one AND field2:two", DEFAULT_FIELD, "A");
+    verifyQuery("field1:three AND field2:four", DEFAULT_FIELD, "A");
   }
 
   @Test()
@@ -150,7 +151,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     region.put("A", new TestObject(value1, null));
     index.waitUntilFlushed(60000);
 
-    verifyQuery("field1:one", "A");
+    verifyQuery("field1:one", DEFAULT_FIELD, "A");
   }
 
   @Test()
@@ -162,7 +163,7 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
 
     //Create a query that throws an exception
     final LuceneQuery<Object, Object> query = luceneService.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME,
-      index -> {
+      (index) -> {
         throw new QueryException("Bad query");
       });
 
@@ -178,9 +179,9 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
 
   }
 
-  private void verifyQuery(String query, String ... expectedKeys) throws ParseException {
+  private void verifyQuery(String query, String defaultField, String ... expectedKeys) throws ParseException {
     final LuceneQuery<String, Object> queryWithStandardAnalyzer = luceneService.createLuceneQueryFactory().create(
-      INDEX_NAME, REGION_NAME, query);
+      INDEX_NAME, REGION_NAME, query, defaultField);
 
     verifyQueryKeys(queryWithStandardAnalyzer, expectedKeys);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
index 4bb67d2..6eb222d 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesPersistenceIntegrationTest.java
@@ -18,35 +18,23 @@
  */
 package com.gemstone.gemfire.cache.lucene;
 
-import static com.gemstone.gemfire.cache.RegionShortcut.*;
 import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.*;
-import static junitparams.JUnitParamsRunner.*;
 import static org.junit.Assert.*;
 
 import java.io.File;
-import java.util.concurrent.TimeUnit;
-import java.util.function.Consumer;
 
 import com.gemstone.gemfire.cache.EvictionAction;
 import com.gemstone.gemfire.cache.EvictionAlgorithm;
-import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionFactory;
 import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
 import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.Type1;
-import com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities;
-import com.gemstone.gemfire.cache.lucene.test.TestObject;
 import com.gemstone.gemfire.internal.cache.EvictionAttributesImpl;
 import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.cache.LocalRegion;
 import com.gemstone.gemfire.internal.cache.PartitionedRegion;
-import com.gemstone.gemfire.test.junit.categories.FlakyTest;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 import com.gemstone.gemfire.test.junit.rules.DiskDirRule;
-import com.jayway.awaitility.Awaitility;
 
-import org.apache.lucene.queryparser.classic.ParseException;
 import org.junit.Assert;
 import org.junit.Rule;
 import org.junit.Test;
@@ -54,7 +42,6 @@ import org.junit.experimental.categories.Category;
 import org.junit.runner.RunWith;
 
 import junitparams.JUnitParamsRunner;
-import junitparams.Parameters;
 
 /**
  * Tests of lucene index creation that use persistence
@@ -108,7 +95,7 @@ public class LuceneQueriesPersistenceIntegrationTest extends LuceneIntegrationTe
     assertNotNull(chunkRegion);
     Assert.assertTrue(0 < userRegion.getDiskRegionStats().getNumOverflowOnDisk());
 
-    LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "s:world");
+    LuceneQuery<Integer, Type1> query = service.createLuceneQueryFactory().create(INDEX_NAME, REGION_NAME, "s:world", DEFAULT_FIELD);
     LuceneQueryResults<Integer, Type1> results = query.search();
     Assert.assertEquals(3, results.size());
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
index 975b92f..1dd4aa2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryFactoryImplJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.*;
@@ -35,6 +36,7 @@ import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 @Category(UnitTest.class)
 public class LuceneQueryFactoryImplJUnitTest {
+
   @Rule
   public ExpectedException thrown = ExpectedException.none();
 
@@ -48,7 +50,7 @@ public class LuceneQueryFactoryImplJUnitTest {
     f.setResultLimit(25);
     String[] projection = new String[] {"a", "b"};
     f.setProjectionFields(projection);
-    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test"));
+    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test", DEFAULT_FIELD));
     assertEquals(25, query.getLimit());
     assertEquals(5, query.getPageSize());
     assertArrayEquals(projection, query.getProjectedFieldNames());
@@ -61,7 +63,7 @@ public class LuceneQueryFactoryImplJUnitTest {
     Cache cache = mock(Cache.class);
     LuceneQueryFactoryImpl f = new LuceneQueryFactoryImpl(cache);
     thrown.expect(IllegalArgumentException.class);
-    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test"));
+    LuceneQuery<Object, Object> query = f.create("index", "region", new StringQueryProvider("test", DEFAULT_FIELD));
   }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
index 262efaa..c2e9b0c 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/LuceneQueryImplIntegrationTest.java
@@ -19,6 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
@@ -29,8 +30,6 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
 import com.gemstone.gemfire.cache.Region;
 import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.execute.FunctionAdapter;
@@ -68,7 +67,7 @@ public class LuceneQueryImplIntegrationTest extends LuceneIntegrationTest {
     TestLuceneFunction function = new TestLuceneFunction();
     FunctionService.registerFunction(function);
 
-    StringQueryProvider provider = new StringQueryProvider();
+    StringQueryProvider provider = new StringQueryProvider(null, DEFAULT_FIELD);
     LuceneQueryImpl<Object, Object> query = new LuceneQueryImpl<>("index", region, provider, null, LIMIT, 20);
     LuceneQueryResults<Object, Object> results = query.search();
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
index da6715a..a08875a 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.assertEquals;
 
 import org.apache.lucene.analysis.Analyzer;
@@ -31,7 +32,6 @@ import org.junit.experimental.categories.Category;
 import org.mockito.Mockito;
 
 import com.gemstone.gemfire.CopyHelper;
-import com.gemstone.gemfire.cache.lucene.LuceneIndex;
 import com.gemstone.gemfire.cache.query.QueryException;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
@@ -53,7 +53,7 @@ public class StringQueryProviderJUnitTest {
 
   @Test
   public void testQueryConstruction() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("foo:bar");
+    StringQueryProvider provider = new StringQueryProvider("foo:bar", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
     assertEquals("foo:bar", query.toString());
@@ -62,7 +62,7 @@ public class StringQueryProviderJUnitTest {
   @Test
   @Ignore("Custom analyzer not yet supported, this is a duplicate test right now")
   public void usesCustomAnalyzer() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("findThis");
+    StringQueryProvider provider = new StringQueryProvider("findThis", DEFAULT_FIELD);
     Query query = provider.getQuery(mockIndex);
     Assert.assertNotNull(query);
     assertEquals("field-1:findthis field-2:findthis", query.toString());
@@ -70,15 +70,24 @@ public class StringQueryProviderJUnitTest {
 
   @Test(expected = QueryException.class)
   public void errorsOnMalformedQueryString() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("invalid:lucene:query:string");
+    StringQueryProvider provider = new StringQueryProvider("invalid:lucene:query:string", DEFAULT_FIELD);
     provider.getQuery(mockIndex);
   }
   
   @Test
   public void testSerialization() {
     LuceneServiceImpl.registerDataSerializables();
-    StringQueryProvider provider = new StringQueryProvider("text:search");
+    StringQueryProvider provider = new StringQueryProvider("text:search", DEFAULT_FIELD);
     StringQueryProvider copy = CopyHelper.deepCopy(provider);
     assertEquals("text:search", copy.getQueryString());
   }
+
+  @Test
+  public void defaultFieldParameterShouldBeUsedByQuery() throws QueryException {
+    StringQueryProvider provider = new StringQueryProvider("findThis",  "field-2");
+    Query query = provider.getQuery(mockIndex);
+    Assert.assertNotNull(query);
+    assertEquals("field-2:findthis", query.toString());
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
index 39a4dde..3b0870e 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionContextJUnitTest.java
@@ -18,6 +18,7 @@
  */
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 
 import org.junit.Test;
@@ -46,7 +47,7 @@ public class LuceneFunctionContextJUnitTest {
   public void testSerialization() {
     LuceneServiceImpl.registerDataSerializables();
 
-    LuceneQueryProvider provider = new StringQueryProvider("text");
+    LuceneQueryProvider provider = new StringQueryProvider("text", DEFAULT_FIELD);
     CollectorManager<TopEntriesCollector> manager = new TopEntriesCollectorManager("test");
     LuceneFunctionContext<TopEntriesCollector> context = new LuceneFunctionContext<>(provider, "testIndex", manager, 123);
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
index c1a64ae..178fae2 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/LuceneFunctionJUnitTest.java
@@ -19,6 +19,7 @@
 
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
+import static com.gemstone.gemfire.cache.lucene.test.LuceneTestUtilities.DEFAULT_FIELD;
 import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
@@ -32,7 +33,6 @@ import com.gemstone.gemfire.cache.execute.FunctionException;
 import com.gemstone.gemfire.cache.execute.ResultSender;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryFactory;
 import com.gemstone.gemfire.cache.lucene.LuceneQueryProvider;
-import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneIndex;
 import com.gemstone.gemfire.cache.lucene.internal.InternalLuceneService;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexImpl;
 import com.gemstone.gemfire.cache.lucene.internal.StringQueryProvider;
@@ -272,7 +272,7 @@ public class LuceneFunctionJUnitTest {
     mockCache = mock(InternalCache.class);
     Analyzer analyzer = new StandardAnalyzer();
     Mockito.doReturn(analyzer).when(mockIndex).getAnalyzer();
-    queryProvider = new StringQueryProvider("gemfire:lucene");
+    queryProvider = new StringQueryProvider("gemfire:lucene", DEFAULT_FIELD);
     
     searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName");
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
index b7709bc..372c5a3 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/distributed/TopEntriesFunctionCollectorJUnitTest.java
@@ -19,12 +19,10 @@
 
 package com.gemstone.gemfire.cache.lucene.internal.distributed;
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
 import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.*;
 
-import java.io.IOException;
 import java.util.Collection;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
index 15ef449..5e1a104 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImplPerformanceTest.java
@@ -74,7 +74,7 @@ public class IndexRepositoryImplPerformanceTest {
   private static int NUM_QUERIES = 500_000;
 
   private StandardAnalyzer analyzer = new StandardAnalyzer();
-  
+
   @Test
   public  void testIndexRepository() throws Exception {
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/d5dae19b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
index 0cf8953..6ef93bf 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
@@ -42,6 +42,7 @@ import com.gemstone.gemfire.internal.cache.LocalRegion;
 public class LuceneTestUtilities {
   public static final String INDEX_NAME = "index";
   public static final String REGION_NAME = "region";
+  public static final String DEFAULT_FIELD = "text";
 
   public static final String CANNOT_CREATE_LUCENE_INDEX_DIFFERENT_FIELDS = "Cannot create Lucene index index on region /region with fields [field1, field2] because another member defines the same index with fields [field1].";
   public static final String CANNOT_CREATE_LUCENE_INDEX_NO_ANALYZER_FIELD2 = "Cannot create Lucene index index on region /region with no analyzer on field field2 because another member defines the same index with analyzer org.apache.lucene.analysis.core.KeywordAnalyzer on that field.";



[04/23] incubator-geode git commit: GEODE-1494: Allowing stats to be measured with callbacks

Posted by kl...@apache.org.
GEODE-1494: Allowing stats to be measured with callbacks

Adding support to measure statistics with suppliers that are sampled
every sample interval. The suppliers are invoked in a separate thread
than the stat sampler so that slow suppliers won't screw up all stats.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/01848b6e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/01848b6e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/01848b6e

Branch: refs/heads/feature/GEODE-835
Commit: 01848b6eea4f90e9525eb42aba4d10ba0584c415
Parents: e9ffdce
Author: Dan Smith <up...@apache.org>
Authored: Fri Jun 3 12:07:37 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Jun 13 10:45:13 2016 -0700

----------------------------------------------------------------------
 .../java/com/gemstone/gemfire/Statistics.java   | 253 +++++++++++++++++++
 .../gemfire/internal/DummyStatisticsImpl.java   |  44 ++++
 .../gemfire/internal/HostStatSampler.java       |  10 +-
 .../gemfire/internal/StatSamplerStats.java      |  34 ++-
 .../gemfire/internal/StatisticsImpl.java        | 143 ++++++++++-
 .../gemfire/internal/StatisticsTypeImpl.java    |   6 +-
 .../internal/statistics/CallbackSampler.java    |  96 +++++++
 .../internal/statistics/SampleCollector.java    |   4 +-
 .../internal/LocalStatisticsImplJUnitTest.java  | 139 ++++++++++
 .../StatArchiveWriterReaderJUnitTest.java       |  16 +-
 .../gemfire/internal/StatSamplerJUnitTest.java  |  34 ++-
 .../statistics/CallbackSamplerJUnitTest.java    |  98 +++++++
 .../internal/statistics/DummyStatistics.java    | 208 ---------------
 13 files changed, 842 insertions(+), 243 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/Statistics.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/Statistics.java b/geode-core/src/main/java/com/gemstone/gemfire/Statistics.java
index d7f45a5..0b9c18e 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/Statistics.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/Statistics.java
@@ -18,6 +18,10 @@ package com.gemstone.gemfire;
 
 //import com.gemstone.gemfire.distributed.DistributedSystem;
 
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+
 /**
  * Instances of this interface maintain the values of various application-defined
  * statistics.  The statistics themselves are described by an instance
@@ -441,4 +445,253 @@ public interface Statistics {
    *         type <code>double</code>.
    */
   public void incDouble(String name, double delta);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param id a statistic id obtained with {@link #nameToId}
+   * or {@link StatisticsType#nameToId}.
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws ArrayIndexOutOfBoundsException If the id is invalid.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not int
+   */
+  public IntSupplier setIntSupplier(int id, IntSupplier supplier);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param name the nane of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with name <code>name</code> or
+   *         if the statistic named <code>name</code> is not of
+   *         type <code>int</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not int
+   */
+  public IntSupplier setIntSupplier(String name, IntSupplier supplier);
+
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param descriptor the descriptor of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with the given <code>descriptor</code> or
+   *         if the described statistic is not of
+   *         type <code>int</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not int
+   */
+  public IntSupplier setIntSupplier(StatisticDescriptor descriptor, IntSupplier supplier);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param id a statistic id obtained with {@link #nameToId}
+   * or {@link StatisticsType#nameToId}.
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws ArrayIndexOutOfBoundsException If the id is invalid.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not long
+   */
+  public LongSupplier setLongSupplier(int id, LongSupplier supplier);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param name the nane of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with name <code>name</code> or
+   *         if the statistic named <code>name</code> is not of
+   *         type <code>long</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not long
+   */
+  public LongSupplier setLongSupplier(String name, LongSupplier supplier);
+
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by long running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param descriptor the descriptor of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with the given <code>descriptor</code> or
+   *         if the described statistic is not of
+   *         type <code>long</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not long
+   */
+  public LongSupplier setLongSupplier(StatisticDescriptor descriptor, LongSupplier supplier);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by double running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param id a statistic id obtained with {@link #nameToId}
+   * or {@link StatisticsType#nameToId}.
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws ArrayIndexOutOfBoundsException If the id is invalid.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not double
+   */
+  public DoubleSupplier setDoubleSupplier(int id, DoubleSupplier supplier);
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by double running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param name the nane of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with name <code>name</code> or
+   *         if the statistic named <code>name</code> is not of
+   *         type <code>double</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not double
+   */
+  public DoubleSupplier setDoubleSupplier(String name, DoubleSupplier supplier);
+
+
+  /**
+   * Provide a callback to compute the value of this statistic
+   * every sample interval and use that as the value of the stat.
+   * <p>
+   * The callback should return quickly because it is invoked on a shared thread.
+   * It should not do any expensive computations, network calls, or access any resources
+   * under locks that may be locked by double running processes.
+   * <p>
+   * This callback will only be invoked if the distributed system property
+   * statistic-sampling-enabled is set to true, and it will be invoked at intervals
+   * determined by the statistic-sampling-rate.
+   * <p>
+   * Get methods are not guaranteed to recompute a new value, they may return
+   * the last sampled value
+   * @param descriptor the descriptor of the statistic to update
+   * @param supplier a callback that will return the value of the stat. This
+   * replaces any previously registered supplier. If the passed in suppplier is null, it
+   * will remove any existing supplier
+   * @return the previously registered supplier, or null if there was no previously registered supplier
+   * @throws IllegalArgumentException
+   *         If no statistic exists with the given <code>descriptor</code> or
+   *         if the described statistic is not of
+   *         type <code>double</code>.
+   * @throws IllegalArgumentException if the type of this
+   * stat is not double
+   */
+  public DoubleSupplier setDoubleSupplier(StatisticDescriptor descriptor, DoubleSupplier supplier);
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/DummyStatisticsImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/DummyStatisticsImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/DummyStatisticsImpl.java
index 83d4055..aa8da50 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/DummyStatisticsImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/DummyStatisticsImpl.java
@@ -16,6 +16,10 @@
  */
 package com.gemstone.gemfire.internal;
 
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+
 import com.gemstone.gemfire.*;
 
 /**
@@ -195,4 +199,44 @@ public class DummyStatisticsImpl implements Statistics {
 
   public final void incDouble(String name, double delta) {
   }
+
+  @Override
+  public IntSupplier setIntSupplier(final int id, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final String name, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final StatisticDescriptor descriptor, final IntSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final int id, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final String name, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public LongSupplier setLongSupplier(final StatisticDescriptor descriptor, final LongSupplier supplier) {
+    return null;
+  }
+
+  @Override public DoubleSupplier setDoubleSupplier(final int id, final DoubleSupplier supplier) {
+    return null;
+  }
+
+  @Override public DoubleSupplier setDoubleSupplier(final String name, final DoubleSupplier supplier) {
+    return null;
+  }
+
+  @Override
+  public DoubleSupplier setDoubleSupplier(final StatisticDescriptor descriptor, final DoubleSupplier supplier) {
+    return null;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
index a5a07ca..38fc83d 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
@@ -26,6 +26,7 @@ import com.gemstone.gemfire.internal.logging.LogService;
 import com.gemstone.gemfire.internal.logging.LoggingThreadGroup;
 import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
 import com.gemstone.gemfire.internal.logging.log4j.LogMarker;
+import com.gemstone.gemfire.internal.statistics.CallbackSampler;
 import com.gemstone.gemfire.internal.statistics.SampleCollector;
 import com.gemstone.gemfire.internal.statistics.StatArchiveHandlerConfig;
 import com.gemstone.gemfire.internal.statistics.StatisticsSampler;
@@ -35,6 +36,7 @@ import org.apache.logging.log4j.Logger;
 import java.io.File;
 import java.net.UnknownHostException;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
 
 /**
  * HostStatSampler implements a thread which will monitor, sample, and archive
@@ -50,7 +52,7 @@ public abstract class HostStatSampler
   public static final String OS_STATS_DISABLED_PROPERTY = "osStatsDisabled";
 
   protected static final String INITIALIZATION_TIMEOUT_PROPERTY = DistributionConfig.GEMFIRE_PREFIX + "statSamplerInitializationTimeout";
-  protected static final int INITIALIZATION_TIMEOUT_DEFAULT = 3000;
+  protected static final int INITIALIZATION_TIMEOUT_DEFAULT = 30000;
   protected static final long INITIALIZATION_TIMEOUT_MILLIS = 
       Long.getLong(INITIALIZATION_TIMEOUT_PROPERTY, INITIALIZATION_TIMEOUT_DEFAULT);
   
@@ -82,6 +84,8 @@ public abstract class HostStatSampler
   private final StoppableCountDownLatch statSamplerInitializedLatch;
 
   private final CancelCriterion stopper;
+
+  private final CallbackSampler callbackSampler;
   
   protected HostStatSampler(CancelCriterion stopper, 
                             StatSamplerStats samplerStats) {
@@ -89,6 +93,7 @@ public abstract class HostStatSampler
     this.statSamplerInitializedLatch = new StoppableCountDownLatch(this.stopper, 1);
     this.samplerStats = samplerStats;
     this.fileSizeLimitInKB = Boolean.getBoolean(TEST_FILE_SIZE_LIMIT_IN_KB_PROPERTY);
+    this.callbackSampler = new CallbackSampler(stopper, samplerStats);
   }
   
   public final StatSamplerStats getStatSamplerStats() {
@@ -276,6 +281,8 @@ public abstract class HostStatSampler
       }  
       ThreadGroup group = 
         LoggingThreadGroup.createThreadGroup("StatSampler Threads");
+
+      this.callbackSampler.start(getStatisticsManager(), group, getSampleRate(), TimeUnit.MILLISECONDS);
       statThread = new Thread(group, this);
       statThread.setName(statThread.getName() + " StatSampler");
       statThread.setPriority(Thread.MAX_PRIORITY);
@@ -298,6 +305,7 @@ public abstract class HostStatSampler
   }
   private final void stop(boolean interruptIfAlive) {
     synchronized (HostStatSampler.class) {
+      this.callbackSampler.stop();
       if ( statThread == null) {
         return; 
       }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/StatSamplerStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatSamplerStats.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatSamplerStats.java
index c702479..bbe333c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatSamplerStats.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatSamplerStats.java
@@ -27,13 +27,19 @@ public class StatSamplerStats {
   public final static String DELAY_DURATION = "delayDuration"; // int
   public final static String STAT_RESOURCES = "statResources"; // int
   public final static String JVM_PAUSES = "jvmPauses"; // int
-  
+  public final static String SAMPLE_CALLBACKS = "sampleCallbacks"; // int
+  public final static String SAMPLE_CALLBACK_ERRORS = "sampleCallbackErrors"; // int
+  public final static String SAMPLE_CALLBACK_DURATION = "sampleCallbackDuration"; // long
+
   private final static StatisticsType samplerType;
   private final static int sampleCountId;
   private final static int sampleTimeId;
   private final static int delayDurationId;
   private final static int statResourcesId;
   private final static int jvmPausesId;
+  private final static int sampleCallbacksId;
+  private final static int sampleCallbackErrorsId;
+  private final static int sampleCallbackDurationId;
   static {
     StatisticsTypeFactory f = StatisticsTypeFactoryImpl.singleton();
     samplerType = f.createType("StatSampler",
@@ -54,12 +60,24 @@ public class StatSamplerStats {
                                  f.createIntCounter(JVM_PAUSES,
                                                     "Total number of JVM pauses (which may or may not be full GC pauses) detected by this sampler. A JVM pause is defined as a system event which kept the statistics sampler thread from sampling for 3000 or more milliseconds. This threshold can be customized by setting the system property gemfire.statSamplerDelayThreshold (units are milliseconds).",
                                                     "jvmPauses", false),
+                                 f.createIntGauge(SAMPLE_CALLBACKS,
+                                   "Total number of statistics that are sampled using callbacks.",
+                                   "resources", false),
+                                 f.createIntCounter(SAMPLE_CALLBACK_ERRORS,
+                                   "Total number of exceptions thrown by callbacks when performing sampling",
+                                   "errors", false),
+                                 f.createLongCounter(SAMPLE_CALLBACK_DURATION,
+                                   "Total amount of time invoking sampling callbacks",
+                                   "milliseconds", false),
                                });
     sampleCountId = samplerType.nameToId(SAMPLE_COUNT);
     sampleTimeId = samplerType.nameToId(SAMPLE_TIME);
     delayDurationId = samplerType.nameToId(DELAY_DURATION);
     statResourcesId = samplerType.nameToId(STAT_RESOURCES);
     jvmPausesId = samplerType.nameToId(JVM_PAUSES);
+    sampleCallbacksId = samplerType.nameToId(SAMPLE_CALLBACKS);
+    sampleCallbackErrorsId = samplerType.nameToId(SAMPLE_CALLBACK_ERRORS);
+    sampleCallbackDurationId = samplerType.nameToId(SAMPLE_CALLBACK_DURATION);
   }
 
   private final Statistics samplerStats;
@@ -78,7 +96,19 @@ public class StatSamplerStats {
   public void incJvmPauses() {
     this.samplerStats.incInt(jvmPausesId, 1);
   }
-  
+
+  public void incSampleCallbackErrors(int delta) {
+    this.samplerStats.incInt(sampleCallbackErrorsId, delta);
+  }
+
+  public void setSampleCallbacks(int count) {
+    this.samplerStats.setInt(sampleCallbacksId, count);
+  }
+
+  public void incSampleCallbackDuration(long delta) {
+    this.samplerStats.incLong(sampleCallbackDurationId, delta);
+  }
+
   public int getSampleCount() {
     return this.samplerStats.getInt(SAMPLE_COUNT);
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsImpl.java
index 2344d93..04bfc01 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsImpl.java
@@ -17,11 +17,23 @@
 package com.gemstone.gemfire.internal;
 
 //import com.gemstone.gemfire.distributed.DistributedSystem;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+import java.util.function.Supplier;
+
 import com.gemstone.gemfire.StatisticDescriptor;
 import com.gemstone.gemfire.Statistics;
 import com.gemstone.gemfire.StatisticsType;
 import com.gemstone.gemfire.internal.concurrent.Atomics;
 import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.internal.util.concurrent.CopyOnWriteHashMap;
+
+import org.apache.logging.log4j.Logger;
 
 // @todo darrel Add statistics instances to archive when they are created. 
 /**
@@ -42,6 +54,8 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
  * @since GemFire 3.0
  */
 public abstract class StatisticsImpl implements Statistics {
+  /** logger - not private for tests */
+  static Logger logger = LogService.getLogger();
 
   /** The type of this statistics instance */
   private final StatisticsTypeImpl type;
@@ -61,6 +75,25 @@ public abstract class StatisticsImpl implements Statistics {
   /** Uniquely identifies this instance */
   private long uniqueId;
 
+  /**
+   * Suppliers of int sample values to be sampled every sample-interval
+   */
+  private final CopyOnWriteHashMap<Integer, IntSupplier> intSuppliers = new CopyOnWriteHashMap<>();
+  /**
+   * Suppliers of long sample values to be sampled every sample-interval
+   */
+  private final CopyOnWriteHashMap<Integer, LongSupplier> longSuppliers = new CopyOnWriteHashMap<>();
+  /**
+   * Suppliers of double sample values to be sampled every sample-interval
+   */
+  private final CopyOnWriteHashMap<Integer, DoubleSupplier> doubleSuppliers = new CopyOnWriteHashMap<>();
+
+  /**
+   * Suppliers that have previously failed. Tracked to avoid logging many messages about
+   * a failing supplier
+   */
+  private final Set<Object> flakySuppliers = new HashSet<Object>();
+
   ///////////////////////  Constructors  ///////////////////////
 
   /** factory method to create a class that implements Statistics
@@ -362,6 +395,12 @@ public abstract class StatisticsImpl implements Statistics {
   }
 
   /**
+   * Increments the value of the statistic of type <code>double</code> at
+   * the given offset by a given amount, but performs no type checking.
+   */
+  protected abstract void _incDouble(int offset, double delta);
+
+  /**
    * For internal use only.
    * Tells the implementation to prepare the data in this instance
    * for sampling.
@@ -372,10 +411,108 @@ public abstract class StatisticsImpl implements Statistics {
   }
 
   /**
-   * Increments the value of the statistic of type <code>double</code> at
-   * the given offset by a given amount, but performs no type checking.
+   * Invoke sample suppliers to retrieve the current value for
+   * the suppler controlled sets and update the stats to reflect
+   * the supplied values.
+   * @return the number of callback errors that occurred while
+   * sampling stats
    */
-  protected abstract void _incDouble(int offset, double delta);
+  public int invokeSuppliers() {
+    int errors = 0;
+    for(Map.Entry<Integer, IntSupplier> entry: intSuppliers.entrySet()) {
+      try {
+        _setInt(entry.getKey(), entry.getValue().getAsInt());
+      } catch(Throwable t) {
+        logSupplierError(t, entry.getKey(), entry.getValue());
+        errors++;
+      }
+    }
+    for(Map.Entry<Integer, LongSupplier> entry: longSuppliers.entrySet()) {
+      try {
+        _setLong(entry.getKey(), entry.getValue().getAsLong());
+      } catch(Throwable t) {
+        logSupplierError(t, entry.getKey(), entry.getValue());
+        errors++;
+      }
+    }
+    for(Map.Entry<Integer, DoubleSupplier> entry: doubleSuppliers.entrySet()) {
+      try {
+        _setDouble(entry.getKey(), entry.getValue().getAsDouble());
+      } catch(Throwable t) {
+        logSupplierError(t, entry.getKey(), entry.getValue());
+        errors++;
+      }
+    }
+
+    return errors;
+  }
+
+  private void logSupplierError(final Throwable t, int statId, Object supplier) {
+    if(flakySuppliers.add(supplier)) {
+      logger.warn("Error invoking supplier for stat {}, id {}", this.getTextId(), statId, t);
+    }
+  }
+
+  /**
+   * @return the number of statistics that are measured using supplier callbacks
+   */
+  public int getSupplierCount() {
+    return intSuppliers.size() + doubleSuppliers.size() + longSuppliers.size();
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final int id, final IntSupplier supplier) {
+    if(id >= type.getIntStatCount()) {
+      throw new IllegalArgumentException("Id " + id + " is not in range for stat" + type);
+    }
+    return intSuppliers.put(id, supplier);
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final String name, final IntSupplier supplier) {
+    return setIntSupplier(nameToId(name), supplier);
+  }
+
+  @Override
+  public IntSupplier setIntSupplier(final StatisticDescriptor descriptor, final IntSupplier supplier) {
+    return setIntSupplier(getIntId(descriptor), supplier);
+  }
+
+  @Override
+  public LongSupplier setLongSupplier(final int id, final LongSupplier supplier) {
+    if(id >= type.getLongStatCount()) {
+      throw new IllegalArgumentException("Id " + id + " is not in range for stat" + type);
+    }
+    return longSuppliers.put(id, supplier);
+  }
+
+  @Override
+  public LongSupplier setLongSupplier(final String name, final LongSupplier supplier) {
+    return setLongSupplier(nameToId(name), supplier);
+  }
+
+  @Override
+  public LongSupplier setLongSupplier(final StatisticDescriptor descriptor, final LongSupplier supplier) {
+    return setLongSupplier(getLongId(descriptor), supplier);
+  }
+
+  @Override
+  public DoubleSupplier setDoubleSupplier(final int id, final DoubleSupplier supplier) {
+    if(id >= type.getDoubleStatCount()) {
+      throw new IllegalArgumentException("Id " + id + " is not in range for stat" + type);
+    }
+    return doubleSuppliers.put(id, supplier);
+  }
+
+  @Override
+  public DoubleSupplier setDoubleSupplier(final String name, final DoubleSupplier supplier) {
+    return setDoubleSupplier(nameToId(name), supplier);
+  }
+
+  @Override
+  public DoubleSupplier setDoubleSupplier(final StatisticDescriptor descriptor, final DoubleSupplier supplier) {
+    return setDoubleSupplier(getDoubleId(descriptor), supplier);
+  }
 
   @Override
   public int hashCode() {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsTypeImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsTypeImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsTypeImpl.java
index 2a29d46..ccd4d6c 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsTypeImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/StatisticsTypeImpl.java
@@ -192,19 +192,19 @@ public class StatisticsTypeImpl implements StatisticsType {
   /**
    * Gets the number of statistics in this type that are ints.
    */
-  public final int getIntStatCount() {
+  public int getIntStatCount() {
     return this.intStatCount;
   }
   /**
    * Gets the number of statistics in this type that are longs.
    */
-  public final int getLongStatCount() {
+  public int getLongStatCount() {
     return this.longStatCount;
   }
   /**
    * Gets the number of statistics that are doubles.
    */
-  public final int getDoubleStatCount() {
+  public int getDoubleStatCount() {
     return this.doubleStatCount;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
new file mode 100644
index 0000000..0180fba
--- /dev/null
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/CallbackSampler.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.gemstone.gemfire.CancelCriterion;
+import com.gemstone.gemfire.Statistics;
+import com.gemstone.gemfire.SystemFailure;
+import com.gemstone.gemfire.internal.StatSamplerStats;
+import com.gemstone.gemfire.internal.StatisticsImpl;
+import com.gemstone.gemfire.internal.StatisticsManager;
+import com.gemstone.gemfire.internal.logging.LogService;
+
+import org.apache.logging.log4j.Logger;
+
+public class CallbackSampler {
+  private static final Logger logger = LogService.getLogger();
+  private StatisticsManager statisticsManager;
+  private final CancelCriterion cancelCriterion;
+  private long sampleIntervalNanos;
+  private ScheduledExecutorService executor;
+  private final StatSamplerStats statSamplerStats;
+
+  public CallbackSampler( final CancelCriterion cancelCriterion,
+                         final StatSamplerStats statSamplerStats)
+  {
+    this.cancelCriterion = cancelCriterion;
+    this.statSamplerStats = statSamplerStats;
+  }
+
+  public void start(StatisticsManager statisticsManager, ThreadGroup threadGroup, int sampleInterval, TimeUnit timeUnit) {
+    ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(runnable -> {
+      Thread thread = new Thread(threadGroup, runnable, "CallbackSampler");
+      thread.setDaemon(true);
+      return thread;
+    });
+    start(executor, statisticsManager, sampleInterval, timeUnit);
+  }
+
+  void start(ScheduledExecutorService executor, StatisticsManager statisticsManager, int sampleInterval, TimeUnit timeUnit) {
+    stop();
+    this.statisticsManager = statisticsManager;
+    this.executor = executor;
+
+    executor.scheduleAtFixedRate(() -> sampleCallbacks(), sampleInterval, sampleInterval, timeUnit);
+  }
+
+  private void sampleCallbacks() {
+    if(cancelCriterion.cancelInProgress() != null) {
+      executor.shutdown();
+    }
+    int errors = 0;
+    int suppliers = 0;
+    long start = System.nanoTime();
+    try {
+      for (Statistics stats : statisticsManager.getStatsList()) {
+        StatisticsImpl statistics = (StatisticsImpl) stats;
+        errors += statistics.invokeSuppliers();
+        suppliers += statistics.getSupplierCount();
+      }
+    } catch(VirtualMachineError e) {
+      SystemFailure.initiateFailure(e);
+    } catch (Throwable throwable) {
+      logger.error("Error invoking statistic suppliers", throwable);
+    } finally {
+      long end = System.nanoTime();
+      statSamplerStats.incSampleCallbackDuration(TimeUnit.NANOSECONDS.toMillis(end - start));
+      statSamplerStats.incSampleCallbackErrors(errors);
+      statSamplerStats.setSampleCallbacks(suppliers);
+    }
+
+  }
+
+  public void stop() {
+    if(executor != null) {
+      this.executor.shutdown();
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/SampleCollector.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/SampleCollector.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/SampleCollector.java
index dfb502b..6a3b421 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/SampleCollector.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/statistics/SampleCollector.java
@@ -286,7 +286,9 @@ public class SampleCollector {
           handler.close();
         }
       }
-      instance = null;
+      if(instance == this) {
+        instance = null;
+      }
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/test/java/com/gemstone/gemfire/internal/LocalStatisticsImplJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/LocalStatisticsImplJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/LocalStatisticsImplJUnitTest.java
new file mode 100644
index 0000000..a9b1ec7
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/LocalStatisticsImplJUnitTest.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+import java.util.function.DoubleSupplier;
+import java.util.function.IntSupplier;
+import java.util.function.LongSupplier;
+
+import com.gemstone.gemfire.StatisticsType;
+import com.gemstone.gemfire.internal.LocalStatisticsImpl;
+import com.gemstone.gemfire.internal.StatisticsImpl;
+import com.gemstone.gemfire.internal.StatisticsManager;
+import com.gemstone.gemfire.internal.StatisticsTypeImpl;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.apache.commons.lang.ObjectUtils.Null;
+import org.apache.logging.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category(UnitTest.class)
+public class LocalStatisticsImplJUnitTest {
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  private StatisticsImpl stats;
+
+  @Before
+  public void createStats() {
+    final StatisticsTypeImpl type = mock(StatisticsTypeImpl.class);
+    when(type.getIntStatCount()).thenReturn(5);
+    when(type.getDoubleStatCount()).thenReturn(5);
+    when(type.getLongStatCount()).thenReturn(5);
+    final String textId = "";
+    final long numbericId = 0;
+    final long uniqueId = 0;
+    final int osStatFlags = 0;
+    final boolean atomicIncrements = false;
+    final StatisticsManager system = mock(StatisticsManager.class);
+    stats = new LocalStatisticsImpl(type, textId, numbericId, uniqueId, atomicIncrements, osStatFlags, system);
+  }
+
+  @Test
+  public void invokeIntSuppliersShouldUpdateStats() {
+    IntSupplier supplier1 = mock(IntSupplier.class);
+    when(supplier1.getAsInt()).thenReturn(23);
+    stats.setIntSupplier(4, supplier1);
+    assertEquals(0, stats.invokeSuppliers());
+
+    verify(supplier1).getAsInt();
+    assertEquals(23, stats.getInt(4));
+  }
+
+  @Test
+  public void invokeLongSuppliersShouldUpdateStats() {
+    LongSupplier supplier1 = mock(LongSupplier.class);
+    when(supplier1.getAsLong()).thenReturn(23L);
+    stats.setLongSupplier(4, supplier1);
+    assertEquals(0, stats.invokeSuppliers());
+
+    verify(supplier1).getAsLong();
+    assertEquals(23L, stats.getLong(4));
+  }
+
+  @Test
+  public void invokeDoubleSuppliersShouldUpdateStats() {
+    DoubleSupplier supplier1 = mock(DoubleSupplier.class);
+    when(supplier1.getAsDouble()).thenReturn(23.3);
+    stats.setDoubleSupplier(4, supplier1);
+    assertEquals(0, stats.invokeSuppliers());
+
+    verify(supplier1).getAsDouble();
+    assertEquals(23.3, stats.getDouble(4), 0.1f);
+  }
+
+  @Test
+  public void getSupplierCountShouldReturnCorrectCount() {
+    IntSupplier supplier1 = mock(IntSupplier.class);
+    stats.setIntSupplier(4, supplier1);
+    assertEquals(1, stats.getSupplierCount());
+  }
+
+  @Test
+  public void invokeSuppliersShouldCatchSupplierErrorsAndReturnCount() {
+    IntSupplier supplier1 = mock(IntSupplier.class);
+    when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
+    stats.setIntSupplier(4, supplier1);
+    assertEquals(1, stats.invokeSuppliers());
+
+    verify(supplier1).getAsInt();
+  }
+
+  @Test
+  public void invokeSuppliersShouldLogErrorOnlyOnce() {
+    final Logger originalLogger = StatisticsImpl.logger;
+    try {
+      final Logger logger = mock(Logger.class);
+      StatisticsImpl.logger = logger;
+      IntSupplier supplier1 = mock(IntSupplier.class);
+      when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
+      stats.setIntSupplier(4, supplier1);
+      assertEquals(1, stats.invokeSuppliers());
+      verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
+      assertEquals(1, stats.invokeSuppliers());
+      //Make sure the logger isn't invoked again
+      verify(logger, times(1)).warn(anyString(), anyString(), anyInt(), isA(NullPointerException.class));
+    } finally {
+      StatisticsImpl.logger = originalLogger;
+    }
+  }
+
+  @Test
+  public void badSupplierParamShouldThrowError() {
+    IntSupplier supplier1 = mock(IntSupplier.class);
+    when(supplier1.getAsInt()).thenReturn(23);
+    thrown.expect(IllegalArgumentException.class);
+    stats.setIntSupplier(23, supplier1);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/test/java/com/gemstone/gemfire/internal/StatArchiveWriterReaderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/StatArchiveWriterReaderJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/StatArchiveWriterReaderJUnitTest.java
index bb15ff2..ea9ff4b 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/StatArchiveWriterReaderJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/StatArchiveWriterReaderJUnitTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.mockito.Mockito.*;
 
 import java.io.BufferedInputStream;
 import java.io.File;
@@ -47,7 +48,6 @@ import com.gemstone.gemfire.i18n.LogWriterI18n;
 import com.gemstone.gemfire.internal.StatArchiveReader.StatValue;
 import com.gemstone.gemfire.internal.logging.InternalLogWriter;
 import com.gemstone.gemfire.internal.logging.PureLogWriter;
-import com.gemstone.gemfire.internal.statistics.DummyStatistics;
 import com.gemstone.gemfire.internal.statistics.ResourceInstance;
 import com.gemstone.gemfire.internal.statistics.ResourceType;
 import com.gemstone.gemfire.internal.statistics.SampleCollector;
@@ -1575,7 +1575,8 @@ public class StatArchiveWriterReaderJUnitTest {
     
     final StatisticsType statsType = createDummyStatisticsType();
     final ResourceType rt = new ResourceType(0, statsType);
-    final Statistics statistics = new ClosedStatistics();
+    final Statistics statistics = mock(Statistics.class);
+    when(statistics.isClosed()).thenReturn(true);
     final ResourceInstance ri = new ResourceInstance(0, statistics, rt);
     
     // if bug #45377 still existed, this call would throw IllegalStateException
@@ -1602,7 +1603,7 @@ public class StatArchiveWriterReaderJUnitTest {
     
     final StatisticsType statsType = createDummyStatisticsType();
     final ResourceType rt = new ResourceType(0, statsType);
-    final Statistics statistics = new DummyStatistics();
+    final Statistics statistics = mock(Statistics.class);
     final ResourceInstance ri = new ResourceInstance(0, statistics, rt);
 
     writer.sampled(TestStatArchiveWriter.WRITER_INITIAL_DATE_MILLIS + 1000,
@@ -1709,14 +1710,7 @@ public class StatArchiveWriterReaderJUnitTest {
       }
     };
   }
-  
-  private static class ClosedStatistics extends DummyStatistics {
-    @Override
-    public boolean isClosed() {
-      return true;
-    }
-  }
-  
+
   /* [KEEP] alternative method for getting an expected golden file:
   Class clazz = getClass();
   assertNotNull(clazz);

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/test/java/com/gemstone/gemfire/internal/StatSamplerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/StatSamplerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/StatSamplerJUnitTest.java
index f2946b6..e16eeaf 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/StatSamplerJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/StatSamplerJUnitTest.java
@@ -117,11 +117,20 @@ public class StatSamplerJUnitTest {
         factory.createLongCounter(  "long_counter_9",   "d9",  "u9"),
         factory.createLongCounter(  "long_counter_10",  "d10", "u10", true),
         factory.createLongGauge(    "long_gauge_11",    "d11", "u11"),
-        factory.createLongGauge(    "long_gauge_12",    "d12", "u12", false)
+        factory.createLongGauge(    "long_gauge_12",    "d12", "u12", false),
+        factory.createLongGauge(    "sampled_long",    "d13", "u13", false),
+        factory.createIntGauge(    "sampled_int",    "d14", "u14", false),
+        factory.createDoubleGauge(    "sampled_double",    "d15", "u15", false)
     };
     final StatisticsType ST1 = factory.createType("ST1", "ST1", statsST1);
     final Statistics st1_1 = factory.createAtomicStatistics(ST1, "st1_1", 1);
-    
+    st1_1.setIntSupplier("sampled_int", () -> 5);
+    getOrCreateExpectedValueMap(st1_1).put("sampled_int", 5);
+    st1_1.setLongSupplier("sampled_long", () -> 6);
+    getOrCreateExpectedValueMap(st1_1).put("sampled_long", 6);
+    st1_1.setDoubleSupplier("sampled_double", () -> 7.0);
+    getOrCreateExpectedValueMap(st1_1).put("sampled_double", 7.0);
+
     boolean done = false;
 
     Statistics[] samplerStatsInstances = factory.findStatisticsByTextId("statSampler");
@@ -319,11 +328,7 @@ public class StatSamplerJUnitTest {
   
   private void incDouble(Statistics statistics, String stat, double value) {
     assertFalse(statistics.isClosed());
-    Map<String,Number> statValues = this.allStatistics.get(statistics.getTextId());
-    if (statValues == null) {
-      statValues = new HashMap<String,Number>();
-      this.allStatistics.put(statistics.getTextId(), statValues);
-    }
+    Map<String, Number> statValues = getOrCreateExpectedValueMap(statistics);
     statistics.incDouble(stat, value);
     statValues.put(stat, statistics.getDouble(stat));
     if (this.statisticTypes.get(statistics.getTextId()) == null) {
@@ -333,11 +338,7 @@ public class StatSamplerJUnitTest {
   
   private void incInt(Statistics statistics, String stat, int value) {
     assertFalse(statistics.isClosed());
-    Map<String,Number> statValues = this.allStatistics.get(statistics.getTextId());
-    if (statValues == null) {
-      statValues = new HashMap<String,Number>();
-      this.allStatistics.put(statistics.getTextId(), statValues);
-    }
+    Map<String, Number> statValues = getOrCreateExpectedValueMap(statistics);
     statistics.incInt(stat, value);
     statValues.put(stat, statistics.getInt(stat));
     if (this.statisticTypes.get(statistics.getTextId()) == null) {
@@ -345,13 +346,18 @@ public class StatSamplerJUnitTest {
     }
   }
 
-  private void incLong(Statistics statistics, String stat, long value) {
-    assertFalse(statistics.isClosed());
+  private Map<String, Number> getOrCreateExpectedValueMap(final Statistics statistics) {
     Map<String,Number> statValues = this.allStatistics.get(statistics.getTextId());
     if (statValues == null) {
       statValues = new HashMap<String,Number>();
       this.allStatistics.put(statistics.getTextId(), statValues);
     }
+    return statValues;
+  }
+
+  private void incLong(Statistics statistics, String stat, long value) {
+    assertFalse(statistics.isClosed());
+    Map<String, Number> statValues = getOrCreateExpectedValueMap(statistics);
     statistics.incLong(stat, value);
     statValues.put(stat, statistics.getLong(stat));
     if (this.statisticTypes.get(statistics.getTextId()) == null) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/CallbackSamplerJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/CallbackSamplerJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/CallbackSamplerJUnitTest.java
new file mode 100644
index 0000000..9109ba7
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/CallbackSamplerJUnitTest.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gemstone.gemfire.internal.statistics;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.util.Arrays;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import com.gemstone.gemfire.CancelCriterion;
+import com.gemstone.gemfire.Statistics;
+import com.gemstone.gemfire.internal.StatSamplerStats;
+import com.gemstone.gemfire.internal.StatisticsImpl;
+import com.gemstone.gemfire.internal.StatisticsManager;
+import com.gemstone.gemfire.test.junit.categories.UnitTest;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.runners.MockitoJUnitRunner;
+
+@Category(UnitTest.class)
+@RunWith(MockitoJUnitRunner.class)
+public class CallbackSamplerJUnitTest {
+  @Mock
+  CancelCriterion cancelCriterion;
+  @Mock
+  StatSamplerStats statSamplerStats;
+  @Mock
+  StatisticsManager statisticsManager;
+  @Mock
+  ScheduledExecutorService executorService;
+  private CallbackSampler sampler;
+
+  @Before
+  public void createSampler() {
+    sampler = new CallbackSampler(cancelCriterion, statSamplerStats);
+  }
+
+  @Test
+  public void taskShouldSampleStatistics() {
+    Runnable sampleTask = invokeStartAndGetTask();
+
+    StatisticsImpl stats1 = mock(StatisticsImpl.class);
+    StatisticsImpl stats2 = mock(StatisticsImpl.class);
+    when(stats1.invokeSuppliers()).thenReturn(3);
+    when(stats2.invokeSuppliers()).thenReturn(2);
+    when(stats1.getSupplierCount()).thenReturn(7);
+    when(stats2.getSupplierCount()).thenReturn(8);
+    when(statisticsManager.getStatsList()).thenReturn(Arrays.asList(stats1, stats2));
+    sampleTask.run();
+    verify(statSamplerStats).setSampleCallbacks(eq(15));
+    verify(statSamplerStats).incSampleCallbackErrors(5);
+    verify(statSamplerStats).incSampleCallbackDuration(anyLong());
+  }
+
+  @Test
+  public void stopShouldStopExecutor() {
+    sampler.start(executorService, statisticsManager, 1, TimeUnit.MILLISECONDS);
+    sampler.stop();
+    verify(executorService).shutdown();
+  }
+
+  @Test
+  public void cancelCriterionShouldStopExecutor() {
+    Runnable sampleTask = invokeStartAndGetTask();
+    when(cancelCriterion.cancelInProgress()).thenReturn("cancelled");
+    sampleTask.run();
+    verify(executorService).shutdown();
+  }
+
+  private Runnable invokeStartAndGetTask() {
+    sampler.start(executorService, statisticsManager, 1, TimeUnit.MILLISECONDS);
+    ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
+    verify(executorService).scheduleAtFixedRate(runnableCaptor.capture(), eq(1L), eq(1L), eq(TimeUnit.MILLISECONDS));
+    return runnableCaptor.getValue();
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/01848b6e/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/DummyStatistics.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/DummyStatistics.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/DummyStatistics.java
deleted file mode 100755
index a1ea030..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/statistics/DummyStatistics.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.internal.statistics;
-
-import com.gemstone.gemfire.StatisticDescriptor;
-import com.gemstone.gemfire.Statistics;
-import com.gemstone.gemfire.StatisticsType;
-
-/**
- * @since GemFire 7.0
- */
-public class DummyStatistics implements Statistics {
-
-  @Override
-  public void close() {
-  }
-
-  @Override
-  public int nameToId(String name) {
-    return 0;
-  }
-  
-  @Override
-  public StatisticDescriptor nameToDescriptor(String name) {
-    return null;
-  }
-  
-  @Override
-  public long getUniqueId() {
-    return 0;
-  }
-
-  @Override
-  public StatisticsType getType() {
-    return null;
-  }
-
-  @Override
-  public String getTextId() {
-    return null;
-  }
-
-  @Override
-  public long getNumericId() {
-    return 0;
-  }
-
-  @Override
-  public boolean isAtomic() {
-    return false;
-  }
-
-  @Override
-  public boolean isClosed() {
-    return false;
-  }
-
-  @Override
-  public void setInt(int id, int value) {
-  }
-
-  @Override
-  public void setInt(String name, int value) {
-  }
-
-  @Override
-  public void setInt(StatisticDescriptor descriptor, int value) {
-  }
-
-  @Override
-  public void setLong(int id, long value) {
-  }
-
-  @Override
-  public void setLong(StatisticDescriptor descriptor, long value) {
-  }
-
-  @Override
-  public void setLong(String name, long value) {
-  }
-
-  @Override
-  public void setDouble(int id, double value) {
-  }
-
-  @Override
-  public void setDouble(StatisticDescriptor descriptor, double value) {
-  }
-
-  @Override
-  public void setDouble(String name, double value) {
-  }
-
-  @Override
-  public int getInt(int id) {
-    return 0;
-  }
-
-  @Override
-  public int getInt(StatisticDescriptor descriptor) {
-    return 0;
-  }
-
-  @Override
-  public int getInt(String name) {
-    return 0;
-  }
-
-  @Override
-  public long getLong(int id) {
-    return 0;
-  }
-
-  @Override
-  public long getLong(StatisticDescriptor descriptor) {
-    return 0;
-  }
-
-  @Override
-  public long getLong(String name) {
-    return 0;
-  }
-
-  @Override
-  public double getDouble(int id) {
-    return 0;
-  }
-
-  @Override
-  public double getDouble(StatisticDescriptor descriptor) {
-    return 0;
-  }
-
-  @Override
-  public double getDouble(String name) {
-    return 0;
-  }
-
-  @Override
-  public Number get(StatisticDescriptor descriptor) {
-    return null;
-  }
-
-  @Override
-  public Number get(String name) {
-    return null;
-  }
-
-  @Override
-  public long getRawBits(StatisticDescriptor descriptor) {
-    return 0;
-  }
-
-  @Override
-  public long getRawBits(String name) {
-    return 0;
-  }
-
-  @Override
-  public void incInt(int id, int delta) {
-  }
-
-  @Override
-  public void incInt(StatisticDescriptor descriptor, int delta) {
-  }
-
-  @Override
-  public void incInt(String name, int delta) {
-  }
-
-  @Override
-  public void incLong(int id, long delta) {
-  }
-
-  @Override
-  public void incLong(StatisticDescriptor descriptor, long delta) {
-  }
-
-  @Override
-  public void incLong(String name, long delta) {
-  }
-
-  @Override
-  public void incDouble(int id, double delta) {
-  }
-
-  @Override
-  public void incDouble(StatisticDescriptor descriptor, double delta) {
-  }
-
-  @Override
-  public void incDouble(String name, double delta) {
-  }
-}


[16/23] incubator-geode git commit: GEODE-1421: improve test to provide more info on failure

Posted by kl...@apache.org.
GEODE-1421: improve test to provide more info on failure

I ran the test 1000 times and they all passed.
Assertions are now done on the member that does
the get that should have also stored the entry
in the cache.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/cdfb9401
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/cdfb9401
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/cdfb9401

Branch: refs/heads/feature/GEODE-835
Commit: cdfb9401cff5b86ebcf8fb424bb36139bba36a91
Parents: 0d5de3e
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jun 14 16:39:10 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jun 14 16:41:19 2016 -0700

----------------------------------------------------------------------
 .../gemfire/cache/management/MemoryThresholdsDUnitTest.java    | 6 ++++++
 1 file changed, 6 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/cdfb9401/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsDUnitTest.java
index a91c8f5..baad698 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/cache/management/MemoryThresholdsDUnitTest.java
@@ -1993,6 +1993,8 @@ public class MemoryThresholdsDUnitTest extends ClientServerTestCase {
         {
           Integer k = new Integer(4);
           assertEquals(k.toString(), r.get(k, new Integer(expectedInvocations++)));
+          assertFalse(hmm.getState().isCritical());
+          assertTrue(r.containsKey(k));
         }
         
         // Place in a critical state for the next test
@@ -2004,6 +2006,8 @@ public class MemoryThresholdsDUnitTest extends ClientServerTestCase {
         {
           Integer k = new Integer(5);
           assertEquals(k.toString(), r.get(k, new Integer(expectedInvocations++)));
+          assertTrue(hmm.getState().isCritical());
+          assertFalse(r.containsKey(k));
         }
 
         newfakeHeapUsage = Math.round(fakeHeapMaxSize * (criticalHeapThresh - 0.3f));  // below critical by 30%
@@ -2015,6 +2019,8 @@ public class MemoryThresholdsDUnitTest extends ClientServerTestCase {
         {
           Integer k = new Integer(6);
           assertEquals(k.toString(), r.get(k, new Integer(expectedInvocations++)));
+          assertFalse(hmm.getState().isCritical());
+          assertTrue(r.containsKey(k));
         }
         return new Integer(expectedInvocations);
       }


[09/23] incubator-geode git commit: GEODE-1514: remove RolePerformanceDUnitTest

Posted by kl...@apache.org.
GEODE-1514: remove RolePerformanceDUnitTest

Flaky performance test of deprecated feature


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e84e8855
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e84e8855
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e84e8855

Branch: refs/heads/feature/GEODE-835
Commit: e84e8855baaf2fbf5756644e7a3b94a28c9dffa1
Parents: de647cd
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Tue Jun 14 10:03:51 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Tue Jun 14 10:03:51 2016 -0700

----------------------------------------------------------------------
 .../cache30/RolePerformanceDUnitTest.java       | 192 -------------------
 1 file changed, 192 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e84e8855/geode-core/src/test/java/com/gemstone/gemfire/cache30/RolePerformanceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RolePerformanceDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/cache30/RolePerformanceDUnitTest.java
deleted file mode 100644
index 8a82cbe..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/cache30/RolePerformanceDUnitTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gemstone.gemfire.cache30;
-
-import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.util.Properties;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.AttributesFactory;
-import com.gemstone.gemfire.cache.CacheException;
-import com.gemstone.gemfire.cache.DataPolicy;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionAttributes;
-import com.gemstone.gemfire.cache.Scope;
-import com.gemstone.gemfire.test.dunit.Host;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
-import com.gemstone.gemfire.test.dunit.SerializableRunnable;
-import com.gemstone.gemfire.test.dunit.cache.internal.JUnit4CacheTestCase;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-
-/**
- * Tests the performance of Regions when Roles are assigned.
- *
- * @since GemFire 5.0
- */
-@Category(DistributedTest.class)
-public class RolePerformanceDUnitTest extends JUnit4CacheTestCase {
-
-  /**
-   * Compares times required for series of puts with Roles assigned to
-   * series of puts with no Roles assigned. Scope is D_ACK.
-   * <p>
-   * Up to 10 attempts will be made before failing.
-   */
-  @Test
-  public void testRolePerformance() {
-    int maxAttempts = 10;
-    for (int i = 1; i <= maxAttempts; i++) {
-      try {
-        if (i > 1) {
-          // clean up from previous run
-          closeCaches();
-        }
-        doTestRolePerformance();
-        break;
-      }
-      // only catch assertion failures...
-      catch (AssertionError e) {
-        if (i == maxAttempts) {
-          throw e;
-        }
-        else {
-          LogWriterUtils.getLogWriter().info("testRolePerformance attempt #" + i + 
-            " failed -- reattempting up to 10x", e);
-        }
-      }
-    }
-  }
-  
-  /**
-   * Implementation of testRolePerformance.
-   */
-  private void doTestRolePerformance() {
-    final String name = this.getUniqueName();
-
-    // throw away this run
-    createConnections(name, false);
-    createRegions(name);
-    executeOperations(name);
-    
-    closeCaches();
-    
-    // first time with no roles
-    createConnections(name, false);
-    createRegions(name);
-    long millisNoRoles = executeOperations(name);
-    
-    closeCaches();
-    
-    // second time with roles
-    createConnections(name, true);
-    createRegions(name);
-    long millisWithRoles = executeOperations(name);
-    
-    long deviation = (long)(millisNoRoles * 0.05); // 5% increase is allowed
-    long ceiling = millisNoRoles + deviation;
-
-    String data = name + " results: millisNoRoles=" + millisNoRoles +
-      ", millisWithRoles=" + millisWithRoles + ", deviation=" + deviation + 
-      ", ceiling=" + ceiling;
-    LogWriterUtils.getLogWriter().info(data);
-    
-    assertTrue("millisWithRoles is greater than allowable deviation: " + data,
-               millisWithRoles <= ceiling);
-  }
-  
-  /**
-   * Create connection to distributed system in all vms and assign one role
-   * to each if assignRoles is true.
-   */
-  private void createConnections(final String name, final boolean assignRoles) {
-    final String[][] vmRoles = new String[][] 
-      {{name+"-A"},{name+"-B"},{name+"-C"},{name+"-D"}};
-    for (int i = 0; i < vmRoles.length; i++) {
-      final int vm = i;
-      Host.getHost(0).getVM(vm).invoke(new SerializableRunnable("Connect") {
-        public void run() {
-          Properties config = new Properties();
-          if (assignRoles) {
-            config.setProperty(ROLES, vmRoles[vm][0]);
-          }
-          getSystem(config);
-        }
-      });
-    }
-  }
-  
-  /**
-   * Close the cache in all vms.
-   */
-  private void closeCaches() { 
-    for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
-      final int vm = i;
-      Host.getHost(0).getVM(vm).invoke(new CacheSerializableRunnable("Close Cache") {
-        public void run2() throws CacheException {
-          closeCache();
-        }
-      });
-    }
-  }
-  
-  /**
-   * Create the named root region in all vms.
-   */
-  private void createRegions(final String name) {
-    for (int i = 0; i < Host.getHost(0).getVMCount(); i++) {
-      final int vm = i;
-      Host.getHost(0).getVM(vm).invoke(new CacheSerializableRunnable("Create Region") {
-        public void run2() throws CacheException {
-          AttributesFactory fac = new AttributesFactory();
-          fac.setScope(Scope.DISTRIBUTED_ACK);
-          fac.setDataPolicy(DataPolicy.REPLICATE);
-          RegionAttributes attr = fac.create();
-          createRootRegion(name, attr);
-        }
-      });
-    }
-  }
-  
-  /**
-   * Execute operations on the named region in one vm.
-   */
-  private long executeOperations(final String name) {
-    Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("Operations") {
-      public void run2() throws CacheException {
-        Region region = getRootRegion(name);
-        long begin = System.currentTimeMillis();
-        for (int i = 0; i < 1000; i++) {
-          region.put("KEY-"+i, "VAL-"+i);
-        }
-        long finish = System.currentTimeMillis();
-        timing = finish - begin;
-      }
-    });
-    Long timing = (Long) Host.getHost(0).getVM(0).invoke(() -> RolePerformanceDUnitTest.getTiming());
-    return timing.longValue();
-  }
-  protected static transient long timing = -1;
-  private static Long getTiming() {
-    return new Long(timing);
-  }
-  
-}
-


[14/23] incubator-geode git commit: GEODE-1545: add a test case for querying JSON in geode-lucene

Posted by kl...@apache.org.
GEODE-1545: add a test case for querying JSON in geode-lucene


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/ed32ceef
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/ed32ceef
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/ed32ceef

Branch: refs/heads/feature/GEODE-835
Commit: ed32ceefba89b5cd295659faa3368971ee4adabb
Parents: d5dae19
Author: zhouxh <gz...@pivotal.io>
Authored: Tue Jun 14 15:10:53 2016 -0700
Committer: zhouxh <gz...@pivotal.io>
Committed: Tue Jun 14 15:14:39 2016 -0700

----------------------------------------------------------------------
 .../lucene/LuceneQueriesIntegrationTest.java    | 68 ++++++++++++++++++++
 .../cache/lucene/test/LuceneTestUtilities.java  | 27 ++++++++
 .../gemfire/cache/lucene/test/TestObject.java   |  7 ++
 3 files changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ed32ceef/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
index 536f5c3..95f5781 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/LuceneQueriesIntegrationTest.java
@@ -42,6 +42,8 @@ import com.gemstone.gemfire.cache.RegionShortcut;
 import com.gemstone.gemfire.cache.execute.FunctionException;
 import com.gemstone.gemfire.cache.lucene.test.TestObject;
 import com.gemstone.gemfire.cache.query.QueryException;
+import com.gemstone.gemfire.pdx.JSONFormatter;
+import com.gemstone.gemfire.pdx.PdxInstance;
 import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
 
 /**
@@ -96,6 +98,12 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     // query will be--field1:one field1:three
     verifyQuery("field1:one@three", DEFAULT_FIELD, "A", "B", "C");
     
+    HashMap expectedResults = new HashMap();
+    expectedResults.put("A", new TestObject(value1, value1));
+    expectedResults.put("B", new TestObject(value2, value2));
+    expectedResults.put("C", new TestObject(value3, value3));
+    verifyQuery("field1:one@three", expectedResults);
+    
     // keyword analyzer, this query will only match the entry that exactly matches
     // this query string will be parsed as "one three"
     // but keyword analyzer will parse one@three to be "one three"
@@ -155,6 +163,29 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
   }
 
   @Test()
+  public void queryJsonObject() throws ParseException {
+    Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
+    fields.put("name", null);
+    fields.put("lastName", null);
+    fields.put("address", null);
+    luceneService.createIndex(INDEX_NAME, REGION_NAME, fields);
+    Region region = cache.createRegionFactory(RegionShortcut.PARTITION)
+      .create(REGION_NAME);
+    final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
+
+    //Put two values with some of the same tokens
+    PdxInstance pdx1 = insertAJson(region, "jsondoc1");
+    PdxInstance pdx2 = insertAJson(region, "jsondoc2");
+    PdxInstance pdx10 = insertAJson(region, "jsondoc10");
+    index.waitUntilFlushed(60000);
+
+    HashMap expectedResults = new HashMap();
+    expectedResults.put("jsondoc1", pdx1);
+    expectedResults.put("jsondoc10", pdx10);
+    verifyQuery("name:jsondoc1*", expectedResults);
+  }
+
+  @Test()
   public void throwFunctionExceptionWhenGivenBadQuery() {
     LuceneService luceneService = LuceneServiceProvider.get(cache);
     luceneService.createIndex(INDEX_NAME, REGION_NAME, "text");
@@ -178,6 +209,36 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
     }
 
   }
+  
+  private PdxInstance insertAJson(Region region, String key) {
+    String jsonCustomer = "{"
+        + "\"name\": \""+key+"\","
+        + "\"lastName\": \"Smith\","
+        + " \"age\": 25,"
+        + "\"address\":"
+        + "{"
+        + "\"streetAddress\": \"21 2nd Street\","
+        + "\"city\": \"New York\","
+        + "\"state\": \"NY\","
+        + "\"postalCode\": \"10021\""
+        + "},"
+        + "\"phoneNumber\":"
+        + "["
+        + "{"
+        + " \"type\": \"home\","
+        + "\"number\": \"212 555-1234\""
+        + "},"
+        + "{"
+        + " \"type\": \"fax\","
+        + "\"number\": \"646 555-4567\""
+        + "}"
+        + "]"
+        + "}";
+
+    PdxInstance pdx = JSONFormatter.fromJSON(jsonCustomer);
+    region.put(key, pdx);
+    return pdx;
+  }
 
   private void verifyQuery(String query, String defaultField, String ... expectedKeys) throws ParseException {
     final LuceneQuery<String, Object> queryWithStandardAnalyzer = luceneService.createLuceneQueryFactory().create(
@@ -185,6 +246,13 @@ public class LuceneQueriesIntegrationTest extends LuceneIntegrationTest {
 
     verifyQueryKeys(queryWithStandardAnalyzer, expectedKeys);
   }
+  
+  private void verifyQuery(String query, HashMap expectedResults) throws ParseException {
+    final LuceneQuery<String, Object> queryWithStandardAnalyzer = luceneService.createLuceneQueryFactory().create(
+      INDEX_NAME, REGION_NAME, query);
+
+    verifyQueryKeyAndValues(queryWithStandardAnalyzer, expectedResults);
+  }
 
   private static class MyCharacterTokenizer extends CharTokenizer {
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ed32ceef/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
index 6ef93bf..d7150d9 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/LuceneTestUtilities.java
@@ -21,10 +21,12 @@ package com.gemstone.gemfire.cache.lucene.test;
 import static org.junit.Assert.*;
 
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Set;
 import java.util.function.Consumer;
 import java.util.stream.Collectors;
+import org.apache.logging.log4j.Logger;
 
 import com.gemstone.gemfire.cache.Cache;
 import com.gemstone.gemfire.cache.asyncqueue.AsyncEventQueue;
@@ -38,6 +40,9 @@ import com.gemstone.gemfire.cache.lucene.LuceneServiceProvider;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneIndexForPartitionedRegion;
 import com.gemstone.gemfire.cache.lucene.internal.LuceneServiceImpl;
 import com.gemstone.gemfire.internal.cache.LocalRegion;
+import com.gemstone.gemfire.internal.logging.LogService;
+import com.gemstone.gemfire.pdx.JSONFormatter;
+import com.gemstone.gemfire.pdx.PdxInstance;
 
 public class LuceneTestUtilities {
   public static final String INDEX_NAME = "index";
@@ -96,6 +101,28 @@ public class LuceneTestUtilities {
     assertEquals(expectedKeySet, actualKeySet);
   }
 
+  /**
+   * Verify that a query returns the expected map of key-value. Ordering is ignored.
+   */
+  public static <K> void verifyQueryKeyAndValues(LuceneQuery<K,Object> query, HashMap expectedResults) {
+    HashMap actualResults = new HashMap<>();
+    final LuceneQueryResults<K, Object> results = query.search();
+    while(results.hasNextPage()) {
+      results.getNextPage().stream()
+        .forEach(struct -> {
+          Object value = struct.getValue();
+          if (value instanceof PdxInstance) {
+            PdxInstance pdx = (PdxInstance)value;
+            String jsonString = JSONFormatter.toJSON(pdx);
+            actualResults.put(struct.getKey(), pdx);
+          } else {
+            actualResults.put(struct.getKey(), value);
+          }
+        });
+    }
+    assertEquals(expectedResults, actualResults);
+  }
+  
   public static void pauseSender(final Cache cache) {
     final AsyncEventQueueImpl queue = (AsyncEventQueueImpl) getIndexQueue(cache);
     queue.getSender().pause();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/ed32ceef/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/TestObject.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/TestObject.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/TestObject.java
index a2b249e..9e984bd 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/TestObject.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/test/TestObject.java
@@ -49,4 +49,11 @@ public class TestObject implements Serializable {
   public void setField2(final String field2) {
     this.field2 = field2;
   }
+  
+  @Override
+  public boolean equals(Object obj) {
+    TestObject testObject = (TestObject)obj;
+    return (testObject.field1.equals(field1) && testObject.field2.equals(field2));
+  }
+
 }


[08/23] incubator-geode git commit: GEODE-1540: fix testAsyncStats

Posted by kl...@apache.org.
GEODE-1540: fix testAsyncStats

Test now uses awaitility and if a stat never does get to the expected
value will now fail with an assertion that shows the actual and expected
value of the stat.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/de647cd7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/de647cd7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/de647cd7

Branch: refs/heads/feature/GEODE-835
Commit: de647cd7f9bce152481b397ea242d9ff8626c4b4
Parents: 6f70cd7
Author: Darrel Schneider <ds...@pivotal.io>
Authored: Mon Jun 13 17:48:56 2016 -0700
Committer: Darrel Schneider <ds...@pivotal.io>
Committed: Mon Jun 13 17:50:10 2016 -0700

----------------------------------------------------------------------
 .../gemfire/internal/cache/OplogJUnitTest.java  | 51 +++++---------------
 1 file changed, 13 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/de647cd7/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java
index b283ec3..d8ef40c 100755
--- a/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/internal/cache/OplogJUnitTest.java
@@ -2641,51 +2641,26 @@ public class OplogJUnitTest extends DiskRegionTestingBase {
     region = DiskRegionHelperFactory.getAsyncOverFlowAndPersistRegion(cache,
         diskProps);
     final DiskStoreStats dss = ((LocalRegion)region).getDiskRegion().getDiskStore().getStats();
-    WaitCriterion evFull = new WaitCriterion() {
-      public boolean done() {
-        return dss.getQueueSize() == 100;
-      }
-      public String description() {
-        return null;
-      }
-    };
-    WaitCriterion ev = new WaitCriterion() {
-      public boolean done() {
-        return dss.getQueueSize() == 0;
-      }
-      public String description() {
-        return null;
-      }
-    };
-    WaitCriterion ev2 = new WaitCriterion() {
-      public boolean done() {
-        return dss.getFlushes() == 100;
-      }
-      public String description() {
-        return null;
-      }
-    };
-    WaitCriterion ev3 = new WaitCriterion() {
-      public boolean done() {
-        return dss.getFlushes() == 200;
-      }
-      public String description() {
-        return null;
-      }
-    };
 
     assertEquals(0, dss.getQueueSize());
     put100Int();
-    Wait.waitForCriterion(evFull, 2 * 1000, 200, true);
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(100, dss.getQueueSize()));
+
     assertEquals(0, dss.getFlushes());
     region.writeToDisk();
-    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
-    Wait.waitForCriterion(ev2, 1000, 200, true);
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(0, dss.getQueueSize()));
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(100, dss.getFlushes()));
     put100Int();
-    Wait.waitForCriterion(evFull, 2 * 1000, 200, true);
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(100, dss.getQueueSize()));
     region.writeToDisk();
-    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
-    Wait.waitForCriterion(ev3, 1000, 200, true);
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(0, dss.getQueueSize()));
+    Awaitility.await().pollInterval(10, TimeUnit.MILLISECONDS).pollDelay(10, TimeUnit.MILLISECONDS).timeout(10, TimeUnit.SECONDS)
+    .until(() -> assertEquals(200, dss.getFlushes()));
     closeDown();
   }
 


[12/23] incubator-geode git commit: GEODE-11: Change from MultiFieldQueryParser to StandardQueryParser

Posted by kl...@apache.org.
GEODE-11: Change from MultiFieldQueryParser to StandardQueryParser


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/79cba4dc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/79cba4dc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/79cba4dc

Branch: refs/heads/feature/GEODE-835
Commit: 79cba4dcb7c28256fa17569956c8143f58388b65
Parents: 33ceb37
Author: Jason Huynh <hu...@gmail.com>
Authored: Fri Jun 3 15:14:20 2016 -0700
Committer: Jason Huynh <hu...@gmail.com>
Committed: Tue Jun 14 14:55:41 2016 -0700

----------------------------------------------------------------------
 .../lucene/internal/StringQueryProvider.java    | 20 ++++++++++----------
 .../internal/StringQueryProviderJUnitTest.java  |  8 --------
 2 files changed, 10 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/79cba4dc/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
index 62cb65c..2ccd58d 100644
--- a/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
+++ b/geode-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProvider.java
@@ -24,9 +24,8 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.logging.log4j.Logger;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.queryparser.classic.MultiFieldQueryParser;
-import org.apache.lucene.queryparser.classic.ParseException;
+import org.apache.lucene.queryparser.flexible.core.QueryNodeException;
+import org.apache.lucene.queryparser.flexible.standard.StandardQueryParser;
 import org.apache.lucene.search.Query;
 
 import com.gemstone.gemfire.DataSerializer;
@@ -38,10 +37,11 @@ import com.gemstone.gemfire.internal.Version;
 import com.gemstone.gemfire.internal.logging.LogService;
 
 /**
- * Constructs a Lucene Query object by parsing a search string. The class uses {@link MultiFieldQueryParser}. It sets
+ * Constructs a Lucene Query object by parsing a search string. The class uses {@link StandardQueryParser}. It sets
  * searchable fields in a {@link LuceneIndex} as default fields.
  */
 public class StringQueryProvider implements LuceneQueryProvider, DataSerializableFixedID {
+
   private static final long serialVersionUID = 1L;
 
   private static final Logger logger = LogService.getLogger();
@@ -65,15 +65,15 @@ public class StringQueryProvider implements LuceneQueryProvider, DataSerializabl
     if (luceneQuery == null) {
       String[] fields = index.getFieldNames();
 
-      LuceneIndexImpl indexImpl = (LuceneIndexImpl)index;
-      MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, indexImpl.getAnalyzer());
+      LuceneIndexImpl indexImpl = (LuceneIndexImpl) index;
+      StandardQueryParser parser = new StandardQueryParser(indexImpl.getAnalyzer());
       try {
-        luceneQuery = parser.parse(query);
+        luceneQuery = parser.parse(query, fields[0]);
         if (logger.isDebugEnabled()) {
-          logger.debug("User query "+query+" is parsed to be: "+luceneQuery);
+          logger.debug("User query " + query + " is parsed to be: " + luceneQuery);
         }
-      } catch (ParseException e) {
-        logger.debug("Malformed lucene query: " + query, e);
+      } catch (QueryNodeException e) {
+        logger.debug("Query node exception:" + query, e);
         throw new QueryException(e);
       }
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/79cba4dc/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
index cfd8c32..da6715a 100644
--- a/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
+++ b/geode-lucene/src/test/java/com/gemstone/gemfire/cache/lucene/internal/StringQueryProviderJUnitTest.java
@@ -60,14 +60,6 @@ public class StringQueryProviderJUnitTest {
   }
 
   @Test
-  public void usesSearchableFieldsAsDefaults() throws QueryException {
-    StringQueryProvider provider = new StringQueryProvider("findThis");
-    Query query = provider.getQuery(mockIndex);
-    Assert.assertNotNull(query);
-    assertEquals("field-1:findthis field-2:findthis", query.toString());
-  }
-
-  @Test
   @Ignore("Custom analyzer not yet supported, this is a duplicate test right now")
   public void usesCustomAnalyzer() throws QueryException {
     StringQueryProvider provider = new StringQueryProvider("findThis");


[02/23] incubator-geode git commit: GEODE-1494: Changing stats list to be a CopyOnWriteArrayList

Posted by kl...@apache.org.
GEODE-1494: Changing stats list to be a CopyOnWriteArrayList

The statsList used to track Statistics in InternalDistributedSystem was
managed under a lock. That was problematic, because code that iterates
on the list needs to hold the lock. If the code invoking callbacks for
GEODE-1494 was slow, that means the lock would block other stats
operations.

Changing this list to a copy on write array list to holding a lock for a
long period of time.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/e9ffdce4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/e9ffdce4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/e9ffdce4

Branch: refs/heads/feature/GEODE-835
Commit: e9ffdce4fdf4f5c3b9f4ae45e19168e3de55ebe9
Parents: 5e0050d
Author: Dan Smith <up...@apache.org>
Authored: Tue Jun 7 11:44:24 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Jun 13 10:38:36 2016 -0700

----------------------------------------------------------------------
 .../internal/InternalDistributedSystem.java     | 36 ++++-------
 .../internal/AbstractStatisticsFactory.java     | 65 ++++++++------------
 .../gemfire/internal/GemFireStatSampler.java    | 14 ++---
 .../gemfire/internal/HostStatSampler.java       | 10 ++-
 .../cache/control/HeapMemoryMonitor.java        | 20 +++---
 5 files changed, 59 insertions(+), 86 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e9ffdce4/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
index 67f5478..a672127 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/InternalDistributedSystem.java
@@ -1668,7 +1668,7 @@ public class InternalDistributedSystem
     return sb.toString().trim();
   }
 
-  private final ArrayList<Statistics> statsList = new ArrayList<Statistics>();
+  private final CopyOnWriteArrayList<Statistics> statsList = new CopyOnWriteArrayList<Statistics>();
   private int statsListModCount = 0;
   private long statsListUniqueId = 1;
   private final Object statsListUniqueIdLock = new Object();
@@ -1698,11 +1698,9 @@ public class InternalDistributedSystem
   @Override
   public final Statistics findStatistics(long id) {
     List<Statistics> statsList = this.statsList;
-    synchronized (statsList) {
-      for (Statistics s : statsList) {
-        if (s.getUniqueId() == id) {
-          return s;
-        }
+    for (Statistics s : statsList) {
+      if (s.getUniqueId() == id) {
+        return s;
       }
     }
     throw new RuntimeException(LocalizedStrings.PureStatSampler_COULD_NOT_FIND_STATISTICS_INSTANCE.toLocalizedString());
@@ -1711,11 +1709,9 @@ public class InternalDistributedSystem
   @Override
   public final boolean statisticsExists(long id) {
     List<Statistics> statsList = this.statsList;
-    synchronized (statsList) {
-      for (Statistics s : statsList) {
-        if (s.getUniqueId() == id) {
-          return true;
-        }
+    for (Statistics s : statsList) {
+      if (s.getUniqueId() == id) {
+        return true;
       }
     }
     return false;
@@ -1724,9 +1720,7 @@ public class InternalDistributedSystem
   @Override
   public final Statistics[] getStatistics() {
     List<Statistics> statsList = this.statsList;
-    synchronized (statsList) {
-      return (Statistics[])statsList.toArray(new Statistics[statsList.size()]);
-    }
+    return (Statistics[])statsList.toArray(new Statistics[statsList.size()]);
   }
   
   // StatisticsFactory methods
@@ -1786,10 +1780,8 @@ public class InternalDistributedSystem
    * This method was added to fix bug 40358
    */
   public void visitStatistics(StatisticsVisitor visitor) {
-    synchronized (this.statsList) {
-      for (Statistics s: this.statsList) {
-        visitor.visit(s);
-      }
+    for (Statistics s: this.statsList) {
+      visitor.visit(s);
     }
   }
 
@@ -1844,11 +1836,9 @@ public class InternalDistributedSystem
     return (Statistics[])hits.toArray(result);
   }
   public Statistics findStatisticsByUniqueId(final long uniqueId) {
-    synchronized (this.statsList) {
-      for (Statistics s: this.statsList) {
-        if (uniqueId == s.getUniqueId()) {
-          return s;
-        }
+    for (Statistics s: this.statsList) {
+      if (uniqueId == s.getUniqueId()) {
+        return s;
       }
     }
     return null;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e9ffdce4/geode-core/src/main/java/com/gemstone/gemfire/internal/AbstractStatisticsFactory.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/AbstractStatisticsFactory.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/AbstractStatisticsFactory.java
index 886258b..972e670 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/AbstractStatisticsFactory.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/AbstractStatisticsFactory.java
@@ -28,6 +28,7 @@ import java.io.Reader;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 
 /**
  * An abstract standalone implementation of {@link StatisticsFactory}.
@@ -41,7 +42,7 @@ public abstract class AbstractStatisticsFactory
 
   private final long id;
   private final String name;
-  private final List<Statistics> statsList;
+  private final CopyOnWriteArrayList<Statistics> statsList;
   private int statsListModCount = 0;
   private long statsListUniqueId = 1;
   private final Object statsListUniqueIdLock;
@@ -53,7 +54,7 @@ public abstract class AbstractStatisticsFactory
     this.name = name;
     this.startTime = startTime;
     
-    this.statsList = new ArrayList<Statistics>();
+    this.statsList = new CopyOnWriteArrayList<Statistics>();
     this.statsListUniqueIdLock = new Object();
     this.tf = StatisticsTypeFactoryImpl.singleton();
   }
@@ -112,11 +113,9 @@ public abstract class AbstractStatisticsFactory
   @Override
   public final boolean statisticsExists(long id) {
     List<Statistics> statsList = this.statsList;
-    synchronized (statsList) {
-      for (Statistics s : statsList) {
-        if (s.getUniqueId() == id) {
-          return true;
-        }
+    for (Statistics s : statsList) {
+      if (s.getUniqueId() == id) {
+        return true;
       }
     }
     return false;
@@ -125,9 +124,7 @@ public abstract class AbstractStatisticsFactory
   @Override
   public final Statistics[] getStatistics() {
     List<Statistics> statsList = this.statsList;
-    synchronized (statsList) {
-      return (Statistics[])statsList.toArray(new Statistics[statsList.size()]);
-    }
+    return (Statistics[])statsList.toArray(new Statistics[statsList.size()]);
   }
   
   // StatisticsFactory methods
@@ -163,13 +160,11 @@ public abstract class AbstractStatisticsFactory
   @Override
   public final Statistics[] findStatisticsByType(StatisticsType type) {
     List<Statistics> hits = new ArrayList<Statistics>();
-    synchronized (statsList) {
-      Iterator<Statistics> it = statsList.iterator();
-      while (it.hasNext()) {
-        Statistics s = (Statistics)it.next();
-        if (type == s.getType()) {
-          hits.add(s);
-        }
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (type == s.getType()) {
+        hits.add(s);
       }
     }
     Statistics[] result = new Statistics[hits.size()];
@@ -179,13 +174,11 @@ public abstract class AbstractStatisticsFactory
   @Override
   public final Statistics[] findStatisticsByTextId(String textId) {
     List<Statistics> hits = new ArrayList<Statistics>();
-    synchronized (statsList) {
-      Iterator<Statistics> it = statsList.iterator();
-      while (it.hasNext()) {
-        Statistics s = (Statistics)it.next();
-        if (s.getTextId().equals(textId)) {
-          hits.add(s);
-        }
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (s.getTextId().equals(textId)) {
+        hits.add(s);
       }
     }
     Statistics[] result = new Statistics[hits.size()];
@@ -195,13 +188,11 @@ public abstract class AbstractStatisticsFactory
   @Override
   public final Statistics[] findStatisticsByNumericId(long numericId) {
     List<Statistics> hits = new ArrayList<Statistics>();
-    synchronized (statsList) {
-      Iterator<Statistics> it = statsList.iterator();
-      while (it.hasNext()) {
-        Statistics s = (Statistics)it.next();
-        if (numericId == s.getNumericId()) {
-          hits.add(s);
-        }
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (numericId == s.getNumericId()) {
+        hits.add(s);
       }
     }
     Statistics[] result = new Statistics[hits.size()];
@@ -209,13 +200,11 @@ public abstract class AbstractStatisticsFactory
   }
   
   public final Statistics findStatisticsByUniqueId(long uniqueId) {
-    synchronized (statsList) {
-      Iterator<Statistics> it = statsList.iterator();
-      while (it.hasNext()) {
-        Statistics s = (Statistics)it.next();
-        if (uniqueId == s.getUniqueId()) {
-          return s;
-        }
+    Iterator<Statistics> it = statsList.iterator();
+    while (it.hasNext()) {
+      Statistics s = (Statistics)it.next();
+      if (uniqueId == s.getUniqueId()) {
+        return s;
       }
     }
     return null;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e9ffdce4/geode-core/src/main/java/com/gemstone/gemfire/internal/GemFireStatSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/GemFireStatSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/GemFireStatSampler.java
index 5930506..1eb35d0 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/GemFireStatSampler.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/GemFireStatSampler.java
@@ -276,14 +276,12 @@ public final class GemFireStatSampler extends HostStatSampler  {
     }
     if (stopRequested()) return;
     HostStatHelper.readyRefreshOSStats();
-    synchronized (l) {
-      Iterator<Statistics> it = l.iterator();
-      while (it.hasNext()) {
-        if (stopRequested()) return;
-        StatisticsImpl s = (StatisticsImpl)it.next();
-        if (s.usesSystemCalls()) {
-          HostStatHelper.refresh((LocalStatisticsImpl)s);
-        }
+    Iterator<Statistics> it = l.iterator();
+    while (it.hasNext()) {
+      if (stopRequested()) return;
+      StatisticsImpl s = (StatisticsImpl)it.next();
+      if (s.usesSystemCalls()) {
+        HostStatHelper.refresh((LocalStatisticsImpl)s);
       }
     }
   }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e9ffdce4/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
index ebb4177..a5a07ca 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/HostStatSampler.java
@@ -510,12 +510,10 @@ public abstract class HostStatSampler
    */
   private void sampleSpecialStats(boolean prepareOnly) {
     List<Statistics> statsList = getStatisticsManager().getStatsList();
-    synchronized (statsList) {
-      for (Statistics s : statsList) {
-        if (stopRequested()) return;
-        if (s instanceof StatisticsImpl) {
-          ((StatisticsImpl)s).prepareForSample();
-        }
+    for (Statistics s : statsList) {
+      if (stopRequested()) return;
+      if (s instanceof StatisticsImpl) {
+        ((StatisticsImpl)s).prepareForSample();
       }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/e9ffdce4/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/control/HeapMemoryMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/control/HeapMemoryMonitor.java b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/control/HeapMemoryMonitor.java
index 90a26cb..bc83335 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/control/HeapMemoryMonitor.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/control/HeapMemoryMonitor.java
@@ -304,18 +304,16 @@ public void stopMonitoring() {
       sampler.waitForInitialization();
       String tenuredPoolName = getTenuredMemoryPoolMXBean().getName();
       List list = this.cache.getDistributedSystem().getStatsList();
-      synchronized (list) {
-        for (Object o : list) {
-          if (o instanceof StatisticsImpl) {
-            StatisticsImpl si = (StatisticsImpl) o;
-            if (si.getTextId().contains(tenuredPoolName) && si.getType().getName().contains("PoolStats")) {
-              sampler.addLocalStatListener(this.statListener, si, "currentUsedMemory");
-              if (this.cache.getLoggerI18n().fineEnabled()) {
-                this.cache.getLoggerI18n().fine("Registered stat listener for " + si.getTextId());
-              }
-
-              return true;
+      for (Object o : list) {
+        if (o instanceof StatisticsImpl) {
+          StatisticsImpl si = (StatisticsImpl) o;
+          if (si.getTextId().contains(tenuredPoolName) && si.getType().getName().contains("PoolStats")) {
+            sampler.addLocalStatListener(this.statListener, si, "currentUsedMemory");
+            if (this.cache.getLoggerI18n().fineEnabled()) {
+              this.cache.getLoggerI18n().fine("Registered stat listener for " + si.getTextId());
             }
+
+            return true;
           }
         }
       }


[05/23] incubator-geode git commit: GEODE-1422: Removing check to skip enqueuing temp events

Posted by kl...@apache.org.
GEODE-1422: Removing check to skip enqueuing temp events

This check was performed outside of synchronizing on the lock, which
means that some events could be added to the temp events after the
check. This caused the test to fail due to temp events being left in the
map.

Also, fixing two race conditions in testParallelPropagationSenderStartAfterStop_Scenario2

1) It did some puts and stopped the sender without waiting for the
puts to complete. So they may not be available on the remote side

2) It started some puts asynchronously, and then started the sender
later. The puts performed before the sender started may not be present
on the remote side.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/be0f7cfb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/be0f7cfb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/be0f7cfb

Branch: refs/heads/feature/GEODE-835
Commit: be0f7cfb396d1f55301ad75bd5398c3d482d193d
Parents: 615e643
Author: Dan Smith <up...@apache.org>
Authored: Thu Jun 9 11:56:58 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Mon Jun 13 10:45:14 2016 -0700

----------------------------------------------------------------------
 .../asyncqueue/internal/ParallelAsyncEventQueueImpl.java    | 4 +---
 .../cache/wan/parallel/ParallelGatewaySenderImpl.java       | 4 +---
 .../parallel/ParallelGatewaySenderOperationsDUnitTest.java  | 9 +++++----
 3 files changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/be0f7cfb/geode-core/src/main/java/com/gemstone/gemfire/cache/asyncqueue/internal/ParallelAsyncEventQueueImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/cache/asyncqueue/internal/ParallelAsyncEventQueueImpl.java b/geode-core/src/main/java/com/gemstone/gemfire/cache/asyncqueue/internal/ParallelAsyncEventQueueImpl.java
index aa3e71c..4b708b8 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/cache/asyncqueue/internal/ParallelAsyncEventQueueImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/cache/asyncqueue/internal/ParallelAsyncEventQueueImpl.java
@@ -112,9 +112,7 @@ public class ParallelAsyncEventQueueImpl extends AbstractGatewaySender {
       
       logger.info(LocalizedMessage.create(LocalizedStrings.ParallelGatewaySenderImpl_STARTED__0, this));
       
-      if (!tmpQueuedEvents.isEmpty()) {
-        enqueueTempEvents();
-      }
+      enqueueTempEvents();
     }
     finally {
       this.getLifeCycleLock().writeLock().unlock();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/be0f7cfb/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderImpl.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderImpl.java b/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderImpl.java
index b313403..8f5b728 100644
--- a/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderImpl.java
+++ b/geode-wan/src/main/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderImpl.java
@@ -111,9 +111,7 @@ public class ParallelGatewaySenderImpl extends AbstractRemoteGatewaySender {
       
       logger.info(LocalizedMessage.create(LocalizedStrings.ParallelGatewaySenderImpl_STARTED__0, this));
       
-      if (!tmpQueuedEvents.isEmpty()) {
-        enqueueTempEvents();
-      }
+      enqueueTempEvents();
     }
     finally {
       this.getLifeCycleLock().writeLock().unlock();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/be0f7cfb/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java b/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
index cda5ba3..a1036f4 100644
--- a/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
+++ b/geode-wan/src/test/java/com/gemstone/gemfire/internal/cache/wan/parallel/ParallelGatewaySenderOperationsDUnitTest.java
@@ -323,7 +323,11 @@ public class ParallelGatewaySenderOperationsDUnitTest extends WANTestBase {
     vm4.invoke(() -> WANTestBase.doPuts( getTestMethodName() + "_PR", 200 ));
     
     LogWriterUtils.getLogWriter().info("Done few puts");
-    
+
+    //Make sure the puts make it to the remote side
+    vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_PR", 200, 120000));
+    vm3.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_PR", 200, 120000));
+
     //now, stop all of the senders
     stopSenders();
     
@@ -350,9 +354,6 @@ public class ParallelGatewaySenderOperationsDUnitTest extends WANTestBase {
     
     async.join();
 
-    vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_PR", 5000, 120000));
-    vm3.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_PR", 5000, 120000));
-    
     //verify all the buckets on all the sender nodes are drained
     validateParallelSenderQueueAllBucketsDrained();