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/12/08 17:12:14 UTC

[01/16] geode git commit: GEODE-2164: Refactored out NAMES_ARRAY from CqNameToOpSingleEntry [Forced Update!]

Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-1027 951e99576 -> 65e5450cc (forced update)


GEODE-2164: Refactored out NAMES_ARRAY from CqNameToOpSingleEntry


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

Branch: refs/heads/feature/GEODE-1027
Commit: 9dd4205daa662df7aadf9f30f6fa4ba21e7b6130
Parents: c8603ef
Author: Jason Huynh <hu...@gmail.com>
Authored: Thu Dec 1 10:27:50 2016 -0800
Committer: Jason Huynh <hu...@gmail.com>
Committed: Tue Dec 6 15:58:01 2016 -0800

----------------------------------------------------------------------
 .../tier/sockets/ClientUpdateMessageImpl.java   | 22 ++++++++------------
 1 file changed, 9 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/9dd4205d/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImpl.java
index a202ba2..6bbe7b8 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/tier/sockets/ClientUpdateMessageImpl.java
@@ -1464,12 +1464,11 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
    * much smaller memory footprint than a HashMap with one entry.
    */
   public static class CqNameToOpSingleEntry implements CqNameToOp {
-    private String name;
+    private String[] name;
     private int op;
 
     private static final String[] EMPTY_NAMES_ARRAY = new String[0];
 
-    private static Map<String, String[]> NAMES_ARRAY = new ConcurrentHashMap<String, String[]>();
 
     public CqNameToOpSingleEntry(String name, Integer op) {
       initializeName(name);
@@ -1477,10 +1476,7 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
     }
 
     private void initializeName(String name) {
-      this.name = name;
-      if (!NAMES_ARRAY.containsKey(name)) {
-        NAMES_ARRAY.put(name, new String[] {name});
-      }
+      this.name = new String[] {name};
     }
 
     @Override
@@ -1490,7 +1486,7 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
       int size = size();
       InternalDataSerializer.writeArrayLength(size, out);
       if (size > 0) {
-        DataSerializer.writeObject(this.name, out);
+        DataSerializer.writeObject(this.name[0], out);
         DataSerializer.writeObject(Integer.valueOf(this.op), out);
       }
     }
@@ -1503,7 +1499,7 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
     @Override
     public void addToMessage(Message message) {
       if (!isEmpty()) {
-        message.addStringPart(this.name, true);
+        message.addStringPart(this.name[0], true);
         message.addIntPart(this.op);
       }
     }
@@ -1515,15 +1511,15 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
 
     @Override
     public String[] getNames() {
-      return (isEmpty()) ? EMPTY_NAMES_ARRAY : NAMES_ARRAY.get(this.name);
+      return (isEmpty()) ? EMPTY_NAMES_ARRAY : this.name;
     }
 
     @Override
     public void add(String name, Integer op) {
       if (isEmpty()) {
-        this.name = name;
+        this.name = new String[] {name};
         this.op = op.intValue();
-      } else if (this.name.equals(name)) {
+      } else if (this.name[0].equals(name)) {
         this.op = op.intValue();
       } else {
         throw new IllegalStateException("tried to add to a full CqNameToOpSingleEntry");
@@ -1532,7 +1528,7 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
 
     @Override
     public void delete(String name) {
-      if (name.equals(this.name)) {
+      if (name.equals(this.name[0])) {
         this.name = null;
       }
     }
@@ -1552,7 +1548,7 @@ public class ClientUpdateMessageImpl implements ClientUpdateMessage, Sizeable, N
 
     public CqNameToOpHashMap(CqNameToOpSingleEntry se) {
       super(2, 1.0f);
-      add(se.name, se.op);
+      add(se.name[0], se.op);
     }
 
     @Override


[10/16] geode git commit: GEODE-2004: [doc update] change to a permission for REST-initiated queries. Updated error messages.

Posted by kl...@apache.org.
GEODE-2004: [doc update] change to a permission for REST-initiated queries. Updated error messages.


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

Branch: refs/heads/feature/GEODE-1027
Commit: 1d34eeb9f6217a4375590094166e5b81a820abae
Parents: 22ec6a7
Author: Dave Barnes <db...@pivotal.io>
Authored: Wed Dec 7 14:37:09 2016 -0800
Committer: Dave Barnes <db...@pivotal.io>
Committed: Wed Dec 7 14:37:09 2016 -0800

----------------------------------------------------------------------
 .../rest_apps/delete_named_query.html.md.erb    |  4 ++-
 .../get_execute_adhoc_query.html.md.erb         | 12 +++++++
 geode-docs/rest_apps/get_queries.html.md.erb    | 30 ++++++++++++++---
 .../rest_apps/post_create_query.html.md.erb     | 16 +++++++--
 .../rest_apps/post_execute_query.html.md.erb    | 18 +++++++++--
 .../rest_apps/put_update_query.html.md.erb      | 34 +++++++++++++++++---
 6 files changed, 100 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/delete_named_query.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/delete_named_query.html.md.erb b/geode-docs/rest_apps/delete_named_query.html.md.erb
index ae109d6..d26ea36 100644
--- a/geode-docs/rest_apps/delete_named_query.html.md.erb
+++ b/geode-docs/rest_apps/delete_named_query.html.md.erb
@@ -54,7 +54,9 @@ Response Payload: application/json
 
 | Status Code               | Description                                                                                   |
 |---------------------------|-----------------------------------------------------------------------------------------------|
-| 404 NOT FOUND             | Query with specified ID could not be found.                                                   |
+| 401 UNAUTHORIZED          | Invalid Username or Password                                                                  |
+| 403 FORBIDDEN             | Insufficient privileges for operation                                                         |
+| 404 NOT FOUND             | Query with specified ID could not be found                                                    |
 | 500 INTERNAL SERVER ERROR | Encountered error at server. Check the HTTP response body for a stack trace of the exception. |
 
 

http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/get_execute_adhoc_query.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/get_execute_adhoc_query.html.md.erb b/geode-docs/rest_apps/get_execute_adhoc_query.html.md.erb
index 0a70c82..dc31407 100644
--- a/geode-docs/rest_apps/get_execute_adhoc_query.html.md.erb
+++ b/geode-docs/rest_apps/get_execute_adhoc_query.html.md.erb
@@ -103,10 +103,22 @@ Content-Type: application/json
 </tr>
 </thead>
 <tbody>
+<tr>
+<td>401 UNAUTHORIZED</td>
+<td>Invalid Username or Password</td>
+</tr>
+<tr>
+<td>403 FORBIDDEN</td>
+<td>Insufficient privileges for operation</td>
+</tr>
 <tr class="odd">
 <td>500 INTERNAL SERVER ERROR</td>
 <td>Error encountered at Geode server. Check the HTTP response body for a stack trace of the exception. Some possible exceptions include:
 <ul>
+<li>A function was applied to a parameter that is improper for that function!</li>
+<li>Bind parameter is not of the expected type!</li>
+<li>Name in the query cannot be resolved!</li>
+<li>The number of bound parameters does not match the number of placeholders!</li>
 <li>Query is not permitted on this type of region!</li>
 <li>Query execution time is exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured!</li>
 <li>Data referenced in from clause is not available for querying!</li>

http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/get_queries.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/get_queries.html.md.erb b/geode-docs/rest_apps/get_queries.html.md.erb
index 71e0219..ba86e55 100644
--- a/geode-docs/rest_apps/get_queries.html.md.erb
+++ b/geode-docs/rest_apps/get_queries.html.md.erb
@@ -65,8 +65,30 @@ Location: http://localhost:8080/gemfire-api/v1/queries
 
 ## Error Codes
 
-| �                         | �                                                                                                                                |
-|---------------------------|----------------------------------------------------------------------------------------------------------------------------------|
-| 500 INTERNAL SERVER ERROR | Error encountered at Geode server. Check the HTTP response body for a stack trace of the exception. |
-
+<table>
+<colgroup>
+<col width="40%" />
+<col width="60%" />
+</colgroup>
+<thead>
+<tr class="header">
+<th>Status Code</th>
+<th>Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>401 UNAUTHORIZED</td>
+<td>Invalid Username or Password</td>
+</tr>
+<tr>
+<td>403 FORBIDDEN</td>
+<td>Insufficient privileges for operation</td>
+</tr>
+<tr class="even">
+<td>500 INTERNAL SERVER ERROR</td>
+<td>Error encountered at Geode server. Check the HTTP response body for a stack trace of the exception.</td>
+</tr>
+</tbody>
+</table>
 

http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/post_create_query.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/post_create_query.html.md.erb b/geode-docs/rest_apps/post_create_query.html.md.erb
index 9062948..9fdba2a 100644
--- a/geode-docs/rest_apps/post_create_query.html.md.erb
+++ b/geode-docs/rest_apps/post_create_query.html.md.erb
@@ -89,9 +89,21 @@ Location: http://localhost:8080/gemfire-api/v1/queries/selectOrders
 </tr>
 </thead>
 <tbody>
-<tr class="odd">
+<tr>
 <td>400 BAD REQUEST</td>
-<td>Returned if user does not specify a query ID or a malformed OQL statement.</td>
+<td>Query ID not specified or malformed OQL statement</td>
+</tr>
+<tr>
+<td>401 UNAUTHORIZED</td>
+<td>Invalid Username or Password</td>
+</tr>
+<tr>
+<td>403 FORBIDDEN</td>
+<td>Insufficient privileges for operation</td>
+</tr>
+<tr>
+<td>409 CONFLICT</td>
+<td>QueryId already assigned to another query</td>
 </tr>
 <tr class="even">
 <td>500 INTERNAL SERVER ERROR</td>

http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/post_execute_query.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/post_execute_query.html.md.erb b/geode-docs/rest_apps/post_execute_query.html.md.erb
index 7d0853c..f0557ba 100644
--- a/geode-docs/rest_apps/post_execute_query.html.md.erb
+++ b/geode-docs/rest_apps/post_execute_query.html.md.erb
@@ -146,9 +146,21 @@ Content-Type: application/json
 </tr>
 </thead>
 <tbody>
-<tr class="odd">
+<tr>
+<tr>
+<td>400 BAD REQUEST</td>
+<td>JSON document in the request body (specifying query bind params) is invalid</td>
+</tr>
+<td>401 UNAUTHORIZED</td>
+<td>Invalid Username or Password</td>
+</tr>
+<tr>
+<td>403 FORBIDDEN</td>
+<td>Insufficient privileges for operation</td>
+</tr>
+<tr>
 <td>404 NOT FOUND</td>
-<td>Query with specified ID could not be found.</td>
+<td>Query with specified ID could not be found</td>
 </tr>
 <tr class="even">
 <td>500 INTERNAL SERVER ERROR</td>
@@ -160,7 +172,7 @@ Content-Type: application/json
 <li>Name in the query cannot be resolved!&quot;</li>
 <li>The number of bound parameters does not match the number of placeholders!</li>
 <li>Query is not permitted on this type of region!</li>
-<li>Query execution time is exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured!</li>
+<li>Query execution time has exceeded max query execution time (gemfire.Cache.MAX_QUERY_EXECUTION_TIME) configured!</li>
 <li>Data referenced in from clause is not available for querying!&quot;</li>
 <li>Query execution gets canceled due to low memory conditions and the resource manager critical heap percentage has been set!&quot;</li>
 <li>Error encountered while executing named query!&quot;</li>

http://git-wip-us.apache.org/repos/asf/geode/blob/1d34eeb9/geode-docs/rest_apps/put_update_query.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/put_update_query.html.md.erb b/geode-docs/rest_apps/put_update_query.html.md.erb
index 966154a..339f4d7 100644
--- a/geode-docs/rest_apps/put_update_query.html.md.erb
+++ b/geode-docs/rest_apps/put_update_query.html.md.erb
@@ -73,10 +73,36 @@ Response Payload:  null
 
 ## Error Codes
 
-| Status Code               | Description                                                                                                                      |
-|---------------------------|----------------------------------------------------------------------------------------------------------------------------------|
-| 404 NOT FOUND             | Returned if the specified queryId cannot be found.                                                                               |
-| 500 INTERNAL SERVER ERROR | Error encountered at Geode server. Check the HTTP response body for a stack trace of the exception. |
+<table>
+<colgroup>
+<col width="50%" />
+<col width="50%" />
+</colgroup>
+<thead>
+<tr class="header">
+<th>Status Code</th>
+<th>Description</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>401 UNAUTHORIZED</td>
+<td>Invalid Username or Password</td>
+</tr>
+<tr>
+<td>403 FORBIDDEN</td>
+<td>Insufficient privileges for operation</td>
+</tr>
+<tr>
+<td>404 NOT FOUND</td>
+<td>QueryID does not exist</td>
+</tr>
+<tr class="odd">
+<td>500 INTERNAL SERVER ERROR</td>
+<td>Error encountered at Geode server. Check the HTTP response body for a stack trace of the exception.</td>
+</tr>
+</tbody>
+</table>
 
 ## Implementation Notes
 


[16/16] geode git commit: GEODE-1027: add unit test for previously committed fix

Posted by kl...@apache.org.
GEODE-1027: add unit test for previously committed fix


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

Branch: refs/heads/feature/GEODE-1027
Commit: 65e5450ccc3556774589867627c19cc2842f0fa5
Parents: ef74181
Author: Kirk Lund <kl...@apache.org>
Authored: Wed Dec 7 15:33:51 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Dec 8 09:12:00 2016 -0800

----------------------------------------------------------------------
 .../internal/statistics/SampleCollector.java    |   4 +-
 .../internal/statistics/StatisticsMonitor.java  |  28 ++---
 .../geode/internal/statistics/ValueMonitor.java |  20 ++--
 .../internal/beans/stats/MBeanStatsMonitor.java |  54 +++++----
 .../internal/statistics/FakeValueMonitor.java   |  37 ++++++
 .../beans/stats/MBeanStatsMonitorTest.java      | 117 +++++++++++++++++++
 6 files changed, 212 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/main/java/org/apache/geode/internal/statistics/SampleCollector.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/SampleCollector.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/SampleCollector.java
index 9f1b343..2abbecd 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/SampleCollector.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/SampleCollector.java
@@ -115,7 +115,7 @@ public class SampleCollector {
    * 
    * @throws IllegalStateException if no SampleCollector has been created and initialized yet
    */
-  public static StatMonitorHandler getStatMonitorHandler() {
+  static StatMonitorHandler getStatMonitorHandler() {
     // sync SampleCollector.class and then instance.sampleHandlers
     synchronized (SampleCollector.class) {
       if (instance == null) {
@@ -321,7 +321,7 @@ public class SampleCollector {
   }
 
   /** For testing only */
-  public StatArchiveHandler getStatArchiveHandler() {
+  StatArchiveHandler getStatArchiveHandler() {
     synchronized (this.sampleHandlers) {
       return this.statArchiveHandler;
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsMonitor.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsMonitor.java
index 16f71e2..a00a7a3 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsMonitor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/StatisticsMonitor.java
@@ -29,14 +29,13 @@ public abstract class StatisticsMonitor {
 
   private final Object mutex = new Object();
 
-  private final ConcurrentHashSet<StatisticsListener> listeners =
-      new ConcurrentHashSet<StatisticsListener>();
+  private final ConcurrentHashSet<StatisticsListener> listeners = new ConcurrentHashSet<>();
 
-  private final ConcurrentHashSet<StatisticId> statisticIds = new ConcurrentHashSet<StatisticId>();
+  private final ConcurrentHashSet<StatisticId> statisticIds = new ConcurrentHashSet<>();
 
   public StatisticsMonitor() {}
 
-  public StatisticsMonitor addStatistic(StatisticId statId) {
+  public StatisticsMonitor addStatistic(final StatisticId statId) {
     if (statId == null) {
       throw new NullPointerException("StatisticId is null");
     }
@@ -46,7 +45,7 @@ public abstract class StatisticsMonitor {
     return this;
   }
 
-  public StatisticsMonitor removeStatistic(StatisticId statId) {
+  public StatisticsMonitor removeStatistic(final StatisticId statId) {
     if (statId == null) {
       throw new NullPointerException("StatisticId is null");
     }
@@ -56,7 +55,7 @@ public abstract class StatisticsMonitor {
     return this;
   }
 
-  public final void addListener(StatisticsListener listener) {
+  public void addListener(final StatisticsListener listener) {
     if (listener == null) {
       throw new NullPointerException("StatisticsListener is null");
     }
@@ -68,7 +67,7 @@ public abstract class StatisticsMonitor {
     }
   }
 
-  public final void removeListener(StatisticsListener listener) {
+  public void removeListener(final StatisticsListener listener) {
     if (listener == null) {
       throw new NullPointerException("StatisticsListener is null");
     }
@@ -93,24 +92,25 @@ public abstract class StatisticsMonitor {
    * @param millisTimeStamp the real time in millis of the sample
    * @param resourceInstances resources with one or more updated values
    */
-  protected void monitor(long millisTimeStamp, List<ResourceInstance> resourceInstances) {
+  protected void monitor(final long millisTimeStamp,
+      final List<ResourceInstance> resourceInstances) {
     monitorStatisticIds(millisTimeStamp, resourceInstances);
   }
 
-  private final void monitorStatisticIds(long millisTimeStamp,
-      List<ResourceInstance> resourceInstances) {
+  private void monitorStatisticIds(final long millisTimeStamp,
+      final List<ResourceInstance> resourceInstances) {
     if (!this.statisticIds.isEmpty()) {
       // TODO:
     }
   }
 
-  protected final void notifyListeners(StatisticsNotification notification) {
+  protected void notifyListeners(final StatisticsNotification notification) {
     for (StatisticsListener listener : this.listeners) {
       listener.handleNotification(notification);
     }
   }
 
-  protected final Object mutex() {
+  protected Object mutex() {
     return this.mutex;
   }
 
@@ -137,7 +137,9 @@ public abstract class StatisticsMonitor {
     return sb.toString();
   }
 
-  /** Override to append to toString() */
+  /**
+   * Override to append to toString()
+   */
   protected StringBuilder appendToString() {
     return null;
   }

http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/main/java/org/apache/geode/internal/statistics/ValueMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/statistics/ValueMonitor.java b/geode-core/src/main/java/org/apache/geode/internal/statistics/ValueMonitor.java
index 1dc6fd0..e46723c 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/statistics/ValueMonitor.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/statistics/ValueMonitor.java
@@ -43,31 +43,31 @@ import org.apache.geode.internal.CopyOnWriteHashSet;
  * @since GemFire 7.0
  * @see org.apache.geode.Statistics
  */
-public final class ValueMonitor extends StatisticsMonitor {
+public class ValueMonitor extends StatisticsMonitor {
 
   public enum Type {
     CHANGE, MATCH, DIFFER
   }
 
-  private final CopyOnWriteHashSet<Statistics> statistics = new CopyOnWriteHashSet<Statistics>();
+  private final CopyOnWriteHashSet<Statistics> statistics = new CopyOnWriteHashSet<>();
 
   public ValueMonitor() {
     super();
   }
 
   @Override
-  public ValueMonitor addStatistic(StatisticId statId) {
+  public ValueMonitor addStatistic(final StatisticId statId) {
     super.addStatistic(statId);
     return this;
   }
 
   @Override
-  public ValueMonitor removeStatistic(StatisticId statId) {
+  public ValueMonitor removeStatistic(final StatisticId statId) {
     super.removeStatistic(statId);
     return this;
   }
 
-  public ValueMonitor addStatistics(Statistics statistics) {
+  public ValueMonitor addStatistics(final Statistics statistics) {
     if (statistics == null) {
       throw new NullPointerException("Statistics is null");
     }
@@ -75,7 +75,7 @@ public final class ValueMonitor extends StatisticsMonitor {
     return this;
   }
 
-  public ValueMonitor removeStatistics(Statistics statistics) {
+  public ValueMonitor removeStatistics(final Statistics statistics) {
     if (statistics == null) {
       throw new NullPointerException("Statistics is null");
     }
@@ -83,14 +83,16 @@ public final class ValueMonitor extends StatisticsMonitor {
     return this;
   }
 
-  protected void monitor(long millisTimeStamp, List<ResourceInstance> resourceInstances) {
+  protected void monitor(final long millisTimeStamp,
+      final List<ResourceInstance> resourceInstances) {
     super.monitor(millisTimeStamp, resourceInstances);
     monitorStatistics(millisTimeStamp, resourceInstances);
   }
 
-  protected void monitorStatistics(long millisTimeStamp, List<ResourceInstance> resourceInstances) {
+  protected void monitorStatistics(final long millisTimeStamp,
+      final List<ResourceInstance> resourceInstances) {
     if (!this.statistics.isEmpty()) {
-      Map<StatisticId, Number> stats = new HashMap<StatisticId, Number>();
+      Map<StatisticId, Number> stats = new HashMap<>();
       for (ResourceInstance resource : resourceInstances) {
         if (this.statistics.contains(resource.getStatistics())) {
           ResourceType resourceType = resource.getResourceType();

http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitor.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitor.java
index 390fb89..c1744f9 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitor.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitor.java
@@ -17,11 +17,12 @@ package org.apache.geode.management.internal.beans.stats;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.logging.log4j.Logger;
+
 import org.apache.geode.StatisticDescriptor;
 import org.apache.geode.Statistics;
 import org.apache.geode.StatisticsType;
-import org.apache.geode.distributed.internal.InternalDistributedSystem;
-import org.apache.geode.i18n.LogWriterI18n;
+import org.apache.geode.internal.logging.LogService;
 import org.apache.geode.internal.statistics.StatisticId;
 import org.apache.geode.internal.statistics.StatisticNotFoundException;
 import org.apache.geode.internal.statistics.StatisticsListener;
@@ -30,11 +31,11 @@ import org.apache.geode.internal.statistics.ValueMonitor;
 
 /**
  * Class to get mappings of stats name to their values
- * 
- * 
  */
 public class MBeanStatsMonitor implements StatisticsListener {
 
+  private static final Logger logger = LogService.getLogger();
+
   protected ValueMonitor monitor;
 
   /**
@@ -44,17 +45,17 @@ public class MBeanStatsMonitor implements StatisticsListener {
 
   protected String monitorName;
 
-  private LogWriterI18n logger;
+  public MBeanStatsMonitor(final String name) {
+    this(name, new ValueMonitor());
+  }
 
-  public MBeanStatsMonitor(String name) {
+  MBeanStatsMonitor(final String name, final ValueMonitor monitor) {
     this.monitorName = name;
-    this.monitor = new ValueMonitor();
+    this.monitor = monitor;
     this.statsMap = new DefaultHashMap();
-    this.logger = InternalDistributedSystem.getLoggerI18n();
-
   }
 
-  public void addStatisticsToMonitor(Statistics stats) {
+  public void addStatisticsToMonitor(final Statistics stats) {
     monitor.addListener(this);// if already listener is added this will be a no-op
     // Initialize the stats with the current values.
     StatisticsType type = stats.getType();
@@ -65,7 +66,7 @@ public class MBeanStatsMonitor implements StatisticsListener {
     monitor.addStatistics(stats);
   }
 
-  public void removeStatisticsFromMonitor(Statistics stats) {
+  public void removeStatisticsFromMonitor(final Statistics stats) {
     statsMap.clear();
   }
 
@@ -73,13 +74,13 @@ public class MBeanStatsMonitor implements StatisticsListener {
     monitor.removeListener(this);
   }
 
-  public Number getStatistic(String statName) {
-    return statsMap.get(statName) != null ? statsMap.get(statName) : 0;
+  public Number getStatistic(final String statName) {
+    Number value = statsMap.get(statName);
+    return value != null ? value : 0;
   }
 
   @Override
-  public void handleNotification(StatisticsNotification notification) {
-
+  public void handleNotification(final StatisticsNotification notification) {
     for (StatisticId statId : notification) {
       StatisticDescriptor descriptor = statId.getStatisticDescriptor();
       String name = descriptor.getName();
@@ -91,33 +92,38 @@ public class MBeanStatsMonitor implements StatisticsListener {
       }
       log(name, value);
       statsMap.put(name, value);
-
     }
   }
 
-  protected void log(String name, Number value) {
-
-    if (logger != null && logger.finestEnabled()) {
-      logger.finest("Monitor = " + monitorName + " descriptor = " + name + " And Value = " + value);
+  protected void log(final String name, final Number value) {
+    if (logger.isTraceEnabled()) {
+      logger.trace("Monitor = {} descriptor = {} And value = {}", monitorName, name, value);
     }
   }
 
-  public static class DefaultHashMap {
-    private Map<String, Number> internalMap = new HashMap<String, Number>();
+  public static class DefaultHashMap { // TODO: delete this class
+    private Map<String, Number> internalMap = new HashMap<>();
 
     public DefaultHashMap() {}
 
-    public Number get(String key) {
+    public Number get(final String key) {
       return internalMap.get(key) != null ? internalMap.get(key) : 0;
     }
 
-    public void put(String key, Number value) {
+    public void put(final String key, final Number value) {
       internalMap.put(key, value);
     }
 
     public void clear() {
       internalMap.clear();
     }
+
+    /**
+     * For testing only
+     */
+    Map<String, Number> getInternalMap() {
+      return this.internalMap;
+    }
   }
 
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/test/java/org/apache/geode/internal/statistics/FakeValueMonitor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/internal/statistics/FakeValueMonitor.java b/geode-core/src/test/java/org/apache/geode/internal/statistics/FakeValueMonitor.java
new file mode 100644
index 0000000..0b3a27d
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/internal/statistics/FakeValueMonitor.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.geode.internal.statistics;
+
+import static org.mockito.Mockito.mock;
+
+/**
+ * Fake ValueMonitor which uses mocked StatMonitorHandler as a collaborator.
+ */
+public class FakeValueMonitor extends ValueMonitor {
+
+  private StatMonitorHandler statMonitorHandler;
+
+  public FakeValueMonitor() {
+    this(mock(StatMonitorHandler.class));
+  }
+
+  public FakeValueMonitor(StatMonitorHandler statMonitorHandler) {
+    this.statMonitorHandler = statMonitorHandler;
+  }
+
+  StatMonitorHandler getStatMonitorHandler() {
+    return this.statMonitorHandler;
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/65e5450c/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitorTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitorTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitorTest.java
new file mode 100644
index 0000000..18d7f81
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/beans/stats/MBeanStatsMonitorTest.java
@@ -0,0 +1,117 @@
+/*
+ * 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 org.apache.geode.management.internal.beans.stats;
+
+import static org.assertj.core.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.TestName;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+
+import org.apache.geode.StatisticDescriptor;
+import org.apache.geode.Statistics;
+import org.apache.geode.StatisticsType;
+import org.apache.geode.i18n.LogWriterI18n;
+import org.apache.geode.internal.statistics.FakeValueMonitor;
+import org.apache.geode.internal.statistics.ValueMonitor;
+import org.apache.geode.management.internal.beans.stats.MBeanStatsMonitor.DefaultHashMap;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class MBeanStatsMonitorTest {
+
+  private ValueMonitor statsMonitor;
+
+  private StatisticDescriptor[] descriptors;
+
+  private Map<String, Number> expectedStatsMap;
+
+  @Spy
+  private DefaultHashMap statsMap;
+  @Mock
+  private LogWriterI18n logWriter;
+  @Mock
+  private Statistics stats;
+  @Mock
+  private StatisticsType statsType;
+
+  @InjectMocks
+  private MBeanStatsMonitor mbeanStatsMonitor;
+
+  @Rule
+  public TestName testName = new TestName();
+
+  @Before
+  public void setUp() throws Exception {
+    this.statsMonitor = spy(new FakeValueMonitor());
+    this.mbeanStatsMonitor =
+        new MBeanStatsMonitor(this.testName.getMethodName(), this.statsMonitor);
+    MockitoAnnotations.initMocks(this);
+
+    this.expectedStatsMap = new HashMap<>();
+    this.descriptors = new StatisticDescriptor[3];
+    for (int i = 0; i < this.descriptors.length; i++) {
+      String key = "stat-" + String.valueOf(i + 1);
+      Number value = i + 1;
+
+      this.expectedStatsMap.put(key, value);
+
+      this.descriptors[i] = mock(StatisticDescriptor.class);
+      when(this.descriptors[i].getName()).thenReturn(key);
+      when(this.stats.get(this.descriptors[i])).thenReturn(value);
+    }
+
+    when(this.statsType.getStatistics()).thenReturn(this.descriptors);
+    when(this.stats.getType()).thenReturn(this.statsType);
+  }
+
+  @Test
+  public void addStatisticsToMonitorShouldAddToInternalMap() throws Exception {
+    this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats);
+
+    assertThat(statsMap.getInternalMap()).containsAllEntriesOf(this.expectedStatsMap);
+  }
+
+  @Test
+  public void addStatisticsToMonitorShouldAddListener() throws Exception {
+    this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats);
+
+    verify(this.statsMonitor, times(1)).addListener(this.mbeanStatsMonitor);
+  }
+
+  @Test
+  public void addStatisticsToMonitorShouldAddStatistics() throws Exception {
+    this.mbeanStatsMonitor.addStatisticsToMonitor(this.stats);
+
+    verify(this.statsMonitor, times(1)).addStatistics(this.stats);
+  }
+
+  @Test
+  public void addNullStatisticsToMonitorShouldThrowNPE() throws Exception {
+    assertThatThrownBy(() -> this.mbeanStatsMonitor.addStatisticsToMonitor(null))
+        .isExactlyInstanceOf(NullPointerException.class);
+  }
+
+}


[08/16] geode git commit: GEODE-2004: [doc update] Create/update/delete query through rest api should require DATA:READ instead of DATA:WRITE

Posted by kl...@apache.org.
GEODE-2004: [doc update] Create/update/delete query through rest api should require DATA:READ instead of DATA:WRITE


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

Branch: refs/heads/feature/GEODE-1027
Commit: 860d7efabc72b3d67406315f5f6baaadc3ff9fd4
Parents: f58a11d
Author: Dave Barnes <db...@pivotal.io>
Authored: Wed Dec 7 12:29:14 2016 -0800
Committer: Dave Barnes <db...@pivotal.io>
Committed: Wed Dec 7 12:29:14 2016 -0800

----------------------------------------------------------------------
 .../managing/security/implementing_authorization.html.md.erb     | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/860d7efa/geode-docs/managing/security/implementing_authorization.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/managing/security/implementing_authorization.html.md.erb b/geode-docs/managing/security/implementing_authorization.html.md.erb
index cd7f829..a01feda 100644
--- a/geode-docs/managing/security/implementing_authorization.html.md.erb
+++ b/geode-docs/managing/security/implementing_authorization.html.md.erb
@@ -141,7 +141,7 @@ This table classifies the permissions assigned for `gfsh` operations.
 | export offline-disk-store              | CLUSTER:READ                     |
 | export stack-traces                    | CLUSTER:READ                     |
 | gc                                     | CLUSTER:MANAGE                   |
-| get --key=key1 --region=region1        | DATA:READ:RegionName:Key         |
+| get &#8209;key=key1 &#8209;region=region1        | DATA:READ:RegionName:Key         |
 | import data                            | DATA:WRITE:RegionName            |
 | import cluster-configuration           | DATA:MANAGE                      |
 | list async-event-queues                | CLUSTER:READ                     |
@@ -160,7 +160,7 @@ This table classifies the permissions assigned for `gfsh` operations.
 | pause gateway-sender                   | DATA:MANAGE                      |
 | pdx rename                             | DATA:MANAGE                      |
 | put --key=key1 --region=region1        | DATA:WRITE:RegionName:Key        |
-| query                                  | DATA:READ:RegionName             |
+| query                                  | DATA:READ                        |
 | rebalance                              | DATA:MANAGE                      |
 | remove                                 | DATA:WRITE:RegionName or DATA:WRITE:RegionName:Key |
 | resume gateway-sender                  | DATA:MANAGE                      |


[15/16] geode git commit: GEODE-1835 : unit test to verify a warning message by the configure pdx command only when there are members in the distributed system.

Posted by kl...@apache.org.
GEODE-1835 : unit test to verify a warning message by the configure pdx
command only when there are members in the distributed system.

This closes #304


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

Branch: refs/heads/feature/GEODE-1027
Commit: ef7418140b903e73bc3a38d3a86c01349924bd09
Parents: 28efd90
Author: Amey Barve <ab...@apache.org>
Authored: Mon Dec 5 18:24:18 2016 +0530
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Dec 8 08:46:38 2016 -0800

----------------------------------------------------------------------
 .../ClusterConfigurationDUnitTest.java             | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/ef741814/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
index 3f7b073..2677900 100644
--- a/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
+++ b/geode-wan/src/test/java/org/apache/geode/management/internal/configuration/ClusterConfigurationDUnitTest.java
@@ -614,6 +614,15 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase {
     });
   }
 
+  @Test
+  public void testConfigurePDXForWarning() throws Exception {
+    setup();
+    CommandResult commandResult = configurePDX("com.foo.*", "true", "true", null, "true");
+    String result = (String) commandResult.getResultData().getGfJsonObject()
+        .getJSONObject("content").getJSONArray("message").get(0);
+    assertEquals(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING, result);
+  }
+
   private Object[] setup() throws IOException {
     final int[] ports = getRandomAvailableTCPPorts(3);
     final int locator1Port = ports[0];
@@ -800,13 +809,14 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase {
     executeAndVerifyCommand(csb.getCommandString());
   }
 
-  private void executeAndVerifyCommand(String commandString) {
+  private CommandResult executeAndVerifyCommand(String commandString) {
     CommandResult cmdResult = executeCommand(commandString);
     org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Command : " + commandString);
     org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()
         .info("Command Result : " + commandResultToString(cmdResult));
     assertEquals(Status.OK, cmdResult.getStatus());
     assertFalse(cmdResult.failedToPersist());
+    return cmdResult;
   }
 
   private void createIndex(String indexName, String expression, String regionName, String group) {
@@ -939,7 +949,7 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase {
     }
   }
 
-  private void configurePDX(String autoSerializerClasses, String ignoreUnreadFields,
+  private CommandResult configurePDX(String autoSerializerClasses, String ignoreUnreadFields,
       String persistent, String portableAutoSerializerClasses, String readSerialized) {
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.CONFIGURE_PDX);
     csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__AUTO__SERIALIZER__CLASSES,
@@ -950,7 +960,8 @@ public class ClusterConfigurationDUnitTest extends CliCommandTestBase {
     csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__PORTABLE__AUTO__SERIALIZER__CLASSES,
         portableAutoSerializerClasses);
     csb.addOptionWithValueCheck(CliStrings.CONFIGURE_PDX__READ__SERIALIZED, readSerialized);
-    executeAndVerifyCommand(csb.getCommandString());
+
+    return executeAndVerifyCommand(csb.getCommandString());
   }
 
   private void createAndDeployJar(String jarName, String group) throws IOException {


[05/16] geode git commit: GEODE-2182: try-catch around size estimation for index look ups

Posted by kl...@apache.org.
GEODE-2182: try-catch around size estimation for index look ups

* Fix possible race condition where entry is destroyed


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

Branch: refs/heads/feature/GEODE-1027
Commit: c2b1c8b1c172073824a8e5c48c45a4285f15e6b1
Parents: ef96dba
Author: Jason Huynh <hu...@gmail.com>
Authored: Mon Dec 5 13:53:22 2016 -0800
Committer: Jason Huynh <hu...@gmail.com>
Committed: Wed Dec 7 09:28:38 2016 -0800

----------------------------------------------------------------------
 .../query/internal/index/CompactRangeIndex.java |  2 +
 .../query/internal/index/MemoryIndexStore.java  | 12 ++-
 .../functional/IndexOnEntrySetJUnitTest.java    | 89 ++++++++++++++------
 3 files changed, 68 insertions(+), 35 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/c2b1c8b1/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
index a8a38bd..80568f5 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/CompactRangeIndex.java
@@ -437,6 +437,8 @@ public class CompactRangeIndex extends AbstractIndex {
           }
           break;
       }
+    } catch (EntryDestroyedException e) {
+      return Integer.MAX_VALUE;
     } finally {
       updateIndexUseEndStats(start, false);
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/c2b1c8b1/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/MemoryIndexStore.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/MemoryIndexStore.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/MemoryIndexStore.java
index 3635897..e9cd070 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/MemoryIndexStore.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/index/MemoryIndexStore.java
@@ -247,10 +247,7 @@ public class MemoryIndexStore implements IndexStore {
    * Find the old key by traversing the forward map in case of in-place update modification If not
    * found it means the value object was modified with same value. So oldKey is same as newKey.
    * 
-   * @param newKey
-   * @param entry
    * @return oldKey
-   * @throws TypeMismatchException
    */
   private Object getOldKey(Object newKey, RegionEntry entry) throws TypeMismatchException {
     for (Object mapEntry : valueToEntriesMap.entrySet()) {
@@ -406,7 +403,6 @@ public class MemoryIndexStore implements IndexStore {
    * RegionEntry) { return Collections.singleton(regionEntries); } return (Collection)
    * regionEntries; }
    */
-
   @Override
   public CloseableIterator<IndexStoreEntry> get(Object indexKey) {
     return new MemoryIndexStoreIterator(
@@ -574,7 +570,6 @@ public class MemoryIndexStore implements IndexStore {
   /**
    * A bi-directional iterator over the CSL. Iterates over the entries of CSL where entry is a
    * mapping (value -> Collection) as well as over the Collection.
-   * 
    */
   private class MemoryIndexStoreIterator implements CloseableIterator<IndexStoreEntry> {
     final Map map;
@@ -662,8 +657,9 @@ public class MemoryIndexStore implements IndexStore {
       }
 
       RegionEntry re = (RegionEntry) valuesIterator.next();
-      if (re == null)
+      if (re == null) {
         throw new NoSuchElementException();
+      }
 
       currentEntry.setMemoryIndexStoreEntry(currKey, re);
       return currentEntry;
@@ -718,7 +714,6 @@ public class MemoryIndexStore implements IndexStore {
 
   /**
    * A wrapper over the entry in the CSL index map. It maps IndexKey -> RegionEntry
-   * 
    */
   class MemoryIndexStoreEntry implements IndexStoreEntry {
     private Object deserializedIndexKey;
@@ -771,6 +766,9 @@ public class MemoryIndexStore implements IndexStore {
     private Object key, value;
 
     public CachedEntryWrapper(LocalRegion.NonTXEntry entry) {
+      if (IndexManager.testHook != null) {
+        IndexManager.testHook.hook(201);
+      }
       this.key = entry.getKey();
       this.value = entry.getValue();
     }

http://git-wip-us.apache.org/repos/asf/geode/blob/c2b1c8b1/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexOnEntrySetJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexOnEntrySetJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexOnEntrySetJUnitTest.java
index 6034d53..f659836 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexOnEntrySetJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/functional/IndexOnEntrySetJUnitTest.java
@@ -14,6 +14,10 @@
  */
 package org.apache.geode.cache.query.functional;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import org.apache.geode.cache.*;
 import org.apache.geode.cache.query.*;
 import org.apache.geode.cache.query.internal.QueryObserverAdapter;
@@ -91,7 +95,15 @@ public class IndexOnEntrySetJUnitTest {
   public void testQueriesOnReplicatedRegion() throws Exception {
     testRegion = createReplicatedRegion(testRegionName);
     String regionPath = "/" + testRegionName + ".entrySet entry";
-    executeQueryTest(getQueriesOnRegion(testRegionName), "entry.key.Index", regionPath);
+    executeQueryTest(getQueriesOnRegion(testRegionName), "entry.key.Index", regionPath, 200);
+  }
+
+  @Test
+  public void testEntryDestroyedRaceWithSizeEstimateReplicatedRegion() throws Exception {
+    testRegion = createReplicatedRegion(testRegionName);
+    String regionPath = "/" + testRegionName + ".entrySet entry";
+    executeQueryTestDestroyDuringSizeEstimation(getQueriesOnRegion(testRegionName),
+        "entry.key.Index", regionPath, 201);
   }
 
   /**
@@ -102,7 +114,7 @@ public class IndexOnEntrySetJUnitTest {
   public void testQueriesOnPartitionedRegion() throws Exception {
     testRegion = createPartitionedRegion(testRegionName);
     String regionPath = "/" + testRegionName + ".entrySet entry";
-    executeQueryTest(getQueriesOnRegion(testRegionName), "entry.key.Index", regionPath);
+    executeQueryTest(getQueriesOnRegion(testRegionName), "entry.key.Index", regionPath, 200);
   }
 
   private Region createReplicatedRegion(String regionName) throws ParseException {
@@ -140,24 +152,26 @@ public class IndexOnEntrySetJUnitTest {
     }
   }
 
-  /**** Query Execution Helpers ****/
+  /****
+   * Query Execution Helpers
+   ****/
 
-  private void executeQueryTest(String[] queries, String indexedExpression, String regionPath)
-      throws Exception {
+  private void executeQueryTest(String[] queries, String indexedExpression, String regionPath,
+      int testHookSpot) throws Exception {
     Cache cache = CacheUtils.getCache();
     boolean[] booleanVals = {true, false};
     for (String query : queries) {
       for (boolean isDestroy : booleanVals) {
         clearData(testRegion);
         populateRegion(testRegion);
-        Assert.assertNotNull(cache.getRegion(testRegionName));
-        Assert.assertEquals(numElem, cache.getRegion(testRegionName).size());
+        assertNotNull(cache.getRegion(testRegionName));
+        assertEquals(numElem, cache.getRegion(testRegionName).size());
         if (isDestroy) {
           helpTestFunctionalIndexForQuery(query, indexedExpression, regionPath,
-              new DestroyEntryTestHook(testRegion));
+              new DestroyEntryTestHook(testRegion, testHookSpot), 1);
         } else {
           helpTestFunctionalIndexForQuery(query, indexedExpression, regionPath,
-              new InvalidateEntryTestHook(testRegion));
+              new InvalidateEntryTestHook(testRegion, testHookSpot), 1);
         }
       }
     }
@@ -166,22 +180,18 @@ public class IndexOnEntrySetJUnitTest {
     for (String query : queries) {
       clearData(testRegion);
       populateRegion(testRegion);
-      Assert.assertNotNull(cache.getRegion(testRegionName));
-      Assert.assertEquals(numElem, cache.getRegion(testRegionName).size());
+      assertNotNull(cache.getRegion(testRegionName));
+      assertEquals(numElem, cache.getRegion(testRegionName).size());
       helpTestFunctionalIndexForQuery(query, indexedExpression, regionPath,
-          new PutEntryTestHook(testRegion));
+          new PutEntryTestHook(testRegion, testHookSpot), 1);
     }
   }
 
   /**
    * helper method to test against a functional index make sure there is no UNDEFINED result
-   * 
-   * @param query
-   * 
-   * @throws Exception
    */
   private SelectResults helpTestFunctionalIndexForQuery(String query, String indexedExpression,
-      String regionPath, AbstractTestHook testHook) throws Exception {
+      String regionPath, AbstractTestHook testHook, int expectedSize) throws Exception {
     MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
     QueryObserverHolder.setInstance(observer);
     IndexManager.testHook = testHook;
@@ -194,27 +204,40 @@ public class IndexOnEntrySetJUnitTest {
       if (row instanceof Struct) {
         Object[] fields = ((Struct) row).getFieldValues();
         for (Object field : fields) {
-          Assert.assertTrue(field != QueryService.UNDEFINED);
+          assertTrue(field != QueryService.UNDEFINED);
           if (field instanceof String) {
-            Assert.assertTrue(((String) field).compareTo(newValue) != 0);
+            assertTrue(((String) field).compareTo(newValue) != 0);
           }
         }
       } else {
-        Assert.assertTrue(row != QueryService.UNDEFINED);
+        assertTrue(row != QueryService.UNDEFINED);
         if (row instanceof String) {
-          Assert.assertTrue(((String) row).compareTo(newValue) != 0);
+          assertTrue(((String) row).compareTo(newValue) != 0);
         }
       }
     }
-    Assert.assertTrue(indexedResults.size() > 0);
-    Assert.assertTrue(observer.indexUsed);
-    Assert.assertTrue(((AbstractTestHook) IndexManager.testHook).isTestHookCalled());
+    assertTrue(indexedResults.size() >= expectedSize);
+    assertTrue(observer.indexUsed);
+    assertTrue(((AbstractTestHook) IndexManager.testHook).isTestHookCalled());
     ((AbstractTestHook) IndexManager.testHook).reset();
     qs.removeIndex(index);
 
     return indexedResults;
   }
 
+  private void executeQueryTestDestroyDuringSizeEstimation(String[] queries,
+      String indexedExpression, String regionPath, int testHookSpot) throws Exception {
+    Cache cache = CacheUtils.getCache();
+    for (String query : queries) {
+      clearData(testRegion);
+      populateRegion(testRegion);
+      assertNotNull(cache.getRegion(testRegionName));
+      assertEquals(numElem, cache.getRegion(testRegionName).size());
+      helpTestFunctionalIndexForQuery(query, indexedExpression, regionPath,
+          new DestroyEntryTestHook(testRegion, testHookSpot), 0);
+    }
+  }
+
   class MyQueryObserverAdapter extends QueryObserverAdapter {
     public boolean indexUsed = false;
 
@@ -255,6 +278,12 @@ public class IndexOnEntrySetJUnitTest {
     Object waitObj = new Object();
     Region r;
 
+    private int testHookSpot;
+
+    public AbstractTestHook(int testHookSpot) {
+      this.testHookSpot = testHookSpot;
+    }
+
     public void reset() {
       isTestHookCalled = false;
     }
@@ -270,7 +299,7 @@ public class IndexOnEntrySetJUnitTest {
 
     @Override
     public void hook(int spot) throws RuntimeException {
-      if (spot == 200) {
+      if (spot == testHookSpot) {
         if (!isTestHookCalled) {
           isTestHookCalled = true;
           try {
@@ -297,7 +326,9 @@ public class IndexOnEntrySetJUnitTest {
 
   class DestroyEntryTestHook extends AbstractTestHook {
 
-    DestroyEntryTestHook(Region r) {
+    DestroyEntryTestHook(Region r, int testHookSpot) {
+
+      super(testHookSpot);
       this.r = r;
     }
 
@@ -312,7 +343,8 @@ public class IndexOnEntrySetJUnitTest {
 
   class InvalidateEntryTestHook extends AbstractTestHook {
 
-    InvalidateEntryTestHook(Region r) {
+    InvalidateEntryTestHook(Region r, int testHookSpot) {
+      super(testHookSpot);
       this.r = r;
     }
 
@@ -327,7 +359,8 @@ public class IndexOnEntrySetJUnitTest {
 
   class PutEntryTestHook extends AbstractTestHook {
 
-    PutEntryTestHook(Region r) {
+    PutEntryTestHook(Region r, int testHookSpot) {
+      super(testHookSpot);
       this.r = r;
     }
 


[02/16] geode git commit: GEODE-1862: Invoke getAllDurableCqsFromServer on the primary queue server

Posted by kl...@apache.org.
GEODE-1862: Invoke getAllDurableCqsFromServer on the primary queue server

Invoking this method on a server that does not have the queue will
return the wrong results.


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

Branch: refs/heads/feature/GEODE-1027
Commit: 05c2388f5add287aa07a43ca08a85776f8b9f43b
Parents: 9dd4205
Author: Barry Oglesby <bo...@pivotal.io>
Authored: Thu Sep 1 17:40:03 2016 -0700
Committer: Dan Smith <up...@apache.org>
Committed: Tue Dec 6 16:53:20 2016 -0800

----------------------------------------------------------------------
 .../cache/client/internal/ConnectionStats.java  |   4 +
 .../cache/client/internal/GetDurableCQsOp.java  |   2 +-
 .../sockets/DurableClientSimpleDUnitTest.java   | 248 ++++++++++++-------
 3 files changed, 159 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/05c2388f/geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionStats.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionStats.java b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionStats.java
index c2229c1..d91719d 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionStats.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/client/internal/ConnectionStats.java
@@ -3344,6 +3344,10 @@ public class ConnectionStats implements MessageStats {
     return this.stats.getLong(executeFunctionDurationId);
   }
 
+  public int getGetDurableCqs() {
+    return this.stats.getInt(getDurableCQsId);
+  }
+
   /**
    * Records that the specified GetClientPRMetadata operation is starting
    * <p>

http://git-wip-us.apache.org/repos/asf/geode/blob/05c2388f/geode-cq/src/main/java/org/apache/geode/cache/client/internal/GetDurableCQsOp.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/main/java/org/apache/geode/cache/client/internal/GetDurableCQsOp.java b/geode-cq/src/main/java/org/apache/geode/cache/client/internal/GetDurableCQsOp.java
index b520c5d..814931c 100755
--- a/geode-cq/src/main/java/org/apache/geode/cache/client/internal/GetDurableCQsOp.java
+++ b/geode-cq/src/main/java/org/apache/geode/cache/client/internal/GetDurableCQsOp.java
@@ -43,7 +43,7 @@ public class GetDurableCQsOp {
    */
   public static List<String> execute(ExecutablePool pool) {
     AbstractOp op = new GetDurableCQsOpImpl();
-    return (List<String>) pool.execute(op);
+    return (List<String>) pool.executeOnPrimary(op);
   }
 
   private GetDurableCQsOp() {

http://git-wip-us.apache.org/repos/asf/geode/blob/05c2388f/geode-cq/src/test/java/org/apache/geode/internal/cache/tier/sockets/DurableClientSimpleDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/org/apache/geode/internal/cache/tier/sockets/DurableClientSimpleDUnitTest.java b/geode-cq/src/test/java/org/apache/geode/internal/cache/tier/sockets/DurableClientSimpleDUnitTest.java
index 68c397d..0ea7050 100644
--- a/geode-cq/src/test/java/org/apache/geode/internal/cache/tier/sockets/DurableClientSimpleDUnitTest.java
+++ b/geode-cq/src/test/java/org/apache/geode/internal/cache/tier/sockets/DurableClientSimpleDUnitTest.java
@@ -16,12 +16,15 @@ package org.apache.geode.internal.cache.tier.sockets;
 
 import static org.apache.geode.internal.cache.tier.sockets.CacheServerTestUtil.TYPE_CREATE;
 import static org.apache.geode.test.dunit.Assert.fail;
+import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.geode.cache.CacheException;
@@ -31,6 +34,7 @@ import org.apache.geode.cache.Region;
 import org.apache.geode.cache.client.Pool;
 import org.apache.geode.cache.client.PoolManager;
 import org.apache.geode.cache.client.ServerRefusedConnectionException;
+import org.apache.geode.cache.client.internal.ConnectionStats;
 import org.apache.geode.cache.client.internal.PoolImpl;
 import org.apache.geode.cache.query.CqAttributes;
 import org.apache.geode.cache.query.CqAttributesFactory;
@@ -42,6 +46,7 @@ import org.apache.geode.cache.query.QueryService;
 import org.apache.geode.cache.query.RegionNotFoundException;
 import org.apache.geode.cache30.CacheSerializableRunnable;
 import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.ServerLocation;
 import org.apache.geode.internal.cache.ClientServerObserver;
 import org.apache.geode.internal.cache.ClientServerObserverAdapter;
 import org.apache.geode.internal.cache.ClientServerObserverHolder;
@@ -83,8 +88,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // normally
     final String durableClientId = getName() + "_client";
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -109,8 +114,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Start normal publisher client
     this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), serverPort,
-            false),
+        getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false),
         regionName));
 
     // Publish some entries
@@ -147,8 +151,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final String regionName1 = regionName + "1";
     final String regionName2 = regionName + "2";
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClients(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName1, regionName2, getClientDistributedSystemProperties(durableClientId)));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName1,
+        regionName2, getClientDistributedSystemProperties(durableClientId)));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -219,8 +223,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // stops normally
     final String durableClientId = getName() + "_client";
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -249,8 +253,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
       public void run2() throws CacheException {
         getSystem(getClientDistributedSystemProperties(durableClientId));
         PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
-        pf.init(getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()),
-            serverPort, true));
+        pf.init(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, true));
         try {
           pf.create("uncreatablePool");
           fail("Should not have been able to create the pool");
@@ -281,8 +284,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Start normal publisher client
     this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), serverPort,
-            false),
+        getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false),
         regionName));
 
     // Publish some entries
@@ -316,8 +318,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // stops normally
     final String durableClientId = getName() + "_client";
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId)));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId)));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -332,8 +334,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     VM durableClient2VM = this.publisherClientVM;
     final String durableClientId2 = getName() + "_client2";
     durableClient2VM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClient2VM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId2)));
+        getClientPool(getServerHostName(durableClient2VM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId2)));
 
     // Send clientReady message
     durableClient2VM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -404,8 +406,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final int durableClientTimeout = 60; // keep the client alive for 60 seconds
     // final boolean durableClientKeepAlive = true; // keep the client alive when it stops normally
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         Boolean.TRUE));
 
@@ -447,10 +448,9 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     });
 
     // Start normal publisher client
-    this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), server1Port,
-            server2Port, false),
-        regionName));
+    this.publisherClientVM.invoke(() -> CacheServerTestUtil
+        .createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()),
+            server1Port, server2Port, false), regionName));
 
     // Publish some entries
     final int numberOfEntries = 10;
@@ -496,8 +496,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Re-start the durable client
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
 
     // Send clientReady message
@@ -565,9 +564,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final int durableClientTimeout = 60; // keep the client alive for 60 seconds
     // final boolean durableClientKeepAlive = true; // keep the client alive when it stops normally
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
-        Boolean.TRUE));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId, durableClientTimeout), Boolean.TRUE));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -595,8 +593,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     VM durableClient2VM = this.server2VM;
     final String durableClientId2 = getName() + "_client2";
     durableClient2VM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClient2VM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId2, durableClientTimeout),
+        getClientPool(getServerHostName(durableClient2VM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId2, durableClientTimeout),
         Boolean.TRUE));
 
     // Send clientReady message
@@ -648,8 +646,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Start normal publisher client
     this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), serverPort,
-            false),
+        getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false),
         regionName));
 
     // Publish some entries
@@ -726,8 +723,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Re-start durable client 1
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
 
     // Send clientReady message
     this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -739,8 +736,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Re-start durable client 2
     durableClient2VM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClient2VM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId2), Boolean.TRUE));
+        getClientPool(getServerHostName(durableClient2VM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId2), Boolean.TRUE));
 
     // Send clientReady message
     durableClient2VM.invoke(new CacheSerializableRunnable("Send clientReady") {
@@ -798,8 +795,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final int durableClientTimeout = 60; // keep the client alive for 60 seconds
     // final boolean durableClientKeepAlive = true; // keep the client alive when it stops normally
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         Boolean.TRUE));
 
@@ -863,10 +859,9 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
         new Integer(server2Port)));
 
     // Start normal publisher client
-    this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), server1Port,
-            server2Port, false),
-        regionName));
+    this.publisherClientVM.invoke(() -> CacheServerTestUtil
+        .createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()),
+            server1Port, server2Port, false), regionName));
 
     // Publish some entries
     final int numberOfEntries = 10;
@@ -894,8 +889,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // Re-start the durable client that is kept alive on the server when it stops
     // normally
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         Boolean.TRUE));
 
@@ -978,8 +972,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final String durableClientId = getName() + "_client";
     // make the client use ClientCacheFactory so it will have a default pool
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createClientCache(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), serverPort, true),
-        regionName, getClientDistributedSystemProperties(durableClientId)));
+        getClientPool(getServerHostName(durableClientVM.getHost()), serverPort, true), regionName,
+        getClientDistributedSystemProperties(durableClientId)));
 
     // verify that readyForEvents has not yet been called on the client's default pool
     this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@@ -1069,39 +1063,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
           CacheServerTestUtil.getCache().readyForEvents();
         }
       });
-
-      // Durable client registers durable cq on server
-      this.durableClientVM.invoke(new CacheSerializableRunnable("Register Cq") {
-        @Override
-        public void run2() throws CacheException {
-          // Get the region
-          Region region = CacheServerTestUtil.getCache().getRegion(regionName);
-          assertNotNull(region);
-
-          // Create CQ Attributes.
-          CqAttributesFactory cqAf = new CqAttributesFactory();
-
-          // Initialize and set CqListener.
-          CqListener[] cqListeners = {new CacheServerTestUtil.ControlCqListener()};
-          cqAf.initCqListeners(cqListeners);
-          CqAttributes cqa = cqAf.create();
-
-          // Create cq's
-          // Get the query service for the Pool
-          QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
-
-          try {
-            CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
-            query.execute();
-          } catch (CqExistsException e) {
-            fail("Failed due to ", e);
-          } catch (CqException e) {
-            fail("Failed due to ", e);
-          } catch (RegionNotFoundException e) {
-            fail("Could not find specified region:" + regionName + ":", e);
-          }
-        }
-      });
+      registerDurableCq(cqName);
 
       // Verify durable client on server1
       this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@@ -1120,8 +1082,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
       // Start normal publisher client
       this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-          getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), serverPort,
-              false),
+          getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false),
           regionName));
 
       // Publish some entries
@@ -1262,6 +1223,41 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     }
   }
 
+  protected void registerDurableCq(final String cqName) {
+    // Durable client registers durable cq on server
+    this.durableClientVM.invoke(new CacheSerializableRunnable("Register Cq") {
+      @Override
+      public void run2() throws CacheException {
+        // Get the region
+        Region region = CacheServerTestUtil.getCache().getRegion(regionName);
+        assertNotNull(region);
+
+        // Create CQ Attributes.
+        CqAttributesFactory cqAf = new CqAttributesFactory();
+
+        // Initialize and set CqListener.
+        CqListener[] cqListeners = {new CacheServerTestUtil.ControlCqListener()};
+        cqAf.initCqListeners(cqListeners);
+        CqAttributes cqa = cqAf.create();
+
+        // Create cq's
+        // Get the query service for the Pool
+        QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
+
+        try {
+          CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
+          query.execute();
+        } catch (CqExistsException e) {
+          fail("Failed due to ", e);
+        } catch (CqException e) {
+          fail("Failed due to ", e);
+        } catch (RegionNotFoundException e) {
+          fail("Could not find specified region:" + regionName + ":", e);
+        }
+      }
+    });
+  }
+
   private void setPeriodicACKObserver(VM vm) {
     CacheSerializableRunnable cacheSerializableRunnable =
         new CacheSerializableRunnable("Set ClientServerObserver") {
@@ -1359,8 +1355,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Start normal publisher client
     this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(publisherClientVM.getHost()), serverPort,
-            false),
+        getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false),
         regionName));
 
     // Publish some entries
@@ -3282,8 +3277,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // final boolean durableClientKeepAlive = true; // keep the client alive when it stops normally
     final String durableClientId = getName() + "_client";
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         Boolean.TRUE));
 
@@ -3355,8 +3349,7 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     // Start up the client again. This time initialize it so that it is not kept
     // alive on the servers when it stops normally.
     this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port, true),
         regionName, getClientDistributedSystemProperties(durableClientId), Boolean.TRUE));
 
     // Send clientReady message
@@ -3424,10 +3417,9 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
         .invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)));
 
     // Start normal publisher client
-    this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(
-        getClientPool(NetworkUtils.getServerHostName(this.publisherClientVM.getHost()), server1Port,
-            server2Port, false),
-        this.regionName));
+    this.publisherClientVM.invoke(() -> CacheServerTestUtil
+        .createCacheClient(getClientPool(getServerHostName(this.publisherClientVM.getHost()),
+            server1Port, server2Port, false), this.regionName));
 
     // Create an entry
     publishEntries(1);
@@ -3436,8 +3428,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     final String durableClientId = getName() + "_client";
     final int durableClientTimeout = 60; // keep the client alive for 60 seconds
     restartDurableClient(new Object[] {
-        getClientPool(NetworkUtils.getServerHostName(this.durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(this.durableClientVM.getHost()), server1Port, server2Port,
+            true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         true});
 
@@ -3469,8 +3461,8 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
 
     // Restart durable client
     restartDurableClient(new Object[] {
-        getClientPool(NetworkUtils.getServerHostName(this.durableClientVM.getHost()), server1Port,
-            server2Port, true),
+        getClientPool(getServerHostName(this.durableClientVM.getHost()), server1Port, server2Port,
+            true),
         regionName, getClientDistributedSystemProperties(durableClientId, durableClientTimeout),
         true});
 
@@ -3499,6 +3491,74 @@ public class DurableClientSimpleDUnitTest extends DurableClientTestCase {
     return registered;
   }
 
+  @Test
+  public void testGetAllDurableCqsFromServer() {
+    // Start server 1
+    final int server1Port = ((Integer) this.server1VM.invoke(CacheServerTestUtil.class,
+        "createCacheServer", new Object[] {regionName, new Boolean(true)})).intValue();
+
+    // Start server 2
+    final int server2Port = ((Integer) this.server2VM.invoke(CacheServerTestUtil.class,
+        "createCacheServer", new Object[] {regionName, new Boolean(true)})).intValue();
+
+    // Start a durable client
+    final String durableClientId = getName() + "_client";
+    this.durableClientVM.invoke(CacheServerTestUtil.class, "createCacheClient",
+        new Object[] {
+            getClientPool(getServerHostName(durableClientVM.getHost()), server1Port, server2Port,
+                true, 0),
+            regionName, getClientDistributedSystemProperties(durableClientId, 60), Boolean.TRUE});
+
+    // Send clientReady message
+    this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
+      public void run2() throws CacheException {
+        CacheServerTestUtil.getCache().readyForEvents();
+      }
+    });
+
+    // Register durable CQ
+    String cqName = getName() + "_cq";
+    registerDurableCq(cqName);
+
+    // Execute getAllDurableCqsFromServer on the client
+    List<String> durableCqNames =
+        (List<String>) this.durableClientVM.invoke(() -> getAllDurableCqsFromServer());
+
+    this.durableClientVM.invoke(() -> verifyDurableCqs(durableCqNames, cqName));
+
+    // Stop the durable client
+    this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
+
+    // Stop the servers
+    this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
+    this.server2VM.invoke(() -> CacheServerTestUtil.closeCache());
+  }
+
+  public static List<String> getAllDurableCqsFromServer() throws CqException {
+    QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
+    return queryService.getAllDurableCqsFromServer();
+  }
+
+  public static void verifyDurableCqs(final List<String> durableCqNames,
+      final String registeredCqName) {
+    // Verify the number of durable CQ names is one, and it matches the registered name
+    assertEquals(1, durableCqNames.size());
+    String returnedCqName = durableCqNames.get(0);
+    assertEquals(registeredCqName, returnedCqName);
+
+    // Get client's primary server
+    PoolImpl pool = CacheServerTestUtil.getPool();
+    ServerLocation primaryServerLocation = pool.getPrimary();
+
+    // Verify the primary server was used and no other server was used
+    Map<ServerLocation, ConnectionStats> statistics = pool.getEndpointManager().getAllStats();
+    for (Map.Entry<ServerLocation, ConnectionStats> entry : statistics.entrySet()) {
+      int expectedGetDurableCqInvocations = entry.getKey().equals(primaryServerLocation) ? 1 : 0;
+      assertEquals(expectedGetDurableCqInvocations, entry.getValue().getGetDurableCqs());
+    }
+  }
+
+
   private void waitForEventsRemovedByQueueRemovalMessage(VM secondaryServerVM,
       final String durableClientId, final int numEvents) {
     secondaryServerVM.invoke(() -> DurableClientSimpleDUnitTest


[06/16] geode git commit: GEODE-2185: Index not used with parameterized query

Posted by kl...@apache.org.
GEODE-2185: Index not used with parameterized query


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

Branch: refs/heads/feature/GEODE-1027
Commit: 7fb0e68b130317ac3cce0fa1ca8f39fb0006720f
Parents: c2b1c8b
Author: Jason Huynh <hu...@gmail.com>
Authored: Tue Dec 6 10:21:01 2016 -0800
Committer: Jason Huynh <hu...@gmail.com>
Committed: Wed Dec 7 09:52:15 2016 -0800

----------------------------------------------------------------------
 .../query/internal/CompiledBindArgument.java    | 18 ++++--
 .../internal/IndexTrackingQueryObserver.java    | 33 ++++++-----
 .../geode/cache/query/data/Instrument.java      | 60 ++++++++++++++++++++
 .../geode/cache/query/data/TradingLine.java     | 41 +++++++++++++
 .../MapRangeIndexMaintenanceJUnitTest.java      | 49 ++++++++++++++++
 5 files changed, 182 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/7fb0e68b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledBindArgument.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledBindArgument.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledBindArgument.java
index cb9218b..106d389 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledBindArgument.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/CompiledBindArgument.java
@@ -46,13 +46,19 @@ public class CompiledBindArgument extends AbstractCompiledValue {
   public void generateCanonicalizedExpression(StringBuffer clauseBuffer, ExecutionContext context)
       throws AmbiguousNameException, TypeMismatchException, NameResolutionException {
 
-    Object bindArg;
-    if (context.isBindArgsSet()
-        && (bindArg = context.getBindArgument(this.index)) instanceof Region) {
-      clauseBuffer.insert(0, ((Region) bindArg).getFullPath());
-    } else {
-      clauseBuffer.insert(0, "$" + this.index);
+    // When compiling a new query, a context is created where there are no bind arguments at this
+    // point
+    if (context.isBindArgsSet()) {
+      Object bindArgumentValue = context.getBindArgument(this.index);
+      if (bindArgumentValue instanceof Region) {
+        clauseBuffer.insert(0, ((Region) bindArgumentValue).getFullPath());
+      } else if (bindArgumentValue instanceof String) {
+        clauseBuffer.insert(0, '\'').insert(0, bindArgumentValue).insert(0, '\'');
+      } else {
+        super.generateCanonicalizedExpression(clauseBuffer, context);
+      }
     }
+
   }
 
   public Object evaluate(ExecutionContext context) {

http://git-wip-us.apache.org/repos/asf/geode/blob/7fb0e68b/geode-core/src/main/java/org/apache/geode/cache/query/internal/IndexTrackingQueryObserver.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/cache/query/internal/IndexTrackingQueryObserver.java b/geode-core/src/main/java/org/apache/geode/cache/query/internal/IndexTrackingQueryObserver.java
index a643b59..da223d5 100644
--- a/geode-core/src/main/java/org/apache/geode/cache/query/internal/IndexTrackingQueryObserver.java
+++ b/geode-core/src/main/java/org/apache/geode/cache/query/internal/IndexTrackingQueryObserver.java
@@ -40,6 +40,7 @@ import org.apache.geode.internal.cache.PartitionedRegionQueryEvaluator.TestHook;
 public class IndexTrackingQueryObserver extends QueryObserverAdapter {
 
   private static final ThreadLocal indexInfo = new ThreadLocal();
+  private static final ThreadLocal lastKeyUsed = new ThreadLocal();
   private static final ThreadLocal lastIndexUsed = new ThreadLocal();
   private volatile TestHook th;
 
@@ -50,15 +51,7 @@ public class IndexTrackingQueryObserver extends QueryObserverAdapter {
       this.indexInfo.set(indexMap);
     }
     IndexInfo iInfo;
-    String indexName;
-    // Dont create new IndexInfo if one is already there in map for aggregation
-    // of results later for whole partition region on this node.
-    if ((index instanceof MapRangeIndex || index instanceof CompactMapRangeIndex)
-        && key instanceof Object[]) {
-      indexName = index.getName() + "-" + ((Object[]) key)[1];
-    } else {
-      indexName = index.getName();
-    }
+    String indexName = getIndexName(index, key);
     if (indexMap.containsKey(indexName)) {
       iInfo = indexMap.get(indexName);
     } else {
@@ -67,6 +60,7 @@ public class IndexTrackingQueryObserver extends QueryObserverAdapter {
     iInfo.addRegionId(index.getRegion().getFullPath());
     indexMap.put(indexName, iInfo);
     this.lastIndexUsed.set(index);
+    this.lastKeyUsed.set(key);
     if (th != null) {
       th.hook(1);
     }
@@ -108,19 +102,32 @@ public class IndexTrackingQueryObserver extends QueryObserverAdapter {
     // append the size of the lookup results (and bucket id if its an Index on bucket)
     // to IndexInfo results Map.
     Map indexMap = (Map) this.indexInfo.get();
-    if (lastIndexUsed.get() != null) {
-      IndexInfo indexInfo = (IndexInfo) indexMap.get(((Index) this.lastIndexUsed.get()).getName());
+    Index index = (Index) lastIndexUsed.get();
+    if (index != null) {
+      IndexInfo indexInfo = (IndexInfo) indexMap.get(getIndexName(index, this.lastKeyUsed.get()));
       if (indexInfo != null) {
-        indexInfo.getResults().put(((Index) this.lastIndexUsed.get()).getRegion().getFullPath(),
-            new Integer(results.size()));
+        indexInfo.getResults().put(index.getRegion().getFullPath(), new Integer(results.size()));
       }
     }
     this.lastIndexUsed.set(null);
+    this.lastKeyUsed.set(null);
     if (th != null) {
       th.hook(3);
     }
   }
 
+  private String getIndexName(Index index, Object key) {
+    String indexName;
+    if ((index instanceof MapRangeIndex || index instanceof CompactMapRangeIndex)
+        && key instanceof Object[]) {
+      indexName = index.getName() + "-" + ((Object[]) key)[1];
+    } else {
+      indexName = index.getName();
+    }
+    return indexName;
+  }
+
+
   /**
    * This should be called only when one query execution on one gemfire node is done. NOT for each
    * buckets.

http://git-wip-us.apache.org/repos/asf/geode/blob/7fb0e68b/geode-core/src/test/java/org/apache/geode/cache/query/data/Instrument.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/data/Instrument.java b/geode-core/src/test/java/org/apache/geode/cache/query/data/Instrument.java
new file mode 100644
index 0000000..131efa6
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/data/Instrument.java
@@ -0,0 +1,60 @@
+/*
+ * 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 org.apache.geode.cache.query.data;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class Instrument implements Serializable {
+
+  private String id;
+
+  private List<TradingLine> tradingLines;
+
+  public Instrument(String id) {
+    this.id = id;
+    this.tradingLines = new ArrayList<>();
+  }
+
+  public String getId() {
+    return this.id;
+  }
+
+  public void addTradingLine(TradingLine tl) {
+    this.tradingLines.add(tl);
+  }
+
+  // This method is needed for the query
+  public List<TradingLine> getTradingLines() {
+    return this.tradingLines;
+  }
+
+  public String toString() {
+    return new StringBuilder().append(getClass().getSimpleName()).append("[").append("id=")
+        .append(this.id).append("; tradingLines=").append(this.tradingLines).append("]").toString();
+  }
+
+  public static Instrument getInstrument(String id) {
+    Instrument inst = new Instrument(id);
+    for (int i = 0; i < 5; i++) {
+      TradingLine tl = new TradingLine();
+      tl.addAlternateReference("SOME_KEY", "SOME_VALUE");
+      tl.addAlternateReference("SOME_OTHER_KEY", "SOME_OTHER_VALUE");
+      inst.addTradingLine(tl);
+    }
+    return inst;
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/7fb0e68b/geode-core/src/test/java/org/apache/geode/cache/query/data/TradingLine.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/data/TradingLine.java b/geode-core/src/test/java/org/apache/geode/cache/query/data/TradingLine.java
new file mode 100644
index 0000000..55a5f43
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/data/TradingLine.java
@@ -0,0 +1,41 @@
+/*
+ * 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 org.apache.geode.cache.query.data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class TradingLine {
+
+  private Map<String, String> alternateReferences;
+
+  public TradingLine() {
+    this.alternateReferences = new HashMap<String, String>();
+  }
+
+  public void addAlternateReference(String key, String value) {
+    this.alternateReferences.put(key, value);
+  }
+
+  // This method is needed for the query
+  public Map<String, String> getAlternateReferences() {
+    return this.alternateReferences;
+  }
+
+  public String toString() {
+    return new StringBuilder().append(getClass().getSimpleName()).append("[")
+        .append("; alternateReferences=").append(this.alternateReferences).append("]").toString();
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode/blob/7fb0e68b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
index 5159f89..988defb 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/internal/index/MapRangeIndexMaintenanceJUnitTest.java
@@ -21,8 +21,13 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
+import java.util.Collection;
 import java.util.HashMap;
 
+import org.apache.geode.cache.query.Query;
+import org.apache.geode.cache.query.data.Instrument;
+import org.apache.geode.cache.query.internal.IndexTrackingQueryObserver;
+import org.apache.geode.cache.query.internal.QueryObserverHolder;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
@@ -65,6 +70,50 @@ public class MapRangeIndexMaintenanceJUnitTest {
   }
 
   @Test
+  public void testMapIndexIsUsedWithBindKeyParameter() throws Exception {
+    // Create Region
+    region =
+        CacheUtils.getCache().createRegionFactory(RegionShortcut.REPLICATE).create("instrument");
+
+    // Initialize observer
+    MyQueryObserverAdapter observer = new MyQueryObserverAdapter();
+    QueryObserverHolder.setInstance(observer);
+
+    // Create map index
+    qs = CacheUtils.getQueryService();
+    qs.createIndex(INDEX_NAME, "tl.alternateReferences['SOME_KEY', 'SOME_OTHER_KEY']",
+        "/instrument i, i.tradingLines tl");
+
+    // Add instruments
+    int numInstruments = 20;
+    for (int i = 0; i < numInstruments; i++) {
+      String key = String.valueOf(i);
+      Object value = Instrument.getInstrument(key);
+      region.put(key, value);
+    }
+
+    // Execute query
+    Query query = qs.newQuery(
+        "<trace> select distinct i from /instrument i, i.tradingLines t where t.alternateReferences[$1]='SOME_VALUE'");
+    SelectResults results = (SelectResults) query.execute(new Object[] {"SOME_KEY"});
+
+    // Verify index was used
+    assertTrue(observer.indexUsed);
+
+    // Verify the results size
+    assertEquals(numInstruments, results.size());
+  }
+
+  private static class MyQueryObserverAdapter extends IndexTrackingQueryObserver {
+    public boolean indexUsed = false;
+
+    public void afterIndexLookup(Collection results) {
+      super.afterIndexLookup(results);
+      indexUsed = true;
+    }
+  }
+
+  @Test
   public void testNullMapKeysInIndexOnLocalRegionForCompactMap() throws Exception {
 
     // Create Partition Region


[13/16] geode git commit: GEODE-734: Remove txt file restriction when exporting stack traces

Posted by kl...@apache.org.
GEODE-734: Remove txt file restriction when exporting stack traces

Adding throws clause to signature instead of catching it in Test.

Separating test scenarios into multiple test cases. Creating files in
TemporaryFolder.

Applying spotless checks

Updated export stack-traces in controller. Removed compulsory file
option. If file is not provided then name is generated. Added one
boolean option fail-if-file-present, if true and file already exists
then command will fail.

Updated Offline help file.

Added test cases to verify new added options

Removed compulsory file option. If file is not provided then name is
generated. Added one boolean option fail-if-file-present, if true and
file already exists then command will fail.

Added message warning user about possible overwrite of file if already
present.

Added test to check if non txt extension file is allowed.

This closes #297


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

Branch: refs/heads/feature/GEODE-1027
Commit: 903135115a0466d86fa663e965ace3ff47eba6b4
Parents: 67dafd8
Author: Deepak Dixit <de...@gmail.com>
Authored: Sat Nov 26 19:11:52 2016 +0530
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Dec 8 08:44:52 2016 -0800

----------------------------------------------------------------------
 .../cli/commands/MiscellaneousCommands.java     |  50 +++++-
 .../internal/cli/i18n/CliStrings.java           |  10 +-
 .../MiscellaneousCommandsController.java        |  15 +-
 .../cli/commands/ShowStackTraceDUnitTest.java   | 158 ++++++++++++++++---
 .../cli/commands/golden-help-offline.properties |   9 +-
 5 files changed, 204 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/90313511/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java
index 9acdcf1..4ef710c 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/MiscellaneousCommands.java
@@ -1023,22 +1023,31 @@ public class MiscellaneousCommands implements CommandMarker {
           optionContext = ConverterHint.ALL_MEMBER_IDNAME,
           help = CliStrings.EXPORT_STACKTRACE__GROUP) String group,
 
-      @CliOption(key = CliStrings.EXPORT_STACKTRACE__FILE, mandatory = true,
-          help = CliStrings.EXPORT_STACKTRACE__FILE__HELP) String fileName) {
+      @CliOption(key = CliStrings.EXPORT_STACKTRACE__FILE,
+          help = CliStrings.EXPORT_STACKTRACE__FILE__HELP) String fileName,
+
+      @CliOption(key = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT,
+          unspecifiedDefaultValue = "false",
+          help = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT__HELP) boolean failIfFilePresent) {
 
     Result result = null;
+    StringBuffer filePrefix = new StringBuffer("stacktrace");
     try {
+      if (fileName == null) {
+        fileName = filePrefix.append("_").append(System.currentTimeMillis()).toString();
+      }
+      final File outFile = new File(fileName);
+      if (outFile.exists() && failIfFilePresent) {
+        return ResultBuilder.createShellClientErrorResult(CliStrings.format(
+            CliStrings.EXPORT_STACKTRACE__ERROR__FILE__PRESENT, outFile.getCanonicalPath()));
+      }
+
       Cache cache = CacheFactory.getAnyInstance();
       GemFireCacheImpl gfeCacheImpl = (GemFireCacheImpl) cache;
       InternalDistributedSystem ads = gfeCacheImpl.getSystem();
 
       InfoResultData resultData = ResultBuilder.createInfoResultData();
 
-      if (!fileName.endsWith(".txt")) {
-        return ResultBuilder
-            .createUserErrorResult(CliStrings.format(CliStrings.INVALID_FILE_EXTENTION, ".txt"));
-      }
-
       Map<String, byte[]> dumps = new HashMap<String, byte[]>();
       Set<DistributedMember> targetMembers = null;
 
@@ -1074,6 +1083,33 @@ public class MiscellaneousCommands implements CommandMarker {
     return result;
   }
 
+  /**
+   * Interceptor used by gfsh to intercept execution of shutdownall.
+   */
+  public static class ExportStackTraceInterceptor extends AbstractCliAroundInterceptor {
+    @Override
+    public Result preExecution(GfshParseResult parseResult) {
+
+      Map<String, String> paramValueMap = parseResult.getParamValueStrings();
+      String fileName = paramValueMap.get(CliStrings.EXPORT_STACKTRACE__FILE);
+
+      Response response = readYesNo(
+          CliStrings.format(CliStrings.EXPORT_STACKTRACE_WARN_USER, fileName), Response.YES);
+      if (response == Response.NO) {
+        return ResultBuilder
+            .createShellClientAbortOperationResult(CliStrings.EXPORT_STACKTRACE_MSG_ABORTING);
+      } else {
+        // we dont to show any info result
+        return ResultBuilder.createInfoResult("");
+      }
+    }
+
+    @Override
+    public Result postExecution(GfshParseResult parseResult, Result commandResult) {
+      return commandResult;
+    }
+  }
+
   /***
    * Writes the Stack traces member-wise to a text file
    * 

http://git-wip-us.apache.org/repos/asf/geode/blob/90313511/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
index 9aaef4d..68dd438 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/i18n/CliStrings.java
@@ -1427,12 +1427,18 @@ public class CliStrings {
   public static final String EXPORT_STACKTRACE__FILE = "file";
   public static final String EXPORT_STACKTRACE__FILE__HELP =
       "Name of the file to which the stack traces will be written.";
+  public static final String EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT = "abort-if-file-exists";
+  public static final String EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT__HELP =
+      "Abort the command if already exists at locator directory";
   public static final String EXPORT_STACKTRACE__MEMBER__NOT__FOUND = "Member not found";
   public static final String EXPORT_STACKTRACE__SUCCESS = "stack-trace(s) exported to file: {0}";
   public static final String EXPORT_STACKTRACE__ERROR = "Error occured while showing stack-traces";
+  public static final String EXPORT_STACKTRACE__ERROR__FILE__PRESENT =
+      "Error occured while exporting stack-traces, file {0} already present";
   public static final String EXPORT_STACKTRACE__HOST = "On host : ";
-  public static final String EXPORT_STACKTRACE__INVALID_FILE_TYPE =
-      "Invalid file extension. File must be a text file (.txt)";
+  public static final String EXPORT_STACKTRACE_WARN_USER =
+      "If file {0} already present at locator directory it will be overwritten, do you want to continue?";
+  public static final String EXPORT_STACKTRACE_MSG_ABORTING = "Aborting export stack-traces";
 
   /* 'gc' command */
   public static final String GC = "gc";

http://git-wip-us.apache.org/repos/asf/geode/blob/90313511/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
index a0fc1e3..ac912c8 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/web/controllers/MiscellaneousCommandsController.java
@@ -100,14 +100,18 @@ public class MiscellaneousCommandsController extends AbstractCommandsController
   @RequestMapping(method = RequestMethod.GET, value = "/stacktraces")
   @ResponseBody
   public String exportStackTraces(
-      @RequestParam(value = CliStrings.EXPORT_STACKTRACE__FILE) final String file,
+      @RequestParam(value = CliStrings.EXPORT_STACKTRACE__FILE, required = false) final String file,
       @RequestParam(value = CliStrings.EXPORT_STACKTRACE__GROUP,
           required = false) final String groupName,
       @RequestParam(value = CliStrings.EXPORT_STACKTRACE__MEMBER,
-          required = false) final String memberNameId) {
+          required = false) final String memberNameId,
+      @RequestParam(value = CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT,
+          required = false) final boolean failIfFilePresent) {
     CommandStringBuilder command = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
 
-    command.addOption(CliStrings.EXPORT_STACKTRACE__FILE, decode(file));
+    if (hasValue(file)) {
+      command.addOption(CliStrings.EXPORT_STACKTRACE__FILE, decode(file));
+    }
 
     if (hasValue(groupName)) {
       command.addOption(CliStrings.EXPORT_STACKTRACE__GROUP, groupName);
@@ -117,6 +121,11 @@ public class MiscellaneousCommandsController extends AbstractCommandsController
       command.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, memberNameId);
     }
 
+    if (hasValue(failIfFilePresent)) {
+      command.addOption(CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT,
+          String.valueOf(failIfFilePresent));
+    }
+
     return processCommand(command.toString());
   }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/90313511/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
index f5d6cde..dda50f6 100644
--- a/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/management/internal/cli/commands/ShowStackTraceDUnitTest.java
@@ -15,26 +15,27 @@
 package org.apache.geode.management.internal.cli.commands;
 
 import static org.apache.geode.distributed.ConfigurationProperties.*;
+import static org.apache.geode.test.dunit.Assert.*;
+import static org.apache.geode.test.dunit.LogWriterUtils.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Properties;
 
 import org.apache.geode.management.cli.Result.Status;
 import org.apache.geode.management.internal.cli.i18n.CliStrings;
+import org.apache.geode.management.internal.cli.json.GfJsonException;
 import org.apache.geode.management.internal.cli.result.CommandResult;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.Host;
 import org.apache.geode.test.dunit.SerializableRunnable;
 import org.apache.geode.test.dunit.VM;
 import org.apache.geode.test.junit.categories.DistributedTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTemporaryFolder;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
-
-import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
-import static org.apache.geode.test.dunit.Assert.assertFalse;
-import static org.apache.geode.test.dunit.Assert.assertTrue;
-import static org.apache.geode.test.dunit.LogWriterUtils.getLogWriter;
+import org.junit.rules.TemporaryFolder;
 
 /***
  * DUnit test for 'show stack-trace' command
@@ -44,6 +45,9 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
 
   private static final long serialVersionUID = 1L;
 
+  @Rule
+  public TemporaryFolder workDirectory = new SerializableTemporaryFolder();
+
   private void createCache(Properties props) {
     getSystem(props);
     getCache();
@@ -90,9 +94,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
   public void testExportStacktrace() throws ClassNotFoundException, IOException {
     setupSystem();
 
-    File allStacktracesFile = new File("allStackTraces.txt");
-    allStacktracesFile.createNewFile();
-    allStacktracesFile.deleteOnExit();
+    File allStacktracesFile = workDirectory.newFile("allStackTraces.txt");
     CommandStringBuilder csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
     csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, allStacktracesFile.getCanonicalPath());
     String commandString = csb.toString();
@@ -101,9 +103,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
     getLogWriter().info("Output : \n" + commandResultToString(commandResult));
     assertTrue(commandResult.getStatus().equals(Status.OK));
 
-    File mgrStacktraceFile = new File("managerStacktrace.txt");
-    mgrStacktraceFile.createNewFile();
-    mgrStacktraceFile.deleteOnExit();
+    File mgrStacktraceFile = workDirectory.newFile("managerStacktrace.txt");
     csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
     csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, mgrStacktraceFile.getCanonicalPath());
     csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "Manager");
@@ -113,9 +113,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
     getLogWriter().info("Output : \n" + commandResultToString(commandResult));
     assertTrue(commandResult.getStatus().equals(Status.OK));
 
-    File serverStacktraceFile = new File("serverStacktrace.txt");
-    serverStacktraceFile.createNewFile();
-    serverStacktraceFile.deleteOnExit();
+    File serverStacktraceFile = workDirectory.newFile("serverStacktrace.txt");
     csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
     csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, serverStacktraceFile.getCanonicalPath());
     csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "Server");
@@ -125,9 +123,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
     getLogWriter().info("Output : \n" + commandResultToString(commandResult));
     assertTrue(commandResult.getStatus().equals(Status.OK));
 
-    File groupStacktraceFile = new File("groupstacktrace.txt");
-    groupStacktraceFile.createNewFile();
-    groupStacktraceFile.deleteOnExit();
+    File groupStacktraceFile = workDirectory.newFile("groupstacktrace.txt");
     csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
     csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, groupStacktraceFile.getCanonicalPath());
     csb.addOption(CliStrings.EXPORT_STACKTRACE__GROUP, "G2");
@@ -137,9 +133,7 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
     getLogWriter().info("Output : \n" + commandResultToString(commandResult));
     assertTrue(commandResult.getStatus().equals(Status.OK));
 
-    File wrongStackTraceFile = new File("wrongStackTrace.txt");
-    wrongStackTraceFile.createNewFile();
-    wrongStackTraceFile.deleteOnExit();
+    File wrongStackTraceFile = workDirectory.newFile("wrongStackTrace.txt");
     csb = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
     csb.addOption(CliStrings.EXPORT_STACKTRACE__FILE, wrongStackTraceFile.getCanonicalPath());
     csb.addOption(CliStrings.EXPORT_STACKTRACE__MEMBER, "WrongMember");
@@ -149,4 +143,120 @@ public class ShowStackTraceDUnitTest extends CliCommandTestBase {
     getLogWriter().info("Output : \n" + commandResultToString(commandResult));
     assertFalse(commandResult.getStatus().equals(Status.OK));
   }
+
+  /***
+   * Tests the behavior of the show stack-trace command to verify that files with any extension are
+   * allowed Refer: GEODE-734
+   *
+   * @throws ClassNotFoundException
+   * @throws IOException
+   */
+  @Test
+  public void testExportStacktraceWithNonTXTFile() throws ClassNotFoundException, IOException {
+    setupSystem();
+
+    // Test non txt extension file is allowed
+    File stacktracesFile = workDirectory.newFile("allStackTraces.log");
+    CommandStringBuilder commandStringBuilder =
+        new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
+    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE,
+        stacktracesFile.getCanonicalPath());
+    String exportCommandString = commandStringBuilder.toString();
+    getLogWriter().info("CommandString : " + exportCommandString);
+    CommandResult exportCommandResult = executeCommand(exportCommandString);
+    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
+    assertTrue(exportCommandResult.getStatus().equals(Status.OK));
+
+    // test file with-out any extension
+    File allStacktracesFile = workDirectory.newFile("allStackTraces");
+    commandStringBuilder = new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
+    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE,
+        allStacktracesFile.getCanonicalPath());
+    exportCommandString = commandStringBuilder.toString();
+    getLogWriter().info("CommandString : " + exportCommandString);
+    exportCommandResult = executeCommand(exportCommandString);
+    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
+    assertTrue(exportCommandResult.getStatus().equals(Status.OK));
+  }
+
+  /***
+   * Tests the behavior of the show stack-trace command when file is already present and
+   * abort-if-file-exists option is set to false(which is default). As a result it should overwrite
+   * the file and return OK status
+   *
+   * @throws ClassNotFoundException
+   * @throws IOException
+   */
+  @Test
+  public void testExportStacktraceWhenFilePresent() throws ClassNotFoundException, IOException {
+    setupSystem();
+
+    // test pass although file present
+    File stacktracesFile = workDirectory.newFile("allStackTraces.log");
+    CommandStringBuilder commandStringBuilder =
+        new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
+    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE,
+        stacktracesFile.getCanonicalPath());
+    String exportCommandString = commandStringBuilder.toString();
+    getLogWriter().info("CommandString : " + exportCommandString);
+    CommandResult exportCommandResult = executeCommand(exportCommandString);
+    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
+    assertTrue(exportCommandResult.getStatus().equals(Status.OK));
+
+  }
+
+  /***
+   * Tests the behavior of the show stack-trace command when file is already present and when
+   * abort-if-file-exists option is set to true. As a result it should fail with ERROR status
+   *
+   * @throws ClassNotFoundException
+   * @throws IOException
+   */
+  @Test
+  public void testExportStacktraceFilePresentWithAbort()
+      throws ClassNotFoundException, IOException, GfJsonException {
+    setupSystem();
+
+    File stacktracesFile = workDirectory.newFile("allStackTraces.log");
+    CommandStringBuilder commandStringBuilder =
+        new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
+    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FILE,
+        stacktracesFile.getCanonicalPath());
+    commandStringBuilder.addOption(CliStrings.EXPORT_STACKTRACE__FAIL__IF__FILE__PRESENT,
+        Boolean.TRUE.toString());
+    String exportCommandString = commandStringBuilder.toString();
+    getLogWriter().info("CommandString : " + exportCommandString);
+    CommandResult exportCommandResult = executeCommand(exportCommandString);
+    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
+    assertTrue(exportCommandResult.getStatus().equals(Status.ERROR));
+    assertTrue(((String) exportCommandResult.getResultData().getGfJsonObject()
+        .getJSONObject("content").getJSONArray("message").get(0))
+            .contains("file " + stacktracesFile.getCanonicalPath() + " already present"));
+  }
+
+  /***
+   * Tests the behavior of the show stack-trace command when file option is not provided File should
+   * get auto-generated
+   *
+   * @throws ClassNotFoundException
+   * @throws IOException
+   */
+  @Test
+  public void testExportStacktraceAutoGenerateFile()
+      throws ClassNotFoundException, IOException, GfJsonException {
+    setupSystem();
+
+    // test auto generated file when file name is not provided
+    CommandStringBuilder commandStringBuilder =
+        new CommandStringBuilder(CliStrings.EXPORT_STACKTRACE);
+    String exportCommandString = commandStringBuilder.toString();
+    getLogWriter().info("CommandString : " + exportCommandString);
+    CommandResult exportCommandResult = executeCommand(exportCommandString);
+    getLogWriter().info("Output : \n" + commandResultToString(exportCommandResult));
+    assertTrue(exportCommandResult.getStatus().equals(Status.OK));
+    assertTrue(
+        ((String) exportCommandResult.getResultData().getGfJsonObject().getJSONObject("content")
+            .getJSONArray("message").get(0)).contains("stack-trace(s) exported to file:"));
+
+  }
 }

http://git-wip-us.apache.org/repos/asf/geode/blob/90313511/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
----------------------------------------------------------------------
diff --git a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
index f08a257..786dd40 100644
--- a/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
+++ b/geode-core/src/test/resources/org/apache/geode/management/internal/cli/commands/golden-help-offline.properties
@@ -1511,7 +1511,8 @@ IS AVAILABLE\n\
 SYNOPSIS\n\
 \ \ \ \ Export the stack trace for a member or members.\n\
 SYNTAX\n\
-\ \ \ \ export stack-traces --file=value [--member=value] [--group=value]\n\
+\ \ \ \ export stack-traces [--member=value] [--group=value] [--file=value]\n\
+\ \ \ \ [--abort-if-file-exists=value]\n\
 PARAMETERS\n\
 \ \ \ \ member\n\
 \ \ \ \ \ \ \ \ Export the stack trace for a member or members.\n\
@@ -1521,7 +1522,11 @@ PARAMETERS\n\
 \ \ \ \ \ \ \ \ Required: false\n\
 \ \ \ \ file\n\
 \ \ \ \ \ \ \ \ Name of the file to which the stack traces will be written.\n\
-\ \ \ \ \ \ \ \ Required: true\n\
+\ \ \ \ \ \ \ \ Required: false\n\
+\ \ \ \ abort-if-file-exists\n\
+\ \ \ \ \ \ \ \ Abort the command if already exists at locator directory\n\
+\ \ \ \ \ \ \ \ Required: false\n\
+\ \ \ \ \ \ \ \ Default (if the parameter is not specified): false\n\
 
 gc.help=\
 NAME\n\


[11/16] geode git commit: GEODE-2179 - Checking for disconnected connection in GatewaySenderMBean

Posted by kl...@apache.org.
GEODE-2179 - Checking for disconnected connection in GatewaySenderMBean

Making sure that the mbean returns false for isConnected if the gateway
is not actually connected to the remote side.


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

Branch: refs/heads/feature/GEODE-1027
Commit: 0494b31caf6f43cec85660fd8d939f2b1c6739c2
Parents: 1d34eeb
Author: Dan Smith <up...@apache.org>
Authored: Fri Dec 2 15:47:13 2016 -0800
Committer: Dan Smith <up...@apache.org>
Committed: Wed Dec 7 15:14:28 2016 -0800

----------------------------------------------------------------------
 .../wan/GatewaySenderEventRemoteDispatcher.java |  2 +-
 .../management/WANManagementDUnitTest.java      | 40 +++++++++++---------
 2 files changed, 24 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/0494b31c/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
index 16b1965..8da5613 100644
--- a/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
+++ b/geode-wan/src/main/java/org/apache/geode/internal/cache/wan/GatewaySenderEventRemoteDispatcher.java
@@ -802,7 +802,7 @@ public class GatewaySenderEventRemoteDispatcher implements GatewaySenderEventDis
 
   @Override
   public boolean isConnectedToRemote() {
-    return connection != null;
+    return connection != null && !connection.isDestroyed();
   }
 
   public void stop() {

http://git-wip-us.apache.org/repos/asf/geode/blob/0494b31c/geode-wan/src/test/java/org/apache/geode/management/WANManagementDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/management/WANManagementDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/management/WANManagementDUnitTest.java
index 9a6cc10..3cc37eb 100644
--- a/geode-wan/src/test/java/org/apache/geode/management/WANManagementDUnitTest.java
+++ b/geode-wan/src/test/java/org/apache/geode/management/WANManagementDUnitTest.java
@@ -19,12 +19,14 @@ import org.junit.Test;
 
 import static org.junit.Assert.*;
 
+import com.jayway.awaitility.Awaitility;
 import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase;
 import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.categories.FlakyTest;
 
 import java.util.Map;
+import java.util.concurrent.TimeUnit;
 
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -60,7 +62,17 @@ public class WANManagementDUnitTest extends ManagementTestBase {
   }
 
   @Test
-  public void testMBeanCallback() throws Exception {
+  public void testMBeanCallbackSerial() throws Exception {
+    testMBeanCallback(false);
+  }
+
+  @Test
+  public void testMBeanCallbackParallel() throws Exception {
+    testMBeanCallback(true);
+
+  }
+
+  public void testMBeanCallback(boolean parallel) throws Exception {
 
     VM nyLocator = getManagedNodeList().get(0);
     VM nyReceiver = getManagedNodeList().get(1);
@@ -103,10 +115,8 @@ public class WANManagementDUnitTest extends ManagementTestBase {
     puneSender.invoke(() -> WANTestBase.waitForSenderRunningState("pn"));
     managing.invoke(() -> WANTestBase.waitForSenderRunningState("pn"));
 
-
-
-    checkSenderMBean(puneSender, getTestMethodName() + "_PR");
-    checkSenderMBean(managing, getTestMethodName() + "_PR");
+    checkSenderMBean(puneSender, getTestMethodName() + "_PR", true);
+    checkSenderMBean(managing, getTestMethodName() + "_PR", true);
 
     checkReceiverMBean(nyReceiver);
 
@@ -119,6 +129,10 @@ public class WANManagementDUnitTest extends ManagementTestBase {
     checkProxySender(managing, puneMember);
     checkSenderNavigationAPIS(managing, puneMember);
 
+    nyReceiver.invoke(() -> WANTestBase.stopReceivers());
+
+    checkSenderMBean(puneSender, getTestMethodName() + "_PR", false);
+    checkSenderMBean(managing, getTestMethodName() + "_PR", false);
   }
 
   @Category(FlakyTest.class) // GEODE-1603
@@ -159,8 +173,7 @@ public class WANManagementDUnitTest extends ManagementTestBase {
     managing.invoke(() -> WANTestBase.createManagementCache(nyPort));
     startManagingNode(managing);
 
-
-    checkSenderMBean(puneSender, getTestMethodName() + "_PR");
+    checkSenderMBean(puneSender, getTestMethodName() + "_PR", true);
     checkReceiverMBean(nyReceiver);
 
     DistributedMember nyMember =
@@ -168,8 +181,6 @@ public class WANManagementDUnitTest extends ManagementTestBase {
 
     checkProxyReceiver(managing, nyMember);
     checkReceiverNavigationAPIS(managing, nyMember);
-
-
   }
 
 
@@ -187,19 +198,15 @@ public class WANManagementDUnitTest extends ManagementTestBase {
     Integer nyPort =
         (Integer) nyLocator.invoke(() -> WANTestBase.createFirstRemoteLocator(12, punePort));
 
-
-
     puneSender.invoke(() -> WANTestBase.createCache(punePort));
     managing.invoke(() -> WANTestBase.createManagementCache(punePort));
     startManagingNode(managing);
 
-
     puneSender.invoke(() -> WANTestBase.createAsyncEventQueue("pn", false, 100, 100, false, false,
         "puneSender", false));
     managing.invoke(() -> WANTestBase.createAsyncEventQueue("pn", false, 100, 100, false, false,
         "managing", false));
 
-
     puneSender.invoke(() -> WANTestBase
         .createReplicatedRegionWithAsyncEventQueue(getTestMethodName() + "_RR", "pn", false));
     managing.invoke(() -> WANTestBase
@@ -213,7 +220,6 @@ public class WANManagementDUnitTest extends ManagementTestBase {
     checkAsyncQueueMBean(puneSender);
     checkAsyncQueueMBean(managing);
 
-
     DistributedMember puneMember =
         (DistributedMember) puneSender.invoke(() -> WANManagementDUnitTest.getMember());
 
@@ -392,7 +398,6 @@ public class WANManagementDUnitTest extends ManagementTestBase {
   }
 
 
-
   /**
    * Checks whether a GatewayReceiverMBean is created or not
    * 
@@ -417,7 +422,7 @@ public class WANManagementDUnitTest extends ManagementTestBase {
    * @param vm reference to VM
    */
   @SuppressWarnings("serial")
-  protected void checkSenderMBean(final VM vm, final String regionPath) {
+  protected void checkSenderMBean(final VM vm, final String regionPath, boolean connected) {
     SerializableRunnable checkMBean = new SerializableRunnable("Check Sender MBean") {
       public void run() {
         Cache cache = GemFireCacheImpl.getInstance();
@@ -425,7 +430,8 @@ public class WANManagementDUnitTest extends ManagementTestBase {
 
         GatewaySenderMXBean bean = service.getLocalGatewaySenderMXBean("pn");
         assertNotNull(bean);
-        assertTrue(bean.isConnected());
+        Awaitility.await().atMost(1, TimeUnit.MINUTES)
+            .until(() -> assertEquals(connected, bean.isConnected()));
 
         ObjectName regionBeanName = service.getRegionMBeanName(
             cache.getDistributedSystem().getDistributedMember(), "/" + regionPath);


[12/16] geode git commit: GEODE-2112: UITests actually take screenshots on failure

Posted by kl...@apache.org.
GEODE-2112: UITests actually take screenshots on failure

This closes #301


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

Branch: refs/heads/feature/GEODE-1027
Commit: 67dafd8e81738a32e2fbf0140f310c9936346a20
Parents: 0494b31
Author: Jared Stewart <js...@pivotal.io>
Authored: Thu Dec 1 11:01:09 2016 -0800
Committer: Kirk Lund <kl...@apache.org>
Committed: Wed Dec 7 15:37:15 2016 -0800

----------------------------------------------------------------------
 .../tests/rules/ScreenshotOnFailureRule.java    |  2 +-
 .../tools/pulse/tests/rules/WebDriverRule.java  |  5 ----
 .../pulse/tests/ui/PulseAnonymousUserTest.java  | 28 +++++---------------
 .../tools/pulse/tests/ui/PulseAuthTest.java     |  6 ++++-
 .../pulse/tests/ui/PulseAutomatedTest.java      |  5 ++++
 .../tools/pulse/tests/ui/PulseNoAuthTest.java   |  6 ++++-
 6 files changed, 23 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java
index 3728015..91465f0 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/ScreenshotOnFailureRule.java
@@ -47,7 +47,7 @@ public class ScreenshotOnFailureRule extends TestWatcher {
       try {
         File screenshot = new File("build/screenshots/" + screenshotName + ".png");
         FileUtils.copyFile(tempFile, screenshot);
-        System.err.println("Screenshot saved to: " + screenshot.getCanonicalPath());
+        System.out.println("Screenshot saved to: " + screenshot.getCanonicalPath());
       } catch (IOException e) {
         throw new Error(e);
       }

http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java
index 03d91ab..e273557 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/rules/WebDriverRule.java
@@ -52,15 +52,10 @@ public class WebDriverRule extends ExternalResource {
     return this.driver;
   }
 
-  @Rule
-  public ScreenshotOnFailureRule screenshotOnFailureRule =
-      new ScreenshotOnFailureRule(() -> driver);
-
   public String getPulseURL() {
     return pulseUrl;
   }
 
-
   @Override
   protected void before() throws Throwable {
     setUpWebDriver();

http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAnonymousUserTest.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAnonymousUserTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAnonymousUserTest.java
index 4d255c8..680b11f 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAnonymousUserTest.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAnonymousUserTest.java
@@ -16,18 +16,13 @@
 
 package org.apache.geode.tools.pulse.tests.ui;
 
-import static org.assertj.core.api.Assertions.*;
+import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.InputStream;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import com.jayway.awaitility.Awaitility;
+import org.apache.geode.test.junit.categories.UITest;
+import org.apache.geode.tools.pulse.tests.rules.ScreenshotOnFailureRule;
 import org.apache.geode.tools.pulse.tests.rules.ServerRule;
 import org.apache.geode.tools.pulse.tests.rules.WebDriverRule;
-import org.junit.AfterClass;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.FixMethodOrder;
 import org.junit.Rule;
@@ -35,18 +30,7 @@ import org.junit.Test;
 import org.junit.experimental.categories.Category;
 import org.junit.runners.MethodSorters;
 import org.openqa.selenium.By;
-import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebElement;
-import org.openqa.selenium.phantomjs.PhantomJSDriver;
-import org.openqa.selenium.remote.DesiredCapabilities;
-import org.openqa.selenium.support.ui.ExpectedCondition;
-import org.openqa.selenium.support.ui.WebDriverWait;
-
-import org.apache.geode.internal.admin.SSLConfig;
-import org.apache.geode.management.internal.JettyHelper;
-import org.apache.geode.test.junit.categories.UITest;
-import org.apache.geode.tools.pulse.tests.PulseTestLocators;
-import org.apache.geode.tools.pulse.tests.Server;
 
 @Category(UITest.class)
 @FixMethodOrder(MethodSorters.JVM)
@@ -58,6 +42,10 @@ public class PulseAnonymousUserTest {
   @Rule
   public WebDriverRule webDriverRule = new WebDriverRule(serverRule.getPulseURL());
 
+  @Rule
+  public ScreenshotOnFailureRule screenshotOnFailureRule =
+      new ScreenshotOnFailureRule(() -> webDriverRule.getDriver());
+
   @Before
   public void setup() {
     webDriverRule.getDriver().get(serverRule.getPulseURL() + "/clusterDetail.html");
@@ -66,8 +54,6 @@ public class PulseAnonymousUserTest {
   @Test
   public void userCanGetToPulseLoginPage() {
     webDriverRule.getDriver().get(serverRule.getPulseURL() + "/Login.html");
-    System.err.println("Pulse url: " + serverRule.getPulseURL());
-    System.err.println(webDriverRule.getDriver().getPageSource().toString());
 
     WebElement userNameElement = webDriverRule.getDriver().findElement(By.id("user_name"));
     WebElement passwordElement = webDriverRule.getDriver().findElement(By.id("user_password"));

http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAuthTest.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAuthTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAuthTest.java
index fc9719d..4a82d1b 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAuthTest.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAuthTest.java
@@ -16,10 +16,10 @@
 package org.apache.geode.tools.pulse.tests.ui;
 
 import org.apache.geode.test.junit.categories.UITest;
+import org.apache.geode.tools.pulse.tests.rules.ScreenshotOnFailureRule;
 import org.apache.geode.tools.pulse.tests.rules.ServerRule;
 import org.apache.geode.tools.pulse.tests.rules.WebDriverRule;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.FixMethodOrder;
 import org.junit.Rule;
@@ -38,6 +38,10 @@ public class PulseAuthTest extends PulseBase {
   public WebDriverRule webDriverRule =
       new WebDriverRule("pulseUser", "12345", serverRule.getPulseURL());
 
+  @Rule
+  public ScreenshotOnFailureRule screenshotOnFailureRule =
+      new ScreenshotOnFailureRule(this::getWebDriver);
+
   @Override
   public WebDriver getWebDriver() {
     return webDriverRule.getDriver();

http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAutomatedTest.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAutomatedTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAutomatedTest.java
index 8df0543..7c42e44 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAutomatedTest.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseAutomatedTest.java
@@ -28,6 +28,7 @@ import java.text.SimpleDateFormat;
 import java.util.List;
 
 import org.apache.geode.tools.pulse.tests.DataBrowserResultLoader;
+import org.apache.geode.tools.pulse.tests.rules.ScreenshotOnFailureRule;
 import org.apache.geode.tools.pulse.tests.rules.ServerRule;
 import org.apache.geode.tools.pulse.tests.rules.WebDriverRule;
 import org.junit.Assert;
@@ -56,6 +57,10 @@ public class PulseAutomatedTest extends PulseBase {
   public WebDriverRule webDriverRule =
       new WebDriverRule("pulseUser", "12345", serverRule.getPulseURL());
 
+  @Rule
+  public ScreenshotOnFailureRule screenshotOnFailureRule =
+      new ScreenshotOnFailureRule(this::getWebDriver);
+
   @Override
   public WebDriver getWebDriver() {
     return webDriverRule.getDriver();

http://git-wip-us.apache.org/repos/asf/geode/blob/67dafd8e/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseNoAuthTest.java
----------------------------------------------------------------------
diff --git a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseNoAuthTest.java b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseNoAuthTest.java
index adcb50f..03265ef 100644
--- a/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseNoAuthTest.java
+++ b/geode-pulse/src/test/java/org/apache/geode/tools/pulse/tests/ui/PulseNoAuthTest.java
@@ -16,10 +16,10 @@
 package org.apache.geode.tools.pulse.tests.ui;
 
 import org.apache.geode.test.junit.categories.UITest;
+import org.apache.geode.tools.pulse.tests.rules.ScreenshotOnFailureRule;
 import org.apache.geode.tools.pulse.tests.rules.ServerRule;
 import org.apache.geode.tools.pulse.tests.rules.WebDriverRule;
 import org.junit.Before;
-import org.junit.BeforeClass;
 import org.junit.ClassRule;
 import org.junit.FixMethodOrder;
 import org.junit.Rule;
@@ -38,6 +38,10 @@ public class PulseNoAuthTest extends PulseBase {
   public WebDriverRule webDriverRule =
       new WebDriverRule("admin", "admin", serverRule.getPulseURL());
 
+  @Rule
+  public ScreenshotOnFailureRule screenshotOnFailureRule =
+      new ScreenshotOnFailureRule(this::getWebDriver);
+
   @Override
   public WebDriver getWebDriver() {
     return webDriverRule.getDriver();


[09/16] geode git commit: GEODE-2092 Update docs with security examples location

Posted by kl...@apache.org.
GEODE-2092 Update docs with security examples location


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

Branch: refs/heads/feature/GEODE-1027
Commit: 22ec6a789a1cbf64e1d7677078558e17efb0c668
Parents: 860d7ef
Author: Karen Miller <km...@pivotal.io>
Authored: Wed Dec 7 12:55:48 2016 -0800
Committer: Karen Miller <km...@pivotal.io>
Committed: Wed Dec 7 14:16:40 2016 -0800

----------------------------------------------------------------------
 geode-docs/managing/security/authentication_examples.html.md.erb | 2 +-
 geode-docs/managing/security/authorization_example.html.md.erb   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/22ec6a78/geode-docs/managing/security/authentication_examples.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/managing/security/authentication_examples.html.md.erb b/geode-docs/managing/security/authentication_examples.html.md.erb
index b7634c8..ce21bac 100644
--- a/geode-docs/managing/security/authentication_examples.html.md.erb
+++ b/geode-docs/managing/security/authentication_examples.html.md.erb
@@ -23,7 +23,7 @@ This example demonstrates the basics of an implementation of the
 `SecurityManager.authenticate` method.
 The remainder of the example may be found within the Apache Geode
 source code within the
-`geode-core/src/main/java/org/apache/geode/security/templates` directory.
+`geode-core/src/main/java/org/apache/geode/examples/security` directory.
 
 Of course, the security implementation of every installation is unique,
 so this example cannot be used in a production environment.

http://git-wip-us.apache.org/repos/asf/geode/blob/22ec6a78/geode-docs/managing/security/authorization_example.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/managing/security/authorization_example.html.md.erb b/geode-docs/managing/security/authorization_example.html.md.erb
index 2e725a1..36182c7 100644
--- a/geode-docs/managing/security/authorization_example.html.md.erb
+++ b/geode-docs/managing/security/authorization_example.html.md.erb
@@ -23,7 +23,7 @@ This example demonstrates the basics of an implementation of the
 `SecurityManager.authorize` method.
 The remainder of the example may be found within the Apache Geode
 source code within the
-`geode-core/src/main/java/org/apache/geode/security/templates` directory.
+`geode-core/src/main/java/org/apache/geode/examples/security` directory.
 
 Of course, the security implementation of every installation is unique,
 so this example cannot be used in a production environment,


[03/16] geode git commit: Removing a bogus import of a javafx class.

Posted by kl...@apache.org.
Removing a bogus import of a javafx class.

This import failed on openjdk.


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

Branch: refs/heads/feature/GEODE-1027
Commit: 033d14f585bafc142a0cf9183fe3350b59e8a112
Parents: 05c2388
Author: Dan Smith <up...@apache.org>
Authored: Tue Dec 6 11:22:36 2016 -0800
Committer: Dan Smith <up...@apache.org>
Committed: Tue Dec 6 16:53:20 2016 -0800

----------------------------------------------------------------------
 .../query/functional/TestNewFunctionSSorRSIntegrationTest.java      | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/033d14f5/geode-core/src/test/java/org/apache/geode/cache/query/functional/TestNewFunctionSSorRSIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/query/functional/TestNewFunctionSSorRSIntegrationTest.java b/geode-core/src/test/java/org/apache/geode/cache/query/functional/TestNewFunctionSSorRSIntegrationTest.java
index 6723243..957ec29 100755
--- a/geode-core/src/test/java/org/apache/geode/cache/query/functional/TestNewFunctionSSorRSIntegrationTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/query/functional/TestNewFunctionSSorRSIntegrationTest.java
@@ -19,7 +19,6 @@
  */
 package org.apache.geode.cache.query.functional;
 
-import static javafx.scene.input.KeyCode.Q;
 import static org.junit.Assert.*;
 
 import java.util.ArrayList;


[07/16] geode git commit: GEODE-2187: Docs: bad subnav link in REST Apps > Troubleshooting

Posted by kl...@apache.org.
GEODE-2187: Docs: bad subnav link in REST Apps > Troubleshooting


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

Branch: refs/heads/feature/GEODE-1027
Commit: f58a11d943bbde29a237968a67392e75690698ee
Parents: 7fb0e68
Author: Dave Barnes <db...@pivotal.io>
Authored: Wed Dec 7 10:15:44 2016 -0800
Committer: Dave Barnes <db...@pivotal.io>
Committed: Wed Dec 7 10:15:44 2016 -0800

----------------------------------------------------------------------
 geode-book/master_middleman/source/subnavs/geode-subnav.erb | 9 ++-------
 geode-docs/rest_apps/troubleshooting.html.md.erb            | 5 +----
 2 files changed, 3 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/f58a11d9/geode-book/master_middleman/source/subnavs/geode-subnav.erb
----------------------------------------------------------------------
diff --git a/geode-book/master_middleman/source/subnavs/geode-subnav.erb b/geode-book/master_middleman/source/subnavs/geode-subnav.erb
index aec611d..16aa1e7 100644
--- a/geode-book/master_middleman/source/subnavs/geode-subnav.erb
+++ b/geode-book/master_middleman/source/subnavs/geode-subnav.erb
@@ -21,7 +21,7 @@ limitations under the License.
     <div class="nav-content">
         <ul>
             <li>
-                <a href="/docs/guide/about_geode.html">Apache Geode 1.0.0-incubating Documentation</a>
+                <a href="/docs/guide/about_geode.html">Apache Geode Documentation</a>
             </li>
             <li class="has_submenu">
                 <a href="/docs/guide/getting_started/book_intro.html">Getting Started with Apache Geode</a>
@@ -1642,13 +1642,8 @@ limitations under the License.
                     <li>
                         <a href="/docs/guide/rest_apps/rest_examples.html">Sample REST Applications</a>
                     </li>
-                    <li class="has_submenu">
+                    <li>
                         <a href="/docs/guide/rest_apps/troubleshooting.html">Troubleshooting and FAQ</a>
-                        <ul>
-                            <li>
-                                <a href="/docs/guide/rest_apps/troubleshooting.html#concept_gsv_zd5_m4">Key Types and JSON Support</a>
-                            </li>
-                        </ul>
                     </li>
                     <li class="has_submenu">
                         <a href="/docs/guide/rest_apps/rest_api_reference.html">Apache Geode REST API Reference</a>

http://git-wip-us.apache.org/repos/asf/geode/blob/f58a11d9/geode-docs/rest_apps/troubleshooting.html.md.erb
----------------------------------------------------------------------
diff --git a/geode-docs/rest_apps/troubleshooting.html.md.erb b/geode-docs/rest_apps/troubleshooting.html.md.erb
index 027e2c6..0f47fff 100644
--- a/geode-docs/rest_apps/troubleshooting.html.md.erb
+++ b/geode-docs/rest_apps/troubleshooting.html.md.erb
@@ -23,10 +23,6 @@ limitations under the License.
 
 This section provides troubleshooting guidance and frequently asked questions about Geode Developer REST APIs.
 
--   **[Key Types and JSON Support](../rest_apps/troubleshooting.html#concept_gsv_zd5_m4)**
-
-    When defining regions (your REST resources), you must only use scalar values for keys and also set value constraints in order to avoid producing JSON that cannot be parsed by Geode.
-
 ## Checking if the REST API Service is Up and Running
 
 Use the ping endpoint to verify whether the REST API server is available.
@@ -52,6 +48,7 @@ If the server is not available, your client will receive an HTTP error code and
 When defining regions (your REST resources), you must only use scalar values for keys and also set value constraints in order to avoid producing JSON that cannot be parsed by Geode.
 
 If Geode regions are not defined with scalar values as keys and value constraints, then you may receive the following error message (even though the JSON is technically valid) in your REST client applications:
+
 ``` pre
 Json doc specified in request body is malformed..!!'
 ```


[14/16] geode git commit: GEODE-1835 : logging a warning message by the configure pdx command only when there are members in the distributed system.

Posted by kl...@apache.org.
GEODE-1835 : logging a warning message by the configure pdx command only
when there are members in the distributed system.


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

Branch: refs/heads/feature/GEODE-1027
Commit: 28efd90290b519d9fe531c826ee4c6e606bcd8e4
Parents: 9031351
Author: Amey Barve <ab...@apache.org>
Authored: Mon Dec 5 11:56:25 2016 +0530
Committer: Kirk Lund <kl...@apache.org>
Committed: Thu Dec 8 08:46:37 2016 -0800

----------------------------------------------------------------------
 .../apache/geode/management/internal/cli/commands/PDXCommands.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/28efd902/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
index 9f7afc1..c5e9a4e 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/cli/commands/PDXCommands.java
@@ -86,7 +86,7 @@ public class PDXCommands extends AbstractCommandsSupport {
           && (patterns != null && patterns.length > 0)) {
         return ResultBuilder.createUserErrorResult(CliStrings.CONFIGURE_PDX__ERROR__MESSAGE);
       }
-      if (CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
+      if (!CliUtil.getAllNormalMembers(CliUtil.getCacheIfExists()).isEmpty()) {
         ird.addLine(CliStrings.CONFIGURE_PDX__NORMAL__MEMBERS__WARNING);
       }
       // Set persistent and the disk-store


[04/16] geode git commit: GEODE-1831: Function no longer gets executed twice on gateway receivers with groups

Posted by kl...@apache.org.
GEODE-1831: Function no longer gets executed twice on gateway receivers with groups


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

Branch: refs/heads/feature/GEODE-1027
Commit: ef96dba9a02d3f0ffab030e9e30c27caea3b4a89
Parents: 033d14f
Author: Barry Oglesby <bo...@pivotal.io>
Authored: Tue Dec 6 12:51:48 2016 -0800
Committer: Barry Oglesby <bo...@pivotal.io>
Committed: Wed Dec 7 09:17:19 2016 -0800

----------------------------------------------------------------------
 .../geode/internal/cache/CacheServerImpl.java   |   8 +-
 .../internal/LocatorLoadBalancingDUnitTest.java |   4 +-
 .../cache/client/internal/LocatorTestBase.java  |  26 +++-
 ...ayReceiverAutoConnectionSourceDUnitTest.java | 126 +++++++++++++++++++
 4 files changed, 153 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/ef96dba9/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerImpl.java
index 8463e82..a3c4a93 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/CacheServerImpl.java
@@ -690,9 +690,11 @@ public class CacheServerImpl extends AbstractCacheServer implements Distribution
    */
   public String[] getCombinedGroups() {
     ArrayList<String> groupList = new ArrayList<String>();
-    for (String g : MemberAttributes.parseGroups(null, getSystem().getConfig().getGroups())) {
-      if (!groupList.contains(g)) {
-        groupList.add(g);
+    if (!this.isGatewayReceiver) {
+      for (String g : MemberAttributes.parseGroups(null, getSystem().getConfig().getGroups())) {
+        if (!groupList.contains(g)) {
+          groupList.add(g);
+        }
       }
     }
     for (String g : getGroups()) {

http://git-wip-us.apache.org/repos/asf/geode/blob/ef96dba9/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorLoadBalancingDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorLoadBalancingDUnitTest.java b/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorLoadBalancingDUnitTest.java
index fffc09b..bd8143e 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorLoadBalancingDUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorLoadBalancingDUnitTest.java
@@ -404,9 +404,9 @@ public class LocatorLoadBalancingDUnitTest extends LocatorTestBase {
     final ServerLoad load1 = new ServerLoad(.3f, .01f, .44f, 4564f);
     final ServerLoad load2 = new ServerLoad(23.2f, 1.1f, 22.3f, .3f);
     int serverPort1 = vm1.invoke("Start BridgeServer", () -> startBridgeServer(null, locators,
-        new String[] {REGION_NAME}, new MyLoadProbe(load1)));
+        new String[] {REGION_NAME}, new MyLoadProbe(load1), false));
     int serverPort2 = vm2.invoke("Start BridgeServer", () -> startBridgeServer(null, locators,
-        new String[] {REGION_NAME}, new MyLoadProbe(load2)));
+        new String[] {REGION_NAME}, new MyLoadProbe(load2), false));
 
     HashMap expected = new HashMap();
     ServerLocation l1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);

http://git-wip-us.apache.org/repos/asf/geode/blob/ef96dba9/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorTestBase.java b/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorTestBase.java
index d6c7b29..c3b349a 100644
--- a/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorTestBase.java
+++ b/geode-core/src/test/java/org/apache/geode/cache/client/internal/LocatorTestBase.java
@@ -14,6 +14,7 @@
  */
 package org.apache.geode.cache.client.internal;
 
+import org.apache.geode.internal.lang.StringUtils;
 import org.apache.geode.test.dunit.internal.JUnit4DistributedTestCase;
 
 import org.apache.geode.cache.*;
@@ -161,14 +162,21 @@ public abstract class LocatorTestBase extends JUnit4DistributedTestCase {
 
   protected int startBridgeServerInVM(VM vm, final String[] groups, final String locators,
       final String[] regions) {
-    return startBridgeServerInVM(vm, groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE);
+    return startBridgeServerInVM(vm, groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE,
+        false);
+  }
+
+  protected int startBridgeServerInVM(VM vm, String[] groups, String locators,
+      boolean useGroupsProperty) {
+    return startBridgeServerInVM(vm, groups, locators, new String[] {REGION_NAME},
+        CacheServer.DEFAULT_LOAD_PROBE, useGroupsProperty);
   }
 
   protected int startBridgeServerInVM(VM vm, final String[] groups, final String locators,
-      final String[] regions, final ServerLoadProbe probe) {
+      final String[] regions, final ServerLoadProbe probe, final boolean useGroupsProperty) {
     SerializableCallable connect = new SerializableCallable("Start bridge server") {
       public Object call() throws IOException {
-        return startBridgeServer(groups, locators, regions, probe);
+        return startBridgeServer(groups, locators, regions, probe, useGroupsProperty);
       }
     };
     Integer port = (Integer) vm.invoke(connect);
@@ -181,14 +189,18 @@ public abstract class LocatorTestBase extends JUnit4DistributedTestCase {
 
   protected int startBridgeServer(final String[] groups, final String locators,
       final String[] regions) throws IOException {
-    return startBridgeServer(groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE);
+    return startBridgeServer(groups, locators, regions, CacheServer.DEFAULT_LOAD_PROBE, false);
   }
 
   protected int startBridgeServer(final String[] groups, final String locators,
-      final String[] regions, final ServerLoadProbe probe) throws IOException {
+      final String[] regions, final ServerLoadProbe probe, final boolean useGroupsProperty)
+      throws IOException {
     Properties props = new Properties();
     props.setProperty(MCAST_PORT, "0");
     props.setProperty(LOCATORS, locators);
+    if (useGroupsProperty) {
+      props.setProperty(GROUPS, StringUtils.concat(groups, ","));
+    }
     DistributedSystem ds = getSystem(props);
     Cache cache = CacheFactory.create(ds);
     AttributesFactory factory = new AttributesFactory();
@@ -201,7 +213,9 @@ public abstract class LocatorTestBase extends JUnit4DistributedTestCase {
     }
     CacheServer server = cache.addCacheServer();
     server.setPort(0);
-    server.setGroups(groups);
+    if (!useGroupsProperty) {
+      server.setGroups(groups);
+    }
     server.setLoadProbe(probe);
     server.start();
 

http://git-wip-us.apache.org/repos/asf/geode/blob/ef96dba9/geode-wan/src/test/java/org/apache/geode/cache/wan/GatewayReceiverAutoConnectionSourceDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-wan/src/test/java/org/apache/geode/cache/wan/GatewayReceiverAutoConnectionSourceDUnitTest.java b/geode-wan/src/test/java/org/apache/geode/cache/wan/GatewayReceiverAutoConnectionSourceDUnitTest.java
new file mode 100644
index 0000000..fb0881c
--- /dev/null
+++ b/geode-wan/src/test/java/org/apache/geode/cache/wan/GatewayReceiverAutoConnectionSourceDUnitTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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 org.apache.geode.cache.wan;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.PoolManager;
+import org.apache.geode.cache.client.internal.AutoConnectionSourceImpl;
+import org.apache.geode.cache.client.internal.LocatorTestBase;
+import org.apache.geode.cache.client.internal.PoolImpl;
+import org.apache.geode.distributed.internal.ServerLocation;
+import org.apache.geode.internal.AvailablePort;
+import org.apache.geode.test.dunit.Host;
+import org.apache.geode.test.dunit.NetworkUtils;
+import org.apache.geode.test.dunit.SerializableRunnable;
+import org.apache.geode.test.dunit.VM;
+import org.apache.geode.test.junit.categories.DistributedTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.util.List;
+
+import static org.junit.Assert.*;
+
+@Category({DistributedTest.class})
+public class GatewayReceiverAutoConnectionSourceDUnitTest extends LocatorTestBase {
+
+  public GatewayReceiverAutoConnectionSourceDUnitTest() {
+    super();
+  }
+
+  @Test
+  public void testBridgeServerAndGatewayReceiverClientAndServerWithoutGroup() throws Exception {
+    runBridgeServerAndGatewayReceiverTest(null, null, true);
+  }
+
+  @Test
+  public void testBridgeServerAndGatewayReceiverClientAndServerWithGroup() throws Exception {
+    String groupName = "group1";
+    runBridgeServerAndGatewayReceiverTest(new String[] {groupName}, groupName, true);
+  }
+
+  @Test
+  public void testBridgeServerAndGatewayReceiverClientWithoutGroupServerWithGroup()
+      throws Exception {
+    String groupName = "group1";
+    runBridgeServerAndGatewayReceiverTest(new String[] {groupName}, null, true);
+  }
+
+  @Test
+  public void testBridgeServerAndGatewayReceiverClientWithGroupServerWithoutGroup()
+      throws Exception {
+    String groupName = "group1";
+    runBridgeServerAndGatewayReceiverTest(null, groupName, false);
+  }
+
+  private void runBridgeServerAndGatewayReceiverTest(String[] serverGroups, String clientGroup,
+      boolean oneServerExpected) throws Exception {
+    final Host host = Host.getHost(0);
+    VM vm0 = host.getVM(0);
+    VM vm1 = host.getVM(1);
+    VM vm2 = host.getVM(2);
+
+    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+    startLocatorInVM(vm0, locatorPort, "");
+
+    String locators = NetworkUtils.getServerHostName(vm0.getHost()) + "[" + locatorPort + "]";
+
+    int serverPort = startBridgeServerInVM(vm1, serverGroups, locators, true);
+
+    addGatewayReceiverToVM(vm1);
+
+    startBridgeClientInVM(vm2, clientGroup, NetworkUtils.getServerHostName(vm0.getHost()),
+        locatorPort);
+
+    // Verify getAllServers returns a valid number of servers
+    verifyGetAllServers(vm2, REGION_NAME, serverPort, oneServerExpected);
+  }
+
+  private void addGatewayReceiverToVM(VM vm) {
+    vm.invoke(new SerializableRunnable("add GatewayReceiver") {
+      public void run() {
+        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
+        GatewayReceiverFactory fact = cache.createGatewayReceiverFactory();
+        GatewayReceiver receiver = fact.create();
+        assertTrue(receiver.isRunning());
+      }
+    });
+  }
+
+  private void verifyGetAllServers(VM vm, final String regionName, final int serverPort,
+      final boolean oneServerExpected) {
+    vm.invoke(new SerializableRunnable("verify getAllServers") {
+      public void run() {
+        Cache cache = (Cache) remoteObjects.get(CACHE_KEY);
+        Region region = cache.getRegion(regionName);
+        PoolImpl pool = (PoolImpl) PoolManager.find(region);
+        AutoConnectionSourceImpl connectionSource =
+            (AutoConnectionSourceImpl) pool.getConnectionSource();
+        List<ServerLocation> allServers = connectionSource.getAllServers();
+        if (oneServerExpected) {
+          // One server is expected. Assert one was returned, and its port matches the input
+          // serverPort.
+          assertEquals(1, allServers.size());
+          ServerLocation serverLocation = allServers.get(0);
+          assertEquals(serverPort, serverLocation.getPort());
+        } else {
+          // No servers are expected. Assert none were returned.
+          assertNull(allServers);
+        }
+      }
+    });
+  }
+}