geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmil...@apache.org
Subject [2/4] geode-examples git commit: GEODE-2231 Revise partitioning example
Date Fri, 31 Mar 2017 20:05:21 GMT
GEODE-2231 Revise partitioning example

- remove spurious .iml files
- simplify by removing BaseClient base class
- only demonstate good distribution of keys
- revise README.md


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

Branch: refs/heads/develop
Commit: e3e9f756e8a464dc7c67a1035620f68ff17223cf
Parents: d551b7c
Author: Karen Miller <kmiller@pivotal.io>
Authored: Mon Mar 6 15:51:05 2017 -0800
Committer: Karen Miller <kmiller@pivotal.io>
Committed: Mon Mar 20 14:01:42 2017 -0700

----------------------------------------------------------------------
 gradle.properties                               |   2 +-
 partitioned/README.md                           | 158 +++----------------
 partitioned/scripts/setEnv.sh                   |   1 -
 partitioned/scripts/startAll.sh                 |   8 +-
 .../examples/partitioned/BadEmployeeKey.java    |  40 -----
 .../geode/examples/partitioned/BaseClient.java  |  79 ----------
 .../geode/examples/partitioned/Consumer.java    |  64 +++-----
 .../geode/examples/partitioned/Producer.java    | 121 +++++---------
 partitioned/src/main/main2.iml                  |   6 -
 .../partitioned/BadEmployeeKeyTest.java         |  41 -----
 .../examples/partitioned/ConsumerTest.java      | 115 +-------------
 .../examples/partitioned/EmployeeDataTest.java  |   4 +-
 .../examples/partitioned/EmployeeKeyTest.java   |   4 +-
 .../examples/partitioned/ProducerTest.java      |  96 +----------
 partitioned/src/test/test5.iml                  |   6 -
 15 files changed, 97 insertions(+), 648 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/gradle.properties
----------------------------------------------------------------------
diff --git a/gradle.properties b/gradle.properties
index 50f950b..06f3b2d 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -16,7 +16,7 @@
 #
 version = 1.2.0-SNAPSHOT
 
-geodeVersion = 1.0.0-incubating
+geodeVersion = 1.1.0
 junitVersion = 4.12
 mockitocoreVersion = 1.10.19
 commonsExecVersion = 1.3

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/README.md
----------------------------------------------------------------------
diff --git a/partitioned/README.md b/partitioned/README.md
index c960fe0..9ae80fa 100644
--- a/partitioned/README.md
+++ b/partitioned/README.md
@@ -17,12 +17,7 @@ limitations under the License.
 
 # Geode partitioned region example
 
-This example demonstrates the basic property of partitioning, as well
-as what can go wrong with partitioned regions. 
-The example is presented in two parts.
-The first part shows partitioning, and the second part demonstrates
-what can go wrong with a flawed implementation.
-
+This example demonstrates the basic property of partitioning.
 The basic property of partitioning is that data entries are distributed 
 across all servers that host a region.
 The distribution is like database sharding, except that the distribution
@@ -30,32 +25,23 @@ occurs automatically. It is also similar to data striping on disks,
 except that the distribution is not based on hardware.
 
 In this example,
-two servers host two partitioned regions. 
+two servers host a single partitioned region. 
 There is no redundancy, so that the basic property of partitioning
 may be observed.
-The Producer code puts the 10 entries into one of the two
-regions.
-The Consumer gets and prints the entries from one of the two regions.
-The regions are partitioned,
-so the entries are distributed among the two servers hosting the region.
+The Producer code puts the 10 entries into the region.
+The Consumer gets and prints the entries from the region.
+Because the region is partitioned,
+its entries are distributed among the two servers hosting the region.
 Since there is no redundancy of the data within the region,
 when one of the servers goes away,
 the entries hosted within that server are also gone.
 
-The two regions are the same, except for the hash code implementation.
-Part 1 of this example shows partitioning, and uses only the region
-called `EmployeeRegion`.
-Part 2 of this example shows what can go wrong with a partitioned
-region if a bad hashing function is implemented for the region keys.
-It uses only the region called `BadEmployeeRegion`.
-
-## Part 1: Partitioning
+## Demonstration of Partitioning
 1. Set directory ```geode-examples/partitioned``` to be the
 current working directory.
 Each step in this example specifies paths relative to that directory.
 
-1. Build the jar (with the ```EmployeeKey```, ```BadEmployeeKey```, 
-and ```EmployeeData``` classes):
+1. Build the jar (with the ```EmployeeKey``` and ```EmployeeData``` classes):
 
     ```
     $   ../gradlew build
@@ -67,13 +53,12 @@ starts the servers:
     ```
     $ scripts/startAll.sh
     ```
-    Each of the servers hosts both partitioned regions.
+    Each of the servers hosts the partitioned region.
     
 1. Run the producer to put 10 entries into the ```EmployeeRegion```.
-The argument specification identifies the region.
 
     ```
-    $ ../gradlew run -Pmain=Producer -Pargs=EmployeeRegion
+    $ ../gradlew run -Pmain=Producer
     ...
     ... 
     INFO: Inserted 10 entries in EmployeeRegion.
@@ -81,16 +66,15 @@ The argument specification identifies the region.
 
 1. There are several ways to see the contents of the region.
 Run the consumer to get and print all 10 entries in the `EmployeeRegion`.
-The argument specification identifies the region.
 
     ```
-    $ ../gradlew run -Pmain=Consumer -Pargs=EmployeeRegion
+    $ ../gradlew run -Pmain=Consumer
     ...
     INFO: 10 entries in EmployeeRegion on the server(s).
     ...
     ```
 
-    To see contents of the region keys, use a ```gfsh``` query:
+    If desired, use a ```gfsh``` query to see contents of the region keys:
 
     ```
     $ $GEODE_HOME/bin/gfsh
@@ -100,14 +84,6 @@ The argument specification identifies the region.
     ...
     ```
 
-
-    Or, to see contents of the region values, use a ```gfsh``` query:
-
-    ```
-    gfsh>query --query="select * from /EmployeeRegion"
-    ...
-    ```
-
     Note that the quantity of entries may also be observed with `gfsh`:
  
     ```
@@ -127,7 +103,7 @@ The argument specification identifies the region.
     ```
 
     As an alternative, `gfsh` maybe used to identify how many entries
-    there are for each region on each server by looking at statistics.
+    are in the region on each server by looking at statistics.
 
     ```
     gfsh>show metrics --categories=partition --region=/EmployeeRegion --member=server1
@@ -154,7 +130,7 @@ remaining server.
 Those hosted by the server that was stopped were lost.
 
     ```
-    $ ../gradlew run -Pmain=Consumer -Pargs=EmployeeRegion
+    $ ../gradlew run -Pmain=Consumer
     ...
     ...
     INFO: 5 entries in EmployeeRegion on the server(s).
@@ -167,110 +143,14 @@ Those hosted by the server that was stopped were lost.
     $ scripts/stopAll.sh
     ```
 
-## Part 2: What Can Go Wrong
+## Things to get Right (TM) for Partitioned Regions
 
-Hashing distributes entries among buckets that reside on servers.
-A good hash code is important in order to spread the entries among buckets.
-
-The ```EmployeeRegion``` used in Part 1 of this example has a good hashing
-function.
-Region entries are well distributed among buckets
+- Hashing distributes entries among buckets that reside on servers.
+A good hash code is important in order to spread the entries among buckets
 (and therefore, among servers).
-The ```BadEmployeeRegion``` used in this part of the example
-has a pointedly poor hash code implementation,
-to illustrate what can go wrong.
-The hash code is so bad that all entries in the
-```BadEmployeeRegion``` end up in the same bucket.
-Because of this,
-one of the servers will host all the entries,
-while the other server will not have any of the entries.
-
-Here are the steps to run through this example again, 
-using ```BadEmployeeRegion``` instead of ```EmployeeRegion```.
-This part assumes that you have already built the JAR (step 2 in Part 1 
-of this example).
-
-1. Set directory ```geode-examples/partitioned``` to be the
-current working directory.
-Each step in this example specifies paths relative to that directory.
-
-1. The logs for the locator and two servers were not removed as part
-of the system shut down in Part 1.  Part 2 of the example works fine
-without removing the logs, but the `startAll.sh` script output will
-note that the regions are already hosted as the servers are started.
-To start Part 2 from scratch, remove the logs and their directories:
-
-    ```
-    $ rm -r locator1 server1 server2
-    ```
-
-1. Run a script that starts a locator and two servers.
-The built JAR will be placed onto the classpath when the script 
-starts the servers:
-
-    ```
-    $ scripts/startAll.sh
-    ```
-
-1. Run the producer to put 10 entries into the ```BadEmployeeRegion```.
-The argument specification identifies the region.
-
-    ```
-    $ ../gradlew run -Pmain=Producer -Pargs=BadEmployeeRegion
-    ... 
-    INFO: Inserted 10 entries in BadEmployeeRegion.
-    ```
-
-1.  Run the consumer to get and print all 10 entries in the
-`BadEmployeeRegion`.  The argument specification identifies the region.
-Alternatively, use one of the `gfsh` commands 
-(given in Part 1 of this example)
-to verify that the servers are hosting the 10 entries in the region.
 
-    ```
-    $ ../gradlew run -Pmain=Consumer -Pargs=BadEmployeeRegion
-    ...
-    INFO: 10 entries in EmployeeRegion on the server(s).
-    ...
-    ```
-
-1.  Kill one of the servers:
-
-    ```
-    $ $GEODE_HOME/bin/gfsh
-    ...
-    gfsh>connect
-    gfsh>stop server --name=server1
-    gfsh>quit
-    ```
-
-1. Run the consumer or a `gfsh` query, and notice that either all or
-none of the entries of the ```BadEmployeeRegion``` are still available on the 
-remaining server.
-Those hosted by the server that was stopped were lost.
-
-    ```
-    $ ../gradlew run -Pmain=Consumer -Pargs=BadEmployeeRegion
-    ...
-    ...
-    INFO: 5 entries in BadEmployeeRegion on the server(s).
-    ...
-    ```
-
-6. Shut down the system:
-
-    ```
-    $ scripts/stopAll.sh
-    ```
-
-## Partitioning Example Takeaways
+- Besides the hash code, equals() needs to be defined.
 
-1. Partitioned regions distribute region entries across buckets within servers.
-A robust system will use redundancy in conjunction with partitioning
+- A robust system will use redundancy in conjunction with partitioning
 in production systems,
 so that data is not lost if a server goes down.
-
-2. A proper hashcode is important for distributing entries across buckets.
-Not demonstrated in this example, but a proper equals method is also
-required.
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/scripts/setEnv.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/setEnv.sh b/partitioned/scripts/setEnv.sh
index e9e860e..0afe249 100755
--- a/partitioned/scripts/setEnv.sh
+++ b/partitioned/scripts/setEnv.sh
@@ -29,5 +29,4 @@ echo "Geode version: `$GEODE_HOME/bin/gfsh version`"
 ## prefer GEODE_HOME for finding gfsh
 export PATH=$GEODE_HOME/bin:$PATH
 
-
 : ${GEODE_LOCATOR_PORT?}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/scripts/startAll.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/startAll.sh b/partitioned/scripts/startAll.sh
index 165fd44..c7c9fe0 100755
--- a/partitioned/scripts/startAll.sh
+++ b/partitioned/scripts/startAll.sh
@@ -17,13 +17,9 @@
 #
 
 set -e
-
 current=`pwd`
-
 cd `dirname $0`
-
 . ./setEnv.sh
-
 cd $current
 
 #export GEODE_LOCATOR_PORT="${GEODE_LOCATOR_PORT:-10334}"
@@ -33,15 +29,13 @@ gfsh start locator --name=locator1 --mcast-port=0 --port=${GEODE_LOCATOR_PORT}
 # start 2 servers on a random available port
 for N in {1..2}
 do
- gfsh start server --locators=localhost[${GEODE_LOCATOR_PORT}] --name=server$N  --server-port=0
--mcast-port=0 --classpath=${PWD}/build/libs/partitioned-0.1.0-SNAPSHOT.jar
+ gfsh start server --locators=localhost[${GEODE_LOCATOR_PORT}] --name=server$N  --server-port=0
--mcast-port=0 --classpath=${PWD}/build/libs/partitioned-1.2.0-SNAPSHOT.jar
 done
 
 # create 2 regions with the same data using GFSH, one that works well,
 #  good keys, and the other that implements a bad hashCode on the key
 gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "create region --name=EmployeeRegion
--type=PARTITION"
 
-gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "create region --name=BadEmployeeRegion
--type=PARTITION"
-
 gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "list members"
 
 exit 0

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/main/java/org/apache/geode/examples/partitioned/BadEmployeeKey.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/BadEmployeeKey.java
b/partitioned/src/main/java/org/apache/geode/examples/partitioned/BadEmployeeKey.java
deleted file mode 100644
index 31c2610..0000000
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/BadEmployeeKey.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.geode.examples.partitioned;
-
-
-public class BadEmployeeKey extends EmployeeKey {
-
-  private static final long serialVersionUID = 1L;
-
-  public BadEmployeeKey() {}
-
-  public BadEmployeeKey(String n, int en) {
-    super(n, en);
-  }
-
-  /*
-   * This hashCode is what makes this class a very poor implementation. It always returns
the value
-   * 1, so that every entry gets placed in the same bucket, and partitioning is useless.
-   *
-   * Forgetting to define, or implementing an erroneous hashCode can result in rotten distribution
-   * of region entries across buckets (and therefore, across partitions).
-   */
-  @Override
-  public int hashCode() {
-    return 1;
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/main/java/org/apache/geode/examples/partitioned/BaseClient.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/BaseClient.java
b/partitioned/src/main/java/org/apache/geode/examples/partitioned/BaseClient.java
deleted file mode 100644
index 5fdc236..0000000
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/BaseClient.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.geode.examples.partitioned;
-
-import java.util.logging.Logger;
-
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
-import org.apache.geode.cache.client.ClientCacheFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-
-
-public abstract class BaseClient {
-
-  static final Logger logger = Logger.getAnonymousLogger();
-  protected ClientCache clientCache;
-
-  protected void setRegion1(Region region) {
-    this.region1 = region;
-  }
-
-  protected void setRegion2(Region region) {
-    this.region2 = region;
-  }
-
-  private Region region1;
-  private Region region2;
-  private final String locatorHost = System.getProperty("GEODE_LOCATOR_HOST", "localhost");
-  private final int locatorPort = Integer.getInteger("GEODE_LOCATOR_PORT", 10334);
-  protected static final String REGION1_NAME = "EmployeeRegion";
-  protected static final String REGION2_NAME = "BadEmployeeRegion";
-  static final int NUM_ENTRIES = 10;
-
-  public BaseClient() {
-    this.clientCache = getClientCache();
-  }
-
-  public BaseClient(ClientCache clientCache) {
-    this.clientCache = clientCache;
-  }
-
-  protected Region getRegion1() {
-    if (region1 == null) {
-      region1 = getClientCache()
-          .<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
-          .create(REGION1_NAME);
-    }
-    return (region1);
-  }
-
-  protected Region getRegion2() {
-    if (region2 == null) {
-      region2 = getClientCache()
-          .<BadEmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
-          .create(REGION2_NAME);
-    }
-    return (region2);
-  }
-
-  protected ClientCache getClientCache() {
-    if (clientCache == null) {
-      clientCache = new ClientCacheFactory().addPoolLocator(locatorHost, locatorPort)
-          .set("log-level", "WARN").create();
-    }
-    return clientCache;
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
index 2e61866..1525280 100644
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
@@ -15,67 +15,55 @@
 package org.apache.geode.examples.partitioned;
 
 import java.util.*;
+import java.util.logging.Logger;
+
 import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
+
+public class Consumer {
 
-public class Consumer extends BaseClient {
+  static final Logger logger = Logger.getAnonymousLogger();
+  private Region region1;
+  private final String locatorHost = System.getProperty("GEODE_LOCATOR_HOST", "localhost");
+  private final int locatorPort = Integer.getInteger("GEODE_LOCATOR_PORT", 10334);
+  protected static final String REGION1_NAME = "EmployeeRegion";
 
   public static void main(String[] args) {
     Consumer c = new Consumer();
-    c.checkAndPrint(args);
+    c.setUpRegion();
+    c.printRegionContents();
   }
 
-  public void checkAndPrint(String[] args) {
-    if (0 == args.length) {
-      throw new RuntimeException("Expected argument specifying region name.");
-    } else {
-      if (args.length > 1) {
-        throw new RuntimeException("Expected only 1 argument, and received more than 1.");
-      } else {
-        if (args[0].equals("EmployeeRegion")) {
-          this.printRegionContents();
-        } else {
-          if (args[0].equals("BadEmployeeRegion")) {
-            this.printBadRegionContents();
-          } else {
-            throw new RuntimeException("Unrecognized region name in argument specification.");
-          }
-        }
-      }
-    }
-  }
 
   public Consumer() {}
 
-  public Consumer(ClientCache clientCache) {
-    this.clientCache = clientCache;
+  public Consumer(Region r) {
+    region1 = r;
+  }
+
+
+  public void setUpRegion() {
+    ClientCache clientCache = new ClientCacheFactory().addPoolLocator(locatorHost, locatorPort)
+        .set("log-level", "WARN").create();
+    region1 =
+        clientCache.<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
+            .create(REGION1_NAME);
   }
 
 
   public void printRegionContents() {
     /* Print EmployeeRegion size and contents */
-    Region r1 = this.getRegion1();
-    Set<EmployeeKey> setOfKeys1 = r1.keySetOnServer();
+    Set<EmployeeKey> setOfKeys1 = region1.keySetOnServer();
     logger.info(setOfKeys1.size() + " entries in EmployeeRegion on the server(s).");
     if (setOfKeys1.size() > 0) {
       logger.info("Contents of EmployeeRegion:");
       for (EmployeeKey key : setOfKeys1) {
-        logger.info(r1.get(key).toString());
+        logger.info(region1.get(key).toString());
       }
     }
   }
 
-  public void printBadRegionContents() {
-    /* Print BadEmployeeRegion size and contents */
-    Region r2 = this.getRegion2();
-    Set<EmployeeKey> setOfKeys2 = r2.keySetOnServer();
-    logger.info(setOfKeys2.size() + " entries in BadEmployeeRegion on the server(s).");
-    if (setOfKeys2.size() > 0) {
-      logger.info("Contents of BadEmployeeRegion:");
-      for (EmployeeKey key : setOfKeys2) {
-        logger.info(r2.get(key).toString());
-      }
-    }
-  }
 
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
index 04fcfc1..5d22360 100644
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
@@ -16,136 +16,87 @@ package org.apache.geode.examples.partitioned;
 
 import org.apache.geode.cache.client.ClientCache;
 import org.apache.geode.cache.Region;
+import org.apache.geode.cache.client.ClientCacheFactory;
+import org.apache.geode.cache.client.ClientRegionShortcut;
 
-public class Producer extends BaseClient {
+import java.util.logging.Logger;
+
+public class Producer {
+
+  static final Logger logger = Logger.getAnonymousLogger();
+  // protected ClientCache clientCache;
+  private Region region1;
+  private final String locatorHost = System.getProperty("GEODE_LOCATOR_HOST", "localhost");
+  private final int locatorPort = Integer.getInteger("GEODE_LOCATOR_PORT", 10334);
+  protected static final String REGION1_NAME = "EmployeeRegion";
 
   public static void main(String[] args) {
     Producer p = new Producer();
-    p.checkAndPopulate(args);
+    p.setUpRegion();
+    p.populateRegion();
   }
 
-  public void checkAndPopulate(String[] args) {
-    if (0 == args.length) {
-      throw new RuntimeException("Expected argument specifying region name.");
-    } else {
-      if (args.length > 1) {
-        throw new RuntimeException("Expected only 1 argument, and received more than 1.");
-      } else {
-        if (args[0].equals("EmployeeRegion")) {
-          this.populateRegion();
-        } else {
-          if (args[0].equals("BadEmployeeRegion")) {
-            this.populateBadRegion();
-          } else {
-            throw new RuntimeException("Unrecognized region name in argument specification.");
-          }
-        }
-      }
-    }
-  }
 
   public Producer() {
-    super();
+
   }
 
-  public Producer(ClientCache clientCache) {
-    super(clientCache);
+  public Producer(Region r) {
+    region1 = r;
   }
 
-  /* Put 10 entries into the region with the quality hashing function. */
+  public void setUpRegion() {
+    ClientCache clientCache = new ClientCacheFactory().addPoolLocator(locatorHost, locatorPort)
+        .set("log-level", "WARN").create();
+    region1 =
+        clientCache.<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.PROXY)
+            .create(REGION1_NAME);
+  }
+
+  /* Put 10 entries into the region with a quality hashing function. */
   public void populateRegion() {
 
-    Region r = getRegion1();
     EmployeeKey k1 = new EmployeeKey("Alex Able", 160);
     EmployeeData d1 = new EmployeeData(k1, 70000, 40);
-    r.put(k1, d1);
+    region1.put(k1, d1);
 
     EmployeeKey k2 = new EmployeeKey("Bertie Bell", 170);
     EmployeeData d2 = new EmployeeData(k2, 72000, 40);
-    r.put(k2, d2);
+    region1.put(k2, d2);
 
     EmployeeKey k3 = new EmployeeKey("Kris Call", 180);
     EmployeeData d3 = new EmployeeData(k3, 68000, 40);
-    r.put(k3, d3);
+    region1.put(k3, d3);
 
     EmployeeKey k4 = new EmployeeKey("Dale Driver", 190);
     EmployeeData d4 = new EmployeeData(k4, 81500, 36);
-    r.put(k4, d4);
+    region1.put(k4, d4);
 
     EmployeeKey k5 = new EmployeeKey("Frankie Forth", 201);
     EmployeeData d5 = new EmployeeData(k5, 45000, 40);
-    r.put(k5, d5);
+    region1.put(k5, d5);
 
     EmployeeKey k6 = new EmployeeKey("Jamie Jive", 220);
     EmployeeData d6 = new EmployeeData(k6, 56500, 40);
-    r.put(k6, d6);
+    region1.put(k6, d6);
 
     EmployeeKey k7 = new EmployeeKey("Morgan Minnow", 230);
     EmployeeData d7 = new EmployeeData(k7, 65000, 36);
-    r.put(k7, d7);
+    region1.put(k7, d7);
 
     EmployeeKey k8 = new EmployeeKey("Pat Puts", 240);
     EmployeeData d8 = new EmployeeData(k8, 67000, 40);
-    r.put(k8, d8);
+    region1.put(k8, d8);
 
     EmployeeKey k9 = new EmployeeKey("Ricky Reliable", 2500);
     EmployeeData d9 = new EmployeeData(k9, 71000, 40);
-    r.put(k9, d9);
+    region1.put(k9, d9);
 
     EmployeeKey k10 = new EmployeeKey("Taylor Tack", 260);
     EmployeeData d10 = new EmployeeData(k10, 70000, 40);
-    r.put(k10, d10);
+    region1.put(k10, d10);
 
     logger.info("Inserted 10 entries in EmployeeRegion.");
   }
 
-  /*
-   * Put 10 entries into the region with the bad hashing function. The entries are the same
as those
-   * put into the region with the quality hashing function.
-   */
-  public void populateBadRegion() {
-
-    Region r = getRegion2();
-    BadEmployeeKey k1 = new BadEmployeeKey("Alex Able", 160);
-    EmployeeData d1 = new EmployeeData(k1, 70000, 40);
-    r.put(k1, d1);
-
-    BadEmployeeKey k2 = new BadEmployeeKey("Bertie Bell", 170);
-    EmployeeData d2 = new EmployeeData(k2, 72000, 40);
-    r.put(k2, d2);
-
-    BadEmployeeKey k3 = new BadEmployeeKey("Kris Call", 180);
-    EmployeeData d3 = new EmployeeData(k3, 68000, 40);
-    r.put(k3, d3);
-
-    BadEmployeeKey k4 = new BadEmployeeKey("Dale Driver", 190);
-    EmployeeData d4 = new EmployeeData(k4, 81500, 36);
-    r.put(k4, d4);
-
-    BadEmployeeKey k5 = new BadEmployeeKey("Frankie Forth", 201);
-    EmployeeData d5 = new EmployeeData(k5, 45000, 40);
-    r.put(k5, d5);
-
-    BadEmployeeKey k6 = new BadEmployeeKey("Jamie Jive", 220);
-    EmployeeData d6 = new EmployeeData(k6, 56500, 40);
-    r.put(k6, d6);
-
-    BadEmployeeKey k7 = new BadEmployeeKey("Morgan Minnow", 230);
-    EmployeeData d7 = new EmployeeData(k7, 65000, 36);
-    r.put(k7, d7);
-
-    BadEmployeeKey k8 = new BadEmployeeKey("Pat Puts", 240);
-    EmployeeData d8 = new EmployeeData(k8, 67000, 40);
-    r.put(k8, d8);
-
-    BadEmployeeKey k9 = new BadEmployeeKey("Ricky Reliable", 2500);
-    EmployeeData d9 = new EmployeeData(k9, 71000, 40);
-    r.put(k9, d9);
-
-    BadEmployeeKey k10 = new BadEmployeeKey("Taylor Tack", 260);
-    EmployeeData d10 = new EmployeeData(k10, 70000, 40);
-    r.put(k10, d10);
-
-    logger.info("Inserted 10 entries in BadEmployeeRegion.");
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/main/main2.iml
----------------------------------------------------------------------
diff --git a/partitioned/src/main/main2.iml b/partitioned/src/main/main2.iml
deleted file mode 100644
index 19dbd15..0000000
--- a/partitioned/src/main/main2.iml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="false">
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/java/org/apache/geode/examples/partitioned/BadEmployeeKeyTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/BadEmployeeKeyTest.java
b/partitioned/src/test/java/org/apache/geode/examples/partitioned/BadEmployeeKeyTest.java
deleted file mode 100644
index dacd669..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/BadEmployeeKeyTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
- * agreements. See the NOTICE file distributed with this work for additional information
regarding
- * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
- * "License"); you may not use this file except in compliance with the License. You may obtain
a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under
the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
- * or implied. See the License for the specific language governing permissions and limitations
under
- * the License.
- */
-package org.apache.geode.examples.partitioned;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-public class BadEmployeeKeyTest {
-
-  private BadEmployeeKey k;
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  @Before
-  public void setup() {
-    k = new BadEmployeeKey("First Last", 3001);
-  }
-
-  @Test
-  public void testHashCode() {
-    assertEquals(1, k.hashCode());
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
index e6a550e..7a399a8 100644
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
+++ b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
@@ -15,50 +15,28 @@
 
 package org.apache.geode.examples.partitioned;
 
-import static org.junit.Assert.*;
 import static org.mockito.Mockito.*;
 
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Set;
 
-import org.apache.geode.cache.client.ClientRegionFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
+
 
 public class ConsumerTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
+  private Region region = mock(Region.class);
 
-  private Consumer consumer;
-  private ClientCache clientCache = mock(ClientCache.class);
-  private Region region1 = mock(Region.class);
-  private Region region2 = mock(Region.class);
-  private ClientRegionFactory clientRegionFactory = mock(ClientRegionFactory.class);
-  private Set keys = mock(Set.class);
-  private static final String[] EMPTYARGS = new String[0];
-  private static final String[] GOODARGS1 = {"EmployeeRegion"};
-  private static final String[] GOODARGS2 = {"BadEmployeeRegion"};
-  private static final String[] BADARGS1 = {""};
-  private static final String[] BADARGS2 = {"BadRegionName"};
-  private static final String[] BADARGS3 = {"BadEmployeeRegion", "2"};
 
   @Before
   public void setup() {
-    when(region1.getName()).thenReturn(Consumer.REGION1_NAME);
-    when(region2.getName()).thenReturn(Consumer.REGION2_NAME);
-    when(keys.size()).thenReturn(Consumer.NUM_ENTRIES);
-    when(clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY))
-        .thenReturn(clientRegionFactory);
-    when(clientRegionFactory.create(Consumer.REGION1_NAME)).thenReturn(region1);
-    when(clientRegionFactory.create(Consumer.REGION2_NAME)).thenReturn(region2);
 
     /* Make a small map that will provide values as a region would */
     Map<EmployeeKey, EmployeeData> emplMap = new HashMap<>();
@@ -69,96 +47,19 @@ public class ConsumerTest {
     EmployeeData d2 = new EmployeeData(k2, 70000, 40);
     emplMap.put(k2, d2);
     /* Use HashMap as fake region for keySetOnServer, size, and get methods */
-    when(region1.keySetOnServer()).thenReturn(emplMap.keySet());
-    when(region1.size()).thenReturn(emplMap.size());
-    when(region1.get(eq(k1))).thenReturn(emplMap.get(k1));
-    when(region1.get(eq(k2))).thenReturn(emplMap.get(k2));
-
-    Map<BadEmployeeKey, EmployeeData> badEmplMap = new HashMap<>();
-    BadEmployeeKey bk1 = new BadEmployeeKey("Bertie Bell", 170);
-    EmployeeData bd1 = new EmployeeData(bk1, 72000, 40);
-    badEmplMap.put(bk1, bd1);
-    BadEmployeeKey bk2 = new BadEmployeeKey("Toni Tiptoe", 180);
-    EmployeeData bd2 = new EmployeeData(bk2, 70000, 40);
-    badEmplMap.put(bk2, bd2);
-    /* Use HashMap as fake region for keySetOnServer, size, and get methods */
-    when(region2.keySetOnServer()).thenReturn(badEmplMap.keySet());
-    when(region2.size()).thenReturn(badEmplMap.size());
-    when(region2.get(eq(bk1))).thenReturn(badEmplMap.get(bk1));
-    when(region2.get(eq(bk2))).thenReturn(badEmplMap.get(bk2));
-
-    consumer = new Consumer(clientCache);
-  }
+    when(region.keySetOnServer()).thenReturn(emplMap.keySet());
+    when(region.size()).thenReturn(emplMap.size());
+    when(region.get(eq(k1))).thenReturn(emplMap.get(k1));
+    when(region.get(eq(k2))).thenReturn(emplMap.get(k2));
 
-  @Test
-  public void numberOfEntriesShouldBeGreaterThanZero() throws Exception {
-    assertTrue(consumer.NUM_ENTRIES > 0);
   }
 
-  @Test
-  public void testConsumerGetRegion1() {
-    assertEquals("Region names do not match", Consumer.REGION1_NAME,
-        consumer.getRegion1().getName());
-  }
-
-  @Test
-  public void testConsumerGetRegion2() {
-    assertEquals("Region names do not match", Consumer.REGION2_NAME,
-        consumer.getRegion2().getName());
-  }
 
   @Test
   public void testPrintRegionContents() {
-    consumer.printRegionContents();
-  }
-
-  @Test
-  public void testPrintBadRegionContents() {
-    consumer.printBadRegionContents();
-  }
-
-  @Test
-  public void testCheckAndPrint1() {
-    /* no exception expected */
-    consumer.checkAndPrint(GOODARGS1);
-  }
-
-  @Test
-  public void testCheckAndPrint2() {
-    /* no exception expected */
-    consumer.checkAndPrint(GOODARGS2);
+    Consumer c = new Consumer(region);
+    c.printRegionContents();
   }
 
-  @Test
-  public void testCheckAndPrint3() {
-    /* no arguments specified, array length should be 0 */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Expected argument specifying region name.");
-    spy(Consumer.class).checkAndPrint(EMPTYARGS);
-  }
-
-  @Test
-  public void testCheckAndPrint4() {
-    /* First argument is the empty string */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Unrecognized region name in argument specification.");
-    spy(Consumer.class).checkAndPrint(BADARGS1);
-  }
-
-  @Test
-  public void testCheckAndPrint5() {
-    /* Arguments are an invalid region name */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Unrecognized region name in argument specification.");
-    spy(Consumer.class).checkAndPrint(BADARGS2);
-  }
-
-  @Test
-  public void testCheckAndPrint6() {
-    /* Arguments are an invalid region name and an extra but unused argument */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Expected only 1 argument, and received more than 1.");
-    spy(Consumer.class).checkAndPrint(BADARGS3);
-  }
 
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
b/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
index 2ec546c..b3112e7 100644
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
+++ b/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
@@ -21,9 +21,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-/**
- * Created by kmiller on 1/31/17.
- */
+
 public class EmployeeDataTest {
   private EmployeeData d;
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
b/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
index 2ce499f..c5e880f 100644
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
+++ b/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
@@ -21,9 +21,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
-/**
- * Created by kmiller on 1/30/17.
- */
+
 public class EmployeeKeyTest {
 
   private EmployeeKey k;

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
index 350d96d..c042af5 100644
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
+++ b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
@@ -17,116 +17,28 @@ package org.apache.geode.examples.partitioned;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.*;
 
-import java.util.Set;
-
-import org.apache.geode.cache.client.ClientRegionFactory;
-import org.apache.geode.cache.client.ClientRegionShortcut;
-import static org.junit.Assert.*;
-import org.junit.After;
-import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
 import org.apache.geode.cache.Region;
-import org.apache.geode.cache.client.ClientCache;
 
 public class ProducerTest {
 
   @Rule
   public ExpectedException expectedException = ExpectedException.none();
 
-  private Producer producer;
   private Producer pMock = mock(Producer.class);
-  private ClientCache clientCache = mock(ClientCache.class);
-  private Region<EmployeeKey, EmployeeData> region1 = mock(Region.class);
-  private Region<BadEmployeeKey, EmployeeData> region2 = mock(Region.class);
-  private ClientRegionFactory clientRegionFactory = mock(ClientRegionFactory.class);
-  private Set keys = mock(Set.class);
-  private static final String[] EMPTYARGS = new String[0];
-  private static final String[] GOODARGS1 = {"EmployeeRegion"};
-  private static final String[] GOODARGS2 = {"BadEmployeeRegion"};
-  private static final String[] BADARGS1 = {""};
-  private static final String[] BADARGS2 = {"BadRegionName"};
-  private static final String[] BADARGS3 = {"BadEmployeeRegion", "2"};
-
-
-  @Before
-  public void setup() {
-    when(region1.getName()).thenReturn(Producer.REGION1_NAME);
-    when(region2.getName()).thenReturn(Producer.REGION2_NAME);
-    when(keys.size()).thenReturn(Producer.NUM_ENTRIES);
-    when(clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY))
-        .thenReturn(clientRegionFactory);
-    when(clientRegionFactory.create(Consumer.REGION1_NAME)).thenReturn(region1);
-    when(clientRegionFactory.create(Consumer.REGION2_NAME)).thenReturn(region2);
-    doNothing().when(pMock).populateRegion();
-
-  }
+  private Region<EmployeeKey, EmployeeData> region = mock(Region.class);
+  private EmployeeData dataMock = mock(EmployeeData.class);
 
 
   @Test
   public void testPopulateRegion() {
-    producer = new Producer(clientCache);
+    Producer producer = new Producer(region);
     producer.populateRegion();
-    verify(region1, times(10)).put(any(), any());
-
-  }
+    verify(region, times(10)).put(any(), any());
 
-  @Test
-  public void testPopulateBadRegion() {
-    producer = new Producer(clientCache);
-    producer.populateBadRegion();
-    verify(region2, times(10)).put(any(), any());
-
-  }
-
-  @Test
-  public void testCheckAndPopulate1() {
-    /* no exception expected */
-    pMock.checkAndPopulate(GOODARGS1);
-  }
-
-  @Test
-  public void testCheckAndPopulate2() {
-    /* no exception expected */
-    pMock.checkAndPopulate(GOODARGS2);
   }
 
-  @Test
-  public void testCheckAndPopulate3() {
-    /* no arguments specified, array length should be 0 */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Expected argument specifying region name.");
-    spy(Producer.class).checkAndPopulate(EMPTYARGS);
-  }
-
-  @Test
-  public void testCheckAndPopulate4() {
-    /* First argument is the empty string */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Unrecognized region name in argument specification.");
-    spy(Producer.class).checkAndPopulate(BADARGS1);
-  }
-
-  @Test
-  public void testCheckAndPopulate5() {
-    /* Arguments are an invalid region name */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Unrecognized region name in argument specification.");
-    spy(Producer.class).checkAndPopulate(BADARGS2);
-  }
-
-  @Test
-  public void testCheckAndPopulate6() {
-    /* Arguments are an invalid region name and an extra but unused argument */
-    expectedException.expect(Exception.class);
-    expectedException.expectMessage("Expected only 1 argument, and received more than 1.");
-    spy(Producer.class).checkAndPopulate(BADARGS3);
-  }
-
-  @After
-  public void tearDown() {
-
-  }
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/e3e9f756/partitioned/src/test/test5.iml
----------------------------------------------------------------------
diff --git a/partitioned/src/test/test5.iml b/partitioned/src/test/test5.iml
deleted file mode 100644
index 19dbd15..0000000
--- a/partitioned/src/test/test5.iml
+++ /dev/null
@@ -1,6 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<module version="4">
-  <component name="NewModuleRootManager" inherit-compiler-output="false">
-    <orderEntry type="sourceFolder" forTests="false" />
-  </component>
-</module>
\ No newline at end of file


Mime
View raw message