geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [11/20] incubator-geode git commit: GEODE-14: Imported modules from geode-1.0.0-SNAPSHOT-2.src.tar
Date Mon, 06 Jul 2015 21:46:32 GMT
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/HibernateTest2.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/HibernateTest2.java b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/HibernateTest2.java
new file mode 100644
index 0000000..686730c
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/HibernateTest2.java
@@ -0,0 +1,155 @@
+/*=========================================================================
+ * Copyright (c) 2002-2014, Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package hibe;
+
+import hydra.*;
+
+import java.util.*;
+import com.gemstone.gemfire.cache.*;
+
+/**
+ * A Hydra test interacts with Hiberate APIs.
+ *
+ * @see HibernatePrms
+ *
+ * @author lhughes
+ * @since 6.5
+ */
+public class HibernateTest2 {
+    
+    /* The singleton instance of EventTest in this VM */
+    static protected HibernateTest2 testInstance;
+    
+    protected boolean useTransactions;
+    // cache whether this instance should perform all operations in one invocation
+    // as a single transaction.
+    protected boolean isSerialExecution;
+
+    /**
+     * STARTTASK for Hibernate (one time execution)
+     */
+    public synchronized static void HydraTask_startTask() {
+       long counter = HibernateBB.getBB().getSharedCounters().incrementAndRead(HibernateBB.STARTTASK);
+       Log.getLogWriter().info("invoked HydraTask_startTask(), STARTTASK counter = " + counter);
+    }
+
+    /**
+     * Creates and {@linkplain #initialize initializes} the singleton
+     * instance of <code>HibernateTest2</code> in this VM.
+     */
+    public synchronized static void HydraTask_initialize() {
+       if (testInstance == null) {
+           testInstance = new HibernateTest2();
+           testInstance.initialize();
+       }
+    }
+    
+    /**
+     * @see #HydraTask_initialize
+     */
+    protected void initialize() {
+        String clientName = System.getProperty( "clientName" );
+        useTransactions = HibernatePrms.useTransactions();
+        isSerialExecution = TestConfig.tab().booleanAt(Prms.serialExecution, false);
+        long counter = HibernateBB.getBB().getSharedCounters().incrementAndRead(HibernateBB.INITTASK);
+
+
+        StringBuffer aStr = new StringBuffer();
+        aStr.append("invoked initialize() in " + clientName + "\n");
+        aStr.append("useTransactions = " + useTransactions + "\n");
+        aStr.append("isSerialExecution = " + isSerialExecution + "\n");
+        aStr.append("INITTASK counter = " + counter);
+
+        Log.getLogWriter().info(aStr.toString());
+    }
+
+    /**
+     * Initializes the test region in the peer VMs
+     */
+    public static void createPeerCache() {
+       CacheHelper.createCache(ConfigPrms.getCacheConfig());
+    }
+
+    /**
+     * Initializes the test region in the bridge server VM
+     */
+    public static void initBridgeServer() {
+       // create cache from xml
+       String cacheXmlFile = "$JTESTS/gemfirePlugins/server.xml";
+       CacheHelper.createCacheFromXml(cacheXmlFile);
+       //BridgeHelper.startBridgeServer(ConfigPrms.getBridgeConfig());
+    }
+    
+    /**
+     * TASK for hibernate test ... MasterController will continually
+     * assign until totalTaskTimeSec.
+     */
+    public static synchronized void HydraTask_doOps() {
+       testInstance.doOps();
+    }
+
+    private void doOps() {
+       long counter = HibernateBB.getBB().getSharedCounters().incrementAndRead(HibernateBB.TASK);
+       Log.getLogWriter().info("invoked doOps(), TASK counter = " + counter);
+    }
+
+    /** 
+     * TASK for jpab (benchmark) test.  Simply wait for client 
+     * to publish data.
+     */
+    public static synchronized void HydraTask_waitForJPAB() {
+      MasterController.sleepForMs(10000);
+      testInstance.displayRegions();
+    }
+    
+    /**
+     * CLOSETASK for validate regions/region sizes
+     */
+    public static synchronized void HydraTask_displayRegions() {
+       testInstance.displayRegions();
+    }
+
+    private void displayRegions() {
+       long counter = HibernateBB.getBB().getSharedCounters().incrementAndRead(HibernateBB.CLOSETASK);
+
+       StringBuffer aStr = new StringBuffer();
+       Set<Region<?,?>> rootRegions = CacheHelper.getCache().rootRegions();
+       aStr.append("There are " + rootRegions.size() + " rootRegions:\n");
+
+       for (Iterator i = rootRegions.iterator(); i.hasNext(); ) {
+          Region r = (Region)i.next();
+          aStr.append(r.getName() + " has " + r.entrySet().size() + " entries\n");
+       }
+       Log.getLogWriter().info(aStr.toString());
+    }
+    
+    /**
+     * CLOSETASK for hibernate test ... 
+     */
+    public static synchronized void HydraTask_closeTask() {
+       testInstance.closeTask();
+    }
+
+    private void closeTask() {
+       long counter = HibernateBB.getBB().getSharedCounters().incrementAndRead(HibernateBB.CLOSETASK);
+       Log.getLogWriter().info("invoked closeTask(), CLOSETASK counter = " + counter);
+    }
+    
+    /**
+     * ENDTASK for hibernate test ... time to check BB counters!
+     */
+    public static synchronized void HydraTask_endTask() {
+       testInstance = new HibernateTest2();
+       testInstance.initialize();
+       testInstance.endTask();
+    }
+
+    private void endTask() {
+       HibernateBB.getBB().printSharedCounters();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.hbm.xml b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.hbm.xml
new file mode 100644
index 0000000..b3ac67b
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.hbm.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="hibe">
+    <class name="Person" table="PERSON">
+        <cache usage="read-write"/>
+        <id name="id" column="PERSON_ID">
+            <generator class="native"/>
+        </id>
+        <property name="age"/>
+        <property name="firstname"/>
+        <property name="lastname"/>
+        <set name="events" table="PERSON_EVENT">
+          <cache usage="read-write"/>
+          <key column="PERSON_ID"/>
+          <many-to-many column="EVENT_ID" class="Event"/>
+        </set>
+    </class>
+</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.java b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.java
new file mode 100644
index 0000000..ad6e6a0
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/Person.java
@@ -0,0 +1,63 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package hibe;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Person {
+  private Long id;
+  private int age;
+  private String firstname;
+  private String lastname;
+
+  private Set<Event> events = new HashSet<Event>();
+  
+  public Person() {}
+
+  private void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setAge(int age) {
+    this.age = age;
+  }
+
+  public int getAge() {
+    return age;
+  }
+
+  public void setFirstname(String firstname) {
+    this.firstname = firstname;
+  }
+
+  public String getFirstname() {
+    return firstname;
+  }
+
+  public void setLastname(String lastname) {
+    this.lastname = lastname;
+  }
+
+  public String getLastname() {
+    return lastname;
+  }
+
+  public void setEvents(Set<Event> events) {
+    this.events = events;
+  }
+
+  public Set<Event> getEvents() {
+    return events;
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.bt
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.bt b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.bt
new file mode 100644
index 0000000..a6408d4
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.bt
@@ -0,0 +1,33 @@
+  /**
+Test each RegionShortcut config possibility.
+
+These ones won't work, so they are left out:
+
+  PARTITION_PROXY,
+  PARTITION_PROXY_REDUNDANT,
+  REPLICATE_PROXY
+
+*/
+
+hibe/hibe1.conf locatorHosts=1 locatorVMsPerHost=1 locatorThreadsPerVM=1 A=client clientHosts=1 clientVMsPerHost=4 clientThreadsPerVM=1 B=hibernate hibernateHosts=1 hibernateVMsPerHost=1 hibernateThreadsPerVM=1
+   region=
+  PARTITION,
+  PARTITION_REDUNDANT,
+  PARTITION_PERSISTENT,
+  PARTITION_REDUNDANT_PERSISTENT,
+  PARTITION_OVERFLOW,
+  PARTITION_REDUNDANT_OVERFLOW,
+  PARTITION_PERSISTENT_OVERFLOW,
+  PARTITION_REDUNDANT_PERSISTENT_OVERFLOW,
+  PARTITION_HEAP_LRU,
+  PARTITION_REDUNDANT_HEAP_LRU,
+  REPLICATE,
+  REPLICATE_PERSISTENT,
+  REPLICATE_OVERFLOW,
+  REPLICATE_PERSISTENT_OVERFLOW,
+  REPLICATE_HEAP_LRU,
+  LOCAL,
+  LOCAL_PERSISTENT,
+  LOCAL_HEAP_LRU,
+  LOCAL_OVERFLOW,
+  LOCAL_PERSISTENT_OVERFLOW

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.inc
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.inc b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.inc
new file mode 100644
index 0000000..e724405
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe.inc
@@ -0,0 +1,128 @@
+hydra.Prms-testRequirement = "Starts a locator and p2p clients in a single DS";
+hydra.Prms-testDescription = " TBD ";
+
+INCLUDE $JTESTS/hydraconfig/hydraparams1.inc;
+INCLUDE $JTESTS/hydraconfig/topology_p2p_2_locator.inc;
+
+/**
+ * Start the locators and connect them to distributed system.
+ */
+INITTASK     taskClass = hydra.DistributedSystemHelper taskMethod = createLocator
+             threadGroups = locator;
+
+INITTASK     taskClass = hydra.DistributedSystemHelper taskMethod = startLocatorAndDS
+             threadGroups = locator;
+
+INITTASK     taskClass   = hibe.HibernateTest taskMethod  = HydraTask_initialize
+             threadGroups = hibernate
+             ;
+
+INITTASK     taskClass   = hibe.HibernateTest taskMethod  = createPeerCache
+             threadGroups = locator,clients
+             ;
+
+TASK         taskClass   = hibe.HibernateTest taskMethod  = doNothing
+	     threadGroups = clients,locator
+	     maxTimesToRun = 1
+             ;
+
+
+CLOSETASK    taskClass   = hibe.HibernateTest taskMethod  = validateEventPersonRegions 
+             threadGroups = hibernate
+             ;
+             
+CLOSETASK    taskClass   = hibe.HibernateTest taskMethod  = validateEventPersonRegionsOnPeers 
+             threadGroups = clients
+             ;
+
+CLOSETASK    taskClass   = hibe.HibernateTest taskMethod  = validateQueryCacheRegion 
+             threadGroups = hibernate
+             ;       
+             
+             
+             
+CLOSETASK    taskClass   = hibe.HibernateTest taskMethod  = HydraTask_closeTask 
+             threadGroups = clients
+             ;
+
+CLOSETASK    taskClass   = hydra.DistributedSystemHelper taskMethod  = stopLocator
+             threadGroups = locator;
+             ;
+
+
+hydra.Prms-totalTaskTimeSec = 600;
+hydra.Prms-maxResultWaitSec = 180;
+
+// test controls the locator (create/start/stop)
+hydra.Prms-manageLocatorAgents = false; // turn off master-managed locators
+
+// define a cache (no regions)
+hydra.ConfigPrms-cacheConfig = gemfireCache;
+hydra.CachePrms-names        = gemfireCache;
+
+// all are peers in a single DS
+hydra.GemFirePrms-distributedSystem = ds;
+
+THREADGROUP locator
+    totalThreads = fcn ${locatorHosts} * ${locatorVMsPerHost}
+                                       * ${locatorThreadsPerVM}
+                   ncf     
+    clientNames  = fcn "hydra.TestConfigFcns.generateNames
+                        (\"locator\", ${locatorHosts}, true)"
+                   ncf;    
+THREADGROUP clients
+    totalThreads = fcn ${clientHosts} * ${clientVMsPerHost}
+                                    * ${clientThreadsPerVM}
+                   ncf     
+    clientNames  = fcn "hydra.TestConfigFcns.generateNames
+                        (\"client\", ${clientHosts}, true)"
+                   ncf;
+
+THREADGROUP hibernate
+    totalThreads = fcn ${hibernateHosts} * ${hibernateVMsPerHost}
+                                    * ${hibernateThreadsPerVM}
+                   ncf
+    clientNames  = fcn "hydra.TestConfigFcns.generateNames
+                        (\"hibernate\", ${hibernateHosts}, true)"
+                   ncf;
+
+
+
+
+// Control logging in hydra controlled portion of test
+//hydra.log.LogPrms-file_logLevel = fine;
+hydra.GemFirePrms-logLevel = fine;
+//hydra.VmPrms-extraVMArgs += "-DDistributionManager.VERBOSE=true";
+//hydra.VmPrms-extraVMArgs += "-DDistributionManager.DEBUG_JAVAGROUPS=true";
+
+
+// need same jars as the jpab (jpa benchmark) 
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/antlr-2.7.6.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/c3p0-0.9.1.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/cglib-2.2.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/commons-collections-3.1.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/dom4j-1.6.1.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/ehcache-core-2.2.0.jar;
+hydra.VmPrms-extraClassPaths += /export/mclaren1/users/sbawaska/gemfireModules/gemfire-modules/target/gemfire-modules-2.1.jar;
+hydra.VmPrms-extraClassPaths += /home/sbawaska/.m2/repository/org/hibernate/hibernate-core/3.5.0-Final/hibernate-core-3.5.0-Final.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/hibernate-index-annotation.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/infinispan-core-4.0.0.FINAL.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/javassist-3.9.0.GA.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/jbosscache-core-3.2.1.GA.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/jdo2-index.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/jpa2.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/jta-1.1.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/openjpa-index-annotation.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/oscache-2.1.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/proxool-0.8.3.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/slf4j-api-1.5.8.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/slf4j-jdk14-1.5.8.jar;
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/lib/swarmcache-1.0RC2.jar;
+
+// jpa test classes
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/jpab.jar;
+
+// hibernate jar from jpa/Hibernate/lib
+hydra.VmPrms-extraClassPaths += /export/java/users/java_share/jpa/jpab/jpa/Hibernate/lib/hibernate3.jar;
+hydra.VmPrms-extraClassPaths += /export/gcm/where/java/derby/derby-10.4.2.0/jars/insane/derby.jar;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe1.conf
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe1.conf b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe1.conf
new file mode 100644
index 0000000..5467a4e
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibe1.conf
@@ -0,0 +1,12 @@
+hydra.Prms-testRequirement = "Basic setup for a concurrent hibernate test";
+hydra.Prms-testDescription = " TBD ";
+
+INCLUDE $JTESTS/hibe/hibe.inc;
+
+hibe.HibernatePrms-cachingStrategy = ${region};
+
+INITTASK         taskClass   = hibe.HibernateTest taskMethod  = testBasic
+             threadGroups = hibernate
+             ;
+
+             
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibernate.bt
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibernate.bt b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibernate.bt
new file mode 100644
index 0000000..11c510e
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/hibe/hibernate.bt
@@ -0,0 +1,8 @@
+gemfirePlugins/p2pJPAB.conf 
+   locatorHosts=1 locatorVMsPerHost=1 locatorThreadsPerVM=1
+
+gemfirePlugins/hctJPAB.conf 
+   locatorHosts=1 locatorVMsPerHost=1 locatorThreadsPerVM=1
+   A=client clientHosts=1 clientVMsPerHost=4 clientThreadsPerVM=1
+   B=hibernate hibernateHosts=1 hibernateVMsPerHost=1 hibernateThreadsPerVM=1
+

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/hydra/readme.txt
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/hydra/readme.txt b/modules/gemfire-modules-hibernate/src/test/hydra/readme.txt
new file mode 100644
index 0000000..7a12e6b
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/hydra/readme.txt
@@ -0,0 +1,48 @@
+To run and compile these tests, you need a gemfire checkout 6.5+
+In that gemfire checkout, cd to the tests directory, and create a symbolic link to the "hibe" directory in here. eg: ln -s /Users/gregp/plugins/gemfire-plugins/src/test/hydra/hibe
+
+Then apply the following patch to build.xml:
+Index: build.xml
+===================================================================
+--- build.xml	(revision 34744)
++++ build.xml	(working copy)
+@@ -866,6 +866,7 @@
+         <pathelement location="${jetty.dir}/jsp-2.1.jar"/>
+         <pathelement location="${bcel.dir}/bcel.jar"/>
+       	<pathelement location="${osgi.core.jar}"/>
++	<pathelement
+location="/home/sbawaska/.m2/repository/org/hibernate/hibernate-core/3.5.0-Final/hibernate-core-3.5.0-Final.jar"/>
+       </classpath>
+     </javac>
+ 
+@@ -936,6 +937,7 @@
+         <pathelement location="${ant.home}/lib/ant.jar"/>
+         <pathelement location="${jetty.dir}/core-3.1.1.jar"/>
+         <pathelement location="${jetty.dir}/jsp-2.1.jar"/>
++        <pathelement
+location="/home/sbawaska/.m2/repository/org/hibernate/hibernate-core/3.5.0-Final/hibernate-core-3.5.0-Final.jar"/>
+       </classpath>
+     </javac>
+ 
+@@ -996,6 +998,7 @@
+       	<include name="hyperictest/lib/*.jar"/>
+       	<include name="hyperictest/config/*.properties"/>
+         <include name="jta/*.xml"/>
++        <include name="hibe/*.xml"/>
+         <include name="junit/runner/excluded.properties"/>
+         <include name="**/*.bt"/>
+         <include name="**/*.conf"/>
+@@ -2901,6 +2904,7 @@
+           <pathelement location="${jetty.dir}/core-3.1.1.jar"/>
+           <pathelement location="${jetty.dir}/jsp-2.1.jar"/>
+ 	        <pathelement location="cobertura.jar"/>
++          <pathelement
+location="/home/sbawaska/.m2/repository/org/hibernate/hibernate-core/3.5.0-Final/hibernate-core-3.5.0-Final.jar"/>
+         </classpath>
+ 
+         <env key="GEMFIRE" value="${product.dir}"/>
+
+
+
+In hibe/hibe.inc , there are references to the modules jar in /Users/gregp that need to be changed, also, there are also references to /export/monaco1 , so those need to be reachable. 
+In gemfire checkout main dir, run ./build.sh compile-tests execute-battery -Dbt.file=`pwd`/tests/hibe/hibe.bt

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Event.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Event.java b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Event.java
new file mode 100644
index 0000000..ed80f08
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Event.java
@@ -0,0 +1,58 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules;
+
+import java.util.Date;
+
+public class Event {
+    private Long id;
+
+    private String title;
+    private Date date;
+    private int i;
+
+    public Event() {}
+
+    public Long getId() {
+        return id;
+    }
+
+    private void setId(Long id) {
+        this.id = id;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public Integer getVersion() {
+    	return i;
+    }
+    
+    public void setVersion(int i) {
+    	this.i = i;
+    }
+    
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getTitle() {
+        return title;
+    }
+
+    public void setTitle(String title) {
+        this.title = title;
+    }
+    @Override
+    public String toString() {
+    	StringBuilder b = new StringBuilder();
+    	b.append("Event:id:"+id+" title:"+title+" date:"+date);
+    	return b.toString();
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/HibernateTestCase.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/HibernateTestCase.java b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/HibernateTestCase.java
new file mode 100644
index 0000000..1c7954c
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/HibernateTestCase.java
@@ -0,0 +1,390 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules;
+
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.Region.Entry;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+import com.gemstone.gemfire.modules.Owner.Status;
+import junit.framework.TestCase;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.cfg.AnnotationConfiguration;
+import org.hibernate.cfg.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+import java.util.logging.Level;
+
+public class HibernateTestCase extends TestCase {
+
+  private Logger log = LoggerFactory.getLogger(getClass());
+
+  //private static final String jdbcURL = "jdbc:hsqldb:hsql://localhost/test";
+  private static final String jdbcURL = "jdbc:hsqldb:mem:test";
+
+  static File tmpDir;
+
+  static String gemfireLog;
+
+  @Override
+  protected void setUp() throws Exception {
+    super.setUp();
+
+    // Create a per-user scratch directory
+    tmpDir = new File(System.getProperty("java.io.tmpdir"),
+            "gemfire_modules-" + System.getProperty("user.name"));
+    tmpDir.mkdirs();
+    tmpDir.deleteOnExit();
+
+    gemfireLog = tmpDir.getPath() +
+            System.getProperty("file.separator") + "gemfire_modules.log";
+  }
+
+  public static SessionFactory getSessionFactory(Properties overrideProps) {
+    System.setProperty("gemfire.home", "GEMFIREHOME");
+    Configuration cfg = new Configuration();
+    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
+    cfg.setProperty("hibernate.connection.driver_class",
+        "org.hsqldb.jdbcDriver");
+    // cfg.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test");
+    cfg.setProperty("hibernate.connection.url", jdbcURL);
+    cfg.setProperty("hibernate.connection.username", "sa");
+    cfg.setProperty("hibernate.connection.password", "");
+    cfg.setProperty("hibernate.connection.pool_size", "1");
+    cfg.setProperty("hibernate.connection.autocommit", "true");
+    cfg.setProperty("hibernate.hbm2ddl.auto", "update");
+
+    cfg.setProperty("hibernate.cache.region.factory_class",
+        "com.gemstone.gemfire.modules.hibernate.GemFireRegionFactory");
+    cfg.setProperty("hibernate.show_sql", "true");
+    cfg.setProperty("hibernate.cache.use_query_cache", "true");
+    //cfg.setProperty("gemfire.mcast-port", AvailablePort.getRandomAvailablePort(AvailablePort.JGROUPS)+"");
+    cfg.setProperty("gemfire.mcast-port", "5555");
+    cfg.setProperty("gemfire.statistic-sampling-enabled", "true");
+    cfg.setProperty("gemfire.log-file", gemfireLog);
+    cfg.setProperty("gemfire.writable-working-dir", tmpDir.getPath());
+    //cfg.setProperty("gemfire.statistic-archive-file", "plugin-stats-file.gfs");
+    //cfg.setProperty("gemfire.default-client-region-attributes-id", "CACHING_PROXY");
+    //cfg.setProperty("gemfire.cache-topology", "client-server");
+    //cfg.setProperty("gemfire.locators", "localhost[5432]");
+    //cfg.setProperty("gemfire.log-level", "fine");
+    // cfg.setProperty("", "");
+    cfg.addClass(Person.class);
+    cfg.addClass(Event.class);
+    if (overrideProps != null) {
+      Iterator it = overrideProps.keySet().iterator();
+      while (it.hasNext()) {
+        String key = (String)it.next();
+        cfg.setProperty(key, overrideProps.getProperty(key));
+      }
+    }
+    return cfg.buildSessionFactory();
+  }
+
+  public void testpreload() {
+    log.info("SWAP:creating session factory In hibernateTestCase");
+
+    Session session = getSessionFactory(null).openSession();
+    log.info("SWAP:session opened");
+    session.beginTransaction();
+    Event theEvent = new Event();
+    theEvent.setTitle("title");
+    theEvent.setDate(new Date());
+    session.save(theEvent);
+    Long id = theEvent.getId();
+    session.getTransaction().commit();
+    session.beginTransaction();
+    Event ev = (Event)session.get(Event.class, id);
+    log.info("SWAP:load complete: " + ev);
+    session.getTransaction().commit();
+  }
+  
+  public void testNothing() throws Exception {
+    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.ALL);
+    log.info("SWAP:creating session factory In hibernateTestCase");
+
+    Session session = getSessionFactory(null).openSession();
+    log.info("SWAP:session opened");
+    // session.setFlushMode(FlushMode.COMMIT);
+    session.beginTransaction();
+    Event theEvent = new Event();
+    theEvent.setTitle("title");
+    theEvent.setDate(new Date());
+    //session.save(theEvent);
+    session.persist(theEvent);
+    Long id = theEvent.getId();
+    session.getTransaction().commit();
+    log.info("commit complete...doing load");
+    session.beginTransaction();
+    Event ev = (Event)session.load(Event.class, id);
+    log.info("load complete: " + ev);
+    log.trace("SWAP");
+    ev.setTitle("newTitle");
+    session.save(ev);
+    log.info("commit");
+    session.getTransaction().commit();
+    log.info("save complete " + ev);
+
+    session.beginTransaction();
+    ev = (Event)session.load(Event.class, id);
+    log.info("load complete: " + ev);
+    ev.setTitle("newTitle2");
+    session.save(ev);
+    log.info("commit");
+    session.getTransaction().commit();
+    log.info("save complete " + ev);
+
+    ev = (Event)session.load(Event.class, id);
+    log.info("second load " + ev);
+    session.flush();
+    session.close();
+    log.info("flush complete session:" + session);
+
+    for (int i=0; i<5; i++) {
+      session = getSessionFactory(null).openSession();
+      log.info("doing get "+id);
+      // ev = (Event) session.load(Event.class, id);
+      ev = (Event)session.get(Event.class, id);
+      log.info("third load " + ev);
+    }
+    printExistingDB();
+    Iterator it = GemFireCacheImpl.getInstance().rootRegions().iterator();
+    while (it.hasNext()) {
+      Region r = (Region)it.next();
+      System.out.println("Region:"+r);
+      Iterator enIt = r.entrySet().iterator();
+      while (enIt.hasNext()) {
+        Region.Entry re = (Entry)enIt.next();
+        System.out.println("key:"+re.getKey()+" value:"+re.getValue());
+      }
+    }
+    Thread.sleep(3000);
+     //System.in.read();
+    // try direct data
+
+  }
+
+  public void _testInvalidation() {
+    Session s = getSessionFactory(null).openSession();
+  }
+
+  static Long personId;
+  public void testRelationship() throws Exception {
+    //java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.ALL);
+    Properties props = new Properties();
+    props.put("gemfire.topology", "client-server");
+    Session session = getSessionFactory(null).openSession();
+    session.beginTransaction();
+
+    Person thePerson = new Person();
+    thePerson.setFirstname("foo");
+    thePerson.setLastname("bar");
+    thePerson.setAge(1);
+    thePerson.setId(99L);
+    session.save(thePerson);
+    personId = thePerson.getId();
+    log.info("person saved");
+    
+    Event theEvent = new Event();
+    theEvent.setTitle("title");
+    theEvent.setDate(new Date());
+    session.save(theEvent);
+    Long eventId = theEvent.getId();
+    log.info("event saved");
+    
+    Event theEvent2 = new Event();
+    theEvent2.setTitle("title2");
+    theEvent2.setDate(new Date());
+    session.save(theEvent2);
+    Long eventId2 = theEvent2.getId();
+    log.info("event2 saved");
+    session.getTransaction().commit();
+    
+    session.beginTransaction();
+    Person aPerson = (Person) session.load(Person.class, personId);
+    Event anEvent = (Event) session.load(Event.class, eventId);
+    Event anEvent2 = (Event) session.load(Event.class, eventId2);
+    log.info("adding event to person");
+    aPerson.getE().add(anEvent);
+    aPerson.getE().add(anEvent2);
+    log.info("calling commit");
+
+    session.getTransaction().commit();
+    log.info("commit complete");
+    session.close();
+    log.info("opening new session");
+    session = getSessionFactory(null).openSession();
+    log.info("SWAP:loading person");
+    aPerson = (Person)session.load(Person.class, personId);
+    log.info("loading events");
+    Iterator<Event> e = aPerson.getE().iterator();
+    while (e.hasNext()) {
+      e.next();
+    }
+    session.close();
+    log.info("opening new session");
+    session = getSessionFactory(null).openSession();
+    log.info("SWAP:loading person");
+    aPerson = (Person)session.load(Person.class, personId);
+    log.info("loading events");
+    e = aPerson.getE().iterator();
+    while (e.hasNext()) {
+      e.next();
+    }
+
+    log.info(aPerson.getE()+"");
+    session.close();
+    //System.in.read();
+//    log.info("opening third session");
+//    session = getSessionFactory().openSession();
+//    log.info("loading person");
+//    aPerson = (Person)session.load(Person.class, personId);
+//    log.info("loading events");
+//    log.info(aPerson.getEvents()+"");
+  }
+  
+  public void _testQueryCache() throws Exception {
+    Session session = getSessionFactory(null).openSession();
+    Query q = session.createQuery("from Event");
+    q.setCacheable(true);
+    List l = q.list();
+    log.info("list:"+l);
+//    log.info("Sleeping for 10 seconds");
+//    Thread.sleep(10000);
+    l = q.list();
+    log.info("list2:"+l);
+    log.info("updating an event");
+    session.beginTransaction();
+    Event e = (Event)l.get(0);
+    e.setDate(new Date());
+    session.saveOrUpdate(e);
+    session.getTransaction().commit();
+    l = q.list();
+    log.info("list3:"+l);
+  }
+  
+  public void testInsert() {
+    Session session = getSessionFactory(null).openSession();
+    Region r = GemFireCacheImpl.getExisting().getRegion(Person.class.getCanonicalName());
+    int initSize = r.size();
+    session.beginTransaction();
+    log.info("SWAP: Saving Person");
+    Person p = new Person();
+    p.setId(10L);
+    p.setFirstname("foo");
+    p.setLastname("bar");
+    session.saveOrUpdate("Person", p);
+    session.getTransaction().commit();
+    assertEquals(1, session.getStatistics().getEntityCount());
+    assertEquals(initSize+1, r.size());
+
+    session.beginTransaction();
+    p.setAge(1);
+    session.saveOrUpdate(p);
+    session.getTransaction().commit();
+    assertEquals(1, session.getStatistics().getEntityCount());
+}
+  
+  public void testNormalRegion() {
+    Properties props = new Properties();
+    props.setProperty("gemfire.default-region-attributes-id", "LOCAL");
+    Session session = getSessionFactory(props).openSession();
+    session.beginTransaction();
+    Event theEvent = new Event();
+    theEvent.setTitle("title");
+    theEvent.setDate(new Date());
+    session.save(theEvent);
+    Long id = theEvent.getId();
+    session.getTransaction().commit();
+    session.beginTransaction();
+    Event ev = (Event)session.load(Event.class, id);
+    ev.setTitle("newTitle");
+    session.save(ev);
+    session.getTransaction().commit();
+  }
+  
+  private void printExistingDB() throws SQLException {
+    try {
+      Class.forName("org.hsqldb.jdbc.JDBCDriver");
+    }
+    catch (Exception e) {
+      System.err.println("ERROR: failed to load HSQLDB JDBC driver.");
+      e.printStackTrace();
+      return;
+    }
+
+    Connection c = DriverManager.getConnection(jdbcURL, "SA", "");
+    log.info("issuing query...");
+    ResultSet rs = c.createStatement().executeQuery("select * from events");
+    int col = rs.getMetaData().getColumnCount();
+    while (rs.next()) {
+      StringBuilder b = new StringBuilder();
+      for (int i = 1; i <= col; i++) {
+        b.append(" col:" + i + ":" + rs.getString(i));
+      }
+      log.info("Query result:" + b.toString());
+    }
+  }
+  
+  public void testEnum() {
+    AnnotationConfiguration cfg = new AnnotationConfiguration();
+    cfg.addAnnotatedClass(Owner.class);
+    cfg.setProperty("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
+    cfg.setProperty("hibernate.connection.driver_class",
+        "org.hsqldb.jdbcDriver");
+    cfg.setProperty("hibernate.connection.url", jdbcURL);
+    cfg.setProperty("hibernate.connection.username", "sa");
+    cfg.setProperty("hibernate.connection.password", "");
+    cfg.setProperty("hibernate.connection.pool_size", "1");
+    cfg.setProperty("hibernate.connection.autocommit", "true");
+    cfg.setProperty("hibernate.hbm2ddl.auto", "update");
+
+    cfg.setProperty("hibernate.cache.region.factory_class",
+        "com.gemstone.gemfire.modules.hibernate.GemFireRegionFactory");
+    cfg.setProperty("hibernate.show_sql", "true");
+    cfg.setProperty("hibernate.cache.use_query_cache", "true");
+    cfg.setProperty("gemfire.statistic-sampling-enabled", "true");
+    cfg.setProperty("gemfire.log-file", gemfireLog);
+    cfg.setProperty("gemfire.writable-working-dir", tmpDir.getPath());
+    cfg.setProperty("gemfire.mcast-port", "5555");
+    //cfg.setProperty("gemfire.cache-topology", "client-server");
+
+    SessionFactory sf = cfg.buildSessionFactory();
+    Session session = sf.openSession();
+    session.beginTransaction();
+    Owner o = new Owner();
+    o.setAddress("addr");
+    o.setCity("pdx");
+    o.setStatus(Status.PREMIUM);
+    session.save(o);
+    long id = o.getId();
+    log.info("testEnum:commiting tx");
+    session.getTransaction().commit();
+    session.close();
+    
+    session = sf.openSession();
+    Owner o1 = (Owner) session.load(Owner.class, id);
+    log.info("loaded:"+o);
+    assertEquals(o.getAddress(), o1.getAddress());
+    assertEquals(o.getCity(), o1.getCity());
+    assertEquals(o.getStatus(), o1.getStatus());
+    o1.setAddress("address2");
+    session.save(o1);
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Owner.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Owner.java b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Owner.java
new file mode 100644
index 0000000..3701711
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Owner.java
@@ -0,0 +1,177 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.persistence.Column;
+import javax.persistence.EnumType;
+import javax.persistence.Enumerated;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.hibernate.annotations.Entity;
+
+
+/**
+ * Simple JavaBean domain object representing an owner.
+ * 
+ * @author Ken Krebs
+ * @author Juergen Hoeller
+ * @author Sam Brannen
+ */
+@javax.persistence.Entity
+@Entity
+public class Owner {
+	private static final long serialVersionUID = 4315791692556052565L;
+
+	@Column(name="address")
+	private String address;
+
+	private String city;
+
+	private String telephone;
+
+//	private Set<Pet> pets;
+	@Id
+	@GeneratedValue
+	private Long id;
+	
+	private long versionNum = -1;
+
+	public enum Status {
+		NORMAL, PREMIUM
+	};
+
+	@Enumerated
+	private Status status = Status.NORMAL;
+
+	  private void setId(Long id) {
+	    this.id = id;
+	  }
+
+	  public Long getId() {
+	    return id;
+	  }
+	  
+	public String getAddress() {
+		return this.address;
+	}
+
+	public void setAddress(String address) {
+		this.address = address;
+	}
+
+	public String getCity() {
+		return this.city;
+	}
+
+	public void setCity(String city) {
+		this.city = city;
+	}
+
+	public String getTelephone() {
+		return this.telephone;
+	}
+
+	public void setTelephone(String telephone) {
+		this.telephone = telephone;
+	}
+
+	public long getVersionNum() {
+		return versionNum;
+	}
+
+	public void setVersionNum(long versionNum) {
+		this.versionNum = versionNum;
+	}
+
+	public Status getStatus() {
+		return this.status;
+	}
+
+	public void setStatus(Status state) {
+		if (state != null) {
+			this.status = state;
+		}
+	}
+
+//	protected void setPetsInternal(Set<Pet> pets) {
+//		this.pets = pets;
+//	}
+//
+//	protected Set<Pet> getPetsInternal() {
+//		if (this.pets == null) {
+//			this.pets = new HashSet<Pet>();
+//		}
+//		return this.pets;
+//	}
+//
+//	public List<Pet> getPets() {
+//		List<Pet> sortedPets = new ArrayList<Pet>(getPetsInternal());
+//		PropertyComparator.sort(sortedPets, new MutableSortDefinition("name",
+//				true, true));
+//		return Collections.unmodifiableList(sortedPets);
+//	}
+//
+//	public void addPet(Pet pet) {
+//		getPetsInternal().add(pet);
+//		pet.setOwner(this);
+//	}
+//
+//	/**
+//	 * Return the Pet with the given name, or null if none found for this Owner.
+//	 * 
+//	 * @param name
+//	 *            to test
+//	 * @return true if pet name is already in use
+//	 */
+//	public Pet getPet(String name) {
+//		return getPet(name, false);
+//	}
+//
+//	/**
+//	 * Return the Pet with the given name, or null if none found for this Owner.
+//	 * 
+//	 * @param name
+//	 *            to test
+//	 * @return true if pet name is already in use
+//	 */
+//	public Pet getPet(String name, boolean ignoreNew) {
+//		name = name.toLowerCase();
+//		for (Pet pet : getPetsInternal()) {
+//			if (!ignoreNew || !pet.isNew()) {
+//				String compName = pet.getName();
+//				compName = compName.toLowerCase();
+//				if (compName.equals(name)) {
+//					return pet;
+//				}
+//			}
+//		}
+//		return null;
+//	}
+//
+//	@Override
+//	public String toString() {
+//		return new ToStringCreator(this).append("id", this.getId())
+//				.append("new", this.isNew())
+//				.append("lastName", this.getLastName())
+//				.append("firstName", this.getFirstName())
+//				.append("address", this.address).append("city", this.city)
+//				.append("telephone", this.telephone)
+//				.append("version", this.versionNum)
+//				.append("status", this.status)
+//
+//				.toString();
+//	}
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Person.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Person.java b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Person.java
new file mode 100644
index 0000000..14e6294
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/Person.java
@@ -0,0 +1,63 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class Person {
+  private Long id;
+  private int age;
+  private String firstname;
+  private String lastname;
+
+  private Set<Event> e = new HashSet<Event>();
+  
+  public Person() {}
+
+  public void setId(Long id) {
+    this.id = id;
+  }
+
+  public Long getId() {
+    return id;
+  }
+
+  public void setAge(int age) {
+    this.age = age;
+  }
+
+  public int getAge() {
+    return age;
+  }
+
+  public void setFirstname(String firstname) {
+    this.firstname = firstname;
+  }
+
+  public String getFirstname() {
+    return firstname;
+  }
+
+  public void setLastname(String lastname) {
+    this.lastname = lastname;
+  }
+
+  public String getLastname() {
+    return lastname;
+  }
+
+  public void setE(Set<Event> events) {
+    this.e = events;
+  }
+
+  public Set<Event> getE() {
+    return e;
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/SecondVMTest.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/SecondVMTest.java b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/SecondVMTest.java
new file mode 100644
index 0000000..a0e6229
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/java/com/gemstone/gemfire/modules/SecondVMTest.java
@@ -0,0 +1,80 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules;
+
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.Properties;
+import java.util.Set;
+import java.util.logging.Level;
+
+import junit.framework.TestCase;
+
+import org.hibernate.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.cache.GemFireCache;
+import com.gemstone.gemfire.cache.Region;
+import com.gemstone.gemfire.cache.Region.Entry;
+import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
+
+public class SecondVMTest extends TestCase {
+
+  private Logger log = LoggerFactory.getLogger(getClass());
+  
+  public void testNoop() {
+    
+  }
+  public void _testStartEmptyVM() throws IOException {
+    Properties gemfireProperties = new Properties();
+    gemfireProperties.setProperty("mcast-port", "5555");
+    gemfireProperties.setProperty("log-level", "fine");
+    Cache cache = new CacheFactory(gemfireProperties).create();
+    System.in.read();
+    Iterator it = cache.rootRegions().iterator();
+    while (it.hasNext()) {
+      Region r = (Region)it.next();
+      System.out.println("Region:"+r);
+      Iterator enIt = r.entrySet().iterator();
+      while (enIt.hasNext()) {
+        Region.Entry re = (Entry)enIt.next();
+        System.out.println("key:"+re.getKey()+" value:"+re.getValue());
+      }
+    }
+  }
+  
+  public void _testStartVM() throws Exception {
+    java.util.logging.Logger.getLogger("org.hibernate").setLevel(Level.ALL);
+    Session session = HibernateTestCase.getSessionFactory(null).openSession();
+    log.info("SWAP:new session open");
+    long id = 1;
+    log.info("loading new person:"+(id));
+    GemFireCache cache = GemFireCacheImpl.getInstance();
+    Iterator<Region<?, ?>> rSet = cache.rootRegions().iterator();
+    while (rSet.hasNext()) {
+      Region<?, ?> r = rSet.next();
+      log.info("SWAP:Region "+r);
+      Iterator<?> keySet = r.keySet().iterator();
+      while (keySet.hasNext()) {
+        log.info("key:"+keySet.next());
+      }
+    }
+    log.info("loading new person:"+(id));
+    session.beginTransaction();
+    Person p = (Person)session.load(Person.class, id);
+    p.setFirstname("SecondVMfirstname"+id);
+    log.info("loading events");
+    log.info(p.getE()+"");
+    session.getTransaction().commit();
+    //System.in.read();
+  }
+  
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Event.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Event.hbm.xml b/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Event.hbm.xml
new file mode 100644
index 0000000..17faf29
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Event.hbm.xml
@@ -0,0 +1,16 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="com.gemstone.gemfire.modules">
+	<class name="Event" table="EVENTS">
+		<cache usage="read-write"/>
+		<id name="id" column="EVENT_ID">
+			<generator class="native"/>
+		</id>
+		<version name="version"/>
+		<property name="date" type="timestamp" column="EVENT_DATE"/>
+        <property name="title"/>
+	</class>
+</hibernate-mapping>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Person.hbm.xml
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Person.hbm.xml b/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Person.hbm.xml
new file mode 100644
index 0000000..a4810d7
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/resources/com/gemstone/gemfire/modules/Person.hbm.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0"?>
+<!DOCTYPE hibernate-mapping PUBLIC
+        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
+        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
+
+<hibernate-mapping package="com.gemstone.gemfire.modules">
+    <class name="Person" table="PERSON">
+        <cache usage="read-write"/>
+        <id name="id" column="PERSON_ID">
+        </id>
+        <property name="age"/>
+        <property name="firstname"/>
+        <property name="lastname"/>
+        <set name="e" table="PERSON_EVENT">
+          <cache usage="read-write"/>
+          <key column="PERSON_ID"/>
+          <many-to-many column="EVENT_ID" class="Event"/>
+        </set>
+    </class>
+</hibernate-mapping>

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/src/test/resources/log4j.properties b/modules/gemfire-modules-hibernate/src/test/resources/log4j.properties
new file mode 100644
index 0000000..c136990
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/src/test/resources/log4j.properties
@@ -0,0 +1,16 @@
+# For JBoss: Avoid to setup Log4J outside $JBOSS_HOME/server/default/deploy/log4j.xml!
+# For all other servers: Comment out the Log4J listener in web.xml to activate Log4J.
+#log4j.rootLogger=DEBUG, stdout, logfile
+log4j.rootLogger=DEBUG, stdout
+
+log4j.appender.stdout=org.apache.log4j.ConsoleAppender
+log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
+log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
+
+#log4j.appender.logfile=org.apache.log4j.RollingFileAppender
+#log4j.appender.logfile.MaxFileSize=512KB
+## Keep three backup files.
+#log4j.appender.logfile.MaxBackupIndex=3
+## Pattern to output: date priority [category] - message
+#log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
+#log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %m%n

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-hibernate/tomcat/conf/tomcat-users.xml
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-hibernate/tomcat/conf/tomcat-users.xml b/modules/gemfire-modules-hibernate/tomcat/conf/tomcat-users.xml
new file mode 100644
index 0000000..6c9f217
--- /dev/null
+++ b/modules/gemfire-modules-hibernate/tomcat/conf/tomcat-users.xml
@@ -0,0 +1,3 @@
+<?xml version='1.0' encoding='utf-8'?>
+<tomcat-users>
+</tomcat-users>

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-session-external/build.gradle
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-session-external/build.gradle b/modules/gemfire-modules-session-external/build.gradle
new file mode 100644
index 0000000..27bd9ca
--- /dev/null
+++ b/modules/gemfire-modules-session-external/build.gradle
@@ -0,0 +1,9 @@
+dependencies {
+  compile project(':gemfire-modules-session')
+
+  testCompile 'javax.servlet:servlet-api:2.5'
+  testCompile 'org.slf4j:slf4j-jdk14:1.7.7'
+  testCompile('com.mockrunner:mockrunner-servlet:1.0.8') {
+    exclude group: 'jboss'
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-session-external/pom.xml
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-session-external/pom.xml b/modules/gemfire-modules-session-external/pom.xml
new file mode 100644
index 0000000..dbbbe40
--- /dev/null
+++ b/modules/gemfire-modules-session-external/pom.xml
@@ -0,0 +1,130 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.gemstone</groupId>
+  <artifactId>gemfire-modules-session-external</artifactId>
+  <packaging>jar</packaging>
+  <version>${gemfire.modules.version}</version>
+  <url>http://maven.apache.org</url>
+  <name>gemfire-modules-session-external</name>
+
+  <parent>
+    <groupId>com.gemstone</groupId>
+    <artifactId>gemfire-modules-parent</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>servlet-api</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet.jsp</groupId>
+      <artifactId>jsp-api</artifactId>
+      <version>2.1</version>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.jdom</groupId>
+      <artifactId>jdom</artifactId>
+      <version>1.1</version>
+    </dependency>
+
+    <dependency>
+      <groupId>com.mockrunner</groupId>
+      <artifactId>mockrunner-servlet</artifactId>
+      <version>1.0.8</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>cglib</groupId>
+      <artifactId>cglib-nodep</artifactId>
+      <version>2.1_3</version>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.gemstone</groupId>
+      <artifactId>gemfire-modules-session</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>com.gemstone</groupId>
+      <artifactId>gemfire-modules</artifactId>
+      <scope>runtime</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>com.gemstone.gemfire</groupId>
+      <artifactId>gemfire</artifactId>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <scope>compile</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-jdk14</artifactId>
+    </dependency>
+  </dependencies>
+
+  <build>
+    <plugins>
+      <!--
+          Use this to run specific tests. Although the surefire
+          plugin is supposed to also be able to exclude certain
+          tests, it seems to not work very well.
+      -->
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.7.2</version>
+        <configuration>
+          <useSystemClassLoader>true</useSystemClassLoader>
+          <includes>
+            <include>**/SessionUberSuite.java</include>
+          </includes>
+          <!--
+              Normally the session manager should only be initialized
+              once. For testing though, we sometimes need to be able
+              to do so repeatedly. This is really a fallout of the
+              singleton nature of the cache.
+          -->
+          <systemPropertyVariables>
+            <gemfire.override.session.manager.count>10000
+            </gemfire.override.session.manager.count>
+          </systemPropertyVariables>
+        </configuration>
+      </plugin>
+
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-jar-plugin</artifactId>
+        <version>2.3.1</version>
+        <configuration>
+          <archive>
+            <manifest>
+              <mainClass>
+                com.gemstone.gemfire.modules.session.installer.Installer
+              </mainClass>
+            </manifest>
+          </archive>
+        </configuration>
+      </plugin>
+
+    </plugins>
+  </build>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionCachingFilter.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionCachingFilter.java b/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionCachingFilter.java
new file mode 100644
index 0000000..191eb49
--- /dev/null
+++ b/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionCachingFilter.java
@@ -0,0 +1,639 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules.session.filter;
+
+import com.gemstone.gemfire.modules.session.filter.util.ThreadLocalSession;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
+import javax.servlet.http.HttpSession;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.security.Principal;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Primary class which orchestrates everything. This is the class which gets
+ * configured in the web.xml.
+ */
+public class SessionCachingFilter implements Filter {
+
+  /**
+   * Logger instance
+   */
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SessionCachingFilter.class.getName());
+
+  /**
+   * The filter configuration object we are associated with.  If this value is
+   * null, this filter instance is not currently configured.
+   */
+  private FilterConfig filterConfig = null;
+
+  /**
+   * Some containers will want to instantiate multiple instances of this filter,
+   * but we only need one SessionManager
+   */
+  private static SessionManager manager = null;
+
+  /**
+   * Can be overridden during testing.
+   */
+  private static AtomicInteger started =
+      new AtomicInteger(
+          Integer.getInteger("gemfire.override.session.manager.count", 1));
+
+  private static int percentInactiveTimeTriggerRebuild =
+      Integer.getInteger("gemfire.session.inactive.trigger.rebuild", 80);
+
+  /**
+   * This latch ensures that at least one thread/instance has fired up the
+   * session manager before any other threads complete the init method.
+   */
+  private static CountDownLatch startingLatch = new CountDownLatch(1);
+
+  /**
+   * This request wrapper class extends the support class
+   * HttpServletRequestWrapper, which implements all the methods in the
+   * HttpServletRequest interface, as delegations to the wrapped request. You
+   * only need to override the methods that you need to change. You can get
+   * access to the wrapped request using the method getRequest()
+   */
+  public static class RequestWrapper extends HttpServletRequestWrapper {
+
+    private static final String URL_SESSION_IDENTIFIER = ";jsessionid=";
+
+    private ResponseWrapper response;
+
+    private boolean sessionFromCookie = false;
+
+    private boolean sessionFromURL = false;
+
+    private String requestedSessionId = null;
+
+    private GemfireHttpSession session = null;
+
+    private SessionManager manager;
+
+    private HttpServletRequest outerRequest = null;
+
+    /**
+     * Need to save this in case we need the original {@code RequestDispatcher}
+     */
+    private HttpServletRequest originalRequest;
+
+    public RequestWrapper(SessionManager manager,
+        HttpServletRequest request,
+        ResponseWrapper response) {
+
+      super(request);
+      this.response = response;
+      this.manager = manager;
+      this.originalRequest = request;
+
+      final Cookie[] cookies = request.getCookies();
+      if (cookies != null) {
+        for (final Cookie cookie : cookies) {
+          if (cookie.getName().equalsIgnoreCase(
+              manager.getSessionCookieName()) &&
+              cookie.getValue().endsWith("-GF")) {
+            requestedSessionId = cookie.getValue();
+            sessionFromCookie = true;
+
+            LOG.debug("Cookie contains sessionId: {}",
+                requestedSessionId);
+          }
+        }
+      }
+
+      if (requestedSessionId == null) {
+        requestedSessionId = extractSessionId();
+        LOG.debug("Extracted sessionId from URL {}", requestedSessionId);
+        if (requestedSessionId != null) {
+          sessionFromURL = true;
+        }
+      }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public HttpSession getSession() {
+      return getSession(true);
+    }
+
+    /**
+     * Create our own sessions. TODO: Handle invalidated sessions
+     *
+     * @return a HttpSession
+     */
+    @Override
+    public HttpSession getSession(boolean create) {
+      if (session != null && session.isValid()) {
+        session.setIsNew(false);
+        session.updateAccessTime();
+                /*
+                 * This is a massively gross hack. Currently, there is no way
+                 * to actually update the last accessed time for a session, so
+                 * what we do here is once we're into X% of the session's TTL
+                 * we grab a new session from the container.
+                 *
+                 * (inactive * 1000) * (pct / 100) ==> (inactive * 10 * pct)
+                 */
+        if (session.getLastAccessedTime() - session.getCreationTime() >
+            (session.getMaxInactiveInterval() * 10 * percentInactiveTimeTriggerRebuild)) {
+          HttpSession nativeSession = super.getSession();
+          session.failoverSession(nativeSession);
+        }
+        return session;
+      }
+
+      if (requestedSessionId != null) {
+        session = (GemfireHttpSession) manager.getSession(
+            requestedSessionId);
+        if (session != null) {
+          session.setIsNew(false);
+          // This means we've failed over to another node
+          if (session.getNativeSession() == null) {
+            try {
+              ThreadLocalSession.set(session);
+              HttpSession nativeSession = super.getSession();
+              session.failoverSession(nativeSession);
+              session.putInRegion();
+            } finally {
+              ThreadLocalSession.remove();
+            }
+          }
+        }
+      }
+
+      if (session == null || !session.isValid()) {
+        if (create) {
+          try {
+            session = (GemfireHttpSession) manager.wrapSession(null);
+            ThreadLocalSession.set(session);
+            HttpSession nativeSession = super.getSession();
+            if (session.getNativeSession() == null) {
+              session.setNativeSession(nativeSession);
+            } else {
+              assert (session.getNativeSession() == nativeSession);
+            }
+            session.setIsNew(true);
+            manager.putSession(session);
+          } finally {
+            ThreadLocalSession.remove();
+          }
+        } else {
+          // create is false, and session is either null or not valid.
+          // The spec says return a null:
+          return null;
+        }
+      }
+
+      if (session != null) {
+        addSessionCookie(response);
+        session.updateAccessTime();
+      }
+
+      return session;
+    }
+
+    private void addSessionCookie(HttpServletResponse response) {
+      // Don't bother if the response is already committed
+      if (response.isCommitted()) {
+        return;
+      }
+
+      // Get the existing cookies
+      Cookie[] cookies = getCookies();
+
+      Cookie cookie = new Cookie(manager.getSessionCookieName(),
+          session.getId());
+      cookie.setPath("".equals(getContextPath()) ? "/" : getContextPath());
+      // Clear out all old cookies and just set ours
+      response.addCookie(cookie);
+
+      // Replace all other cookies which aren't JSESSIONIDs
+      if (cookies != null) {
+        for (Cookie c : cookies) {
+          if (manager.getSessionCookieName().equals(c.getName())) {
+            continue;
+          }
+          response.addCookie(c);
+        }
+      }
+
+    }
+
+    private String getCookieString(Cookie c) {
+      StringBuilder cookie = new StringBuilder();
+      cookie.append(c.getName()).append("=").append(c.getValue());
+
+      if (c.getPath() != null) {
+        cookie.append("; ").append("Path=").append(c.getPath());
+      }
+      if (c.getDomain() != null) {
+        cookie.append("; ").append("Domain=").append(c.getDomain());
+      }
+      if (c.getSecure()) {
+        cookie.append("; ").append("Secure");
+      }
+
+      cookie.append("; HttpOnly");
+
+      return cookie.toString();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isRequestedSessionIdFromCookie() {
+      return sessionFromCookie;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isRequestedSessionIdFromURL() {
+      return sessionFromURL;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getRequestedSessionId() {
+      if (requestedSessionId != null) {
+        return requestedSessionId;
+      } else {
+        return super.getRequestedSessionId();
+      }
+    }
+
+        /*
+         * Hmmm... not sure if this is right or even good to do. So, in some
+         * cases - for ex. using a Spring security filter, we have 3 possible
+         * wrappers to deal with - the original, this one and one created by
+         * Spring. When a servlet or JSP is forwarded to the original request
+         * is passed in, but then this (the wrapped) request is used by the JSP.
+         * In some cases, the outer wrapper also contains information relevant
+         * to the request - in this case security info. So here we allow access
+         * to that. There's probably a better way....
+         */
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public Principal getUserPrincipal() {
+      if (outerRequest != null) {
+        return outerRequest.getUserPrincipal();
+      } else {
+        return super.getUserPrincipal();
+      }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public String getRemoteUser() {
+      if (outerRequest != null) {
+        return outerRequest.getRemoteUser();
+      } else {
+        return super.getRemoteUser();
+      }
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public boolean isUserInRole(String role) {
+      if (outerRequest != null) {
+        return outerRequest.isUserInRole(role);
+      } else {
+        return super.isUserInRole(role);
+      }
+    }
+
+    //////////////////////////////////////////////////////////////
+    // Non-API methods
+
+    void setOuterWrapper(HttpServletRequest outer) {
+      this.outerRequest = outer;
+    }
+
+    //////////////////////////////////////////////////////////////
+    // Private methods
+    private String extractSessionId() {
+      final int prefix = getRequestURL().indexOf(URL_SESSION_IDENTIFIER);
+      if (prefix != -1) {
+        final int start = prefix + URL_SESSION_IDENTIFIER.length();
+        int suffix = getRequestURL().indexOf("?", start);
+        if (suffix < 0) {
+          suffix = getRequestURL().indexOf("#", start);
+        }
+        if (suffix <= prefix) {
+          return getRequestURL().substring(start);
+        }
+        return getRequestURL().substring(start, suffix);
+      }
+      return null;
+    }
+  }
+
+  /**
+   * This response wrapper class extends the support class
+   * HttpServletResponseWrapper, which implements all the methods in the
+   * HttpServletResponse interface, as delegations to the wrapped response. You
+   * only need to override the methods that you need to change. You can get
+   * access to the wrapped response using the method getResponse()
+   */
+  class ResponseWrapper extends HttpServletResponseWrapper {
+
+    HttpServletResponse originalResponse;
+
+    public ResponseWrapper(HttpServletResponse response) throws IOException {
+      super(response);
+      originalResponse = response;
+    }
+
+    public HttpServletResponse getOriginalResponse() {
+      return originalResponse;
+    }
+
+    @Override
+    public void setHeader(String name, String value) {
+      super.setHeader(name, value);
+    }
+
+    @Override
+    public void setIntHeader(String name, int value) {
+      super.setIntHeader(name, value);
+    }
+  }
+
+
+  public SessionCachingFilter() {
+  }
+
+  /**
+   * @param request  The servlet request we are processing
+   * @param response The servlet response we are creating
+   * @param chain    The filter chain we are processing
+   * @throws IOException      if an input/output error occurs
+   * @throws ServletException if a servlet error occurs
+   */
+  @Override
+  public void doFilter(ServletRequest request, ServletResponse response,
+      FilterChain chain)
+      throws IOException, ServletException {
+
+    HttpServletRequest httpReq = (HttpServletRequest) request;
+    HttpServletResponse httpResp = (HttpServletResponse) response;
+
+    /**
+     * Early out if this isn't the right kind of request. We might see a
+     * RequestWrapper instance during a forward or include request.
+     */
+    if (request instanceof RequestWrapper ||
+        !(request instanceof HttpServletRequest)) {
+      LOG.debug("Handling already-wrapped request");
+      chain.doFilter(request, response);
+      return;
+    }
+
+    // Create wrappers for the request and response objects.
+    // Using these, you can extend the capabilities of the
+    // request and response, for example, allow setting parameters
+    // on the request before sending the request to the rest of the filter chain,
+    // or keep track of the cookies that are set on the response.
+    //
+    // Caveat: some servers do not handle wrappers very well for forward or
+    // include requests.
+
+    ResponseWrapper wrappedResponse = new ResponseWrapper(httpResp);
+    final RequestWrapper wrappedRequest =
+        new RequestWrapper(manager, httpReq, wrappedResponse);
+
+    Throwable problem = null;
+
+    try {
+      chain.doFilter(wrappedRequest, wrappedResponse);
+    } catch (Throwable t) {
+      // If an exception is thrown somewhere down the filter chain,
+      // we still want to execute our after processing, and then
+      // rethrow the problem after that.
+      problem = t;
+      LOG.error("Exception processing filter chain", t);
+    }
+
+    GemfireHttpSession session =
+        (GemfireHttpSession) wrappedRequest.getSession(false);
+
+    // If there was a problem, we want to rethrow it if it is
+    // a known type, otherwise log it.
+    if (problem != null) {
+      if (problem instanceof ServletException) {
+        throw (ServletException) problem;
+      }
+      if (problem instanceof IOException) {
+        throw (IOException) problem;
+      }
+      sendProcessingError(problem, response);
+    }
+
+    /**
+     * Commit any updates. What actually happens at that point is
+     * dependent on the type of attributes defined for use by the sessions.
+     */
+    if (session != null) {
+      session.commit();
+    }
+  }
+
+  /**
+   * Return the filter configuration object for this filter.
+   */
+  public FilterConfig getFilterConfig() {
+    return (this.filterConfig);
+  }
+
+  /**
+   * Set the filter configuration object for this filter.
+   *
+   * @param filterConfig The filter configuration object
+   */
+  public void setFilterConfig(FilterConfig filterConfig) {
+    this.filterConfig = filterConfig;
+  }
+
+  /**
+   * Destroy method for this filter
+   */
+  @Override
+  public void destroy() {
+    if (manager != null) {
+      manager.stop();
+    }
+  }
+
+  /**
+   * This is where all the initialization happens.
+   *
+   * @param config
+   * @throws ServletException
+   */
+  @Override
+  public void init(final FilterConfig config) {
+    LOG.info("Starting Session Filter initialization");
+    this.filterConfig = config;
+
+    if (started.getAndDecrement() > 0) {
+      /**
+       * Allow override for testing purposes
+       */
+      String managerClassStr =
+          config.getInitParameter("session-manager-class");
+
+      // Otherwise default
+      if (managerClassStr == null) {
+        managerClassStr = GemfireSessionManager.class.getName();
+      }
+
+      try {
+        manager = (SessionManager) Class.forName(
+            managerClassStr).newInstance();
+        manager.start(config, this.getClass().getClassLoader());
+      } catch (Exception ex) {
+        LOG.error("Exception creating Session Manager", ex);
+      }
+
+      startingLatch.countDown();
+    } else {
+      try {
+        startingLatch.await();
+      } catch (InterruptedException iex) {
+      }
+
+      LOG.debug("SessionManager and listener initialization skipped - "
+          + "already done.");
+    }
+
+    LOG.info("Session Filter initialization complete");
+    LOG.debug("Filter class loader {}", this.getClass().getClassLoader());
+  }
+
+  /**
+   * Return a String representation of this object.
+   */
+  @Override
+  public String toString() {
+    if (filterConfig == null) {
+      return ("SessionCachingFilter()");
+    }
+    StringBuilder sb = new StringBuilder("SessionCachingFilter(");
+    sb.append(filterConfig);
+    sb.append(")");
+    return (sb.toString());
+
+  }
+
+
+  private void sendProcessingError(Throwable t, ServletResponse response) {
+    String stackTrace = getStackTrace(t);
+
+    if (stackTrace != null && !stackTrace.equals("")) {
+      try {
+        response.setContentType("text/html");
+        PrintStream ps = new PrintStream(response.getOutputStream());
+        PrintWriter pw = new PrintWriter(ps);
+        pw.print(
+            "<html>\n<head>\n<title>Error</title>\n</head>\n<body>\n"); //NOI18N
+
+        // PENDING! Localize this for next official release
+        pw.print("<h1>The resource did not process correctly</h1>\n<pre>\n");
+        pw.print(stackTrace);
+        pw.print("</pre></body>\n</html>"); //NOI18N
+        pw.close();
+        ps.close();
+        response.getOutputStream().close();
+      } catch (Exception ex) {
+      }
+    } else {
+      try {
+        PrintStream ps = new PrintStream(response.getOutputStream());
+        t.printStackTrace(ps);
+        ps.close();
+        response.getOutputStream().close();
+      } catch (Exception ex) {
+      }
+    }
+  }
+
+  public static String getStackTrace(Throwable t) {
+    String stackTrace = null;
+    try {
+      StringWriter sw = new StringWriter();
+      PrintWriter pw = new PrintWriter(sw);
+      t.printStackTrace(pw);
+      pw.close();
+      sw.close();
+      stackTrace = sw.getBuffer().toString();
+    } catch (Exception ex) {
+    }
+    return stackTrace;
+  }
+
+  /**
+   * Retrieve the SessionManager. This is only here so that tests can get access
+   * to the cache.
+   */
+  static SessionManager getSessionManager() {
+    return manager;
+  }
+
+  /**
+   * Return the GemFire session which wraps a native session
+   *
+   * @param nativeSession the native session for which the corresponding GemFire
+   *                      session should be returned.
+   * @return the GemFire session or null if no session maps to the native
+   * session
+   */
+  public static HttpSession getWrappingSession(HttpSession nativeSession) {
+        /*
+         * This is a special case where the GemFire session has been set as a
+         * ThreadLocal during session creation.
+         */
+    GemfireHttpSession gemfireSession = (GemfireHttpSession) ThreadLocalSession.get();
+    if (gemfireSession != null) {
+      gemfireSession.setNativeSession(nativeSession);
+      return gemfireSession;
+    }
+    return getSessionManager().getWrappingSession(nativeSession.getId());
+  }
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/4b56f5e4/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionListener.java
----------------------------------------------------------------------
diff --git a/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionListener.java b/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionListener.java
new file mode 100644
index 0000000..9726be0
--- /dev/null
+++ b/modules/gemfire-modules-session-external/src/main/java/com/gemstone/gemfire/modules/session/filter/SessionListener.java
@@ -0,0 +1,41 @@
+/*=========================================================================
+ * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
+ * This product is protected by U.S. and international copyright
+ * and intellectual property laws. Pivotal products are covered by
+ * one or more patents listed at http://www.pivotal.io/patents.
+ *=========================================================================
+ */
+package com.gemstone.gemfire.modules.session.filter;
+
+import com.gemstone.gemfire.distributed.DistributedSystemDisconnectedException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+public class SessionListener implements HttpSessionListener {
+
+  private static final Logger LOG =
+      LoggerFactory.getLogger(SessionListener.class.getName());
+
+  public void sessionCreated(HttpSessionEvent httpSessionEvent) {
+  }
+
+  /**
+   * This will receive events from the container using the native sessions.
+   */
+  public void sessionDestroyed(HttpSessionEvent event) {
+    String nativeId = event.getSession().getId();
+    try {
+      String sessionId = SessionCachingFilter.getSessionManager().destroyNativeSession(
+          nativeId);
+      LOG.debug(
+          "Received sessionDestroyed event for native session {} (wrapped by {})",
+          nativeId, sessionId);
+    } catch (DistributedSystemDisconnectedException dex) {
+      LOG.debug("Cache disconnected - unable to destroy native session {0}",
+          nativeId);
+    }
+  }
+}


Mime
View raw message