You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ab...@apache.org on 2017/05/10 00:39:08 UTC

[1/5] geode-examples git commit: GEODE-2831: Improve geode examples

Repository: geode-examples
Updated Branches:
  refs/heads/develop 47008179e -> 5ebbc817e


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java
----------------------------------------------------------------------
diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java b/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java
new file mode 100644
index 0000000..53e8e0e
--- /dev/null
+++ b/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java
@@ -0,0 +1,56 @@
+/*
+ * 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.replicated;
+
+import java.util.function.Consumer;
+import java.util.stream.IntStream;
+
+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 class Example implements Consumer<Region<Integer, String>> {
+  public static void main(String[] args) {
+    // connect to the locator using default port 10334
+    ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
+        .set("log-level", "WARN").create();
+
+    // create a local region that matches the server region
+    Region<Integer, String> region =
+        cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+            .create("example-region");
+
+    new Example().accept(region);
+    cache.close();
+  }
+
+  @Override
+  public void accept(Region<Integer, String> region) {
+    // insert values into the region
+    int count = 10;
+    IntStream.range(0, count).forEach(i -> region.put(i, "value" + i));
+    System.out
+        .println(String.format("Inserted %d entries into region %s", count, region.getName()));
+
+    // count the values in the region
+    int inserted = region.keySetOnServer().size();
+    System.out.println(String.format("Counted %d keys in region %s", inserted, region.getName()));
+
+    // fetch the values in the region
+    region.keySetOnServer()
+        .forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key))));
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
----------------------------------------------------------------------
diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java b/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
deleted file mode 100644
index 7503a25..0000000
--- a/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
+++ /dev/null
@@ -1,37 +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.replicated;
-
-import org.apache.geode.cache.client.ClientCache;
-
-public class Producer extends BaseClient {
-
-  public static void main(String[] args) {
-    new Producer().populateRegion();
-  }
-
-  public Producer() {}
-
-  public Producer(ClientCache clientCache) {
-    this.clientCache = clientCache;
-  }
-
-  public void populateRegion() {
-    for (int i = 0; i < NUM_ENTRIES; i++) {
-      getRegion().put(i, "value" + i);
-    }
-    logger.info("Done. Inserted " + NUM_ENTRIES + " entries.");
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/main2.iml
----------------------------------------------------------------------
diff --git a/replicated/src/main/main2.iml b/replicated/src/main/main2.iml
deleted file mode 100644
index 19dbd15..0000000
--- a/replicated/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/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
----------------------------------------------------------------------
diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
deleted file mode 100644
index 4bbf051..0000000
--- a/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
+++ /dev/null
@@ -1,70 +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.replicated;
-
-import static org.junit.Assert.*;
-import static org.mockito.Mockito.*;
-
-import java.util.Set;
-
-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;
-import org.apache.geode.cache.client.NoAvailableLocatorsException;
-
-public class ConsumerTest {
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private Consumer consumer;
-  private ClientCache clientCache = mock(ClientCache.class);
-  private Region region = mock(Region.class);
-  private Set keys = mock(Set.class);
-
-  @Before
-  public void setup() {
-    when(region.getName()).thenReturn(Consumer.REGION_NAME);
-    when(keys.size()).thenReturn(Consumer.NUM_ENTRIES);
-    when(region.keySetOnServer()).thenReturn(keys);
-    when(clientCache.getRegion(any())).thenReturn(region);
-    consumer = new Consumer(clientCache);
-    consumer.setRegion(region);
-  }
-
-  @Test
-  public void numberOfEntriesOnServerShouldMatchConsumerEntries() throws Exception {
-    assertEquals(consumer.NUM_ENTRIES, consumer.countEntriesOnServer());
-  }
-
-  @Test
-  public void numberOfEntriesShouldBeGreaterThanZero() throws Exception {
-    assertTrue(consumer.NUM_ENTRIES > 0);
-  }
-
-  @Test
-  public void countingEntriesWithoutConnectionShouldThrowNoAvailableLocatorsException()
-      throws Exception {
-    consumer = new Consumer();
-    expectedException.expect(NoAvailableLocatorsException.class);
-    assertEquals(consumer.NUM_ENTRIES, consumer.countEntriesOnServer());
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java
----------------------------------------------------------------------
diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java
new file mode 100644
index 0000000..3bab1f0
--- /dev/null
+++ b/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.replicated;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.cache.Region;
+import org.geode.examples.util.Mocks;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+
+public class ExampleTest {
+
+  @Rule
+  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+  @Test
+  public void testExample() throws Exception {
+    Region<Integer, String> region = Mocks.region("example-region");
+    new Example().accept(region);
+
+    assertThat(systemOutRule.getLog()).contains("Inserted 10 entries into region");
+    assertThat(systemOutRule.getLog()).contains("value9");
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
----------------------------------------------------------------------
diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
deleted file mode 100644
index 88ce2b1..0000000
--- a/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
+++ /dev/null
@@ -1,68 +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.replicated;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-import java.util.Set;
-
-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 ClientCache clientCache = mock(ClientCache.class);
-  private Region region = mock(Region.class);
-  private Set keys = mock(Set.class);
-
-  @Before
-  public void setup() throws Exception {
-    when(region.getName()).thenReturn(Producer.REGION_NAME);
-    when(region.keySetOnServer()).thenReturn(keys);
-    when(clientCache.getRegion(any())).thenReturn(region);
-  }
-
-  @Test
-  public void populateRegionShouldReturnCorrectNumberOfEntries() throws Exception {
-    producer = new Producer(clientCache);
-    producer.setRegion(region);
-
-    producer.populateRegion();
-    verify(region, times(producer.NUM_ENTRIES)).put(any(), any());
-  }
-
-  @Test
-  public void populateWhenRegionDoesNotExistShouldThrowNullPointer() throws Exception {
-    producer = new Producer(clientCache);
-    expectedException.expect(NullPointerException.class);
-    producer.populateRegion();
-  }
-
-  @After
-  public void tearDown() {
-
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
----------------------------------------------------------------------
diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
deleted file mode 100644
index 927af49..0000000
--- a/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
+++ /dev/null
@@ -1,165 +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.replicated;
-
-import static org.hamcrest.core.Is.*;
-import static org.junit.Assert.*;
-import static org.junit.Assume.*;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecuteResultHandler;
-import org.apache.commons.exec.ExecuteException;
-import org.apache.commons.exec.environment.EnvironmentUtils;
-import org.apache.geode.examples.utils.ShellUtil;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-/**
- * Tests for the shell scripts of the replicated example
- */
-public class ReplicatedTest {
-
-  // TODO: parameterize
-  public static final String GEODE_LOCATOR_PORT = "GEODE_LOCATOR_PORT=";
-  private static final String startScriptFileName = "startAll.sh";
-  private static final String stopScriptFileName = "stopAll.sh";
-  private static final String pidkillerScriptFileName = "pidkiller.sh";
-  private boolean processRunning = false;
-  private ShellUtil shell = new ShellUtil();
-  private final long scriptTimeout = TimeUnit.SECONDS.toMillis(120);
-  private static final Logger logger = Logger.getAnonymousLogger();
-
-  @Rule
-  public TemporaryFolder testFolder = new TemporaryFolder();
-
-  private int locatorPort;
-  private Map environment;
-
-  @Before
-  public void setup() throws IOException {
-    // ignores test if running on windows
-    assumeThat(System.getProperty("os.name").startsWith("Windows"), is(false));
-
-    locatorPort = getAvailablePort();
-    environment = EnvironmentUtils.getProcEnvironment();
-    EnvironmentUtils.addVariableToEnvironment(environment, GEODE_LOCATOR_PORT + locatorPort);
-    logger.fine("Locator port: " + locatorPort);
-  }
-
-  @Test
-  public void checkIfScriptsExistsAndAreExecutable() throws IOException {
-    assertTrue(
-        shell.getFileFromClassLoader(startScriptFileName).map(x -> x.isFile()).orElse(false));
-    assertTrue(shell.getFileFromClassLoader(stopScriptFileName).map(x -> x.isFile()).orElse(false));
-  }
-
-  @Test
-  public void executeStartThenStopScript() throws InterruptedException, IOException {
-    final int exitCodeStart = executeScript(startScriptFileName);
-    assertEquals(0, exitCodeStart);
-
-    final int exitCodeStop = executeScript(stopScriptFileName);
-    assertEquals(0, exitCodeStop);
-  }
-
-  @Test
-  public void failToStopWhenNoServersAreRunning() throws InterruptedException, IOException {
-    final int exitCode;
-
-    exitCode = executeScript(stopScriptFileName);
-    assertEquals(1, exitCode);
-  }
-
-  /**
-   * Execute the kill script that looks for pid files
-   * 
-   * @throws IOException
-   * @throws InterruptedException
-   */
-  private void runKillScript() throws IOException, InterruptedException {
-    CommandLine cmdLine = CommandLine.parse(shell.getFileFromClassLoader(pidkillerScriptFileName)
-        .map(x -> x.getAbsolutePath()).orElseThrow(IllegalArgumentException::new));
-    cmdLine.addArgument(testFolder.getRoot().getAbsolutePath());
-
-    DefaultExecuteResultHandler resultHandler =
-        shell.execute(cmdLine, scriptTimeout, environment, testFolder.getRoot());
-    resultHandler.waitFor(scriptTimeout);
-  }
-
-  /**
-   * Given a script file name, runs the script and return the exit code. If exitCode != 0 extract
-   * and prints exception.
-   * 
-   * @param scriptName
-   * @return <code>int</code> with exitCode
-   * @throws IOException
-   * @throws InterruptedException
-   */
-  private int executeScript(String scriptName) throws IOException, InterruptedException {
-    final int exitCode;
-    DefaultExecuteResultHandler resultHandler =
-        shell.execute(scriptName, scriptTimeout, environment, testFolder.getRoot());
-    processRunning = true;
-    resultHandler.waitFor();
-
-    logger.finest(String.format("Executing %s...", scriptName));
-    exitCode = resultHandler.getExitValue();
-
-    // extract and log exception if any happened
-    if (exitCode != 0) {
-      ExecuteException executeException = resultHandler.getException();
-      logger.log(Level.SEVERE, executeException.getMessage(), executeException);
-    }
-    return exitCode;
-  }
-
-  @After
-  public void tearDown() {
-    if (processRunning) {
-      try {
-        runKillScript();
-      } catch (IOException | InterruptedException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * Get a random available port
-   * 
-   * @return <code>int</code> port number
-   */
-  private static int getAvailablePort() {
-    try (ServerSocket socket = new ServerSocket(0)) {
-      int port = socket.getLocalPort();
-      socket.close();
-      return port;
-    } catch (IOException ioex) {
-      logger.log(Level.SEVERE, ioex.getMessage(), ioex);
-    }
-    throw new IllegalStateException("No TCP/IP ports available.");
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/test5.iml
----------------------------------------------------------------------
diff --git a/replicated/src/test/test5.iml b/replicated/src/test/test5.iml
deleted file mode 100644
index 19dbd15..0000000
--- a/replicated/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

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 9af877b..28a63f8 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -18,5 +18,3 @@ rootProject.name = 'geode-examples'
 
 include 'replicated'
 include 'partitioned'
-include 'utils'
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/src/test/java/org/geode/examples/util/Mocks.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/geode/examples/util/Mocks.java b/src/test/java/org/geode/examples/util/Mocks.java
new file mode 100644
index 0000000..ec36681
--- /dev/null
+++ b/src/test/java/org/geode/examples/util/Mocks.java
@@ -0,0 +1,55 @@
+/*
+ * 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.geode.examples.util;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.geode.cache.Region;
+import org.mockito.invocation.InvocationOnMock;
+
+public class Mocks {
+  private Mocks() { }
+  
+  @SuppressWarnings("unchecked")
+  public static <K, V> Region<K, V> region(String name) throws Exception {
+    Map<K, V> data = new HashMap<>();
+    Region<K, V> region = mock(Region.class);
+
+    when(region.getName()).thenReturn(name);
+    when(region.put(any(), any())).then(inv -> data.put(getKey(inv), getValue(inv)));
+    when(region.get(any())).then(inv -> data.get(getKey(inv)));
+    when(region.keySet()).thenReturn(data.keySet());
+    when(region.values()).thenReturn(data.values());
+    when(region.size()).thenReturn(data.size());
+    when(region.keySetOnServer()).thenReturn(data.keySet());
+
+    return region;
+  }
+  
+  @SuppressWarnings("unchecked")
+  private static <K> K getKey(InvocationOnMock inv) {
+    return (K) inv.getArguments()[0];
+  }
+
+  @SuppressWarnings("unchecked")
+  private static <V> V getValue(InvocationOnMock inv) {
+    return (V) inv.getArguments()[1];
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java
----------------------------------------------------------------------
diff --git a/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java b/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java
deleted file mode 100644
index f02b961..0000000
--- a/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java
+++ /dev/null
@@ -1,106 +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.utils;
-
-import java.io.File;
-import java.io.IOException;
-import java.net.URL;
-import java.util.Map;
-import java.util.Optional;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecuteResultHandler;
-import org.apache.commons.exec.DefaultExecutor;
-import org.apache.commons.exec.ExecuteWatchdog;
-import org.apache.commons.exec.PumpStreamHandler;
-import org.apache.commons.exec.ShutdownHookProcessDestroyer;
-
-/**
- * Utility class for executing shell commands using Apache commons-exec
- */
-public class ShellUtil {
-
-  private final ClassLoader classLoader = getClass().getClassLoader();
-
-  public Optional<File> getFileFromClassLoader(String fileName) {
-    URL resourceURL = classLoader.getResource(fileName);
-    return (resourceURL == null) ? Optional.empty() : Optional.of(new File(resourceURL.getFile()));
-  }
-
-  public CommandLine parseCommandLine(String fileName) {
-    return getFileFromClassLoader(fileName).map(file -> CommandLine.parse(file.getAbsolutePath()))
-        .orElseThrow(IllegalArgumentException::new);
-  }
-
-  public DefaultExecuteResultHandler execute(CommandLine cmdLine, long timeout, Map environment,
-      File dir) throws IOException {
-    ExecutorTemplate exampleTestExecutor = new ExecutorTemplate(timeout, dir).invoke();
-    DefaultExecutor executor = exampleTestExecutor.getExecutor();
-    DefaultExecuteResultHandler resultHandler = exampleTestExecutor.getResultHandler();
-    executor.execute(cmdLine, environment, resultHandler);
-
-    return resultHandler;
-
-  }
-
-  public DefaultExecuteResultHandler execute(String fileName, long timeout, Map environment,
-      File dir) throws IOException {
-    ExecutorTemplate exampleTestExecutor = new ExecutorTemplate(timeout, dir).invoke();
-    DefaultExecutor executor = exampleTestExecutor.getExecutor();
-    DefaultExecuteResultHandler resultHandler = exampleTestExecutor.getResultHandler();
-    executor.execute(parseCommandLine(fileName), environment, resultHandler);
-
-    return resultHandler;
-  }
-
-  /**
-   * Executor template for common scenarios
-   */
-  private static class ExecutorTemplate {
-
-    private final long timeout;
-    private final File dir;
-    private DefaultExecutor executor;
-    private DefaultExecuteResultHandler resultHandler;
-
-    public ExecutorTemplate(final long timeout, final File dir) {
-      this.timeout = timeout;
-      this.dir = dir;
-    }
-
-    public DefaultExecutor getExecutor() {
-      return executor;
-    }
-
-    public DefaultExecuteResultHandler getResultHandler() {
-      return resultHandler;
-    }
-
-    public ExecutorTemplate invoke() {
-      executor = new DefaultExecutor();
-      ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout);
-      executor.setWatchdog(watchdog);
-
-      PumpStreamHandler psh = new PumpStreamHandler(System.out, System.err);
-      executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
-      executor.setStreamHandler(psh);
-      executor.setWorkingDirectory(dir);
-
-      resultHandler = new DefaultExecuteResultHandler();
-      return this;
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/utils/src/main/main5.iml
----------------------------------------------------------------------
diff --git a/utils/src/main/main5.iml b/utils/src/main/main5.iml
deleted file mode 100644
index 19dbd15..0000000
--- a/utils/src/main/main5.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


[2/5] geode-examples git commit: GEODE-2831: Improve geode examples

Posted by ab...@apache.org.
GEODE-2831: Improve geode examples

Pare down the approach for constructing an example
to require the just the following:
- A README.md file
- A scripts/start.gfsh file to start the cluster
- A scripts.stop.gfsh file to stop the cluster
- An Example.java application along with supporting
  classes and tests

The build script contains tasks to start / run / stop
each example.  The README.md file in the root project
provides further details on building and running.


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

Branch: refs/heads/develop
Commit: c21e76b2b0b9eeab1e18416272b747ceb0595325
Parents: 4700817
Author: Anthony Baker <ab...@apache.org>
Authored: Mon Apr 24 12:24:47 2017 -0700
Committer: Anthony Baker <ab...@apache.org>
Committed: Wed Apr 26 16:46:11 2017 -0700

----------------------------------------------------------------------
 .travis.yml                                     |   2 +
 BUILDING.md                                     |  51 -----
 README.md                                       |  61 ++++--
 build.gradle                                    |  84 ++++----
 gradle.properties                               |   6 +-
 gradle/ide.gradle                               |  30 +++
 gradle/spotless.gradle                          |  26 +++
 partitioned/README.md                           | 194 ++++++++-----------
 partitioned/build.gradle                        |  20 --
 partitioned/scripts/.gitignore                  |   2 -
 partitioned/scripts/pidkiller.sh                |  35 ----
 partitioned/scripts/setEnv.sh                   |  32 ---
 partitioned/scripts/start.gfsh                  |  25 +++
 partitioned/scripts/startAll.sh                 |  42 ----
 partitioned/scripts/stop.gfsh                   |  18 ++
 partitioned/scripts/stopAll.sh                  |  28 ---
 .../geode/examples/partitioned/Consumer.java    |  69 -------
 .../examples/partitioned/EmployeeData.java      |  31 +--
 .../geode/examples/partitioned/EmployeeKey.java |  58 +++---
 .../geode/examples/partitioned/Example.java     |  61 ++++++
 .../geode/examples/partitioned/Producer.java    | 101 ----------
 .../examples/partitioned/ConsumerTest.java      |  65 -------
 .../examples/partitioned/EmployeeDataTest.java  |  68 -------
 .../examples/partitioned/EmployeeKeyTest.java   |  59 ------
 .../geode/examples/partitioned/ExampleTest.java |  38 ++++
 .../examples/partitioned/PartitionedTest.java   | 164 ----------------
 .../examples/partitioned/ProducerTest.java      |  44 -----
 replicated/README.md                            |  47 ++---
 replicated/build.gradle                         |  20 --
 replicated/scripts/.gitignore                   |   2 -
 replicated/scripts/pidkiller.sh                 |  35 ----
 replicated/scripts/setEnv.sh                    |  33 ----
 replicated/scripts/start.gfsh                   |  25 +++
 replicated/scripts/startAll.sh                  |  45 -----
 replicated/scripts/stop.gfsh                    |  18 ++
 replicated/scripts/stopAll.sh                   |  28 ---
 .../geode/examples/replicated/BaseClient.java   |  60 ------
 .../geode/examples/replicated/Consumer.java     |  37 ----
 .../geode/examples/replicated/Example.java      |  56 ++++++
 .../geode/examples/replicated/Producer.java     |  37 ----
 replicated/src/main/main2.iml                   |   6 -
 .../geode/examples/replicated/ConsumerTest.java |  70 -------
 .../geode/examples/replicated/ExampleTest.java  |  38 ++++
 .../geode/examples/replicated/ProducerTest.java |  68 -------
 .../examples/replicated/ReplicatedTest.java     | 165 ----------------
 replicated/src/test/test5.iml                   |   6 -
 settings.gradle                                 |   2 -
 .../java/org/geode/examples/util/Mocks.java     |  55 ++++++
 .../apache/geode/examples/utils/ShellUtil.java  | 106 ----------
 utils/src/main/main5.iml                        |   6 -
 50 files changed, 617 insertions(+), 1762 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index bcef9b8..8a77c32 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -18,6 +18,8 @@ language: java
 jdk:
   - oraclejdk8
 
+script: ./gradlew runAll
+
 before_cache:
   - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/BUILDING.md
----------------------------------------------------------------------
diff --git a/BUILDING.md b/BUILDING.md
deleted file mode 100644
index 3885f87..0000000
--- a/BUILDING.md
+++ /dev/null
@@ -1,51 +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.
--->
-
-# Building this Release from Source
-
-Build instructions differ slightly for Unix and Windows platforms.
-All platforms require a Java installation, with JDK 1.8 or more recent version.
-
-## Build from Source on Unix
-
-1. Set the JAVA\_HOME environment variable.  For example:
-
-    ```     
-    JAVA_HOME=/usr/java/jdk1.8.0_60
-    export JAVA_HOME
-    ```
-2. Download the project source from the Releases page at [Apache Geode] (http://geode.apache.org), and unpack the source code.
-3. Within the directory containing the unpacked source code, build and run the tests:
-    
-    ```
-    $ ./gradlew build
-    ```
-
-## Build from Source on Windows
-
-1. Set the JAVA\_HOME environment variable.  For example:
-
-    ```
-    $ set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_60"
-    ```
-2. Install Gradle, version 3.3 or a more recent version.
-3. Download the project source from the Releases page at [Apache Geode] (http://geode.apache.org), and unpack the source code.
-4. Within the folder containing the unpacked source code, build and run the tests:
-
-    ```
-    $ gradle build
-    ```

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 14ceb87..1894591 100644
--- a/README.md
+++ b/README.md
@@ -17,29 +17,59 @@ limitations under the License.
 
 [<img src="https://geode.apache.org/img/apache_geode_logo.png" align="center"/>](http://geode.apache.org)
 
-[![Build Status](https://travis-ci.org/apache/geode-examples.svg?branch=develop)](https://travis-ci.org/apache/geode-examples) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 
+[![Build Status](https://travis-ci.org/apache/geode-examples.svg?branch=develop)](https://travis-ci.org/apache/geode-examples) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0)
 
 # Apache Geode examples
 
-This is the home of Apache Geode examples that are bundled with the project. Contributions<sup>[2]</sup> and corrections are welcome. Please talk to us about your suggestions at [dev@geode.apache.org](mailto:dev@geode.apache.org) or submit a [pull request](https://github.com/apache/geode/pull/new/develop).
+This is the home of Apache Geode examples that are bundled with the project.
+Contributions<sup>[2]</sup> and corrections are welcome. Please talk to us
+about your suggestions at [dev@geode.apache.org](mailto:dev@geode.apache.org)
+or submit a [pull request](https://github.com/apache/geode/pull/new/develop).
 
-## Example requirements
+## Adding a new example
 
-All examples:
+Follow this approach to add a new example:
 
-*  Need to be testable. Use unit tests, integration tests or whatever is applicable. Tests will run through the project's CI.
-*  Should be `Gradle` projects or part of existing ones. There may be exceptions here, but the community should have a consensus to accept.
-*  Have to follow code format & style from Apache Geode <sup>[1]</sup> guidelines.
-*  Should contain a `README.md` file with step-by-step instruction on how to set up and run the example. *Diagrams give you extra credit.*
-*  Donations need to be licensed through ASL 2.0 and contributors need to file an ICLA<sup>[3]</sup>.
+* Create a subdirectory with a descriptive name like `cache-writer`
+* Create a `README.md` file in the example subproject to walk the user through the tutorial
+* Create a Java class with a main method in the `org.apache.geode.examples.$name.Example` class
+* Create a cluster initialization script in `scripts/start.gfsh`
+* Create a cluster shutdown script in `scripts/stop.gfsh`
 
-## Structure
+The scripts should contain `gfsh` commands for starting locators, servers, and
+creating regions--everything that the example program will need to use.  Where
+appropriate you should also add unit tests.  To customize the build you can add
+a `build.gradle` file.
 
-### Installation and a Tutorial for Beginners
+Note that the build may fail if you do not add ASF license headers or use the
+correct formatting (you can fix formatting with `gradle spotlessApply`).
 
-*  [How to Install](http://geode.apache.org/docs/guide/getting_started/installation/install_standalone.html)
-*  Set a `GEODE_HOME` environment variable to point to the root directory of the installation; this directory contains `bin/`. For those that have built from source, it will be the `/path/to/geode/geode-assembly/build/install/apache-geode` directory.
-*  If desired run the tutorial: [Apache Geode in 15 minutes or Less](http://geode.apache.org/docs/guide/getting_started/15_minute_quickstart_gfsh.html)
+## Running an example
+
+The gradle build will automatically download and install a Geode release in the
+`build` directory.  You can run an example with the following gradle targets:
+
+* `build` - compiles the example and runs unit tests
+* `start` - initializes the Geode cluster
+* `run` - runs the example Application
+* `stop` - shuts down the cluster
+* `runAll` - invokes start, run, stop
+
+The commands you need to invoke will be given in the `README.md` file.  Sample
+usage:
+
+    $ ./gradle :replicated:start
+    $ ./gradle :replicated:run
+    $ ./gradle :replicated:stop
+    $ ./gradle runAll
+
+## Catalog of examples
+
+The following sections call out ready-made examples or new examples that could
+be built.  You may want to start your journey with the [Apache Geode in 15
+minutes or
+Less](http://geode.apache.org/docs/guide/getting_started/15_minute_quickstart_gfsh.html)
+tutorial.
 
 ### Basics
 
@@ -78,7 +108,8 @@ All examples:
 
 ### Use cases, integrations and external examples
 
-This section has self-contained little projects that illustrate a use case or an integration with other projects.
+This section has self-contained little projects that illustrate a use case or
+an integration with other projects.
 
 *  SpringBoot Application
 *  HTTP Session replication

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index cceeb3b..8289ead 100644
--- a/build.gradle
+++ b/build.gradle
@@ -44,7 +44,7 @@ task downloadGeode {
 task verifyGeode(type: de.undercouch.gradle.tasks.download.Verify, dependsOn: downloadGeode) {
   src installFile
   algorithm "SHA-256"
-  doFirst { 
+  doFirst {
     checksum file("${installFile}.sha256").text.split(' ')[0]
   }
 }
@@ -57,52 +57,56 @@ task installGeode(type: Copy, dependsOn: verifyGeode) {
   into buildDir
 }
 
-subprojects {
-    apply plugin:'java'
+allprojects {
+  apply plugin:'java'
 
-    repositories {
-        mavenCentral()
-    }
+  repositories { mavenCentral() }
 
-    dependencies {
-        compile "org.apache.geode:geode-core:$geodeVersion"
-        compile "org.apache.commons:commons-exec:$commonsExecVersion"
-        runtime "org.slf4j:slf4j-log4j12:$slf4jVersion"
+  dependencies {
+    compile "org.apache.geode:geode-core:$geodeVersion"
+    
+    testCompile "com.jayway.awaitility:awaitility:$awaitilityVersion"
+    testCompile "junit:junit:$junitVersion"
+    testCompile "org.mockito:mockito-core:$mockitocoreVersion"
+    testCompile "com.github.stefanbirkner:system-rules:$systemrulesVersion"
+    testCompile "org.assertj:assertj-core:$assertjVersion"
+  }
+}
 
-        testCompile "com.jayway.awaitility:awaitility:$awaitilityVersion"
-        testCompile project(":utils")
-        testCompile "junit:junit:$junitVersion"
-        testCompile "org.mockito:mockito-core:$mockitocoreVersion"
-    }
+subprojects {
+  dependencies {
+    runtime "org.slf4j:slf4j-log4j12:$slf4jVersion"
+    
+    testCompile project.parent.sourceSets.test.output
+  }
+  
+  def geodePath = "${System.env.PATH}${System.getProperty('path.separator')}${installDir}/bin"
+  task start(type: Exec, dependsOn: [installGeode, build]) {
+    workingDir buildDir
+    environment 'GEODE_HOME', installDir
+    environment 'PATH', geodePath
+    commandLine 'sh', '-c', "gfsh run --file=${projectDir}/scripts/start.gfsh"
+  }
 
-    task run(type: JavaExec) {
-        description = 'Run example'
-        def mainClass = rootProject.hasProperty('main') ? "${rootProject.getProperty('main')}" : 'Main'
-        main = "org.apache.geode.examples.${project.name}.$mainClass"
-        classpath = sourceSets.main.runtimeClasspath
-        standardInput = System.in
-        systemProperties = System.getProperties()
-        if (rootProject.hasProperty('args')) {
-            args = ["${rootProject.getProperty('args')}"]
-        }
-    }
+  task stop(type: Exec, dependsOn: installGeode) {
+    workingDir buildDir
+    environment 'GEODE_HOME', installDir
+    environment 'PATH', geodePath
+    commandLine 'sh', '-c', "gfsh run --file=${projectDir}/scripts/stop.gfsh"
+  }
 
-    test.dependsOn installGeode
-    test {
-	environment 'GEODE_HOME': "$rootProject.buildDir/apache-geode-$geodeVersion"
-    }
+  task run(type: JavaExec, dependsOn: build) {
+    description = 'Run example'
+    classpath = sourceSets.main.runtimeClasspath
+    main = "org.apache.geode.examples.${project.name}.Example"
+  }
 
-    apply plugin: "com.diffplug.gradle.spotless"
-    spotless {
-	lineEndings = 'unix';
-	java {
-	    target project.fileTree(project.projectDir) {
-		include '**/*.java'
-	    }
-	    eclipseFormatFile "${rootProject.projectDir}/etc/eclipse-java-google-style.xml"
-	}
-    }
+  task runAll(dependsOn: [start, run, stop])
+  run.mustRunAfter start
+  stop.mustRunAfter run
 }
 
+apply from: "gradle/spotless.gradle"
+apply from: "gradle/ide.gradle"
 apply from: "gradle/rat.gradle"
 apply from: "gradle/release.gradle"

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/gradle.properties
----------------------------------------------------------------------
diff --git a/gradle.properties b/gradle.properties
index 06f3b2d..83479a1 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -17,8 +17,10 @@
 version = 1.2.0-SNAPSHOT
 
 geodeVersion = 1.1.0
+
+assertjVersion = 3.6.2
+awaitilityVersion = 1.7.0
 junitVersion = 4.12
 mockitocoreVersion = 1.10.19
-commonsExecVersion = 1.3
-awaitilityVersion = 1.7.0
 slf4jVersion = 1.7.22
+systemrulesVersion = 1.16.1

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/gradle/ide.gradle
----------------------------------------------------------------------
diff --git a/gradle/ide.gradle b/gradle/ide.gradle
new file mode 100644
index 0000000..b3da6ab
--- /dev/null
+++ b/gradle/ide.gradle
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+allprojects {
+  apply plugin: 'eclipse'
+  eclipse {
+    classpath {
+      defaultOutputDir = file('build-eclipse')
+      downloadSources = true
+    }
+  }
+
+  apply plugin: 'idea'
+  idea {
+    module { downloadSources = true }
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/gradle/spotless.gradle
----------------------------------------------------------------------
diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle
new file mode 100644
index 0000000..77d29d2
--- /dev/null
+++ b/gradle/spotless.gradle
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+subprojects {
+  apply plugin: "com.diffplug.gradle.spotless"
+  spotless {
+    lineEndings = 'unix';
+    java {
+      target project.fileTree(project.projectDir) { include '**/*.java' }
+      eclipseFormatFile "${rootProject.projectDir}/etc/eclipse-java-google-style.xml"
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/README.md
----------------------------------------------------------------------
diff --git a/partitioned/README.md b/partitioned/README.md
index 75be8b5..1643d06 100644
--- a/partitioned/README.md
+++ b/partitioned/README.md
@@ -17,143 +17,103 @@ limitations under the License.
 
 # Geode partitioned region example
 
-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
-occurs automatically. 
-
-In this example,
-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 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;
+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 occurs automatically.
+
+In this example, two servers host a single partitioned region.  There is no
+redundancy, so that the basic property of partitioning may be observed.  The
+example puts 10 entries into the region and prints them.  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 example demonstrates this.
 
+This example assumes that Java and Geode are installed.
+
 ## 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``` and ```EmployeeData``` classes):
-
-    ```
-    $   ../gradlew build
-    ```
-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
-    ```
-    Each of the servers hosts the partitioned region.
-    
-1. Run the producer to put 10 entries into the ```EmployeeRegion```.
-
-    ```
-    $ ../gradlew run -Pmain=Producer
-    ...
-    ... 
-    INFO: Inserted 10 entries in EmployeeRegion.
-    ```
-
-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`.
-
-    ```
-    $ ../gradlew run -Pmain=Consumer
-    ...
-    INFO: 10 entries in EmployeeRegion on the server(s).
-    ...
-    ```
-
-    If desired, use a ```gfsh``` query to see contents of the region keys:
-
-    ```
-    $ $GEODE_HOME/bin/gfsh
-    ...
-    gfsh>connect
-    gfsh>query --query="select e.key from /EmployeeRegion.entries e"
-    ...
-    ```
+1. Build the example (with the `EmployeeKey` and `EmployeeData` classes)
+
+        $ ./gradlew build
+
+2. Run a script that starts a locator and two servers.  Each of the servers
+hosts the partitioned region.  The example classes will be placed onto the
+classpath when the script starts the servers.
+
+        $ gfsh run --file=scripts/start.gfsh
+
+3. Run the example to put 10 entries into the `example-region`. The data
+will also be retrieved from the region and printed to the console.
+
+        $ ./gradlew run
+
+4. Run a `gfsh` command to see the contents of the region
+
+        $ gfsh
+        ...
+        gfsh>connect --locators=127.0.0.1[10334]
+        gfsh>query --query="select e.key from /example-region.entries e"
+        ...
 
     Note that the quantity of entries may also be observed with `gfsh`:
- 
-    ```
-    gfsh>describe region --name=EmployeeRegion
-    ..........................................................
-    Name            : EmployeeRegion
-    Data Policy     : partition
-    Hosting Members : server2
-                      server1
-
-    Non-Default Attributes Shared By Hosting Members  
-
-     Type  |    Name     | Value
-    ------ | ----------- | ---------
-    Region | size        | 10
-           | data-policy | PARTITION
-    ```
+
+        gfsh>describe region --name=example-region
+        ..........................................................
+        Name            : example-region
+        Data Policy     : partition
+        Hosting Members : server2
+                          server1
+
+        Non-Default Attributes Shared By Hosting Members  
+
+         Type  |    Name     | Value
+        ------ | ----------- | ---------
+        Region | size        | 10
+               | data-policy | PARTITION
 
     As an alternative, `gfsh` maybe used to identify how many entries
     are in the region on each server by looking at statistics.
 
-    ```
-    gfsh>show metrics --categories=partition --region=/EmployeeRegion --member=server1
-    ```
-
-    Within the output, the result for `totalBucketSize` identifies
-    the number of entries hosted on the specified server.
-    Vary the command to see statistics for both `server1` and `server2`.
-    Note that approximately half the entries will be on each server.
-    And, the quantity on each server may vary if the example is started
-    over and run again.
-
-1. The region entries are distributed across both servers.
-Kill one of the servers:
-
-    ```
-    $ $GEODE_HOME/bin/gfsh
-    ...
-    gfsh>connect
-    gfsh>stop server --name=server1
-    gfsh>quit
-    ```
-
-1. Run the consumer a second time, and notice that approximately half of
-the entries of the ```EmployeeRegion``` are still available on the 
+        gfsh>show metrics --categories=partition --region=/example-region --member=server1
+
+    Within the output, the result for `totalBucketSize` identifies the number
+    of entries hosted on the specified server.  Vary the command to see
+    statistics for both `server1` and `server2`.  Note that approximately half
+    the entries will be on each server.  And, the quantity on each server may
+    vary if the example is started over and run again.
+
+5. The region entries are distributed across both servers.
+Stop one of the servers
+
+        $ gfsh
+        ...
+        gfsh>connect --locators=127.0.0.1[10334]
+        gfsh>stop server --name=server1
+        gfsh>quit
+
+6. Run the consumer a second time, and notice that approximately half of
+the entries of the ```EmployeeRegion``` are still available on the
 remaining server.
 Those hosted by the server that was stopped were lost.
 
-    ```
-    $ ../gradlew run -Pmain=Consumer
-    ...
-    ...
-    INFO: 5 entries in EmployeeRegion on the server(s).
-    ...
-    ```
+        $ ./gradlew run
 
-6. Shut down the system:
+7. Shut down the cluster
 
-    ```
-    $ scripts/stopAll.sh
-    ```
+        $ gfsh run --file=scripts/stop.gfsh
 
 ## Things to Get Right 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
-(and therefore, among servers).
+- 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).
 
-- Besides the hash code, equals() needs to be defined.
+- Besides the hash code, `equals()` needs to be defined.
 
-- A system that ought to not lose data if a system member goes down
-will use redundancy in conjunction with partitioning
-in production systems.
+- A system that ought to not lose data if a system member goes down will use
+redundancy in conjunction with partitioning in production systems.

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/build.gradle
----------------------------------------------------------------------
diff --git a/partitioned/build.gradle b/partitioned/build.gradle
deleted file mode 100644
index 52283ec..0000000
--- a/partitioned/build.gradle
+++ /dev/null
@@ -1,20 +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.
- */
-
-sourceSets.test {
-  resources.srcDirs = ["${projectDir}/scripts"]
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/.gitignore
----------------------------------------------------------------------
diff --git a/partitioned/scripts/.gitignore b/partitioned/scripts/.gitignore
deleted file mode 100644
index 32f8870..0000000
--- a/partitioned/scripts/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-locator1/
-server*/

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/pidkiller.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/pidkiller.sh b/partitioned/scripts/pidkiller.sh
deleted file mode 100755
index ecf8f2d..0000000
--- a/partitioned/scripts/pidkiller.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-# @brief Script that look for .pid files on a directory and kill those processes.
-#
-
-export DIR=$1
-
-if [ $# -eq 0 ]
-  then
-    echo "No arguments supplied. Script needs directory to look for pid files."
-    exit 1
-fi
-
-for pid in `find $DIR -name "*.pid"`
-do
- echo "Found: $pid"
- kill -9 `cat $pid`
- echo "Killed."
-done
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/setEnv.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/setEnv.sh b/partitioned/scripts/setEnv.sh
deleted file mode 100755
index 0afe249..0000000
--- a/partitioned/scripts/setEnv.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-## check if locator port has been set otherwise set to default
-export GEODE_LOCATOR_PORT="${GEODE_LOCATOR_PORT:-10334}"
-
-## check if GEODE_HOME has been set
-: ${GEODE_HOME?"GEODE_HOME enviroment variable needs to be set"}
-
-## check if gfsh script is accessible and print version
-: ${GEODE_HOME/bin/gfsh?"gfsh doesn't seem to be available. Please check $GEODE_HOME"}
-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/c21e76b2/partitioned/scripts/start.gfsh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/start.gfsh b/partitioned/scripts/start.gfsh
new file mode 100644
index 0000000..0da16d8
--- /dev/null
+++ b/partitioned/scripts/start.gfsh
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+start locator --bind-address=127.0.0.1
+
+start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../classes/main
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../classes/main
+
+create region --name=example-region --type=PARTITION
+
+list members
+describe region --name=example-region
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/startAll.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/startAll.sh b/partitioned/scripts/startAll.sh
deleted file mode 100755
index c7c9fe0..0000000
--- a/partitioned/scripts/startAll.sh
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-set -e
-current=`pwd`
-cd `dirname $0`
-. ./setEnv.sh
-cd $current
-
-#export GEODE_LOCATOR_PORT="${GEODE_LOCATOR_PORT:-10334}"
-# start a locator
-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-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 "list members"
-
-exit 0
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/stop.gfsh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/stop.gfsh b/partitioned/scripts/stop.gfsh
new file mode 100644
index 0000000..9281b31
--- /dev/null
+++ b/partitioned/scripts/stop.gfsh
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+connect --locator=127.0.0.1[10334]
+shutdown --include-locators=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/scripts/stopAll.sh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/stopAll.sh b/partitioned/scripts/stopAll.sh
deleted file mode 100755
index a6364a8..0000000
--- a/partitioned/scripts/stopAll.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-set -e
-
-current=`pwd`
-
-cd `dirname $0`
-
-. ./setEnv.sh
-
-cd $current
-
-gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "shutdown --include-locators=true"

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index 1525280..0000000
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Consumer.java
+++ /dev/null
@@ -1,69 +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.*;
-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 {
-
-  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.setUpRegion();
-    c.printRegionContents();
-  }
-
-
-  public Consumer() {}
-
-  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 */
-    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(region1.get(key).toString());
-      }
-    }
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeData.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeData.java b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeData.java
index c79962d..234458f 100644
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeData.java
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeData.java
@@ -17,44 +17,33 @@ package org.apache.geode.examples.partitioned;
 import java.io.Serializable;
 
 public class EmployeeData implements Serializable {
-
   private static final long serialVersionUID = 1L;
 
   private EmployeeKey nameAndNumber;
   private int salary;
   private int hoursPerWeek;
 
-  public EmployeeData() {}
-
-  public EmployeeData(EmployeeKey k, int s, int hrs) {
-    this.nameAndNumber = k;
-    this.salary = s;
-    this.hoursPerWeek = hrs;
+  public EmployeeData(EmployeeKey nameAndNumber, int salary, int hoursPerWeek) {
+    this.nameAndNumber = nameAndNumber;
+    this.salary = salary;
+    this.hoursPerWeek = hoursPerWeek;
   }
 
   public EmployeeKey getNameAndNumber() {
-    return (nameAndNumber);
+    return nameAndNumber;
   }
 
   public int getSalary() {
-    return (salary);
+    return salary;
   }
 
   public int getHoursPerWeek() {
-    return (hoursPerWeek);
-  }
-
-  public boolean equals(EmployeeData e) {
-    if (this.nameAndNumber.equals(e.getNameAndNumber()) && (this.salary == e.getSalary())
-        && (this.hoursPerWeek == e.getHoursPerWeek())) {
-      return true;
-    }
-    return false;
+    return hoursPerWeek;
   }
 
+  @Override
   public String toString() {
-    return (this.nameAndNumber.toString() + " salary=" + this.salary + " hoursPerWeek="
-        + this.hoursPerWeek);
+    return "EmployeeData [nameAndNumber=" + nameAndNumber + ", salary=" + salary + ", hoursPerWeek="
+        + hoursPerWeek + "]";
   }
-
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
index 7581676..dd9d6ec 100644
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
@@ -17,53 +17,55 @@ package org.apache.geode.examples.partitioned;
 import java.io.Serializable;
 
 public class EmployeeKey implements Serializable {
-
   private static final long serialVersionUID = 1L;
 
   private String name;
   private int emplNumber;
 
-  public EmployeeKey() {}
+  public String getName() {
+    return name;
+  }
 
-  public EmployeeKey(String n, int en) {
-    this.name = n;
-    this.emplNumber = en;
+  public int getEmplNumber() {
+    return emplNumber;
   }
 
-  public String getName() {
-    return (name);
+  public EmployeeKey(String name, int emplNumber) {
+    super();
+    this.name = name;
+    this.emplNumber = emplNumber;
   }
 
-  public int getEmplNumber() {
-    return (emplNumber);
+  @Override
+  public int hashCode() {
+    final int prime = 31;
+    int result = 1;
+    result = prime * result + emplNumber;
+    result = prime * result + ((name == null) ? 0 : name.hashCode());
+    return result;
   }
 
   @Override
-  public boolean equals(Object o) {
-    if (this == o) {
+  public boolean equals(Object obj) {
+    if (this == obj)
       return true;
-    }
-    if (o == null || getClass() != o.getClass()) {
+    if (obj == null)
       return false;
-    }
-
-    EmployeeKey that = (EmployeeKey) o;
-
-    if (emplNumber != that.emplNumber) {
+    if (getClass() != obj.getClass())
+      return false;
+    EmployeeKey other = (EmployeeKey) obj;
+    if (emplNumber != other.emplNumber)
       return false;
-    }
-    return name.equals(that.name);
+    if (name == null) {
+      if (other.name != null)
+        return false;
+    } else if (!name.equals(other.name))
+      return false;
+    return true;
   }
 
   @Override
-  public int hashCode() {
-    int result = name.hashCode();
-    result = 31 * result + emplNumber;
-    return result;
-  }
-
   public String toString() {
-    return ("Name: " + this.name + " Employee Number: " + this.emplNumber);
+    return "EmployeeKey [name=" + name + ", emplNumber=" + emplNumber + "]";
   }
-
 }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/src/main/java/org/apache/geode/examples/partitioned/Example.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Example.java b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Example.java
new file mode 100644
index 0000000..d60894e
--- /dev/null
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/Example.java
@@ -0,0 +1,61 @@
+/*
+ * 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.Arrays;
+import java.util.Random;
+import java.util.function.Consumer;
+
+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 class Example implements Consumer<Region<EmployeeKey, EmployeeData>> {
+  public static void main(String[] args) {
+    // connect to the locator using default port 10334
+    ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
+        .set("log-level", "WARN").create();
+
+    // create a local region that matches the server region
+    Region<EmployeeKey, EmployeeData> region = cache
+        .<EmployeeKey, EmployeeData>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+        .create("example-region");
+
+    new Example().accept(region);
+    cache.close();
+  }
+
+  @Override
+  public void accept(Region<EmployeeKey, EmployeeData> region) {
+    // insert values into the region
+    Random r = new Random();
+    String[] names =
+        "Alex Able,Bertie Bell,Kris Call,Dale Driver,Frankie Forth,Jamie Jive,Morgan Minnow,Pat Puts,Ricky Reliable,Taylor Tack"
+            .split(",");
+    Arrays.stream(names).forEach(name -> {
+      EmployeeKey key = new EmployeeKey(name, r.nextInt());
+      EmployeeData val = new EmployeeData(key, r.nextInt(), 40);
+      region.put(key, val);
+    });
+
+    // count the values in the region
+    int inserted = region.keySetOnServer().size();
+    System.out.println(String.format("Counted %d keys in region %s", inserted, region.getName()));
+
+    // fetch the values in the region
+    region.keySetOnServer().forEach(key -> System.out.println(region.get(key)));
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index 9fc87e8..0000000
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/Producer.java
+++ /dev/null
@@ -1,101 +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 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;
-
-import java.util.logging.Logger;
-
-public class Producer {
-
-  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) {
-    Producer p = new Producer();
-    p.setUpRegion();
-    p.populateRegion();
-  }
-
-
-  public Producer() {
-
-  }
-
-  public Producer(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);
-  }
-
-  /* Put 10 entries into the region with a quality hashing function. */
-  public void populateRegion() {
-
-    EmployeeKey k1 = new EmployeeKey("Alex Able", 160);
-    EmployeeData d1 = new EmployeeData(k1, 70000, 40);
-    region1.put(k1, d1);
-
-    EmployeeKey k2 = new EmployeeKey("Bertie Bell", 170);
-    EmployeeData d2 = new EmployeeData(k2, 72000, 40);
-    region1.put(k2, d2);
-
-    EmployeeKey k3 = new EmployeeKey("Kris Call", 180);
-    EmployeeData d3 = new EmployeeData(k3, 68000, 40);
-    region1.put(k3, d3);
-
-    EmployeeKey k4 = new EmployeeKey("Dale Driver", 190);
-    EmployeeData d4 = new EmployeeData(k4, 81500, 36);
-    region1.put(k4, d4);
-
-    EmployeeKey k5 = new EmployeeKey("Frankie Forth", 201);
-    EmployeeData d5 = new EmployeeData(k5, 45000, 40);
-    region1.put(k5, d5);
-
-    EmployeeKey k6 = new EmployeeKey("Jamie Jive", 220);
-    EmployeeData d6 = new EmployeeData(k6, 56500, 40);
-    region1.put(k6, d6);
-
-    EmployeeKey k7 = new EmployeeKey("Morgan Minnow", 230);
-    EmployeeData d7 = new EmployeeData(k7, 65000, 36);
-    region1.put(k7, d7);
-
-    EmployeeKey k8 = new EmployeeKey("Pat Puts", 240);
-    EmployeeData d8 = new EmployeeData(k8, 67000, 40);
-    region1.put(k8, d8);
-
-    EmployeeKey k9 = new EmployeeKey("Ricky Reliable", 2500);
-    EmployeeData d9 = new EmployeeData(k9, 71000, 40);
-    region1.put(k9, d9);
-
-    EmployeeKey k10 = new EmployeeKey("Taylor Tack", 260);
-    EmployeeData d10 = new EmployeeData(k10, 70000, 40);
-    region1.put(k10, d10);
-
-    logger.info("Inserted 10 entries in EmployeeRegion.");
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index 7a399a8..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ConsumerTest.java
+++ /dev/null
@@ -1,65 +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.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.rules.ExpectedException;
-
-import org.apache.geode.cache.Region;
-
-
-public class ConsumerTest {
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-  private Region region = mock(Region.class);
-
-
-  @Before
-  public void setup() {
-
-    /* Make a small map that will provide values as a region would */
-    Map<EmployeeKey, EmployeeData> emplMap = new HashMap<>();
-    EmployeeKey k1 = new EmployeeKey("Bertie Bell", 170);
-    EmployeeData d1 = new EmployeeData(k1, 72000, 40);
-    emplMap.put(k1, d1);
-    EmployeeKey k2 = new EmployeeKey("Toni Tiptoe", 180);
-    EmployeeData d2 = new EmployeeData(k2, 70000, 40);
-    emplMap.put(k2, d2);
-    /* Use HashMap as fake region for keySetOnServer, size, and get methods */
-    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 testPrintRegionContents() {
-    Consumer c = new Consumer(region);
-    c.printRegionContents();
-  }
-
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index b3112e7..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeDataTest.java
+++ /dev/null
@@ -1,68 +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 EmployeeDataTest {
-  private EmployeeData d;
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  @Before
-  public void setup() {
-    EmployeeKey k = new EmployeeKey("First Last", 3001);
-    d = new EmployeeData(k, 40000, 38);
-  }
-
-  @Test
-  public void testGetNameAndNumber() {
-    assertEquals("First Last", d.getNameAndNumber().getName());
-    assertEquals(3001, d.getNameAndNumber().getEmplNumber());
-  }
-
-  @Test
-  public void testGetSalary() {
-    assertEquals(40000, d.getSalary());
-  }
-
-  @Test
-  public void testGetHoursPerWeek() {
-    assertEquals(38, d.getHoursPerWeek());
-  }
-
-  @Test
-  public void testEquals() {
-    EmployeeKey otherKey = new EmployeeKey("First Last", 3001);
-    EmployeeData otherData = new EmployeeData(otherKey, 40000, 38);
-    assertTrue(d.equals(otherData));
-    EmployeeKey nonMatchingKey = new EmployeeKey("Othername", 1);
-    EmployeeData nonMatchingData = new EmployeeData(nonMatchingKey, 39999, 40);
-    assertFalse(d.equals(nonMatchingData));
-  }
-
-  @Test
-  public void testToString() {
-    assertEquals(d.getNameAndNumber().toString() + " salary=40000 hoursPerWeek=38", d.toString());
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index c5e880f..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/EmployeeKeyTest.java
+++ /dev/null
@@ -1,59 +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 EmployeeKeyTest {
-
-  private EmployeeKey k;
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  @Before
-  public void setup() {
-    k = new EmployeeKey("First Last", 3001);
-  }
-
-  @Test
-  public void testGetName() {
-    assertEquals("First Last", k.getName());
-  }
-
-  @Test
-  public void testGetEmplNumber() {
-    assertEquals(3001, k.getEmplNumber());
-  }
-
-  @Test
-  public void testEquals() {
-    EmployeeKey otherKey = new EmployeeKey("First Last", 3001);
-    assertTrue(k.equals(otherKey));
-    EmployeeKey nonMatchingKey = new EmployeeKey("Othername", 1);
-    assertFalse(k.equals(nonMatchingKey));
-  }
-
-  @Test
-  public void testToString() {
-    assertEquals("Name: First Last Employee Number: 3001", k.toString());
-  }
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/src/test/java/org/apache/geode/examples/partitioned/ExampleTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ExampleTest.java b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ExampleTest.java
new file mode 100644
index 0000000..757e664
--- /dev/null
+++ b/partitioned/src/test/java/org/apache/geode/examples/partitioned/ExampleTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.assertj.core.api.Assertions.assertThat;
+
+import org.apache.geode.cache.Region;
+import org.geode.examples.util.Mocks;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+
+public class ExampleTest {
+
+  @Rule
+  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+  @Test
+  public void testExample() throws Exception {
+    Region<EmployeeKey, EmployeeData> region = Mocks.region("example-region");
+    new Example().accept(region);
+
+    assertThat(systemOutRule.getLog()).contains("Counted 10 keys in region");
+    assertThat(systemOutRule.getLog()).contains("Jamie Jive");
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/partitioned/src/test/java/org/apache/geode/examples/partitioned/PartitionedTest.java
----------------------------------------------------------------------
diff --git a/partitioned/src/test/java/org/apache/geode/examples/partitioned/PartitionedTest.java b/partitioned/src/test/java/org/apache/geode/examples/partitioned/PartitionedTest.java
deleted file mode 100644
index d2a1288..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/PartitionedTest.java
+++ /dev/null
@@ -1,164 +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.hamcrest.core.Is.*;
-import static org.junit.Assert.*;
-import static org.junit.Assume.*;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import org.apache.commons.exec.CommandLine;
-import org.apache.commons.exec.DefaultExecuteResultHandler;
-import org.apache.commons.exec.ExecuteException;
-import org.apache.commons.exec.environment.EnvironmentUtils;
-import org.apache.geode.examples.utils.ShellUtil;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
-/**
- * Tests for the shell scripts of the partitioned example
- */
-public class PartitionedTest {
-
-  public static final String GEODE_LOCATOR_PORT = "GEODE_LOCATOR_PORT=";
-  private static final String startScriptFileName = "startAll.sh";
-  private static final String stopScriptFileName = "stopAll.sh";
-  private static final String pidkillerScriptFileName = "pidkiller.sh";
-  private boolean processRunning = false;
-  private ShellUtil shell = new ShellUtil();
-  private final long scriptTimeout = TimeUnit.SECONDS.toMillis(120);
-  private static final Logger logger = Logger.getAnonymousLogger();
-
-  @Rule
-  public TemporaryFolder testFolder = new TemporaryFolder();
-
-  private int locatorPort;
-  private Map environment;
-
-  @Before
-  public void setup() throws IOException {
-    // ignores test if running on windows
-    assumeThat(System.getProperty("os.name").startsWith("Windows"), is(false));
-
-    locatorPort = getAvailablePort();
-    environment = EnvironmentUtils.getProcEnvironment();
-    EnvironmentUtils.addVariableToEnvironment(environment, GEODE_LOCATOR_PORT + locatorPort);
-    logger.fine("Locator port: " + locatorPort);
-  }
-
-  @Test
-  public void checkIfScriptsExistsAndAreExecutable() throws IOException {
-    assertTrue(
-        shell.getFileFromClassLoader(startScriptFileName).map(x -> x.isFile()).orElse(false));
-    assertTrue(shell.getFileFromClassLoader(stopScriptFileName).map(x -> x.isFile()).orElse(false));
-  }
-
-  @Test
-  public void executeStartThenStopScript() throws InterruptedException, IOException {
-    final int exitCodeStart = executeScript(startScriptFileName);
-    assertEquals(0, exitCodeStart);
-
-    final int exitCodeStop = executeScript(stopScriptFileName);
-    assertEquals(0, exitCodeStop);
-  }
-
-  @Test
-  public void failToStopWhenNoServersAreRunning() throws InterruptedException, IOException {
-    final int exitCode;
-
-    exitCode = executeScript(stopScriptFileName);
-    assertEquals(1, exitCode);
-  }
-
-  /**
-   * Execute the kill script that looks for pid files
-   * 
-   * @throws IOException
-   * @throws InterruptedException
-   */
-  private void runKillScript() throws IOException, InterruptedException {
-    CommandLine cmdLine = CommandLine.parse(shell.getFileFromClassLoader(pidkillerScriptFileName)
-        .map(x -> x.getAbsolutePath()).orElseThrow(IllegalArgumentException::new));
-    cmdLine.addArgument(testFolder.getRoot().getAbsolutePath());
-
-    DefaultExecuteResultHandler resultHandler =
-        shell.execute(cmdLine, scriptTimeout, environment, testFolder.getRoot());
-    resultHandler.waitFor(scriptTimeout);
-  }
-
-  /**
-   * Given a script file name, runs the script and return the exit code. If exitCode != 0 extract
-   * and prints exception.
-   * 
-   * @param scriptName
-   * @return <code>int</code> with exitCode
-   * @throws IOException
-   * @throws InterruptedException
-   */
-  private int executeScript(String scriptName) throws IOException, InterruptedException {
-    final int exitCode;
-    DefaultExecuteResultHandler resultHandler =
-        shell.execute(scriptName, scriptTimeout, environment, testFolder.getRoot());
-    processRunning = true;
-    resultHandler.waitFor();
-
-    logger.finest(String.format("Executing %s...", scriptName));
-    exitCode = resultHandler.getExitValue();
-
-    // extract and log exception if any happened
-    if (exitCode != 0) {
-      ExecuteException executeException = resultHandler.getException();
-      logger.log(Level.SEVERE, executeException.getMessage(), executeException);
-    }
-    return exitCode;
-  }
-
-  @After
-  public void tearDown() {
-    if (processRunning) {
-      try {
-        runKillScript();
-      } catch (IOException | InterruptedException e) {
-        e.printStackTrace();
-      }
-    }
-  }
-
-  /**
-   * Get a random available port
-   * 
-   * @return <code>int</code> port number
-   */
-  private static int getAvailablePort() {
-    try (ServerSocket socket = new ServerSocket(0)) {
-      int port = socket.getLocalPort();
-      socket.close();
-      return port;
-    } catch (IOException ioex) {
-      logger.log(Level.SEVERE, ioex.getMessage(), ioex);
-    }
-    throw new IllegalStateException("No TCP/IP ports available.");
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/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
deleted file mode 100644
index c042af5..0000000
--- a/partitioned/src/test/java/org/apache/geode/examples/partitioned/ProducerTest.java
+++ /dev/null
@@ -1,44 +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.mockito.Matchers.any;
-import static org.mockito.Mockito.*;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import org.apache.geode.cache.Region;
-
-public class ProducerTest {
-
-  @Rule
-  public ExpectedException expectedException = ExpectedException.none();
-
-  private Producer pMock = mock(Producer.class);
-  private Region<EmployeeKey, EmployeeData> region = mock(Region.class);
-  private EmployeeData dataMock = mock(EmployeeData.class);
-
-
-  @Test
-  public void testPopulateRegion() {
-    Producer producer = new Producer(region);
-    producer.populateRegion();
-    verify(region, times(10)).put(any(), any());
-
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/README.md
----------------------------------------------------------------------
diff --git a/replicated/README.md b/replicated/README.md
index 6af34a5..696c48a 100644
--- a/replicated/README.md
+++ b/replicated/README.md
@@ -17,47 +17,28 @@ limitations under the License.
 
 # Geode replicated region example
 
-This is one of the most basic examples. 
-Two servers host a replicated region.
-The producer puts 50 entries into the replicated region. The consumer prints the number of entries in the region.
+This is a simple example that demonstrates putting values into a
+replicated region, checking the size, and retrieving the values.
 
-## Steps
-1. From the ```geode-examples/replicated``` directory, start the locator and two servers:
-
-        $ scripts/startAll.sh
+This example assumes you have installed Java and Geode.
 
-2. Run the producer:
-
-        $ ../gradlew run -Pmain=Producer
-        ...
-        ... 
-        INFO: Done. Inserted 50 entries.
+## Steps
+1. From the ```geode-examples/replicated``` directory, start the locator and two servers
 
-3. Run the consumer:
+        $ gfsh run --file=scripts/start.gfsh
 
-        $ ../gradlew run -Pmain=Consumer
-        ...
-        ...
-        INFO: Done. 50 entries available on the server(s).
+2. Run the example to create entries in the region
 
-4. Kill one of the servers:
+        $ ./gradlew run
 
-        $ $GEODE_HOME/bin/gfsh
-        ...
-        gfsh>connect
-        gfsh>stop server --name=server1
-        gfsh>quit
+3. Kill one of the servers
 
-5. Run the consumer a second time, and notice that all the entries are still available due to replication: 
+        $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1"
 
-        $ ../gradlew run -Pmain=Consumer
-        ...
-        ...
-        INFO: Done. 50 entries available on the server(s).
+4. Run the example a second time, and notice that all the entries are still available due to replication
 
-6. Shut down the system:
+        $ ./gradlew run 
 
-        $ scripts/stopAll.sh
+5. Shut down the system:
 
-This example is a simple demonstration of using gfsh and some basic Geode APIs,
-as well how to write tests using mocks for Geode applications.
+        $ gfsh run --file=scripts/stop.gfsh

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/build.gradle
----------------------------------------------------------------------
diff --git a/replicated/build.gradle b/replicated/build.gradle
deleted file mode 100644
index 52283ec..0000000
--- a/replicated/build.gradle
+++ /dev/null
@@ -1,20 +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.
- */
-
-sourceSets.test {
-  resources.srcDirs = ["${projectDir}/scripts"]
-}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/.gitignore
----------------------------------------------------------------------
diff --git a/replicated/scripts/.gitignore b/replicated/scripts/.gitignore
deleted file mode 100644
index 32f8870..0000000
--- a/replicated/scripts/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-locator1/
-server*/

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/pidkiller.sh
----------------------------------------------------------------------
diff --git a/replicated/scripts/pidkiller.sh b/replicated/scripts/pidkiller.sh
deleted file mode 100755
index ecf8f2d..0000000
--- a/replicated/scripts/pidkiller.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-# @brief Script that look for .pid files on a directory and kill those processes.
-#
-
-export DIR=$1
-
-if [ $# -eq 0 ]
-  then
-    echo "No arguments supplied. Script needs directory to look for pid files."
-    exit 1
-fi
-
-for pid in `find $DIR -name "*.pid"`
-do
- echo "Found: $pid"
- kill -9 `cat $pid`
- echo "Killed."
-done
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/setEnv.sh
----------------------------------------------------------------------
diff --git a/replicated/scripts/setEnv.sh b/replicated/scripts/setEnv.sh
deleted file mode 100755
index e9e860e..0000000
--- a/replicated/scripts/setEnv.sh
+++ /dev/null
@@ -1,33 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-## check if locator port has been set otherwise set to default
-export GEODE_LOCATOR_PORT="${GEODE_LOCATOR_PORT:-10334}"
-
-## check if GEODE_HOME has been set
-: ${GEODE_HOME?"GEODE_HOME enviroment variable needs to be set"}
-
-## check if gfsh script is accessible and print version
-: ${GEODE_HOME/bin/gfsh?"gfsh doesn't seem to be available. Please check $GEODE_HOME"}
-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/c21e76b2/replicated/scripts/start.gfsh
----------------------------------------------------------------------
diff --git a/replicated/scripts/start.gfsh b/replicated/scripts/start.gfsh
new file mode 100644
index 0000000..3399719
--- /dev/null
+++ b/replicated/scripts/start.gfsh
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+start locator --bind-address=127.0.0.1
+
+start server --name=server1 --locators=127.0.0.1[10334] --server-port=0
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0
+
+create region --name=example-region --type=REPLICATE
+
+list members
+describe region --name=example-region
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/startAll.sh
----------------------------------------------------------------------
diff --git a/replicated/scripts/startAll.sh b/replicated/scripts/startAll.sh
deleted file mode 100755
index 2b08f19..0000000
--- a/replicated/scripts/startAll.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-set -e
-
-current=`pwd`
-
-cd `dirname $0`
-
-. ./setEnv.sh
-
-cd $current
-
-#export GEODE_LOCATOR_PORT="${GEODE_LOCATOR_PORT:-10334}"
-# start a locator
-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
-done
-
-# create a region using GFSH
-gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "create region --name=myRegion --type=REPLICATE"
-
-gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "list members"
-
-exit 0
-

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/stop.gfsh
----------------------------------------------------------------------
diff --git a/replicated/scripts/stop.gfsh b/replicated/scripts/stop.gfsh
new file mode 100644
index 0000000..9281b31
--- /dev/null
+++ b/replicated/scripts/stop.gfsh
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+connect --locator=127.0.0.1[10334]
+shutdown --include-locators=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/scripts/stopAll.sh
----------------------------------------------------------------------
diff --git a/replicated/scripts/stopAll.sh b/replicated/scripts/stopAll.sh
deleted file mode 100755
index a6364a8..0000000
--- a/replicated/scripts/stopAll.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-set -e
-
-current=`pwd`
-
-cd `dirname $0`
-
-. ./setEnv.sh
-
-cd $current
-
-gfsh -e "connect --locator=localhost[${GEODE_LOCATOR_PORT}]" -e "shutdown --include-locators=true"

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
----------------------------------------------------------------------
diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java b/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
deleted file mode 100644
index fb54a52..0000000
--- a/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
+++ /dev/null
@@ -1,60 +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.replicated;
-
-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 setRegion(Region region) {
-    this.region = region;
-  }
-
-  private Region region;
-  private final String locatorHost = System.getProperty("GEODE_LOCATOR_HOST", "localhost");
-  private final int locatorPort = Integer.getInteger("GEODE_LOCATOR_PORT", 10334);
-  protected static final String REGION_NAME = "myRegion";
-  static final int NUM_ENTRIES = 50;
-
-  public BaseClient() {
-    this.clientCache = getClientCache();
-  }
-
-  protected Region getRegion() {
-    if (region == null) {
-      region = getClientCache()
-          .<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
-          .create(REGION_NAME);
-    }
-    return region;
-  }
-
-  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/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
----------------------------------------------------------------------
diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java b/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
deleted file mode 100644
index 8124199..0000000
--- a/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
+++ /dev/null
@@ -1,37 +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.replicated;
-
-import org.apache.geode.cache.client.ClientCache;
-
-public class Consumer extends BaseClient {
-
-  public static void main(String[] args) {
-    new Consumer().countEntriesOnServer();
-  }
-
-  public Consumer() {}
-
-  public Consumer(ClientCache clientCache) {
-    this.clientCache = clientCache;
-  }
-
-  public int countEntriesOnServer() {
-    int size = getRegion().keySetOnServer().size();
-    logger.info(String.format("Done. %d entries available on the server(s).", size));
-    return size;
-  }
-
-}


[5/5] geode-examples git commit: GEODE-2831 Fix typo

Posted by ab...@apache.org.
GEODE-2831 Fix typo


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

Branch: refs/heads/develop
Commit: 5ebbc817e3b77a07750c3512c0040f92c93cf393
Parents: 69973da
Author: Anthony Baker <ab...@apache.org>
Authored: Tue May 9 16:57:58 2017 -0700
Committer: Anthony Baker <ab...@apache.org>
Committed: Tue May 9 16:57:58 2017 -0700

----------------------------------------------------------------------
 .../main/java/org/apache/geode/examples/loader/QuoteLoader.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/5ebbc817/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
----------------------------------------------------------------------
diff --git a/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
index 522365d..4359572 100644
--- a/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
+++ b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
@@ -83,7 +83,7 @@ public class QuoteLoader implements CacheLoader<String, String>, Declarable {
     quotes.put("Orson Scott Card",
         "Everybody walks past a thousand story ideas every day. The good writers are the ones who see five or six of them. Most people don’t see any.");
     quotes.put("Ray Bradbury",
-        "Any man who keeps working is not a failure. He may not be a great writer, but if he applies the old-fashioned virtues of hard, constant labor, he’ll eventually make some kind of career for himself as writer.");
+        "Any man who keeps working is not a failure. He may not be a great writer, but if he applies the old-fashioned virtues of hard, constant labor, he’ll eventually make some kind of career for himself as a writer.");
     quotes.put("Robert Benchley",
         "It took me fifteen years to discover I had no talent for writing, but I couldn’t give it up because by that time I was too famous.");
     quotes.put("Somerset Maugham",


[3/5] geode-examples git commit: GEODE-2831 Add cache loader example

Posted by ab...@apache.org.
GEODE-2831 Add cache loader example

Add a cache loader example.  Fix a few path issues and an eclipse
project dependency.


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

Branch: refs/heads/develop
Commit: 4a678e448b6580075ac23ce58864875c4eadeeaa
Parents: c21e76b
Author: Anthony Baker <ab...@apache.org>
Authored: Thu Apr 27 11:35:17 2017 -0700
Committer: Anthony Baker <ab...@apache.org>
Committed: Thu Apr 27 17:12:58 2017 -0700

----------------------------------------------------------------------
 .gitignore                                      |   4 +-
 build.gradle                                    |  27 +++--
 gradle.properties                               |   2 +-
 gradle/ide.gradle                               |   6 ++
 gradle/rat.gradle                               |   7 +-
 loader/README.md                                |  58 +++++++++++
 loader/scripts/start.gfsh                       |  25 +++++
 loader/scripts/stop.gfsh                        |  18 ++++
 .../apache/geode/examples/loader/Example.java   |  71 +++++++++++++
 .../geode/examples/loader/QuoteLoader.java      | 102 +++++++++++++++++++
 .../geode/examples/loader/ExampleTest.java      |  56 ++++++++++
 partitioned/README.md                           |   6 +-
 partitioned/scripts/start.gfsh                  |   6 +-
 replicated/README.md                            |  20 ++--
 replicated/scripts/start.gfsh                   |   2 +-
 settings.gradle                                 |   1 +
 .../java/org/geode/examples/util/Mocks.java     |   8 ++
 17 files changed, 396 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 88e27ec..bc00815 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,7 +13,9 @@ build/
 build-eclipse/
 /tags
 
-
+locator
+server1
+server2
 
 *.iml
 *.ipr

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/build.gradle
----------------------------------------------------------------------
diff --git a/build.gradle b/build.gradle
index 8289ead..3f4a569 100644
--- a/build.gradle
+++ b/build.gradle
@@ -73,23 +73,38 @@ allprojects {
   }
 }
 
+configurations {
+  testArchives
+}
+
+dependencies {
+  testArchives sourceSets.test.output
+}
+
 subprojects {
   dependencies {
-    runtime "org.slf4j:slf4j-log4j12:$slf4jVersion"
-    
-    testCompile project.parent.sourceSets.test.output
+    compile "org.apache.logging.log4j:log4j-core:$log4jVersion"
+    runtime "org.apache.logging.log4j:log4j-slf4j-impl:$log4jVersion"
+    testCompile project(path: ':', configuration: 'testArchives') 
   }
   
+  task cleanServer << {
+    delete 'locator'
+    delete 'server1'
+    delete 'server2'
+  }
+  clean.finalizedBy cleanServer
+
   def geodePath = "${System.env.PATH}${System.getProperty('path.separator')}${installDir}/bin"
-  task start(type: Exec, dependsOn: [installGeode, build]) {
-    workingDir buildDir
+  task start(type: Exec, dependsOn: [installGeode, build, cleanServer]) {
+    workingDir projectDir
     environment 'GEODE_HOME', installDir
     environment 'PATH', geodePath
     commandLine 'sh', '-c', "gfsh run --file=${projectDir}/scripts/start.gfsh"
   }
 
   task stop(type: Exec, dependsOn: installGeode) {
-    workingDir buildDir
+    workingDir projectDir
     environment 'GEODE_HOME', installDir
     environment 'PATH', geodePath
     commandLine 'sh', '-c', "gfsh run --file=${projectDir}/scripts/stop.gfsh"

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/gradle.properties
----------------------------------------------------------------------
diff --git a/gradle.properties b/gradle.properties
index 83479a1..60428c3 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -22,5 +22,5 @@ assertjVersion = 3.6.2
 awaitilityVersion = 1.7.0
 junitVersion = 4.12
 mockitocoreVersion = 1.10.19
-slf4jVersion = 1.7.22
+log4jVersion = 2.7
 systemrulesVersion = 1.16.1

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/gradle/ide.gradle
----------------------------------------------------------------------
diff --git a/gradle/ide.gradle b/gradle/ide.gradle
index b3da6ab..4d3d808 100644
--- a/gradle/ide.gradle
+++ b/gradle/ide.gradle
@@ -20,6 +20,12 @@ allprojects {
     classpath {
       defaultOutputDir = file('build-eclipse')
       downloadSources = true
+      file {
+        whenMerged { classpath ->
+          // Remove missing resource dirs
+          classpath.entries.removeAll { entry -> (entry.path.contains('geode-examples/build/resources')) }
+        }
+      }  
     }
   }
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/gradle/rat.gradle
----------------------------------------------------------------------
diff --git a/gradle/rat.gradle b/gradle/rat.gradle
index 33d95ca..fe73400 100644
--- a/gradle/rat.gradle
+++ b/gradle/rat.gradle
@@ -58,7 +58,12 @@ rat {
     '**/*.patch',
     '**/*.diff',
     '**/*.rej',
-    '**/*.orig'
+    '**/*.orig',
+
+    // working directories
+    '**/locator/**',
+    '**/server1/**',
+    '**/server2/**'
   ]
 }
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/README.md
----------------------------------------------------------------------
diff --git a/loader/README.md b/loader/README.md
new file mode 100644
index 0000000..db61cfb
--- /dev/null
+++ b/loader/README.md
@@ -0,0 +1,58 @@
+<!--
+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.
+-->
+
+# Geode cache loader example
+
+This is a simple example that demonstrates loading values using a
+`CacheLoader`.  Invoking `Region.get()` causes the `CacheLoader` to
+produce a value that is stored in the region.  This approach is
+commonly used to fetch data from other systems like a database.
+
+This example assumes you have installed Java and Geode.
+
+## Steps
+
+1. From the `geode-examples/loader` directory, build the example and
+   run unit tests
+
+        $ ../gradlew build
+
+2. Next start the locator and two servers
+
+        $ gfsh run --file=scripts/start.gfsh
+
+3. Run the example to load the entries
+
+        $ ../gradlew run
+
+    The example fetches the entries twice.  The first retrieval is slow,
+    simulating a network call.  Subsequent retrievals are much faster since the
+    values are stored in the cache.  The loader logs requests into the Geode
+    server logs.  You can find those at `build/server1/server1.log` or
+    `build/server2/server2.log`.
+
+4. Kill one of the servers
+
+        $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1"
+
+5. Run the example a second time, and notice that all the entries are still available due to replication
+
+        $ ../gradlew run 
+
+6. Shut down the system:
+
+        $ gfsh run --file=scripts/stop.gfsh

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/scripts/start.gfsh
----------------------------------------------------------------------
diff --git a/loader/scripts/start.gfsh b/loader/scripts/start.gfsh
new file mode 100644
index 0000000..a078862
--- /dev/null
+++ b/loader/scripts/start.gfsh
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+start locator --name=locator --bind-address=127.0.0.1
+
+start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/main
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/main
+
+create region --name=example-region --type=REPLICATE --cache-loader=org.apache.geode.examples.loader.QuoteLoader
+
+list members
+describe region --name=example-region
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/scripts/stop.gfsh
----------------------------------------------------------------------
diff --git a/loader/scripts/stop.gfsh b/loader/scripts/stop.gfsh
new file mode 100644
index 0000000..9281b31
--- /dev/null
+++ b/loader/scripts/stop.gfsh
@@ -0,0 +1,18 @@
+#
+# 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.
+#
+connect --locator=127.0.0.1[10334]
+shutdown --include-locators=true
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/src/main/java/org/apache/geode/examples/loader/Example.java
----------------------------------------------------------------------
diff --git a/loader/src/main/java/org/apache/geode/examples/loader/Example.java b/loader/src/main/java/org/apache/geode/examples/loader/Example.java
new file mode 100644
index 0000000..c80676f
--- /dev/null
+++ b/loader/src/main/java/org/apache/geode/examples/loader/Example.java
@@ -0,0 +1,71 @@
+/*
+ * 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.loader;
+
+import java.util.Arrays;
+import java.util.function.Consumer;
+
+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 class Example implements Consumer<Region<String, String>> {
+  private static final String[] AUTHORS =
+      ("Anton Chekhov,C. J. Cherryh,Dorothy Parker,Douglas Adams,Emily Dickinson,"
+          + "Ernest Hemingway,F. Scott Fitzgerald,Henry David Thoreau,Henry Wadsworth Longfellow,"
+          + "Herman Melville,Jean-Paul Sartre,Mark Twain,Orson Scott Card,Ray Bradbury,Robert Benchley,"
+          + "Somerset Maugham,Stephen King,Terry Pratchett,Ursula K. Le Guin,William Faulkner")
+              .split(",");
+
+  public static void main(String[] args) {
+    // connect to the locator using default port 10334
+    ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334)
+        .set("log-level", "WARN").create();
+
+    // create a local region that matches the server region
+    Region<String, String> region =
+        cache.<String, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY)
+            .create("example-region");
+
+    new Example().accept(region);
+    cache.close();
+  }
+
+  @Override
+  public void accept(Region<String, String> region) {
+    // initial fetch invokes the cache loader
+    {
+      long start = System.currentTimeMillis();
+      Arrays.stream(AUTHORS)
+          .forEach(author -> System.out.println(author + ": " + region.get(author)));
+
+      long elapsed = System.currentTimeMillis() - start;
+      System.out.println(
+          String.format("\n\nLoaded %d definitions in %d ms\n\n", AUTHORS.length, elapsed));
+    }
+
+    // fetch from cache, really fast!
+    {
+      long start = System.currentTimeMillis();
+      Arrays.stream(AUTHORS)
+          .forEach(author -> System.out.println(author + ": " + region.get(author)));
+
+      long elapsed = System.currentTimeMillis() - start;
+      System.out.println(
+          String.format("\n\nFetched %d cached definitions in %d ms\n\n", AUTHORS.length, elapsed));
+    }
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
----------------------------------------------------------------------
diff --git a/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
new file mode 100644
index 0000000..bc28bca
--- /dev/null
+++ b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
@@ -0,0 +1,102 @@
+/*
+ * 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.loader;
+
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.geode.cache.CacheLoader;
+import org.apache.geode.cache.CacheLoaderException;
+import org.apache.geode.cache.Declarable;
+import org.apache.geode.cache.LoaderHelper;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class QuoteLoader implements CacheLoader<String, String>, Declarable {
+  private static final Logger log = LogManager.getLogger(QuoteLoader.class);
+
+  private final Map<String, String> quotes;
+
+  public QuoteLoader() {
+    quotes = getQuotes();
+  }
+
+  @Override
+  public void init(Properties props) {}
+
+  @Override
+  public void close() {}
+
+  @Override
+  public String load(LoaderHelper<String, String> helper) throws CacheLoaderException {
+
+    log.info("Loading quote for {} into region {}", helper.getKey(), helper.getRegion().getName());
+    String quote = quotes.get(helper.getKey());
+
+    try {
+      // simulate network delay for a REST call or a database query
+      Thread.sleep(100);
+      return quote;
+
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new CacheLoaderException(e);
+    }
+  }
+
+  Map<String, String> getQuotes() {
+    Map<String, String> quotes = new ConcurrentHashMap<String, String>();
+
+    // sourced from http://www.writersdigest.com/writing-quotes
+    quotes.put("Anton Chekhov",
+        "My own experience is that once a story has been written, one has to cross out the beginning and the end. It is there that we authors do most of our lying");
+    quotes.put("C. J. Cherryh",
+        "It is perfectly okay to write garbage—as long as you edit brilliantly");
+    quotes.put("Dorothy Parker", "I can’t write five words but that I change seven");
+    quotes.put("Douglas Adams",
+        "I love deadlines. I like the whooshing sound they make as they fly by");
+    quotes.put("Emily Dickinson", "A wounded deer leaps the highest");
+    quotes.put("Ernest Hemingway", "Prose is architecture, not interior decoration");
+    quotes.put("F. Scott Fitzgerald",
+        "Begin with an individual, and before you know it you have created a type; begin with a type, and you find you have created – nothing");
+    quotes.put("Henry David Thoreau",
+        "Not that the story need be long, but it will take a long while to make it short");
+    quotes.put("Henry Wadsworth Longfellow",
+        "Great is the art of beginning, but greater is the art of ending");
+    quotes.put("Herman Melville", "To produce a mighty book, you must choose a mighty theme");
+    quotes.put("Jean-Paul Sartre", "Poetry creates the myth, the prose writer draws its portrait");
+    quotes.put("Mark Twain",
+        "Most writers regard the truth as their most valuable possession, and therefore are most economical in its use");
+    quotes.put("Orson Scott Card",
+        "Everybody walks past a thousand story ideas every day. The good writers are the ones who see five or six of them. Most people don’t see any");
+    quotes.put("Ray Bradbury",
+        "Any man who keeps working is not a failure. He may not be a great writer, but if he applies the old-fashioned virtues of hard, constant labor, he’ll eventually make some kind of career for himself as writer");
+    quotes.put("Robert Benchley",
+        "It took me fifteen years to discover I had no talent for writing, but I couldn’t give it up because by that time I was too famous");
+    quotes.put("Somerset Maugham",
+        "If you can tell stories, create characters, devise incidents, and have sincerity and passion, it doesn’t matter a damn how you write");
+    quotes.put("Stephen King",
+        "I try to create sympathy for my characters, then turn the monsters loose");
+    quotes.put("Terry Pratchett",
+        "There’s no such thing as writer’s block. That was invented by people in California who couldn’t write");
+    quotes.put("Ursula K. Le Guin",
+        "The unread story is not a story; it is little black marks on wood pulp. The reader, reading it, makes it live: a live thing, a story");
+    quotes.put("William Faulkner",
+        "Get it down. Take chances. It may be bad, but it’s the only way you can do anything really good");
+
+    return quotes;
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
----------------------------------------------------------------------
diff --git a/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java b/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
new file mode 100644
index 0000000..158cef7
--- /dev/null
+++ b/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
@@ -0,0 +1,56 @@
+/*
+ * 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.loader;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.apache.geode.cache.LoaderHelper;
+import org.apache.geode.cache.Region;
+import org.geode.examples.util.Mocks;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.SystemOutRule;
+
+public class ExampleTest {
+
+  @Rule
+  public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
+
+  @Test
+  public void testExample() throws Exception {
+    QuoteLoader loader = new QuoteLoader();
+    Region<String, String> region = Mocks.region("example-region");
+
+    @SuppressWarnings("unchecked")
+    LoaderHelper<String, String> helper = mock(LoaderHelper.class);
+    when(helper.getRegion()).thenReturn(region);
+
+    when(region.get(any())).then(inv -> {
+      String key = inv.getArgumentAt(0, String.class);
+      when(helper.getKey()).thenReturn(key);
+
+      return loader.load(helper);
+    });
+
+    new Example().accept(region);
+
+    assertThat(systemOutRule.getLog()).contains("Anton Chekhov");
+    assertThat(systemOutRule.getLog()).contains("Loaded 20 definitions");
+    assertThat(systemOutRule.getLog()).contains("Fetched 20 cached definitions");
+  }
+}

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/partitioned/README.md
----------------------------------------------------------------------
diff --git a/partitioned/README.md b/partitioned/README.md
index 1643d06..db960bf 100644
--- a/partitioned/README.md
+++ b/partitioned/README.md
@@ -39,7 +39,7 @@ Each step in this example specifies paths relative to that directory.
 
 1. Build the example (with the `EmployeeKey` and `EmployeeData` classes)
 
-        $ ./gradlew build
+        $ ../gradlew build
 
 2. Run a script that starts a locator and two servers.  Each of the servers
 hosts the partitioned region.  The example classes will be placed onto the
@@ -50,7 +50,7 @@ classpath when the script starts the servers.
 3. Run the example to put 10 entries into the `example-region`. The data
 will also be retrieved from the region and printed to the console.
 
-        $ ./gradlew run
+        $ ../gradlew run
 
 4. Run a `gfsh` command to see the contents of the region
 
@@ -101,7 +101,7 @@ the entries of the ```EmployeeRegion``` are still available on the
 remaining server.
 Those hosted by the server that was stopped were lost.
 
-        $ ./gradlew run
+        $ ../gradlew run
 
 7. Shut down the cluster
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/partitioned/scripts/start.gfsh
----------------------------------------------------------------------
diff --git a/partitioned/scripts/start.gfsh b/partitioned/scripts/start.gfsh
index 0da16d8..84f95a7 100644
--- a/partitioned/scripts/start.gfsh
+++ b/partitioned/scripts/start.gfsh
@@ -14,10 +14,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-start locator --bind-address=127.0.0.1
+start locator --name=locator --bind-address=127.0.0.1
 
-start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../classes/main
-start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../classes/main
+start server --name=server1 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/main
+start server --name=server2 --locators=127.0.0.1[10334] --server-port=0 --classpath=../build/classes/main
 
 create region --name=example-region --type=PARTITION
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/replicated/README.md
----------------------------------------------------------------------
diff --git a/replicated/README.md b/replicated/README.md
index 696c48a..4d0d32e 100644
--- a/replicated/README.md
+++ b/replicated/README.md
@@ -23,22 +23,28 @@ replicated region, checking the size, and retrieving the values.
 This example assumes you have installed Java and Geode.
 
 ## Steps
-1. From the ```geode-examples/replicated``` directory, start the locator and two servers
+
+1. From the `geode-examples/replicated` directory, build the example and
+   run unit tests
+
+        $ ../gradlew build
+
+2. Next start the locator and two servers
 
         $ gfsh run --file=scripts/start.gfsh
 
-2. Run the example to create entries in the region
+3. Run the example to create entries in the region
 
-        $ ./gradlew run
+        $ ../gradlew run
 
-3. Kill one of the servers
+4. Kill one of the servers
 
         $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1"
 
-4. Run the example a second time, and notice that all the entries are still available due to replication
+5. Run the example a second time, and notice that all the entries are still available due to replication
 
-        $ ./gradlew run 
+        $ ../gradlew run 
 
-5. Shut down the system:
+6. Shut down the system:
 
         $ gfsh run --file=scripts/stop.gfsh

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/replicated/scripts/start.gfsh
----------------------------------------------------------------------
diff --git a/replicated/scripts/start.gfsh b/replicated/scripts/start.gfsh
index 3399719..acc58a5 100644
--- a/replicated/scripts/start.gfsh
+++ b/replicated/scripts/start.gfsh
@@ -14,7 +14,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
-start locator --bind-address=127.0.0.1
+start locator --name=locator --bind-address=127.0.0.1
 
 start server --name=server1 --locators=127.0.0.1[10334] --server-port=0
 start server --name=server2 --locators=127.0.0.1[10334] --server-port=0

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/settings.gradle
----------------------------------------------------------------------
diff --git a/settings.gradle b/settings.gradle
index 28a63f8..7c07f23 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -18,3 +18,4 @@ rootProject.name = 'geode-examples'
 
 include 'replicated'
 include 'partitioned'
+include 'loader'

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/4a678e44/src/test/java/org/geode/examples/util/Mocks.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/geode/examples/util/Mocks.java b/src/test/java/org/geode/examples/util/Mocks.java
index ec36681..d5007f7 100644
--- a/src/test/java/org/geode/examples/util/Mocks.java
+++ b/src/test/java/org/geode/examples/util/Mocks.java
@@ -17,6 +17,7 @@ package org.geode.examples.util;
 import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.doAnswer;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -39,6 +40,13 @@ public class Mocks {
     when(region.values()).thenReturn(data.values());
     when(region.size()).thenReturn(data.size());
     when(region.keySetOnServer()).thenReturn(data.keySet());
+    when(region.containsKey(any())).then(inv -> data.containsKey(getKey(inv)));
+    when(region.containsKeyOnServer(any())).then(inv -> data.containsKey(getKey(inv)));
+    
+    doAnswer(inv -> {
+      data.putAll((Map<? extends K, ? extends V>) inv.getArguments()[0]);
+      return inv.getArguments();
+    }).when(region).putAll(any());
 
     return region;
   }


[4/5] geode-examples git commit: GEODE-2831 Update examples to clarify steps to follow

Posted by ab...@apache.org.
GEODE-2831 Update examples to clarify steps to follow


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

Branch: refs/heads/develop
Commit: 69973da734c95e2d3ed96fb6c2edcf5106632695
Parents: 4a678e4
Author: Anthony Baker <ab...@apache.org>
Authored: Tue May 9 14:15:47 2017 -0700
Committer: Anthony Baker <ab...@apache.org>
Committed: Tue May 9 14:15:47 2017 -0700

----------------------------------------------------------------------
 loader/README.md                                | 10 +----
 .../geode/examples/loader/QuoteLoader.java      | 40 ++++++++++----------
 partitioned/README.md                           | 13 +++----
 .../geode/examples/partitioned/EmployeeKey.java |  6 +--
 replicated/README.md                            |  4 +-
 5 files changed, 30 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode-examples/blob/69973da7/loader/README.md
----------------------------------------------------------------------
diff --git a/loader/README.md b/loader/README.md
index db61cfb..e69d9c9 100644
--- a/loader/README.md
+++ b/loader/README.md
@@ -45,14 +45,6 @@ This example assumes you have installed Java and Geode.
     server logs.  You can find those at `build/server1/server1.log` or
     `build/server2/server2.log`.
 
-4. Kill one of the servers
-
-        $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1"
-
-5. Run the example a second time, and notice that all the entries are still available due to replication
-
-        $ ../gradlew run 
-
-6. Shut down the system:
+4. Shut down the system:
 
         $ gfsh run --file=scripts/stop.gfsh

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/69973da7/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
----------------------------------------------------------------------
diff --git a/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
index bc28bca..522365d 100644
--- a/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
+++ b/loader/src/main/java/org/apache/geode/examples/loader/QuoteLoader.java
@@ -62,40 +62,40 @@ public class QuoteLoader implements CacheLoader<String, String>, Declarable {
 
     // sourced from http://www.writersdigest.com/writing-quotes
     quotes.put("Anton Chekhov",
-        "My own experience is that once a story has been written, one has to cross out the beginning and the end. It is there that we authors do most of our lying");
+        "My own experience is that once a story has been written, one has to cross out the beginning and the end. It is there that we authors do most of our lying.");
     quotes.put("C. J. Cherryh",
-        "It is perfectly okay to write garbage—as long as you edit brilliantly");
-    quotes.put("Dorothy Parker", "I can’t write five words but that I change seven");
+        "It is perfectly okay to write garbage—as long as you edit brilliantly.");
+    quotes.put("Dorothy Parker", "I can’t write five words but that I change seven.");
     quotes.put("Douglas Adams",
-        "I love deadlines. I like the whooshing sound they make as they fly by");
-    quotes.put("Emily Dickinson", "A wounded deer leaps the highest");
-    quotes.put("Ernest Hemingway", "Prose is architecture, not interior decoration");
+        "I love deadlines. I like the whooshing sound they make as they fly by.");
+    quotes.put("Emily Dickinson", "A wounded deer leaps the highest.");
+    quotes.put("Ernest Hemingway", "Prose is architecture, not interior decoration.");
     quotes.put("F. Scott Fitzgerald",
-        "Begin with an individual, and before you know it you have created a type; begin with a type, and you find you have created – nothing");
+        "Begin with an individual, and before you know it you have created a type; begin with a type, and you find you have created – nothing.");
     quotes.put("Henry David Thoreau",
-        "Not that the story need be long, but it will take a long while to make it short");
+        "Not that the story need be long, but it will take a long while to make it short.");
     quotes.put("Henry Wadsworth Longfellow",
-        "Great is the art of beginning, but greater is the art of ending");
-    quotes.put("Herman Melville", "To produce a mighty book, you must choose a mighty theme");
-    quotes.put("Jean-Paul Sartre", "Poetry creates the myth, the prose writer draws its portrait");
+        "Great is the art of beginning, but greater is the art of ending.");
+    quotes.put("Herman Melville", "To produce a mighty book, you must choose a mighty theme.");
+    quotes.put("Jean-Paul Sartre", "Poetry creates the myth, the prose writer draws its portrait.");
     quotes.put("Mark Twain",
-        "Most writers regard the truth as their most valuable possession, and therefore are most economical in its use");
+        "Most writers regard the truth as their most valuable possession, and therefore are most economical in its use.");
     quotes.put("Orson Scott Card",
-        "Everybody walks past a thousand story ideas every day. The good writers are the ones who see five or six of them. Most people don’t see any");
+        "Everybody walks past a thousand story ideas every day. The good writers are the ones who see five or six of them. Most people don’t see any.");
     quotes.put("Ray Bradbury",
-        "Any man who keeps working is not a failure. He may not be a great writer, but if he applies the old-fashioned virtues of hard, constant labor, he’ll eventually make some kind of career for himself as writer");
+        "Any man who keeps working is not a failure. He may not be a great writer, but if he applies the old-fashioned virtues of hard, constant labor, he’ll eventually make some kind of career for himself as writer.");
     quotes.put("Robert Benchley",
-        "It took me fifteen years to discover I had no talent for writing, but I couldn’t give it up because by that time I was too famous");
+        "It took me fifteen years to discover I had no talent for writing, but I couldn’t give it up because by that time I was too famous.");
     quotes.put("Somerset Maugham",
-        "If you can tell stories, create characters, devise incidents, and have sincerity and passion, it doesn’t matter a damn how you write");
+        "If you can tell stories, create characters, devise incidents, and have sincerity and passion, it doesn’t matter a damn how you write.");
     quotes.put("Stephen King",
-        "I try to create sympathy for my characters, then turn the monsters loose");
+        "I try to create sympathy for my characters, then turn the monsters loose.");
     quotes.put("Terry Pratchett",
-        "There’s no such thing as writer’s block. That was invented by people in California who couldn’t write");
+        "There’s no such thing as writer’s block. That was invented by people in California who couldn’t write.");
     quotes.put("Ursula K. Le Guin",
-        "The unread story is not a story; it is little black marks on wood pulp. The reader, reading it, makes it live: a live thing, a story");
+        "The unread story is not a story; it is little black marks on wood pulp. The reader, reading it, makes it live: a live thing, a story.");
     quotes.put("William Faulkner",
-        "Get it down. Take chances. It may be bad, but it’s the only way you can do anything really good");
+        "Get it down. Take chances. It may be bad, but it’s the only way you can do anything really good.");
 
     return quotes;
   }

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/69973da7/partitioned/README.md
----------------------------------------------------------------------
diff --git a/partitioned/README.md b/partitioned/README.md
index db960bf..6334ce1 100644
--- a/partitioned/README.md
+++ b/partitioned/README.md
@@ -87,21 +87,18 @@ will also be retrieved from the region and printed to the console.
     the entries will be on each server.  And, the quantity on each server may
     vary if the example is started over and run again.
 
-5. The region entries are distributed across both servers.
-Stop one of the servers
+5. The region entries are distributed across both servers.  Stop one of the servers
 
         $ gfsh
         ...
         gfsh>connect --locators=127.0.0.1[10334]
         gfsh>stop server --name=server1
-        gfsh>quit
 
-6. Run the consumer a second time, and notice that approximately half of
-the entries of the ```EmployeeRegion``` are still available on the
-remaining server.
-Those hosted by the server that was stopped were lost.
+6. Run the query a second time, and notice that all the entries hosted on
+   `server1` are missing as expected.  Those hosted by the server that was stopped
+    were lost.
 
-        $ ../gradlew run
+        gfsh>query --query="select e.key from /example-region.entries e"
 
 7. Shut down the cluster
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/69973da7/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
----------------------------------------------------------------------
diff --git a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
index dd9d6ec..e6b475d 100644
--- a/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
+++ b/partitioned/src/main/java/org/apache/geode/examples/partitioned/EmployeeKey.java
@@ -38,10 +38,8 @@ public class EmployeeKey implements Serializable {
 
   @Override
   public int hashCode() {
-    final int prime = 31;
-    int result = 1;
-    result = prime * result + emplNumber;
-    result = prime * result + ((name == null) ? 0 : name.hashCode());
+    int result = name.hashCode();
+    result = 31 * result + emplNumber;
     return result;
   }
 

http://git-wip-us.apache.org/repos/asf/geode-examples/blob/69973da7/replicated/README.md
----------------------------------------------------------------------
diff --git a/replicated/README.md b/replicated/README.md
index 4d0d32e..7a5a0f8 100644
--- a/replicated/README.md
+++ b/replicated/README.md
@@ -41,9 +41,9 @@ This example assumes you have installed Java and Geode.
 
         $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "stop server --name=server1"
 
-5. Run the example a second time, and notice that all the entries are still available due to replication
+5. Run a gfsh query, and notice that all the entries are still available due to replication
 
-        $ ../gradlew run 
+        $ gfsh -e "connect --locator=127.0.0.1[10334]" -e "query --query='select e.key from /example-region.entries e'"
 
 6. Shut down the system: