You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ma...@apache.org on 2016/07/08 19:47:35 UTC
[04/11] incubator-geode git commit: [GEODE-33] - Adding geode-example
module Creating a simple example for replicated regions to test the proposed
example model Adding script tests Adding server folders to gitignore Adding
gitignore and readme files
[GEODE-33] - Adding geode-example module
Creating a simple example for replicated regions to test the proposed example model
Adding script tests
Adding server folders to gitignore
Adding gitignore and readme files
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/bd75c732
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/bd75c732
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/bd75c732
Branch: refs/heads/develop
Commit: bd75c732aa21d4d92e78d5cd960a507039d0fd40
Parents: 617d313
Author: William Markito <wm...@pivotal.io>
Authored: Wed Jun 8 20:30:32 2016 -0700
Committer: William Markito <wm...@pivotal.io>
Committed: Fri Jul 8 12:42:39 2016 -0700
----------------------------------------------------------------------
geode-examples/README.md | 68 ++++++++
geode-examples/build.gradle | 51 ++++++
geode-examples/gradle.properties | 19 +++
.../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 53636 bytes
.../gradle/wrapper/gradle-wrapper.properties | 6 +
geode-examples/gradlew | 160 +++++++++++++++++++
geode-examples/gradlew.bat | 90 +++++++++++
geode-examples/replicated/README.md | 39 +++++
geode-examples/replicated/build.gradle | 16 ++
geode-examples/replicated/scripts/.gitignore | 2 +
geode-examples/replicated/scripts/setEnv.sh | 24 +++
geode-examples/replicated/scripts/startAll.sh | 40 +++++
geode-examples/replicated/scripts/stopAll.sh | 22 +++
.../geode/examples/replicated/BaseClient.java | 63 ++++++++
.../geode/examples/replicated/Consumer.java | 44 +++++
.../geode/examples/replicated/Producer.java | 40 +++++
.../geode/examples/replicated/ConsumerTest.java | 66 ++++++++
.../geode/examples/replicated/ProducerTest.java | 73 +++++++++
.../examples/replicated/ReplicatedTest.java | 155 ++++++++++++++++++
.../geode/examples/replicated/ShellUtil.java | 33 ++++
geode-examples/settings.gradle | 19 +++
21 files changed, 1030 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/README.md
----------------------------------------------------------------------
diff --git a/geode-examples/README.md b/geode-examples/README.md
new file mode 100644
index 0000000..25a0dfc
--- /dev/null
+++ b/geode-examples/README.md
@@ -0,0 +1,68 @@
+# Apache Geode examples
+
+This is the home of Apache Geode examples that are bundled with the project. Contributions<sup>[2]</sup> and corrections are as usual welcome and if you have any suggestions come talk to us at [dev@geode.incubator.apache.org](mailto:dev@geode.incubator.apache.org) or just submit a [pull request](https://github.com/apache/incubator-geode/pull/new/develop).
+
+## Example requirements
+
+All examples:
+ * Needs to be testable. (unit tests, integration tests or what's applicable) - Tests will ran through project CI.
+ * Should be `Gradle` projects or part of existing ones. <sup>There could be a few exceptions here, but community should have consensus to accept</sup>
+ * 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 setup and run. (Diagrams give extra credits).
+ * Donations need to be licensed through ASL 2.0 and contributors need to file an ICLA<sup>[3]</sup>
+
+## Structure
+
+### Quick start & Installation
+
+ * [How to Install](http://geode.docs.pivotal.io/docs/getting_started/installation/install_standalone.html)
+ * [Apache Geode in 15 minutes or Less](http://geode.docs.pivotal.io/docs/getting_started/15_minute_quickstart_gfsh.html)
+
+### Basics
+
+ * [Replicated Region]()
+ * Partitioned Region
+ * Persistence
+ * OQL (Querying)
+
+### Intermediate
+
+ * PDX & Serialization
+ * Functions
+ * CacheLoader & CacheWriter
+ * Listeners
+ * Async Event Queues
+ * Continuous Querying
+ * Transactions
+ * Eviction
+ * Expiration
+ * Overflow
+ * Security
+ * Off-heap
+
+### Advanced
+
+ * WAN Gateway
+ * Durable subscriptions
+ * Delta propagation
+ * Network partition detection
+ * D-lock
+ * Compression
+ * Resource manager
+ * PDX Advanced
+
+### Use cases & integrations
+
+ This section should have self contained little projects that illustrate a use case or integration with some other projects.
+
+ * SpringBoot Application
+ * HTTP Session replication
+ * Redis
+ * Memcached
+ * Spark Connector
+
+## References
+
+- [1] - https://cwiki.apache.org/confluence/display/GEODE/Criteria+for+Code+Submissions
+- [2] - https://cwiki.apache.org/confluence/display/GEODE/How+to+Contribute
+- [3] - http://www.apache.org/licenses/#clas
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/build.gradle
----------------------------------------------------------------------
diff --git a/geode-examples/build.gradle b/geode-examples/build.gradle
new file mode 100644
index 0000000..fe0d93b
--- /dev/null
+++ b/geode-examples/build.gradle
@@ -0,0 +1,51 @@
+/*
+ * 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:'java'
+
+ repositories {
+ maven {
+ url "https://repository.apache.org/content/repositories/snapshots/"
+ }
+ mavenCentral()
+ }
+
+ dependencies {
+ compile "org.apache.geode:geode-core:$geodeVersion"
+// testCompile "org.apache.geode:geode-junit:$geodeVersion"
+ testCompile "junit:junit:$junitVersion"
+ testCompile "org.mockito:mockito-core:$mockitocoreVersion"
+ compile "com.jayway.awaitility:awaitility:1.7.0"
+ }
+
+ 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')}"]
+ }
+ }
+
+}
+
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/gradle.properties
----------------------------------------------------------------------
diff --git a/geode-examples/gradle.properties b/geode-examples/gradle.properties
new file mode 100644
index 0000000..31e0ed5
--- /dev/null
+++ b/geode-examples/gradle.properties
@@ -0,0 +1,19 @@
+#
+# 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.
+#
+geodeVersion = 1.0.0-incubating.M3-SNAPSHOT
+junitVersion = 4.12
+mockitocoreVersion = 1.10.19
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/gradle/wrapper/gradle-wrapper.jar
----------------------------------------------------------------------
diff --git a/geode-examples/gradle/wrapper/gradle-wrapper.jar b/geode-examples/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..9411448
Binary files /dev/null and b/geode-examples/gradle/wrapper/gradle-wrapper.jar differ
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/gradle/wrapper/gradle-wrapper.properties
----------------------------------------------------------------------
diff --git a/geode-examples/gradle/wrapper/gradle-wrapper.properties b/geode-examples/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..9af0d52
--- /dev/null
+++ b/geode-examples/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,6 @@
+#Wed Jun 01 15:34:43 PDT 2016
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-2.9-bin.zip
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/gradlew
----------------------------------------------------------------------
diff --git a/geode-examples/gradlew b/geode-examples/gradlew
new file mode 100755
index 0000000..9d82f78
--- /dev/null
+++ b/geode-examples/gradlew
@@ -0,0 +1,160 @@
+#!/usr/bin/env bash
+
+##############################################################################
+##
+## Gradle start up script for UN*X
+##
+##############################################################################
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS=""
+
+APP_NAME="Gradle"
+APP_BASE_NAME=`basename "$0"`
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD="maximum"
+
+warn ( ) {
+ echo "$*"
+}
+
+die ( ) {
+ echo
+ echo "$*"
+ echo
+ exit 1
+}
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+case "`uname`" in
+ CYGWIN* )
+ cygwin=true
+ ;;
+ Darwin* )
+ darwin=true
+ ;;
+ MINGW* )
+ msys=true
+ ;;
+esac
+
+# Attempt to set APP_HOME
+# Resolve links: $0 may be a link
+PRG="$0"
+# Need this for relative symlinks.
+while [ -h "$PRG" ] ; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`"/$link"
+ fi
+done
+SAVED="`pwd`"
+cd "`dirname \"$PRG\"`/" >/dev/null
+APP_HOME="`pwd -P`"
+cd "$SAVED" >/dev/null
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD="$JAVA_HOME/jre/sh/java"
+ else
+ JAVACMD="$JAVA_HOME/bin/java"
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD="java"
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
+ MAX_FD_LIMIT=`ulimit -H -n`
+ if [ $? -eq 0 ] ; then
+ if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
+ MAX_FD="$MAX_FD_LIMIT"
+ fi
+ ulimit -n $MAX_FD
+ if [ $? -ne 0 ] ; then
+ warn "Could not set maximum file descriptor limit: $MAX_FD"
+ fi
+ else
+ warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
+ fi
+fi
+
+# For Darwin, add options to specify how the application appears in the dock
+if $darwin; then
+ GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
+fi
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin ; then
+ APP_HOME=`cygpath --path --mixed "$APP_HOME"`
+ CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
+ JAVACMD=`cygpath --unix "$JAVACMD"`
+
+ # We build the pattern for arguments to be converted via cygpath
+ ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
+ SEP=""
+ for dir in $ROOTDIRSRAW ; do
+ ROOTDIRS="$ROOTDIRS$SEP$dir"
+ SEP="|"
+ done
+ OURCYGPATTERN="(^($ROOTDIRS))"
+ # Add a user-defined pattern to the cygpath arguments
+ if [ "$GRADLE_CYGPATTERN" != "" ] ; then
+ OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
+ fi
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ i=0
+ for arg in "$@" ; do
+ CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
+ CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
+
+ if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
+ eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
+ else
+ eval `echo args$i`="\"$arg\""
+ fi
+ i=$((i+1))
+ done
+ case $i in
+ (0) set -- ;;
+ (1) set -- "$args0" ;;
+ (2) set -- "$args0" "$args1" ;;
+ (3) set -- "$args0" "$args1" "$args2" ;;
+ (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
+ (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
+ (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
+ (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
+ (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
+ (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
+ esac
+fi
+
+# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
+function splitJvmOpts() {
+ JVM_OPTS=("$@")
+}
+eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
+JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
+
+exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/gradlew.bat
----------------------------------------------------------------------
diff --git a/geode-examples/gradlew.bat b/geode-examples/gradlew.bat
new file mode 100644
index 0000000..8a0b282
--- /dev/null
+++ b/geode-examples/gradlew.bat
@@ -0,0 +1,90 @@
+@if "%DEBUG%" == "" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS=
+
+set DIRNAME=%~dp0
+if "%DIRNAME%" == "" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if "%ERRORLEVEL%" == "0" goto init
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto init
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:init
+@rem Get command-line arguments, handling Windowz variants
+
+if not "%OS%" == "Windows_NT" goto win9xME_args
+if "%@eval[2+2]" == "4" goto 4NT_args
+
+:win9xME_args
+@rem Slurp the command line arguments.
+set CMD_LINE_ARGS=
+set _SKIP=2
+
+:win9xME_args_slurp
+if "x%~1" == "x" goto execute
+
+set CMD_LINE_ARGS=%*
+goto execute
+
+:4NT_args
+@rem Get arguments from the 4NT Shell from JP Software
+set CMD_LINE_ARGS=%$
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
+
+:end
+@rem End local scope for the variables with windows NT shell
+if "%ERRORLEVEL%"=="0" goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
+exit /b 1
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/README.md
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/README.md b/geode-examples/replicated/README.md
new file mode 100644
index 0000000..d6c0936
--- /dev/null
+++ b/geode-examples/replicated/README.md
@@ -0,0 +1,39 @@
+# Geode replicated region example
+
+This is one of the most basic examples for Geode.
+It created a replicated region and insert a couple of entries and then print the number of entries in the server.
+
+## Steps
+1. Start servers
+```
+$ scripts/startAll.sh
+```
+1. Run producer
+```
+$ gradle run -Pmain=Producer
+...
+...
+INFO: Done. Inserted 50 entries.
+```
+1. Run consumer
+```
+$ gradle run -Pmain=Consumer
+...
+...
+INFO: Done. 50 entries available on the server(s).
+```
+1. Kill a node
+```
+$ ???
+```
+1. Run the consumer a 2nd time
+```
+$ gradle run -Pmain=Consumer
+...
+...
+INFO: Done. 50 entries available on the server(s).
+```
+
+This example is a simple demonstration on basic APIs of Geode as well how to write tests using mocks for Geode applications.
+
+TODO: assume jUnit4
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/build.gradle
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/build.gradle b/geode-examples/replicated/build.gradle
new file mode 100644
index 0000000..ae6f28c
--- /dev/null
+++ b/geode-examples/replicated/build.gradle
@@ -0,0 +1,16 @@
+/*
+ * 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.
+ */
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/scripts/.gitignore
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/scripts/.gitignore b/geode-examples/replicated/scripts/.gitignore
new file mode 100644
index 0000000..32f8870
--- /dev/null
+++ b/geode-examples/replicated/scripts/.gitignore
@@ -0,0 +1,2 @@
+locator1/
+server*/
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/scripts/setEnv.sh
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/scripts/setEnv.sh b/geode-examples/replicated/scripts/setEnv.sh
new file mode 100755
index 0000000..77784ff
--- /dev/null
+++ b/geode-examples/replicated/scripts/setEnv.sh
@@ -0,0 +1,24 @@
+#
+# 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.
+#
+#!/bin/bash
+
+## 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`"
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/scripts/startAll.sh
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/scripts/startAll.sh b/geode-examples/replicated/scripts/startAll.sh
new file mode 100755
index 0000000..f543412
--- /dev/null
+++ b/geode-examples/replicated/scripts/startAll.sh
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+#!/bin/bash
+
+set -e
+
+cd `dirname $0`
+
+. ./setEnv.sh
+
+# start a locator
+gfsh start locator --name=locator1 --mcast-port=0
+
+# start 2 servers on a random available port
+for N in {1..2}
+do
+ gfsh start server --locators=localhost[10334] --name=server$N --server-port=0 --mcast-port=0
+done
+
+# create a region using GFSH
+gfsh -e "connect" -e "create region --name=myRegion --type=REPLICATE"
+
+gfsh -e "connect" -e "list members"
+
+exit 0
+
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/scripts/stopAll.sh
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/scripts/stopAll.sh b/geode-examples/replicated/scripts/stopAll.sh
new file mode 100755
index 0000000..4d792de
--- /dev/null
+++ b/geode-examples/replicated/scripts/stopAll.sh
@@ -0,0 +1,22 @@
+#
+# 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.
+#
+#!/bin/bash
+set -e
+
+cd `dirname $0`
+
+gfsh -e "connect" -e "shutdown --include-locators=true"
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
new file mode 100644
index 0000000..45349ac
--- /dev/null
+++ b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/BaseClient.java
@@ -0,0 +1,63 @@
+/*
+ * 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 com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.ClientCacheFactory;
+import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
+
+import java.util.logging.Logger;
+
+
+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("locatorHost", "localhost");
+ private final int locatorPort = Integer.getInteger("locatorPort", 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/incubator-geode/blob/bd75c732/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
new file mode 100644
index 0000000..7fa32b1
--- /dev/null
+++ b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Consumer.java
@@ -0,0 +1,44 @@
+/*
+ * 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 com.gemstone.gemfire.cache.client.ClientCache;
+
+/**
+ * @author wmarkito
+ * @date 5/31/16.
+ */
+public class Consumer extends BaseClient {
+
+ public static void main(String[] args) {
+ new Consumer().countEntries();
+ }
+
+ public Consumer() {
+ }
+
+ public Consumer(ClientCache clientCache) {
+ this.clientCache = clientCache;
+ }
+
+ public int countEntries() {
+ int size = getRegion().keySetOnServer().size();
+ logger.info(String.format("Done. %d entries available on the server(s).", size));
+ return size;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
new file mode 100644
index 0000000..e25ca01
--- /dev/null
+++ b/geode-examples/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java
@@ -0,0 +1,40 @@
+/*
+ * 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 com.gemstone.gemfire.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/incubator-geode/blob/bd75c732/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
new file mode 100644
index 0000000..3231092
--- /dev/null
+++ b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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 com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.client.ClientCache;
+import com.gemstone.gemfire.cache.client.NoAvailableLocatorsException;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.Set;
+
+import static org.mockito.Mockito.*;
+import static org.junit.Assert.*;
+
+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 countEntriesOnARegion() throws Exception {
+ assertEquals(consumer.NUM_ENTRIES, consumer.countEntries());
+ }
+
+ @Test
+ public void countEntriesOnARegionWithNoConnection() throws Exception {
+ consumer = new Consumer();
+ expectedException.expect(NoAvailableLocatorsException.class);
+ assertEquals(consumer.NUM_ENTRIES, consumer.countEntries());
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
new file mode 100644
index 0000000..85f8038
--- /dev/null
+++ b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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 com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.client.ClientCache;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.util.Set;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+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 populateRegion() throws Exception {
+ producer = new Producer(clientCache);
+ producer.setRegion(region);
+
+ producer.populateRegion();
+ verify(region, times(producer.NUM_ENTRIES)).put(any(), any());
+ }
+
+ @Test
+ public void populateWhenRegionDoesntExist() throws Exception {
+ producer = new Producer(clientCache);
+ expectedException.expect(NullPointerException.class);
+ producer.populateRegion();
+ }
+
+ @After
+ public void tearDown() {
+
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
new file mode 100644
index 0000000..aeccf7b
--- /dev/null
+++ b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java
@@ -0,0 +1,155 @@
+/*
+ * 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.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class ReplicatedTest {
+
+ //TODO: parameterize
+ private String startScript = "/Users/wmarkito/Pivotal/ASF/incubator-geode/geode-examples/replicated/scripts/startAll.sh";
+ private String stopScript = "/Users/wmarkito/Pivotal/ASF/incubator-geode/geode-examples/replicated/scripts/stopAll.sh";
+ private boolean processRunning = false;
+ private ShellUtil shell;
+ private Process process;
+
+ private int waitTimeForScript=1000;
+
+ @Before
+ public void setup() {
+ if (processRunning) {
+ stop();
+ }
+ }
+
+ @Test
+ public void checkIfScriptsExists() throws IOException {
+//
+// ClassLoader classLoader = getClass().getClassLoader();
+//
+// File file = new File(classLoader.getResource("startAll.sh").getFile());
+//
+// System.out.println(file.getCanonicalPath());
+
+ assertTrue(Paths.get(startScript).toFile().exists());
+ assertTrue(Paths.get(stopScript).toFile().exists());
+ }
+
+
+ private Process start() {
+ Process p = new ShellUtil().exec(startScript).get();
+ processRunning = true;
+ return p;
+ }
+
+ private Process stop() {
+ Process p = new ShellUtil().exec(stopScript).get();
+ processRunning = false;
+ return p;
+ }
+
+
+ @Test
+ public void testStartAndStop() throws InterruptedException {
+ boolean status = false;
+ int exitCode = -1;
+
+ process = start();
+ status = process.waitFor(waitTimeForScript, TimeUnit.SECONDS);
+ exitCode = process.exitValue();
+ verify(status, exitCode);
+
+ process = stop();
+ status = process.waitFor(waitTimeForScript, TimeUnit.SECONDS);
+ exitCode = process.exitValue();
+ verify(status, exitCode);
+ }
+
+ private void verify(boolean status, int exitCode) {
+ assertEquals(exitCode, 0);
+ assertEquals(status, true);
+ }
+
+ @After
+ public void tearDown() {
+ if (processRunning) {
+ stop();
+ }
+ }
+
+
+// @Test
+// public void testStopScript() {
+// assertEquals(0, new ShellUtil().exec(stopScript).get().exitValue());
+// }
+
+
+// @Test
+// public void test() {
+// Producer producer = new Producer();
+// Consumer consumer = new Consumer();
+//
+// producer.populateRegion();
+// int numEntries = consumer.countEntries();
+//
+// assertEquals(BaseClient.NUM_ENTRIES, numEntries);
+// }
+//
+// private Cache setupCacheServer() {
+// Cache cache = new CacheFactory()
+// .set("name", "geode-server")
+// .set("mcast-port", "0")
+// .set("log-file", "ReplicatedTest.log")
+// .set("log-level", "config")
+// .create();
+//
+// RegionFactory<String, String> regionFactory = cache.createRegionFactory();
+//
+// regionFactory.setDataPolicy(DataPolicy.REPLICATE);
+//
+// Region myRegion = regionFactory.create(BaseClient.REGION_NAME);
+//
+// assertNotNull("The /myExample Region was not properly configured and initialized!", myRegion);
+//// assertEquals(BaseClient.REGION_NAME, myRegion.getFullPath());
+// assertEquals(BaseClient.REGION_NAME, myRegion.getName());
+// assertTrue(myRegion.isEmpty());
+//
+// CacheServer cacheServer = cache.addCacheServer();
+//
+// cacheServer.setPort(0);
+// cacheServer.setMaxConnections(5);
+//
+// try {
+// cacheServer.start();
+// } catch (IOException e) {
+// throw new RuntimeException(e);
+// }
+// assertTrue("Cache Server is not running!", cacheServer.isRunning());
+//
+// return cache;
+// }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ShellUtil.java
----------------------------------------------------------------------
diff --git a/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ShellUtil.java b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ShellUtil.java
new file mode 100644
index 0000000..852ac88
--- /dev/null
+++ b/geode-examples/replicated/src/test/java/org/apache/geode/examples/replicated/ShellUtil.java
@@ -0,0 +1,33 @@
+/*
+ * 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.io.IOException;
+import java.util.Optional;
+
+public class ShellUtil {
+
+ public Optional<Process> exec(String command) {
+ try {
+ return Optional.of(Runtime.getRuntime().exec(command));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return Optional.empty();
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/bd75c732/geode-examples/settings.gradle
----------------------------------------------------------------------
diff --git a/geode-examples/settings.gradle b/geode-examples/settings.gradle
new file mode 100644
index 0000000..cb71558
--- /dev/null
+++ b/geode-examples/settings.gradle
@@ -0,0 +1,19 @@
+/*
+ * 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.
+ */
+rootProject.name = 'geode-examples'
+
+include 'replicated'
\ No newline at end of file