You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/09/05 23:11:04 UTC

[01/33] git commit: add pushy

Repository: incubator-usergrid
Updated Branches:
  refs/heads/two-dot-o a1684d0e8 -> 55e5c163c


add pushy


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

Branch: refs/heads/two-dot-o
Commit: d2280dff201e765e451a5965163125adb449911d
Parents: 3416ac0
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 12:29:44 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 12:29:44 2014 -0600

----------------------------------------------------------------------
 .../_maven.repositories                         |   9 +
 ...14c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar | Bin 0 -> 160121 bytes
 ...14c97c6e3ef40c88590e1b196d3ec55b-sources.jar | Bin 0 -> 59657 bytes
 ...63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar | Bin 0 -> 67666 bytes
 ...7c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated |  16 ++
 ...63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom | 166 +++++++++++++++++++
 ...7c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated |  16 ++
 .../pushy-0.4-apigee.pom                        | 166 +++++++++++++++++++
 stack/pom.xml                                   |  13 +-
 9 files changed, 383 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
new file mode 100644
index 0000000..a4c5c52
--- /dev/null
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
@@ -0,0 +1,9 @@
+#NOTE: This is an internal implementation file, its format can be changed without prior notice.
+#Tue Jul 29 08:10:25 MDT 2014
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar>local-dependencies=
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom>=
+pushy-0.4-apigee.pom>local-dependencies=
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar>=
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar>=
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom>local-dependencies=
+pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar>=

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar
new file mode 100644
index 0000000..f5822ac
Binary files /dev/null and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar
new file mode 100644
index 0000000..ea25c9d
Binary files /dev/null and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar
new file mode 100644
index 0000000..1472acb
Binary files /dev/null and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
new file mode 100644
index 0000000..733d7a6
--- /dev/null
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
@@ -0,0 +1,16 @@
+#NOTE: This is an internal implementation file, its format can be changed without prior notice.
+#Thu Jul 24 13:16:38 MDT 2014
+file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.error=
+http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406229398295
+http\://download.java.net/maven/2/.lastUpdated=1406229397326
+http\://repo.maven.apache.org/maven2/.lastUpdated=1406229398556
+http\://oss.sonatype.org/content/repositories/snapshots/.error=
+http\://download.java.net/maven/2/.error=
+file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.lastUpdated=1406229398434
+http\://repo.maven.apache.org/maven2/.error=
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.error=
+http\://maven.springframework.org/milestone/.lastUpdated=1406229398432
+http\://repository.codehaus.org/.lastUpdated=1406229397898
+http\://repository.codehaus.org/.error=
+http\://maven.springframework.org/milestone/.error=
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406229397817

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
new file mode 100644
index 0000000..982bb21
--- /dev/null
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
@@ -0,0 +1,166 @@
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.relayrides</groupId>
+  <artifactId>pushy</artifactId>
+  <version>0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b</version>
+  <name>Pushy</name>
+  <description>A Java library for sending push notifications</description>
+  <parent>
+    <groupId>org.sonatype.oss</groupId>
+    <artifactId>oss-parent</artifactId>
+    <version>7</version>
+  </parent>
+  <licenses>
+    <license>
+      <name>The MIT License (MIT)</name>
+      <url>http://opensource.org/licenses/MIT</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+  <dependencies>
+  	<dependency>
+  		<groupId>org.slf4j</groupId>
+  		<artifactId>slf4j-api</artifactId>
+  		<version>1.7.6</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>junit</groupId>
+  		<artifactId>junit</artifactId>
+  		<version>4.11</version>
+  		<scope>test</scope>
+  	</dependency>
+  	<dependency>
+  		<groupId>io.netty</groupId>
+  		<artifactId>netty-all</artifactId>
+  		<version>4.0.21.Final</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>com.googlecode.json-simple</groupId>
+  		<artifactId>json-simple</artifactId>
+  		<version>1.1.1</version>
+  		<exclusions>
+  			<exclusion>
+  				<groupId>junit</groupId>
+  				<artifactId>junit</artifactId>
+  			</exclusion>
+  		</exclusions>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.slf4j</groupId>
+  		<artifactId>slf4j-simple</artifactId>
+  		<version>1.7.6</version>
+  		<scope>test</scope>
+  	</dependency>
+  </dependencies>
+  <properties>
+  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.16</version>
+        <configuration>
+            <argLine>-Dorg.slf4j.simpleLogger.defaultLogLevel=warn</argLine>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>2.9.1</version>
+        <configuration>
+          <overview>${basedir}/src/main/java/overview.html</overview>
+          <show>public</show>
+          <links>
+              <link>http://netty.io/4.0/api/</link>
+          </links>
+        </configuration>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.2.1</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>release-sign-artifacts</id>
+      <activation>
+        <property>
+          <name>performRelease</name>
+          <value>true</value>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-gpg-plugin</artifactId>
+            <version>1.1</version>
+            <executions>
+              <execution>
+                <id>sign-artifacts</id>
+                <phase>verify</phase>
+                <goals>
+                  <goal>sign</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+  <organization>
+  	<name>RelayRides</name>
+  	<url>https://relayrides.com/</url>
+  </organization>
+  <developers>
+    <developer>
+      <id>jon</id>
+      <name>Jon Chambers</name>
+	  <email>jon@relayrides.com</email>
+	  <url>https://github.com/jchambers</url>
+	  <organization>RelayRides</organization>
+	  <organizationUrl>https://relayrides.com/</organizationUrl>
+	  <roles>
+	    <role>developer</role>
+	  </roles>
+	  <timezone>-5</timezone>
+    </developer>
+  </developers>
+  <inceptionYear>2013</inceptionYear>
+  <url>http://relayrides.github.com/pushy/</url>
+  <scm>
+  	<connection>scm:git:https://github.com/relayrides/pushy.git</connection>
+  	<developerConnection>scm:git:git@github.com:relayrides/pushy.git</developerConnection>
+  	<url>https://github.com/relayrides/pushy</url>
+  </scm>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
new file mode 100644
index 0000000..d0ccc7a
--- /dev/null
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
@@ -0,0 +1,16 @@
+#NOTE: This is an internal implementation file, its format can be changed without prior notice.
+#Thu Jul 24 13:16:37 MDT 2014
+file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.error=
+http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406229390366
+http\://download.java.net/maven/2/.lastUpdated=1406229388629
+http\://repo.maven.apache.org/maven2/.lastUpdated=1406229397163
+http\://oss.sonatype.org/content/repositories/snapshots/.error=
+http\://download.java.net/maven/2/.error=
+file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.lastUpdated=1406229396602
+http\://repo.maven.apache.org/maven2/.error=
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.error=
+http\://maven.springframework.org/milestone/.lastUpdated=1406229396596
+http\://repository.codehaus.org/.lastUpdated=1406229389917
+http\://repository.codehaus.org/.error=
+http\://maven.springframework.org/milestone/.error=
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406229389776

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee.pom
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee.pom b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee.pom
new file mode 100644
index 0000000..39f61e3
--- /dev/null
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee.pom
@@ -0,0 +1,166 @@
+<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/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>com.relayrides</groupId>
+  <artifactId>pushy</artifactId>
+  <version>0.4-apigee</version>
+  <name>Pushy</name>
+  <description>A Java library for sending push notifications</description>
+  <parent>
+    <groupId>org.sonatype.oss</groupId>
+    <artifactId>oss-parent</artifactId>
+    <version>7</version>
+  </parent>
+  <licenses>
+    <license>
+      <name>The MIT License (MIT)</name>
+      <url>http://opensource.org/licenses/MIT</url>
+      <distribution>repo</distribution>
+    </license>
+  </licenses>
+  <dependencies>
+  	<dependency>
+  		<groupId>org.slf4j</groupId>
+  		<artifactId>slf4j-api</artifactId>
+  		<version>1.7.6</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>junit</groupId>
+  		<artifactId>junit</artifactId>
+  		<version>4.11</version>
+  		<scope>test</scope>
+  	</dependency>
+  	<dependency>
+  		<groupId>io.netty</groupId>
+  		<artifactId>netty-all</artifactId>
+  		<version>4.0.21.Final</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>com.googlecode.json-simple</groupId>
+  		<artifactId>json-simple</artifactId>
+  		<version>1.1.1</version>
+  		<exclusions>
+  			<exclusion>
+  				<groupId>junit</groupId>
+  				<artifactId>junit</artifactId>
+  			</exclusion>
+  		</exclusions>
+  	</dependency>
+  	<dependency>
+  		<groupId>org.slf4j</groupId>
+  		<artifactId>slf4j-simple</artifactId>
+  		<version>1.7.6</version>
+  		<scope>test</scope>
+  	</dependency>
+  </dependencies>
+  <properties>
+  	<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+  </properties>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>3.1</version>
+        <configuration>
+          <source>1.6</source>
+          <target>1.6</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>2.16</version>
+        <configuration>
+            <argLine>-Dorg.slf4j.simpleLogger.defaultLogLevel=warn</argLine>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-javadoc-plugin</artifactId>
+        <version>2.9.1</version>
+        <configuration>
+          <overview>${basedir}/src/main/java/overview.html</overview>
+          <show>public</show>
+          <links>
+              <link>http://netty.io/4.0/api/</link>
+          </links>
+        </configuration>
+        <executions>
+          <execution>
+            <id>attach-javadocs</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-source-plugin</artifactId>
+        <version>2.2.1</version>
+        <executions>
+          <execution>
+            <id>attach-sources</id>
+            <goals>
+              <goal>jar</goal>
+            </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <profiles>
+    <profile>
+      <id>release-sign-artifacts</id>
+      <activation>
+        <property>
+          <name>performRelease</name>
+          <value>true</value>
+        </property>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-gpg-plugin</artifactId>
+            <version>1.1</version>
+            <executions>
+              <execution>
+                <id>sign-artifacts</id>
+                <phase>verify</phase>
+                <goals>
+                  <goal>sign</goal>
+                </goals>
+              </execution>
+            </executions>
+          </plugin>
+        </plugins>
+      </build>
+    </profile>
+  </profiles>
+  <organization>
+  	<name>RelayRides</name>
+  	<url>https://relayrides.com/</url>
+  </organization>
+  <developers>
+    <developer>
+      <id>jon</id>
+      <name>Jon Chambers</name>
+	  <email>jon@relayrides.com</email>
+	  <url>https://github.com/jchambers</url>
+	  <organization>RelayRides</organization>
+	  <organizationUrl>https://relayrides.com/</organizationUrl>
+	  <roles>
+	    <role>developer</role>
+	  </roles>
+	  <timezone>-5</timezone>
+    </developer>
+  </developers>
+  <inceptionYear>2013</inceptionYear>
+  <url>http://relayrides.github.com/pushy/</url>
+  <scm>
+  	<connection>scm:git:https://github.com/relayrides/pushy.git</connection>
+  	<developerConnection>scm:git:git@github.com:relayrides/pushy.git</developerConnection>
+  	<url>https://github.com/relayrides/pushy</url>
+  </scm>
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/d2280dff/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index e51da28..35c3979 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -1400,13 +1400,20 @@
         <version>1.1</version>
       </dependency>
 
-    <dependency>
+      <dependency>
         <groupId>org.elasticsearch</groupId>
         <artifactId>elasticsearch</artifactId>
         <version>${elasticsearch.version}</version>
-    </dependency>
+      </dependency>
+        
+      <dependency>
+        <groupId>com.relayrides</groupId>
+        <artifactId>pushy</artifactId>
+        <!-- The sha in the version is the git commit used in this build.  Check out the pushy source, then this commit to build the library locally -->
+        <version>0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b</version>
+      </dependency>
 
-    </dependencies>
+     </dependencies>
 
   </dependencyManagement>
 


[25/33] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications

Posted by sn...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications

# By Anuradha Weeraman (55) and others
# Via Dave Johnson (30) and others
* 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid: (212 commits)
  Add some missing headers, and make some header more consistent.
  Exclude all DLL files from the release, and add a README file to each directory that formerly contained DLLs to explain that.
  Change to allow Launcher to compile with AppleJavaExtensions v1.4
  Permissive license notices should go in license file.
  Preparing for RC5 which will exclude the Portal's bower_components, node_modules and other giti-gnored files.
  Adding properties file for corepersistence/common tests.
  refreshIndex() fixes counting mutator test.
  Test fixes for tests that seem to fail intermittently on machines with lots of cores.
  Test to prove that arrays, not queries and geo queries play well together.
  Get permissions right, who knows who that WAR came from.
  configurable surefire arglines
  Revert to launcher AppleJavaExtensions 1.4 so that at least the launcher will build.
  Make it possible to deploy a UG 1 WAR.
  Don't build the launcher until we have a fix for the Apple ext jar issue.
  Fork count of two seems to work for me.
  Portal - updated grunt to remove old task types
  More JSON serialization fixes: EntityRef and CredentialsInfo should not be serialized with type info.
  Fixed obscelete tests
  Reverting previous change; jumped the gun on that one.
  Fix JSON mapper to use same setup as we do in Collections module serializer.
  ...

Conflicts:
	stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
	stack/core/src/main/resources/usergrid-core-context.xml
	stack/pom.xml


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

Branch: refs/heads/two-dot-o
Commit: 1d8dd2f6d970af69740e725825fd3d8db1aec5b0
Parents: 646b98c 479969f
Author: grey <gr...@apigee.com>
Authored: Wed Sep 3 14:50:06 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Sep 3 14:50:06 2014 -0700

----------------------------------------------------------------------
 .gitignore                                      |    22 +-
 DISCLAIMER                                      |     9 +
 LICENSE                                         |    26 +
 NOTICE                                          |    11 +-
 README.md                                       |    20 +-
 bower.json                                      |    39 -
 .../src/test/resources/install_cassandra.sh     |    19 -
 chop/stack/src/test/resources/install_es.sh     |    19 -
 .../stack/src/test/resources/setup_cassandra.sh |    19 -
 chop/stack/src/test/resources/setup_es.sh       |    19 -
 .../src/main/resources/jettyjam.properties      |    18 -
 portal/Gruntfile.js                             |   136 +-
 portal/README.md                                |    20 +-
 portal/archive/coming_soon.html                 |    31 -
 portal/archive/config.js                        |    72 -
 .../ui-bg_diagonals-thick_90_eeeeee_40x40.png   |   Bin 251 -> 0 bytes
 .../images/ui-bg_flat_100_deedf7_40x100.png     |   Bin 182 -> 0 bytes
 .../images/ui-bg_flat_100_e4f1fb_40x100.png     |   Bin 213 -> 0 bytes
 .../images/ui-bg_flat_100_f2f5f7_40x100.png     |   Bin 212 -> 0 bytes
 .../images/ui-bg_flat_15_cd0a0a_40x100.png      |   Bin 181 -> 0 bytes
 .../images/ui-bg_flat_50_3baae3_40x100.png      |   Bin 182 -> 0 bytes
 .../images/ui-bg_flat_80_d7ebf9_40x100.png      |   Bin 183 -> 0 bytes
 .../ui-bg_highlight-hard_70_000000_1x100.png    |   Bin 118 -> 0 bytes
 .../ui-bg_highlight-soft_25_ffef8f_1x100.png    |   Bin 153 -> 0 bytes
 .../images/ui-icons_000000_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_2694e8_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_2e83ff_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_3d80b3_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_72a7cf_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_ffffff_256x240.png          |   Bin 4369 -> 0 bytes
 .../css/custom-theme/jquery-ui-1.8.9.custom.css |   573 -
 portal/archive/css/jquery-ui-timepicker.css     |    53 -
 portal/archive/css/jquery.ui.statusbar.css      |    25 -
 portal/archive/css/prettify.css                 |    52 -
 portal/archive/css/usergrid-stripped.css        |  5199 ----
 portal/archive/css/usergrid.css                 |  5203 ----
 portal/archive/dash/README.md                   |     3 -
 .../archive/dash/config/testacular-e2e.conf.js  |    22 -
 portal/archive/dash/config/testacular.conf.js   |    20 -
 portal/archive/dash/test/e2e/runner.html        |    10 -
 portal/archive/dash/test/e2e/scenarios.js       |    45 -
 .../dash/test/lib/angular/angular-mocks.js      |  1764 --
 .../dash/test/lib/angular/angular-scenario.js   | 26195 -----------------
 .../archive/dash/test/lib/angular/version.txt   |     1 -
 .../archive/dash/test/unit/controllersSpec.js   |    31 -
 portal/archive/dash/test/unit/directivesSpec.js |    19 -
 portal/archive/dash/test/unit/filtersSpec.js    |    19 -
 portal/archive/dash/test/unit/servicesSpec.js   |    14 -
 portal/archive/images/APNS_cert_upload.png      |   Bin 33956 -> 0 bytes
 portal/archive/images/APNS_certification.png    |   Bin 16855 -> 0 bytes
 portal/archive/images/android-notification.png  |   Bin 41629 -> 0 bytes
 portal/archive/images/android-sdk-download.png  |   Bin 4848 -> 0 bytes
 portal/archive/images/api-activity.gif          |   Bin 10819 -> 0 bytes
 portal/archive/images/apigee-logo.png           |   Bin 3647 -> 0 bytes
 portal/archive/images/apigeetopbar.png          |   Bin 4658 -> 0 bytes
 portal/archive/images/background_one_col.png    |   Bin 3126 -> 0 bytes
 portal/archive/images/btn-copyCurl-up.png       |   Bin 2762 -> 0 bytes
 portal/archive/images/clippy-bg.png             |   Bin 561 -> 0 bytes
 portal/archive/images/close.gif                 |   Bin 718 -> 0 bytes
 portal/archive/images/dotnet-sdk-download.png   |   Bin 7149 -> 0 bytes
 portal/archive/images/down_arrow.png            |   Bin 1285 -> 0 bytes
 portal/archive/images/error.png                 |   Bin 2009 -> 0 bytes
 portal/archive/images/faviconApigee.ico         |   Bin 1150 -> 0 bytes
 .../images/glyphicons-halflings-white.png       |   Bin 4352 -> 0 bytes
 portal/archive/images/glyphicons-halflings.png  |   Bin 4352 -> 0 bytes
 .../glyphicons_halflings_135_wrench-white2.pdn  |   Bin 5400 -> 0 bytes
 .../glyphicons_halflings_135_wrench-white2.png  |   Bin 296 -> 0 bytes
 .../images/glyphicons_halflings_135_wrench.png  |   Bin 228 -> 0 bytes
 .../glyphicons_halflings_135_wrench_white.png   |   Bin 251 -> 0 bytes
 .../glyphicons_halflings_wrench_white.png       |   Bin 1016 -> 0 bytes
 portal/archive/images/google_api_key.png        |   Bin 98118 -> 0 bytes
 portal/archive/images/green_dot.png             |   Bin 3472 -> 0 bytes
 portal/archive/images/grid.png                  |   Bin 166 -> 0 bytes
 portal/archive/images/icons.png                 |   Bin 13132 -> 0 bytes
 portal/archive/images/ios-sdk-download.png      |   Bin 4886 -> 0 bytes
 portal/archive/images/iphone_message.png        |   Bin 90307 -> 0 bytes
 .../archive/images/javascript-sdk-download.png  |   Bin 4618 -> 0 bytes
 portal/archive/images/left_arrow.png            |   Bin 1257 -> 0 bytes
 portal/archive/images/logo-white.png            |   Bin 2014 -> 0 bytes
 portal/archive/images/menuActiveTriangle.png    |   Bin 315 -> 0 bytes
 portal/archive/images/nodejs-sdk-download.png   |   Bin 5273 -> 0 bytes
 portal/archive/images/notice.png                |   Bin 2112 -> 0 bytes
 portal/archive/images/orange-arrow.png          |   Bin 242 -> 0 bytes
 .../archive/images/push_notifications_icon.png  |   Bin 338 -> 0 bytes
 portal/archive/images/red_dot.png               |   Bin 3482 -> 0 bytes
 portal/archive/images/right_arrow.png           |   Bin 1251 -> 0 bytes
 portal/archive/images/ruby-sdk-download.png     |   Bin 6343 -> 0 bytes
 portal/archive/images/step_1.png                |   Bin 1953 -> 0 bytes
 portal/archive/images/step_2.png                |   Bin 2117 -> 0 bytes
 portal/archive/images/step_3.png                |   Bin 2162 -> 0 bytes
 portal/archive/images/success.png               |   Bin 1863 -> 0 bytes
 portal/archive/images/swish_arrow.png           |   Bin 220 -> 0 bytes
 portal/archive/images/topbackground.png         |   Bin 2890 -> 0 bytes
 portal/archive/images/up_arrow.png              |   Bin 1292 -> 0 bytes
 portal/archive/images/user-photo.png            |   Bin 3849 -> 0 bytes
 portal/archive/images/user_profile.png          |   Bin 3775 -> 0 bytes
 portal/archive/images/usergrid_200.png          |   Bin 6397 -> 0 bytes
 portal/archive/images/usergrid_400.png          |   Bin 8746 -> 0 bytes
 portal/archive/images/warning.png               |   Bin 1179 -> 0 bytes
 portal/archive/images/yellow_dot.png            |   Bin 3475 -> 0 bytes
 portal/archive/index-stripped2.html             |  1795 --
 portal/archive/index.html                       |  1932 --
 portal/archive/js/app/app.js                    |   131 -
 portal/archive/js/app/console.js                |  5397 ----
 portal/archive/js/app/helpers.js                |   241 -
 portal/archive/js/app/navigation.js             |   251 -
 portal/archive/js/app/pages.js                  |   161 -
 portal/archive/js/app/params.js                 |    30 -
 portal/archive/js/app/quickLogin.js             |    30 -
 portal/archive/js/app/session.js                |   176 -
 portal/archive/js/app/sso.js                    |   135 -
 portal/archive/js/app/status.js                 |    37 -
 portal/archive/js/app/ui/collections.entity.js  |   320 -
 portal/archive/js/app/ui/collections.user.js    |   120 -
 portal/archive/js/app/ui/ui.js                  |   415 -
 portal/archive/js/app/usergrid.appSDK.js        |  2097 --
 portal/archive/js/app/usergrid.appSDK.orig.js   |  2070 --
 portal/archive/js/lib/MD5.min.js                |     1 -
 portal/archive/js/lib/backbone.js               |  1431 -
 portal/archive/js/lib/bootstrap.min.js          |     7 -
 portal/archive/js/lib/date.min.js               |     2 -
 portal/archive/js/lib/jquery-1.7.2.min.js       |     4 -
 portal/archive/js/lib/jquery-ui-1.8.18.min.js   |    15 -
 portal/archive/js/lib/jquery.dataset.min.js     |     1 -
 portal/archive/js/lib/jquery.dform-0.1.3.min.js |    16 -
 portal/archive/js/lib/jquery.jsonp-2.3.1.min.js |     3 -
 portal/archive/js/lib/jquery.tmpl.min.js        |    10 -
 .../archive/js/lib/jquery.ui.statusbar.min.js   |     1 -
 .../archive/js/lib/jquery.ui.timepicker.min.js  |     1 -
 portal/archive/js/lib/prettify.js               |  1477 -
 portal/archive/js/lib/underscore-min.js         |     5 -
 portal/archive/js/spec/client-tests.js          |   159 -
 portal/archive/js/spec/index.html               |    20 -
 portal/archive/js/spec/qunit-git.css            |   238 -
 portal/archive/js/spec/qunit-git.js             |  1865 --
 portal/archive/js/unit-tests/appSDK-tests.js    |   255 -
 portal/archive/js/unit-tests/ie-jquery-tests.js |   191 -
 portal/archive/js/unit-tests/qunit.css          |   231 -
 portal/archive/js/unit-tests/qunit.js           |  1934 --
 portal/archive/loading.html                     |     9 -
 portal/archive/max/index.html                   |     0
 portal/archive/planned_outage.html              |    48 -
 portal/archive/push/index.html                  |    34 -
 portal/archive/service_down.html                |    48 -
 .../apigee.ui.activities.table_rows.html        |    14 -
 .../templates/apigee.ui.admins.table_rows.html  |     8 -
 .../apigee.ui.applications.table_rows.html      |     4 -
 .../apigee.ui.collection.table_rows.html        |    67 -
 .../apigee.ui.collections.query.indexes.html    |     5 -
 .../apigee.ui.collections.table_rows.html       |     9 -
 .../apigee.ui.collections.user.header.html      |    21 -
 .../templates/apigee.ui.curl.detail.html        |    11 -
 .../templates/apigee.ui.feed.table_rows.html    |    15 -
 .../templates/apigee.ui.groups.table_rows.html  |    14 -
 .../apigee.ui.panels.group.activities.html      |    28 -
 .../apigee.ui.panels.group.details.html         |    97 -
 .../apigee.ui.panels.group.memberships.html     |    40 -
 .../apigee.ui.panels.group.permissions.html     |    99 -
 ...pigee.ui.panels.notifications.configure.html |    14 -
 .../apigee.ui.panels.role.permissions.html      |    58 -
 .../templates/apigee.ui.panels.role.users.html  |    38 -
 .../apigee.ui.panels.user.activities.html       |    40 -
 .../templates/apigee.ui.panels.user.graph.html  |    80 -
 .../apigee.ui.panels.user.memberships.html      |    40 -
 .../apigee.ui.panels.user.permissions.html      |   105 -
 .../apigee.ui.panels.user.profile.html          |   113 -
 .../apigee.ui.role.groups.table_rows.html       |    44 -
 .../templates/apigee.ui.roles.table_rows.html   |    15 -
 .../templates/apigee.ui.users.table_rows.html   |    18 -
 portal/archive/templates/test/modalForm2.html   |    32 -
 portal/archive/test/autocomplete.html           |    25 -
 portal/archive/test/modalForm.html              |    32 -
 portal/bower.json                               |     6 +-
 portal/build.sh                                 |    24 +-
 portal/config.js                                |    49 +-
 portal/css/apigeeGlobalNavigation.css           |   291 -
 portal/css/dash.min.css                         |     1 -
 portal/css/main.css                             |    94 +-
 portal/css/main.min.css                         |     1 +
 portal/favicon.ico                              |   Bin 1150 -> 3989 bytes
 portal/helpJson.json                            |    47 +
 portal/img/green_dot.png                        |   Bin 3472 -> 0 bytes
 portal/img/logo.gif                             |   Bin 2279 -> 0 bytes
 portal/img/logo.png                             |   Bin 0 -> 7758 bytes
 portal/img/push/APNS_cert_upload.png            |   Bin 33956 -> 0 bytes
 portal/img/push/APNS_certification.png          |   Bin 16855 -> 0 bytes
 portal/img/push/android-notification.png        |   Bin 41629 -> 0 bytes
 portal/img/push/google_api_key.png              |   Bin 98118 -> 0 bytes
 portal/img/push/iphone_message.png              |   Bin 90307 -> 0 bytes
 portal/img/push/step_1.png                      |   Bin 1953 -> 0 bytes
 portal/img/push/step_2.png                      |   Bin 2117 -> 0 bytes
 portal/img/push/step_3.png                      |   Bin 2162 -> 0 bytes
 portal/img/red_dot.png                          |   Bin 3482 -> 0 bytes
 portal/img/yellow_dot.png                       |   Bin 3475 -> 0 bytes
 portal/index-template.html                      |    44 +-
 portal/js/activities/activities.html            |    56 +-
 .../js/app-overview/app-overview-controller.js  |    61 +-
 portal/js/app-overview/app-overview.html        |    60 +-
 .../js/app-overview/doc-includes/android.html   |   401 +-
 portal/js/app-overview/doc-includes/ios.html    |   364 +-
 .../app-overview/doc-includes/javascript.html   |   216 +-
 portal/js/app-overview/doc-includes/net.html    |    16 +
 portal/js/app-overview/doc-includes/node.html   |    16 +
 portal/js/app-overview/doc-includes/ruby.html   |    16 +
 .../app-overview/getting-started-controller.js  |   107 -
 portal/js/app-overview/getting-started.html     |   119 -
 portal/js/app.js                                |    21 +-
 portal/js/charts/chart-controller.js            |     6 -
 portal/js/charts/chart-directives.js            |   141 -
 portal/js/charts/chart-service.js               |   494 -
 portal/js/charts/highcharts.json                |   329 -
 portal/js/charts/sparklines.js                  |     2 -
 portal/js/data/data.html                        |   261 +-
 portal/js/data/display-generic.html             |   168 +-
 portal/js/data/display-groups.html              |    16 +
 portal/js/data/display-roles.html               |    18 +-
 portal/js/data/display-users.html               |   257 +-
 portal/js/data/entity.html                      |    31 +-
 portal/js/dialogs/modal.html                    |    49 +-
 portal/js/global/app-switcher-directive.js      |    53 -
 portal/js/global/appswitcher-template.html      |    34 -
 portal/js/global/help-service.js                |    22 +-
 portal/js/global/insecure-banner.html           |    30 +-
 portal/js/global/page-controller.js             |    17 +-
 portal/js/global/page-title.html                |    44 +-
 portal/js/global/ug-service.js                  |    45 +-
 portal/js/groups/groups-activities.html         |    44 +-
 portal/js/groups/groups-details.html            |    83 +-
 portal/js/groups/groups-members.html            |   101 +-
 portal/js/groups/groups-roles.html              |   247 +-
 portal/js/groups/groups-tabs.html               |    45 +-
 portal/js/groups/groups.html                    |   196 +-
 portal/js/libs/Highcharts-2.3.5/index.htm       |    79 -
 .../js/adapters/mootools-adapter.js             |    13 -
 .../js/adapters/mootools-adapter.src.js         |   328 -
 .../js/adapters/prototype-adapter.js            |    16 -
 .../js/adapters/prototype-adapter.src.js        |   385 -
 .../libs/Highcharts-2.3.5/js/highcharts-more.js |    35 -
 .../Highcharts-2.3.5/js/highcharts-more.src.js  |  1581 -
 .../js/libs/Highcharts-2.3.5/js/highcharts.js   |   250 -
 .../libs/Highcharts-2.3.5/js/highcharts.src.js  | 15281 ----------
 .../Highcharts-2.3.5/js/modules/canvas-tools.js |   133 -
 .../js/modules/canvas-tools.src.js              |  3113 --
 .../js/libs/Highcharts-2.3.5/js/modules/data.js |    14 -
 .../Highcharts-2.3.5/js/modules/data.src.js     |   512 -
 .../Highcharts-2.3.5/js/modules/exporting.js    |    23 -
 .../js/modules/exporting.src.js                 |   752 -
 .../Highcharts-2.3.5/js/themes/dark-blue.js     |   263 -
 .../Highcharts-2.3.5/js/themes/dark-green.js    |   263 -
 .../js/libs/Highcharts-2.3.5/js/themes/gray.js  |   262 -
 .../js/libs/Highcharts-2.3.5/js/themes/grid.js  |    95 -
 .../js/libs/Highcharts-2.3.5/js/themes/skies.js |    89 -
 portal/js/libs/angular-1.0.5/angular-cookies.js |   183 -
 .../libs/angular-1.0.5/angular-cookies.min.js   |     7 -
 portal/js/libs/angular-1.0.5/angular-loader.js  |   276 -
 .../js/libs/angular-1.0.5/angular-loader.min.js |     7 -
 portal/js/libs/angular-1.0.5/angular-mocks.js   |  1886 --
 .../js/libs/angular-1.0.5/angular-resource.js   |   445 -
 .../libs/angular-1.0.5/angular-resource.min.js  |    10 -
 .../js/libs/angular-1.0.5/angular-sanitize.js   |   535 -
 .../libs/angular-1.0.5/angular-sanitize.min.js  |    13 -
 portal/js/libs/angular-1.0.5/angular.js         | 14733 ---------
 portal/js/libs/angular-1.0.5/angular.min.js     |   161 -
 portal/js/libs/angular-1.0.5/version.txt        |     1 -
 portal/js/libs/angular-1.1.5/angular-1.1.5.js   | 16876 -----------
 .../js/libs/angular-1.1.5/angular-merge.min.js  |     8 -
 .../angular-1.1.5/angular-resource-1.1.5.js     |   537 -
 .../angularitics-0.8.5-google-analytics.js      |     7 -
 .../js/libs/angularitics/angularitics-0.8.5.js  |     6 -
 portal/js/login/forgot-password.html            |    27 +-
 portal/js/login/loading.html                    |    20 +-
 portal/js/login/login.html                      |   114 +-
 portal/js/login/logout.html                     |    18 +-
 portal/js/login/register.html                   |    80 +-
 portal/js/menu.html                             |    32 +-
 portal/js/menus/appMenu.html                    |    88 +-
 portal/js/menus/orgMenu.html                    |    39 +-
 portal/js/org-overview/org-overview.html        |   269 +-
 portal/js/profile/account.html                  |    31 +-
 portal/js/profile/organizations.html            |   136 +-
 portal/js/profile/profile.html                  |   105 +-
 portal/js/roles/roles-groups.html               |    99 +-
 portal/js/roles/roles-settings.html             |   173 +-
 portal/js/roles/roles-tabs.html                 |    48 +-
 portal/js/roles/roles-users.html                |   100 +-
 portal/js/roles/roles.html                      |   184 +-
 portal/js/shell/shell.html                      |    37 +-
 portal/js/users/users-activities.html           |    75 +-
 portal/js/users/users-feed.html                 |    63 +-
 portal/js/users/users-graph.html                |   125 +-
 portal/js/users/users-groups.html               |   116 +-
 portal/js/users/users-profile.html              |   154 +-
 portal/js/users/users-roles.html                |   258 +-
 portal/js/users/users-tabs.html                 |    17 +-
 portal/js/users/users.html                      |   272 +-
 portal/package.json                             |     7 +-
 portal/scripts/e2e-test.bat                     |    15 +
 portal/scripts/e2e-test.sh                      |    15 +
 portal/scripts/test.bat                         |    15 +
 portal/scripts/test.sh                          |    15 +
 portal/scripts/watchr.rb                        |    15 +
 portal/scripts/web-server.js                    |    19 +
 portal/sdk/usergrid.0.10.4.js                   |  1402 -
 portal/sdk/usergrid.0.10.5.js                   |  1755 --
 portal/sdk/usergrid.0.10.7.js                   |  2265 --
 portal/server.js                                |    19 +
 portal/tests/karma.conf.js                      |    23 +-
 portal/tests/protractor-ignore/profile.spec.js  |    97 +
 portal/tests/protractor/applications.spec.js    |    20 +
 portal/tests/protractor/data.spec.js            |    20 +
 portal/tests/protractor/forgotPassword.spec.js  |    20 +
 portal/tests/protractor/login.spec.js           |    20 +
 portal/tests/protractor/organization.spec.js    |    20 +
 portal/tests/protractor/profile.spec.js         |    77 -
 portal/tests/protractor/roles.spec.js           |    20 +
 portal/tests/protractor/shell.spec.js           |    20 +
 portal/tests/protractor/users.spec.js           |    20 +
 portal/tests/protractor/util.js                 |    24 +-
 portal/tests/protractorConf.js                  |    24 +-
 portal/tests/selenium/chromedriver              |   Bin 22034760 -> 0 bytes
 .../selenium-server-standalone-2.37.0.jar       |   Bin 34730734 -> 0 bytes
 portal/tests/unit/sample.spec.js                |    19 +
 release/pom.xml                                 |    65 +
 release/sign-release.sh                         |    30 +
 release/src/main/assembly/source.xml            |    57 +
 sdks/android/.gitignore                         |    20 -
 sdks/android/README.txt                         |     2 +
 sdks/android/dist/jackson-core-asl-1.9.1.jar    |   Bin 228286 -> 0 bytes
 sdks/android/dist/jackson-mapper-asl-1.9.1.jar  |   Bin 764465 -> 0 bytes
 .../dist/spring-android-core-1.0.0.M4.jar       |   Bin 83065 -> 0 bytes
 .../spring-android-rest-template-1.0.0.M4.jar   |   Bin 137368 -> 0 bytes
 sdks/android/doc/allclasses-frame.html          |    27 -
 sdks/android/doc/allclasses-noframe.html        |    27 -
 sdks/android/doc/constant-values.html           |   153 -
 sdks/android/doc/deprecated-list.html           |   117 -
 sdks/android/doc/help-doc.html                  |   222 -
 sdks/android/doc/index-all.html                 |   371 -
 sdks/android/doc/index.html                     |    68 -
 .../apache/usergrid/android/client/Client.html  |   989 -
 .../client/callbacks/ApiResponseCallback.html   |   224 -
 .../client/callbacks/ClientAsyncTask.html       |   338 -
 .../client/callbacks/ClientCallback.html        |   227 -
 .../callbacks/DeviceRegistrationCallback.html   |   220 -
 .../callbacks/GroupsRetrievedCallback.html      |   220 -
 .../client/callbacks/QueryResultsCallback.html  |   220 -
 .../class-use/ApiResponseCallback.html          |   282 -
 .../callbacks/class-use/ClientAsyncTask.html    |   117 -
 .../callbacks/class-use/ClientCallback.html     |   180 -
 .../class-use/DeviceRegistrationCallback.html   |   171 -
 .../class-use/GroupsRetrievedCallback.html      |   160 -
 .../class-use/QueryResultsCallback.html         |   219 -
 .../android/client/callbacks/package-frame.html |    28 -
 .../client/callbacks/package-summary.html       |   166 -
 .../android/client/callbacks/package-tree.html  |   145 -
 .../android/client/callbacks/package-use.html   |   178 -
 .../android/client/class-use/Client.html        |   117 -
 .../usergrid/android/client/package-frame.html  |    20 -
 .../android/client/package-summary.html         |   137 -
 .../usergrid/android/client/package-tree.html   |   134 -
 .../usergrid/android/client/package-use.html    |   117 -
 .../android/client/utils/DeviceUuidFactory.html |   352 -
 .../android/client/utils/ObjectUtils.html       |   258 -
 .../utils/class-use/DeviceUuidFactory.html      |   117 -
 .../client/utils/class-use/ObjectUtils.html     |   117 -
 .../android/client/utils/package-frame.html     |    21 -
 .../android/client/utils/package-summary.html   |   142 -
 .../android/client/utils/package-tree.html      |   131 -
 .../android/client/utils/package-use.html       |   117 -
 sdks/android/doc/overview-frame.html            |    23 -
 sdks/android/doc/overview-summary.html          |   139 -
 sdks/android/doc/overview-tree.html             |   154 -
 sdks/android/doc/package-list                   |     3 -
 sdks/android/doc/resources/background.gif       |   Bin 2313 -> 0 bytes
 sdks/android/doc/resources/tab.gif              |   Bin 291 -> 0 bytes
 sdks/android/doc/resources/titlebar.gif         |   Bin 10701 -> 0 bytes
 sdks/android/doc/resources/titlebar_end.gif     |   Bin 849 -> 0 bytes
 sdks/android/doc/stylesheet.css                 |   474 -
 .../0.0.6/usergrid-java-client-0.0.6.jar        |   Bin 46389 -> 0 bytes
 .../0.0.6/usergrid-java-client-0.0.6.jar.sha1   |     1 -
 .../0.0.6/usergrid-java-client-0.0.6.pom        |    95 -
 .../0.0.6/usergrid-java-client-0.0.6.pom.sha1   |     1 -
 .../maven-metadata-local.xml                    |    12 -
 sdks/android/pom.xml                            |    43 +-
 .../apache/usergrid/android/client/Client.java  |   185 +-
 .../client/callbacks/ApiResponseCallback.java   |    16 +
 .../client/callbacks/ClientAsyncTask.java       |    16 +
 .../client/callbacks/ClientCallback.java        |    16 +
 .../callbacks/DeviceRegistrationCallback.java   |    16 +
 .../callbacks/GroupsRetrievedCallback.java      |    16 +
 .../client/callbacks/QueryResultsCallback.java  |    16 +
 .../android/client/utils/DeviceUuidFactory.java |    16 +
 .../android/client/utils/ObjectUtils.java       |    16 +
 .../NSubstitute.1.6.0.0/BreakingChanges.txt     |   131 -
 .../packages/NSubstitute.1.6.0.0/CHANGELOG.txt  |   103 -
 .../packages/NSubstitute.1.6.0.0/README.txt     |   119 -
 sdks/dotnet/packages/NUnit.2.6.2/README.txt     |     3 +
 .../packages/Newtonsoft.Json.4.5.11/README.txt  |     3 +
 sdks/dotnet/packages/RestSharp.104.1/readme.txt |    19 -
 .../LocationDotNetSample/Form1.cs               |    18 +-
 .../packages/Geocoder.0.1.0.0/README.txt        |     3 +
 sdks/html5-javascript/README.md                 |    76 +-
 .../examples/all-calls/all-calls.html           |    18 +-
 sdks/html5-javascript/examples/all-calls/app.js |    19 +-
 sdks/html5-javascript/examples/dogs/app.js      |    17 +
 sdks/html5-javascript/examples/dogs/dogs.html   |    19 +-
 sdks/html5-javascript/examples/facebook/app.js  |    17 +
 .../examples/facebook/facebook.html             |    19 +-
 .../examples/facebook/guide.html                |    17 +
 .../examples/persistence/test.html              |    19 +-
 .../examples/persistence/test.js                |    17 +
 sdks/html5-javascript/examples/test/test.html   |    19 +-
 .../extensions/usergrid.validation.js           |    30 +-
 sdks/html5-javascript/index.html                |    17 +
 sdks/html5-javascript/lib/Module.js             |    19 +-
 sdks/html5-javascript/lib/Usergrid.js           |    36 +-
 sdks/html5-javascript/lib/modules/Asset.js      |   168 +-
 sdks/html5-javascript/lib/modules/Client.js     |     8 +-
 sdks/html5-javascript/lib/modules/Entity.js     |   179 +-
 sdks/html5-javascript/lib/modules/Group.js      |     2 +-
 sdks/html5-javascript/tests/mocha/index.html    |    25 +-
 sdks/html5-javascript/tests/mocha/test.js       |    17 +
 .../tests/qunit/apigee_test.html                |    17 +
 sdks/html5-javascript/tests/qunit/tests.js      |    17 +
 sdks/html5-javascript/tests/test.html           |    17 +
 sdks/html5-javascript/tests/test.js             |    17 +
 sdks/html5-javascript/usergrid.js               |   268 +-
 sdks/html5-javascript/usergrid.min.js           |    35 +-
 sdks/ios/Nukefile                               |    17 +
 sdks/ios/UGAPI/v2/UGConnection.h                |    16 +
 sdks/ios/UGAPI/v2/UGConnection.m                |    18 +-
 sdks/ios/UGAPI/v2/UGHTTPClient.h                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPClient.m                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPHelpers.h               |    19 +-
 sdks/ios/UGAPI/v2/UGHTTPHelpers.m               |    17 +-
 sdks/ios/UGAPI/v2/UGHTTPResult.h                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPResult.m                |    16 +
 .../samples/Books/books/AddBookViewController.h |    31 +
 .../samples/Books/books/AddBookViewController.m |    17 +
 sdks/ios/samples/Books/books/AppDelegate.h      |    31 +
 sdks/ios/samples/Books/books/AppDelegate.m      |    17 +
 .../samples/Books/books/BooksViewController.h   |    31 +
 .../samples/Books/books/BooksViewController.m   |    17 +
 .../Books/books/UGSignInViewController.h        |    14 +
 .../Books/books/UGSignInViewController.m        |    17 +
 sdks/ios/samples/Books/books/books-Info.plist   |    18 +
 sdks/ios/samples/Books/books/books-Prefix.pch   |    17 +
 .../Books/books/en.lproj/InfoPlist.strings      |    19 +
 sdks/ios/samples/Books/books/main.m             |    17 +
 .../ios/samples/Browser/browser/UGAppDelegate.h |    14 +
 .../ios/samples/Browser/browser/UGAppDelegate.m |    17 +
 .../Browser/browser/UGAppViewController.h       |    14 +
 .../Browser/browser/UGAppViewController.m       |    17 +
 .../browser/UGCollectionViewController.h        |    14 +
 .../browser/UGCollectionViewController.m        |    17 +
 .../Browser/browser/UGEntityViewController.h    |    14 +
 .../Browser/browser/UGEntityViewController.m    |    17 +
 .../Browser/browser/UGSignInViewController.h    |    14 +
 .../Browser/browser/UGSignInViewController.m    |    17 +
 .../Browser/browser/UGTextViewController.h      |    14 +
 .../Browser/browser/UGTextViewController.m      |    17 +
 .../samples/Browser/browser/browser-Info.plist  |    18 +
 sdks/ios/samples/Browser/browser/main.m         |    17 +
 sdks/ios/samples/parties/parties/AppDelegate.h  |    14 +-
 sdks/ios/samples/parties/parties/AppDelegate.m  |    17 +
 .../parties/parties/PartiesViewController.h     |    14 +-
 .../parties/parties/PartiesViewController.m     |    17 +
 .../parties/parties/PartyViewController.h       |    14 +-
 .../parties/parties/PartyViewController.m       |    17 +
 sdks/ios/samples/parties/parties/main.m         |    17 +
 .../samples/parties/parties/parties-Info.plist  |    18 +
 sdks/ios/test/test_client.nu                    |    17 +
 sdks/ios/test/test_connection.nu                |    17 +
 sdks/java/.gitignore                            |    20 -
 sdks/java/dist/jackson-core-asl-1.9.1.jar       |   Bin 228286 -> 0 bytes
 sdks/java/dist/jackson-mapper-asl-1.9.1.jar     |   Bin 764465 -> 0 bytes
 sdks/java/dist/spring-android-core-1.0.0.M4.jar |   Bin 83065 -> 0 bytes
 .../spring-android-rest-template-1.0.0.M4.jar   |   Bin 137368 -> 0 bytes
 .../usergrid-android-client-0.0.1-SNAPSHOT.jar  |   Bin 66123 -> 0 bytes
 sdks/java/doc/allclasses-frame.html             |    40 -
 sdks/java/doc/allclasses-noframe.html           |    40 -
 sdks/java/doc/constant-values.html              |   731 -
 sdks/java/doc/deprecated-list.html              |   117 -
 sdks/java/doc/help-doc.html                     |   222 -
 sdks/java/doc/index-all.html                    |  1299 -
 sdks/java/doc/index.html                        |    68 -
 .../usergrid/java/client/Client.Query.html      |   238 -
 .../java/client/Client.QueuePosition.html       |   381 -
 .../org/apache/usergrid/java/client/Client.html |  1652 --
 .../java/client/class-use/Client.Query.html     |   246 -
 .../client/class-use/Client.QueuePosition.html  |   192 -
 .../usergrid/java/client/class-use/Client.html  |   175 -
 .../entities/Activity.ActivityCollection.html   |   408 -
 .../entities/Activity.ActivityObject.html       |   720 -
 .../client/entities/Activity.MediaLink.html     |   434 -
 .../usergrid/java/client/entities/Activity.html |  1449 -
 .../usergrid/java/client/entities/Device.html   |   387 -
 .../usergrid/java/client/entities/Entity.html   |   599 -
 .../usergrid/java/client/entities/Group.html    |   427 -
 .../usergrid/java/client/entities/Message.html  |   641 -
 .../usergrid/java/client/entities/User.html     |   707 -
 .../class-use/Activity.ActivityCollection.html  |   117 -
 .../class-use/Activity.ActivityObject.html      |   231 -
 .../entities/class-use/Activity.MediaLink.html  |   191 -
 .../client/entities/class-use/Activity.html     |   203 -
 .../java/client/entities/class-use/Device.html  |   169 -
 .../java/client/entities/class-use/Entity.html  |   415 -
 .../java/client/entities/class-use/Group.html   |   159 -
 .../java/client/entities/class-use/Message.html |   183 -
 .../java/client/entities/class-use/User.html    |   248 -
 .../java/client/entities/package-frame.html     |    28 -
 .../java/client/entities/package-summary.html   |   169 -
 .../java/client/entities/package-tree.html      |   141 -
 .../java/client/entities/package-use.html       |   219 -
 .../java/client/exception/ClientException.html  |   263 -
 .../exception/class-use/ClientException.html    |   117 -
 .../java/client/exception/package-frame.html    |    20 -
 .../java/client/exception/package-summary.html  |   137 -
 .../java/client/exception/package-tree.html     |   142 -
 .../java/client/exception/package-use.html      |   117 -
 .../usergrid/java/client/package-frame.html     |    28 -
 .../usergrid/java/client/package-summary.html   |   167 -
 .../usergrid/java/client/package-tree.html      |   146 -
 .../usergrid/java/client/package-use.html       |   158 -
 .../java/client/response/AggregateCounter.html  |   316 -
 .../client/response/AggregateCounterSet.html    |   444 -
 .../java/client/response/ApiResponse.html       |  1148 -
 .../client/response/ClientCredentialsInfo.html  |   316 -
 .../java/client/response/QueueInfo.html         |   297 -
 .../response/class-use/AggregateCounter.html    |   191 -
 .../response/class-use/AggregateCounterSet.html |   170 -
 .../client/response/class-use/ApiResponse.html  |   365 -
 .../class-use/ClientCredentialsInfo.html        |   170 -
 .../client/response/class-use/QueueInfo.html    |   187 -
 .../java/client/response/package-frame.html     |    24 -
 .../java/client/response/package-summary.html   |   151 -
 .../java/client/response/package-tree.html      |   134 -
 .../java/client/response/package-use.html       |   178 -
 .../usergrid/java/client/utils/JsonUtils.html   |   480 -
 .../usergrid/java/client/utils/MapUtils.html    |   260 -
 .../usergrid/java/client/utils/ObjectUtils.html |   258 -
 .../usergrid/java/client/utils/UrlUtils.html    |   314 -
 .../java/client/utils/class-use/JsonUtils.html  |   117 -
 .../java/client/utils/class-use/MapUtils.html   |   117 -
 .../client/utils/class-use/ObjectUtils.html     |   117 -
 .../java/client/utils/class-use/UrlUtils.html   |   117 -
 .../java/client/utils/package-frame.html        |    23 -
 .../java/client/utils/package-summary.html      |   147 -
 .../java/client/utils/package-tree.html         |   133 -
 .../usergrid/java/client/utils/package-use.html |   117 -
 sdks/java/doc/overview-frame.html               |    25 -
 sdks/java/doc/overview-summary.html             |   147 -
 sdks/java/doc/overview-tree.html                |   184 -
 sdks/java/doc/package-list                      |     5 -
 sdks/java/doc/resources/background.gif          |   Bin 2313 -> 0 bytes
 sdks/java/doc/resources/tab.gif                 |   Bin 291 -> 0 bytes
 sdks/java/doc/resources/titlebar.gif            |   Bin 10701 -> 0 bytes
 sdks/java/doc/resources/titlebar_end.gif        |   Bin 849 -> 0 bytes
 sdks/java/doc/serialized-form.html              |   134 -
 sdks/java/doc/stylesheet.css                    |   474 -
 sdks/java/pom.xml                               |    21 +-
 sdks/nodejs/.gitignore                          |     2 -
 sdks/nodejs/.npmignore                          |     1 -
 sdks/nodejs/lib/usergrid.js                     |   195 +-
 sdks/nodejs/test.js                             |    17 +
 sdks/nodejs/test/client.js                      |    18 +
 sdks/nodejs/test/collection.js                  |    17 +
 sdks/nodejs/test/entity.js                      |    17 +
 sdks/perl/Build.PL                              |    46 +
 sdks/perl/LICENSE                               |   202 +
 sdks/perl/MANIFEST                              |    23 +
 sdks/perl/Makefile.PL                           |    41 +
 sdks/perl/README.md                             |   341 +
 sdks/perl/examples/books.pl                     |    48 +
 sdks/perl/lib/Usergrid/Client.pm                |   492 +
 sdks/perl/lib/Usergrid/Collection.pm            |   212 +
 sdks/perl/lib/Usergrid/Entity.pm                |    92 +
 sdks/perl/lib/Usergrid/Request.pm               |   249 +
 sdks/perl/t/01_init.t                           |    27 +
 sdks/perl/t/02_login.t                          |    64 +
 sdks/perl/t/03_update.t                         |   102 +
 sdks/perl/t/04_collection.t                     |   104 +
 sdks/perl/t/05_query.t                          |   108 +
 sdks/perl/t/06_batch_update.t                   |   107 +
 sdks/perl/t/07_batch_delete.t                   |    87 +
 sdks/perl/t/08_connections.t                    |    94 +
 sdks/perl/t/09_paging.t                         |   140 +
 sdks/perl/t/10_auto_paging.t                    |    94 +
 sdks/php/kessel/config.ini                      |    18 -
 sdks/php/kessel/kessel.rb                       |   188 -
 sdks/ruby-on-rails/.gitignore                   |    18 -
 sdks/ruby-on-rails/.rspec                       |     1 -
 sdks/ruby-on-rails/.rvmrc                       |     2 -
 sdks/usergrid-java-sdk-0.0.6/README.txt         |     5 +
 sdks/usergrid-java-sdk-0.0.6/pom.xml            |   114 +
 .../java/org/usergrid/java/client/Client.java   |  1292 +
 .../usergrid/java/client/entities/Activity.java |   626 +
 .../usergrid/java/client/entities/Device.java   |    68 +
 .../usergrid/java/client/entities/Entity.java   |   191 +
 .../usergrid/java/client/entities/Group.java    |    79 +
 .../usergrid/java/client/entities/Message.java  |   148 +
 .../org/usergrid/java/client/entities/User.java |   158 +
 .../java/client/exception/ClientException.java  |    42 +
 .../java/client/response/AggregateCounter.java  |    52 +
 .../client/response/AggregateCounterSet.java    |   111 +
 .../java/client/response/ApiResponse.java       |   421 +
 .../client/response/ClientCredentialsInfo.java  |    58 +
 .../java/client/response/QueueInfo.java         |    44 +
 .../usergrid/java/client/utils/JsonUtils.java   |   182 +
 .../usergrid/java/client/utils/MapUtils.java    |    39 +
 .../usergrid/java/client/utils/ObjectUtils.java |    36 +
 .../usergrid/java/client/utils/UrlUtils.java    |   124 +
 stack/README.md                                 |    14 +-
 stack/awscluster/aws-sample.properties          |    17 +
 stack/awscluster/src/main/cql/create_locks.cql  |    17 +
 .../awscluster/src/main/cql/create_usergrid.cql |    17 +
 .../main/cql/create_usergrid_applications.cql   |    17 +
 .../main/dist/init_instance/init_rest_server.sh |    13 +-
 stack/cloudbees.xml                             |    18 +
 .../main/resources/usergrid-default.properties  |    29 +-
 stack/config/src/test/resources/cassandra.yaml  |    25 +-
 .../src/test/resources/usergrid-test.properties |    14 +
 stack/core/pom.xml                              |    44 +-
 .../java/org/apache/usergrid/batch/Job.java     |    12 +-
 .../org/apache/usergrid/batch/JobFactory.java   |     2 +-
 .../usergrid/batch/UsergridJobFactory.java      |     6 +-
 .../batch/service/JobSchedulerService.java      |   302 +-
 .../corepersistence/CpEntityManager.java        |    54 +-
 .../corepersistence/CpEntityMapUtils.java       |     2 +-
 .../corepersistence/CpRelationManager.java      |    63 +-
 .../apache/usergrid/metrics/MetricsFactory.java |     8 -
 .../java/org/apache/usergrid/mq/Message.java    |    10 +-
 .../usergrid/mq/cassandra/QueueManagerImpl.java |    38 +-
 .../mq/cassandra/io/AbstractSearch.java         |     5 +-
 .../mq/cassandra/io/ConsumerTransaction.java    |    12 +-
 .../usergrid/persistence/CredentialsInfo.java   |    13 +-
 .../apache/usergrid/persistence/EntityRef.java  |     1 -
 .../persistence/ObservableIterator.java         |    82 +
 .../apache/usergrid/persistence/PathQuery.java  |     8 +-
 .../usergrid/persistence/SimpleEntityRef.java   |    36 +-
 .../cassandra/CassandraPersistenceUtils.java    |     9 +-
 .../persistence/cassandra/CassandraService.java |   137 +-
 .../cassandra/EntityManagerFactoryImpl.java     |     5 +-
 .../cassandra/EntityManagerImpl.java            |    58 +-
 .../persistence/cassandra/GeoIndexManager.java  |    21 +-
 .../persistence/cassandra/QueryProcessor.java   |     3 +-
 .../cassandra/RelationManagerImpl.java          |    55 +-
 .../persistence/cassandra/Serializers.java      |    14 +-
 .../persistence/hector/CountingMutator.java     |   344 +
 .../usergrid/persistence/query/ir/AllNode.java  |    12 +
 .../persistence/query/ir/BooleanNode.java       |    16 +
 .../query/ir/EmailIdentifierNode.java           |    12 +
 .../query/ir/NameIdentifierNode.java            |    12 +
 .../usergrid/persistence/query/ir/NotNode.java  |    12 +
 .../persistence/query/ir/OrderByNode.java       |    16 +-
 .../persistence/query/ir/QueryNode.java         |    12 +
 .../persistence/query/ir/SliceNode.java         |    12 +
 .../query/ir/UuidIdentifierNode.java            |    12 +
 .../persistence/query/ir/WithinNode.java        |    12 +
 .../query/ir/result/SubtractionIterator.java    |     8 +-
 .../org/apache/usergrid/utils/JsonUtils.java    |     8 +-
 .../org/apache/usergrid/utils/UUIDUtils.java    |    11 +
 .../main/resources/usergrid-core-context.xml    |     2 +-
 .../apache/usergrid/batch/BulkTestUtils.java    |    10 +-
 .../usergrid/batch/UsergridJobFactoryTest.java  |     3 +-
 .../usergrid/batch/job/CountdownLatchJob.java   |     6 +
 .../usergrid/batch/job/DelayExecution.java      |     6 +
 .../usergrid/batch/job/DelayHeartbeat.java      |     6 +
 .../batch/job/FailureJobExceuction.java         |    74 -
 .../usergrid/batch/job/FailureJobExecution.java |    87 +
 .../usergrid/batch/job/OnlyOnceExceution.java   |     6 +
 .../job/OnlyOnceUnlockOnFailExceution.java      |     6 +
 .../usergrid/batch/job/SchedulerRuntime1IT.java |     5 +-
 .../usergrid/batch/job/SchedulerRuntime2IT.java |    61 +-
 .../usergrid/batch/job/SchedulerRuntime3IT.java |    39 +-
 .../usergrid/batch/job/SchedulerRuntime4IT.java |    11 +-
 .../usergrid/batch/job/SchedulerRuntime5IT.java |     4 +-
 .../usergrid/batch/job/SchedulerRuntime6IT.java |    14 +-
 .../usergrid/batch/job/SchedulerRuntime7IT.java |    14 +-
 .../usergrid/batch/job/SchedulerRuntime8IT.java |     4 +-
 .../batch/job/SchedulerRuntimeIntervalIT.java   |   115 +
 .../usergrid/batch/job/TestJobListener.java     |    67 +-
 .../usergrid/batch/job/TestJobListenerTest.java |     7 +-
 .../corepersistence/CpEntityMapUtilsTest.java   |   119 +
 .../usergrid/persistence/CollectionIT.java      |    66 +
 .../usergrid/persistence/CountingMutatorIT.java |   119 +
 .../org/apache/usergrid/persistence/GeoIT.java  |    95 +-
 .../persistence/GeoQueryBooleanTest.java        |   190 +
 .../apache/usergrid/persistence/IndexIT.java    |    21 +-
 .../usergrid/persistence/PathQueryIT.java       |     4 +-
 .../cassandra/QueryProcessorTest.java           |    93 +-
 .../query/IntersectionTransitivePagingIT.java   |   163 +
 .../query/IntersectionUnionPagingIT.java        |     4 +-
 .../persistence/query/NotSubPropertyIT.java     |   177 +
 stack/core/src/test/resources/cassandra.yaml    |    17 +
 .../core/src/test/resources/project.properties  |    24 +-
 .../resources/usergrid-properties-context.xml   |    17 +
 .../usergrid-scheduler-test.properties          |    20 +-
 .../test/resources/usergrid-test-context.xml    |    16 +
 .../exception/CollectionRuntimeException.java   |     1 -
 .../exception/WriteUniqueVerifyException.java   |    18 -
 .../mvcc/entity/impl/MvccLogEntryImpl.java      |     3 +-
 .../UniqueValueSerializationStrategyImpl.java   |     2 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |     7 +-
 .../MvccEntitySerializationStrategyImpl.java    |    25 +-
 .../collection/guice/TestModule.java            |     2 +
 .../mvcc/stage/delete/MarkStartTest.java        |     3 +
 .../collection/mvcc/stage/load/LoadTest.java    |     7 +
 ...MvccEntitySerializationStrategyImplTest.java |    13 +-
 .../collection/util/InvalidIdGenerator.java     |    14 -
 .../src/test/resources/usergrid-UNIT.properties |     1 +
 .../core/astyanax/ColumnNameIterator.java       |    27 +-
 .../persistence/core/astyanax/ColumnSearch.java |    46 +
 .../persistence/core/astyanax/ColumnTypes.java  |     3 +
 .../astyanax/MultiKeyColumnNameIterator.java    |   235 +
 .../core/astyanax/MultiRowColumnIterator.java   |   253 +
 .../core/astyanax/MultiTennantColumnFamily.java |    13 +-
 .../core/hystrix/HystrixCassandra.java          |    73 +-
 .../persistence/core/rx/ObservableIterator.java |     2 +-
 .../persistence/core/rx/OrderedMerge.java       |   194 +-
 .../core/scope/ApplicationScopeImpl.java        |     3 +-
 .../persistence/core/util/ValidationUtils.java  |     2 +-
 .../core/astyanax/ColumnNameIteratorTest.java   |   205 +
 .../MultiKeyColumnNameIteratorTest.java         |   330 +
 .../astyanax/MultiRowColumnIteratorTest.java    |   502 +
 .../persistence/core/astyanax/TestUtils.java    |    76 +
 .../core/cassandra/CassandraRule.java           |    24 +-
 .../persistence/core/rx/OrderedMergeTest.java   |   146 +-
 .../common/src/test/resources/log4j.properties  |    39 +
 .../src/test/resources/usergrid-UNIT.properties |    14 +
 .../src/test/resources/usergrid.properties      |     1 +
 stack/corepersistence/graph/pom.xml             |     7 +
 .../apache/usergrid/persistence/graph/Edge.java |     1 -
 .../usergrid/persistence/graph/GraphFig.java    |    90 +-
 .../persistence/graph/SearchByEdge.java         |     8 +-
 .../persistence/graph/SearchByEdgeType.java     |    18 +-
 .../persistence/graph/guice/GraphModule.java    |    51 +-
 .../persistence/graph/guice/MergedProxy.java    |    34 -
 .../graph/guice/StorageEdgeSerialization.java   |    34 -
 .../graph/impl/CollectionIndexObserver.java     |     2 +-
 .../graph/impl/GraphManagerImpl.java            |    54 +-
 .../persistence/graph/impl/SimpleEdge.java      |     7 +-
 .../graph/impl/SimpleMarkedEdge.java            |     4 +-
 .../graph/impl/SimpleSearchByEdge.java          |    20 +-
 .../graph/impl/SimpleSearchByEdgeType.java      |    22 +-
 .../graph/impl/SimpleSearchByIdType.java        |     6 +-
 .../impl/stage/EdgeDeleteListenerImpl.java      |     3 -
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |    16 +-
 .../graph/impl/stage/EdgeMetaRepair.java        |     2 -
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |    67 +-
 .../impl/stage/NodeDeleteListenerImpl.java      |    26 +-
 .../EdgeMetadataSerialization.java              |     3 +-
 .../graph/serialization/EdgeSerialization.java  |     3 +-
 .../graph/serialization/NodeSerialization.java  |     3 +-
 .../impl/EdgeMetadataSerializationImpl.java     |     8 +-
 .../impl/EdgeSerializationImpl.java             |  1037 +-
 .../impl/NodeSerializationImpl.java             |    86 +-
 .../serialization/impl/shard/DirectedEdge.java  |    41 +
 .../impl/shard/DirectedEdgeMeta.java            |   575 +
 .../impl/shard/EdgeColumnFamilies.java          |    60 +
 .../serialization/impl/shard/EdgeRowKey.java    |    44 +
 .../impl/shard/EdgeShardSerialization.java      |    24 +-
 .../impl/shard/EdgeShardStrategy.java           |    45 +-
 .../impl/shard/NodeShardAllocation.java         |    21 +-
 .../impl/shard/NodeShardApproximation.java      |    31 +-
 .../impl/shard/NodeShardCache.java              |    21 +-
 .../serialization/impl/shard/NodeType.java      |    66 +
 .../graph/serialization/impl/shard/RowKey.java  |    55 +
 .../serialization/impl/shard/RowKeyType.java    |    66 +
 .../graph/serialization/impl/shard/Shard.java   |   143 +
 .../impl/shard/ShardEntryGroup.java             |   324 +
 .../impl/shard/ShardGroupCompaction.java        |    71 +
 .../impl/shard/ShardedEdgeSerialization.java    |   186 +
 .../serialization/impl/shard/count/Counter.java |     8 +-
 .../shard/count/NodeShardApproximationImpl.java |   177 +-
 .../count/NodeShardCounterSerialization.java    |     2 +-
 .../NodeShardCounterSerializationImpl.java      |    98 +-
 .../impl/shard/count/ShardKey.java              |    53 +-
 .../impl/shard/impl/EdgeRowKey.java             |    46 -
 .../impl/shard/impl/EdgeRowKeySerializer.java   |    58 -
 .../impl/shard/impl/EdgeSearcher.java           |   162 +
 .../shard/impl/EdgeShardSerializationImpl.java  |    90 +-
 .../shard/impl/NodeShardAllocationImpl.java     |   288 +-
 .../impl/shard/impl/NodeShardCacheImpl.java     |   254 +-
 .../shard/impl/ShardEntryGroupIterator.java     |   123 +
 .../shard/impl/ShardGroupColumnIterator.java    |   130 +
 .../shard/impl/ShardGroupCompactionImpl.java    |   618 +
 .../impl/ShardedEdgeSerializationImpl.java      |  1006 +
 .../impl/shard/impl/ShardsColumnIterator.java   |   127 +
 .../shard/impl/SizebasedEdgeColumnFamilies.java |   154 +
 .../shard/impl/SizebasedEdgeShardStrategy.java  |    51 +-
 .../impl/shard/impl/SourceEdgeSearcher.java     |    22 +
 .../DescendingTimestampComparator.java          |    43 +
 .../DirectedEdgeDescendingComparator.java       |    69 +
 .../impl/comparators/OrderedComparator.java     |    52 +
 .../SourceDirectedEdgeDescendingComparator.java |    42 +
 .../TargetDirectedEdgeDescendingComparator.java |    42 +
 .../impl/serialize/EdgeRowKeySerializer.java    |    63 +
 .../shard/impl/serialize/EdgeSerializer.java    |    77 +
 .../serialize/EdgeShardRowKeySerializer.java    |   103 +
 .../shard/impl/serialize/RowSerializer.java     |    63 +
 .../shard/impl/serialize/RowTypeSerializer.java |    62 +
 .../graph/serialization/util/EdgeHasher.java    |    86 -
 .../graph/serialization/util/EdgeUtils.java     |   132 -
 .../serialization/util/GraphValidation.java     |   189 +
 .../graph/ComittedGraphManagerIT.java           |   138 -
 .../graph/CommittedGraphManagerIT.java          |   135 +
 .../persistence/graph/GraphManagerIT.java       |     3 -
 .../persistence/graph/GraphManagerLoadTest.java |     7 +-
 .../graph/GraphManagerShardConsistencyIT.java   |   563 +
 .../graph/GraphManagerShardingIT.java           |    48 +-
 .../graph/GraphManagerStressTest.java           |     9 +-
 .../usergrid/persistence/graph/SimpleTest.java  |    18 +-
 .../graph/StorageGraphManagerIT.java            |     2 +-
 .../graph/impl/EdgeDeleteListenerTest.java      |     4 +-
 .../graph/impl/NodeDeleteListenerTest.java      |     2 -
 .../graph/impl/stage/EdgeDeleteRepairTest.java  |     7 +-
 .../graph/impl/stage/EdgeMetaRepairTest.java    |     2 -
 .../EdgeMetadataSerializationTest.java          |     2 +-
 .../EdgeSerializationChopTest.java              |     7 +-
 .../serialization/NodeSerializationTest.java    |     3 +-
 .../PermanentSerializationTest.java             |     3 -
 .../graph/serialization/TestCount.java          |     1 -
 .../impl/shard/EdgeShardSerializationTest.java  |   108 +-
 .../impl/shard/NodeShardAllocationTest.java     |   620 +-
 .../impl/shard/NodeShardCacheTest.java          |   235 +-
 .../impl/shard/ShardEntryGroupTest.java         |   409 +
 .../impl/shard/ShardGroupCompactionTest.java    |   226 +
 .../shard/count/NodeShardApproximationTest.java |   130 +-
 .../NodeShardCounterSerializationTest.java      |     8 +-
 .../shard/impl/ShardEntryGroupIteratorTest.java |   276 +
 ...rceDirectedEdgeDescendingComparatorTest.java |   136 +
 ...getDirectedEdgeDescendingComparatorTest.java |   136 +
 .../serialization/util/EdgeHasherTest.java      |   501 -
 .../graph/test/util/EdgeTestUtils.java          |    12 +-
 .../graph/src/test/resources/log4j.properties   |     1 +
 .../test/resources/usergrid-SHARD.properties    |    23 +
 .../src/test/resources/usergrid-UNIT.properties |     3 +
 .../persistence/model/entity/Entity.java        |     2 +-
 .../persistence/model/field/AbstractField.java  |     2 +-
 .../persistence/model/field/ArrayField.java     |     4 +
 .../usergrid/persistence/model/field/Field.java |     2 +-
 .../persistence/model/field/SetField.java       |     1 +
 .../model/field/value/EntityObject.java         |    12 +-
 .../persistence/model/entity/SimpleIdTest.java  |    73 +
 .../model/src/test/resources/log4j.properties   |    29 +
 stack/corepersistence/pom.xml                   |     4 +-
 .../src/main/java/CpQueryFilter.tokens          |    47 +
 .../usergrid/persistence/index/query/Query.java |    19 +-
 .../persistence/index/utils/JsonUtils.java      |   329 -
 .../persistence/index/impl/EntityIndexTest.java |    19 +
 .../src/test/resources/log4j.properties         |     6 +-
 .../apache/usergrid/launcher/AppleUtils.java    |    21 +-
 .../launcher/src/main/resources/cassandra.yaml  |    25 +-
 .../1.5.4/AppleJavaExtensions-1.5.4.jar         |   Bin 23531 -> 0 bytes
 .../1.5.4/AppleJavaExtensions-1.5.4.pom         |     9 -
 .../maven-metadata-local.xml                    |    12 -
 .../recaptcha4j/0.0.8/recaptcha4j-0.0.8.jar     |   Bin 10344 -> 0 bytes
 .../recaptcha4j/0.0.8/recaptcha4j-0.0.8.pom     |     9 -
 .../recaptcha4j/maven-metadata-local.xml        |    12 -
 .../0.0.3/usergrid-java-client-0.0.3.jar        |   Bin 45750 -> 0 bytes
 .../usergrid-java-client-0.0.3.jar.lastUpdated  |     5 -
 .../0.0.3/usergrid-java-client-0.0.3.jar.sha1   |     1 -
 .../0.0.3/usergrid-java-client-0.0.3.pom        |    87 -
 .../usergrid-java-client-0.0.3.pom.lastUpdated  |     5 -
 .../0.0.3/usergrid-java-client-0.0.3.pom.sha1   |     1 -
 .../maven-metadata-local.xml                    |    13 -
 stack/mongo-emulator/pom.xml                    |     2 +-
 .../test/resources/usergrid-test-context.xml    |    78 +-
 stack/pom.xml                                   |    69 +-
 stack/query-validator/pom.xml                   |     2 +-
 .../test/resources/usergrid-test-context.xml    |     3 +-
 stack/rest/pom.xml                              |    29 +-
 .../exceptions/JsonParseExceptionMapper.java    |    35 +
 .../apache/usergrid/rest/AbstractRestIT.java    |    11 +
 .../applications/users/MatrixQueryTests.java    |   202 +
 .../users/PermissionsResourceIT.java            |     1 +
 .../rest/applications/utils/UserRepo.java       |     9 +
 .../rest/management/ExportResourceIT.java       |   131 +-
 .../rest/test/resource/MatrixResource.java      |    64 +
 .../rest/test/resource/NamedResource.java       |     5 +
 .../rest/test/resource/SetResource.java         |    12 +
 .../rest/test/resource/ValueResource.java       |    18 +-
 .../resources/usergrid-properties-context.xml   |    17 +
 .../resources/usergrid-rest-deploy-context.xml  |    16 +
 .../test/resources/usergrid-test-context.xml    |    16 +
 stack/services/pom.xml                          |    10 +-
 .../management/AccountCreationProps.java        |     6 +-
 .../cassandra/ManagementServiceImpl.java        |     8 +-
 .../usergrid/management/export/ExportJob.java   |     6 +
 .../management/export/ExportServiceImpl.java    |     5 +
 .../usergrid/services/ServiceRequest.java       |    11 +-
 .../apache/usergrid/management/EmailFlowIT.java |    17 +-
 .../usergrid/management/OrganizationIT.java     |     2 +
 .../resources/usergrid-properties-context.xml   |    17 +
 stack/test-utils/pom.xml                        |     2 +-
 .../src/main/resources/cassandra.yaml           |    25 +-
 .../src/test/resources/project.properties       |    21 +-
 .../resources/usergrid-custom-test.properties   |    16 +
 .../resources/usergrid-properties-context.xml   |    17 +
 stack/tools/pom.xml                             |     2 +-
 .../org/apache/usergrid/tools/AppNameFix.java   |    59 +-
 .../RepairingMismatchedApplicationMetadata.java |    92 +-
 .../src/main/resources/apidoc/applications.yaml |    21 +-
 .../src/main/resources/apidoc/management.yaml   |    21 +-
 stack/tools/src/main/resources/log4j.properties |    45 +
 stack/websocket/pom.xml                         |     2 +-
 ugc/features/step_definitions/ugc_steps.rb      |    23 +-
 ugc/features/support/env.rb                     |    23 +-
 ugc/lib/ugc.rb                                  |    23 +-
 ugc/lib/ugc/application.rb                      |    23 +-
 ugc/lib/ugc/commands/delete.rb                  |    23 +-
 ugc/lib/ugc/commands/get.rb                     |    23 +-
 ugc/lib/ugc/commands/logout.rb                  |    16 +
 ugc/lib/ugc/commands/post.rb                    |    23 +-
 ugc/lib/ugc/commands/profile.rb                 |    23 +-
 ugc/lib/ugc/commands/put.rb                     |    23 +-
 ugc/lib/ugc/commands/query.rb                   |    23 +-
 ugc/lib/ugc/commands/target.rb                  |    23 +-
 ugc/lib/ugc/helpers/curl.rb                     |    23 +-
 ugc/lib/ugc/helpers/format.rb                   |    23 +-
 ugc/lib/ugc/helpers/history.rb                  |    23 +-
 ugc/lib/ugc/helpers/parse.rb                    |    23 +-
 ugc/lib/ugc/helpers/rest.rb                     |    23 +-
 ugc/lib/ugc/management.rb                       |    23 +-
 ugc/lib/ugc/settings.rb                         |    23 +-
 ugc/lib/ugc/version.rb                          |    23 +-
 ugc/test/default_test.rb                        |    23 +-
 ugc/test/test_helper.rb                         |    23 +-
 928 files changed, 28111 insertions(+), 168084 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1d8dd2f6/stack/core/pom.xml
----------------------------------------------------------------------
diff --cc stack/core/pom.xml
index 899d30e,709d9aa..33a0ca4
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@@ -545,22 -545,43 +544,53 @@@
          <version>2.0.0-SNAPSHOT</version>
      </dependency>
  
+         <dependency>
+             <groupId>org.apache.usergrid.chop</groupId>
+             <artifactId>chop-stack</artifactId>
+             <version>2.0.0-SNAPSHOT</version>
+         </dependency>
+     -->
+ 
      <dependency>
-         <groupId>org.apache.usergrid.chop</groupId>
-         <artifactId>chop-stack</artifactId>
-         <version>2.0.0-SNAPSHOT</version>
-     </dependency>-->
+       <groupId>com.codahale.metrics</groupId>
+       <artifactId>metrics-core</artifactId>
+       <version>${metrics.version}</version>
+     </dependency>
+ 
+     <dependency>
+       <groupId>com.codahale.metrics</groupId>
+       <artifactId>metrics-graphite</artifactId>
+       <version>${metrics.version}</version>
+     </dependency>
+ 
+     <dependency>
+       <groupId>com.netflix.rxjava</groupId>
+       <artifactId>rxjava-core</artifactId>
+       <version>${rx.version}</version>
+     </dependency>
+ 
+     <dependency>
+       <groupId>com.netflix.rxjava</groupId>
+       <artifactId>rxjava-math</artifactId>
+       <version>${rx.version}</version>
+     </dependency>
+ 
+     <dependency>
+       <groupId>com.clearspring.analytics</groupId>
+       <artifactId>stream</artifactId>
+       <version>2.7.0</version>
+     </dependency>
  
 +    <dependency>
 +      <groupId>com.codahale.metrics</groupId>
 +      <artifactId>metrics-core</artifactId>
 +      <version>${metrics.version}</version>
 +    </dependency>
 +    <dependency>
 +      <groupId>com.codahale.metrics</groupId>
 +      <artifactId>metrics-graphite</artifactId>
 +      <version>${metrics.version}</version>
 +    </dependency>
    </dependencies>
  
  </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1d8dd2f6/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --cc stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 4640fba,7e1f199..b27a61d
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@@ -410,13 -411,13 +411,13 @@@ public class CpEntityManager implement
  
          EntityCollectionManager ecm = managerCache.getEntityCollectionManager( collectionScope );
  
-         if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
-             throw new IllegalArgumentException(
-                 "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
-         }
+ //        if ( !UUIDUtils.isTimeBased( id.getUuid() ) ) {
+ //            throw new IllegalArgumentException(
+ //                "Entity Id " + id.getType() + ":"+ id.getUuid() +" uuid not time based");
+ //        }
  
          org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
 -                ecm.load( id ).toBlockingObservable().last();
 +                ecm.load( id ).toBlocking().last();
  
          if ( cpEntity == null ) {
              if ( logger.isDebugEnabled() ) {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1d8dd2f6/stack/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1d8dd2f6/stack/services/pom.xml
----------------------------------------------------------------------


[19/33] git commit: update apns size

Posted by sn...@apache.org.
update apns size


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

Branch: refs/heads/two-dot-o
Commit: 1e7a1aeea02856832a43e822ef3f622938e8e42d
Parents: 390baed
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 21 08:21:03 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 21 08:21:03 2014 -0600

----------------------------------------------------------------------
 .../apache/usergrid/services/notifications/apns/APNsAdapter.java   | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1e7a1aee/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index 552d138..ded9ac7 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -220,7 +220,7 @@ public class APNsAdapter implements ProviderAdapter {
         }
         if (payload.length() > 2048) {
             throw new IllegalArgumentException(
-                    "Apple APNs payloads must be 256 characters or less");
+                    "Apple APNs payloads must be 2048 characters or less");
         }
         return payload;
     }


[10/33] git commit: fix null reference exception

Posted by sn...@apache.org.
fix null reference exception


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

Branch: refs/heads/two-dot-o
Commit: ed43ff9cc2a84f7e52c49e78e7f32fd6a8ceed9e
Parents: cb0e4b5
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Aug 19 09:24:43 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Aug 19 09:24:43 2014 -0600

----------------------------------------------------------------------
 .../usergrid/services/notifications/NotificationsQueueManager.java | 2 +-
 .../apache/usergrid/services/notifications/apns/APNsAdapter.java   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ed43ff9c/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
index 95dfb8e..e7ea96c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
@@ -221,9 +221,9 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         }
         notification.addProperties(properties);
         em.update(notification);
-        long elapsed = notification.getQueued() - startTime;
 
         if (LOG.isInfoEnabled()) {
+            long elapsed = notification.getQueued() != null ? notification.getQueued() - startTime : 0;
             StringBuilder sb = new StringBuilder();
             sb.append("notification ").append(notification.getUuid());
             sb.append(" done queuing to ").append(deviceCount);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ed43ff9c/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index 73399c9..0f17dbe 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -161,7 +161,7 @@ public class APNsAdapter implements ProviderAdapter {
                 pushManager.start();
             }
         }catch(IllegalStateException ise){
-            logger.debug("failed to start",ise);//could have failed because its starteded
+            logger.debug("failed to start",ise);//could have failed because its started
         }
         return pushManager;
     }


[11/33] git commit: moving notifications, notifiers entities

Posted by sn...@apache.org.
moving notifications, notifiers entities


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/51e09317
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/51e09317
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/51e09317

Branch: refs/heads/two-dot-o
Commit: 51e09317892e69ca567fba0afd4b4e509633c80d
Parents: ed43ff9
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Aug 19 15:03:26 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Aug 19 15:03:26 2014 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |   4 +-
 .../usergrid/persistence/Notification.java      | 241 -------------------
 .../apache/usergrid/persistence/Notifier.java   | 139 -----------
 .../apache/usergrid/persistence/Receipt.java    | 133 ----------
 .../persistence/entities/Notification.java      | 240 ++++++++++++++++++
 .../usergrid/persistence/entities/Notifier.java | 135 +++++++++++
 .../usergrid/persistence/entities/Receipt.java  | 133 ++++++++++
 .../services/notifications/JobScheduler.java    |   2 +-
 .../notifications/NotificationBatchJob.java     |   2 +-
 .../services/notifications/NotificationJob.java |   2 +-
 .../notifications/NotificationServiceProxy.java |   4 +-
 .../notifications/NotificationsService.java     |   3 +
 .../services/notifications/ProviderAdapter.java |   4 +-
 .../services/notifications/QueueJob.java        |   2 +-
 .../services/notifications/TaskManager.java     |   3 +
 .../services/notifications/TaskTracker.java     |   4 +-
 .../services/notifications/TestAdapter.java     |   4 +-
 .../notifications/apns/APNsAdapter.java         |   4 +-
 .../notifications/apns/APNsNotification.java    |   2 +-
 .../services/notifications/gcm/GCMAdapter.java  |   4 +-
 .../services/notifiers/NotifiersService.java    |  15 +-
 .../AbstractServiceNotificationTest.java        |   2 +
 .../apns/MockSuccessfulProviderAdapter.java     |   4 +-
 .../apns/NotificationsServiceTest.java          |  40 ++-
 .../gcm/MockSuccessfulProviderAdapter.java      |   3 +-
 .../gcm/NotificationsServiceTest.java           |   4 +-
 .../notifiers/NotifiersServiceTest.java         |   2 +-
 27 files changed, 568 insertions(+), 567 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index 7795550..02f12d6 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -416,7 +416,7 @@ public class CpEntityManager implements EntityManager {
         }
 
         org.apache.usergrid.persistence.model.entity.Entity cpEntity = 
-                ecm.load( id ).toBlockingObservable().last();
+                ecm.load( id ).toBlocking().last();
 
         if ( cpEntity == null ) {
             if ( logger.isDebugEnabled() ) {
@@ -2557,7 +2557,7 @@ public class CpEntityManager implements EntityManager {
             logger.debug("About to Write {}:{} version {}", new Object[] { 
                 cpEntity.getId().getType(), cpEntity.getId().getUuid(), cpEntity.getVersion() });
 
-             cpEntity = ecm .write( cpEntity ).toBlockingObservable().last();
+             cpEntity = ecm .write( cpEntity ).toBlocking().last();
 
             logger.debug("Wrote {}:{} version {}", new Object[] { 
                 cpEntity.getId().getType(), cpEntity.getId().getUuid(), cpEntity.getVersion() });

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
deleted file mode 100644
index f3b7392..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence;
-
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.usergrid.persistence.PathQuery;
-import org.apache.usergrid.persistence.TypedEntity;
-import org.apache.usergrid.persistence.annotations.EntityCollection;
-import org.apache.usergrid.persistence.annotations.EntityProperty;
-import org.apache.usergrid.persistence.entities.Device;
-
-/**
- * The entity class for representing Notifications.
- */
-@XmlRootElement
-public class Notification extends TypedEntity {
-
-    public static final String ENTITY_TYPE = "notification";
-
-    public static final String RECEIPTS_COLLECTION = "receipts";
-
-    public static enum State {
-        CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
-    }
-
-    /** Map Notifier ID -> Payload data */
-    @EntityProperty
-    protected Map<String, Object> payloads;
-
-    /** Time processed */
-    @EntityProperty
-    protected Long queued;
-
-    /** Time send started */
-    @EntityProperty
-    protected Long started;
-
-    /** Time processed */
-    @EntityProperty
-    protected Long finished;
-
-    /** Time to deliver to provider */
-    @EntityProperty
-    protected Long deliver;
-
-    /** Time to expire the notification */
-    @EntityProperty
-    protected Long expire;
-
-    /** True if notification is canceled */
-    @EntityProperty
-    protected Boolean canceled;
-
-    /** Error message */
-    @EntityProperty
-    protected String errorMessage;
-
-    @EntityCollection(type = "receipt")
-    protected List<UUID> receipts;
-
-    /** stats (sent & errors) */
-    @EntityProperty
-    protected Map<String, Long> statistics;
-
-    /** stats (sent & errors) */
-    @EntityProperty
-    @JsonIgnore
-    protected PathQuery<Device> pathQuery;
-
-    public Notification() {
-    }
-
-    @JsonIgnore
-    public List<UUID> getReceipts() {
-        return receipts;
-    }
-
-    public void setReceipts(List<UUID> receipts) {
-        this.receipts = receipts;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Map<String, Object> getPayloads() {
-        return payloads;
-    }
-
-    public void setPayloads(Map<String, Object> payloads) {
-        this.payloads = payloads;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getFinished() {
-        return finished;
-    }
-
-    public void setFinished(Long finished) {
-        this.finished = finished;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getDeliver() {
-        return deliver;
-    }
-
-    public void setDeliver(Long deliver) {
-        this.deliver = deliver;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getExpire() {
-        return expire;
-    }
-
-    public void setExpire(Long expire) {
-        this.expire = expire;
-    }
-
-    @JsonIgnore
-    public boolean isExpired() {
-        return expire != null && expire > System.currentTimeMillis();
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Boolean getCanceled() {
-        return canceled;
-    }
-
-    public void setCanceled(Boolean canceled) {
-        this.canceled = canceled;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getStarted() {
-        return started;
-    }
-
-    public void setStarted(Long started) {
-        this.started = started;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public String getErrorMessage() {
-        return errorMessage;
-    }
-
-    public void setErrorMessage(String errorMessage) {
-        this.errorMessage = errorMessage;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Map<String, Long> getStatistics() {
-        return statistics;
-    }
-
-    public void setStatistics(Map<String, Long> statistics) {
-        this.statistics = statistics;
-    }
-
-    public void updateStatistics(long sent, long errors) {
-        if (this.statistics == null) {
-            this.statistics = new HashMap<String, Long>(2);
-            this.statistics.put("sent", sent);
-            this.statistics.put("errors", errors);
-        } else {
-            this.statistics.put("sent", sent + this.statistics.get("sent"));
-            this.statistics.put("errors",
-                    errors + this.statistics.get("errors"));
-        }
-    }
-
-    /** don't bother, I will ignore you */
-    public void setState(State ignored) {
-        // does nothing - state is derived
-    }
-
-    @EntityProperty
-    public State getState() {
-        if (getErrorMessage() != null) {
-            return State.FAILED;
-        } else if (getCanceled() == Boolean.TRUE) {
-            return State.CANCELED;
-        } else if (getFinished() != null) {
-            return State.FINISHED;
-        } else if (getStarted() != null && getDeliver() == null) {
-            return State.STARTED;
-        } else if (isExpired()) {
-            return State.EXPIRED;
-        } else if (getDeliver() != null || getQueued() != null) {
-            return State.SCHEDULED;
-        }
-        return State.CREATED;
-    }
-
-    @JsonIgnore
-    public PathQuery<Device> getPathQuery() {
-        return pathQuery;
-    }
-
-    public void setPathQuery(PathQuery<Device> pathQuery) {
-        this.pathQuery = pathQuery;
-    }
-
-    @JsonIgnore
-    public int getExpireTimeInSeconds() {
-        long expirySeconds = getExpire() != null ? getExpire() * 1000 : 0;
-        return (expirySeconds > Integer.MAX_VALUE) ? Integer.MAX_VALUE
-                : (int) expirySeconds;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getQueued() {
-        return queued;
-    }
-
-    public void setQueued(Long queued) {
-        this.queued = queued;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
deleted file mode 100644
index 953ec6d..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence;
-
-import org.codehaus.jackson.annotate.JsonIgnore;
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-import org.apache.usergrid.persistence.TypedEntity;
-import org.apache.usergrid.persistence.annotations.EntityProperty;
-
-import javax.net.ssl.SSLContext;
-import javax.xml.bind.annotation.XmlRootElement;
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.security.KeyStore;
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * The entity class for representing Notifiers.
- */
-@XmlRootElement
-public class Notifier extends TypedEntity {
-
-    public static final String ENTITY_TYPE = "notifier";
-
-    @EntityProperty(aliasProperty = true, unique = true, basic = true)
-    protected String name;
-
-    @EntityProperty(required = true)
-    protected String provider;
-
-    @EntityProperty
-    protected String environment;
-
-    // Apple APNs
-    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
-    protected byte[] p12Certificate;
-
-    // Apple APNs
-    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
-    protected String certificatePassword;
-
-    // Google GCM
-    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
-    protected String apiKey;
-    private javax.net.ssl.SSLContext SSLContext;
-
-    public Notifier() {
-    }
-
-    public Notifier(UUID id) {
-        uuid = id;
-    }
-
-
-
-    @Override
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public String getName() {
-        return name;
-    }
-
-    public void setName(String name) {
-        this.name = name;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public String getProvider() {
-        return provider;
-    }
-
-    public void setProvider(String provider) {
-        this.provider = provider;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public String getEnvironment() {
-        return environment;
-    }
-
-    public void setEnvironment(String environment) {
-        this.environment = environment;
-    }
-
-    @JsonIgnore
-    public boolean isProduction() {
-        return !"development".equals(environment);
-    }
-
-    @JsonIgnore
-    public byte[] getP12Certificate() {
-        return p12Certificate;
-    }
-
-    public void setP12Certificate(byte[] p12Certificate) {
-        this.p12Certificate = p12Certificate;
-    }
-
-    @JsonIgnore
-    public InputStream getP12CertificateStream() {
-        byte[] cert = getP12Certificate();
-        return cert != null ? new ByteArrayInputStream(cert) : null;
-    }
-
-    @JsonIgnore
-    public String getCertificatePassword() {
-        return certificatePassword;
-    }
-
-    public void setCertificatePassword(String certificatePassword) {
-        this.certificatePassword = certificatePassword;
-    }
-
-    @JsonIgnore
-    public String getApiKey() {
-        return apiKey;
-    }
-
-    public void setApiKey(String apiKey) {
-        this.apiKey = apiKey;
-    }
-
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
deleted file mode 100644
index f1c034b..0000000
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.persistence;
-
-import org.codehaus.jackson.map.annotate.JsonSerialize;
-import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
-
-import javax.xml.bind.annotation.XmlRootElement;
-import java.util.UUID;
-import org.apache.usergrid.persistence.annotations.EntityProperty;
-
-@XmlRootElement
-public class Receipt extends TypedEntity {
-
-    public static final String ENTITY_TYPE = "receipt";
-    public static final String NOTIFICATION_CONNECTION = "notification";
-
-    /** device id **/
-    @EntityProperty
-    protected UUID deviceId;
-
-    /** data sent to provider */
-    @EntityProperty
-    protected Object payload;
-
-    /** Time sent to provider */
-    @EntityProperty
-    protected Long sent;
-
-    /** Error code */
-    @EntityProperty
-    protected Object errorCode;
-
-    /** Error message */
-    @EntityProperty
-    protected String errorMessage;
-
-    /** The push token given by the provider */
-    @EntityProperty
-    protected String notifierId;
-
-    /**
-     * UUID of the Notification that sent this - not a Connection for
-     * performance reasons
-     */
-    @EntityProperty
-    protected UUID notificationUUID;
-
-    public Receipt() {
-    }
-
-    public Receipt(UUID notificationUUID, String notifierId, Object payload,UUID deviceId) {
-        this.notificationUUID = notificationUUID;
-        this.notifierId = notifierId;
-        this.payload = payload;
-        this.setDeviceId(deviceId);
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Object getPayload() {
-        return payload;
-    }
-
-    public void setPayload(Object payload) {
-        this.payload = payload;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Long getSent() {
-        return sent;
-    }
-
-    public void setSent(Long sent) {
-        this.sent = sent;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public Object getErrorCode() {
-        return errorCode;
-    }
-
-    public void setErrorCode(Object errorCode) {
-        this.errorCode = errorCode;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public String getErrorMessage() {
-        return errorMessage;
-    }
-
-    public void setErrorMessage(String errorMessage) {
-        this.errorMessage = errorMessage;
-    }
-
-    public String getNotifierId() {
-        return notifierId;
-    }
-
-    public void setNotifierId(String notifierId) {
-        this.notifierId = notifierId;
-    }
-
-    public UUID getNotificationUUID() {
-        return notificationUUID;
-    }
-
-    public void setNotificationUUID(UUID notificationUUID) {
-        this.notificationUUID = notificationUUID;
-    }
-
-    @JsonSerialize(include = Inclusion.NON_NULL)
-    public UUID getDeviceId() {
-        return deviceId;
-    }
-
-    public void setDeviceId(UUID deviceId) {
-        this.deviceId = deviceId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
new file mode 100644
index 0000000..c723302
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -0,0 +1,240 @@
+/*
+ * 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.usergrid.persistence.entities;
+
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityCollection;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.persistence.entities.Device;
+
+/**
+ * The entity class for representing Notifications.
+ */
+@XmlRootElement
+public class Notification extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notification";
+
+    public static final String RECEIPTS_COLLECTION = "receipts";
+
+    public static enum State {
+        CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
+    }
+
+    /** Map Notifier ID -> Payload data */
+    @EntityProperty
+    protected Map<String, Object> payloads;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long queued;
+
+    /** Time send started */
+    @EntityProperty
+    protected Long started;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long finished;
+
+    /** Time to deliver to provider */
+    @EntityProperty
+    protected Long deliver;
+
+    /** Time to expire the notification */
+    @EntityProperty
+    protected Long expire;
+
+    /** True if notification is canceled */
+    @EntityProperty
+    protected Boolean canceled;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    @EntityCollection(type = "receipt")
+    protected List<UUID> receipts;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    protected Map<String, Long> statistics;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    @JsonIgnore
+    protected PathQuery<Device> pathQuery;
+
+    public Notification() {
+    }
+
+    @JsonIgnore
+    public List<UUID> getReceipts() {
+        return receipts;
+    }
+
+    public void setReceipts(List<UUID> receipts) {
+        this.receipts = receipts;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Map<String, Object> getPayloads() {
+        return payloads;
+    }
+
+    public void setPayloads(Map<String, Object> payloads) {
+        this.payloads = payloads;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getFinished() {
+        return finished;
+    }
+
+    public void setFinished(Long finished) {
+        this.finished = finished;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getDeliver() {
+        return deliver;
+    }
+
+    public void setDeliver(Long deliver) {
+        this.deliver = deliver;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getExpire() {
+        return expire;
+    }
+
+    public void setExpire(Long expire) {
+        this.expire = expire;
+    }
+
+    @JsonIgnore
+    public boolean isExpired() {
+        return expire != null && expire > System.currentTimeMillis();
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Boolean getCanceled() {
+        return canceled;
+    }
+
+    public void setCanceled(Boolean canceled) {
+        this.canceled = canceled;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getStarted() {
+        return started;
+    }
+
+    public void setStarted(Long started) {
+        this.started = started;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Map<String, Long> getStatistics() {
+        return statistics;
+    }
+
+    public void setStatistics(Map<String, Long> statistics) {
+        this.statistics = statistics;
+    }
+
+    public void updateStatistics(long sent, long errors) {
+        if (this.statistics == null) {
+            this.statistics = new HashMap<String, Long>(2);
+            this.statistics.put("sent", sent);
+            this.statistics.put("errors", errors);
+        } else {
+            this.statistics.put("sent", sent + this.statistics.get("sent"));
+            this.statistics.put("errors",
+                    errors + this.statistics.get("errors"));
+        }
+    }
+
+    /** don't bother, I will ignore you */
+    public void setState(State ignored) {
+        // does nothing - state is derived
+    }
+
+    @EntityProperty
+    public State getState() {
+        if (getErrorMessage() != null) {
+            return State.FAILED;
+        } else if (getCanceled() == Boolean.TRUE) {
+            return State.CANCELED;
+        } else if (getFinished() != null) {
+            return State.FINISHED;
+        } else if (getStarted() != null && getDeliver() == null) {
+            return State.STARTED;
+        } else if (isExpired()) {
+            return State.EXPIRED;
+        } else if (getDeliver() != null || getQueued() != null) {
+            return State.SCHEDULED;
+        }
+        return State.CREATED;
+    }
+
+    @JsonIgnore
+    public PathQuery<Device> getPathQuery() {
+        return pathQuery;
+    }
+
+    public void setPathQuery(PathQuery<Device> pathQuery) {
+        this.pathQuery = pathQuery;
+    }
+
+    @JsonIgnore
+    public int getExpireTimeInSeconds() {
+        long expirySeconds = getExpire() != null ? getExpire() * 1000 : 0;
+        return (expirySeconds > Integer.MAX_VALUE) ? Integer.MAX_VALUE
+                : (int) expirySeconds;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getQueued() {
+        return queued;
+    }
+
+    public void setQueued(Long queued) {
+        this.queued = queued;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notifier.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notifier.java
new file mode 100644
index 0000000..be0b447
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notifier.java
@@ -0,0 +1,135 @@
+/*
+ * 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.usergrid.persistence.entities;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.UUID;
+
+/**
+ * The entity class for representing Notifiers.
+ */
+@XmlRootElement
+public class Notifier extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notifier";
+
+    @EntityProperty(aliasProperty = true, unique = true, basic = true)
+    protected String name;
+
+    @EntityProperty(required = true)
+    protected String provider;
+
+    @EntityProperty
+    protected String environment;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected byte[] p12Certificate;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String certificatePassword;
+
+    // Google GCM
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String apiKey;
+    private javax.net.ssl.SSLContext SSLContext;
+
+    public Notifier() {
+    }
+
+    public Notifier(UUID id) {
+        uuid = id;
+    }
+
+
+
+    @Override
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public String getProvider() {
+        return provider;
+    }
+
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public String getEnvironment() {
+        return environment;
+    }
+
+    public void setEnvironment(String environment) {
+        this.environment = environment;
+    }
+
+    @JsonIgnore
+    public boolean isProduction() {
+        return !"development".equals(environment);
+    }
+
+    @JsonIgnore
+    public byte[] getP12Certificate() {
+        return p12Certificate;
+    }
+
+    public void setP12Certificate(byte[] p12Certificate) {
+        this.p12Certificate = p12Certificate;
+    }
+
+    @JsonIgnore
+    public InputStream getP12CertificateStream() {
+        byte[] cert = getP12Certificate();
+        return cert != null ? new ByteArrayInputStream(cert) : null;
+    }
+
+    @JsonIgnore
+    public String getCertificatePassword() {
+        return certificatePassword;
+    }
+
+    public void setCertificatePassword(String certificatePassword) {
+        this.certificatePassword = certificatePassword;
+    }
+
+    @JsonIgnore
+    public String getApiKey() {
+        return apiKey;
+    }
+
+    public void setApiKey(String apiKey) {
+        this.apiKey = apiKey;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Receipt.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Receipt.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Receipt.java
new file mode 100644
index 0000000..1ffc351
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Receipt.java
@@ -0,0 +1,133 @@
+/*
+ * 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.usergrid.persistence.entities;
+
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import org.apache.usergrid.persistence.TypedEntity;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.UUID;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+@XmlRootElement
+public class Receipt extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "receipt";
+    public static final String NOTIFICATION_CONNECTION = "notification";
+
+    /** device id **/
+    @EntityProperty
+    protected UUID deviceId;
+
+    /** data sent to provider */
+    @EntityProperty
+    protected Object payload;
+
+    /** Time sent to provider */
+    @EntityProperty
+    protected Long sent;
+
+    /** Error code */
+    @EntityProperty
+    protected Object errorCode;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    /** The push token given by the provider */
+    @EntityProperty
+    protected String notifierId;
+
+    /**
+     * UUID of the Notification that sent this - not a Connection for
+     * performance reasons
+     */
+    @EntityProperty
+    protected UUID notificationUUID;
+
+    public Receipt() {
+    }
+
+    public Receipt(UUID notificationUUID, String notifierId, Object payload,UUID deviceId) {
+        this.notificationUUID = notificationUUID;
+        this.notifierId = notifierId;
+        this.payload = payload;
+        this.setDeviceId(deviceId);
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Object getPayload() {
+        return payload;
+    }
+
+    public void setPayload(Object payload) {
+        this.payload = payload;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Long getSent() {
+        return sent;
+    }
+
+    public void setSent(Long sent) {
+        this.sent = sent;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public Object getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(Object errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    public String getNotifierId() {
+        return notifierId;
+    }
+
+    public void setNotifierId(String notifierId) {
+        this.notifierId = notifierId;
+    }
+
+    public UUID getNotificationUUID() {
+        return notificationUUID;
+    }
+
+    public void setNotificationUUID(UUID notificationUUID) {
+        this.notificationUUID = notificationUUID;
+    }
+
+    @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+    public UUID getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(UUID deviceId) {
+        this.deviceId = deviceId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
index c366a86..54b4434 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
@@ -18,7 +18,7 @@ package org.apache.usergrid.services.notifications;
 
 import org.apache.usergrid.batch.service.SchedulerService;
 import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.Notification;
 import org.apache.usergrid.persistence.entities.JobData;
 import org.apache.usergrid.services.ServiceManager;
 import org.slf4j.Logger;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
index 81006ce..05fd360 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
@@ -21,7 +21,7 @@ import java.util.UUID;
 
 import javax.annotation.PostConstruct;
 
-import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
index f80ee1e..4cf8c2f 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
@@ -20,7 +20,7 @@ import java.util.UUID;
 
 import javax.annotation.PostConstruct;
 
-import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
index 908482f..7712163 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
@@ -16,8 +16,8 @@
  */
 package org.apache.usergrid.services.notifications;
 
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 
 import java.util.Set;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index 7dd6503..ae289ed 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -23,6 +23,9 @@ import com.codahale.metrics.Timer;
 import org.apache.usergrid.metrics.MetricsFactory;
 import org.apache.usergrid.mq.Message;
 import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.services.*;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
index 5489c2d..5268674 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
@@ -19,8 +19,8 @@ package org.apache.usergrid.services.notifications;
 import java.util.Date;
 import java.util.Map;
 import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.apache.usergrid.services.ServicePayload;
 
 /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
index 554074e..e34c816 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
@@ -21,7 +21,7 @@ import java.util.UUID;
 
 import javax.annotation.PostConstruct;
 
-import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.Notification;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index e6c876c..85c4a16 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -19,6 +19,9 @@ package org.apache.usergrid.services.notifications;
 import java.util.*;
 
 import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
index 3b4d3d7..1ae0591 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
@@ -17,8 +17,8 @@
 package org.apache.usergrid.services.notifications;
 
 
-import org.apache.usergrid.persistence.Notifier;
-import org.apache.usergrid.persistence.Receipt;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
 
 import java.util.UUID;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
index b3f6243..1f996a9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.usergrid.services.notifications;
 
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index 0f17dbe..c3c1990 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -21,8 +21,8 @@ import com.google.common.cache.*;
 import com.relayrides.pushy.apns.*;
 import com.relayrides.pushy.apns.util.*;
 
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.mortbay.util.ajax.JSON;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
index 11a9856..b580410 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
@@ -21,7 +21,7 @@ import com.relayrides.pushy.apns.util.MalformedTokenStringException;
 import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
 import com.relayrides.pushy.apns.util.TokenUtil;
 
-import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.Notification;
 import org.apache.usergrid.services.notifications.TaskTracker;
 
 import java.util.Calendar;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
index 04a07d8..e9856f1 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
@@ -17,8 +17,8 @@
 package org.apache.usergrid.services.notifications.gcm;
 
 import com.google.android.gcm.server.*;
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.mortbay.util.ajax.JSON;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
index f923e2e..8c41e0a 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
@@ -16,8 +16,8 @@
  */
 package org.apache.usergrid.services.notifiers;
 
-import org.apache.usergrid.persistence.DynamicEntity;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.services.*;
@@ -26,7 +26,6 @@ import org.apache.usergrid.services.notifications.ProviderAdapter;
 
 import java.util.Arrays;
 import java.util.Set;
-import java.util.UUID;
 
 public class NotifiersService extends AbstractCollectionService {
 
@@ -59,15 +58,13 @@ public class NotifiersService extends AbstractCollectionService {
 
         ServiceResults results = super.postCollection(context);
 
-        DynamicEntity entity = (DynamicEntity) results.getEntity();
-        Notifier notifier1 = new Notifier();
-        notifier1.setProperties(entity.getProperties());
-        if (entity != null) {
+        Notifier notifier =(Notifier) results.getEntity();
+        if (notifier != null) {
             try {
-                ns.testConnection(notifier1);
+                ns.testConnection(notifier);
             } catch (Exception e) {
                 logger.info("notifier testConnection() failed", e);
-                em.delete(entity);
+                em.delete(notifier);
                 throw e;
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
index 265475a..d3d0727 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
@@ -1,6 +1,8 @@
 package org.apache.usergrid.notifications;
 
 import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.persistence.index.query.Query;
 import org.apache.usergrid.services.notifications.NotificationsService;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
index 3502022..d780150 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
@@ -1,7 +1,7 @@
 package org.apache.usergrid.notifications.apns;
 
-import org.apache.usergrid.persistence.Notification;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.apache.usergrid.services.notifications.apns.APNsNotification;
 import org.apache.usergrid.services.notifications.apns.APNsAdapter;
 import org.apache.usergrid.services.notifications.ConnectionException;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
index 40b1098..a50d942 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
@@ -20,7 +20,9 @@ import com.relayrides.pushy.apns.util.*;
 import org.apache.commons.io.IOUtils;
 import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
 import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.*;
 import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.services.notifications.*;
 import org.apache.usergrid.services.notifications.apns.APNsAdapter;
 import org.apache.usergrid.services.notifications.apns.APNsNotification;
@@ -39,9 +41,6 @@ import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
-import org.apache.usergrid.persistence.entities.Device;
-import org.apache.usergrid.persistence.entities.Group;
-import org.apache.usergrid.persistence.entities.User;
 import org.apache.usergrid.services.ServiceAction;
 
 import static org.junit.Assert.assertEquals;
@@ -91,8 +90,7 @@ public class NotificationsServiceTest extends AbstractServiceNotificationTest {
         app.put("p12Certificate", certBytes);
         fis.close();
 
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
         notifier = app.getEm().get(e.getUuid(), Notifier.class);
         final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
 
@@ -114,19 +112,19 @@ public class NotificationsServiceTest extends AbstractServiceNotificationTest {
         e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
         device2 = app.getEm().get(e.getUuid(), Device.class);
 
-        // create User
-        user1 = new User();
-        user1.setUsername("user1");
-        user1.setEmail("user1@usergrid.org");
-        user1 = app.getEm().create(user1);
-        app.getEm().createConnection(user1, "devices", device1);
-        app.getEm().createConnection(user1, "devices", device2);
-
-        // create Group
-        group1 = new Group();
-        group1.setPath("path");
-        group1 = app.getEm().create(group1);
-        app.getEm().createConnection(group1, "users", user1);
+//        // create User
+//        user1 = new User();
+//        user1.setUsername("user1");
+//        user1.setEmail("user1@usergrid.org");
+//        user1 = app.getEm().create(user1);
+//        app.getEm().createConnection(user1, "devices", device1);
+//        app.getEm().createConnection(user1, "devices", device2);
+//
+//        // create Group
+//        group1 = new Group();
+//        group1.setPath("path");
+//        group1 = app.getEm().create(group1);
+//        app.getEm().createConnection(group1, "users", user1);
 
         ns = getNotificationService();
     }
@@ -161,13 +159,13 @@ public class NotificationsServiceTest extends AbstractServiceNotificationTest {
 
         ns.addDevice(notification, device1);
 
-        // verify Query for CREATED state
+//        // verify Query for CREATED state
         Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+//        query.addEqualityFilter("state", Notification.State.STARTED.toString());
         Results results = app.getEm().searchCollection(
                 app.getEm().getApplicationRef(), "notifications", query);
         Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
+//        assertNotNull(entity);
 
         // perform push //
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
index b834d8a..12dbe08 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
@@ -1,6 +1,7 @@
 package org.apache.usergrid.notifications.gcm;
 
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.apache.usergrid.services.notifications.ConnectionException;
 import org.apache.usergrid.services.notifications.NotificationsService;
 import org.apache.usergrid.services.notifications.ProviderAdapter;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
index e21492b..ad64fd5 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
@@ -16,7 +16,9 @@
 package org.apache.usergrid.notifications.gcm;
 
 import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.services.notifications.NotificationsService;
 import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
 import org.junit.Before;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/51e09317/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
index cb4c5a6..ff97578 100644
--- a/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
@@ -2,7 +2,7 @@ package org.apache.usergrid.notifiers;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.usergrid.notifications.apns.MockSuccessfulProviderAdapter;
-import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.entities.Notifier;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;


[22/33] git commit: Removed the pool from the test adapter as it was timing out and causing errors.

Posted by sn...@apache.org.
Removed the pool from the test adapter as it was timing out and causing errors.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/10c8d280
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/10c8d280
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/10c8d280

Branch: refs/heads/two-dot-o
Commit: 10c8d280049b2c8deef683ad33e4113efcb37452
Parents: ddc219c
Author: grey <gr...@apigee.com>
Authored: Fri Aug 22 07:52:18 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Fri Aug 22 07:52:18 2014 -0700

----------------------------------------------------------------------
 .../services/notifications/TestAdapter.java     | 30 ++++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10c8d280/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
index 1f996a9..2f28364 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
@@ -64,23 +64,23 @@ public class TestAdapter implements ProviderAdapter {
         final APNsNotification apnsNotification = APNsNotification.create(
                 "", payload.toString(), notification, tracker);
 
-        if (pool == null) {
+       // if (pool == null) {
             apnsNotification.messageSent();
 
-        } else {
-            pool.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.sleep(DELAY);
-                        apnsNotification.messageSent();
-                        log.debug("messageSent() - " + payload.toString());
-                    } catch (Exception e) {
-                        log.error("messageSent() returned error", e);
-                    }
-                }
-            });
-        }
+//        } else {
+//            pool.submit(new Runnable() {
+//                @Override
+//                public void run() {
+//                    try {
+//                        Thread.sleep(DELAY);
+//                        apnsNotification.messageSent();
+//                        log.debug("messageSent() - " + payload.toString());
+//                    } catch (Exception e) {
+//                        log.error("messageSent() returned error", e);
+//                    }
+//                }
+//            });
+//        }
     }
 
     @Override


[09/33] git commit: tests added, somewhat working

Posted by sn...@apache.org.
tests added, somewhat working


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

Branch: refs/heads/two-dot-o
Commit: cb0e4b59139c2fd4edfefc51baf5b4527b547c50
Parents: 2a411bf
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 17:49:03 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 17:49:03 2014 -0600

----------------------------------------------------------------------
 stack/services/pom.xml                          |   1 +
 .../services/notifiers/NotifiersService.java    |  12 +-
 .../AbstractServiceNotificationTest.java        | 106 +++
 .../apns/MockSuccessfulProviderAdapter.java     | 101 +++
 .../apns/NotificationsServiceTest.java          | 872 +++++++++++++++++++
 .../gcm/MockSuccessfulProviderAdapter.java      |  71 ++
 .../gcm/NotificationsServiceTest.java           | 545 ++++++++++++
 .../notifiers/NotifiersServiceTest.java         | 224 +++++
 .../src/test/resources/pushtest_dev.p12         | Bin 0 -> 3203 bytes
 .../src/test/resources/pushtest_dev_recent.p12  | Bin 0 -> 3227 bytes
 .../src/test/resources/pushtest_prod.p12        | Bin 0 -> 3205 bytes
 .../resources/usergrid-custom-test.properties   |   6 +
 12 files changed, 1934 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/pom.xml
----------------------------------------------------------------------
diff --git a/stack/services/pom.xml b/stack/services/pom.xml
index ace3c8d..ef5ed5c 100644
--- a/stack/services/pom.xml
+++ b/stack/services/pom.xml
@@ -253,6 +253,7 @@
           <include>**/*.yaml</include>
           <include>**/*.xml</include>
           <include>**/*.properties</include>
+          <include>**/*.p12</include>
         </includes>
       </testResource>
       <testResource>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
index 8d7964d..f923e2e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
@@ -16,6 +16,7 @@
  */
 package org.apache.usergrid.services.notifiers;
 
+import org.apache.usergrid.persistence.DynamicEntity;
 import org.apache.usergrid.persistence.Notifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -25,6 +26,7 @@ import org.apache.usergrid.services.notifications.ProviderAdapter;
 
 import java.util.Arrays;
 import java.util.Set;
+import java.util.UUID;
 
 public class NotifiersService extends AbstractCollectionService {
 
@@ -57,13 +59,15 @@ public class NotifiersService extends AbstractCollectionService {
 
         ServiceResults results = super.postCollection(context);
 
-        Notifier notifier = (Notifier) results.getEntity();
-        if (notifier != null) {
+        DynamicEntity entity = (DynamicEntity) results.getEntity();
+        Notifier notifier1 = new Notifier();
+        notifier1.setProperties(entity.getProperties());
+        if (entity != null) {
             try {
-                ns.testConnection(notifier);
+                ns.testConnection(notifier1);
             } catch (Exception e) {
                 logger.info("notifier testConnection() failed", e);
-                em.delete(notifier);
+                em.delete(entity);
                 throw e;
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
new file mode 100644
index 0000000..265475a
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
@@ -0,0 +1,106 @@
+package org.apache.usergrid.notifications;
+
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.usergrid.services.AbstractServiceIT;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class AbstractServiceNotificationTest extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Rule
+    public TestName name = new TestName();
+
+    @BeforeClass
+    public static void beforeClass() {
+    }
+
+    @Before
+    public void before() throws Exception {
+
+    }
+
+    protected NotificationsService getNotificationService(){
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        return ns;
+    }
+
+    protected Notification scheduleNotificationAndWait(Notification notification)
+            throws Exception {
+        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            notification = app.getEm().get(notification.getUuid(),
+                    Notification.class);
+            if (notification.getFinished() != null) {
+                return notification;
+            }
+        }
+        fail("Notification failed to complete");
+        return null;
+    }
+
+    protected List<EntityRef> getNotificationReceipts(EntityRef notification)
+            throws Exception {
+        Results r = app.getEm().getCollection(notification,
+                Notification.RECEIPTS_COLLECTION, null, 1000000,
+                Query.Level.REFS, false);
+        List<EntityRef> list =new ArrayList<EntityRef>();//get all
+        PagingResultsIterator it = new PagingResultsIterator(r);
+        while(it.hasNext()){
+           list.add((EntityRef)it.next());
+        }
+        return list;
+    }
+
+    protected void checkReceipts(Notification notification, int expected)
+            throws Exception {
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            receipts =getNotificationReceipts(notification);
+            if (receipts.size()==expected) {
+                 break;
+            }
+        }
+        assertEquals(expected, receipts.size());
+        for (EntityRef receipt : receipts) {
+            Receipt r = app.getEm().get(receipt, Receipt.class);
+            assertNotNull(r.getSent());
+            assertNotNull(r.getPayload());
+            assertNotNull(r.getNotifierId());
+            EntityRef source = getNotificationService().getSourceNotification(r);
+            assertEquals(source.getUuid(), notification.getUuid());
+        }
+    }
+
+    protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
+        Map<String, Long> statistics = null;
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
+            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
+                break;
+            }
+        }
+        assertEquals(sent, statistics.get("sent").longValue());
+        assertEquals(errors, statistics.get("errors").longValue());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
new file mode 100644
index 0000000..3502022
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
@@ -0,0 +1,101 @@
+package org.apache.usergrid.notifications.apns;
+
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.services.notifications.apns.APNsNotification;
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.ServicePayload;
+
+public class MockSuccessfulProviderAdapter implements ProviderAdapter {
+
+    private static ProviderAdapter realProviderAdapter;
+
+    public static void install(NotificationsService ns) {
+        install(ns, false);
+    }
+
+    public static void install(NotificationsService ns, boolean doAsync) {
+        if (realProviderAdapter != null)
+            realProviderAdapter = ns.providerAdapters.get("apple");
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter(
+                doAsync));
+    }
+
+    public static void uninstall(NotificationsService ns) {
+        if (realProviderAdapter != null) {
+            ns.providerAdapters.put("apple", realProviderAdapter);
+        }
+    }
+
+    private ExecutorService pool;
+
+    public MockSuccessfulProviderAdapter() {
+    }
+
+    public MockSuccessfulProviderAdapter(boolean async) {
+        if (async) {
+            pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+        }
+    }
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+    }
+
+    @Override
+    public String translatePayload(Object payload) throws Exception {
+        return payload.toString();
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        return null;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+    }
+
+    @Override
+    public void sendNotification(final String providerId,
+            final Notifier notifier, final Object payload,
+            final Notification notification, final TaskTracker tracker)
+            throws Exception {
+
+        final APNsNotification apnsNotification = APNsNotification.create(
+                providerId, payload.toString(), notification, tracker);
+
+        if (pool == null) {
+            apnsNotification.messageSent();
+        } else {
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        Thread.sleep(new Random().nextInt(100));
+                        apnsNotification.messageSent();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
new file mode 100644
index 0000000..40b1098
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
@@ -0,0 +1,872 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.notifications.apns;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.*;
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.*;
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.apns.APNsNotification;
+import org.junit.After;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.persistence.entities.Group;
+import org.apache.usergrid.persistence.entities.User;
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+// todo: test reschedule on delivery time change
+// todo: test restart of queuing
+public class NotificationsServiceTest extends AbstractServiceNotificationTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsServiceTest.class);
+
+    /**
+     * set to true to run tests against actual Apple servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "apple" : "noop";
+
+    private static final String PUSH_TOKEN = "29026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private Group group1;
+    private User user1;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+        // create apns notifier //
+        NotificationsQueueManager.IS_TEST = true;
+
+        app.clear();
+        app.put("name", "apns");
+        app.put("provider",PROVIDER);
+        app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device1");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device2");
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+
+        // create User
+        user1 = new User();
+        user1.setUsername("user1");
+        user1.setEmail("user1@usergrid.org");
+        user1 = app.getEm().create(user1);
+        app.getEm().createConnection(user1, "devices", device1);
+        app.getEm().createConnection(user1, "devices", device2);
+
+        // create Group
+        group1 = new Group();
+        group1.setPath("path");
+        group1 = app.getEm().create(group1);
+        app.getEm().createConnection(group1, "users", user1);
+
+        ns = getNotificationService();
+    }
+
+    @After
+    public void after() throws Exception {
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // verify Query for CREATED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        // perform push //
+
+        notification = scheduleNotificationAndWait(notification);
+
+        // verify Query for FINISHED state
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        checkReceipts(notification, 1);
+        checkStatistics(notification, 1, 0);
+    }
+
+    @Test
+    public void pushWithNoValidDevicesShouldComplete() throws Exception {
+
+        // create unrelated notifier
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", "xxx");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+
+        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = "gcm" + NOTIFIER_ID_POSTFIX;
+
+        // create unrelated device
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        Device device = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device.getProperty(key), PUSH_TOKEN);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("started", System.currentTimeMillis());
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device);
+
+        // verify Query for CREATED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        // perform push //
+
+        ns.getQueueManager().processBatchAndReschedule(notification, null);
+
+        // verify Query for FINISHED state
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        notification = (Notification) entity.toTypedEntity();
+        checkReceipts(notification, 0);
+        checkStatistics(notification, 0, 0);
+    }
+
+    @Test
+    public void scheduledNotification() throws Exception {
+
+        // create push notification //
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("deliver", System.currentTimeMillis() + 240000);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // delay until the scheduler has time to run
+        Thread.sleep(500);
+
+        // verify Query for SCHEDULED state
+        Query query = new Query();
+        query.addEqualityFilter("state",
+                Notification.State.SCHEDULED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        try {
+            e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
+                    e.getUuid()).getEntity();
+        }catch (Exception deleteException){
+            LOG.error("Couldn't delete",deleteException);
+        }
+        app.getEm().get(e.getUuid(), Notification.class);
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 255) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals(ex.getMessage(),
+                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            APNsNotification apnsNotification = APNsNotification
+                                    .create(providerId, payload.toString(),
+                                            notification, tracker);
+                            apnsNotification.messageSent();
+                            apnsNotification
+                                    .messageSendFailed( RejectedNotificationReason.INVALID_TOKEN);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkStatistics(notification, 0, 1);
+
+        notification = (Notification) app.getEm().get(notification)
+                .toTypedEntity();
+        checkReceipts(notification, 1);
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
+    }
+
+    @Test
+    public void twoDevicesOneNotifier() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Test
+    public void twoDevicesTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), "apns2");
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), "development");
+
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device2.setProperty(key, null);
+        device2.setProperty(key2, null);
+        app.getEm().update(device2);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
+    }
+
+    @Test
+    public void oneDeviceTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        Object nameValue = "apns2";
+        Object environValue = "development";
+
+        app.clear();
+        app.put("name", nameValue);
+        app.put("provider", PROVIDER);
+        app.put("environment", environValue);
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), nameValue);
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), environValue);
+
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device1.setProperty(key2, PUSH_TOKEN);
+        app.getEm().update(device1);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badCertificate() throws Exception {
+
+        // create an apns notifier with the wrong certificate //
+
+        app.clear();
+        app.put("name", "prod_apns");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "empty.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+
+        // mock error (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void testConnection(Notifier notifier)
+                                throws ConnectionException {
+                            Exception e = new SocketException(
+                                    "Connection closed by remote host");
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification,null);
+            fail("testConnection() should have failed");
+        } catch (Exception ex) {
+            // good, there should be an error
+        }
+
+        // verify Query for FAILED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.FAILED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void inactiveDeviceUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public Map<String, Date> getInactiveDevices(
+                                Notifier notifier, EntityManager em)
+                                throws Exception {
+                            return Collections.singletonMap(PUSH_TOKEN,
+                                    new Date());
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        assertNotNull(device1.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+        assertNotNull(device2.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        // check provider IDs //
+
+        device1 = app.getEm().get(device1, Device.class);
+        assertNull(device1
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+        device2 = app.getEm().get(device2, Device.class);
+        assertNull(device2
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void batchTest() throws Exception {
+
+        final int NUM_DEVICES = 50;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        final Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        // perform push //
+        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
+        NotificationsQueueManager.BATCH_SIZE = 10;
+        try {
+            ExecutorService pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                        try {
+                             scheduleNotificationAndWait(notification);
+                        }catch (Exception e){}
+                }});
+        } finally {
+            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
+        }
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        MockSuccessfulProviderAdapter.install(ns, true);
+
+        final int NUM_DEVICES = 10000;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    private String getPayload(){
+        ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
+        builder.setAlertBody("Hello, World!");
+        builder.setSoundFileName("chime");
+        String payload = builder.buildWithDefaultMaximumLength();
+        return payload;
+    }
+    // todo: can't do the following tests here. do it in the REST tier...
+    // private Notification postNotification(String path) throws Exception {
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // path).getEntity();
+    // Thread.sleep(1000); // this sucks
+    // Notification notification = app.getEm().get(e, Notification.class);
+    // return notification;
+    // }
+    //
+    // @Test
+    // public void matrixPushDevice() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaUser() throws Exception {
+    //
+    // Notification notification = postNotification("users/" + user1.getName() +
+    // "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaGroup() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushDeviceQuery() throws Exception {
+    //
+    // Notification notification = postNotification("devices;ql=name=" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushUserQuery() throws Exception {
+    //
+    // Notification notification = postNotification("users;ql=/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
new file mode 100644
index 0000000..b834d8a
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
@@ -0,0 +1,71 @@
+package org.apache.usergrid.notifications.gcm;
+
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.util.Date;
+import java.util.Map;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.ServicePayload;
+
+public class MockSuccessfulProviderAdapter implements ProviderAdapter {
+
+    private static ProviderAdapter realProviderAdapter;
+
+    public static void install(NotificationsService ns) {
+        if (realProviderAdapter != null)
+            realProviderAdapter = ns.providerAdapters.get("google");
+        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter());
+    }
+
+    public static void uninstall(NotificationsService ns) {
+        if (realProviderAdapter != null) {
+            ns.providerAdapters.put("google", realProviderAdapter);
+        }
+    }
+
+    public MockSuccessfulProviderAdapter() {
+    }
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+    }
+
+    @Override
+    public String translatePayload(Object payload) throws Exception {
+        return payload.toString();
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        return null;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+    }
+
+    @Override
+    public void sendNotification(String providerId, Notifier notifier,
+            Object payload, Notification notification, final TaskTracker tracker)
+            throws Exception {
+        new Thread() {
+            @Override
+            public void run() {
+                try {
+                    tracker.completed();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }.start();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
new file mode 100644
index 0000000..e21492b
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
@@ -0,0 +1,545 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.notifications.gcm;
+
+import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.*;
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+public class NotificationsServiceTest extends AbstractServiceNotificationTest {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(NotificationsServiceTest.class);
+
+    /**
+     * set to true to run tests against actual GCM servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "google"
+            : "noop";
+
+    private static final String API_KEY = "AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM";
+    private static final String PUSH_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+
+        // create gcm notifier //
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+
+        notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(key), PUSH_TOKEN);
+
+        app.put(key, PUSH_TOKEN);
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+        ns = getNotificationService();
+    }
+
+    @Test
+    public void emptyPushNotification() throws Exception {
+
+        app.clear();
+        app.put("name", "foo");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Notifier n = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put("foo", payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 0);
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void singlePushNotificationViaUser() throws Exception {
+
+        app.clear();
+
+        app.put("username", "asdf");
+        app.put("email", "asdf@adsf.com");
+        Entity user = app.testRequest(ServiceAction.POST, 1, "users")
+                .getEntity();
+        assertNotNull(user);
+        Entity device = app.testRequest(ServiceAction.POST, 1, "users",
+                user.getUuid(), "devices", device1.getUuid()).getEntity();
+        assertEquals(device.getUuid(), device1.getUuid());
+
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void twoBatchNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device2);
+        ns.addDevice(notification, device1);
+
+        // reduce Batch size to 1
+        Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
+        field.setAccessible(true);
+        int multicastSize = field.getInt(GCMAdapter.class);
+        try {
+            field.setInt(GCMAdapter.class, 1);
+
+            // perform push //
+            notification = scheduleNotificationAndWait(notification);
+
+            checkReceipts(notification, 2);
+        } finally {
+            field.setInt(GCMAdapter.class, multicastSize);
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void providerIdUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        final String newProviderId = "newProviderId";
+        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void sendNotification(String providerId, Notifier notifier,
+                    Object payload, Notification notification,
+                    TaskTracker tracker) throws Exception {
+                tracker.completed(newProviderId);
+            }
+        });
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+
+        Device device = (Device) app.getEm().get(device1).toTypedEntity();
+        assertEquals(newProviderId,
+                device.getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "gcm2");
+        app.put("provider", "google");
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 4080) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals("java.lang.IllegalArgumentException: GCM payloads must be 4096 characters or less",
+                    ex.getMessage());
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            tracker.failed("InvalidRegistration",
+                                    "InvalidRegistration");
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // device w/ bad token
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        assertEquals(1, receipts.size());
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals("InvalidRegistration", receipt.getErrorCode());
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badAPIKey() throws Exception {
+
+        if (!USE_REAL_CONNECTIONS) {
+            // mock action (based on verified actual behavior) //
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            Exception e = new IOException();
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // save bad API key
+        app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification, null);
+            fail("Should have received a ConnectionException");
+        } catch (ConnectionException ex) {
+            // good
+        }
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        final int NUM_DEVICES = 10000;
+
+        // create notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // create a bunch of devices and add them to the notification
+        properties = new LinkedHashMap<String, Object>();
+        properties.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", properties);
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    // @Test
+    // public void inactiveDeviceUpdate() throws Exception {
+    //
+    // if (!USE_REAL_CONNECTIONS) {
+    // // mock action (based on verified actual behavior) //
+    // NotificationsService.providerAdapters.put("apple", new
+    // MockSuccessfulProviderAdapter() {
+    // public Map<String,Date> getInactiveDevices(Notifier notifier,
+    // EntityManager em) throws Exception {
+    // return Collections.singletonMap(PUSH_TOKEN, new Date());
+    // }
+    // });
+    // }
+    //
+    // // create push notification //
+    //
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    // properties.put("queued", System.currentTimeMillis());
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // "notifications").getEntity();
+    // testRequest(sm, ServiceAction.GET, 1, null, "notifications",
+    // e.getUuid());
+    //
+    // Notification notification = em.get(e.getUuid(), Notification.class);
+    // assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),
+    // payload);
+    //
+    // ns.addDevice(notification, device1);
+    // ns.addDevice(notification, device2);
+    //
+    // assertNotNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // assertNotNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    //
+    // // perform push //
+    // notification = scheduleNotificationAndWait(notification);
+    //
+    // // check provider IDs //
+    //
+    // device1 = em.get(device1, Device.class);
+    // assertNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // device2 = em.get(device2, Device.class);
+    // assertNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
new file mode 100644
index 0000000..cb4c5a6
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
@@ -0,0 +1,224 @@
+package org.apache.usergrid.notifiers;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.notifications.apns.MockSuccessfulProviderAdapter;
+import org.apache.usergrid.persistence.Notifier;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.SocketException;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.services.AbstractServiceIT;
+import org.apache.usergrid.services.ServiceAction;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertArrayEquals;
+
+import static org.junit.Assert.fail;
+
+public class NotifiersServiceTest extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Before
+    public void before() throws Exception {
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        MockSuccessfulProviderAdapter.install(ns);
+    }
+
+    @Test
+    public void badProvider() throws Exception {
+
+        app.clear();
+        app.put("provider", "xxx");
+        app.put("environment", "production");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad provider");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badGcmToken() throws Exception {
+        app.clear();
+        app.put("provider", "google");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with missing apiKey");
+        } catch (RequiredPropertyNotFoundException e) {
+            // ok
+        }
+
+        // mock action (based on verified actual behavior) //
+        ns.providerAdapters
+                .put("google",
+                        new org.apache.usergrid.notifications.gcm.MockSuccessfulProviderAdapter() {
+                            @Override
+                            public void testConnection(Notifier notifier)
+                                    throws ConnectionException {
+                                throw new ConnectionException("", null);
+                            }
+                        });
+
+        app.put("apiKey", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with bad connection");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void badAPNsEnvironment() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad environment");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void goodAPNsCreation() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, false,
+                        new Object[] { "notifiers" }).getEntity()
+                .toTypedEntity();
+
+        assertEquals(app.get("provider"), notifier.getProvider());
+        assertEquals(app.get("environment"), notifier.getEnvironment());
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsCertificate() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new SocketException(
+                        "Connection closed by remote host");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_prod.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsPassword() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new Exception("invalid ssl config");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        app.put("certificatePassword", "wrong");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void encryption() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Field f = Schema.class.getDeclaredField("encryptionSeed");
+        f.setAccessible(true);
+        byte[] originalSeed = (byte[]) f.get(Schema.class);
+        byte[] encryptionSeed = "This is a new seed.".getBytes();
+        f.set(Schema.class, encryptionSeed);
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+
+        f.set(Schema.class, originalSeed);
+
+        try {
+            app.getEm().get(notifier.getUuid());
+            fail("Should have failed to retrieve the encrypted entity.");
+        } catch (IllegalStateException e) {
+            // ok! This should happen.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/resources/pushtest_dev.p12
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/pushtest_dev.p12 b/stack/services/src/test/resources/pushtest_dev.p12
new file mode 100644
index 0000000..b4373a2
Binary files /dev/null and b/stack/services/src/test/resources/pushtest_dev.p12 differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/resources/pushtest_dev_recent.p12
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/pushtest_dev_recent.p12 b/stack/services/src/test/resources/pushtest_dev_recent.p12
new file mode 100644
index 0000000..80941c5
Binary files /dev/null and b/stack/services/src/test/resources/pushtest_dev_recent.p12 differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/resources/pushtest_prod.p12
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/pushtest_prod.p12 b/stack/services/src/test/resources/pushtest_prod.p12
new file mode 100644
index 0000000..e6d4690
Binary files /dev/null and b/stack/services/src/test/resources/pushtest_prod.p12 differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb0e4b59/stack/services/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/usergrid-custom-test.properties b/stack/services/src/test/resources/usergrid-custom-test.properties
index 7f141f8..94b8adf 100644
--- a/stack/services/src/test/resources/usergrid-custom-test.properties
+++ b/stack/services/src/test/resources/usergrid-custom-test.properties
@@ -20,3 +20,9 @@ cassandra.timeout=5000
 cassandra.connections=1000
 hystrix.threadpool.graph_user.coreSize=100
 hystrix.threadpool.graph_async.coreSize=100
+
+#Poll interval to check for new jobs in millseconds. 10 milliseconds for testing
+usergrid.scheduler.job.interval=100
+
+# number of delivery queue processes expected
+notification.concurrent.batches=2


[08/33] git commit: adding rest resources

Posted by sn...@apache.org.
adding rest resources


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2a411bfc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2a411bfc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2a411bfc

Branch: refs/heads/two-dot-o
Commit: 2a411bfc78391c470cfe7ceb84488aa15429ead4
Parents: 9d7901a
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 15:06:06 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 15:06:06 2014 -0600

----------------------------------------------------------------------
 .../notifiers/NotifierResource.java             | 103 +++++++++++++
 .../notifiers/NotifiersResource.java            | 153 +++++++++++++++++++
 2 files changed, 256 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2a411bfc/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
new file mode 100644
index 0000000..72883b0
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifierResource.java
@@ -0,0 +1,103 @@
+/*
+ * 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.usergrid.rest.applications.notifiers;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+import com.sun.jersey.multipart.FormDataMultiPart;
+import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.persistence.index.query.Identifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.applications.ServiceResource;
+import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
+import org.apache.usergrid.services.ServiceAction;
+import org.apache.usergrid.services.ServicePayload;
+
+@Component("org.apache.usergrid.rest.applications.notifiers.NotifierResource")
+@Scope("prototype")
+@Produces(MediaType.APPLICATION_JSON)
+public class NotifierResource extends ServiceResource {
+
+    private static final Logger logger = LoggerFactory.getLogger(NotifierResource.class);
+
+    private Identifier identifier;
+
+    public NotifierResource init(Identifier identifier) throws Exception {
+        this.identifier = identifier;
+        return this;
+    }
+
+    /* Multipart PUT update with uploaded p12Certificate */
+    @PUT
+    @RequireApplicationAccess
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Override
+    public JSONWithPadding executeMultiPartPut(@Context UriInfo ui,
+        @QueryParam("callback") @DefaultValue("callback") String callback,
+        FormDataMultiPart multiPart) throws Exception {
+
+        logger.debug("NotifierResource.executePut");
+
+        String name =         getValueOrNull(multiPart, "name"); 
+        String provider =     getValueOrNull(multiPart, "provider"); 
+        String certPassword = getValueOrNull(multiPart, "certificatePassword"); 
+
+        InputStream is = null;
+        if (multiPart.getField("p12Certificate") != null) {
+            is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
+        }
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        properties.put("name", name);
+        properties.put("provider", provider);
+        properties.put("environment", "production");
+        properties.put("certificatePassword", certPassword);
+        if (is != null) {
+            byte[] certBytes = IOUtils.toByteArray(is);
+            properties.put("p12Certificate", certBytes);
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction("put");
+        response.setApplication(services.getApplication());
+        response.setParams(ui.getQueryParameters());
+        ServicePayload payload = getPayload(properties);
+        executeServiceRequest(ui, response, ServiceAction.PUT, payload);
+
+        return new JSONWithPadding(response, callback);
+    }
+
+    private String getValueOrNull(FormDataMultiPart multiPart, String name) {
+        if (multiPart.getField(name) != null) {
+            return multiPart.getField(name).getValue();
+        }
+        return null;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2a411bfc/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
new file mode 100644
index 0000000..cfbbb45
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/notifiers/NotifiersResource.java
@@ -0,0 +1,153 @@
+/*
+ * 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.usergrid.rest.applications.notifiers;
+
+import com.sun.jersey.api.json.JSONWithPadding;
+import com.sun.jersey.multipart.FormDataMultiPart;
+import java.io.InputStream;
+import java.util.HashMap;
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.persistence.index.query.Identifier;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.PathSegment;
+import javax.ws.rs.core.UriInfo;
+import java.util.LinkedHashMap;
+import java.util.UUID;
+
+import org.apache.usergrid.rest.AbstractContextResource;
+import org.apache.usergrid.rest.ApiResponse;
+import org.apache.usergrid.rest.applications.ServiceResource;
+import org.apache.usergrid.rest.security.annotations.RequireApplicationAccess;
+import org.apache.usergrid.services.ServiceAction;
+import org.apache.usergrid.services.ServicePayload;
+
+import static org.apache.usergrid.services.ServiceParameter.addParameter;
+
+@Component("org.apache.usergrid.rest.applications.notifiers.NotifiersResource")
+@Scope("prototype")
+@Produces(MediaType.APPLICATION_JSON)
+public class NotifiersResource extends ServiceResource {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotifiersResource.class);
+
+    @Override
+    @Path("{entityId: [A-Fa-f0-9]{8}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{4}-[A-Fa-f0-9]{12}}")
+    public AbstractContextResource addIdParameter(@Context UriInfo ui,
+            @PathParam("entityId") PathSegment entityId) throws Exception {
+
+        logger.info("NotifiersResource.addIdParameter");
+
+        UUID itemId = UUID.fromString(entityId.getPath());
+
+        addParameter(getServiceParameters(), itemId);
+
+        addMatrixParams(getServiceParameters(), ui, entityId);
+
+        return getSubResource(NotifierResource.class).init(  Identifier.fromUUID(itemId));
+    }
+
+    @Override
+    @Path("{itemName}")
+    public AbstractContextResource addNameParameter(@Context UriInfo ui,
+            @PathParam("itemName") PathSegment itemName) throws Exception {
+
+        logger.info("NotifiersResource.addNameParameter");
+
+        logger.info("Current segment is " + itemName.getPath());
+
+        if (itemName.getPath().startsWith("{")) {
+            Query query = Query.fromJsonString(itemName.getPath());
+            if (query != null) {
+                addParameter(getServiceParameters(), query);
+            }
+            addMatrixParams(getServiceParameters(), ui, itemName);
+
+            return getSubResource(ServiceResource.class);
+        }
+
+        addParameter(getServiceParameters(), itemName.getPath());
+
+        addMatrixParams(getServiceParameters(), ui, itemName);
+        Identifier id = Identifier.from(itemName.getPath());
+        if (id == null) {
+            throw new IllegalArgumentException(
+                    "Not a valid Notifier identifier: " + itemName.getPath());
+        }
+        return getSubResource(NotifierResource.class).init(id);
+    }
+
+    /* Multipart POST create with uploaded p12Certificate */
+    @POST
+    @RequireApplicationAccess
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Override
+    public JSONWithPadding executeMultiPartPost(
+            @Context UriInfo ui,
+            @QueryParam("callback") @DefaultValue("callback") String callback,
+            FormDataMultiPart multiPart)
+            throws Exception {
+
+        logger.debug("ServiceResource.uploadData");
+
+        String name =         getValueOrNull(multiPart, "name"); 
+        String provider =     getValueOrNull(multiPart, "provider"); 
+        String environment =  getValueOrNull(multiPart, "environment"); 
+        String certPassword = getValueOrNull(multiPart, "certificatePassword"); 
+
+        InputStream is = null;
+        if (multiPart.getField("p12Certificate") != null) {
+            is = multiPart.getField("p12Certificate").getEntityAs(InputStream.class);
+        }
+
+
+        HashMap<String, Object> certProps = new LinkedHashMap<String, Object>();
+        certProps.put("name", name);
+        certProps.put("provider", provider);
+        certProps.put("environment", environment);
+        certProps.put("certificatePassword", certPassword);
+        if (is != null) {
+            byte[] certBytes = IOUtils.toByteArray(is);
+            certProps.put("p12Certificate", certBytes);
+        }
+
+        ApiResponse response = createApiResponse();
+        response.setAction("post");
+        response.setApplication(services.getApplication());
+        response.setParams(ui.getQueryParameters());
+        ServicePayload payload = getPayload(certProps);
+        executeServiceRequest(ui, response, ServiceAction.POST, payload);
+
+        return new JSONWithPadding(response, callback);
+    }
+
+    private String getValueOrNull(FormDataMultiPart multiPart, String name) {
+        if (multiPart.getField(name) != null) {
+            return multiPart.getField(name).getValue();
+        }
+        return null;
+    }
+}


[23/33] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications

Posted by sn...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications

# By Dave Johnson (3) and ryan bridges (2)
# Via ryan bridges
* 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid:
  setting the max heap back to 1024m
  POM updates to control test fork behavior.
  Add support for c3.2xlarge to AWS Cluster template.
  Fix  to "reindex on update" logic that allows the ServiceInvocationIT tests to pass.
  Make sure Tomcat gets the ulimit.

Conflicts:
	stack/pom.xml


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/8a209362
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/8a209362
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/8a209362

Branch: refs/heads/two-dot-o
Commit: 8a20936275587ad861a68db78011391c30ab2735
Parents: 10c8d28 981f4af
Author: grey <gr...@apigee.com>
Authored: Mon Aug 25 16:38:11 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Mon Aug 25 16:38:11 2014 -0700

----------------------------------------------------------------------
 .../main/dist/init_instance/init_rest_server.sh |   6 +-
 stack/awscluster/ugcluster-cf.json              |  10 +-
 stack/core/pom.xml                              |  14 ++-
 .../corepersistence/CpEntityManager.java        |  63 ++---------
 .../corepersistence/CpRelationManager.java      | 108 ++++++++++++++++---
 stack/pom.xml                                   |   8 ++
 stack/rest/pom.xml                              |  11 +-
 stack/services/pom.xml                          |  28 +++--
 .../usergrid/services/ServiceInvocationIT.java  |  49 ++++-----
 .../usergrid/cassandra/CassandraMain.java       |   2 +-
 .../usergrid/cassandra/CassandraResource.java   |   4 +-
 11 files changed, 179 insertions(+), 124 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8a209362/stack/core/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8a209362/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8a209362/stack/pom.xml
----------------------------------------------------------------------
diff --cc stack/pom.xml
index 600217c,0ff39ae..c212920
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@@ -115,7 -115,11 +115,11 @@@
      <antlr.version>3.4</antlr.version>
      <tika.version>1.4</tika.version>
      <elasticsearch.version>1.2.3</elasticsearch.version>
 -
 +    <metrics.version>3.0.0</metrics.version>
+     <usergrid.it.forkCount>3</usergrid.it.forkCount>
+     <usergrid.it.reuseForks>false</usergrid.it.reuseForks>
+     <usergrid.it.parallel>suites</usergrid.it.parallel>
+ 
    </properties>
  
    <licenses>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/8a209362/stack/services/pom.xml
----------------------------------------------------------------------


[31/33] git commit: Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-single-queue

Posted by sn...@apache.org.
Merge branch 'two-dot-o' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-single-queue


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

Branch: refs/heads/two-dot-o
Commit: af4aa4074d6c876f00508c0083a45770ad98e754
Parents: 84d0d50 a1684d0
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Sep 4 11:43:31 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Sep 4 11:43:31 2014 -0600

----------------------------------------------------------------------
 portal/dist/usergrid-portal.zip | Bin 15544780 -> 0 bytes
 stack/awscluster/assembly.xml   |   4 +---
 stack/core/pom.xml              |   2 ++
 stack/rest/pom.xml              |   2 ++
 stack/services/pom.xml          |   2 ++
 5 files changed, 7 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/af4aa407/stack/core/pom.xml
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/af4aa407/stack/services/pom.xml
----------------------------------------------------------------------


[21/33] git commit: abstract queue messages

Posted by sn...@apache.org.
abstract queue messages


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/06db9e79
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/06db9e79
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/06db9e79

Branch: refs/heads/two-dot-o
Commit: 06db9e798df420e05760d3e3c7083915b9377e04
Parents: ddc219c
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 21 12:46:50 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 21 12:46:50 2014 -0600

----------------------------------------------------------------------
 .../NotificationsQueueManager.java              |  6 +--
 .../services/notifications/QueueMessage.java    | 43 ++++++++++++++++++++
 2 files changed, 45 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/06db9e79/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
index f36a3de..23e3e62 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
@@ -74,7 +74,6 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
     private final InflectionUtils utils;
     private AtomicLong consecutiveEmptyQueues = new AtomicLong();
     private Long pushAutoExpireAfter = null;
-    static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
 
     public final Map<String, ProviderAdapter> providerAdapters =   new HashMap<String, ProviderAdapter>(3);
     {
@@ -173,8 +172,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
                                         sketch.add(hash,1);
                                     }
                                     maySchedule |= deviceCount.incrementAndGet() % BATCH_SIZE == 0;
-                                    Message message = new Message();
-                                    message.setProperty(MESSAGE_PROPERTY_DEVICE_UUID, deviceRef.getUuid());
+                                    QueueMessage message = new QueueMessage(deviceRef);
                                     qm.postToQueue(queueName, message);
                                     if(notification.getQueued() == null){
                                         // update queued time
@@ -329,7 +327,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
                             return messageObservable.map(new Func1<Message, Message>() {
                                 @Override
                                 public Message call(Message message) {
-                                    UUID deviceUUID = (UUID) message.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID);
+                                    UUID deviceUUID =QueueMessage.generate(message).getUuid();
                                     boolean foundNotifier = false;
                                     for (Map.Entry<String, Object> entry : payloads.entrySet()) {
                                         try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/06db9e79/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueMessage.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueMessage.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueMessage.java
new file mode 100644
index 0000000..065d6a3
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueMessage.java
@@ -0,0 +1,43 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.mq.Message;
+import org.apache.usergrid.persistence.EntityRef;
+
+import java.util.UUID;
+
+public class QueueMessage extends Message {
+
+    static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
+
+    public QueueMessage() {
+    }
+
+    public QueueMessage(UUID deviceId){
+        this.setProperty(MESSAGE_PROPERTY_DEVICE_UUID,deviceId);
+    }
+
+    public QueueMessage(EntityRef deviceRef){
+        this.setProperty(MESSAGE_PROPERTY_DEVICE_UUID,deviceRef.getUuid());
+    }
+
+    public static QueueMessage generate(Message message){
+        return new QueueMessage((UUID) message.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID));
+    }
+
+}


[06/33] adding notificationsservice

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
new file mode 100644
index 0000000..554074e
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
@@ -0,0 +1,127 @@
+/*
+ * 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.usergrid.services.notifications;
+
+
+import java.util.UUID;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.usergrid.persistence.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import org.apache.usergrid.batch.JobExecution;
+import org.apache.usergrid.batch.job.OnlyOnceJob;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.entities.JobData;
+import org.apache.usergrid.services.ServiceManager;
+import org.apache.usergrid.services.ServiceManagerFactory;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+
+
+@Component( "queueJob" )
+public class QueueJob extends OnlyOnceJob {
+
+    private static final Logger logger = LoggerFactory.getLogger( QueueJob.class );
+
+    @Autowired
+    private MetricsFactory metricsService;
+
+    @Autowired
+    private ServiceManagerFactory smf;
+
+    @Autowired
+    private EntityManagerFactory emf;
+    private Histogram histogram;
+    private Meter requests;
+    private Timer execution;
+
+
+    public QueueJob() {
+        logger.info( "QueueJob created: " + this );
+    }
+
+
+    @PostConstruct
+    void init() {
+        histogram = metricsService.getHistogram( QueueJob.class, "cycle" );
+        requests = metricsService.getMeter( QueueJob.class, "requests" );
+        execution = metricsService.getTimer( QueueJob.class, "execution" );
+    }
+
+
+    @Override
+    public void doJob( JobExecution jobExecution ) throws Exception {
+        Timer.Context timer = execution.time();
+        requests.mark();
+        logger.info( "execute QueueJob {}", jobExecution );
+
+        JobData jobData = jobExecution.getJobData();
+        UUID applicationId = ( UUID ) jobData.getProperty( "applicationId" );
+        ServiceManager sm = smf.getServiceManager( applicationId );
+        NotificationsService notificationsService = ( NotificationsService ) sm.getService( "notifications" );
+
+        EntityManager em = emf.getEntityManager( applicationId );
+
+        try {
+            if ( em == null ) {
+                logger.info( "no EntityManager for applicationId  {}", applicationId );
+                return;
+            }
+            UUID notificationId = ( UUID ) jobData.getProperty( "notificationId" );
+            Notification notification = em.get( notificationId, Notification.class );
+            if ( notification == null ) {
+                logger.info( "notificationId {} no longer exists", notificationId );
+                return;
+            }
+
+            try {
+                notificationsService.getQueueManager().queueNotification( notification, jobExecution );
+            }
+            catch ( Exception e ) {
+                logger.error( "execute QueueJob failed", e );
+                em.setProperty( notification, "errorMessage", e.getMessage() );
+                throw e;
+            }
+            finally {
+                long diff = System.currentTimeMillis() - notification.getCreated();
+                histogram.update( diff );
+            }
+        }
+        finally {
+            timer.stop();
+        }
+
+        logger.info( "execute QueueJob completed normally" );
+    }
+
+
+    @Override
+    protected long getDelay( JobExecution execution ) throws Exception {
+        return TaskManager.BATCH_DEATH_PERIOD;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
new file mode 100644
index 0000000..e6c876c
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -0,0 +1,196 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import java.util.*;
+
+import org.apache.usergrid.persistence.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.usergrid.mq.Message;
+import org.apache.usergrid.mq.QueueManager;
+import org.apache.usergrid.mq.QueueResults;
+import org.apache.usergrid.persistence.entities.Device;
+
+/**
+ * When all Tasks are "complete", this calls notifyAll(). Note: This may not
+ * mean that all work is done, however, as delivery errors may come in after a
+ * notification is "sent."
+ */
+public class TaskManager {
+
+    // period to poll for batch completion (keep well under Job scheduler
+    // heartbeat value!)
+    private static final long BATCH_POLL_PERIOD = 60 * 1000;
+    // period to tell job scheduler to wait between heartbeats before timing out
+    // this transaction
+    public static final long SCHEDULER_HEARTBEAT_PERIOD = 5 * 60 * 1000;
+    // period at which the batch is considered dead without activity (10
+    // minutes)
+    // setting it high means that a batch that is dead will hang for longer
+    // but setting it too low may cause duplicates to be sent.
+    // also used for Delay before another Job will be attempted - thus total
+    // time
+    // before a job might be restarted could be as long as 2 x
+    // BATCH_DEATH_PERIOD
+    static final long BATCH_DEATH_PERIOD = 10 * 60 * 1000;
+    public static final long MESSAGE_TRANSACTION_TIMEOUT = SCHEDULER_HEARTBEAT_PERIOD;
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(TaskManager.class);
+    private final String path;
+
+    private Notification notification;
+    private  ConcurrentHashMap<UUID,Message> remaining;
+    private AtomicLong successes = new AtomicLong();
+    private AtomicLong failures = new AtomicLong();
+    private AtomicLong skips = new AtomicLong();
+    private QueueManager qm;
+    private EntityManager em;
+    private NotificationServiceProxy ns;
+
+    public TaskManager(  EntityManager em, NotificationServiceProxy ns,QueueManager qm, Notification notification, QueueResults queueResults) {
+        this.em = em;
+        this.qm = qm;
+        this.ns = ns;
+        this.path = queueResults.getPath();
+        this.notification = notification;
+        this.remaining = new ConcurrentHashMap<UUID,Message>();
+        for (Message m : queueResults.getMessages()) {
+            remaining
+                    .put((UUID) m.getObjectProperty("deviceUUID"), m);
+        }
+    }
+
+    public void skip(UUID deviceUUID) throws Exception {
+        if (LOG.isDebugEnabled()) {
+            LOG.debug("notification {} skipped device {}",
+                    notification.getUuid(), deviceUUID);
+        }
+        skips.incrementAndGet();
+        completed(null, null, deviceUUID, null);
+    }
+
+    public void completed(Notifier notifier, Receipt receipt, UUID deviceUUID,
+            String newProviderId) throws Exception {
+
+            LOG.debug("REMOVED {}", deviceUUID);
+            try {
+                EntityRef deviceRef = new SimpleEntityRef(Device.ENTITY_TYPE,
+                        deviceUUID);
+
+                if (receipt != null) {
+                    LOG.debug("notification {} sent to device {}. saving receipt.",
+                            notification.getUuid(), deviceUUID);
+                    successes.incrementAndGet();
+                    receipt.setSent(System.currentTimeMillis());
+                    this.saveReceipt(notification, deviceRef, receipt);
+                    LOG.debug("notification {} receipt saved for device {}",
+                            notification.getUuid(), deviceUUID);
+                }
+
+                if (remaining.containsKey(deviceUUID)) {
+                    LOG.debug("notification {} removing device {} from remaining", notification.getUuid(), deviceUUID);
+                    qm.commitTransaction(path, remaining.get(deviceUUID).getTransaction(), null);
+                }
+
+                if (newProviderId != null) {
+                    LOG.debug("notification {} replacing device {} notifierId", notification.getUuid(), deviceUUID);
+                    replaceProviderId(deviceRef, notifier, newProviderId);
+                }
+
+                LOG.debug("notification {} completed device {}", notification.getUuid(), deviceUUID);
+
+            } finally {
+                LOG.debug("COUNT is: {}", successes.get());
+                remaining.remove(deviceUUID);
+                // note: stats are transient for the duration of the batch
+                if (remaining.size() == 0) {
+                    long successesCopy = successes.get();
+                    long failuresCopy = failures.get();
+                    if (successesCopy > 0 || failuresCopy > 0 || skips.get()>0) {
+                        ns.finishedBatch(notification, successesCopy, failuresCopy);
+                    }
+                }
+
+            }
+    }
+
+    public void failed(Notifier notifier, Receipt receipt, UUID deviceUUID, Object code,
+            String message) throws Exception {
+
+        try {
+
+
+            if (LOG.isDebugEnabled()) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("notification ").append(notification.getUuid());
+                sb.append(" for device ").append(deviceUUID);
+                sb.append(" got error ").append(code);
+                LOG.debug(sb.toString());
+            }
+
+            failures.incrementAndGet();
+            if (receipt.getUuid() != null) {
+                successes.decrementAndGet();
+            }
+            receipt.setErrorCode(code);
+            receipt.setErrorMessage(message);
+            this.saveReceipt(notification, new SimpleEntityRef( Device.ENTITY_TYPE, deviceUUID), receipt);
+            LOG.debug("notification {} receipt saved for device {}",  notification.getUuid(), deviceUUID);
+        } finally {
+            completed(notifier, null, deviceUUID, null);
+        }
+    }
+
+    /*
+    * called from TaskManager - creates a persistent receipt and updates the
+    * passed one w/ the UUID
+    */
+    public void saveReceipt(EntityRef notification, EntityRef device,
+                            Receipt receipt) throws Exception {
+        if (receipt.getUuid() == null) {
+            Receipt savedReceipt = em.create(receipt);
+            receipt.setUuid(savedReceipt.getUuid());
+
+            List<EntityRef> entities = Arrays.asList(notification, device);
+            em.addToCollections(entities, Notification.RECEIPTS_COLLECTION,  savedReceipt);
+        } else {
+            em.update(receipt);
+        }
+    }
+
+    protected void replaceProviderId(EntityRef device, Notifier notifier,
+                                     String newProviderId) throws Exception {
+        Object value = em.getProperty(device, notifier.getName()
+                + NotificationsService.NOTIFIER_ID_POSTFIX);
+        if (value != null) {
+            em.setProperty(device, notifier.getName() + NotificationsService.NOTIFIER_ID_POSTFIX,  newProviderId);
+        } else {
+            value = em.getProperty(device, notifier.getUuid()
+                    + NotificationsService.NOTIFIER_ID_POSTFIX);
+            if (value != null) {
+                em.setProperty(device,  notifier.getUuid() + NotificationsService.NOTIFIER_ID_POSTFIX, newProviderId);
+            }
+        }
+    }
+
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
new file mode 100644
index 0000000..3b4d3d7
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
@@ -0,0 +1,50 @@
+/*
+ * 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.usergrid.services.notifications;
+
+
+import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.persistence.Receipt;
+
+import java.util.UUID;
+
+public class TaskTracker {
+
+    private Notifier notifier;
+    private TaskManager taskManager;
+    private Receipt receipt;
+    private UUID id;
+
+    public TaskTracker(Notifier notifier, TaskManager taskManager, Receipt receipt, UUID id) {
+        this.notifier = notifier;
+        this.taskManager = taskManager;
+        this.receipt = receipt;
+        this.id = id;
+    }
+
+    public void completed() throws Exception {
+        taskManager.completed(notifier, receipt, id, null);
+    }
+
+    public void failed(Object code, String message) throws Exception {
+        taskManager.failed(notifier, receipt, id, code, message);
+    }
+
+    public void completed(String newToken) throws Exception {
+        taskManager.completed(notifier, receipt, id, newToken);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
new file mode 100644
index 0000000..b3f6243
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TestAdapter.java
@@ -0,0 +1,106 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+import java.util.Date;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.ServicePayload;
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.apns.APNsNotification;
+
+/**
+ * Just used for testing. Performance and such.
+ */
+public class TestAdapter implements ProviderAdapter {
+
+    private static final Logger log = LoggerFactory.getLogger(TestAdapter.class);
+    private static final int DELAY = 1; // if delay > 0, uses threadpool
+
+    private ExecutorService pool = null;
+
+    public TestAdapter() {
+        if (DELAY > 0) {
+            pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+        }
+    }
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+    }
+
+    @Override
+    public void sendNotification(
+            String providerId, 
+            Notifier notifier,
+            final Object payload, 
+            Notification notification,
+            TaskTracker tracker)
+            throws Exception {
+
+        final APNsNotification apnsNotification = APNsNotification.create(
+                "", payload.toString(), notification, tracker);
+
+        if (pool == null) {
+            apnsNotification.messageSent();
+
+        } else {
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        Thread.sleep(DELAY);
+                        apnsNotification.messageSent();
+                        log.debug("messageSent() - " + payload.toString());
+                    } catch (Exception e) {
+                        log.error("messageSent() returned error", e);
+                    }
+                }
+            });
+        }
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+        log.debug("doneSendingNotifications()");
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        log.debug("getInactiveDevices()");
+        return null;
+    }
+
+    @Override
+    public Object translatePayload(Object payload) throws Exception {
+        return payload;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
new file mode 100644
index 0000000..73399c9
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -0,0 +1,280 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.google.common.cache.*;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.*;
+
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+import org.mortbay.util.ajax.JSON;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.security.*;
+import java.util.*;
+import java.util.concurrent.*;
+
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.services.ServicePayload;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import javax.net.ssl.SSLContext;
+
+/**
+ * Adapter for Apple push notifications
+ */
+public class APNsAdapter implements ProviderAdapter {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(APNsAdapter.class);
+
+    public static int MAX_CONNECTION_POOL_SIZE = 15;
+    private static final Set<String> validEnvironments = new HashSet<String>();
+    private static final String TEST_TOKEN = "ff026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
+    private static final String TEST_PAYLOAD = "{}";
+
+    static {
+        validEnvironments.add("development");
+        validEnvironments.add("production");
+        validEnvironments.add("mock");
+    }
+
+    public APNsAdapter(){}
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+        if(isMock(notifier)){
+            delayRandom(notifier); return;
+        }
+        TestAPNsNotification notification =  TestAPNsNotification.create(TEST_TOKEN, TEST_PAYLOAD);
+        try {
+            CountDownLatch latch = new CountDownLatch(1);
+            notification.setLatch(latch);
+                PushManager<SimpleApnsPushNotification> pushManager = getPushManager(notifier);
+                addToQueue(pushManager, notification);
+                latch.await(10000,TimeUnit.MILLISECONDS);
+                if(notification.hasFailed()){
+                    // this is expected with a bad certificate (w/message: comes from failedconnectionlistener
+                    throw new ConnectionException("Bad certificate. Double-check your environment.",notification.getCause() != null ? notification.getCause() : new Exception("Bad certificate."));
+                }
+                notification.finished();
+            } catch (Exception e) {
+                notification.finished();
+
+                if (e instanceof ConnectionException) {
+                throw (ConnectionException) e;
+            }
+            if (e instanceof InterruptedException) {
+                throw new ConnectionException("Test notification timed out", e);
+            }
+            logger.warn("testConnection got non-fatal error", e.getCause());
+        }
+    }
+
+    private BlockingQueue<SimpleApnsPushNotification> addToQueue(PushManager<SimpleApnsPushNotification> pushManager, SimpleApnsPushNotification notification) throws InterruptedException {
+        BlockingQueue<SimpleApnsPushNotification> queue = pushManager.getQueue();
+        queue.offer(notification,2500,TimeUnit.MILLISECONDS);
+        return queue;
+    }
+
+    @Override
+    public void sendNotification(String providerId, Notifier notifier,
+            Object payload, Notification notification, TaskTracker tracker)
+            throws Exception {
+        if(isMock(notifier)){
+            tracker.completed("Mocked!");
+            return;
+        }
+        APNsNotification apnsNotification = APNsNotification.create(providerId, payload.toString(), notification, tracker);
+        PushManager<SimpleApnsPushNotification> pushManager = getPushManager(notifier);
+        try {
+            addToQueue(pushManager, apnsNotification);
+            apnsNotification.messageSent();
+        }catch (InterruptedException ie){
+            apnsNotification.messageSendFailed(ie);
+            throw ie;
+        }
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+        // do nothing - no batching
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        Map<String,Date> map = new HashMap<String,Date>();
+        if(isMock(notifier)){
+            return map;
+        }
+        PushManager<SimpleApnsPushNotification> pushManager = getPushManager(notifier);
+
+        List<ExpiredToken> tokens = null;
+        try {
+            tokens = pushManager.getExpiredTokens();
+        }catch (FeedbackConnectionException fce){
+            logger.debug("Failed to get tokens",fce);
+            return map;
+        }
+        for(ExpiredToken token : tokens){
+            String expiredToken = new String(token.getToken());
+            map.put(expiredToken, token.getExpiration());
+        }
+        return map;
+    }
+
+    private PushManager<SimpleApnsPushNotification> getPushManager(Notifier notifier) throws ExecutionException {
+        PushManager<SimpleApnsPushNotification> pushManager = apnsServiceMap.get(notifier);
+        if(pushManager != null &&  !pushManager.isStarted() && pushManager.isShutDown()){
+            try{
+                pushManager = createApnsService(notifier);
+            }catch(Exception e){
+                logger.error("could not instantiate push manager.");
+                throw new ExecutionException(e);
+            }
+            apnsServiceMap.put(notifier,pushManager);
+        }
+        try {
+            if (!pushManager.isStarted()) { //ensure manager is started
+                pushManager.start();
+            }
+        }catch(IllegalStateException ise){
+            logger.debug("failed to start",ise);//could have failed because its starteded
+        }
+        return pushManager;
+    }
+
+    //cache to retrieve push manager, cached per notifier, so many notifications will get same push manager
+    private static LoadingCache<Notifier, PushManager<SimpleApnsPushNotification>> apnsServiceMap = CacheBuilder
+            .newBuilder().expireAfterAccess(10, TimeUnit.MINUTES)
+            .removalListener(new RemovalListener<Notifier, PushManager<SimpleApnsPushNotification>>() {
+                @Override
+                public void onRemoval(
+                        RemovalNotification<Notifier, PushManager<SimpleApnsPushNotification>> notification) {
+                    try {
+                        PushManager<SimpleApnsPushNotification> manager = notification.getValue();
+                        if(!manager.isShutDown()){
+                            notification.getValue().shutdown();
+                        }
+                    } catch (Exception ie) {
+                        logger.error("Failed to shutdown from cache",ie);
+                    }
+                }
+            }).build(new CacheLoader<Notifier, PushManager<SimpleApnsPushNotification>>() {
+                @Override
+                public PushManager<SimpleApnsPushNotification> load(Notifier notifier) {
+                    try{
+                        return createApnsService(notifier);
+                    }catch (KeyStoreException ke){
+                        logger.error("Could not instantiate pushmanager",ke);
+                        return null;
+                    }
+                }
+            });
+
+
+    protected static PushManager<SimpleApnsPushNotification> createApnsService(Notifier notifier) throws KeyStoreException{
+        LinkedBlockingQueue<SimpleApnsPushNotification> queue = new LinkedBlockingQueue<SimpleApnsPushNotification>();
+        PushManagerConfiguration config = new PushManagerConfiguration();
+        config.setConcurrentConnectionCount(Runtime.getRuntime().availableProcessors() * 2);
+        PushManager<SimpleApnsPushNotification> pushManager =  new PushManager<SimpleApnsPushNotification>(getApnsEnvironment(notifier), getSSLContext(notifier), null, null, queue, config);
+        //only tested when a message is sent
+        pushManager.registerRejectedNotificationListener(new RejectedAPNsListener());
+        //this will get tested when start is called
+        pushManager.registerFailedConnectionListener(new FailedConnectionListener());
+        return pushManager;
+    }
+
+    @Override
+    public Object translatePayload(Object objPayload) throws Exception {
+        String payload;
+        if (objPayload instanceof String) {
+            payload = (String) objPayload;
+            if (!payload.startsWith("{")) {
+                payload = "{\"aps\":{\"alert\":\"" + payload + "\"}}";
+            }
+        } else {
+            payload = JSON.toString(objPayload);
+        }
+        if (payload.length() > 256) {
+            throw new IllegalArgumentException(
+                    "Apple APNs payloads must be 256 characters or less");
+        }
+        return payload;
+    }
+
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+        String environment = payload.getStringProperty("environment");
+        if (!validEnvironments.contains(environment)) {
+            throw new IllegalArgumentException("environment must be one of: "
+                    + Arrays.toString(validEnvironments.toArray()));
+        }
+
+        if (payload.getProperty("p12Certificate") == null) {
+            throw new RequiredPropertyNotFoundException("notifier",
+                    "p12Certificate");
+        }
+    }
+    public boolean isMock(Notifier notifier){
+        return notifier.getEnvironment() !=null ? notifier.getEnvironment().equals("mock") : false ;
+    }
+    public boolean delayRandom(Notifier notifier) {
+        boolean wasDelayed = false;
+        if (isMock(notifier)) {
+            try {
+                Thread.sleep(
+                        new Random().nextInt(300)
+                );
+                wasDelayed = true;
+            } catch (InterruptedException ie) {
+                //delay was stopped
+            }
+        }
+        return wasDelayed;
+    }
+
+    private static ApnsEnvironment getApnsEnvironment(Notifier notifier){
+        return  notifier.isProduction()
+                ? ApnsEnvironment.getProductionEnvironment()
+                : ApnsEnvironment.getSandboxEnvironment();
+    }
+
+
+    private static SSLContext getSSLContext(Notifier notifier) {
+        try {
+            KeyStore keyStore = KeyStore.getInstance("PKCS12");
+            String password = notifier.getCertificatePassword();
+            char[] passChars =(password != null ? password : "").toCharArray();
+            InputStream stream = notifier.getP12CertificateStream();
+            keyStore.load(stream,passChars);
+            SSLContext context =  SSLContextUtil.createDefaultSSLContext(keyStore, passChars);
+            return context;
+        }catch (Exception e){
+            throw new RuntimeException("Error getting certificate",e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
new file mode 100644
index 0000000..11a9856
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsNotification.java
@@ -0,0 +1,101 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.RejectedNotificationReason;
+import com.relayrides.pushy.apns.util.MalformedTokenStringException;
+import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
+import com.relayrides.pushy.apns.util.TokenUtil;
+
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.util.Calendar;
+import java.util.Date;
+/**
+ * Standard apigee notificatton
+ */
+public class APNsNotification extends SimpleApnsPushNotification {
+
+
+    private TaskTracker tracker;
+
+    /**
+     * Factory method
+     * @param providerId token for device
+     * @param payload body
+     * @param notification notification entity
+     * @param tracker tracks completion
+     * @return
+     */
+    public static APNsNotification create(String providerId, String payload, Notification notification, TaskTracker tracker) throws RuntimeException {
+
+        Calendar date  = Calendar.getInstance();
+        date.add(Calendar.SECOND, notification.getExpireTimeInSeconds());
+      try {
+          final byte[] token = TokenUtil.tokenStringToByteArray(providerId);
+
+          return new APNsNotification(tracker, date.getTime(), token, payload, notification);
+      }catch(MalformedTokenStringException mtse){
+          throw new RuntimeException("Exception converting token",mtse);
+      }
+    }
+
+    /**
+     * Default constructor
+     * @param tracker
+     * @param expiryTime
+     * @param token
+     * @param payload
+     */
+    public APNsNotification(TaskTracker tracker, Date expiryTime, byte[] token, String payload,Notification notification) {
+        super(token, payload, expiryTime);
+        this.tracker = tracker;
+    }
+
+    /**
+     * mark message sent
+     * @throws Exception
+     */
+    public void messageSent() throws Exception {
+        if (tracker != null) {
+            tracker.completed();
+        }
+    }
+
+    /**
+     * mark message failed
+     *
+     * @throws Exception
+     */
+    public void messageSendFailed(RejectedNotificationReason reason) throws Exception {
+        if (tracker != null) {
+            tracker.failed(reason.name(), "Failed sending notification.");
+        }
+    }
+
+    /**
+     * mark message failed, from exception
+     * @param cause
+     * @throws Exception
+     */
+    public void messageSendFailed(Throwable cause) throws Exception {
+        if (tracker != null) {
+            tracker.failed(cause.getClass().getSimpleName(), cause.getMessage());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/FailedConnectionListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/FailedConnectionListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/FailedConnectionListener.java
new file mode 100644
index 0000000..552701f
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/FailedConnectionListener.java
@@ -0,0 +1,88 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.SSLException;
+import javax.net.ssl.SSLHandshakeException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * Provides a single listener that basically just delegates back to the
+ * APNsNotification for handling.
+ */
+public class FailedConnectionListener implements com.relayrides.pushy.apns.FailedConnectionListener<SimpleApnsPushNotification> {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(RejectedAPNsListener.class);
+
+    @Override
+    public void handleFailedConnection(PushManager<? extends SimpleApnsPushNotification> pushManager, Throwable cause) {
+        List<SimpleApnsPushNotification> notifications = new ArrayList<SimpleApnsPushNotification>();
+        if (cause instanceof SSLException || cause instanceof SSLHandshakeException) { //cert is probably bad so shut it down.
+            if (!pushManager.isShutDown()) {
+                pushManager.unregisterFailedConnectionListener(this);
+
+                try {
+                    BlockingQueue notificationQueue =  pushManager.getQueue();
+                    if(notificationQueue !=null){
+                        LinkedBlockingQueue<SimpleApnsPushNotification>  queue =  ( LinkedBlockingQueue<SimpleApnsPushNotification> )notificationQueue;
+                        Object[] objectMess = queue.toArray(); //get messages still in queue
+                        for(Object o : objectMess){
+                            if(o instanceof SimpleApnsPushNotification) {
+                                notifications.add((SimpleApnsPushNotification) o);
+                            }
+                        }
+                    }
+                    pushManager.shutdown();
+                } catch (InterruptedException ie) {
+                    logger.error("Failed to stop push services", ie);
+                }
+            } else {
+                return;
+            }
+        }
+        //mark all unsent notifications failed
+        if (notifications != null) {
+            for (SimpleApnsPushNotification notification : notifications) {
+                if (notification instanceof APNsNotification) {
+                    try {
+                        ((APNsNotification) notification).messageSendFailed(cause);//mark failed with bad token
+                    } catch (Exception e) {
+                        logger.error("failed to track notification in failed connection listener", e);
+                    }
+                }
+                //if test this is a problem because you can't connect
+                if (notification instanceof TestAPNsNotification) {
+                    TestAPNsNotification testAPNsNotification = ((TestAPNsNotification) notification);
+                    testAPNsNotification.setReason(cause);
+                    testAPNsNotification.countdown();
+                }
+
+            }
+            pushManager.getQueue().clear();
+        }
+        logger.error("Failed to register push connection", cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/RejectedAPNsListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/RejectedAPNsListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/RejectedAPNsListener.java
new file mode 100644
index 0000000..545dc0c
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/RejectedAPNsListener.java
@@ -0,0 +1,53 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.*;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Provides a single listener that basically just delegates back to the
+ * APNsNotification for handling.
+ */
+public class RejectedAPNsListener implements RejectedNotificationListener<SimpleApnsPushNotification>{
+
+    @Override
+    public void handleRejectedNotification(PushManager<? extends SimpleApnsPushNotification> pushManager, SimpleApnsPushNotification notification, RejectedNotificationReason rejectionReason) {
+        try {
+            //mark failed for standard notification
+            if (notification instanceof APNsNotification) {
+                ((APNsNotification) notification).messageSendFailed(rejectionReason);
+            }
+            //if test getting here means it worked
+            if(notification instanceof TestAPNsNotification){
+                TestAPNsNotification testAPNsNotification = (TestAPNsNotification) notification;
+                testAPNsNotification.setReason(rejectionReason);
+                testAPNsNotification.countdown();
+                logger.error("Failed to connect to APN's service",testAPNsNotification);
+            }
+
+        } catch (Exception e) {
+            logger.error("Failed to track rejected listener", e);
+        }
+        System.out.format("%s was rejected with rejection reason %s\n", notification, rejectionReason);
+    }
+
+    private static final Logger logger = LoggerFactory.getLogger(RejectedAPNsListener.class);
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsListener.java
new file mode 100644
index 0000000..9d112d4
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsListener.java
@@ -0,0 +1,100 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.ApnsConnection;
+import com.relayrides.pushy.apns.ApnsConnectionListener;
+import com.relayrides.pushy.apns.RejectedNotificationReason;
+import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.concurrent.CountDownLatch;
+
+public class TestAPNsListener implements ApnsConnectionListener<SimpleApnsPushNotification> {
+
+    private final CountDownLatch latch;
+
+    private boolean connectionFailed = false;
+    private boolean connectionClosed = false;
+
+    private Throwable connectionFailureCause;
+
+    private final ArrayList<SimpleApnsPushNotification> writeFailures = new ArrayList<SimpleApnsPushNotification>();
+
+    private SimpleApnsPushNotification rejectedNotification;
+    private RejectedNotificationReason rejectionReason;
+
+    private final ArrayList<SimpleApnsPushNotification> unprocessedNotifications = new ArrayList<SimpleApnsPushNotification>();
+
+    public TestAPNsListener() {
+        this.latch = new CountDownLatch(1);
+    }
+
+    public void handleConnectionSuccess(final ApnsConnection<SimpleApnsPushNotification> connection) {
+        latch.countDown();
+    }
+
+    public void handleConnectionFailure(final ApnsConnection<SimpleApnsPushNotification> connection, final Throwable cause) {
+        this.connectionFailed = true;
+        this.connectionFailureCause = cause;
+        latch.countDown();
+    }
+
+    public void handleConnectionClosure(ApnsConnection<SimpleApnsPushNotification> connection) {
+        try {
+            connection.waitForPendingWritesToFinish();
+        } catch (InterruptedException ignored) {
+        }
+        this.connectionClosed = true;
+        latch.countDown();
+    }
+
+    public void handleWriteFailure(ApnsConnection<SimpleApnsPushNotification> connection,
+                                   SimpleApnsPushNotification notification, Throwable cause) {
+
+        this.writeFailures.add(notification);
+    }
+
+    public void handleRejectedNotification(ApnsConnection<SimpleApnsPushNotification> connection,
+                                           SimpleApnsPushNotification rejectedNotification, RejectedNotificationReason reason) {
+
+        this.rejectedNotification = rejectedNotification;
+        this.rejectionReason = reason;
+    }
+
+    public void handleUnprocessedNotifications(ApnsConnection<SimpleApnsPushNotification> connection,
+                                               Collection<SimpleApnsPushNotification> unprocessedNotifications) {
+
+        this.unprocessedNotifications.addAll(unprocessedNotifications);
+    }
+
+    public void handleConnectionWritabilityChange(ApnsConnection<SimpleApnsPushNotification> connection, boolean writable) {
+    }
+
+    public boolean hasConnectionFailed() {
+        return connectionFailed;
+    }
+
+    public Throwable getConnectionFailureCause(){
+        return connectionFailureCause;
+    }
+
+    public CountDownLatch getLatch() {
+        return latch;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsNotification.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsNotification.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsNotification.java
new file mode 100644
index 0000000..014d275
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/TestAPNsNotification.java
@@ -0,0 +1,124 @@
+/*
+ * 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.RejectedNotificationReason;
+import com.relayrides.pushy.apns.util.MalformedTokenStringException;
+import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
+import com.relayrides.pushy.apns.util.TokenUtil;
+import com.yammer.metrics.Metrics;
+import com.yammer.metrics.core.Timer;
+import com.yammer.metrics.core.TimerContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Calendar;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * notification type for testing connections
+ */
+public class TestAPNsNotification extends SimpleApnsPushNotification {
+
+    private static final Logger logger = LoggerFactory.getLogger(TestAPNsNotification.class);
+
+    boolean hasFailed = false;
+
+    CountDownLatch latch;
+
+    private final Timer processTimer  =
+            Metrics.newTimer(TestAPNsNotification.class, "apns_test_notification", TimeUnit.MICROSECONDS, TimeUnit.SECONDS);
+    private TimerContext timer;
+    private Throwable cause;
+
+    public static TestAPNsNotification create(String tokenString, String payload) throws RuntimeException{
+        try {
+            final byte[] token = TokenUtil.tokenStringToByteArray(tokenString);
+            return new TestAPNsNotification( token, payload);
+        }catch (MalformedTokenStringException mtse) {
+            throw new RuntimeException("exception foreign byte array",mtse);
+        }
+    }
+
+    /**
+     * setup concurrency
+     * @param latch
+     */
+    public void setLatch(CountDownLatch latch){
+        this.latch = latch;
+    }
+
+    /**
+     * get concurrency
+     * @return
+     */
+    public CountDownLatch getLatch(){
+        return latch;
+    }
+
+    /**
+     * decrement countdown for concurrency
+     */
+    public void countdown(){
+        if(latch != null){
+            latch.countDown();
+        }
+    }
+
+    public TestAPNsNotification( byte[] token, String payload) {
+        super(token, payload, Calendar.getInstance().getTime());
+        this.timer = processTimer.time();
+    }
+
+    /**
+     * has this failed
+     * @return
+     */
+    public boolean hasFailed(){
+        return hasFailed;
+    }
+
+    /**
+     * stop timer
+     */
+    public void finished(){
+        this.timer.stop();
+    }
+
+    /**
+     * get failure reason
+     * @return cause
+     */
+    public Throwable getCause(){return cause;}
+    /**
+     * mark failure state
+     * @param cause
+     */
+    public void setReason(Throwable cause){
+        hasFailed = true; //token is definitely invalid, so don't fail
+        this.cause = cause;
+    }
+    /**
+     * mark failure state
+     * @param reason
+     */
+    public void setReason(RejectedNotificationReason reason){
+        hasFailed = reason != RejectedNotificationReason.INVALID_TOKEN; //token is definitely invalid, so don't fail
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
new file mode 100644
index 0000000..04a07d8
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/gcm/GCMAdapter.java
@@ -0,0 +1,221 @@
+/*
+ * 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.usergrid.services.notifications.gcm;
+
+import com.google.android.gcm.server.*;
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+import org.mortbay.util.ajax.JSON;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.services.ServicePayload;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.io.IOException;
+import java.util.*;
+
+public class GCMAdapter implements ProviderAdapter {
+
+    private static final Logger LOG = LoggerFactory.getLogger(GCMAdapter.class);
+    private static final int SEND_RETRIES = 3;
+    private static int BATCH_SIZE = 1000;
+
+    private Map<Notifier, Batch> notifierBatches = new HashMap<Notifier, Batch>();
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+        if(isMock(notifier)){
+            try{Thread.sleep(200);}catch (Exception ie){}
+            return;
+        }
+        Sender sender = new Sender(notifier.getApiKey());
+        Message message = new Message.Builder().build();
+        try {
+            Result result = sender.send(message, "device_token", 1);
+            LOG.debug("testConnection result: {}", result);
+        } catch (IOException e) {
+            throw new ConnectionException(e.getMessage(), e);
+        }
+    }
+
+    @Override
+    public void sendNotification(String providerId, Notifier notifier,
+            Object payload, Notification notification, TaskTracker tracker)
+            throws Exception {
+        Map<String,Object> map = (Map<String, Object>) payload;
+        final String expiresKey = "time_to_live";
+        if(!map.containsKey(expiresKey) && notification.getExpire() != null){
+            int expireSeconds = notification.getExpireTimeInSeconds();
+            expireSeconds = expireSeconds <= 2419200 ? expireSeconds : 2419200; //send the max gcm value documented here http://developer.android.com/google/gcm/adv.html#ttl
+            map.put(expiresKey, expireSeconds);
+        }
+        Batch batch = getBatch(notifier, map);
+        batch.add(providerId, tracker);
+    }
+
+    synchronized private Batch getBatch(Notifier notifier,
+            Map<String, Object> payload) {
+        Batch batch = notifierBatches.get(notifier);
+        if (batch == null && payload != null) {
+            batch = new Batch(notifier, payload);
+            notifierBatches.put(notifier, batch);
+        }
+        return batch;
+    }
+
+    @Override
+    synchronized public void doneSendingNotifications() throws Exception {
+        for (Batch batch : notifierBatches.values()) {
+            batch.send();
+        }
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        Batch batch = getBatch(notifier, null);
+        Map<String,Date> map = null;
+        if(batch != null) {
+            map = batch.getAndClearInactiveDevices();
+        }
+        return map;
+    }
+
+    @Override
+    public Map<String, Object> translatePayload(Object payload)
+            throws Exception {
+        Map<String, Object> mapPayload = new HashMap<String, Object>();
+        if (payload instanceof Map) {
+            mapPayload = (Map<String, Object>) payload;
+        } else if (payload instanceof String) {
+            mapPayload.put("data", payload);
+        } else {
+            throw new IllegalArgumentException(
+                    "GCM Payload must be either a Map or a String");
+        }
+        if (JSON.toString(mapPayload).length() > 4096) {
+            throw new IllegalArgumentException(
+                    "GCM payloads must be 4096 characters or less");
+        }
+        return mapPayload;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+        if (payload.getProperty("apiKey") == null) {
+            throw new RequiredPropertyNotFoundException("notifier", "apiKey");
+        }
+    }
+
+    private class Batch {
+        private Notifier notifier;
+        private Map payload;
+        private List<String> ids;
+        private List<TaskTracker> trackers;
+        private Map<String, Date> inactiveDevices = new HashMap<String, Date>();
+
+        Batch(Notifier notifier, Map<String, Object> payload) {
+            this.notifier = notifier;
+            this.payload = payload;
+            this.ids = new ArrayList<String>();
+            this.trackers = new ArrayList<TaskTracker>();
+        }
+
+        synchronized Map<String, Date> getAndClearInactiveDevices() {
+            Map<String, Date> map = inactiveDevices;
+            inactiveDevices = new HashMap<String, Date>();
+            return map;
+        }
+
+        synchronized void add(String id, TaskTracker tracker) throws Exception {
+            ids.add(id);
+            trackers.add(tracker);
+
+            if (ids.size() == BATCH_SIZE) {
+                send();
+            }
+        }
+
+        // Message.Builder requires the payload to be Map<String,String> for no
+        // good reason, so I just blind cast it.
+        // What actually happens is: "JSONValue.toJSONString(payload);" so
+        // anything that JSONValue can handle is fine.
+        // (What is necessary here is that the Map needs to have a nested
+        // structure.)
+        synchronized void send() throws Exception {
+            if (ids.size() == 0)
+                return;
+            Sender sender = new Sender(notifier.getApiKey());
+            Message.Builder builder = new Message.Builder();
+            builder.setData(payload);
+            Message message = builder.build();
+            if(isMock(notifier)){
+                delayRandom(notifier);
+                for(TaskTracker tracker : trackers){
+                    tracker.completed("Mocked!");
+                }
+                return;
+            }else {
+                MulticastResult multicastResult = sender.send(message, ids,
+                        SEND_RETRIES);
+                LOG.debug("sendNotification result: {}", multicastResult);
+
+                for (int i = 0; i < multicastResult.getTotal(); i++) {
+                    Result result = multicastResult.getResults().get(i);
+
+                    if (result.getMessageId() != null) {
+                        String canonicalRegId = result.getCanonicalRegistrationId();
+                        trackers.get(i).completed(canonicalRegId);
+                    } else {
+                        String error = result.getErrorCodeName();
+                        trackers.get(i).failed(error, error);
+                        if (Constants.ERROR_NOT_REGISTERED.equals(error)
+                                || Constants.ERROR_INVALID_REGISTRATION
+                                .equals(error)) {
+                            inactiveDevices.put(ids.get(i), new Date());
+                        }
+                    }
+                }
+            }
+            this.ids.clear();
+            this.trackers.clear();
+        }
+    }
+    public boolean isMock(Notifier notifier){
+        return notifier.getEnvironment() !=null ? notifier.getEnvironment().equals("mock") : false ;
+    }
+    public boolean delayRandom(Notifier notifier) {
+        boolean wasDelayed = false;
+        if (isMock(notifier)) {
+            try {
+                Thread.sleep(
+                        new Random().nextInt(300)
+                );
+                wasDelayed = true;
+            } catch (InterruptedException ie) {
+                //delay was stopped
+            }
+        }
+        return wasDelayed;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.java
new file mode 100644
index 0000000..8d7964d
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifiers/NotifiersService.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.usergrid.services.notifiers;
+
+import org.apache.usergrid.persistence.Notifier;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.*;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+
+import java.util.Arrays;
+import java.util.Set;
+
+public class NotifiersService extends AbstractCollectionService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotifiersService.class);
+
+    public NotifiersService() {
+        super();
+        logger.info("/notifiers");
+    }
+
+    @Override
+    public ServiceResults postCollection(ServiceContext context)
+            throws Exception {
+
+        ServicePayload payload = context.getPayload();
+
+        NotificationsService ns = (NotificationsService) sm
+                .getService("notifications");
+        Set<String> providers = ns.getProviders();
+
+        String provider = payload.getStringProperty("provider");
+        if (!providers.contains(provider)) {
+            throw new IllegalArgumentException("provider must be one of: "
+                    + Arrays.toString(providers.toArray()));
+        }
+
+        ProviderAdapter providerAdapter = ns.providerAdapters.get(provider);
+        providerAdapter.validateCreateNotifier(payload);
+
+        ServiceResults results = super.postCollection(context);
+
+        Notifier notifier = (Notifier) results.getEntity();
+        if (notifier != null) {
+            try {
+                ns.testConnection(notifier);
+            } catch (Exception e) {
+                logger.info("notifier testConnection() failed", e);
+                em.delete(notifier);
+                throw e;
+            }
+        }
+
+        return results;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/users/devices/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/devices/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/notifications/NotificationsService.java
new file mode 100644
index 0000000..79972c6
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/devices/notifications/NotificationsService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.users.devices.notifications;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotificationsService extends
+        org.apache.usergrid.services.notifications.NotificationsService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotificationsService.class);
+
+    public NotificationsService() {
+        logger.info("/users/*/devices/*/notifications");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/users/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/users/notifications/NotificationsService.java
new file mode 100644
index 0000000..4b536bc
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/notifications/NotificationsService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.users.notifications;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotificationsService extends
+        org.apache.usergrid.services.notifications.NotificationsService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotificationsService.class);
+
+    public NotificationsService() {
+        logger.info("/users/*/notifications");
+    }
+
+}


[30/33] git commit: change to managementappid

Posted by sn...@apache.org.
change to managementappid


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/84d0d500
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/84d0d500
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/84d0d500

Branch: refs/heads/two-dot-o
Commit: 84d0d50082a99a5809acc3fda38d0dc95caa7cd4
Parents: 0a13340
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Sep 4 11:33:46 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Sep 4 11:33:46 2014 -0600

----------------------------------------------------------------------
 .../org/apache/usergrid/services/notifications/QueueListener.java  | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/84d0d500/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
index 0ff8482..29e62c2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
@@ -112,7 +112,7 @@ public class QueueListener  {
     }
 
     private void execute(){
-        svcMgr = smf.getServiceManager(new UUID( 0, 1 ));
+        svcMgr = smf.getServiceManager(smf.getManagementAppId());
         queueManager = svcMgr.getQueueManager();
         final AtomicInteger consecutiveExceptions = new AtomicInteger();
         // run until there are no more active jobs


[05/33] git commit: adding an iterator interface to look for extra pages

Posted by sn...@apache.org.
adding an iterator interface to look for extra pages


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0a61101d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0a61101d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0a61101d

Branch: refs/heads/two-dot-o
Commit: 0a61101dafc1ab5e719fe3a8662714ab32b89b19
Parents: 99c80fa
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Jul 29 11:30:55 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 14:37:19 2014 -0600

----------------------------------------------------------------------
 .../persistence/MultiQueryIterator.java         |  6 +++-
 .../persistence/PagingResultsIterator.java      |  7 ++++-
 .../usergrid/persistence/ResultsIterator.java   | 30 ++++++++++++++++++++
 3 files changed, 41 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a61101d/stack/core/src/main/java/org/apache/usergrid/persistence/MultiQueryIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/MultiQueryIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/MultiQueryIterator.java
index 6135524..5b64d0b 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/MultiQueryIterator.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/MultiQueryIterator.java
@@ -27,7 +27,7 @@ import org.apache.usergrid.persistence.index.query.Query.Level;
  * For each in a set of source refs executes a sub-query and provides a unified iterator over 
  * the union of all results. Honors page sizes for the Query to ensure memory isn't blown out.
  */
-public class MultiQueryIterator implements Iterator {
+public class MultiQueryIterator implements ResultsIterator {
 
     private EntityManager entityManager;
     private Iterator<EntityRef> source;
@@ -74,6 +74,10 @@ public class MultiQueryIterator implements Iterator {
         return false;
     }
 
+    @Override
+    public boolean hasPages(){
+        return currentIterator != null && currentIterator instanceof ResultsIterator && ((ResultsIterator)currentIterator).hasPages();
+    }
 
     @Override
     public Object next() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a61101d/stack/core/src/main/java/org/apache/usergrid/persistence/PagingResultsIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/PagingResultsIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/PagingResultsIterator.java
index eab6c37..183cc30 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/PagingResultsIterator.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/PagingResultsIterator.java
@@ -25,7 +25,7 @@ import static org.apache.usergrid.persistence.index.query.Query.Level.REFS;
 
 
 /** iterates over a Results object, crossing page boundaries automatically */
-public class PagingResultsIterator implements Iterator, Iterable {
+public class PagingResultsIterator implements ResultsIterator, Iterable {
 
     private Results results;
     private Iterator currentPageIterator;
@@ -61,6 +61,11 @@ public class PagingResultsIterator implements Iterator, Iterable {
         return false;
     }
 
+    @Override
+    public boolean hasPages(){
+        return results != null && results.hasCursor();
+    }
+
 
     /** @return the next object (type varies according the Results.Level) */
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a61101d/stack/core/src/main/java/org/apache/usergrid/persistence/ResultsIterator.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/ResultsIterator.java b/stack/core/src/main/java/org/apache/usergrid/persistence/ResultsIterator.java
new file mode 100644
index 0000000..6ed2bad
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/ResultsIterator.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.persistence;
+
+import java.util.Iterator;
+
+/**
+ * Iterator to know if we have more records in cursor.
+ */
+public interface ResultsIterator extends Iterator {
+    /**
+     * is there a cursor
+     * @return
+     */
+    boolean hasPages();
+}


[15/33] git commit: move tests

Posted by sn...@apache.org.
move tests


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

Branch: refs/heads/two-dot-o
Commit: dd4e7650bcf84488c05343a6bd768f2871f532df
Parents: 3c761ff
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Aug 19 20:02:31 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Aug 19 20:02:31 2014 -0600

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      |   2 +-
 .../usergrid/services/NotifiersServiceTest.java | 224 -----
 .../AbstractServiceNotificationIT.java          | 107 +++
 .../AbstractServiceNotificationTest.java        | 107 ---
 .../notifications/NotifiersServiceIT.java       | 224 +++++
 .../apns/NotificationsServiceIT.java            | 857 ++++++++++++++++++
 .../apns/NotificationsServiceTest.java          | 868 -------------------
 .../gcm/NotificationsServiceIT.java             | 546 ++++++++++++
 .../gcm/NotificationsServiceTest.java           | 546 ------------
 9 files changed, 1735 insertions(+), 1746 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index c723302..7a643ac 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -195,7 +195,7 @@ public class Notification extends TypedEntity {
         // does nothing - state is derived
     }
 
-    @EntityProperty
+    @EntityProperty(mutable = true, indexed = true)
     public State getState() {
         if (getErrorMessage() != null) {
             return State.FAILED;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
deleted file mode 100644
index 06dc1a3..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.apache.usergrid.services;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.usergrid.services.notifications.apns.MockSuccessfulProviderAdapter;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.NotificationsService;
-
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.net.SocketException;
-import org.apache.usergrid.persistence.Schema;
-import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
-import org.apache.usergrid.services.AbstractServiceIT;
-import org.apache.usergrid.services.ServiceAction;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertArrayEquals;
-
-import static org.junit.Assert.fail;
-
-public class NotifiersServiceTest extends AbstractServiceIT {
-    private NotificationsService ns;
-
-    @Before
-    public void before() throws Exception {
-        ns = (NotificationsService) app.getSm().getService("notifications");
-        MockSuccessfulProviderAdapter.install(ns);
-    }
-
-    @Test
-    public void badProvider() throws Exception {
-
-        app.clear();
-        app.put("provider", "xxx");
-        app.put("environment", "production");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad provider");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badGcmToken() throws Exception {
-        app.clear();
-        app.put("provider", "google");
-        app.put("environment", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with missing apiKey");
-        } catch (RequiredPropertyNotFoundException e) {
-            // ok
-        }
-
-        // mock action (based on verified actual behavior) //
-        ns.providerAdapters
-                .put("google",
-                        new org.apache.usergrid.services.notifications.gcm.MockSuccessfulProviderAdapter() {
-                            @Override
-                            public void testConnection(Notifier notifier)
-                                    throws ConnectionException {
-                                throw new ConnectionException("", null);
-                            }
-                        });
-
-        app.put("apiKey", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with bad connection");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void badAPNsEnvironment() throws Exception {
-
-        MockSuccessfulProviderAdapter.uninstall(ns);
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad environment");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void goodAPNsCreation() throws Exception {
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Notifier notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, false,
-                        new Object[] { "notifiers" }).getEntity()
-                .toTypedEntity();
-
-        assertEquals(app.get("provider"), notifier.getProvider());
-        assertEquals(app.get("environment"), notifier.getEnvironment());
-        assertArrayEquals(notifier.getP12Certificate(), certBytes);
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badAPNsCertificate() throws Exception {
-
-        // mock error (based on verified actual behavior) //
-        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void testConnection(Notifier notifier)
-                    throws ConnectionException {
-                Exception e = new SocketException(
-                        "Connection closed by remote host");
-                throw new ConnectionException(e.getMessage(), e);
-            }
-        });
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_prod.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad connection test");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badAPNsPassword() throws Exception {
-
-        // mock error (based on verified actual behavior) //
-        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void testConnection(Notifier notifier)
-                    throws ConnectionException {
-                Exception e = new Exception("invalid ssl config");
-                throw new ConnectionException(e.getMessage(), e);
-            }
-        });
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-        app.put("certificatePassword", "wrong");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad connection test");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void encryption() throws Exception {
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Field f = Schema.class.getDeclaredField("encryptionSeed");
-        f.setAccessible(true);
-        byte[] originalSeed = (byte[]) f.get(Schema.class);
-        byte[] encryptionSeed = "This is a new seed.".getBytes();
-        f.set(Schema.class, encryptionSeed);
-
-        Notifier notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-
-        assertArrayEquals(notifier.getP12Certificate(), certBytes);
-
-        f.set(Schema.class, originalSeed);
-
-        try {
-            app.getEm().get(notifier.getUuid());
-            fail("Should have failed to retrieve the encrypted entity.");
-        } catch (IllegalStateException e) {
-            // ok! This should happen.
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
new file mode 100644
index 0000000..5cef8a8
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -0,0 +1,107 @@
+package org.apache.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.usergrid.services.AbstractServiceIT;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class AbstractServiceNotificationIT extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Rule
+    public TestName name = new TestName();
+
+    @BeforeClass
+    public static void beforeClass() {
+    }
+
+    @Before
+    public void before() throws Exception {
+
+    }
+
+    protected NotificationsService getNotificationService(){
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        return ns;
+    }
+
+    protected Notification scheduleNotificationAndWait(Notification notification)
+            throws Exception {
+        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            notification = app.getEm().get(notification.getUuid(),
+                    Notification.class);
+            if (notification.getFinished() != null) {
+                return notification;
+            }
+        }
+        fail("Notification failed to complete");
+        return null;
+    }
+
+    protected List<EntityRef> getNotificationReceipts(EntityRef notification)
+            throws Exception {
+        Results r = app.getEm().getCollection(notification,
+                Notification.RECEIPTS_COLLECTION, null, 1000000,
+                Query.Level.REFS, false);
+        List<EntityRef> list =new ArrayList<EntityRef>();//get all
+        PagingResultsIterator it = new PagingResultsIterator(r);
+        while(it.hasNext()){
+           list.add((EntityRef)it.next());
+        }
+        return list;
+    }
+
+    protected void checkReceipts(Notification notification, int expected)
+            throws Exception {
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            receipts =getNotificationReceipts(notification);
+            if (receipts.size()==expected) {
+                 break;
+            }
+        }
+        assertEquals(expected, receipts.size());
+        for (EntityRef receipt : receipts) {
+            Receipt r = app.getEm().get(receipt, Receipt.class);
+            assertNotNull(r.getSent());
+            assertNotNull(r.getPayload());
+            assertNotNull(r.getNotifierId());
+            EntityRef source = getNotificationService().getSourceNotification(r);
+            assertEquals(source.getUuid(), notification.getUuid());
+        }
+    }
+
+    protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
+        Map<String, Long> statistics = null;
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
+            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
+                break;
+            }
+        }
+        assertEquals(sent, statistics.get("sent").longValue());
+        assertEquals(errors, statistics.get("errors").longValue());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
deleted file mode 100644
index 87bed27..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-package org.apache.usergrid.services.notifications;
-
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.usergrid.services.AbstractServiceIT;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-public class AbstractServiceNotificationTest extends AbstractServiceIT {
-    private NotificationsService ns;
-
-    @Rule
-    public TestName name = new TestName();
-
-    @BeforeClass
-    public static void beforeClass() {
-    }
-
-    @Before
-    public void before() throws Exception {
-
-    }
-
-    protected NotificationsService getNotificationService(){
-        ns = (NotificationsService) app.getSm().getService("notifications");
-        return ns;
-    }
-
-    protected Notification scheduleNotificationAndWait(Notification notification)
-            throws Exception {
-        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            notification = app.getEm().get(notification.getUuid(),
-                    Notification.class);
-            if (notification.getFinished() != null) {
-                return notification;
-            }
-        }
-        fail("Notification failed to complete");
-        return null;
-    }
-
-    protected List<EntityRef> getNotificationReceipts(EntityRef notification)
-            throws Exception {
-        Results r = app.getEm().getCollection(notification,
-                Notification.RECEIPTS_COLLECTION, null, 1000000,
-                Query.Level.REFS, false);
-        List<EntityRef> list =new ArrayList<EntityRef>();//get all
-        PagingResultsIterator it = new PagingResultsIterator(r);
-        while(it.hasNext()){
-           list.add((EntityRef)it.next());
-        }
-        return list;
-    }
-
-    protected void checkReceipts(Notification notification, int expected)
-            throws Exception {
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            receipts =getNotificationReceipts(notification);
-            if (receipts.size()==expected) {
-                 break;
-            }
-        }
-        assertEquals(expected, receipts.size());
-        for (EntityRef receipt : receipts) {
-            Receipt r = app.getEm().get(receipt, Receipt.class);
-            assertNotNull(r.getSent());
-            assertNotNull(r.getPayload());
-            assertNotNull(r.getNotifierId());
-            EntityRef source = getNotificationService().getSourceNotification(r);
-            assertEquals(source.getUuid(), notification.getUuid());
-        }
-    }
-
-    protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
-        Map<String, Long> statistics = null;
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
-            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
-                break;
-            }
-        }
-        assertEquals(sent, statistics.get("sent").longValue());
-        assertEquals(errors, statistics.get("errors").longValue());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
new file mode 100644
index 0000000..a0dc60c
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
@@ -0,0 +1,224 @@
+package org.apache.usergrid.services.notifications;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.services.notifications.apns.MockSuccessfulProviderAdapter;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.SocketException;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.services.AbstractServiceIT;
+import org.apache.usergrid.services.ServiceAction;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertArrayEquals;
+
+import static org.junit.Assert.fail;
+
+public class NotifiersServiceIT extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Before
+    public void before() throws Exception {
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        MockSuccessfulProviderAdapter.install(ns);
+    }
+
+    @Test
+    public void badProvider() throws Exception {
+
+        app.clear();
+        app.put("provider", "xxx");
+        app.put("environment", "production");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad provider");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badGcmToken() throws Exception {
+        app.clear();
+        app.put("provider", "google");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with missing apiKey");
+        } catch (RequiredPropertyNotFoundException e) {
+            // ok
+        }
+
+        // mock action (based on verified actual behavior) //
+        ns.providerAdapters
+                .put("google",
+                        new org.apache.usergrid.services.notifications.gcm.MockSuccessfulProviderAdapter() {
+                            @Override
+                            public void testConnection(Notifier notifier)
+                                    throws ConnectionException {
+                                throw new ConnectionException("", null);
+                            }
+                        });
+
+        app.put("apiKey", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with bad connection");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void badAPNsEnvironment() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad environment");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void goodAPNsCreation() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, false,
+                        new Object[] { "notifiers" }).getEntity()
+                .toTypedEntity();
+
+        assertEquals(app.get("provider"), notifier.getProvider());
+        assertEquals(app.get("environment"), notifier.getEnvironment());
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsCertificate() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new SocketException(
+                        "Connection closed by remote host");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_prod.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsPassword() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new Exception("invalid ssl config");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        app.put("certificatePassword", "wrong");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void encryption() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Field f = Schema.class.getDeclaredField("encryptionSeed");
+        f.setAccessible(true);
+        byte[] originalSeed = (byte[]) f.get(Schema.class);
+        byte[] encryptionSeed = "This is a new seed.".getBytes();
+        f.set(Schema.class, encryptionSeed);
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+
+        f.set(Schema.class, originalSeed);
+
+        try {
+            app.getEm().get(notifier.getUuid());
+            fail("Should have failed to retrieve the encrypted entity.");
+        } catch (IllegalStateException e) {
+            // ok! This should happen.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
new file mode 100644
index 0000000..fd00d39
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -0,0 +1,857 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.*;
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.services.notifications.AbstractServiceNotificationIT;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.*;
+import org.junit.After;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+// todo: test reschedule on delivery time change
+// todo: test restart of queuing
+public class NotificationsServiceIT extends AbstractServiceNotificationIT {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsServiceIT.class);
+
+    /**
+     * set to true to run tests against actual Apple servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "apple" : "noop";
+
+    private static final String PUSH_TOKEN = "29026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private Group group1;
+    private User user1;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+        // create apns notifier //
+        NotificationsQueueManager.IS_TEST = true;
+
+        app.clear();
+        app.put("name", "apns");
+        app.put("provider",PROVIDER);
+        app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device1");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device2");
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+
+        // create User
+        app.put( "username", "edanuff" );
+        app.put( "email", "ed@anuff.com" );
+//        user1 = (User)app.testRequest( ServiceAction.POST, 1, "users" ).getEntity();
+//        app.getEm().createConnection(user1, "devices", device1);
+//        app.getEm().createConnection(user1, "devices", device2);
+
+        // create Group
+        app.put( "path", "path" );
+        app.put( "title", "group" );
+        group1 = (Group) app.testRequest( ServiceAction.POST, 1, "groups" ).getEntity();
+
+//        app.getEm().createConnection(group1, "users", user1);
+
+        ns = getNotificationService();
+    }
+
+    @After
+    public void after() throws Exception {
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+//        // verify Query for CREATED state
+        assertEquals(notification.getState(), Notification.State.STARTED);
+
+        // perform push //
+
+        notification = scheduleNotificationAndWait(notification);
+
+        // verify Query for FINISHED state
+        assertEquals(notification.getState(), Notification.State.FINISHED);
+
+        checkReceipts(notification, 1);
+        checkStatistics(notification, 1, 0);
+    }
+
+    @Test
+    public void pushWithNoValidDevicesShouldComplete() throws Exception {
+
+        // create unrelated notifier
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", "xxx");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+
+        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = "gcm" + NOTIFIER_ID_POSTFIX;
+
+        // create unrelated device
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        Device device = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device.getProperty(key), PUSH_TOKEN);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("started", System.currentTimeMillis());
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device);
+
+        // verify Query for CREATED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        // perform push //
+
+        ns.getQueueManager().processBatchAndReschedule(notification, null);
+
+        // verify Query for FINISHED state
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        notification = (Notification) entity.toTypedEntity();
+        checkReceipts(notification, 0);
+        checkStatistics(notification, 0, 0);
+    }
+
+    @Test
+    public void scheduledNotification() throws Exception {
+
+        // create push notification //
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("deliver", System.currentTimeMillis() + 240000);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // delay until the scheduler has time to run
+        Thread.sleep(500);
+
+        // verify Query for SCHEDULED state
+        Query query = new Query();
+        query.addEqualityFilter("state",
+                Notification.State.SCHEDULED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        try {
+            e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
+                    e.getUuid()).getEntity();
+        }catch (Exception deleteException){
+            LOG.error("Couldn't delete",deleteException);
+        }
+        app.getEm().get(e.getUuid(), Notification.class);
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 255) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals(ex.getMessage(),
+                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            APNsNotification apnsNotification = APNsNotification
+                                    .create(providerId, payload.toString(),
+                                            notification, tracker);
+                            apnsNotification.messageSent();
+                            apnsNotification
+                                    .messageSendFailed( RejectedNotificationReason.INVALID_TOKEN);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkStatistics(notification, 0, 1);
+
+        notification = (Notification) app.getEm().get(notification)
+                .toTypedEntity();
+        checkReceipts(notification, 1);
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
+    }
+
+    @Test
+    public void twoDevicesOneNotifier() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Test
+    public void twoDevicesTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), "apns2");
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), "development");
+
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device2.setProperty(key, null);
+        device2.setProperty(key2, null);
+        app.getEm().update(device2);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
+    }
+
+    @Test
+    public void oneDeviceTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        Object nameValue = "apns2";
+        Object environValue = "development";
+
+        app.clear();
+        app.put("name", nameValue);
+        app.put("provider", PROVIDER);
+        app.put("environment", environValue);
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), nameValue);
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), environValue);
+
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device1.setProperty(key2, PUSH_TOKEN);
+        app.getEm().update(device1);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badCertificate() throws Exception {
+
+        // create an apns notifier with the wrong certificate //
+
+        app.clear();
+        app.put("name", "prod_apns");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "empty.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+
+        // mock error (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void testConnection(Notifier notifier)
+                                throws ConnectionException {
+                            Exception e = new SocketException(
+                                    "Connection closed by remote host");
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification,null);
+            fail("testConnection() should have failed");
+        } catch (Exception ex) {
+            // good, there should be an error
+        }
+
+        // verify Query for FAILED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.FAILED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void inactiveDeviceUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public Map<String, Date> getInactiveDevices(
+                                Notifier notifier, EntityManager em)
+                                throws Exception {
+                            return Collections.singletonMap(PUSH_TOKEN,
+                                    new Date());
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        assertNotNull(device1.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+        assertNotNull(device2.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        // check provider IDs //
+
+        device1 = app.getEm().get(device1, Device.class);
+        assertNull(device1
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+        device2 = app.getEm().get(device2, Device.class);
+        assertNull(device2
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void batchTest() throws Exception {
+
+        final int NUM_DEVICES = 50;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        final Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        // perform push //
+        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
+        NotificationsQueueManager.BATCH_SIZE = 10;
+        try {
+            ExecutorService pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                        try {
+                             scheduleNotificationAndWait(notification);
+                        }catch (Exception e){}
+                }});
+        } finally {
+            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
+        }
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        MockSuccessfulProviderAdapter.install(ns, true);
+
+        final int NUM_DEVICES = 10000;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    private String getPayload(){
+        ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
+        builder.setAlertBody("Hello, World!");
+        builder.setSoundFileName("chime");
+        String payload = builder.buildWithDefaultMaximumLength();
+        return payload;
+    }
+    // todo: can't do the following tests here. do it in the REST tier...
+    // private Notification postNotification(String path) throws Exception {
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // path).getEntity();
+    // Thread.sleep(1000); // this sucks
+    // Notification notification = app.getEm().get(e, Notification.class);
+    // return notification;
+    // }
+    //
+    // @Test
+    // public void matrixPushDevice() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaUser() throws Exception {
+    //
+    // Notification notification = postNotification("users/" + user1.getName() +
+    // "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaGroup() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushDeviceQuery() throws Exception {
+    //
+    // Notification notification = postNotification("devices;ql=name=" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushUserQuery() throws Exception {
+    //
+    // Notification notification = postNotification("users;ql=/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+}


[17/33] git commit: merge

Posted by sn...@apache.org.
merge


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2c6cb6f9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2c6cb6f9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2c6cb6f9

Branch: refs/heads/two-dot-o
Commit: 2c6cb6f9557b2236383fe7edf8d652c756ccaab8
Parents: 9d4b70e ac0ca5d
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 20 17:16:22 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 20 17:16:22 2014 -0600

----------------------------------------------------------------------
 .../src/main/groovy/NodeRegistry.groovy         | 17 +++++++---
 .../src/main/groovy/configure_cassandra.groovy  | 10 +-----
 .../corepersistence/CpEntityManager.java        |  7 ++--
 .../corepersistence/CpEntityManagerFactory.java | 17 ++++++++++
 .../resources/usergrid-custom-test.properties   |  6 ++--
 stack/rest/pom.xml                              |  2 --
 .../rest/test/RefreshIndexResource.java         |  6 ++--
 stack/rest/src/main/webapp/WEB-INF/web.xml      | 34 ++++++++++----------
 .../apache/usergrid/rest/TomcatResource.java    |  4 ++-
 .../activities/PagingEntitiesTest.java          |  2 +-
 .../rest/management/ManagementResourceIT.java   |  2 ++
 .../rest/management/users/MUUserResourceIT.java | 24 ++++++++------
 .../resources/usergrid-custom-test.properties   | 12 ++++---
 .../resources/usergrid-custom-test.properties   |  6 ++--
 stack/test-utils/pom.xml                        |  5 ---
 15 files changed, 87 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c6cb6f9/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2c6cb6f9/stack/services/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --cc stack/services/src/test/resources/usergrid-custom-test.properties
index 94b8adf,71c7acc..b8965ee
--- a/stack/services/src/test/resources/usergrid-custom-test.properties
+++ b/stack/services/src/test/resources/usergrid-custom-test.properties
@@@ -16,13 -16,7 +16,13 @@@
  # with ug.heapmax=5000m and ug.heapmin=3000m (set in Maven settings.xml) 
  cassandra.startup=embedded
  elasticsearch.startup=embedded
- cassandra.timeout=5000
+ cassandra.timeout=2000
  cassandra.connections=1000
- hystrix.threadpool.graph_user.coreSize=100
- hystrix.threadpool.graph_async.coreSize=100
 +
 +#Poll interval to check for new jobs in millseconds. 10 milliseconds for testing
 +usergrid.scheduler.job.interval=100
 +
 +# number of delivery queue processes expected
 +notification.concurrent.batches=2
+ hystrix.threadpool.graph_user.coreSize=200
+ hystrix.threadpool.graph_async.coreSize=200


[28/33] single queue

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index cba47c4..c0b8cdd 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -19,7 +19,7 @@ package org.apache.usergrid.services.notifications.apns;
 import com.relayrides.pushy.apns.*;
 import com.relayrides.pushy.apns.util.*;
 import org.apache.commons.io.IOUtils;
-import org.apache.usergrid.services.notifications.AbstractServiceNotificationIT;
+import org.apache.usergrid.services.ServiceParameter;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.entities.*;
 import org.apache.usergrid.persistence.index.query.Query;
@@ -30,12 +30,7 @@ import org.slf4j.LoggerFactory;
 
 import java.io.InputStream;
 import java.net.SocketException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
@@ -71,6 +66,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     private Group group1;
     private User user1;
     private NotificationsService ns;
+    QueueListener listener;
 
     @Override
     @Before
@@ -78,12 +74,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         super.before();
         // create apns notifier //
         NotificationsQueueManager.IS_TEST = true;
-
         app.clear();
-        app.put("name", "apns");
+        app.put("name", "apNs");
         app.put("provider",PROVIDER);
         app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
+        // app.put("certificatePassword","pushy-test");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream( "pushtest_dev_recent.p12");
         byte[] certBytes = IOUtils.toByteArray(fis);
         app.put("p12Certificate", certBytes);
         fis.close();
@@ -111,24 +107,39 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device2 = app.getEm().get(e.getUuid(), Device.class);
 
         // create User
-        app.put( "username", "edanuff" );
-        app.put( "email", "ed@anuff.com" );
-//        user1 = (User)app.testRequest( ServiceAction.POST, 1, "users" ).getEntity();
-//        app.getEm().createConnection(user1, "devices", device1);
-//        app.getEm().createConnection(user1, "devices", device2);
+        user1 = new User();
+        user1.setUsername("user1");
+        user1.setEmail("user1@usergrid.org");
+        user1 = app.getEm().create(user1);
+        app.getEm().createConnection(user1, "devices", device1);
+        app.getEm().createConnection(user1, "devices", device2);
 
         // create Group
-        app.put( "path", "path" );
-        app.put( "title", "group" );
-        group1 = (Group) app.testRequest( ServiceAction.POST, 1, "groups" ).getEntity();
-
-//        app.getEm().createConnection(group1, "users", user1);
+        group1 = new Group();
+        group1.setPath("path");
+        group1 = app.getEm().create(group1);
+        app.getEm().createConnection(group1, "users", user1);
 
         ns = getNotificationService();
+
+        Query query = new Query();
+        //query.addIdentifier(sp.getIdentifier());
+        query.setLimit(100);
+        query.setCollection("devices");
+        query.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        PathQuery pathQuery = new PathQuery( new SimpleEntityRef(app.getEm().getApplicationRef()), query);
+
+        ns.getQueueManager().TEST_PATH_QUERY = pathQuery;
+
+        ApplicationQueueManager.QUEUE_NAME = "notifications/test/" + UUID.randomUUID().toString();
+        listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties());
+        listener.run();
     }
 
     @After
     public void after() throws Exception {
+        listener.stop();
+        listener = null;
     }
 
     @Test
@@ -137,11 +148,17 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         // create push notification //
 
         app.clear();
-        String payload = getPayload();
+        Query pQuery = new Query();
+        pQuery.setLimit(100);
+        pQuery.setCollection("devices");
+        pQuery.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        pQuery.addIdentifier(new ServiceParameter.NameParameter(device1.getUuid().toString()).getIdentifier());
+        ns.getQueueManager().TEST_PATH_QUERY =  new PathQuery( new SimpleEntityRef(app.getEm().getApplicationRef()), pQuery);
 
 
+        String payload = getPayload();
         Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier.getName().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
 
@@ -152,20 +169,29 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Notification notification = app.getEm().get(e.getUuid(),
                 Notification.class);
         assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
+                notification.getPayloads().get(notifier.getName().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
 
-//        // verify Query for CREATED state
-        assertEquals(notification.getState(), Notification.State.STARTED);
+        // verify Query for CREATED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
 
         // perform push //
 
         notification = scheduleNotificationAndWait(notification);
 
         // verify Query for FINISHED state
-        assertEquals(notification.getState(), Notification.State.FINISHED);
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
 
         checkReceipts(notification, 1);
         checkStatistics(notification, 1, 0);
@@ -181,21 +207,18 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         app.put("provider", PROVIDER);
         app.put("environment", "development");
         app.put("apiKey", "xxx");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream( "pushtest_dev_recent.p12");
         byte[] certBytes = IOUtils.toByteArray(fis);
         app.put("p12Certificate", certBytes);
 
-        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
+        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity().toTypedEntity();
         String key = "gcm" + NOTIFIER_ID_POSTFIX;
 
         // create unrelated device
 
         app.clear();
         app.put(key, PUSH_TOKEN);
-        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
-                .getEntity();
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
         app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
 
         Device device = app.getEm().get(e.getUuid(), Device.class);
@@ -213,43 +236,45 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         app.put("started", System.currentTimeMillis());
         app.put("queued", System.currentTimeMillis());
 
+        Query pQuery = new Query();
+        pQuery.setLimit(100);
+        pQuery.setCollection("devices");
+        pQuery.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        pQuery.addIdentifier(new ServiceParameter.NameParameter("1234").getIdentifier());
+        ns.getQueueManager().TEST_PATH_QUERY =   new PathQuery( new SimpleEntityRef(app.getEm().getApplicationRef()), pQuery);
         e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
+        Notification notification = app.getEm().get(e.getUuid(),  Notification.class);
         assertEquals(
                 notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
+                payload
+        );
 
-        ns.addDevice(notification, device);
 
         // verify Query for CREATED state
-        Query query = Query.fromQL("select * where type = 'notification'");
-//        Query query = new Query();
-//        query.addEqualityFilter("state", Notification.State.STARTED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Notification note = (Notification) results.getEntitiesMap().get(notification.getUuid());
-        assertEquals(Notification.State.STARTED,note.getState());
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        Results results = app.getEm().searchCollection(app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        scheduleNotificationAndWait(notification);
 
         // perform push //
 
-        ns.getQueueManager().processBatchAndReschedule(notification, null);
+        //ns.getQueueManager().processBatchAndReschedule(notification, null);
+        notification = app.getEm().get(e.getUuid(), Notification.class);
 
-        //app.getEm().refreshIndex();
         // verify Query for FINISHED state
-        query = Query.fromQL("select * where type = 'notification'");
-
-//        query = new Query();
-//        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
         results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
                 "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
 
-        note = (Notification) results.getEntitiesMap().get(notification.getUuid());
-        assertEquals(Notification.State.FINISHED,note.getState());
-
-        notification = note;
+        notification = (Notification) entity.toTypedEntity();
         checkReceipts(notification, 0);
         checkStatistics(notification, 0, 0);
     }
@@ -276,20 +301,18 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
 
         // delay until the scheduler has time to run
         Thread.sleep(500);
 
         // verify Query for SCHEDULED state
-        Query query = Query.fromQL("select * where type = 'notification'");
-//        Query query = new Query();
-//        query.addEqualityFilter("state",
-//                Notification.State.SCHEDULED.toString());
+        Query query = new Query();
+        query.addEqualityFilter("state",
+                Notification.State.SCHEDULED.toString());
         Results results = app.getEm().searchCollection(
                 app.getEm().getApplicationRef(), "notifications", query);
-        Notification note = (Notification)results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(note);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
 
         try {
             e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
@@ -335,7 +358,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // need the real provider for this one...
         app.clear();
-        app.put("name", "apns2");
+        app.put("name", "apNS2");
         app.put("provider", "apple");
         app.put("environment", "development");
         InputStream fis = getClass().getClassLoader().getResourceAsStream(
@@ -350,7 +373,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.clear();
         StringBuilder sb = new StringBuilder();
         sb.append("{\"x\":\"");
-        while (sb.length() < 2047) {
+        while (sb.length() < 255) {
             sb.append("x");
         }
         sb.append("\"}");
@@ -364,7 +387,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
             fail("invalid payload should have been rejected");
         } catch (Exception ex) {
             assertEquals(ex.getMessage(),
-                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 2048 characters or less");
+                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
             // ok
         }
     }
@@ -381,8 +404,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                     new MockSuccessfulProviderAdapter() {
                         @Override
                         public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
+                                                     Notifier notifier, Object payload,
+                                                     Notification notification, TaskTracker tracker)
                                 throws Exception {
                             APNsNotification apnsNotification = APNsNotification
                                     .create(providerId, payload.toString(),
@@ -432,6 +455,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // create push notification //
 
+
         app.clear();
         String payload = getPayload();
         Map<String, String> payloads = new HashMap<String, String>(1);
@@ -449,8 +473,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
 
         // perform push //
         notification = scheduleNotificationAndWait(notification);
@@ -463,7 +485,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // create a 2nd notifier //
         app.clear();
-        app.put("name", "apns2");
+        app.put("name", "apNs2");
         app.put("provider", PROVIDER);
         app.put("environment", "development");
         InputStream fis = getClass().getClassLoader().getResourceAsStream(
@@ -474,10 +496,10 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
                 .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
+        app.testRequest(ServiceAction.GET, 1, "notifiers", "apNs2");
 
         Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-        assertEquals(notifier2.getName(), "apns2");
+        assertEquals(notifier2.getName(), "apNs2");
         assertEquals(notifier2.getProvider(), PROVIDER);
         assertEquals(notifier2.getEnvironment(), "development");
 
@@ -506,9 +528,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
         // perform push //
         notification = scheduleNotificationAndWait(notification);
 
@@ -519,7 +538,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     public void oneDeviceTwoNotifiers() throws Exception {
 
         // create a 2nd notifier //
-        Object nameValue = "apns2";
+        Object nameValue = "apNs2";
         Object environValue = "development";
 
         app.clear();
@@ -626,12 +645,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
+//        ns.addDevice(notification, device1);
 
         // perform push //
 
         try {
-            ns.getQueueManager().processBatchAndReschedule(notification,null);
+            scheduleNotificationAndWait(notification);
             fail("testConnection() should have failed");
         } catch (Exception ex) {
             // good, there should be an error
@@ -683,9 +702,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         assertEquals(
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
+//
+//        ns.addDevice(notification, device1);
+//        ns.addDevice(notification, device2);
 
         assertNotNull(device1.getProperty(notifier.getName()
                 + NOTIFIER_ID_POSTFIX));
@@ -693,7 +712,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 + NOTIFIER_ID_POSTFIX));
 
         // perform push //
-        notification = scheduleNotificationAndWait(notification);
+        scheduleNotificationAndWait(notification);
 
         // check provider IDs //
 
@@ -709,6 +728,26 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     public void batchTest() throws Exception {
 
         final int NUM_DEVICES = 50;
+        // perform push //
+        int oldBatchSize = ApplicationQueueManager.BATCH_SIZE;
+        ApplicationQueueManager.BATCH_SIZE = 10;
+
+        app.clear();
+        app.put("name", UUID.randomUUID().toString());
+        app.put("provider","noop");
+        app.put("environment", "mock");
+        Entity entity = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
+        Notifier notifier = app.getEm().get(entity.getUuid(), Notifier.class);
+        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create a bunch of devices and add them to the notification
+
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            app.clear();
+            app.put(notifierKey, PUSH_TOKEN);
+            app.put("name", "device"+i*10);
+            app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        }
 
         app.clear();
         String payload = getPayload();
@@ -718,34 +757,14 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         app.put("queued", System.currentTimeMillis());
 
         // create a notification
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-        final Notification notification = (Notification) e.toTypedEntity();
+        entity = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", entity.getUuid());
+        final Notification notification = (Notification) entity.toTypedEntity();
 
-        // create a bunch of devices and add them to the notification
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", app.getProperties());
-            ns.addDevice(notification, entity);
-        }
-
-        // perform push //
-        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
-        NotificationsQueueManager.BATCH_SIZE = 10;
         try {
-            ExecutorService pool = Executors
-                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
-            pool.submit(new Runnable() {
-                @Override
-                public void run() {
-                        try {
-                             scheduleNotificationAndWait(notification);
-                        }catch (Exception e){}
-                }});
+            scheduleNotificationAndWait(notification);
         } finally {
-            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
+            ApplicationQueueManager.BATCH_SIZE = oldBatchSize;
         }
 
         // check receipts //

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 937b53d..32a7328 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -16,26 +16,27 @@
  */
 package org.apache.usergrid.services.notifications.gcm;
 
-import org.apache.usergrid.services.notifications.AbstractServiceNotificationIT;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.AbstractServiceIT;
+import org.apache.usergrid.services.ServiceManagerFactory;
+import org.apache.usergrid.services.ServiceParameter;
+import org.apache.usergrid.services.notifications.*;
 import org.apache.usergrid.persistence.entities.Notification;
 import org.apache.usergrid.persistence.entities.Notifier;
 import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
+import org.junit.*;
+import org.junit.rules.TestName;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.TaskTracker;
 
 import java.io.IOException;
 import java.lang.reflect.Field;
 import java.util.*;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityRef;
+
 import org.apache.usergrid.persistence.entities.Device;
 import org.apache.usergrid.services.ServiceAction;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import static org.junit.Assert.*;
 import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
@@ -59,6 +60,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     private Notifier notifier;
     private Device device1, device2;
     private NotificationsService ns;
+    private QueueListener listener;
 
     @Override
     @Before
@@ -94,6 +96,23 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
         device2 = app.getEm().get(e.getUuid(), Device.class);
         ns = getNotificationService();
+        Query query = new Query();
+        //query.addIdentifier(sp.getIdentifier());
+        query.setLimit(100);
+        query.setCollection("devices");
+        query.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        PathQuery pathQuery =  new PathQuery(new SimpleEntityRef(  app.getEm().getApplicationRef()), query);
+
+        ns.getQueueManager().TEST_PATH_QUERY = pathQuery;
+        ApplicationQueueManager.QUEUE_NAME = "notifications/test/" + UUID.randomUUID().toString();
+        listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties());
+        listener.run();
+    }
+
+    @After
+    public void after(){
+        listener.stop();
+        listener = null;
     }
 
     @Test
@@ -121,7 +140,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         Notification notification = app.getEm().get(e.getUuid(),
                 Notification.class);
-        ns.addDevice(notification, device1);
 
         // perform push //
         notification = scheduleNotificationAndWait(notification);
@@ -131,6 +149,13 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     @Test
     public void singlePushNotification() throws Exception {
 
+        Query pQuery = new Query();
+        pQuery.setLimit(100);
+        pQuery.setCollection("devices");
+        pQuery.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        pQuery.addIdentifier(new ServiceParameter.NameParameter(device1.getUuid().toString()).getIdentifier());
+        ns.getQueueManager().TEST_PATH_QUERY =  new PathQuery(new SimpleEntityRef( app.getEm().getApplicationRef()), pQuery);
+
         app.clear();
         String payload = "Hello, World!";
         Map<String, String> payloads = new HashMap<String, String>(1);
@@ -148,8 +173,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device1);
-
         // perform push //
         notification = scheduleNotificationAndWait(notification);
         checkReceipts(notification, 1);
@@ -158,6 +181,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     @Test
     public void singlePushNotificationViaUser() throws Exception {
 
+
         app.clear();
 
         app.put("username", "asdf");
@@ -169,6 +193,14 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 user.getUuid(), "devices", device1.getUuid()).getEntity();
         assertEquals(device.getUuid(), device1.getUuid());
 
+
+        Query pQuery = new Query();
+        pQuery.setLimit(100);
+        pQuery.setCollection("devices");
+        pQuery.setResultsLevel(Query.Level.ALL_PROPERTIES);
+        pQuery.addIdentifier(new ServiceParameter.NameParameter(user.getUuid().toString()).getIdentifier());
+        ns.getQueueManager().TEST_PATH_QUERY =  new PathQuery(new SimpleEntityRef(  app.getEm().getApplicationRef()), pQuery);
+
         String payload = "Hello, World!";
         Map<String, String> payloads = new HashMap<String, String>(1);
         payloads.put(notifier.getUuid().toString(), payload);
@@ -181,7 +213,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         Notification notification = app.getEm().get(e.getUuid(),
                 Notification.class);
-        ns.addDevice(notification, device1);
 
         // perform push //
         notification = scheduleNotificationAndWait(notification);
@@ -208,9 +239,6 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 notification.getPayloads().get(notifier.getUuid().toString()),
                 payload);
 
-        ns.addDevice(notification, device2);
-        ns.addDevice(notification, device1);
-
         // reduce Batch size to 1
         Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
         field.setAccessible(true);
@@ -237,8 +265,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
             @Override
             public void sendNotification(String providerId, Notifier notifier,
-                    Object payload, Notification notification,
-                    TaskTracker tracker) throws Exception {
+                                         Object payload, Notification notification,
+                                         TaskTracker tracker) throws Exception {
                 tracker.completed(newProviderId);
             }
         });
@@ -345,8 +373,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                     new MockSuccessfulProviderAdapter() {
                         @Override
                         public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
+                                                     Notifier notifier, Object payload,
+                                                     Notification notification, TaskTracker tracker)
                                 throws Exception {
                             tracker.failed("InvalidRegistration",
                                     "InvalidRegistration");
@@ -402,8 +430,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                     new MockSuccessfulProviderAdapter() {
                         @Override
                         public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
+                                                     Notifier notifier, Object payload,
+                                                     Notification notification, TaskTracker tracker)
                                 throws Exception {
                             Exception e = new IOException();
                             throw new ConnectionException(e.getMessage(), e);
@@ -437,12 +465,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // perform push //
 
-        try {
-            ns.getQueueManager().processBatchAndReschedule(notification, null);
-            fail("Should have received a ConnectionException");
-        } catch (ConnectionException ex) {
-            // good
-        }
+        // ns.getQueueManager().processBatchAndReschedule(notification, null);
+        fail("Should have received a ConnectionException");
     }
 
     @Ignore("Run only if you need to.")
@@ -544,4 +568,4 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     // assertNull(device2.getProperty(notifier.getName() +
     // NOTIFIER_ID_POSTFIX));
     // }
-}
+}
\ No newline at end of file


[03/33] git commit: add notification entities

Posted by sn...@apache.org.
add notification entities


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

Branch: refs/heads/two-dot-o
Commit: 05d90c6680363dedd1d3aae0c7587bd7b6b4a55f
Parents: 9d2121c
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 13:49:29 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 13:49:29 2014 -0600

----------------------------------------------------------------------
 .../usergrid/persistence/Notification.java      | 241 +++++++++++++++++++
 .../apache/usergrid/persistence/Notifier.java   | 139 +++++++++++
 .../apache/usergrid/persistence/Receipt.java    | 133 ++++++++++
 3 files changed, 513 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
new file mode 100644
index 0000000..f3b7392
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Notification.java
@@ -0,0 +1,241 @@
+/*
+ * 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.usergrid.persistence;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityCollection;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+import org.apache.usergrid.persistence.entities.Device;
+
+/**
+ * The entity class for representing Notifications.
+ */
+@XmlRootElement
+public class Notification extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notification";
+
+    public static final String RECEIPTS_COLLECTION = "receipts";
+
+    public static enum State {
+        CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
+    }
+
+    /** Map Notifier ID -> Payload data */
+    @EntityProperty
+    protected Map<String, Object> payloads;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long queued;
+
+    /** Time send started */
+    @EntityProperty
+    protected Long started;
+
+    /** Time processed */
+    @EntityProperty
+    protected Long finished;
+
+    /** Time to deliver to provider */
+    @EntityProperty
+    protected Long deliver;
+
+    /** Time to expire the notification */
+    @EntityProperty
+    protected Long expire;
+
+    /** True if notification is canceled */
+    @EntityProperty
+    protected Boolean canceled;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    @EntityCollection(type = "receipt")
+    protected List<UUID> receipts;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    protected Map<String, Long> statistics;
+
+    /** stats (sent & errors) */
+    @EntityProperty
+    @JsonIgnore
+    protected PathQuery<Device> pathQuery;
+
+    public Notification() {
+    }
+
+    @JsonIgnore
+    public List<UUID> getReceipts() {
+        return receipts;
+    }
+
+    public void setReceipts(List<UUID> receipts) {
+        this.receipts = receipts;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Map<String, Object> getPayloads() {
+        return payloads;
+    }
+
+    public void setPayloads(Map<String, Object> payloads) {
+        this.payloads = payloads;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getFinished() {
+        return finished;
+    }
+
+    public void setFinished(Long finished) {
+        this.finished = finished;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getDeliver() {
+        return deliver;
+    }
+
+    public void setDeliver(Long deliver) {
+        this.deliver = deliver;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getExpire() {
+        return expire;
+    }
+
+    public void setExpire(Long expire) {
+        this.expire = expire;
+    }
+
+    @JsonIgnore
+    public boolean isExpired() {
+        return expire != null && expire > System.currentTimeMillis();
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Boolean getCanceled() {
+        return canceled;
+    }
+
+    public void setCanceled(Boolean canceled) {
+        this.canceled = canceled;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getStarted() {
+        return started;
+    }
+
+    public void setStarted(Long started) {
+        this.started = started;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Map<String, Long> getStatistics() {
+        return statistics;
+    }
+
+    public void setStatistics(Map<String, Long> statistics) {
+        this.statistics = statistics;
+    }
+
+    public void updateStatistics(long sent, long errors) {
+        if (this.statistics == null) {
+            this.statistics = new HashMap<String, Long>(2);
+            this.statistics.put("sent", sent);
+            this.statistics.put("errors", errors);
+        } else {
+            this.statistics.put("sent", sent + this.statistics.get("sent"));
+            this.statistics.put("errors",
+                    errors + this.statistics.get("errors"));
+        }
+    }
+
+    /** don't bother, I will ignore you */
+    public void setState(State ignored) {
+        // does nothing - state is derived
+    }
+
+    @EntityProperty
+    public State getState() {
+        if (getErrorMessage() != null) {
+            return State.FAILED;
+        } else if (getCanceled() == Boolean.TRUE) {
+            return State.CANCELED;
+        } else if (getFinished() != null) {
+            return State.FINISHED;
+        } else if (getStarted() != null && getDeliver() == null) {
+            return State.STARTED;
+        } else if (isExpired()) {
+            return State.EXPIRED;
+        } else if (getDeliver() != null || getQueued() != null) {
+            return State.SCHEDULED;
+        }
+        return State.CREATED;
+    }
+
+    @JsonIgnore
+    public PathQuery<Device> getPathQuery() {
+        return pathQuery;
+    }
+
+    public void setPathQuery(PathQuery<Device> pathQuery) {
+        this.pathQuery = pathQuery;
+    }
+
+    @JsonIgnore
+    public int getExpireTimeInSeconds() {
+        long expirySeconds = getExpire() != null ? getExpire() * 1000 : 0;
+        return (expirySeconds > Integer.MAX_VALUE) ? Integer.MAX_VALUE
+                : (int) expirySeconds;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getQueued() {
+        return queued;
+    }
+
+    public void setQueued(Long queued) {
+        this.queued = queued;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
new file mode 100644
index 0000000..953ec6d
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Notifier.java
@@ -0,0 +1,139 @@
+/*
+ * 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.usergrid.persistence;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+import org.apache.usergrid.persistence.TypedEntity;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+import javax.net.ssl.SSLContext;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * The entity class for representing Notifiers.
+ */
+@XmlRootElement
+public class Notifier extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "notifier";
+
+    @EntityProperty(aliasProperty = true, unique = true, basic = true)
+    protected String name;
+
+    @EntityProperty(required = true)
+    protected String provider;
+
+    @EntityProperty
+    protected String environment;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected byte[] p12Certificate;
+
+    // Apple APNs
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String certificatePassword;
+
+    // Google GCM
+    @EntityProperty(indexed = false, includedInExport = false, encrypted = true)
+    protected String apiKey;
+    private javax.net.ssl.SSLContext SSLContext;
+
+    public Notifier() {
+    }
+
+    public Notifier(UUID id) {
+        uuid = id;
+    }
+
+
+
+    @Override
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getProvider() {
+        return provider;
+    }
+
+    public void setProvider(String provider) {
+        this.provider = provider;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getEnvironment() {
+        return environment;
+    }
+
+    public void setEnvironment(String environment) {
+        this.environment = environment;
+    }
+
+    @JsonIgnore
+    public boolean isProduction() {
+        return !"development".equals(environment);
+    }
+
+    @JsonIgnore
+    public byte[] getP12Certificate() {
+        return p12Certificate;
+    }
+
+    public void setP12Certificate(byte[] p12Certificate) {
+        this.p12Certificate = p12Certificate;
+    }
+
+    @JsonIgnore
+    public InputStream getP12CertificateStream() {
+        byte[] cert = getP12Certificate();
+        return cert != null ? new ByteArrayInputStream(cert) : null;
+    }
+
+    @JsonIgnore
+    public String getCertificatePassword() {
+        return certificatePassword;
+    }
+
+    public void setCertificatePassword(String certificatePassword) {
+        this.certificatePassword = certificatePassword;
+    }
+
+    @JsonIgnore
+    public String getApiKey() {
+        return apiKey;
+    }
+
+    public void setApiKey(String apiKey) {
+        this.apiKey = apiKey;
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/05d90c66/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
new file mode 100644
index 0000000..f1c034b
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Receipt.java
@@ -0,0 +1,133 @@
+/*
+ * 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.usergrid.persistence;
+
+import org.codehaus.jackson.map.annotate.JsonSerialize;
+import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.UUID;
+import org.apache.usergrid.persistence.annotations.EntityProperty;
+
+@XmlRootElement
+public class Receipt extends TypedEntity {
+
+    public static final String ENTITY_TYPE = "receipt";
+    public static final String NOTIFICATION_CONNECTION = "notification";
+
+    /** device id **/
+    @EntityProperty
+    protected UUID deviceId;
+
+    /** data sent to provider */
+    @EntityProperty
+    protected Object payload;
+
+    /** Time sent to provider */
+    @EntityProperty
+    protected Long sent;
+
+    /** Error code */
+    @EntityProperty
+    protected Object errorCode;
+
+    /** Error message */
+    @EntityProperty
+    protected String errorMessage;
+
+    /** The push token given by the provider */
+    @EntityProperty
+    protected String notifierId;
+
+    /**
+     * UUID of the Notification that sent this - not a Connection for
+     * performance reasons
+     */
+    @EntityProperty
+    protected UUID notificationUUID;
+
+    public Receipt() {
+    }
+
+    public Receipt(UUID notificationUUID, String notifierId, Object payload,UUID deviceId) {
+        this.notificationUUID = notificationUUID;
+        this.notifierId = notifierId;
+        this.payload = payload;
+        this.setDeviceId(deviceId);
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Object getPayload() {
+        return payload;
+    }
+
+    public void setPayload(Object payload) {
+        this.payload = payload;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Long getSent() {
+        return sent;
+    }
+
+    public void setSent(Long sent) {
+        this.sent = sent;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public Object getErrorCode() {
+        return errorCode;
+    }
+
+    public void setErrorCode(Object errorCode) {
+        this.errorCode = errorCode;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public String getErrorMessage() {
+        return errorMessage;
+    }
+
+    public void setErrorMessage(String errorMessage) {
+        this.errorMessage = errorMessage;
+    }
+
+    public String getNotifierId() {
+        return notifierId;
+    }
+
+    public void setNotifierId(String notifierId) {
+        this.notifierId = notifierId;
+    }
+
+    public UUID getNotificationUUID() {
+        return notificationUUID;
+    }
+
+    public void setNotificationUUID(UUID notificationUUID) {
+        this.notificationUUID = notificationUUID;
+    }
+
+    @JsonSerialize(include = Inclusion.NON_NULL)
+    public UUID getDeviceId() {
+        return deviceId;
+    }
+
+    public void setDeviceId(UUID deviceId) {
+        this.deviceId = deviceId;
+    }
+}


[18/33] git commit: upgrade pushy

Posted by sn...@apache.org.
upgrade pushy


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/390baed5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/390baed5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/390baed5

Branch: refs/heads/two-dot-o
Commit: 390baed5c967ef346df13ac30ab66a272eaaf1f0
Parents: 2c6cb6f
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 21 08:13:37 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 21 08:13:37 2014 -0600

----------------------------------------------------------------------
 .../_maven.repositories                         |   3 +--
 ...14c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar | Bin 160121 -> 160201 bytes
 ...14c97c6e3ef40c88590e1b196d3ec55b-sources.jar | Bin 59657 -> 59744 bytes
 ...63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar | Bin 67666 -> 67751 bytes
 ...7c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated |  17 +++++++----------
 ...63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom |   2 +-
 ...7c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated |  17 +++++++----------
 .../notifications/apns/APNsAdapter.java         |   2 +-
 8 files changed, 17 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
index a4c5c52..4b4ac07 100644
--- a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/_maven.repositories
@@ -1,8 +1,7 @@
 #NOTE: This is an internal implementation file, its format can be changed without prior notice.
-#Tue Jul 29 08:10:25 MDT 2014
+#Wed Aug 20 23:57:49 MDT 2014
 pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar>local-dependencies=
 pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom>=
-pushy-0.4-apigee.pom>local-dependencies=
 pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar>=
 pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar>=
 pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom>local-dependencies=

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar
index f5822ac..969757f 100644
Binary files a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-javadoc.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar
index ea25c9d..9e167fb 100644
Binary files a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b-sources.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar
index 1472acb..3246a7a 100644
Binary files a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar and b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar differ

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
index 733d7a6..592c733 100644
--- a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.jar.lastUpdated
@@ -1,16 +1,13 @@
 #NOTE: This is an internal implementation file, its format can be changed without prior notice.
-#Thu Jul 24 13:16:38 MDT 2014
-file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.error=
-http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406229398295
-http\://download.java.net/maven/2/.lastUpdated=1406229397326
-http\://repo.maven.apache.org/maven2/.lastUpdated=1406229398556
+#Tue Jul 29 08:11:52 MDT 2014
+http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406643112428
+http\://download.java.net/maven/2/.lastUpdated=1406643110976
 http\://oss.sonatype.org/content/repositories/snapshots/.error=
 http\://download.java.net/maven/2/.error=
-file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.lastUpdated=1406229398434
-http\://repo.maven.apache.org/maven2/.error=
+http\://maven.springframework.org/milestone/.lastUpdated=1406643112690
+http\://repository.codehaus.org/.lastUpdated=1406643111574
 https\://repository-hector-dev.forge.cloudbees.com/snapshot/.error=
-http\://maven.springframework.org/milestone/.lastUpdated=1406229398432
-http\://repository.codehaus.org/.lastUpdated=1406229397898
 http\://repository.codehaus.org/.error=
 http\://maven.springframework.org/milestone/.error=
-https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406229397817
+file\:///Users/ApigeeCorporation/Dev/apigee/apigee-URAP/m2/repository/.lastUpdated=1406643112703
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406643111364

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
index 982bb21..78f6a8e 100644
--- a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom
@@ -32,7 +32,7 @@
   	<dependency>
   		<groupId>io.netty</groupId>
   		<artifactId>netty-all</artifactId>
-  		<version>4.0.21.Final</version>
+  		<version>4.0.23.Final</version>
   	</dependency>
   	<dependency>
   		<groupId>com.googlecode.json-simple</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
----------------------------------------------------------------------
diff --git a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
index d0ccc7a..1038f38 100644
--- a/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
+++ b/stack/m2/repository/com/relayrides/pushy/0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b/pushy-0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b.pom.lastUpdated
@@ -1,16 +1,13 @@
 #NOTE: This is an internal implementation file, its format can be changed without prior notice.
-#Thu Jul 24 13:16:37 MDT 2014
-file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.error=
-http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406229390366
-http\://download.java.net/maven/2/.lastUpdated=1406229388629
-http\://repo.maven.apache.org/maven2/.lastUpdated=1406229397163
+#Tue Jul 29 08:11:50 MDT 2014
+http\://oss.sonatype.org/content/repositories/snapshots/.lastUpdated=1406643109745
+http\://download.java.net/maven/2/.lastUpdated=1406643106235
 http\://oss.sonatype.org/content/repositories/snapshots/.error=
 http\://download.java.net/maven/2/.error=
-file\:///Users/apigee/develop/usergrid/usergrid-rest-apigee-production/m2/repository/.lastUpdated=1406229396602
-http\://repo.maven.apache.org/maven2/.error=
+http\://maven.springframework.org/milestone/.lastUpdated=1406643110610
+http\://repository.codehaus.org/.lastUpdated=1406643107580
 https\://repository-hector-dev.forge.cloudbees.com/snapshot/.error=
-http\://maven.springframework.org/milestone/.lastUpdated=1406229396596
-http\://repository.codehaus.org/.lastUpdated=1406229389917
 http\://repository.codehaus.org/.error=
 http\://maven.springframework.org/milestone/.error=
-https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406229389776
+file\:///Users/ApigeeCorporation/Dev/apigee/apigee-URAP/m2/repository/.lastUpdated=1406643110624
+https\://repository-hector-dev.forge.cloudbees.com/snapshot/.lastUpdated=1406643107290

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/390baed5/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
index c3c1990..552d138 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/apns/APNsAdapter.java
@@ -218,7 +218,7 @@ public class APNsAdapter implements ProviderAdapter {
         } else {
             payload = JSON.toString(objPayload);
         }
-        if (payload.length() > 256) {
+        if (payload.length() > 2048) {
             throw new IllegalArgumentException(
                     "Apple APNs payloads must be 256 characters or less");
         }


[29/33] git commit: single queue

Posted by sn...@apache.org.
single queue


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/0a13340f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/0a13340f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/0a13340f

Branch: refs/heads/two-dot-o
Commit: 0a13340f4130cab187d059d968560327d170b4a2
Parents: c4b1ae6
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Sep 4 10:26:17 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Sep 4 10:26:17 2014 -0600

----------------------------------------------------------------------
 .../persistence/entities/Notification.java      |   9 +
 .../notifications/ApplicationQueueManager.java  | 558 +++++++++++++++++++
 .../notifications/ApplicationQueueMessage.java  |  93 ++++
 .../notifications/NotificationBatchJob.java     |  13 +-
 .../services/notifications/NotificationJob.java |  58 +-
 .../notifications/NotificationsService.java     |  30 +-
 .../notifications/NotificationsTaskManager.java |  33 ++
 .../services/notifications/QueueListener.java   | 195 +++++++
 .../services/notifications/QueueManager.java    |  33 ++
 .../notifications/SingleQueueTaskManager.java   | 224 ++++++++
 .../services/notifications/TaskManager.java     |   2 +-
 .../services/notifications/TaskTracker.java     |  15 +-
 .../resources/usergrid-services-context.xml     |   3 +
 .../AbstractServiceNotificationIT.java          |  12 +-
 .../apns/NotificationsServiceIT.java            | 231 ++++----
 .../gcm/NotificationsServiceIT.java             |  82 ++-
 16 files changed, 1383 insertions(+), 208 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index 7a643ac..d8e7242 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -41,6 +41,10 @@ public class Notification extends TypedEntity {
 
     public static final String RECEIPTS_COLLECTION = "receipts";
 
+    /** Total count */
+    @EntityProperty
+    protected int expectedCount;
+
     public static enum State {
         CREATED, FAILED, SCHEDULED, STARTED, FINISHED, CANCELED, EXPIRED
     }
@@ -237,4 +241,9 @@ public class Notification extends TypedEntity {
     public void setQueued(Long queued) {
         this.queued = queued;
     }
+
+    public void setExpectedCount(int expectedCount) {  this.expectedCount = expectedCount;  }
+
+    @org.codehaus.jackson.map.annotate.JsonSerialize(include = org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion.NON_NULL)
+    public int getExpectedCount() {  return expectedCount;  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
new file mode 100644
index 0000000..c88702e
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
@@ -0,0 +1,558 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import com.clearspring.analytics.hash.MurmurHash;
+import com.clearspring.analytics.stream.frequency.CountMinSketch;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+import org.apache.usergrid.batch.JobExecution;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.mq.QueueQuery;
+import org.apache.usergrid.mq.QueueResults;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+import rx.Subscriber;
+import rx.functions.Action1;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+
+
+/**
+ * Created by ApigeeCorporation on 8/27/14.
+ */
+public class ApplicationQueueManager implements QueueManager {
+    public static String QUEUE_NAME = "notifications/queuelistenerv1";
+    public static int BATCH_SIZE = 1000;
+
+    public static final long MESSAGE_TRANSACTION_TIMEOUT =  5 * 60 * 1000;
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsQueueManager.class);
+
+    //need a mocking framework, this is to substitute for no mocking
+    public static PathQuery<Device> TEST_PATH_QUERY = null;
+
+    //this is for tests, will not mark initial post complete, set to false for tests
+    private final Meter sendMeter;
+    private final Histogram queueSize;
+    private static ExecutorService INACTIVE_DEVICE_CHECK_POOL = Executors.newFixedThreadPool(5);
+    public static final String NOTIFIER_ID_POSTFIX = ".notifier.id";
+
+    private final EntityManager em;
+    private final org.apache.usergrid.mq.QueueManager qm;
+    private final JobScheduler jobScheduler;
+
+    public final Map<String, ProviderAdapter> providerAdapters =   new HashMap<String, ProviderAdapter>(3);
+    {
+        providerAdapters.put("apple", APNS_ADAPTER);
+        providerAdapters.put("google", new GCMAdapter());
+        providerAdapters.put("noop", TEST_ADAPTER);
+    };
+    // these 2 can be static, but GCM can't. future: would be nice to get gcm
+    // static as well...
+    public static ProviderAdapter APNS_ADAPTER = new APNsAdapter();
+    public static ProviderAdapter TEST_ADAPTER = new TestAdapter();
+
+    //cache to retrieve push manager, cached per notifier, so many notifications will get same push manager
+    private static LoadingCache<EntityManager, HashMap<Object,Notifier>> notifierCacheMap = CacheBuilder
+            .newBuilder()
+            .expireAfterWrite(90, TimeUnit.SECONDS)
+            .build(new CacheLoader<EntityManager, HashMap<Object, Notifier>>() {
+                @Override
+                public HashMap<Object, Notifier> load(EntityManager em) {
+                    HashMap<Object, Notifier> notifierHashMap = new HashMap<Object, Notifier>();
+                    Query query = new Query();
+                    query.setCollection("notifiers");
+                    query.setLimit(100);
+                    PathQuery<Notifier> pathQuery = new PathQuery<Notifier>(new SimpleEntityRef( em.getApplicationRef() ), query);
+                    Iterator<Notifier> notifierIterator = pathQuery.iterator(em);
+                    while (notifierIterator.hasNext()) {
+                        Notifier notifier = notifierIterator.next();
+                        String name = notifier.getName() != null ? notifier.getName() : "" ;
+                        UUID uuid = notifier.getUuid() != null ? notifier.getUuid() : UUID.randomUUID();
+                        notifierHashMap.put(name.toLowerCase(), notifier);
+                        notifierHashMap.put(uuid, notifier);
+                        notifierHashMap.put(uuid.toString(), notifier);
+                    }
+                    return notifierHashMap;
+                }
+            });;
+
+    public ApplicationQueueManager(JobScheduler jobScheduler, EntityManager entityManager, org.apache.usergrid.mq.QueueManager queueManager, MetricsFactory metricsFactory){
+        this.em = entityManager;
+        this.qm = queueManager;
+        this.jobScheduler = jobScheduler;
+        this.sendMeter = metricsFactory.getMeter(NotificationsService.class, "send");
+        this.queueSize = metricsFactory.getHistogram(NotificationsService.class, "queue_size");
+    }
+
+    public static QueueResults getDeliveryBatch(org.apache.usergrid.mq.QueueManager queueManager) throws Exception {
+        QueueQuery qq = new QueueQuery();
+        qq.setLimit(BATCH_SIZE);
+        qq.setTimeout(MESSAGE_TRANSACTION_TIMEOUT);
+        QueueResults results = queueManager.getFromQueue(QUEUE_NAME, qq);
+        LOG.debug("got batch of {} devices", results.size());
+        return results;
+    }
+
+    public boolean scheduleQueueJob(Notification notification) throws Exception{
+        return jobScheduler.scheduleQueueJob(notification);
+    }
+
+    public void queueNotification(final Notification notification, final JobExecution jobExecution) throws Exception {
+        if (notification.getCanceled() == Boolean.TRUE) {
+            LOG.info("notification " + notification.getUuid() + " canceled");
+            if (jobExecution != null) {
+                jobExecution.killed();
+            }
+            return;
+        }
+
+        long startTime = System.currentTimeMillis();
+        LOG.info("notification {} start queuing", notification.getUuid());
+        final PathQuery<Device> pathQuery = TEST_PATH_QUERY == null ? notification.getPathQuery() : TEST_PATH_QUERY; //devices query
+        final AtomicInteger deviceCount = new AtomicInteger(); //count devices so you can make a judgement on batching
+        final ConcurrentLinkedQueue<String> errorMessages = new ConcurrentLinkedQueue<String>(); //build up list of issues
+        final HashMap<Object,Notifier> notifierMap =  getNotifierMap();
+        final Map<String,Object> payloads = notification.getPayloads();
+
+        //get devices in querystring, and make sure you have access
+        if (pathQuery != null) {
+            final Iterator<Device> iterator = pathQuery.iterator(em);
+            //if there are more pages (defined by PAGE_SIZE) you probably want this to be async, also if this is already a job then don't reschedule
+            if (iterator instanceof ResultsIterator && ((ResultsIterator) iterator).hasPages() && jobExecution == null) {
+                jobScheduler.scheduleQueueJob(notification, true);
+                return;
+            }
+            final CountMinSketch sketch = new CountMinSketch(0.0001,.99,7364181); //add probablistic counter to find dups
+
+            rx.Observable.create(new IteratorObservable<Entity>(iterator)).parallel(new Func1<Observable<Entity>, Observable<Entity>>() {
+                @Override
+                public rx.Observable<Entity> call(rx.Observable<Entity> deviceObservable) {
+                    return deviceObservable.map(new Func1<Entity, Entity>() {
+                        @Override
+                        public Entity call(Entity entity) {
+                            try {
+                                List<EntityRef> devicesRef = getDevices(entity); // resolve group
+
+                                for (EntityRef deviceRef : devicesRef) {
+                                    long hash = MurmurHash.hash(deviceRef.getUuid());
+                                    if (sketch.estimateCount(hash) > 0) { //look for duplicates
+                                        LOG.debug("Maybe Found duplicate device: {}", deviceRef.getUuid());
+                                        continue;
+                                    } else {
+                                        sketch.add(hash, 1);
+                                    }
+                                    String notifierId = null;
+                                    String notifierKey = null;
+
+                                    //find the device notifier info, match it to the payload
+                                    for (Map.Entry<String, Object> entry : payloads.entrySet()) {
+                                        Notifier notifier = notifierMap.get(entry.getKey().toLowerCase());
+                                        String providerId = getProviderId(deviceRef, notifier);
+                                        if (providerId != null) {
+                                            notifierId = providerId;
+                                            notifierKey = entry.getKey().toLowerCase();
+                                            break;
+                                        }
+                                    }
+
+                                    if (notifierId == null) {
+                                        LOG.debug("Notifier did not match for device {} ", deviceRef);
+                                        continue;
+                                    }
+
+                                    ApplicationQueueMessage message = new ApplicationQueueMessage(em.getApplication().getUuid(), notification.getUuid(), deviceRef.getUuid(), notifierKey, notifierId);
+                                    qm.postToQueue(QUEUE_NAME, message);
+                                    if (notification.getQueued() == null) {
+                                        // update queued time
+                                        notification.setQueued(System.currentTimeMillis());
+                                        em.update(notification);
+                                    }
+                                    deviceCount.incrementAndGet();
+                                }
+
+                            } catch (Exception deviceLoopException) {
+                                LOG.error("Failed to add devices", deviceLoopException);
+                                errorMessages.add("Failed to add devices for entity: " + entity.getUuid() + " error:" + deviceLoopException);
+                            }
+                            return entity;
+                        }
+                    });
+                }
+            }, Schedulers.io())
+                    .doOnError(new Action1<Throwable>() {
+                        @Override
+                        public void call(Throwable throwable) {
+                            LOG.error("Failed while writing", throwable);
+                        }
+                    })
+                    .toBlocking()
+                    .lastOrDefault(null);
+        }
+
+        // update queued time
+        Map<String, Object> properties = new HashMap<String, Object>(2);
+        properties.put("queued", notification.getQueued());
+        properties.put("state", notification.getState());
+
+
+        if(errorMessages.size()>0){
+            if (notification.getErrorMessage() == null) {
+                notification.setErrorMessage("There was a problem delivering all of your notifications. See deliveryErrors in properties");
+            }
+        }
+
+        notification.setExpectedCount(deviceCount.get());
+        notification.addProperties(properties);
+        em.update(notification);
+
+        //do i have devices, and have i already started batching.
+        if (deviceCount.get() <= 0) {
+            SingleQueueTaskManager taskManager = new SingleQueueTaskManager(em, qm, this, notification);
+            //if i'm in a test value will be false, do not mark finished for test orchestration, not ideal need real tests
+            taskManager.finishedBatch();
+        }
+
+        if (LOG.isInfoEnabled()) {
+            long elapsed = notification.getQueued() != null ? notification.getQueued() - startTime : 0;
+            StringBuilder sb = new StringBuilder();
+            sb.append("notification ").append(notification.getUuid());
+            sb.append(" done queuing to ").append(deviceCount);
+            sb.append(" devices in ").append(elapsed).append(" ms");
+            LOG.info(sb.toString());
+        }
+
+    }
+
+
+    public HashMap<Object,Notifier> getNotifierMap(){
+        try{
+            HashMap<Object,Notifier> map = notifierCacheMap.get(em);
+            return map;
+        }catch (ExecutionException ee){
+            LOG.error("failed to get from cache",ee);
+            return new HashMap<Object, Notifier>();
+        }
+    }
+    private void clearNotifierMap(){
+        notifierCacheMap.invalidate(em);
+    }
+
+
+    /**
+     * send batches of notifications to provider
+     * @param messages
+     * @throws Exception
+     */
+    public Observable sendBatchToProviders( final List<ApplicationQueueMessage> messages) {
+        final Map<Object, Notifier> notifierMap = getNotifierMap();
+        final QueueManager proxy = this;
+        final ConcurrentHashMap<UUID,SingleQueueTaskManager> taskMap = new ConcurrentHashMap<UUID, SingleQueueTaskManager>(messages.size());
+        final ConcurrentHashMap<UUID,Notification> notificationMap = new ConcurrentHashMap<UUID, Notification>(messages.size());
+
+        return rx.Observable
+                .from(messages)
+                .parallel(new Func1<rx.Observable<ApplicationQueueMessage>, rx.Observable<ApplicationQueueMessage>>() {
+                    @Override
+                    public rx.Observable<ApplicationQueueMessage> call(rx.Observable<ApplicationQueueMessage> messageObservable) {
+                        return messageObservable.map(new Func1<ApplicationQueueMessage, ApplicationQueueMessage>() {
+                            @Override
+                            public ApplicationQueueMessage call(ApplicationQueueMessage message) {
+                                try {
+                                    UUID deviceUUID = message.getUuid();
+                                    Notification notification = notificationMap.get(message.getNotificationId());
+                                    if (notification == null) {
+                                        notification = em.get(message.getNotificationId(), Notification.class);
+                                        notificationMap.put(message.getNotificationId(), notification);
+                                    }
+                                    SingleQueueTaskManager taskManager;
+                                    synchronized (taskMap) {
+                                        taskManager = taskMap.get(message.getNotificationId());
+                                        if (taskManager == null) {
+                                            taskManager = new SingleQueueTaskManager(em, qm, proxy, notification);
+                                            taskMap.put(message.getNotificationId(), taskManager);
+                                        }
+                                    }
+
+                                    final Map<String, Object> payloads = notification.getPayloads();
+                                    final Map<String, Object> translatedPayloads = translatePayloads(payloads, notifierMap);
+                                    LOG.info("sending notification for device {} for Notification: {}", deviceUUID, notification.getUuid());
+                                    if(!isOkToSend(notification)){
+                                        return message;
+                                    }
+                                    taskManager.addMessage(deviceUUID,message);
+                                    try {
+                                        String notifierName = message.getNotifierKey().toLowerCase();
+                                        Notifier notifier = notifierMap.get(notifierName.toLowerCase());
+                                        Object payload = translatedPayloads.get(notifierName);
+                                        Receipt receipt = new Receipt(notification.getUuid(), message.getNotifierId(), payload, deviceUUID);
+                                        TaskTracker tracker = new TaskTracker(notifier, taskManager, receipt, deviceUUID);
+
+                                        if (payload == null) {
+                                            LOG.debug("selected device {} for notification {} doesn't have a valid payload. skipping.", deviceUUID, notification.getUuid());
+                                            tracker.failed(0, "failed to match payload to " + message.getNotifierId() + " notifier");
+
+                                        }else{
+                                            try {
+                                                ProviderAdapter providerAdapter = providerAdapters.get(notifier.getProvider());
+                                                providerAdapter.sendNotification(message.getNotifierId(), notifier, payload, notification, tracker);
+                                            } catch (Exception e) {
+                                                tracker.failed(0, e.getMessage());
+                                            }
+                                        }
+
+                                    } finally {
+                                        sendMeter.mark();
+                                    }
+
+                                } catch (Exception e) {
+                                    LOG.error("Failure unknown",e);
+                                }
+                                return message;
+                            }
+                        });
+                    }
+                }, Schedulers.io())
+                .buffer(BATCH_SIZE)
+                .map(new Func1<List<ApplicationQueueMessage>, HashMap<UUID, ApplicationQueueMessage>>() {
+                    @Override
+                    public HashMap<UUID, ApplicationQueueMessage> call(List<ApplicationQueueMessage> queueMessages) {
+                        //for gcm this will actually send notification
+                        for (ProviderAdapter providerAdapter : providerAdapters.values()) {
+                            try {
+                                providerAdapter.doneSendingNotifications();
+                            } catch (Exception e) {
+                                LOG.error("providerAdapter.doneSendingNotifications: ", e);
+                            }
+                        }
+                        //TODO: check if a notification is done and mark it
+                        HashMap<UUID, ApplicationQueueMessage> notifications = new HashMap<UUID, ApplicationQueueMessage>();
+                        for (ApplicationQueueMessage message : queueMessages) {
+                            if (notifications.get(message.getNotificationId()) == null) {
+                                try {
+                                    SingleQueueTaskManager taskManager = taskMap.get(message.getNotificationId());
+                                    notifications.put(message.getNotificationId(), message);
+                                    taskManager.finishedBatch();
+                                } catch (Exception e) {
+                                    LOG.error("Failed to finish batch", e);
+                                }
+                            }
+
+                        }
+                        return notifications;
+                    }
+                })
+                .doOnError(new Action1<Throwable>() {
+                    @Override
+                    public void call(Throwable throwable) {
+                        LOG.error("Failed while sending",throwable);
+                    }
+                });
+
+
+    }
+
+
+    /**
+     * Call the adapter with the notifier
+     */
+    private Map<String, Object> translatePayloads(Map<String, Object> payloads, Map<Object, Notifier> notifierMap) throws Exception {
+        Map<String, Object> translatedPayloads = new HashMap<String, Object>(
+                payloads.size());
+        for (Map.Entry<String, Object> entry : payloads.entrySet()) {
+            String payloadKey = entry.getKey().toLowerCase();
+            Object payloadValue = entry.getValue();
+            Notifier notifier = notifierMap.get(payloadKey);
+            if(notifier==null){
+                clearNotifierMap();
+                notifierMap = getNotifierMap();
+                notifier = notifierMap.get(payloadKey);
+            }
+            if (notifier != null) {
+                ProviderAdapter providerAdapter = providerAdapters.get(notifier.getProvider());
+                if (providerAdapter != null) {
+                    Object translatedPayload = payloadValue != null ? providerAdapter.translatePayload(payloadValue) : null;
+                    if (translatedPayload != null) {
+                        translatedPayloads.put(payloadKey, translatedPayload);
+                    }
+                }
+            }
+        }
+        return translatedPayloads;
+    }
+
+
+    private static final class IteratorObservable<T> implements rx.Observable.OnSubscribe<T> {
+        private final Iterator<T> input;
+        private IteratorObservable( final Iterator input ) {this.input = input;}
+
+        @Override
+        public void call( final Subscriber<? super T> subscriber ) {
+
+            /**
+             * You would replace this code with your file reading.  Instead of emitting from an iterator,
+             * you would create a bean object that represents the entity, and then emit it
+             */
+
+            try {
+                while ( !subscriber.isUnsubscribed() && input.hasNext() ) {
+                    //send our input to the next
+                    subscriber.onNext( (T) input.next() );
+                }
+
+                //tell the subscriber we don't have any more data
+                subscriber.onCompleted();
+            }
+            catch ( Throwable t ) {
+                LOG.error("failed on subscriber",t);
+                subscriber.onError( t );
+            }
+        }
+    }
+
+    public void asyncCheckForInactiveDevices(Set<Notifier> notifiers)  throws Exception {
+        for (final Notifier notifier : notifiers) {
+            INACTIVE_DEVICE_CHECK_POOL.execute(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        checkForInactiveDevices(notifier);
+                    } catch (Exception e) {
+                        LOG.error("checkForInactiveDevices", e); // not
+                        // essential so
+                        // don't fail,
+                        // but log
+                    }
+                }
+            });
+        }
+    }
+
+    /** gets the list of inactive devices from the Provider and updates them */
+    private void checkForInactiveDevices(Notifier notifier) throws Exception {
+        ProviderAdapter providerAdapter = providerAdapters.get(notifier
+                .getProvider());
+        if (providerAdapter != null) {
+            LOG.debug("checking notifier {} for inactive devices", notifier);
+            Map<String, Date> inactiveDeviceMap = providerAdapter
+                    .getInactiveDevices(notifier, em);
+
+            if (inactiveDeviceMap != null && inactiveDeviceMap.size() > 0) {
+                LOG.debug("processing {} inactive devices",
+                        inactiveDeviceMap.size());
+                Map<String, Object> clearPushtokenMap = new HashMap<String, Object>(
+                        2);
+                clearPushtokenMap.put(notifier.getName() + NOTIFIER_ID_POSTFIX,
+                        "");
+                clearPushtokenMap.put(notifier.getUuid() + NOTIFIER_ID_POSTFIX,
+                        "");
+
+                // todo: this could be done in a single query
+                for (Map.Entry<String, Date> entry : inactiveDeviceMap
+                        .entrySet()) {
+                    // name
+                    Query query = new Query();
+                    query.addEqualityFilter(notifier.getName()
+                            + NOTIFIER_ID_POSTFIX, entry.getKey());
+                    Results results = em.searchCollection(em.getApplication(),
+                            "devices", query);
+                    for (Entity e : results.getEntities()) {
+                        em.updateProperties(e, clearPushtokenMap);
+                    }
+                    // uuid
+                    query = new Query();
+                    query.addEqualityFilter(notifier.getUuid()
+                            + NOTIFIER_ID_POSTFIX, entry.getKey());
+                    results = em.searchCollection(em.getApplication(),
+                            "devices", query);
+                    for (Entity e : results.getEntities()) {
+                        em.updateProperties(e, clearPushtokenMap);
+                    }
+                }
+            }
+            LOG.debug("finished checking notifier {} for inactive devices",
+                    notifier);
+        }
+    }
+
+    private boolean isOkToSend(Notification notification) {
+        if (notification.getFinished() != null) {
+            LOG.info("notification {} already processed. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        if (notification.getCanceled() == Boolean.TRUE) {
+            LOG.info("notification {} canceled. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        if (notification.isExpired()) {
+            LOG.info("notification {} expired. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        return true;
+    }
+
+    private List<EntityRef> getDevices(EntityRef ref) throws Exception {
+        List<EntityRef> devices = Collections.EMPTY_LIST;
+        if ("device".equals(ref.getType())) {
+            devices = Collections.singletonList(ref);
+        } else if ("user".equals(ref.getType())) {
+            devices = em.getCollection(ref, "devices", null, Query.MAX_LIMIT,
+                    Query.Level.REFS, false).getRefs();
+        } else if ("group".equals(ref.getType())) {
+            devices = new ArrayList<EntityRef>();
+            for (EntityRef r : em.getCollection(ref, "users", null,
+                    Query.MAX_LIMIT, Query.Level.REFS, false).getRefs()) {
+                devices.addAll(getDevices(r));
+            }
+        }
+        return devices;
+    }
+
+
+    private String getProviderId(EntityRef device, Notifier notifier) throws Exception {
+        try {
+            Object value = em.getProperty(device, notifier.getName() + NOTIFIER_ID_POSTFIX);
+            if (value == null) {
+                value = em.getProperty(device, notifier.getUuid() + NOTIFIER_ID_POSTFIX);
+            }
+            return value != null ? value.toString() : null;
+        } catch (Exception e) {
+            LOG.error("Errer getting provider ID, proceding with rest of batch", e);
+            return null;
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
new file mode 100644
index 0000000..f66fbf7
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
@@ -0,0 +1,93 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.mq.Message;
+
+import java.util.UUID;
+
+/**
+ * Created by ApigeeCorporation on 9/4/14.
+ */
+public class ApplicationQueueMessage extends Message {
+
+
+    static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
+    static final String MESSAGE_PROPERTY_APPLICATION_UUID = "applicationUUID";
+    static final String MESSAGE_PROPERTY_NOTIFIER_ID = "notifierId";
+    static final String MESSAGE_PROPERTY_NOTIFICATION_ID = "notificationId";
+    static final String MESSAGE_PROPERTY_NOTIFIER_NAME = "notifierName";
+
+
+    public ApplicationQueueMessage() {
+    }
+
+    public ApplicationQueueMessage(UUID applicationId, UUID notificationId, UUID deviceId, String notifierKey, String notifierId) {
+        setApplicationId(applicationId);
+        setDeviceId(deviceId);
+        setNotificationId(notificationId);
+        setNotifierKey(notifierKey);
+        setNotifierId(notifierId);
+    }
+
+
+    public static ApplicationQueueMessage generate(Message message) {
+        return new ApplicationQueueMessage(UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_APPLICATION_UUID)), UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_NOTIFICATION_ID)), UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_DEVICE_UUID)), message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME), message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID));
+    }
+
+    public UUID getApplicationId() {
+        return (UUID) this.getObjectProperty(MESSAGE_PROPERTY_APPLICATION_UUID);
+    }
+
+    public void setApplicationId(UUID applicationId) {
+        this.setProperty(MESSAGE_PROPERTY_APPLICATION_UUID, applicationId);
+    }
+
+    public UUID getDeviceId() {
+        return (UUID) this.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID);
+    }
+
+    public void setDeviceId(UUID deviceId) {
+        this.setProperty(MESSAGE_PROPERTY_DEVICE_UUID, deviceId);
+    }
+
+    public UUID getNotificationId() {
+        return (UUID) this.getObjectProperty(MESSAGE_PROPERTY_NOTIFICATION_ID);
+    }
+
+    public void setNotificationId(UUID notificationId) {
+        this.setProperty(MESSAGE_PROPERTY_NOTIFICATION_ID, notificationId);
+    }
+
+    public String getNotifierId() {
+        return this.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID);
+    }
+
+    public void setNotifierId(String notifierId) {
+        this.setProperty(MESSAGE_PROPERTY_NOTIFIER_ID, notifierId);
+    }
+
+    public String getNotifierKey() {
+        return this.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME);
+    }
+
+    public void setNotifierKey(String name) {
+        this.setProperty(MESSAGE_PROPERTY_NOTIFIER_NAME, name);
+    }
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
index b9ea73e..5e7e568 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
@@ -17,6 +17,7 @@
 package org.apache.usergrid.services.notifications;
 
 
+import java.util.Properties;
 import java.util.UUID;
 
 import javax.annotation.PostConstruct;
@@ -59,6 +60,9 @@ public class NotificationBatchJob implements Job {
     @Autowired
     private EntityManagerFactory emf;
 
+    @Autowired
+    private Properties properties;
+
 
     public NotificationBatchJob() {
 
@@ -102,7 +106,14 @@ public class NotificationBatchJob implements Job {
 
 
             try {
-                notificationsService.getQueueManager().processBatchAndReschedule( notification, jobExecution );
+                NotificationsQueueManager queueManager = new NotificationsQueueManager(
+                        new JobScheduler(sm,em),
+                        em,
+                        properties,
+                        sm.getQueueManager(),
+                        metricsService
+                );
+                queueManager.processBatchAndReschedule(notification, jobExecution);
             }
             catch ( Exception e ) {
                 logger.error( "execute NotificationBatchJob failed", e );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
index 35051bc..372ad4e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
@@ -46,19 +46,6 @@ public class NotificationJob extends OnlyOnceJob {
 
     private static final Logger logger = LoggerFactory.getLogger( NotificationJob.class );
 
-    @Autowired
-    private MetricsFactory metricsService;
-
-    @Autowired
-    private ServiceManagerFactory smf;
-
-    @Autowired
-    private EntityManagerFactory emf;
-    private Meter requests;
-    private Timer execution;
-    private Histogram end;
-
-
     public NotificationJob() {
 
     }
@@ -66,56 +53,13 @@ public class NotificationJob extends OnlyOnceJob {
 
     @PostConstruct
     void init() {
-        requests = metricsService.getMeter( NotificationJob.class, "requests" );
-        execution = metricsService.getTimer( NotificationJob.class, "execution" );
-        end = metricsService.getHistogram( QueueJob.class, "end" );
     }
 
 
     @Override
     public void doJob( JobExecution jobExecution ) throws Exception {
 
-        Timer.Context timer = execution.time();
-        requests.mark();
-
-        logger.info( "execute NotificationJob {}", jobExecution );
-
-        JobData jobData = jobExecution.getJobData();
-        UUID applicationId = ( UUID ) jobData.getProperty( "applicationId" );
-        ServiceManager sm = smf.getServiceManager( applicationId );
-        NotificationsService notificationsService = ( NotificationsService ) sm.getService( "notifications" );
-
-        EntityManager em = emf.getEntityManager( applicationId );
-        try {
-            if ( em == null ) {
-                logger.info( "no EntityManager for applicationId  {}", applicationId );
-                return;
-            }
-            UUID notificationId = ( UUID ) jobData.getProperty( "notificationId" );
-            Notification notification = em.get( notificationId, Notification.class );
-            if ( notification == null ) {
-                logger.info( "notificationId {} no longer exists", notificationId );
-                return;
-            }
-
-            try {
-                notificationsService.getQueueManager().processBatchAndReschedule( notification, jobExecution );
-            }
-            catch ( Exception e ) {
-                logger.error( "execute NotificationJob failed", e );
-                em.setProperty( notification, "errorMessage", e.getMessage() );
-                throw e;
-            }
-            finally {
-                long diff = System.currentTimeMillis() - notification.getCreated();
-                end.update( diff );
-            }
-        }
-        finally {
-            timer.stop();
-        }
-
-        logger.info( "execute NotificationJob completed normally" );
+        logger.info( "execute NotificationJob is deprecated " );
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index e347f98..5a64cbc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -39,6 +39,7 @@ import static org.apache.usergrid.utils.InflectionUtils.pluralize;
 
 import org.apache.usergrid.services.notifications.apns.APNsAdapter;
 import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
+import org.springframework.beans.factory.annotation.Autowired;
 import rx.Observable;
 import rx.functions.Func1;
 import rx.schedulers.Schedulers;
@@ -79,8 +80,12 @@ public class NotificationsService extends AbstractCollectionService {
         providerAdapters.put("noop", TEST_ADAPTER);
     }
 
-    private NotificationsQueueManager notificationQueueManager;
+    private ApplicationQueueManager notificationQueueManager;
     private long gracePeriod;
+    @Autowired
+    private ServiceManagerFactory smf;
+    @Autowired
+    private EntityManagerFactory emf;
 
     public NotificationsService() {
         LOG.info("/notifications");
@@ -89,6 +94,9 @@ public class NotificationsService extends AbstractCollectionService {
     @Override
     public void init( ServiceInfo info ) {
         super.init(info);
+        smf = getApplicationContext().getBean(ServiceManagerFactory.class);
+        emf = getApplicationContext().getBean(EntityManagerFactory.class);
+
         metricsService = getApplicationContext().getBean(MetricsFactory.class);
         sendMeter = metricsService.getMeter(NotificationsService.class, "send");
         postMeter = metricsService.getMeter(NotificationsService.class, "requests");
@@ -96,14 +104,15 @@ public class NotificationsService extends AbstractCollectionService {
         queueSize = metricsService.getHistogram(NotificationsService.class, "queue_size");
         outstandingQueue = metricsService.getCounter(NotificationsService.class,"current_queue");
         JobScheduler jobScheduler = new JobScheduler(sm,em);
-        notificationQueueManager = new NotificationsQueueManager(jobScheduler,em,sm.getProperties(),sm.getQueueManager(),metricsService);
+        notificationQueueManager = new ApplicationQueueManager(jobScheduler,em,smf.getServiceManager(smf.getManagementAppId()).getQueueManager(),metricsService);
         gracePeriod = jobScheduler.SCHEDULER_GRACE_PERIOD;
     }
 
-    public NotificationsQueueManager getQueueManager(){
+    public ApplicationQueueManager getQueueManager(){
         return notificationQueueManager;
     }
 
+
     @Override
     public ServiceContext getContext(ServiceAction action,
             ServiceRequest request, ServiceResults previousResults,
@@ -206,7 +215,7 @@ public class NotificationsService extends AbstractCollectionService {
         Long deliver = (Long) payload.getProperty("deliver");
         if (deliver != null) {
             if (!deliver.equals(notification.getDeliver())) {
-                notificationQueueManager.processBatchAndReschedule((Notification) response, null);
+                notificationQueueManager.queueNotification((Notification) response, null);
             }
         }
         return response;
@@ -327,4 +336,17 @@ public class NotificationsService extends AbstractCollectionService {
             providerAdapter.testConnection(notifier);
         }
     }
+
+
+    public ServiceManagerFactory getServiceManagerFactory(){
+        return this.smf;
+    }
+    public EntityManagerFactory getEntityManagerFactory(){
+        return this.emf;
+    }
+
+
+    public MetricsFactory getMetricsFactory() {
+        return metricsService;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsTaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsTaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsTaskManager.java
new file mode 100644
index 0000000..0869f73
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsTaskManager.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.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+
+import java.util.UUID;
+
+public interface NotificationsTaskManager {
+
+    void completed(Notifier notifier, Receipt receipt, UUID deviceUUID,
+                   String newProviderId) throws Exception;
+
+    void failed(Notifier notifier, Receipt receipt, UUID deviceUUID, Object code,
+                String message) throws Exception;
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
new file mode 100644
index 0000000..0ff8482
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java
@@ -0,0 +1,195 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.mq.*;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.services.ServiceManager;
+import org.apache.usergrid.services.ServiceManagerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import rx.Observable;
+import rx.functions.Action1;
+import rx.functions.Func1;
+import rx.observables.GroupedObservable;
+import rx.schedulers.Schedulers;
+
+import javax.annotation.PostConstruct;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicInteger;
+
+public class QueueListener  {
+    public static int MAX_CONSECUTIVE_FAILS = 10;
+
+
+    private static final Logger LOG = LoggerFactory.getLogger(QueueListener.class);
+
+    @Autowired
+    private MetricsFactory metricsService;
+
+    @Autowired
+    private ServiceManagerFactory smf;
+
+    @Autowired
+    private EntityManagerFactory emf;
+
+    @Autowired
+    private Properties properties;
+
+    private org.apache.usergrid.mq.QueueManager queueManager;
+
+    private ServiceManager svcMgr;
+
+    private long sleepPeriod = 5000;
+
+    ExecutorService pool;
+    List<Future> futures;
+
+    public static final String MAX_THREADS = "1";
+
+    public QueueListener() {
+        pool = Executors.newFixedThreadPool(1);
+    }
+    public QueueListener(ServiceManagerFactory smf, EntityManagerFactory emf, MetricsFactory metricsService, Properties props){
+        this();
+        this.smf = smf;
+        this.emf = emf;
+        this.metricsService = metricsService;
+        this.properties = props;
+    }
+
+    @PostConstruct
+    void init() {
+        run();
+    }
+
+    public void run(){
+        int threadCount = 0;
+        try {
+            sleepPeriod = new Long(properties.getProperty("usergrid.notifications.listener.sleep", "5000")).longValue();
+            int maxThreads = new Integer(properties.getProperty("usergrid.notifications.listener.maxThreads", MAX_THREADS));
+            futures = new ArrayList<Future>(maxThreads);
+            while (threadCount++ < maxThreads) {
+                futures.add(
+                        pool.submit(new Runnable() {
+                            @Override
+                            public void run() {
+                                try {
+                                    execute();
+                                } catch (Exception e) {
+                                    LOG.error("failed to start push", e);
+                                }
+                            }
+                        })
+                );
+            }
+        }catch (Exception e){
+            LOG.error("QueueListener failed to start:", e);
+        }
+    }
+
+    private void execute(){
+        svcMgr = smf.getServiceManager(new UUID( 0, 1 ));
+        queueManager = svcMgr.getQueueManager();
+        final AtomicInteger consecutiveExceptions = new AtomicInteger();
+        // run until there are no more active jobs
+        while ( true ) {
+            try {
+                QueueResults results = ApplicationQueueManager.getDeliveryBatch(queueManager);
+                List<Message> messages = results.getMessages();
+                if(messages.size()>0) {
+                    Observable.from(messages) //observe all messages
+                            .subscribeOn(Schedulers.io())
+                            .map(new Func1<Message, ApplicationQueueMessage>() { //map a message to a typed message
+                                @Override
+                                public ApplicationQueueMessage call(Message message) {
+                                    return ApplicationQueueMessage.generate(message);
+                                }
+                            })
+                            .groupBy(new Func1<ApplicationQueueMessage, UUID>() { //group all of the messages together by app id
+                                @Override
+                                public UUID call(ApplicationQueueMessage message) {
+                                    return message.getApplicationId();
+                                }
+                            })
+                            .flatMap(new Func1<GroupedObservable<UUID, ApplicationQueueMessage>, Observable<?>>() { //take the observable and buffer in
+                                @Override
+                                public Observable<?> call(GroupedObservable<UUID, ApplicationQueueMessage> groupedObservable) {
+                                    UUID appId = groupedObservable.getKey();
+                                    EntityManager entityManager = emf.getEntityManager(appId);
+                                    ServiceManager serviceManager = smf.getServiceManager(appId);
+                                    final ApplicationQueueManager manager = new ApplicationQueueManager(
+                                            new JobScheduler(serviceManager, entityManager),
+                                            entityManager,
+                                            queueManager,
+                                            metricsService
+                                    );
+
+                                    return groupedObservable //buffer all of your notifications into a sender and send.
+                                            .buffer(ApplicationQueueManager.BATCH_SIZE)
+                                            .flatMap(new Func1<List<ApplicationQueueMessage>, Observable<?>>() {
+                                                @Override
+                                                public Observable<?> call(List<ApplicationQueueMessage> queueMessages) {
+                                                    return manager.sendBatchToProviders(queueMessages);
+                                                }
+                                            });
+                                }
+                            })
+                            .doOnError(new Action1<Throwable>() {
+                                @Override
+                                public void call(Throwable throwable) {
+                                    LOG.error("Failed while listening",throwable);
+                                }
+                            })
+                            .toBlocking()
+                            .last();
+                    LOG.info("Messages sent in batch");
+
+                }
+                else{
+                    Thread.sleep(sleepPeriod);
+                }
+                //send to the providers
+                consecutiveExceptions.set(0);
+            }catch (Exception ex){
+                LOG.error("failed to dequeue",ex);
+                if(consecutiveExceptions.getAndIncrement() > MAX_CONSECUTIVE_FAILS){
+                    LOG.error("killing message listener; too many failures");
+                    break;
+                }
+            }
+        }
+    }
+
+    public void stop(){
+        for(Future future : futures){
+            future.cancel(true);
+        }
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueManager.java
new file mode 100644
index 0000000..3abe6b2
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueManager.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.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.entities.Notifier;
+
+import java.util.HashMap;
+import java.util.Set;
+
+/**
+ * Created by ApigeeCorporation on 9/4/14.
+ */
+public interface QueueManager {
+
+    public HashMap<Object,Notifier> getNotifierMap();
+
+    public void asyncCheckForInactiveDevices(Set<Notifier> notifiers) throws Exception ;
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
new file mode 100644
index 0000000..9f0a0e6
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/SingleQueueTaskManager.java
@@ -0,0 +1,224 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
+
+public class SingleQueueTaskManager implements NotificationsTaskManager {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(TaskManager.class);
+    private final String path;
+    private final QueueManager proxy;
+
+    private Notification notification;
+    private AtomicLong successes = new AtomicLong();
+    private AtomicLong failures = new AtomicLong();
+    private org.apache.usergrid.mq.QueueManager qm;
+    private EntityManager em;
+    private ConcurrentHashMap<UUID, ApplicationQueueMessage> messageMap;
+    private boolean hasFinished;
+
+    public SingleQueueTaskManager(EntityManager em, org.apache.usergrid.mq.QueueManager qm, QueueManager proxy, Notification notification) {
+        this.em = em;
+        this.qm = qm;
+        this.path = ApplicationQueueManager.QUEUE_NAME;
+        this.notification = notification;
+        this.proxy = proxy;
+        this.messageMap = new ConcurrentHashMap<UUID, ApplicationQueueMessage>();
+        hasFinished = false;
+    }
+
+    public void addMessage(UUID deviceId, ApplicationQueueMessage message) {
+        messageMap.put(deviceId, message);
+    }
+
+    public void completed(Notifier notifier, Receipt receipt, UUID deviceUUID, String newProviderId) throws Exception {
+        LOG.debug("REMOVED {}", deviceUUID);
+        try {
+            EntityRef deviceRef = new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID);
+            if (receipt != null) {
+                LOG.debug("notification {} sent to device {}. saving receipt.", notification.getUuid(), deviceUUID);
+                receipt.setSent(System.currentTimeMillis());
+                this.saveReceipt(notification, deviceRef, receipt);
+                LOG.debug("notification {} receipt saved for device {}", notification.getUuid(), deviceUUID);
+                successes.incrementAndGet();
+            }
+
+            LOG.debug("notification {} removing device {} from remaining", notification.getUuid(), deviceUUID);
+            qm.commitTransaction(path, messageMap.get(deviceUUID).getTransaction(), null);
+            if (newProviderId != null) {
+                LOG.debug("notification {} replacing device {} notifierId", notification.getUuid(), deviceUUID);
+                replaceProviderId(deviceRef, notifier, newProviderId);
+            }
+
+            LOG.debug("notification {} completed device {}", notification.getUuid(), deviceUUID);
+
+        } finally {
+            LOG.debug("COUNT is: {}", successes.get());
+            if (hasFinished) { //process has finished but notifications are still coming in
+                finishedBatch();
+
+            }
+        }
+    }
+
+    public void failed(Notifier notifier, Receipt receipt, UUID deviceUUID, Object code, String message) throws Exception {
+
+        try {
+            if (LOG.isDebugEnabled()) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("notification ").append(notification.getUuid());
+                sb.append(" for device ").append(deviceUUID);
+                sb.append(" got error ").append(code);
+                LOG.debug(sb.toString());
+            }
+
+            failures.incrementAndGet();
+            if (receipt.getUuid() != null) {
+                successes.decrementAndGet();
+            }
+            receipt.setErrorCode(code);
+            receipt.setErrorMessage(message);
+            this.saveReceipt(notification, new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID), receipt);
+            LOG.debug("notification {} receipt saved for device {}", notification.getUuid(), deviceUUID);
+        } finally {
+            completed(notifier, null, deviceUUID, null);
+        }
+    }
+
+    /*
+    * called from TaskManager - creates a persistent receipt and updates the
+    * passed one w/ the UUID
+    */
+    private void saveReceipt(EntityRef notification, EntityRef device, Receipt receipt) throws Exception {
+        if (receipt.getUuid() == null) {
+            Receipt savedReceipt = em.create(receipt);
+            receipt.setUuid(savedReceipt.getUuid());
+
+            List<EntityRef> entities = Arrays.asList(notification, device);
+            em.addToCollections(entities, Notification.RECEIPTS_COLLECTION, savedReceipt);
+        } else {
+            em.update(receipt);
+        }
+    }
+
+    protected void replaceProviderId(EntityRef device, Notifier notifier,
+                                     String newProviderId) throws Exception {
+        Object value = em.getProperty(device, notifier.getName()
+                + NotificationsService.NOTIFIER_ID_POSTFIX);
+        if (value != null) {
+            em.setProperty(device, notifier.getName() + NotificationsService.NOTIFIER_ID_POSTFIX, newProviderId);
+        } else {
+            value = em.getProperty(device, notifier.getUuid()
+                    + NotificationsService.NOTIFIER_ID_POSTFIX);
+            if (value != null) {
+                em.setProperty(device, notifier.getUuid() + NotificationsService.NOTIFIER_ID_POSTFIX, newProviderId);
+            }
+        }
+    }
+
+    public void finishedBatch() throws Exception {
+        synchronized (this) { //avoid issues with counting
+            long successes = this.successes.getAndSet(0); //reset counters
+            long failures = this.failures.getAndSet(0); //reset counters
+            this.hasFinished = true;
+
+            // refresh notification
+            Notification notification = em.get(this.notification.getUuid(), Notification.class);
+            notification.setModified(System.currentTimeMillis());
+
+            Map<String, Object> properties;
+            Map<String, Long> stats;
+            String statsKey = "statistics_batch";
+
+            //write out current results to a set so no overlap in multiple writes will occur
+            if (successes + failures > 0) {
+                properties = new HashMap<String, Object>(4);
+                stats = new HashMap<String, Long>(2);
+                stats.put("sent", successes);
+                stats.put("errors", failures);
+                properties.put(statsKey + "_" + System.currentTimeMillis(), stats);
+                properties.put("modified", notification.getModified());
+                em.updateProperties(notification, properties);
+            }
+
+            //resum the stats
+            properties = em.getProperties(notification); // re-read
+            long sent = 0;
+            long errors = 0;
+            for (String key : properties.keySet()) {
+                if (key.contains(statsKey)) {
+                    stats = (Map<String, Long>) properties.get(key);
+                    sent += stats.get("sent");
+                    errors += stats.get("errors");
+                }
+            }
+
+            //and write them out again, this will produce the most accurate count
+            stats = new HashMap<String, Long>(2);
+            stats.put("sent", sent);
+            stats.put("errors", errors);
+            notification.setStatistics(stats);
+
+            if (LOG.isInfoEnabled()) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("notification ").append(notification.getUuid());
+                sb.append(" sending to ").append(sent + errors);
+                LOG.info(sb.toString());
+            }
+
+            //none of this is known and should you ever do this
+            if (notification.getExpectedCount() <= (errors + sent)) {
+                notification.setFinished(notification.getModified());
+                properties.put("finished", notification.getModified());
+                properties.put("state", notification.getState());
+
+                if (LOG.isInfoEnabled()) {
+                    long elapsed = notification.getFinished() - notification.getStarted();
+                    StringBuilder sb = new StringBuilder();
+                    sb.append("done sending to devices in ").append(elapsed).append(" ms");
+                    LOG.info(sb.toString());
+                }
+            }
+
+            LOG.info("notification finished batch: {}", notification.getUuid());
+            em.updateProperties(notification, properties);
+            em.update(notification);
+        }
+
+        Set<Notifier> notifiers = new HashSet<Notifier>(proxy.getNotifierMap().values()); // remove dups
+        proxy.asyncCheckForInactiveDevices(notifiers);
+    }
+
+
+    protected void hasFinished(boolean hasFinished) {
+        this.hasFinished = hasFinished;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index 85c4a16..9a5b632 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -37,7 +37,7 @@ import org.apache.usergrid.persistence.entities.Device;
  * mean that all work is done, however, as delivery errors may come in after a
  * notification is "sent."
  */
-public class TaskManager {
+public class TaskManager implements NotificationsTaskManager {
 
     // period to poll for batch completion (keep well under Job scheduler
     // heartbeat value!)

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
index 1ae0591..322c4bf 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskTracker.java
@@ -22,29 +22,30 @@ import org.apache.usergrid.persistence.entities.Receipt;
 
 import java.util.UUID;
 
+
 public class TaskTracker {
 
     private Notifier notifier;
-    private TaskManager taskManager;
+    private NotificationsTaskManager taskManager;
     private Receipt receipt;
-    private UUID id;
+    private UUID deviceId;
 
-    public TaskTracker(Notifier notifier, TaskManager taskManager, Receipt receipt, UUID id) {
+    public TaskTracker(Notifier notifier, NotificationsTaskManager taskManager, Receipt receipt, UUID deviceId) {
         this.notifier = notifier;
         this.taskManager = taskManager;
         this.receipt = receipt;
-        this.id = id;
+        this.deviceId = deviceId;
     }
 
     public void completed() throws Exception {
-        taskManager.completed(notifier, receipt, id, null);
+        taskManager.completed(notifier, receipt, deviceId, null);
     }
 
     public void failed(Object code, String message) throws Exception {
-        taskManager.failed(notifier, receipt, id, code, message);
+        taskManager.failed(notifier, receipt, deviceId, code, message);
     }
 
     public void completed(String newToken) throws Exception {
-        taskManager.completed(notifier, receipt, id, newToken);
+        taskManager.completed(notifier, receipt, deviceId, newToken);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index 39748e1..be47f08 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -89,4 +89,7 @@
 
   <bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
 
+  <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener" scope="singleton"/>
+
+
 </beans>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0a13340f/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index bfa52e7..7c68b7f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -20,6 +20,7 @@ import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.entities.Notification;
 import org.apache.usergrid.persistence.entities.Receipt;
 import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.ServiceManagerFactory;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Rule;
@@ -30,14 +31,20 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.usergrid.services.AbstractServiceIT;
+import org.springframework.beans.factory.annotation.Autowired;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
+
 public class AbstractServiceNotificationIT extends AbstractServiceIT {
     private NotificationsService ns;
+    @Autowired
+    private ServiceManagerFactory smf;
 
+    @Autowired
+    private EntityManagerFactory emf;
     @Rule
     public TestName name = new TestName();
 
@@ -57,7 +64,6 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
 
     protected Notification scheduleNotificationAndWait(Notification notification)
             throws Exception {
-        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
         long timeout = System.currentTimeMillis() + 60000;
         while (System.currentTimeMillis() < timeout) {
             Thread.sleep(200);
@@ -79,7 +85,7 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
         List<EntityRef> list =new ArrayList<EntityRef>();//get all
         PagingResultsIterator it = new PagingResultsIterator(r);
         while(it.hasNext()){
-           list.add((EntityRef)it.next());
+            list.add((EntityRef)it.next());
         }
         return list;
     }
@@ -92,7 +98,7 @@ public class AbstractServiceNotificationIT extends AbstractServiceIT {
             Thread.sleep(200);
             receipts =getNotificationReceipts(notification);
             if (receipts.size()==expected) {
-                 break;
+                break;
             }
         }
         assertEquals(expected, receipts.size());


[20/33] git commit: update limit

Posted by sn...@apache.org.
update limit


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

Branch: refs/heads/two-dot-o
Commit: ddc219c63b1e984f6d5638cdbb0c5a22affba8bc
Parents: 1e7a1ae
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Aug 21 08:26:01 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Aug 21 08:26:01 2014 -0600

----------------------------------------------------------------------
 .../services/notifications/apns/NotificationsServiceIT.java      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/ddc219c6/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index 0f89b21..ed15eeb 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -344,7 +344,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         payloads.clear();
         StringBuilder sb = new StringBuilder();
         sb.append("{\"x\":\"");
-        while (sb.length() < 255) {
+        while (sb.length() < 2047) {
             sb.append("x");
         }
         sb.append("\"}");
@@ -358,7 +358,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
             fail("invalid payload should have been rejected");
         } catch (Exception ex) {
             assertEquals(ex.getMessage(),
-                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
+                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 2048 characters or less");
             // ok
         }
     }


[14/33] move tests

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
deleted file mode 100644
index c30edb7..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
+++ /dev/null
@@ -1,868 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed 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.usergrid.services.notifications.apns;
-
-import com.relayrides.pushy.apns.*;
-import com.relayrides.pushy.apns.util.*;
-import org.apache.commons.io.IOUtils;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.services.notifications.AbstractServiceNotificationTest;
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.*;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.services.notifications.*;
-import org.junit.After;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.InputStream;
-import java.net.SocketException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.usergrid.services.ServiceAction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
-
-// todo: test reschedule on delivery time change
-// todo: test restart of queuing
-public class NotificationsServiceTest extends AbstractServiceNotificationTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger(NotificationsServiceTest.class);
-
-    /**
-     * set to true to run tests against actual Apple servers - but they may not
-     * all run correctly
-     */
-    private static final boolean USE_REAL_CONNECTIONS = false;
-    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "apple" : "noop";
-
-    private static final String PUSH_TOKEN = "29026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
-
-    private Notifier notifier;
-    private Device device1, device2;
-    private Group group1;
-    private User user1;
-    private NotificationsService ns;
-
-    @Override
-    @Before
-    public void before() throws Exception {
-        super.before();
-        // create apns notifier //
-        NotificationsQueueManager.IS_TEST = true;
-
-        app.clear();
-        app.put("name", "apns");
-        app.put("provider",PROVIDER);
-        app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
-        notifier = app.getEm().get(e.getUuid(), Notifier.class);
-        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
-
-        // create devices //
-
-        app.clear();
-        app.put(notifierKey, PUSH_TOKEN);
-        app.put("name", "device1");
-
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
-
-        app.clear();
-        app.put(notifierKey, PUSH_TOKEN);
-        app.put("name", "device2");
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device2 = app.getEm().get(e.getUuid(), Device.class);
-
-        // create User
-        app.put( "username", "edanuff" );
-        app.put( "email", "ed@anuff.com" );
-//        user1 = (User)app.testRequest( ServiceAction.POST, 1, "users" ).getEntity();
-//        app.getEm().createConnection(user1, "devices", device1);
-//        app.getEm().createConnection(user1, "devices", device2);
-
-        // create Group
-        app.put( "path", "path" );
-        app.put( "title", "group" );
-        group1 = (Group) app.testRequest( ServiceAction.POST, 1, "groups" ).getEntity();
-
-//        app.getEm().createConnection(group1, "users", user1);
-
-        ns = getNotificationService();
-    }
-
-    @After
-    public void after() throws Exception {
-    }
-
-    @Test
-    public void singlePushNotification() throws Exception {
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-
-
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-//        // verify Query for CREATED state
-        Query query = new Query();
-        query.addFilter("state='"+Notification.State.STARTED.toString()+"'");
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        // perform push //
-
-        notification = scheduleNotificationAndWait(notification);
-
-        // verify Query for FINISHED state
-        query = new Query();
-        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
-        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
-                "notifications", query);
-        entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        checkReceipts(notification, 1);
-        checkStatistics(notification, 1, 0);
-    }
-
-    @Test
-    public void pushWithNoValidDevicesShouldComplete() throws Exception {
-
-        // create unrelated notifier
-
-        app.clear();
-        app.put("name", "gcm");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", "xxx");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-
-        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-        String key = "gcm" + NOTIFIER_ID_POSTFIX;
-
-        // create unrelated device
-
-        app.clear();
-        app.put(key, PUSH_TOKEN);
-        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        Device device = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device.getProperty(key), PUSH_TOKEN);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-
-
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("started", System.currentTimeMillis());
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device);
-
-        // verify Query for CREATED state
-        Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.STARTED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        // perform push //
-
-        ns.getQueueManager().processBatchAndReschedule(notification, null);
-
-        // verify Query for FINISHED state
-        query = new Query();
-        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
-        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
-                "notifications", query);
-        entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        notification = (Notification) entity.toTypedEntity();
-        checkReceipts(notification, 0);
-        checkStatistics(notification, 0, 0);
-    }
-
-    @Test
-    public void scheduledNotification() throws Exception {
-
-        // create push notification //
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("deliver", System.currentTimeMillis() + 240000);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // delay until the scheduler has time to run
-        Thread.sleep(500);
-
-        // verify Query for SCHEDULED state
-        Query query = new Query();
-        query.addEqualityFilter("state",
-                Notification.State.SCHEDULED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        try {
-            e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
-                    e.getUuid()).getEntity();
-        }catch (Exception deleteException){
-            LOG.error("Couldn't delete",deleteException);
-        }
-        app.getEm().get(e.getUuid(), Notification.class);
-    }
-
-    @Test
-    public void badPayloads() throws Exception {
-
-        MockSuccessfulProviderAdapter.uninstall(ns);
-
-        // bad payloads format
-
-        app.clear();
-        app.put("payloads", "{asdf}");
-
-        try {
-            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                    .getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // bad notifier
-
-        Map<String, String> payloads = new HashMap<String, String>(2);
-        app.put("payloads", payloads);
-        payloads.put("xxx", "");
-        try {
-            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                    .getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // payload too long
-
-        // need the real provider for this one...
-        app.clear();
-        app.put("name", "apns2");
-        app.put("provider", "apple");
-        app.put("environment", "development");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-
-        payloads.clear();
-        StringBuilder sb = new StringBuilder();
-        sb.append("{\"x\":\"");
-        while (sb.length() < 255) {
-            sb.append("x");
-        }
-        sb.append("\"}");
-        payloads.put(notifier2.getUuid().toString(), sb.toString());
-
-        app.clear();
-        app.put("payloads", payloads);
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (Exception ex) {
-            assertEquals(ex.getMessage(),
-                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
-            // ok
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badToken() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            APNsNotification apnsNotification = APNsNotification
-                                    .create(providerId, payload.toString(),
-                                            notification, tracker);
-                            apnsNotification.messageSent();
-                            apnsNotification
-                                    .messageSendFailed( RejectedNotificationReason.INVALID_TOKEN);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        properties.put("payloads", payloads);
-        properties.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkStatistics(notification, 0, 1);
-
-        notification = (Notification) app.getEm().get(notification)
-                .toTypedEntity();
-        checkReceipts(notification, 1);
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
-        assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
-    }
-
-    @Test
-    public void twoDevicesOneNotifier() throws Exception {
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2);
-    }
-
-    @Test
-    public void twoDevicesTwoNotifiers() throws Exception {
-
-        // create a 2nd notifier //
-        app.clear();
-        app.put("name", "apns2");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
-
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-        assertEquals(notifier2.getName(), "apns2");
-        assertEquals(notifier2.getProvider(), PROVIDER);
-        assertEquals(notifier2.getEnvironment(), "development");
-
-        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
-        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
-        device2.setProperty(key, null);
-        device2.setProperty(key2, null);
-        app.getEm().update(device2);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        payloads.put(notifier2.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
-    }
-
-    @Test
-    public void oneDeviceTwoNotifiers() throws Exception {
-
-        // create a 2nd notifier //
-        Object nameValue = "apns2";
-        Object environValue = "development";
-
-        app.clear();
-        app.put("name", nameValue);
-        app.put("provider", PROVIDER);
-        app.put("environment", environValue);
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
-
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-        assertEquals(notifier2.getName(), nameValue);
-        assertEquals(notifier2.getProvider(), PROVIDER);
-        assertEquals(notifier2.getEnvironment(), environValue);
-
-        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
-        device1.setProperty(key2, PUSH_TOKEN);
-        app.getEm().update(device1);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        payloads.put(notifier2.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2);
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badCertificate() throws Exception {
-
-        // create an apns notifier with the wrong certificate //
-
-        app.clear();
-        app.put("name", "prod_apns");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "empty.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        notifier = app.getEm().get(e.getUuid(), Notifier.class);
-
-        // mock error (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void testConnection(Notifier notifier)
-                                throws ConnectionException {
-                            Exception e = new SocketException(
-                                    "Connection closed by remote host");
-                            throw new ConnectionException(e.getMessage(), e);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-
-        try {
-            ns.getQueueManager().processBatchAndReschedule(notification,null);
-            fail("testConnection() should have failed");
-        } catch (Exception ex) {
-            // good, there should be an error
-        }
-
-        // verify Query for FAILED state
-        Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.FAILED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void inactiveDeviceUpdate() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public Map<String, Date> getInactiveDevices(
-                                Notifier notifier, EntityManager em)
-                                throws Exception {
-                            return Collections.singletonMap(PUSH_TOKEN,
-                                    new Date());
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        assertNotNull(device1.getProperty(notifier.getName()
-                + NOTIFIER_ID_POSTFIX));
-        assertNotNull(device2.getProperty(notifier.getName()
-                + NOTIFIER_ID_POSTFIX));
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        // check provider IDs //
-
-        device1 = app.getEm().get(device1, Device.class);
-        assertNull(device1
-                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-        device2 = app.getEm().get(device2, Device.class);
-        assertNull(device2
-                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-    }
-
-    @Test
-    public void batchTest() throws Exception {
-
-        final int NUM_DEVICES = 50;
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        // create a notification
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-        final Notification notification = (Notification) e.toTypedEntity();
-
-        // create a bunch of devices and add them to the notification
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", app.getProperties());
-            ns.addDevice(notification, entity);
-        }
-
-        // perform push //
-        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
-        NotificationsQueueManager.BATCH_SIZE = 10;
-        try {
-            ExecutorService pool = Executors
-                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
-            pool.submit(new Runnable() {
-                @Override
-                public void run() {
-                        try {
-                             scheduleNotificationAndWait(notification);
-                        }catch (Exception e){}
-                }});
-        } finally {
-            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
-        }
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    @Ignore("Run only if you need to.")
-    @Test
-    public void loadTest() throws Exception {
-
-        MockSuccessfulProviderAdapter.install(ns, true);
-
-        final int NUM_DEVICES = 10000;
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        // create a notification
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-        Notification notification = (Notification) e.toTypedEntity();
-
-        // create a bunch of devices and add them to the notification
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", app.getProperties());
-            ns.addDevice(notification, entity);
-        }
-
-        long time = System.currentTimeMillis();
-        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
-                System.currentTimeMillis() - time);
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    private String getPayload(){
-        ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
-        builder.setAlertBody("Hello, World!");
-        builder.setSoundFileName("chime");
-        String payload = builder.buildWithDefaultMaximumLength();
-        return payload;
-    }
-    // todo: can't do the following tests here. do it in the REST tier...
-    // private Notification postNotification(String path) throws Exception {
-    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-    // String payload =
-    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
-    // Map<String, String> payloads = new HashMap<String, String>(1);
-    // payloads.put(notifier.getUuid().toString(), payload);
-    // properties.put("payloads", payloads);
-    //
-    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
-    // path).getEntity();
-    // Thread.sleep(1000); // this sucks
-    // Notification notification = app.getEm().get(e, Notification.class);
-    // return notification;
-    // }
-    //
-    // @Test
-    // public void matrixPushDevice() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaUser() throws Exception {
-    //
-    // Notification notification = postNotification("users/" + user1.getName() +
-    // "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaGroup() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushDeviceQuery() throws Exception {
-    //
-    // Notification notification = postNotification("devices;ql=name=" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushUserQuery() throws Exception {
-    //
-    // Notification notification = postNotification("users;ql=/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
new file mode 100644
index 0000000..989c2ce
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -0,0 +1,546 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.services.notifications.gcm;
+
+import org.apache.usergrid.services.notifications.AbstractServiceNotificationIT;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.*;
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+public class NotificationsServiceIT extends AbstractServiceNotificationIT {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(NotificationsServiceIT.class);
+
+    /**
+     * set to true to run tests against actual GCM servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "google"
+            : "noop";
+
+    private static final String API_KEY = "AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM";
+    private static final String PUSH_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+
+        // create gcm notifier //
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+
+        notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(key), PUSH_TOKEN);
+
+        app.put(key, PUSH_TOKEN);
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+        ns = getNotificationService();
+    }
+
+    @Test
+    public void emptyPushNotification() throws Exception {
+
+        app.clear();
+        app.put("name", "foo");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Notifier n = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put("foo", payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 0);
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void singlePushNotificationViaUser() throws Exception {
+
+        app.clear();
+
+        app.put("username", "asdf");
+        app.put("email", "asdf@adsf.com");
+        Entity user = app.testRequest(ServiceAction.POST, 1, "users")
+                .getEntity();
+        assertNotNull(user);
+        Entity device = app.testRequest(ServiceAction.POST, 1, "users",
+                user.getUuid(), "devices", device1.getUuid()).getEntity();
+        assertEquals(device.getUuid(), device1.getUuid());
+
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void twoBatchNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device2);
+        ns.addDevice(notification, device1);
+
+        // reduce Batch size to 1
+        Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
+        field.setAccessible(true);
+        int multicastSize = field.getInt(GCMAdapter.class);
+        try {
+            field.setInt(GCMAdapter.class, 1);
+
+            // perform push //
+            notification = scheduleNotificationAndWait(notification);
+
+            checkReceipts(notification, 2);
+        } finally {
+            field.setInt(GCMAdapter.class, multicastSize);
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void providerIdUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        final String newProviderId = "newProviderId";
+        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void sendNotification(String providerId, Notifier notifier,
+                    Object payload, Notification notification,
+                    TaskTracker tracker) throws Exception {
+                tracker.completed(newProviderId);
+            }
+        });
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+
+        Device device = (Device) app.getEm().get(device1).toTypedEntity();
+        assertEquals(newProviderId,
+                device.getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "gcm2");
+        app.put("provider", "google");
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 4080) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals("java.lang.IllegalArgumentException: GCM payloads must be 4096 characters or less",
+                    ex.getMessage());
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            tracker.failed("InvalidRegistration",
+                                    "InvalidRegistration");
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // device w/ bad token
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        assertEquals(1, receipts.size());
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals("InvalidRegistration", receipt.getErrorCode());
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badAPIKey() throws Exception {
+
+        if (!USE_REAL_CONNECTIONS) {
+            // mock action (based on verified actual behavior) //
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            Exception e = new IOException();
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // save bad API key
+        app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification, null);
+            fail("Should have received a ConnectionException");
+        } catch (ConnectionException ex) {
+            // good
+        }
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        final int NUM_DEVICES = 10000;
+
+        // create notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // create a bunch of devices and add them to the notification
+        properties = new LinkedHashMap<String, Object>();
+        properties.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", properties);
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    // @Test
+    // public void inactiveDeviceUpdate() throws Exception {
+    //
+    // if (!USE_REAL_CONNECTIONS) {
+    // // mock action (based on verified actual behavior) //
+    // NotificationsService.providerAdapters.put("apple", new
+    // MockSuccessfulProviderAdapter() {
+    // public Map<String,Date> getInactiveDevices(Notifier notifier,
+    // EntityManager em) throws Exception {
+    // return Collections.singletonMap(PUSH_TOKEN, new Date());
+    // }
+    // });
+    // }
+    //
+    // // create push notification //
+    //
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    // properties.put("queued", System.currentTimeMillis());
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // "notifications").getEntity();
+    // testRequest(sm, ServiceAction.GET, 1, null, "notifications",
+    // e.getUuid());
+    //
+    // Notification notification = em.get(e.getUuid(), Notification.class);
+    // assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),
+    // payload);
+    //
+    // ns.addDevice(notification, device1);
+    // ns.addDevice(notification, device2);
+    //
+    // assertNotNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // assertNotNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    //
+    // // perform push //
+    // notification = scheduleNotificationAndWait(notification);
+    //
+    // // check provider IDs //
+    //
+    // device1 = em.get(device1, Device.class);
+    // assertNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // device2 = em.get(device2, Device.class);
+    // assertNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/dd4e7650/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
deleted file mode 100644
index 7be8e88..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
+++ /dev/null
@@ -1,546 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed 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.usergrid.services.notifications.gcm;
-
-import org.apache.usergrid.services.notifications.AbstractServiceNotificationTest;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.TaskTracker;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.*;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.entities.Device;
-import org.apache.usergrid.services.ServiceAction;
-
-import static org.junit.Assert.*;
-import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
-
-public class NotificationsServiceTest extends AbstractServiceNotificationTest {
-
-    private static final Logger LOG = LoggerFactory
-            .getLogger(NotificationsServiceTest.class);
-
-    /**
-     * set to true to run tests against actual GCM servers - but they may not
-     * all run correctly
-     */
-    private static final boolean USE_REAL_CONNECTIONS = false;
-    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "google"
-            : "noop";
-
-    private static final String API_KEY = "AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM";
-    private static final String PUSH_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
-
-    private Notifier notifier;
-    private Device device1, device2;
-    private NotificationsService ns;
-
-    @Override
-    @Before
-    public void before() throws Exception {
-        super.before();
-
-        // create gcm notifier //
-
-        app.clear();
-        app.put("name", "gcm");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-
-        notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
-
-        // create devices //
-
-        app.clear();
-        app.put(key, PUSH_TOKEN);
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device1.getProperty(key), PUSH_TOKEN);
-
-        app.put(key, PUSH_TOKEN);
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device2 = app.getEm().get(e.getUuid(), Device.class);
-        ns = getNotificationService();
-    }
-
-    @Test
-    public void emptyPushNotification() throws Exception {
-
-        app.clear();
-        app.put("name", "foo");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-        Notifier n = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put("foo", payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 0);
-    }
-
-    @Test
-    public void singlePushNotification() throws Exception {
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-    }
-
-    @Test
-    public void singlePushNotificationViaUser() throws Exception {
-
-        app.clear();
-
-        app.put("username", "asdf");
-        app.put("email", "asdf@adsf.com");
-        Entity user = app.testRequest(ServiceAction.POST, 1, "users")
-                .getEntity();
-        assertNotNull(user);
-        Entity device = app.testRequest(ServiceAction.POST, 1, "users",
-                user.getUuid(), "devices", device1.getUuid()).getEntity();
-        assertEquals(device.getUuid(), device1.getUuid());
-
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-    }
-
-    @Test
-    public void twoBatchNotification() throws Exception {
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device2);
-        ns.addDevice(notification, device1);
-
-        // reduce Batch size to 1
-        Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
-        field.setAccessible(true);
-        int multicastSize = field.getInt(GCMAdapter.class);
-        try {
-            field.setInt(GCMAdapter.class, 1);
-
-            // perform push //
-            notification = scheduleNotificationAndWait(notification);
-
-            checkReceipts(notification, 2);
-        } finally {
-            field.setInt(GCMAdapter.class, multicastSize);
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void providerIdUpdate() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        final String newProviderId = "newProviderId";
-        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void sendNotification(String providerId, Notifier notifier,
-                    Object payload, Notification notification,
-                    TaskTracker tracker) throws Exception {
-                tracker.completed(newProviderId);
-            }
-        });
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-
-        Device device = (Device) app.getEm().get(device1).toTypedEntity();
-        assertEquals(newProviderId,
-                device.getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-    }
-
-    @Test
-    public void badPayloads() throws Exception {
-
-        // bad payloads format
-
-        app.clear();
-        app.put("payloads", "{asdf}");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // bad notifier
-
-        Map<String, String> payloads = new HashMap<String, String>(2);
-        app.put("payloads", payloads);
-        payloads.put("xxx", "");
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // payload too long
-
-        // need the real provider for this one...
-        app.clear();
-        app.put("name", "gcm2");
-        app.put("provider", "google");
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-
-        payloads.clear();
-        StringBuilder sb = new StringBuilder();
-        sb.append("{\"x\":\"");
-        while (sb.length() < 4080) {
-            sb.append("x");
-        }
-        sb.append("\"}");
-        payloads.put(notifier2.getUuid().toString(), sb.toString());
-
-        app.clear();
-        app.put("payloads", payloads);
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (Exception ex) {
-            assertEquals("java.lang.IllegalArgumentException: GCM payloads must be 4096 characters or less",
-                    ex.getMessage());
-            // ok
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badToken() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("google",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            tracker.failed("InvalidRegistration",
-                                    "InvalidRegistration");
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        // device w/ bad token
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
-
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        assertEquals(1, receipts.size());
-        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
-        assertEquals("InvalidRegistration", receipt.getErrorCode());
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badAPIKey() throws Exception {
-
-        if (!USE_REAL_CONNECTIONS) {
-            // mock action (based on verified actual behavior) //
-            ns.providerAdapters.put("google",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            Exception e = new IOException();
-                            throw new ConnectionException(e.getMessage(), e);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // save bad API key
-        app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
-
-        // perform push //
-
-        try {
-            ns.getQueueManager().processBatchAndReschedule(notification, null);
-            fail("Should have received a ConnectionException");
-        } catch (ConnectionException ex) {
-            // good
-        }
-    }
-
-    @Ignore("Run only if you need to.")
-    @Test
-    public void loadTest() throws Exception {
-
-        final int NUM_DEVICES = 10000;
-
-        // create notification //
-
-        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        properties.put("payloads", payloads);
-        properties.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        // create a bunch of devices and add them to the notification
-        properties = new LinkedHashMap<String, Object>();
-        properties.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", properties);
-            ns.addDevice(notification, entity);
-        }
-
-        long time = System.currentTimeMillis();
-        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
-                System.currentTimeMillis() - time);
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    // @Test
-    // public void inactiveDeviceUpdate() throws Exception {
-    //
-    // if (!USE_REAL_CONNECTIONS) {
-    // // mock action (based on verified actual behavior) //
-    // NotificationsService.providerAdapters.put("apple", new
-    // MockSuccessfulProviderAdapter() {
-    // public Map<String,Date> getInactiveDevices(Notifier notifier,
-    // EntityManager em) throws Exception {
-    // return Collections.singletonMap(PUSH_TOKEN, new Date());
-    // }
-    // });
-    // }
-    //
-    // // create push notification //
-    //
-    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-    // String payload =
-    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
-    // Map<String, String> payloads = new HashMap<String, String>(1);
-    // payloads.put(notifier.getUuid().toString(), payload);
-    // properties.put("payloads", payloads);
-    // properties.put("queued", System.currentTimeMillis());
-    //
-    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
-    // "notifications").getEntity();
-    // testRequest(sm, ServiceAction.GET, 1, null, "notifications",
-    // e.getUuid());
-    //
-    // Notification notification = em.get(e.getUuid(), Notification.class);
-    // assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),
-    // payload);
-    //
-    // ns.addDevice(notification, device1);
-    // ns.addDevice(notification, device2);
-    //
-    // assertNotNull(device1.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // assertNotNull(device2.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    //
-    // // perform push //
-    // notification = scheduleNotificationAndWait(notification);
-    //
-    // // check provider IDs //
-    //
-    // device1 = em.get(device1, Device.class);
-    // assertNull(device1.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // device2 = em.get(device2, Device.class);
-    // assertNull(device2.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // }
-}


[13/33] git commit: move tests

Posted by sn...@apache.org.
move tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/3c761ff4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/3c761ff4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/3c761ff4

Branch: refs/heads/two-dot-o
Commit: 3c761ff4b2b51be594efe02ed660a8790858444b
Parents: 51e0931
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Aug 19 17:02:28 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Aug 19 17:02:28 2014 -0600

----------------------------------------------------------------------
 .../AbstractServiceNotificationTest.java        | 108 ---
 .../apns/MockSuccessfulProviderAdapter.java     | 101 ---
 .../apns/NotificationsServiceTest.java          | 870 -------------------
 .../gcm/MockSuccessfulProviderAdapter.java      |  72 --
 .../gcm/NotificationsServiceTest.java           | 547 ------------
 .../notifiers/NotifiersServiceTest.java         | 224 -----
 .../usergrid/services/NotifiersServiceTest.java | 224 +++++
 .../AbstractServiceNotificationTest.java        | 107 +++
 .../apns/MockSuccessfulProviderAdapter.java     |  99 +++
 .../apns/NotificationsServiceTest.java          | 868 ++++++++++++++++++
 .../gcm/MockSuccessfulProviderAdapter.java      |  72 ++
 .../gcm/NotificationsServiceTest.java           | 546 ++++++++++++
 12 files changed, 1916 insertions(+), 1922 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
deleted file mode 100644
index d3d0727..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/AbstractServiceNotificationTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package org.apache.usergrid.notifications;
-
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.usergrid.services.AbstractServiceIT;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-public class AbstractServiceNotificationTest extends AbstractServiceIT {
-    private NotificationsService ns;
-
-    @Rule
-    public TestName name = new TestName();
-
-    @BeforeClass
-    public static void beforeClass() {
-    }
-
-    @Before
-    public void before() throws Exception {
-
-    }
-
-    protected NotificationsService getNotificationService(){
-        ns = (NotificationsService) app.getSm().getService("notifications");
-        return ns;
-    }
-
-    protected Notification scheduleNotificationAndWait(Notification notification)
-            throws Exception {
-        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            notification = app.getEm().get(notification.getUuid(),
-                    Notification.class);
-            if (notification.getFinished() != null) {
-                return notification;
-            }
-        }
-        fail("Notification failed to complete");
-        return null;
-    }
-
-    protected List<EntityRef> getNotificationReceipts(EntityRef notification)
-            throws Exception {
-        Results r = app.getEm().getCollection(notification,
-                Notification.RECEIPTS_COLLECTION, null, 1000000,
-                Query.Level.REFS, false);
-        List<EntityRef> list =new ArrayList<EntityRef>();//get all
-        PagingResultsIterator it = new PagingResultsIterator(r);
-        while(it.hasNext()){
-           list.add((EntityRef)it.next());
-        }
-        return list;
-    }
-
-    protected void checkReceipts(Notification notification, int expected)
-            throws Exception {
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            receipts =getNotificationReceipts(notification);
-            if (receipts.size()==expected) {
-                 break;
-            }
-        }
-        assertEquals(expected, receipts.size());
-        for (EntityRef receipt : receipts) {
-            Receipt r = app.getEm().get(receipt, Receipt.class);
-            assertNotNull(r.getSent());
-            assertNotNull(r.getPayload());
-            assertNotNull(r.getNotifierId());
-            EntityRef source = getNotificationService().getSourceNotification(r);
-            assertEquals(source.getUuid(), notification.getUuid());
-        }
-    }
-
-    protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
-        Map<String, Long> statistics = null;
-        long timeout = System.currentTimeMillis() + 60000;
-        while (System.currentTimeMillis() < timeout) {
-            Thread.sleep(200);
-            statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
-            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
-                break;
-            }
-        }
-        assertEquals(sent, statistics.get("sent").longValue());
-        assertEquals(errors, statistics.get("errors").longValue());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
deleted file mode 100644
index d780150..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/MockSuccessfulProviderAdapter.java
+++ /dev/null
@@ -1,101 +0,0 @@
-package org.apache.usergrid.notifications.apns;
-
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.apache.usergrid.services.notifications.apns.APNsNotification;
-import org.apache.usergrid.services.notifications.apns.APNsAdapter;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.apache.usergrid.services.notifications.ProviderAdapter;
-import org.apache.usergrid.services.notifications.TaskTracker;
-
-import java.util.Date;
-import java.util.Map;
-import java.util.Random;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.services.ServicePayload;
-
-public class MockSuccessfulProviderAdapter implements ProviderAdapter {
-
-    private static ProviderAdapter realProviderAdapter;
-
-    public static void install(NotificationsService ns) {
-        install(ns, false);
-    }
-
-    public static void install(NotificationsService ns, boolean doAsync) {
-        if (realProviderAdapter != null)
-            realProviderAdapter = ns.providerAdapters.get("apple");
-        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter(
-                doAsync));
-    }
-
-    public static void uninstall(NotificationsService ns) {
-        if (realProviderAdapter != null) {
-            ns.providerAdapters.put("apple", realProviderAdapter);
-        }
-    }
-
-    private ExecutorService pool;
-
-    public MockSuccessfulProviderAdapter() {
-    }
-
-    public MockSuccessfulProviderAdapter(boolean async) {
-        if (async) {
-            pool = Executors
-                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
-        }
-    }
-
-    @Override
-    public void testConnection(Notifier notifier) throws ConnectionException {
-    }
-
-    @Override
-    public String translatePayload(Object payload) throws Exception {
-        return payload.toString();
-    }
-
-    @Override
-    public Map<String, Date> getInactiveDevices(Notifier notifier,
-            EntityManager em) throws Exception {
-        return null;
-    }
-
-    @Override
-    public void validateCreateNotifier(ServicePayload payload) throws Exception {
-    }
-
-    @Override
-    public void doneSendingNotifications() throws Exception {
-    }
-
-    @Override
-    public void sendNotification(final String providerId,
-            final Notifier notifier, final Object payload,
-            final Notification notification, final TaskTracker tracker)
-            throws Exception {
-
-        final APNsNotification apnsNotification = APNsNotification.create(
-                providerId, payload.toString(), notification, tracker);
-
-        if (pool == null) {
-            apnsNotification.messageSent();
-        } else {
-            pool.submit(new Runnable() {
-                @Override
-                public void run() {
-                    try {
-                        Thread.sleep(new Random().nextInt(100));
-                        apnsNotification.messageSent();
-                    } catch (Exception e) {
-                        e.printStackTrace();
-                    }
-                }
-            });
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
deleted file mode 100644
index a50d942..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/apns/NotificationsServiceTest.java
+++ /dev/null
@@ -1,870 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed 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.usergrid.notifications.apns;
-
-import com.relayrides.pushy.apns.*;
-import com.relayrides.pushy.apns.util.*;
-import org.apache.commons.io.IOUtils;
-import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.*;
-import org.apache.usergrid.persistence.index.query.Query;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
-import org.apache.usergrid.services.notifications.*;
-import org.apache.usergrid.services.notifications.apns.APNsAdapter;
-import org.apache.usergrid.services.notifications.apns.APNsNotification;
-import org.junit.After;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.InputStream;
-import java.net.SocketException;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.usergrid.services.ServiceAction;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
-
-// todo: test reschedule on delivery time change
-// todo: test restart of queuing
-public class NotificationsServiceTest extends AbstractServiceNotificationTest {
-
-    private static final Logger LOG = LoggerFactory.getLogger(NotificationsServiceTest.class);
-
-    /**
-     * set to true to run tests against actual Apple servers - but they may not
-     * all run correctly
-     */
-    private static final boolean USE_REAL_CONNECTIONS = false;
-    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "apple" : "noop";
-
-    private static final String PUSH_TOKEN = "29026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
-
-    private Notifier notifier;
-    private Device device1, device2;
-    private Group group1;
-    private User user1;
-    private NotificationsService ns;
-
-    @Override
-    @Before
-    public void before() throws Exception {
-        super.before();
-        // create apns notifier //
-        NotificationsQueueManager.IS_TEST = true;
-
-        app.clear();
-        app.put("name", "apns");
-        app.put("provider",PROVIDER);
-        app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
-        notifier = app.getEm().get(e.getUuid(), Notifier.class);
-        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
-
-        // create devices //
-
-        app.clear();
-        app.put(notifierKey, PUSH_TOKEN);
-        app.put("name", "device1");
-
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
-
-        app.clear();
-        app.put(notifierKey, PUSH_TOKEN);
-        app.put("name", "device2");
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device2 = app.getEm().get(e.getUuid(), Device.class);
-
-//        // create User
-//        user1 = new User();
-//        user1.setUsername("user1");
-//        user1.setEmail("user1@usergrid.org");
-//        user1 = app.getEm().create(user1);
-//        app.getEm().createConnection(user1, "devices", device1);
-//        app.getEm().createConnection(user1, "devices", device2);
-//
-//        // create Group
-//        group1 = new Group();
-//        group1.setPath("path");
-//        group1 = app.getEm().create(group1);
-//        app.getEm().createConnection(group1, "users", user1);
-
-        ns = getNotificationService();
-    }
-
-    @After
-    public void after() throws Exception {
-    }
-
-    @Test
-    public void singlePushNotification() throws Exception {
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-
-
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-//        // verify Query for CREATED state
-        Query query = new Query();
-//        query.addEqualityFilter("state", Notification.State.STARTED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-//        assertNotNull(entity);
-
-        // perform push //
-
-        notification = scheduleNotificationAndWait(notification);
-
-        // verify Query for FINISHED state
-        query = new Query();
-        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
-        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
-                "notifications", query);
-        entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        checkReceipts(notification, 1);
-        checkStatistics(notification, 1, 0);
-    }
-
-    @Test
-    public void pushWithNoValidDevicesShouldComplete() throws Exception {
-
-        // create unrelated notifier
-
-        app.clear();
-        app.put("name", "gcm");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", "xxx");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-
-        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-        String key = "gcm" + NOTIFIER_ID_POSTFIX;
-
-        // create unrelated device
-
-        app.clear();
-        app.put(key, PUSH_TOKEN);
-        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        Device device = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device.getProperty(key), PUSH_TOKEN);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-
-
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("started", System.currentTimeMillis());
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device);
-
-        // verify Query for CREATED state
-        Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.STARTED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        // perform push //
-
-        ns.getQueueManager().processBatchAndReschedule(notification, null);
-
-        // verify Query for FINISHED state
-        query = new Query();
-        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
-        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
-                "notifications", query);
-        entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        notification = (Notification) entity.toTypedEntity();
-        checkReceipts(notification, 0);
-        checkStatistics(notification, 0, 0);
-    }
-
-    @Test
-    public void scheduledNotification() throws Exception {
-
-        // create push notification //
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("deliver", System.currentTimeMillis() + 240000);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // delay until the scheduler has time to run
-        Thread.sleep(500);
-
-        // verify Query for SCHEDULED state
-        Query query = new Query();
-        query.addEqualityFilter("state",
-                Notification.State.SCHEDULED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-
-        try {
-            e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
-                    e.getUuid()).getEntity();
-        }catch (Exception deleteException){
-            LOG.error("Couldn't delete",deleteException);
-        }
-        app.getEm().get(e.getUuid(), Notification.class);
-    }
-
-    @Test
-    public void badPayloads() throws Exception {
-
-        MockSuccessfulProviderAdapter.uninstall(ns);
-
-        // bad payloads format
-
-        app.clear();
-        app.put("payloads", "{asdf}");
-
-        try {
-            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                    .getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // bad notifier
-
-        Map<String, String> payloads = new HashMap<String, String>(2);
-        app.put("payloads", payloads);
-        payloads.put("xxx", "");
-        try {
-            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                    .getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // payload too long
-
-        // need the real provider for this one...
-        app.clear();
-        app.put("name", "apns2");
-        app.put("provider", "apple");
-        app.put("environment", "development");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-
-        payloads.clear();
-        StringBuilder sb = new StringBuilder();
-        sb.append("{\"x\":\"");
-        while (sb.length() < 255) {
-            sb.append("x");
-        }
-        sb.append("\"}");
-        payloads.put(notifier2.getUuid().toString(), sb.toString());
-
-        app.clear();
-        app.put("payloads", payloads);
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-            fail("invalid payload should have been rejected");
-        } catch (Exception ex) {
-            assertEquals(ex.getMessage(),
-                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
-            // ok
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badToken() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            APNsNotification apnsNotification = APNsNotification
-                                    .create(providerId, payload.toString(),
-                                            notification, tracker);
-                            apnsNotification.messageSent();
-                            apnsNotification
-                                    .messageSendFailed( RejectedNotificationReason.INVALID_TOKEN);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        properties.put("payloads", payloads);
-        properties.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkStatistics(notification, 0, 1);
-
-        notification = (Notification) app.getEm().get(notification)
-                .toTypedEntity();
-        checkReceipts(notification, 1);
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
-        assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
-    }
-
-    @Test
-    public void twoDevicesOneNotifier() throws Exception {
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2);
-    }
-
-    @Test
-    public void twoDevicesTwoNotifiers() throws Exception {
-
-        // create a 2nd notifier //
-        app.clear();
-        app.put("name", "apns2");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
-
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-        assertEquals(notifier2.getName(), "apns2");
-        assertEquals(notifier2.getProvider(), PROVIDER);
-        assertEquals(notifier2.getEnvironment(), "development");
-
-        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
-        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
-        device2.setProperty(key, null);
-        device2.setProperty(key2, null);
-        app.getEm().update(device2);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        payloads.put(notifier2.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
-    }
-
-    @Test
-    public void oneDeviceTwoNotifiers() throws Exception {
-
-        // create a 2nd notifier //
-        Object nameValue = "apns2";
-        Object environValue = "development";
-
-        app.clear();
-        app.put("name", nameValue);
-        app.put("provider", PROVIDER);
-        app.put("environment", environValue);
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
-
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-        assertEquals(notifier2.getName(), nameValue);
-        assertEquals(notifier2.getProvider(), PROVIDER);
-        assertEquals(notifier2.getEnvironment(), environValue);
-
-        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
-        device1.setProperty(key2, PUSH_TOKEN);
-        app.getEm().update(device1);
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        payloads.put(notifier2.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        checkReceipts(notification, 2);
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badCertificate() throws Exception {
-
-        // create an apns notifier with the wrong certificate //
-
-        app.clear();
-        app.put("name", "prod_apns");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "empty.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        notifier = app.getEm().get(e.getUuid(), Notifier.class);
-
-        // mock error (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void testConnection(Notifier notifier)
-                                throws ConnectionException {
-                            Exception e = new SocketException(
-                                    "Connection closed by remote host");
-                            throw new ConnectionException(e.getMessage(), e);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-
-        try {
-            ns.getQueueManager().processBatchAndReschedule(notification,null);
-            fail("testConnection() should have failed");
-        } catch (Exception ex) {
-            // good, there should be an error
-        }
-
-        // verify Query for FAILED state
-        Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.FAILED.toString());
-        Results results = app.getEm().searchCollection(
-                app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void inactiveDeviceUpdate() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("apple",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public Map<String, Date> getInactiveDevices(
-                                Notifier notifier, EntityManager em)
-                                throws Exception {
-                            return Collections.singletonMap(PUSH_TOKEN,
-                                    new Date());
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-        ns.addDevice(notification, device2);
-
-        assertNotNull(device1.getProperty(notifier.getName()
-                + NOTIFIER_ID_POSTFIX));
-        assertNotNull(device2.getProperty(notifier.getName()
-                + NOTIFIER_ID_POSTFIX));
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        // check provider IDs //
-
-        device1 = app.getEm().get(device1, Device.class);
-        assertNull(device1
-                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-        device2 = app.getEm().get(device2, Device.class);
-        assertNull(device2
-                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-    }
-
-    @Test
-    public void batchTest() throws Exception {
-
-        final int NUM_DEVICES = 50;
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        // create a notification
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-        final Notification notification = (Notification) e.toTypedEntity();
-
-        // create a bunch of devices and add them to the notification
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", app.getProperties());
-            ns.addDevice(notification, entity);
-        }
-
-        // perform push //
-        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
-        NotificationsQueueManager.BATCH_SIZE = 10;
-        try {
-            ExecutorService pool = Executors
-                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
-            pool.submit(new Runnable() {
-                @Override
-                public void run() {
-                        try {
-                             scheduleNotificationAndWait(notification);
-                        }catch (Exception e){}
-                }});
-        } finally {
-            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
-        }
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    @Ignore("Run only if you need to.")
-    @Test
-    public void loadTest() throws Exception {
-
-        MockSuccessfulProviderAdapter.install(ns, true);
-
-        final int NUM_DEVICES = 10000;
-
-        app.clear();
-        String payload = getPayload();
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        // create a notification
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-        Notification notification = (Notification) e.toTypedEntity();
-
-        // create a bunch of devices and add them to the notification
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", app.getProperties());
-            ns.addDevice(notification, entity);
-        }
-
-        long time = System.currentTimeMillis();
-        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
-                System.currentTimeMillis() - time);
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    private String getPayload(){
-        ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
-        builder.setAlertBody("Hello, World!");
-        builder.setSoundFileName("chime");
-        String payload = builder.buildWithDefaultMaximumLength();
-        return payload;
-    }
-    // todo: can't do the following tests here. do it in the REST tier...
-    // private Notification postNotification(String path) throws Exception {
-    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-    // String payload =
-    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
-    // Map<String, String> payloads = new HashMap<String, String>(1);
-    // payloads.put(notifier.getUuid().toString(), payload);
-    // properties.put("payloads", payloads);
-    //
-    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
-    // path).getEntity();
-    // Thread.sleep(1000); // this sucks
-    // Notification notification = app.getEm().get(e, Notification.class);
-    // return notification;
-    // }
-    //
-    // @Test
-    // public void matrixPushDevice() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaUser() throws Exception {
-    //
-    // Notification notification = postNotification("users/" + user1.getName() +
-    // "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushViaGroup() throws Exception {
-    //
-    // Notification notification = postNotification("devices/" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushDeviceQuery() throws Exception {
-    //
-    // Notification notification = postNotification("devices;ql=name=" +
-    // device1.getName() + "/notifications");
-    // checkReceipts(notification, 1);
-    // checkStatistics(notification, 1, 0);
-    // }
-    //
-    // @Test
-    // public void matrixPushUserQuery() throws Exception {
-    //
-    // Notification notification = postNotification("users;ql=/notifications");
-    // checkReceipts(notification, 2);
-    // checkStatistics(notification, 2, 0);
-    // }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
deleted file mode 100644
index 12dbe08..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/MockSuccessfulProviderAdapter.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.apache.usergrid.notifications.gcm;
-
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.apache.usergrid.services.notifications.ProviderAdapter;
-import org.apache.usergrid.services.notifications.TaskTracker;
-
-import java.util.Date;
-import java.util.Map;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.services.ServicePayload;
-
-public class MockSuccessfulProviderAdapter implements ProviderAdapter {
-
-    private static ProviderAdapter realProviderAdapter;
-
-    public static void install(NotificationsService ns) {
-        if (realProviderAdapter != null)
-            realProviderAdapter = ns.providerAdapters.get("google");
-        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter());
-    }
-
-    public static void uninstall(NotificationsService ns) {
-        if (realProviderAdapter != null) {
-            ns.providerAdapters.put("google", realProviderAdapter);
-        }
-    }
-
-    public MockSuccessfulProviderAdapter() {
-    }
-
-    @Override
-    public void testConnection(Notifier notifier) throws ConnectionException {
-    }
-
-    @Override
-    public String translatePayload(Object payload) throws Exception {
-        return payload.toString();
-    }
-
-    @Override
-    public Map<String, Date> getInactiveDevices(Notifier notifier,
-            EntityManager em) throws Exception {
-        return null;
-    }
-
-    @Override
-    public void validateCreateNotifier(ServicePayload payload) throws Exception {
-    }
-
-    @Override
-    public void doneSendingNotifications() throws Exception {
-    }
-
-    @Override
-    public void sendNotification(String providerId, Notifier notifier,
-            Object payload, Notification notification, final TaskTracker tracker)
-            throws Exception {
-        new Thread() {
-            @Override
-            public void run() {
-                try {
-                    tracker.completed();
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }.start();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
deleted file mode 100644
index ad64fd5..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifications/gcm/NotificationsServiceTest.java
+++ /dev/null
@@ -1,547 +0,0 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
- *
- * Licensed 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.usergrid.notifications.gcm;
-
-import org.apache.usergrid.notifications.AbstractServiceNotificationTest;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.services.notifications.NotificationsService;
-import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.TaskTracker;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.util.*;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.entities.Device;
-import org.apache.usergrid.services.ServiceAction;
-
-import static org.junit.Assert.*;
-import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
-
-public class NotificationsServiceTest extends AbstractServiceNotificationTest {
-
-    private static final Logger LOG = LoggerFactory
-            .getLogger(NotificationsServiceTest.class);
-
-    /**
-     * set to true to run tests against actual GCM servers - but they may not
-     * all run correctly
-     */
-    private static final boolean USE_REAL_CONNECTIONS = false;
-    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "google"
-            : "noop";
-
-    private static final String API_KEY = "AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM";
-    private static final String PUSH_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
-
-    private Notifier notifier;
-    private Device device1, device2;
-    private NotificationsService ns;
-
-    @Override
-    @Before
-    public void before() throws Exception {
-        super.before();
-
-        // create gcm notifier //
-
-        app.clear();
-        app.put("name", "gcm");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-
-        notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
-
-        // create devices //
-
-        app.clear();
-        app.put(key, PUSH_TOKEN);
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
-
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-        assertEquals(device1.getProperty(key), PUSH_TOKEN);
-
-        app.put(key, PUSH_TOKEN);
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device2 = app.getEm().get(e.getUuid(), Device.class);
-        ns = getNotificationService();
-    }
-
-    @Test
-    public void emptyPushNotification() throws Exception {
-
-        app.clear();
-        app.put("name", "foo");
-        app.put("provider", PROVIDER);
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-        Notifier n = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put("foo", payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 0);
-    }
-
-    @Test
-    public void singlePushNotification() throws Exception {
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-    }
-
-    @Test
-    public void singlePushNotificationViaUser() throws Exception {
-
-        app.clear();
-
-        app.put("username", "asdf");
-        app.put("email", "asdf@adsf.com");
-        Entity user = app.testRequest(ServiceAction.POST, 1, "users")
-                .getEntity();
-        assertNotNull(user);
-        Entity device = app.testRequest(ServiceAction.POST, 1, "users",
-                user.getUuid(), "devices", device1.getUuid()).getEntity();
-        assertEquals(device.getUuid(), device1.getUuid());
-
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-    }
-
-    @Test
-    public void twoBatchNotification() throws Exception {
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device2);
-        ns.addDevice(notification, device1);
-
-        // reduce Batch size to 1
-        Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
-        field.setAccessible(true);
-        int multicastSize = field.getInt(GCMAdapter.class);
-        try {
-            field.setInt(GCMAdapter.class, 1);
-
-            // perform push //
-            notification = scheduleNotificationAndWait(notification);
-
-            checkReceipts(notification, 2);
-        } finally {
-            field.setInt(GCMAdapter.class, multicastSize);
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void providerIdUpdate() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        final String newProviderId = "newProviderId";
-        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void sendNotification(String providerId, Notifier notifier,
-                    Object payload, Notification notification,
-                    TaskTracker tracker) throws Exception {
-                tracker.completed(newProviderId);
-            }
-        });
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        checkReceipts(notification, 1);
-
-        Device device = (Device) app.getEm().get(device1).toTypedEntity();
-        assertEquals(newProviderId,
-                device.getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
-    }
-
-    @Test
-    public void badPayloads() throws Exception {
-
-        // bad payloads format
-
-        app.clear();
-        app.put("payloads", "{asdf}");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // bad notifier
-
-        Map<String, String> payloads = new HashMap<String, String>(2);
-        app.put("payloads", payloads);
-        payloads.put("xxx", "");
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (IllegalArgumentException ex) {
-            // ok
-        }
-
-        // payload too long
-
-        // need the real provider for this one...
-        app.clear();
-        app.put("name", "gcm2");
-        app.put("provider", "google");
-        app.put("environment", "development");
-        app.put("apiKey", API_KEY);
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
-                .getEntity();
-        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
-
-        payloads.clear();
-        StringBuilder sb = new StringBuilder();
-        sb.append("{\"x\":\"");
-        while (sb.length() < 4080) {
-            sb.append("x");
-        }
-        sb.append("\"}");
-        payloads.put(notifier2.getUuid().toString(), sb.toString());
-
-        app.clear();
-        app.put("payloads", payloads);
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifications");
-            fail("invalid payload should have been rejected");
-        } catch (Exception ex) {
-            assertEquals("java.lang.IllegalArgumentException: GCM payloads must be 4096 characters or less",
-                    ex.getMessage());
-            // ok
-        }
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badToken() throws Exception {
-
-        // mock action (based on verified actual behavior) //
-        if (!USE_REAL_CONNECTIONS) {
-            ns.providerAdapters.put("google",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            tracker.failed("InvalidRegistration",
-                                    "InvalidRegistration");
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        // device w/ bad token
-        app.clear();
-        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
-
-        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-        device1 = app.getEm().get(e.getUuid(), Device.class);
-
-        ns.addDevice(notification, device1);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-
-        List<EntityRef> receipts = getNotificationReceipts(notification);
-        assertEquals(1, receipts.size());
-        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
-        assertEquals("InvalidRegistration", receipt.getErrorCode());
-    }
-
-    @Ignore
-    // todo: how can I mock this?
-    @Test
-    public void badAPIKey() throws Exception {
-
-        if (!USE_REAL_CONNECTIONS) {
-            // mock action (based on verified actual behavior) //
-            ns.providerAdapters.put("google",
-                    new MockSuccessfulProviderAdapter() {
-                        @Override
-                        public void sendNotification(String providerId,
-                                Notifier notifier, Object payload,
-                                Notification notification, TaskTracker tracker)
-                                throws Exception {
-                            Exception e = new IOException();
-                            throw new ConnectionException(e.getMessage(), e);
-                        }
-                    });
-        }
-
-        // create push notification //
-
-        app.clear();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        app.put("payloads", payloads);
-        app.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        ns.addDevice(notification, device1);
-
-        // save bad API key
-        app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
-
-        // perform push //
-
-        try {
-            ns.getQueueManager().processBatchAndReschedule(notification, null);
-            fail("Should have received a ConnectionException");
-        } catch (ConnectionException ex) {
-            // good
-        }
-    }
-
-    @Ignore("Run only if you need to.")
-    @Test
-    public void loadTest() throws Exception {
-
-        final int NUM_DEVICES = 10000;
-
-        // create notification //
-
-        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-        String payload = "Hello, World!";
-        Map<String, String> payloads = new HashMap<String, String>(1);
-        payloads.put(notifier.getUuid().toString(), payload);
-        properties.put("payloads", payloads);
-        properties.put("queued", System.currentTimeMillis());
-
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
-        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
-
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
-        assertEquals(
-                notification.getPayloads().get(notifier.getUuid().toString()),
-                payload);
-
-        // create a bunch of devices and add them to the notification
-        properties = new LinkedHashMap<String, Object>();
-        properties.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
-        for (int i = 0; i < NUM_DEVICES; i++) {
-            Entity entity = app.getEm().create("device", properties);
-            ns.addDevice(notification, entity);
-        }
-
-        long time = System.currentTimeMillis();
-        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
-
-        // perform push //
-        notification = scheduleNotificationAndWait(notification);
-        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
-                System.currentTimeMillis() - time);
-
-        // check receipts //
-        checkReceipts(notification, NUM_DEVICES);
-        checkStatistics(notification, NUM_DEVICES, 0);
-    }
-
-    // @Test
-    // public void inactiveDeviceUpdate() throws Exception {
-    //
-    // if (!USE_REAL_CONNECTIONS) {
-    // // mock action (based on verified actual behavior) //
-    // NotificationsService.providerAdapters.put("apple", new
-    // MockSuccessfulProviderAdapter() {
-    // public Map<String,Date> getInactiveDevices(Notifier notifier,
-    // EntityManager em) throws Exception {
-    // return Collections.singletonMap(PUSH_TOKEN, new Date());
-    // }
-    // });
-    // }
-    //
-    // // create push notification //
-    //
-    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
-    // String payload =
-    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
-    // Map<String, String> payloads = new HashMap<String, String>(1);
-    // payloads.put(notifier.getUuid().toString(), payload);
-    // properties.put("payloads", payloads);
-    // properties.put("queued", System.currentTimeMillis());
-    //
-    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
-    // "notifications").getEntity();
-    // testRequest(sm, ServiceAction.GET, 1, null, "notifications",
-    // e.getUuid());
-    //
-    // Notification notification = em.get(e.getUuid(), Notification.class);
-    // assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),
-    // payload);
-    //
-    // ns.addDevice(notification, device1);
-    // ns.addDevice(notification, device2);
-    //
-    // assertNotNull(device1.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // assertNotNull(device2.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    //
-    // // perform push //
-    // notification = scheduleNotificationAndWait(notification);
-    //
-    // // check provider IDs //
-    //
-    // device1 = em.get(device1, Device.class);
-    // assertNull(device1.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // device2 = em.get(device2, Device.class);
-    // assertNull(device2.getProperty(notifier.getName() +
-    // NOTIFIER_ID_POSTFIX));
-    // }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
deleted file mode 100644
index ff97578..0000000
--- a/stack/services/src/test/java/org/apache/usergrid/notifiers/NotifiersServiceTest.java
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.apache.usergrid.notifiers;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.usergrid.notifications.apns.MockSuccessfulProviderAdapter;
-import org.apache.usergrid.persistence.entities.Notifier;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.apache.usergrid.services.notifications.ConnectionException;
-import org.apache.usergrid.services.notifications.NotificationsService;
-
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.net.SocketException;
-import org.apache.usergrid.persistence.Schema;
-import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
-import org.apache.usergrid.services.AbstractServiceIT;
-import org.apache.usergrid.services.ServiceAction;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertArrayEquals;
-
-import static org.junit.Assert.fail;
-
-public class NotifiersServiceTest extends AbstractServiceIT {
-    private NotificationsService ns;
-
-    @Before
-    public void before() throws Exception {
-        ns = (NotificationsService) app.getSm().getService("notifications");
-        MockSuccessfulProviderAdapter.install(ns);
-    }
-
-    @Test
-    public void badProvider() throws Exception {
-
-        app.clear();
-        app.put("provider", "xxx");
-        app.put("environment", "production");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad provider");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badGcmToken() throws Exception {
-        app.clear();
-        app.put("provider", "google");
-        app.put("environment", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with missing apiKey");
-        } catch (RequiredPropertyNotFoundException e) {
-            // ok
-        }
-
-        // mock action (based on verified actual behavior) //
-        ns.providerAdapters
-                .put("google",
-                        new org.apache.usergrid.notifications.gcm.MockSuccessfulProviderAdapter() {
-                            @Override
-                            public void testConnection(Notifier notifier)
-                                    throws ConnectionException {
-                                throw new ConnectionException("", null);
-                            }
-                        });
-
-        app.put("apiKey", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with bad connection");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void badAPNsEnvironment() throws Exception {
-
-        MockSuccessfulProviderAdapter.uninstall(ns);
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "xxx");
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad environment");
-        } catch (IllegalArgumentException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void goodAPNsCreation() throws Exception {
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Notifier notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, false,
-                        new Object[] { "notifiers" }).getEntity()
-                .toTypedEntity();
-
-        assertEquals(app.get("provider"), notifier.getProvider());
-        assertEquals(app.get("environment"), notifier.getEnvironment());
-        assertArrayEquals(notifier.getP12Certificate(), certBytes);
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badAPNsCertificate() throws Exception {
-
-        // mock error (based on verified actual behavior) //
-        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void testConnection(Notifier notifier)
-                    throws ConnectionException {
-                Exception e = new SocketException(
-                        "Connection closed by remote host");
-                throw new ConnectionException(e.getMessage(), e);
-            }
-        });
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_prod.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad connection test");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Ignore("Mock doesn't work")
-    @Test
-    public void badAPNsPassword() throws Exception {
-
-        // mock error (based on verified actual behavior) //
-        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
-            @Override
-            public void testConnection(Notifier notifier)
-                    throws ConnectionException {
-                Exception e = new Exception("invalid ssl config");
-                throw new ConnectionException(e.getMessage(), e);
-            }
-        });
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-        app.put("certificatePassword", "wrong");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        try {
-            app.testRequest(ServiceAction.POST, 1, "notifiers");
-            fail("notifier creation should have failed with a bad connection test");
-        } catch (ConnectionException e) {
-            // ok
-        }
-    }
-
-    @Test
-    public void encryption() throws Exception {
-
-        app.clear();
-        app.put("provider", "apple");
-        app.put("environment", "development");
-
-        InputStream fis = getClass().getClassLoader().getResourceAsStream(
-                "pushtest_dev_recent.p12");
-        byte[] certBytes = IOUtils.toByteArray(fis);
-        app.put("p12Certificate", certBytes);
-        fis.close();
-
-        Field f = Schema.class.getDeclaredField("encryptionSeed");
-        f.setAccessible(true);
-        byte[] originalSeed = (byte[]) f.get(Schema.class);
-        byte[] encryptionSeed = "This is a new seed.".getBytes();
-        f.set(Schema.class, encryptionSeed);
-
-        Notifier notifier = (Notifier) app
-                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
-                .toTypedEntity();
-
-        assertArrayEquals(notifier.getP12Certificate(), certBytes);
-
-        f.set(Schema.class, originalSeed);
-
-        try {
-            app.getEm().get(notifier.getUuid());
-            fail("Should have failed to retrieve the encrypted entity.");
-        } catch (IllegalStateException e) {
-            // ok! This should happen.
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
new file mode 100644
index 0000000..06dc1a3
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/NotifiersServiceTest.java
@@ -0,0 +1,224 @@
+package org.apache.usergrid.services;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.services.notifications.apns.MockSuccessfulProviderAdapter;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.net.SocketException;
+import org.apache.usergrid.persistence.Schema;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.services.AbstractServiceIT;
+import org.apache.usergrid.services.ServiceAction;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertArrayEquals;
+
+import static org.junit.Assert.fail;
+
+public class NotifiersServiceTest extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Before
+    public void before() throws Exception {
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        MockSuccessfulProviderAdapter.install(ns);
+    }
+
+    @Test
+    public void badProvider() throws Exception {
+
+        app.clear();
+        app.put("provider", "xxx");
+        app.put("environment", "production");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad provider");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badGcmToken() throws Exception {
+        app.clear();
+        app.put("provider", "google");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with missing apiKey");
+        } catch (RequiredPropertyNotFoundException e) {
+            // ok
+        }
+
+        // mock action (based on verified actual behavior) //
+        ns.providerAdapters
+                .put("google",
+                        new org.apache.usergrid.services.notifications.gcm.MockSuccessfulProviderAdapter() {
+                            @Override
+                            public void testConnection(Notifier notifier)
+                                    throws ConnectionException {
+                                throw new ConnectionException("", null);
+                            }
+                        });
+
+        app.put("apiKey", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with bad connection");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void badAPNsEnvironment() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "xxx");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad environment");
+        } catch (IllegalArgumentException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void goodAPNsCreation() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, false,
+                        new Object[] { "notifiers" }).getEntity()
+                .toTypedEntity();
+
+        assertEquals(app.get("provider"), notifier.getProvider());
+        assertEquals(app.get("environment"), notifier.getEnvironment());
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsCertificate() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new SocketException(
+                        "Connection closed by remote host");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_prod.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Ignore("Mock doesn't work")
+    @Test
+    public void badAPNsPassword() throws Exception {
+
+        // mock error (based on verified actual behavior) //
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void testConnection(Notifier notifier)
+                    throws ConnectionException {
+                Exception e = new Exception("invalid ssl config");
+                throw new ConnectionException(e.getMessage(), e);
+            }
+        });
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        app.put("certificatePassword", "wrong");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifiers");
+            fail("notifier creation should have failed with a bad connection test");
+        } catch (ConnectionException e) {
+            // ok
+        }
+    }
+
+    @Test
+    public void encryption() throws Exception {
+
+        app.clear();
+        app.put("provider", "apple");
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Field f = Schema.class.getDeclaredField("encryptionSeed");
+        f.setAccessible(true);
+        byte[] originalSeed = (byte[]) f.get(Schema.class);
+        byte[] encryptionSeed = "This is a new seed.".getBytes();
+        f.set(Schema.class, encryptionSeed);
+
+        Notifier notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        assertArrayEquals(notifier.getP12Certificate(), certBytes);
+
+        f.set(Schema.class, originalSeed);
+
+        try {
+            app.getEm().get(notifier.getUuid());
+            fail("Should have failed to retrieve the encrypted entity.");
+        } catch (IllegalStateException e) {
+            // ok! This should happen.
+        }
+    }
+}


[02/33] git commit: add vcm

Posted by sn...@apache.org.
add vcm


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

Branch: refs/heads/two-dot-o
Commit: 9d2121c7afba8a500289d478d83c762036617044
Parents: d2280df
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 12:49:36 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 12:49:36 2014 -0600

----------------------------------------------------------------------
 stack/pom.xml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d2121c7/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 35c3979..adc02fd 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -1405,7 +1405,7 @@
         <artifactId>elasticsearch</artifactId>
         <version>${elasticsearch.version}</version>
       </dependency>
-        
+
       <dependency>
         <groupId>com.relayrides</groupId>
         <artifactId>pushy</artifactId>
@@ -1413,7 +1413,13 @@
         <version>0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b</version>
       </dependency>
 
-     </dependencies>
+      <dependency>
+          <groupId>com.ganyo</groupId>
+          <artifactId>gcm-server</artifactId>
+          <version>1.0.2</version>
+      </dependency>
+
+    </dependencies>
 
   </dependencyManagement>
 


[04/33] git commit: add metrics factory, cod hale.metrics to pom, add property

Posted by sn...@apache.org.
add metrics factory, cod hale.metrics to pom, add property


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/99c80faf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/99c80faf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/99c80faf

Branch: refs/heads/two-dot-o
Commit: 99c80faf21e179ab83cf9d1c8090a52ab3b9c481
Parents: 05d90c6
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Jul 18 14:41:58 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 14:10:44 2014 -0600

----------------------------------------------------------------------
 .../main/resources/usergrid-default.properties  |   3 +
 stack/core/pom.xml                              |  11 +-
 .../apache/usergrid/metrics/MetricsFactory.java | 121 +++++++++++++++++++
 .../main/resources/usergrid-core-context.xml    |   3 +
 stack/pom.xml                                   |   2 +-
 5 files changed, 138 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/99c80faf/stack/config/src/main/resources/usergrid-default.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/main/resources/usergrid-default.properties b/stack/config/src/main/resources/usergrid-default.properties
index 09d4f94..1f7caf5 100644
--- a/stack/config/src/main/resources/usergrid-default.properties
+++ b/stack/config/src/main/resources/usergrid-default.properties
@@ -365,6 +365,9 @@ usergrid.management.email.user-pin=\
     <p>${pin}</p>
 
 
+# graphite server
+usergrid.metrics.graphite.host=badhost
+
 ###############################################################################
 #
 # Redirect urls to use instead of internal JSPs.  Not all of these should be

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/99c80faf/stack/core/pom.xml
----------------------------------------------------------------------
diff --git a/stack/core/pom.xml b/stack/core/pom.xml
index b3a3949..ac94015 100644
--- a/stack/core/pom.xml
+++ b/stack/core/pom.xml
@@ -489,7 +489,6 @@
       <scope>test</scope>
     </dependency>
 
-
     <!-- Core Persistence deps -->
     <dependency>
 	    <groupId>org.apache.usergrid</groupId>
@@ -548,6 +547,16 @@
         <version>2.0.0-SNAPSHOT</version>
     </dependency>-->
 
+    <dependency>
+      <groupId>com.codahale.metrics</groupId>
+      <artifactId>metrics-core</artifactId>
+      <version>${metrics.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>com.codahale.metrics</groupId>
+      <artifactId>metrics-graphite</artifactId>
+      <version>${metrics.version}</version>
+    </dependency>
   </dependencies>
 
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/99c80faf/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java b/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
new file mode 100644
index 0000000..c5dbf1e
--- /dev/null
+++ b/stack/core/src/main/java/org/apache/usergrid/metrics/MetricsFactory.java
@@ -0,0 +1,121 @@
+/*
+ * 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.usergrid.metrics;
+import com.codahale.metrics.*;
+import com.codahale.metrics.graphite.Graphite;
+import com.codahale.metrics.graphite.GraphiteReporter;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+import java.net.InetSocketAddress;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Singleton class to manage metrics.
+ */
+@Component("metricsFactory")
+public class MetricsFactory {
+    @Autowired
+    private Properties properties;
+    public MetricRegistry registry;
+    private GraphiteReporter graphiteReporter;
+    private JmxReporter jmxReporter;
+    private ConcurrentHashMap<String,Metric> hashMap;
+    private static final Logger LOG = LoggerFactory.getLogger(MetricsFactory.class);
+
+    public MetricsFactory() {
+
+    }
+
+    @PostConstruct
+    void init() {
+        properties = new Properties();
+        try {
+            properties.load(Thread.currentThread()
+                    .getContextClassLoader()
+                    .getResourceAsStream("usergrid.properties"));
+        } catch (Exception e) {
+            LOG.error("Could not load props","");
+        }
+        registry = new MetricRegistry();
+        String badHost = "badhost";
+        String metricsHost = properties.getProperty("usergrid.metrics.graphite.host", badHost);
+        Graphite graphite = new Graphite(new InetSocketAddress(metricsHost, 2003));
+        graphiteReporter = GraphiteReporter.forRegistry(registry)
+                .prefixedWith("notifications")
+                .convertRatesTo(TimeUnit.SECONDS)
+                .convertDurationsTo(TimeUnit.MILLISECONDS)
+                .filter(MetricFilter.ALL)
+                .build(graphite);
+        if(metricsHost!=badHost) {
+            graphiteReporter.start(30, TimeUnit.SECONDS);
+        }else {
+            LOG.warn("MetricsService:Logger not started.");
+            graphiteReporter.stop();
+        }
+        hashMap = new ConcurrentHashMap<String, Metric>();
+
+        jmxReporter = JmxReporter.forRegistry(registry).build();
+        jmxReporter.start();
+    }
+
+    public MetricRegistry getRegistry() {
+        return registry;
+    }
+
+    public Timer getTimer(Class<?> klass, String name) {
+        return getMetric(Timer.class, klass, name);
+    }
+
+    public Histogram getHistogram(Class<?> klass, String name) {
+        return getMetric(Histogram.class, klass, name);
+    }
+
+    public Counter getCounter(Class<?> klass, String name) {
+        return getMetric(Counter.class, klass, name);
+    }
+
+    public Meter getMeter(Class<?> klass, String name) {
+        return getMetric(Meter.class, klass, name);
+    }
+
+    private <T> T getMetric(Class<T> metricClass, Class<?> klass, String name) {
+        String key = metricClass.getName() + klass.getName() + name;
+        Metric metric = hashMap.get(key);
+        if (metric == null) {
+            if (metricClass == Histogram.class) {
+                metric = this.getRegistry().histogram(MetricRegistry.name(klass, name));
+            }
+            if (metricClass == Timer.class) {
+                metric = this.getRegistry().timer(MetricRegistry.name(klass, name));
+            }
+            if (metricClass == Meter.class) {
+                metric = this.getRegistry().meter(MetricRegistry.name(klass, name));
+            }
+            if (metricClass == Counter.class) {
+                metric = this.getRegistry().counter(MetricRegistry.name(klass, name));
+            }
+            hashMap.put(key, metric);
+        }
+        return (T) metric;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/99c80faf/stack/core/src/main/resources/usergrid-core-context.xml
----------------------------------------------------------------------
diff --git a/stack/core/src/main/resources/usergrid-core-context.xml b/stack/core/src/main/resources/usergrid-core-context.xml
index 9321fb6..cd8802c 100644
--- a/stack/core/src/main/resources/usergrid-core-context.xml
+++ b/stack/core/src/main/resources/usergrid-core-context.xml
@@ -186,6 +186,9 @@
 
     <bean id="jobFactory" class="org.apache.usergrid.batch.UsergridJobFactory" />
 
+    <bean id="metricsFactory" class="org.apache.usergrid.metrics.MetricsFactory" scope="singleton"/>
+
+    <!-- scan all job classes -->
     <context:component-scan base-package="org.apache.usergrid.batch.job" />
     <context:annotation-config />
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/99c80faf/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index adc02fd..600217c 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -115,7 +115,7 @@
     <antlr.version>3.4</antlr.version>
     <tika.version>1.4</tika.version>
     <elasticsearch.version>1.2.3</elasticsearch.version>
-
+    <metrics.version>3.0.0</metrics.version>
   </properties>
 
   <licenses>


[32/33] git commit: add null check

Posted by sn...@apache.org.
add null check


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/93477bc8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/93477bc8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/93477bc8

Branch: refs/heads/two-dot-o
Commit: 93477bc8b876e437b413927d99a83bc9800ab87e
Parents: af4aa40
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Sep 4 13:23:08 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Sep 4 13:23:08 2014 -0600

----------------------------------------------------------------------
 .../services/notifications/gcm/NotificationsServiceIT.java     | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/93477bc8/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 32a7328..e77541f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -111,8 +111,10 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
     @After
     public void after(){
-        listener.stop();
-        listener = null;
+        if(listener!=null) {
+            listener.stop();
+            listener = null;
+        }
     }
 
     @Test


[07/33] git commit: adding notificationsservice

Posted by sn...@apache.org.
adding notificationsservice


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

Branch: refs/heads/two-dot-o
Commit: 9d7901ae388d80350439221f1a253a0846db7c71
Parents: 0a61101
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Aug 18 14:53:51 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Aug 18 14:53:51 2014 -0600

----------------------------------------------------------------------
 .../index/exceptions/NoIndexException.java      |  17 +-
 .../index/query/tree/NotOperand.java            |  17 +-
 .../index/query/tree/WithinOperand.java         |  17 +-
 .../query/tree/StringLiteralTest.java           |  17 +-
 stack/services/pom.xml                          |  11 +
 .../notifications/NotificationsService.java     |  32 +
 .../notifications/NotificationsService.java     |  32 +
 .../notifications/NotificationsService.java     |  32 +
 .../notifications/ConnectionException.java      |  25 +
 .../services/notifications/JobScheduler.java    |  92 +++
 .../notifications/NotificationBatchJob.java     | 125 ++++
 .../services/notifications/NotificationJob.java | 129 ++++
 .../notifications/NotificationServiceProxy.java |  32 +
 .../NotificationsQueueManager.java              | 654 +++++++++++++++++++
 .../notifications/NotificationsService.java     | 327 ++++++++++
 .../services/notifications/ProviderAdapter.java |  55 ++
 .../services/notifications/QueueJob.java        | 127 ++++
 .../services/notifications/TaskManager.java     | 196 ++++++
 .../services/notifications/TaskTracker.java     |  50 ++
 .../services/notifications/TestAdapter.java     | 106 +++
 .../notifications/apns/APNsAdapter.java         | 280 ++++++++
 .../notifications/apns/APNsNotification.java    | 101 +++
 .../apns/FailedConnectionListener.java          |  88 +++
 .../apns/RejectedAPNsListener.java              |  53 ++
 .../notifications/apns/TestAPNsListener.java    | 100 +++
 .../apns/TestAPNsNotification.java              | 124 ++++
 .../services/notifications/gcm/GCMAdapter.java  | 221 +++++++
 .../services/notifiers/NotifiersService.java    |  73 +++
 .../notifications/NotificationsService.java     |  32 +
 .../notifications/NotificationsService.java     |  32 +
 30 files changed, 3165 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
index c505721..3043768 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/exceptions/NoIndexException.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.persistence.index.exceptions;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
index 8588d24..35b41f3 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/NotOperand.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.persistence.index.query.tree;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
index 602fc34..9d913e3 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/query/tree/WithinOperand.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.persistence.index.query.tree;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
index f67cb11..161430a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/query/tree/StringLiteralTest.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.persistence.query.tree;
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/pom.xml
----------------------------------------------------------------------
diff --git a/stack/services/pom.xml b/stack/services/pom.xml
index 3d81558..ace3c8d 100644
--- a/stack/services/pom.xml
+++ b/stack/services/pom.xml
@@ -549,6 +549,17 @@
       <scope>test</scope>
     </dependency>
 
+    <dependency>
+      <groupId>com.relayrides</groupId>
+      <artifactId>pushy</artifactId>
+      <!-- The sha in the version is the git commit used in this build.  Check out the pushy source, then this commit to build the library locally -->
+      <version>0.4-apigee-63dec68314c97c6e3ef40c88590e1b196d3ec55b</version>
+    </dependency>
 
+    <dependency>
+      <groupId>com.ganyo</groupId>
+      <artifactId>gcm-server</artifactId>
+      <version>1.0.2</version>
+    </dependency>
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/devices/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/devices/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/devices/notifications/NotificationsService.java
new file mode 100644
index 0000000..c766c72
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/devices/notifications/NotificationsService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.devices.notifications;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotificationsService extends
+        org.apache.usergrid.services.notifications.NotificationsService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotificationsService.class);
+
+    public NotificationsService() {
+        logger.info("/devices/*/notifications");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/groups/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/groups/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/groups/notifications/NotificationsService.java
new file mode 100644
index 0000000..9e965b5
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/groups/notifications/NotificationsService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.groups.notifications;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotificationsService extends
+        org.apache.usergrid.services.notifications.NotificationsService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotificationsService.class);
+
+    public NotificationsService() {
+        logger.info("/groups/*/notifications");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/groups/users/devices/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/groups/users/devices/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/groups/users/devices/notifications/NotificationsService.java
new file mode 100644
index 0000000..7587bd0
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/groups/users/devices/notifications/NotificationsService.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.groups.users.devices.notifications;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NotificationsService extends
+        org.apache.usergrid.services.notifications.NotificationsService {
+
+    private static final Logger logger = LoggerFactory
+            .getLogger(NotificationsService.class);
+
+    public NotificationsService() {
+        logger.info("/groups/*/users/*/devices/*/notifications");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/ConnectionException.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ConnectionException.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ConnectionException.java
new file mode 100644
index 0000000..314834b
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ConnectionException.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.services.notifications;
+
+import org.springframework.core.NestedCheckedException;
+
+public class ConnectionException extends NestedCheckedException {
+    public ConnectionException(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
new file mode 100644
index 0000000..c366a86
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/JobScheduler.java
@@ -0,0 +1,92 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.batch.service.SchedulerService;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.entities.JobData;
+import org.apache.usergrid.services.ServiceManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class JobScheduler{
+    public static final long SCHEDULER_GRACE_PERIOD = 250;
+    private final EntityManager em;
+
+    protected ServiceManager sm;
+    private final Logger LOG = LoggerFactory.getLogger(NotificationsService.class);
+
+    public JobScheduler(ServiceManager sm,EntityManager em){
+        this.sm=sm; this.em = em;
+    }
+    public void scheduleBatchJob(Notification notification, long delay) throws Exception {
+
+        JobData jobData = new JobData();
+        jobData.setProperty("applicationId", sm.getApplicationId());
+        jobData.setProperty("notificationId", notification.getUuid());
+        jobData.setProperty("deliver", notification.getDeliver());
+
+        long soonestPossible = System.currentTimeMillis() + SCHEDULER_GRACE_PERIOD + delay;
+
+        SchedulerService scheduler = getSchedulerService();
+        scheduler.createJob("notificationBatchJob", soonestPossible, jobData);
+
+        LOG.info("notification {} batch scheduled for delivery", notification.getUuid());
+    }
+    public boolean scheduleQueueJob(Notification notification) throws Exception {
+        return scheduleQueueJob(notification,false);
+    }
+
+    public boolean scheduleQueueJob(Notification notification, boolean forceSchedule) throws Exception {
+
+        boolean scheduleInFuture = notification.getDeliver() != null;
+        long scheduleAt = (notification.getDeliver() != null) ? notification.getDeliver() : 0;
+        long soonestPossible = System.currentTimeMillis() + SCHEDULER_GRACE_PERIOD;
+        if (scheduleAt < soonestPossible) {
+            scheduleAt = soonestPossible;
+            scheduleInFuture = false;
+        }
+
+        // update Notification properties
+        if (notification.getStarted() == null || notification.getStarted() == 0) {
+            notification.setStarted(System.currentTimeMillis());
+            Map<String, Object> properties = new HashMap<String, Object>(2);
+            properties.put("started", notification.getStarted());
+            properties.put("state", notification.getState());
+            em.updateProperties(notification, properties);
+        }
+        boolean scheduled = scheduleInFuture || forceSchedule;
+        if(scheduled) {
+            JobData jobData = new JobData();
+            jobData.setProperty("applicationId", sm.getApplicationId());
+            jobData.setProperty("notificationId", notification.getUuid());
+            jobData.setProperty("deliver", notification.getDeliver());
+            SchedulerService scheduler = getSchedulerService();
+            scheduler.createJob("queueJob", scheduleAt, jobData);
+        }
+        LOG.info("notification {} scheduled for queuing", notification.getUuid());
+        return scheduled;
+    }
+    private SchedulerService getSchedulerService() {
+        return sm.getSchedulerService();
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
new file mode 100644
index 0000000..81006ce
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
@@ -0,0 +1,125 @@
+/*
+ * 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.usergrid.services.notifications;
+
+
+import java.util.UUID;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.usergrid.persistence.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import org.apache.usergrid.batch.Job;
+import org.apache.usergrid.batch.JobExecution;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.entities.JobData;
+import org.apache.usergrid.services.ServiceManager;
+import org.apache.usergrid.services.ServiceManagerFactory;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+
+
+@Component( "notificationBatchJob" )
+public class NotificationBatchJob implements Job {
+
+    private static final Logger logger = LoggerFactory.getLogger( NotificationBatchJob.class );
+    private Meter postSendMeter;
+    private Timer timerMetric;
+    private Meter requestMeter;
+    private Histogram cycleMetric;
+
+    @Autowired
+    private MetricsFactory metricsService;
+
+    @Autowired
+    private ServiceManagerFactory smf;
+
+    @Autowired
+    private EntityManagerFactory emf;
+
+
+    public NotificationBatchJob() {
+
+    }
+
+
+    @PostConstruct
+    void init() {
+        postSendMeter = metricsService.getMeter( NotificationsService.class, "post-send" );
+        requestMeter = metricsService.getMeter( NotificationBatchJob.class, "requests" );
+        timerMetric = metricsService.getTimer( NotificationBatchJob.class, "execution" );
+        cycleMetric = metricsService.getHistogram( NotificationsService.class, "cycle" );
+    }
+
+
+    public void execute( JobExecution jobExecution ) throws Exception {
+
+        Timer.Context timer = timerMetric.time();
+        requestMeter.mark();
+        logger.info( "execute NotificationBatchJob {}", jobExecution );
+
+        JobData jobData = jobExecution.getJobData();
+        UUID applicationId = ( UUID ) jobData.getProperty( "applicationId" );
+        ServiceManager sm = smf.getServiceManager( applicationId );
+        NotificationsService notificationsService = ( NotificationsService ) sm.getService( "notifications" );
+
+        EntityManager em = emf.getEntityManager( applicationId );
+
+        try {
+            if ( em == null ) {
+                logger.info( "no EntityManager for applicationId  {}", applicationId );
+                return;
+            }
+
+            UUID notificationId = ( UUID ) jobData.getProperty( "notificationId" );
+            Notification notification = em.get( notificationId, Notification.class );
+            if ( notification == null ) {
+                logger.info( "notificationId {} no longer exists", notificationId );
+                return;
+            }
+
+
+            try {
+                notificationsService.getQueueManager().processBatchAndReschedule( notification, jobExecution );
+            }
+            catch ( Exception e ) {
+                logger.error( "execute NotificationBatchJob failed", e );
+                em.setProperty( notification, "errorMessage", e.getMessage() );
+                throw e;
+            }
+            finally {
+                long diff = System.currentTimeMillis() - notification.getCreated();
+                cycleMetric.update( diff );
+                postSendMeter.mark();
+            }
+        }
+        finally {
+            timer.stop();
+        }
+
+        logger.info( "execute NotificationBatch completed normally" );
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
new file mode 100644
index 0000000..f80ee1e
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
@@ -0,0 +1,129 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import java.util.UUID;
+
+import javax.annotation.PostConstruct;
+
+import org.apache.usergrid.persistence.Notification;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import org.apache.usergrid.batch.JobExecution;
+import org.apache.usergrid.batch.job.OnlyOnceJob;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityManagerFactory;
+import org.apache.usergrid.persistence.entities.JobData;
+import org.apache.usergrid.services.ServiceManager;
+import org.apache.usergrid.services.ServiceManagerFactory;
+
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.codahale.metrics.Timer;
+
+
+@Component( "notificationJob" )
+public class NotificationJob extends OnlyOnceJob {
+
+
+    private static final Logger logger = LoggerFactory.getLogger( NotificationJob.class );
+
+    @Autowired
+    private MetricsFactory metricsService;
+
+    @Autowired
+    private ServiceManagerFactory smf;
+
+    @Autowired
+    private EntityManagerFactory emf;
+    private Meter requests;
+    private Timer execution;
+    private Histogram end;
+
+
+    public NotificationJob() {
+
+    }
+
+
+    @PostConstruct
+    void init() {
+        requests = metricsService.getMeter( NotificationJob.class, "requests" );
+        execution = metricsService.getTimer( NotificationJob.class, "execution" );
+        end = metricsService.getHistogram( QueueJob.class, "end" );
+    }
+
+
+    @Override
+    public void doJob( JobExecution jobExecution ) throws Exception {
+
+        Timer.Context timer = execution.time();
+        requests.mark();
+
+        logger.info( "execute NotificationJob {}", jobExecution );
+
+        JobData jobData = jobExecution.getJobData();
+        UUID applicationId = ( UUID ) jobData.getProperty( "applicationId" );
+        ServiceManager sm = smf.getServiceManager( applicationId );
+        NotificationsService notificationsService = ( NotificationsService ) sm.getService( "notifications" );
+
+        EntityManager em = emf.getEntityManager( applicationId );
+        try {
+            if ( em == null ) {
+                logger.info( "no EntityManager for applicationId  {}", applicationId );
+                return;
+            }
+            UUID notificationId = ( UUID ) jobData.getProperty( "notificationId" );
+            Notification notification = em.get( notificationId, Notification.class );
+            if ( notification == null ) {
+                logger.info( "notificationId {} no longer exists", notificationId );
+                return;
+            }
+
+            try {
+                notificationsService.getQueueManager().processBatchAndReschedule( notification, jobExecution );
+            }
+            catch ( Exception e ) {
+                logger.error( "execute NotificationJob failed", e );
+                em.setProperty( notification, "errorMessage", e.getMessage() );
+                throw e;
+            }
+            finally {
+                long diff = System.currentTimeMillis() - notification.getCreated();
+                end.update( diff );
+            }
+        }
+        finally {
+            timer.stop();
+        }
+
+        logger.info( "execute NotificationJob completed normally" );
+    }
+
+
+    @Override
+    protected long getDelay( JobExecution execution ) throws Exception {
+        return TaskManager.BATCH_DEATH_PERIOD;
+    }
+
+
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
new file mode 100644
index 0000000..908482f
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationServiceProxy.java
@@ -0,0 +1,32 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+
+import java.util.Set;
+
+/**
+ * Created by ApigeeCorporation on 8/6/14.
+ */
+public interface NotificationServiceProxy {
+
+    public void finishedBatch(Notification notification, long successes, long failures) throws Exception;
+
+    void asyncCheckForInactiveDevices(Set<Notifier> notifiers) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
new file mode 100644
index 0000000..95dfb8e
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
@@ -0,0 +1,654 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import com.codahale.metrics.Counter;
+import com.codahale.metrics.Histogram;
+import com.codahale.metrics.Meter;
+import com.google.common.cache.*;
+import org.apache.usergrid.batch.JobExecution;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.mq.Message;
+import org.apache.usergrid.mq.QueueManager;
+import org.apache.usergrid.mq.QueueQuery;
+import org.apache.usergrid.mq.QueueResults;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
+import org.apache.usergrid.utils.InflectionUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import rx.Observable;
+import rx.Subscriber;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+import java.util.*;
+import java.util.concurrent.*;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+
+/**
+ * Created by ApigeeCorporation on 8/13/14.
+ */
+public class NotificationsQueueManager implements NotificationServiceProxy {
+    private static final String NOTIFICATION_CONCURRENT_BATCHES = "notification.concurrent.batches";
+    private static final long CONSECUTIVE_EMPTY_QUEUES = 10;
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsQueueManager.class);
+
+    //this is for tests, will not mark initial post complete, set to false for tests
+    public static boolean IS_TEST = false;
+    private final Meter sendMeter;
+    private final Histogram queueSize;
+    private final Counter outstandingQueue;
+    private static ExecutorService INACTIVE_DEVICE_CHECK_POOL = Executors.newFixedThreadPool(5);
+    public static final String NOTIFIER_ID_POSTFIX = ".notifier.id";
+    public static int BATCH_SIZE = 1000;
+    // timeout for message queue transaction
+    public static final long MESSAGE_TRANSACTION_TIMEOUT = TaskManager.MESSAGE_TRANSACTION_TIMEOUT;
+    // If this property is set Notifications are automatically expired in
+    // the isOkToSent() method after the specified number of milliseconds
+    public static final String PUSH_AUTO_EXPIRE_AFTER_PROPNAME = "usergrid.push-auto-expire-after";
+    private final EntityManager em;
+    private final QueueManager qm;
+    private final JobScheduler jobScheduler;
+    private final Properties props;
+    private final InflectionUtils utils;
+    private AtomicLong consecutiveEmptyQueues = new AtomicLong();
+    private Long pushAutoExpireAfter = null;
+    static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
+
+    public final Map<String, ProviderAdapter> providerAdapters =   new HashMap<String, ProviderAdapter>(3);
+            {
+                providerAdapters.put("apple", APNS_ADAPTER);
+                providerAdapters.put("google", new GCMAdapter());
+                providerAdapters.put("noop", TEST_ADAPTER);
+            };
+    // these 2 can be static, but GCM can't. future: would be nice to get gcm
+    // static as well...
+    public static ProviderAdapter APNS_ADAPTER = new APNsAdapter();
+    public static ProviderAdapter TEST_ADAPTER = new TestAdapter();
+
+    //cache to retrieve push manager, cached per notifier, so many notifications will get same push manager
+    private static LoadingCache<EntityManager, HashMap<Object,Notifier>> notifierCacheMap = CacheBuilder
+            .newBuilder()
+            .expireAfterWrite(5, TimeUnit.MINUTES)
+            .build(new CacheLoader<EntityManager, HashMap<Object, Notifier>>() {
+                @Override
+                public HashMap<Object, Notifier> load(EntityManager em) {
+                    HashMap<Object, Notifier> notifierHashMap = new HashMap<Object, Notifier>();
+                    Query query = new Query();
+                    query.setCollection("notifiers");
+                    query.setLimit(50);
+                    PathQuery<Notifier> pathQuery = new PathQuery<Notifier>(em.getApplicationRef(), query);
+                    Iterator<Notifier> notifierIterator = pathQuery.iterator(em);
+                    while (notifierIterator.hasNext()) {
+                        Notifier notifier = notifierIterator.next();
+                        notifierHashMap.put(notifier.getName().toLowerCase(), notifier);
+                        notifierHashMap.put(notifier.getUuid(), notifier);
+                        notifierHashMap.put(notifier.getUuid().toString(), notifier);
+
+                    }
+                    return notifierHashMap;
+                }
+            });;
+
+    public NotificationsQueueManager(JobScheduler jobScheduler, EntityManager entityManager, Properties props, QueueManager queueManager, MetricsFactory metricsFactory){
+        this.em = entityManager;
+        this.qm = queueManager;
+        this.jobScheduler = jobScheduler;
+        this.props = props;
+        this.sendMeter = metricsFactory.getMeter(NotificationsService.class, "send");
+        this.queueSize = metricsFactory.getHistogram(NotificationsService.class, "queue_size");
+        this.outstandingQueue = metricsFactory.getCounter(NotificationsService.class,"current_queue");
+        utils = new InflectionUtils();
+    }
+
+    public boolean scheduleQueueJob(Notification notification) throws Exception{
+        return jobScheduler.scheduleQueueJob(notification);
+    }
+
+    public void queueNotification(final Notification notification, final JobExecution jobExecution) throws Exception {
+        if (notification.getCanceled() == Boolean.TRUE) {
+            LOG.info("notification " + notification.getUuid() + " canceled");
+            if (jobExecution != null) {
+                jobExecution.killed();
+            }
+            return;
+        }
+
+        long startTime = System.currentTimeMillis();
+        LOG.info("notification {} start queuing", notification.getUuid());
+        final PathQuery<Device> pathQuery = notification.getPathQuery(); //devices query
+        final AtomicInteger deviceCount = new AtomicInteger(); //count devices so you can make a judgement on batching
+        final AtomicInteger batchCount = new AtomicInteger(); //count devices so you can make a judgement on batching
+        final int numCurrentBatchesConfig = getNumConcurrentBatches();
+
+        final ConcurrentLinkedQueue<String> errorMessages = new ConcurrentLinkedQueue<String>(); //build up list of issues
+
+        //get devices in querystring, and make sure you have access
+        if (pathQuery != null) {
+            final Iterator<Device> iterator = pathQuery.iterator(em);
+            //if there are more pages (defined by PAGE_SIZE) you probably want this to be async, also if this is already a job then don't reschedule
+            if (iterator instanceof ResultsIterator && ((ResultsIterator) iterator).hasPages() && jobExecution == null) {
+                jobScheduler.scheduleQueueJob(notification, true);
+                return;
+            }
+
+            Observable.create(new IteratorObservable<Entity>(iterator)).parallel(new Func1<Observable<Entity>, Observable<Entity>>() {
+                @Override
+                public Observable<Entity> call(Observable<Entity> deviceObservable) {
+                    return deviceObservable.map( new Func1<Entity,Entity>() {
+                        @Override
+                        public Entity call(Entity entity) {
+                            try {
+                                List<EntityRef> devicesRef = getDevices(entity); // resolve group
+                                boolean maySchedule = false;
+                                for (EntityRef deviceRef : devicesRef) {
+                                    maySchedule |= deviceCount.incrementAndGet() % BATCH_SIZE == 0;
+                                    Message message = new Message();
+                                    message.setProperty(MESSAGE_PROPERTY_DEVICE_UUID, deviceRef.getUuid());
+                                    qm.postToQueue( getJobQueueName(notification), message);
+                                    if(notification.getQueued() == null){
+                                        // update queued time
+                                        notification.setQueued(System.currentTimeMillis());
+                                        em.update(notification);
+                                    }
+                                }
+
+                                //start working if you are on a large batch,
+                                if (maySchedule && numCurrentBatchesConfig >= batchCount.incrementAndGet()) {
+                                    processBatchAndReschedule(notification, jobExecution);
+                                }
+
+                                if(devicesRef.size() <=0){
+                                    errorMessages.add("Could not find devices for entity: "+entity.getUuid());
+                                }
+
+                            } catch (Exception deviceLoopException) {
+                                LOG.error("Failed to add devices", deviceLoopException);
+                                errorMessages.add("Failed to add devices for entity: "+entity.getUuid() + " error:"+ deviceLoopException);
+                            }
+                            return entity;
+                        }
+                    });
+                }
+            }, Schedulers.io()).toBlocking().lastOrDefault(null);
+
+        }
+
+        batchCount.set(Math.min(numCurrentBatchesConfig, batchCount.get()));
+        // update queued time
+        Map<String, Object> properties = new HashMap<String, Object>(2);
+        properties.put("queued", notification.getQueued());
+        properties.put("state", notification.getState());
+
+        //do i have devices, and have i already started batching.
+        if (deviceCount.get()>0 ) {
+            if(batchCount.get() <= 0) {
+                processBatchAndReschedule(notification, jobExecution);
+            }
+        } else {
+            //if i'm in a test value will be false, do not mark finished for test orchestration, not ideal need real tests
+            if(!IS_TEST) {
+                finishedBatch(notification, 0, 0);
+                errorMessages.add("No devices for notification " + notification.getUuid());
+            }
+        }
+
+        if(!IS_TEST && errorMessages.size()>0){
+            properties.put("deliveryErrors", errorMessages.toArray());
+            if(notification.getErrorMessage()==null){
+                notification.setErrorMessage("There was a problem delivering all of your notifications. See deliveryErrors in properties");
+            }
+        }
+        notification.addProperties(properties);
+        em.update(notification);
+        long elapsed = notification.getQueued() - startTime;
+
+        if (LOG.isInfoEnabled()) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("notification ").append(notification.getUuid());
+            sb.append(" done queuing to ").append(deviceCount);
+            sb.append(" devices in ").append(elapsed).append(" ms");
+            LOG.info(sb.toString());
+        }
+    }
+    public void finishedBatch(Notification notification, long successes, long failures) throws Exception {
+        finishedBatch(notification,successes,failures,false);
+    }
+    public void finishedBatch(Notification notification, long successes, long failures, boolean overrideComplete) throws Exception {
+        if (LOG.isDebugEnabled()) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("finishedBatch ").append(notification.getUuid());
+            sb.append(" successes: ").append(successes);
+            sb.append(" failures: ").append(failures);
+            LOG.info(sb.toString());
+        }
+
+        notification = em.get(notification, Notification.class); // refresh data
+        notification.updateStatistics(successes, failures);
+        notification.setModified(System.currentTimeMillis());
+        Map<String, Object> properties = new HashMap<String, Object>(4);
+        properties.put("statistics", notification.getStatistics());
+        properties.put("modified", notification.getModified());
+
+        if (isNotificationDeliveryComplete(notification) || overrideComplete) {
+            notification.setFinished(notification.getModified());
+            properties.put("finished", notification.getModified());
+            properties.put("state", notification.getState());
+            long elapsed = notification.getFinished()
+                    - notification.getStarted();
+            long sent = notification.getStatistics().get("sent");
+            long errors = notification.getStatistics().get("errors");
+
+            if (LOG.isInfoEnabled()) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("notification ").append(notification.getUuid());
+                sb.append(" done sending to ").append(sent + errors);
+                sb.append(" devices in ").append(elapsed).append(" ms");
+                LOG.info(sb.toString());
+            }
+
+        } else {
+            LOG.info("notification finished batch: {}",
+                    notification.getUuid());
+        }
+        em.updateProperties(notification, properties);
+
+        Set<Notifier> notifiers = new HashSet<Notifier>(getNotifierMap().values()); // remove dups
+        asyncCheckForInactiveDevices(notifiers);
+    }
+
+    private HashMap<Object,Notifier> getNotifierMap(){
+        try{
+            return notifierCacheMap.get(em);
+        }catch (ExecutionException ee){
+            LOG.error("failed to get from cache",ee);
+            return new HashMap<Object, Notifier>();
+        }
+    }
+    /*
+        * returns partial list of Device EntityRefs (up to BATCH_SIZE) - empty when
+        * done w/ delivery
+        */
+    private QueueResults getDeliveryBatch(EntityRef notification, int batchSize) throws Exception {
+
+        QueueQuery qq = new QueueQuery();
+        qq.setLimit(batchSize);
+        qq.setTimeout(MESSAGE_TRANSACTION_TIMEOUT);
+        QueueResults results = qm.getFromQueue(getJobQueueName(notification), qq);
+        LOG.debug("got batch of {} devices for notification {}",
+                results.size(), notification.getUuid());
+        return results;
+    }
+    /**
+     * executes a Notification batch and schedules the next one - called by
+     * NotificationBatchJob
+     */
+    public void processBatchAndReschedule(Notification notification, JobExecution jobExecution) throws Exception {
+        if (!isOkToSend(notification,jobExecution)) {
+            LOG.info("notification " + notification.getUuid() + " canceled");
+            if (jobExecution != null) {
+                jobExecution.killed();
+            }
+            return;
+        }
+
+        LOG.debug("processing batch {}", notification.getUuid());
+
+        QueueResults queueResults = getDeliveryBatch(notification, jobExecution == null ? BATCH_SIZE/2 : BATCH_SIZE ); //if first run then throttle the batch down by factor of 2 if its a job then try to grab alot of notifications and run them all
+
+        long reschedule_delay = jobScheduler.SCHEDULER_GRACE_PERIOD;
+        final TaskManager taskManager =  new TaskManager( em, this, qm, notification, queueResults);
+        if (queueResults.size() > 0) {
+            consecutiveEmptyQueues.set(0);
+            sendBatchToProviders(taskManager, notification, queueResults.getMessages());
+        }else{
+            consecutiveEmptyQueues.incrementAndGet();
+        }
+
+        if (!isNotificationDeliveryComplete(notification) && consecutiveEmptyQueues.get() <= CONSECUTIVE_EMPTY_QUEUES) {
+            if(jobExecution==null) {
+                jobScheduler.scheduleBatchJob(notification, reschedule_delay);
+            }else{
+                processBatchAndReschedule(notification, jobExecution);
+            }
+        } else {
+            consecutiveEmptyQueues.set(0);
+            finishedBatch(notification, 0, 0,true);
+        }
+
+        LOG.debug("finished processing batch");
+    }
+
+    /**
+     * send batches of notifications to provider
+     * @param taskManager
+     * @param notification
+     * @param queueResults
+     * @throws Exception
+     */
+    private void sendBatchToProviders(final TaskManager taskManager, final Notification notification, List<Message> queueResults) throws Exception {
+
+        LOG.info("sending batch of {} devices for Notification: {}", queueResults.size(), notification.getUuid());
+        final Map<Object, Notifier> notifierMap = getNotifierMap();
+        queueSize.update(queueResults.size());
+        final Map<String, Object> payloads = notification.getPayloads();
+        final Map<String, Object> translatedPayloads = translatePayloads(payloads, notifierMap);
+        try {
+            Observable
+                    .from(queueResults)
+                    .parallel(new Func1<Observable<Message>, Observable<Message>>() {
+                        @Override
+                        public Observable<Message> call(Observable<Message> messageObservable) {
+                            return messageObservable.map(new Func1<Message, Message>() {
+                                @Override
+                                public Message call(Message message) {
+                                    UUID deviceUUID = (UUID) message.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID);
+                                    boolean foundNotifier = false;
+                                    for (Map.Entry<String, Object> entry : payloads.entrySet()) {
+                                        try {
+                                            String payloadKey = entry.getKey();
+                                            Notifier notifier = notifierMap.get(payloadKey.toLowerCase());
+                                            EntityRef deviceRef = new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID);
+
+                                            String providerId;
+                                            try {
+                                                providerId = getProviderId(deviceRef, notifier);
+                                                if (providerId == null) {
+                                                    LOG.debug("Provider not found.{} {}", deviceRef,notifier.getName());
+                                                    continue;
+                                                }
+                                            } catch (Exception providerException) {
+                                                LOG.error("Exception getting provider.", providerException);
+                                                continue;
+                                            }
+                                            Object payload = translatedPayloads.get(payloadKey);
+
+                                            Receipt receipt = new Receipt(notification.getUuid(), providerId, payload,deviceUUID);
+                                            TaskTracker tracker = new TaskTracker(notifier, taskManager, receipt, deviceUUID);
+                                            if (payload == null) {
+                                                LOG.debug("selected device {} for notification {} doesn't have a valid payload. skipping.", deviceUUID, notification.getUuid());
+                                                try {
+                                                    tracker.failed(0, "failed to match payload to " + payloadKey + " notifier");
+                                                } catch (Exception e) {
+                                                    LOG.debug("failed to mark device failed" + e);
+                                                }
+                                                continue;
+                                            }
+
+                                            if (LOG.isDebugEnabled()) {
+                                                StringBuilder sb = new StringBuilder();
+                                                sb.append("sending notification ").append(notification.getUuid());
+                                                sb.append(" to device ").append(deviceUUID);
+                                                LOG.debug(sb.toString());
+                                            }
+
+                                            try {
+                                                ProviderAdapter providerAdapter = providerAdapters.get(notifier.getProvider());
+                                                providerAdapter.sendNotification(providerId, notifier, payload, notification, tracker);
+
+                                            } catch (Exception e) {
+                                                try {
+                                                    tracker.failed(0, e.getMessage());
+                                                } catch (Exception trackerException) {
+                                                    LOG.error("tracker failed", trackerException);
+                                                }
+                                            }
+                                            foundNotifier = true;
+                                        } finally {
+                                            sendMeter.mark();
+                                        }
+                                    }
+                                    if (!foundNotifier) {
+                                        try {
+                                            taskManager.skip(deviceUUID);
+                                        } catch (Exception trackerException) {
+                                            LOG.error("failed on skip", trackerException);
+                                        }
+                                    }
+                                    return message;
+                                }
+                            });
+                        }
+                    }, Schedulers.io())
+                    .toBlocking()
+                    .lastOrDefault(null);
+
+            //for gcm this will actually send notification
+            for (ProviderAdapter providerAdapter : providerAdapters.values()) {
+                try {
+                    providerAdapter.doneSendingNotifications();
+                } catch (Exception e) {
+                    LOG.error("providerAdapter.doneSendingNotifications: ", e);
+                }
+            }
+
+        } finally {
+            outstandingQueue.dec();
+            LOG.info("finished sending batch for notification {}", notification.getUuid());
+        }
+
+    }
+
+    private Map<String, Object> translatePayloads(Map<String, Object> payloads, Map<Object, Notifier> notifierMap) throws Exception {
+        Map<String, Object> translatedPayloads = new HashMap<String, Object>(
+                payloads.size());
+        for (Map.Entry<String, Object> entry : payloads.entrySet()) {
+            String payloadKey = entry.getKey();
+            Object payloadValue = entry.getValue();
+            Notifier notifier = notifierMap.get(payloadKey);
+            if (notifier != null) {
+                ProviderAdapter providerAdapter = providerAdapters.get(notifier
+                        .getProvider());
+                if (providerAdapter != null) {
+                    Object translatedPayload = payloadValue != null ? providerAdapter
+                            .translatePayload(payloadValue) : null;
+                    if (translatedPayload != null) {
+                        translatedPayloads.put(payloadKey, translatedPayload);
+                    }
+                }
+            }
+        }
+        return translatedPayloads;
+    }
+
+    private int getNumConcurrentBatches() {
+        return Integer.parseInt(props.getProperty(NOTIFICATION_CONCURRENT_BATCHES, "1"));
+    }
+
+    private static final class IteratorObservable<T> implements Observable.OnSubscribe<T> {
+        private final Iterator<T> input;
+        private IteratorObservable( final Iterator input ) {this.input = input;}
+
+        @Override
+        public void call( final Subscriber<? super T> subscriber ) {
+
+            /**
+             * You would replace this code with your file reading.  Instead of emitting from an iterator,
+             * you would create a bean object that represents the entity, and then emit it
+             */
+
+            try {
+                while ( !subscriber.isUnsubscribed() && input.hasNext() ) {
+                    //send our input to the next
+                    subscriber.onNext( (T) input.next() );
+                }
+
+                //tell the subscriber we don't have any more data
+                subscriber.onCompleted();
+            }
+            catch ( Throwable t ) {
+                LOG.error("failed on subscriber",t);
+                subscriber.onError( t );
+            }
+        }
+    }
+
+    public void asyncCheckForInactiveDevices(Set<Notifier> notifiers)  throws Exception {
+        for (final Notifier notifier : notifiers) {
+            INACTIVE_DEVICE_CHECK_POOL.execute(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        checkForInactiveDevices(notifier);
+                    } catch (Exception e) {
+                        LOG.error("checkForInactiveDevices", e); // not
+                        // essential so
+                        // don't fail,
+                        // but log
+                    }
+                }
+            });
+        }
+    }
+
+    /** gets the list of inactive devices from the Provider and updates them */
+    private void checkForInactiveDevices(Notifier notifier) throws Exception {
+        ProviderAdapter providerAdapter = providerAdapters.get(notifier
+                .getProvider());
+        if (providerAdapter != null) {
+            LOG.debug("checking notifier {} for inactive devices", notifier);
+            Map<String, Date> inactiveDeviceMap = providerAdapter
+                    .getInactiveDevices(notifier, em);
+
+            if (inactiveDeviceMap != null && inactiveDeviceMap.size() > 0) {
+                LOG.debug("processing {} inactive devices",
+                        inactiveDeviceMap.size());
+                Map<String, Object> clearPushtokenMap = new HashMap<String, Object>(
+                        2);
+                clearPushtokenMap.put(notifier.getName() + NOTIFIER_ID_POSTFIX,
+                        "");
+                clearPushtokenMap.put(notifier.getUuid() + NOTIFIER_ID_POSTFIX,
+                        "");
+
+                // todo: this could be done in a single query
+                for (Map.Entry<String, Date> entry : inactiveDeviceMap
+                        .entrySet()) {
+                    // name
+                    Query query = new Query();
+                    query.addEqualityFilter(notifier.getName()
+                            + NOTIFIER_ID_POSTFIX, entry.getKey());
+                    Results results = em.searchCollection(em.getApplication(),
+                            "devices", query);
+                    for (Entity e : results.getEntities()) {
+                        em.updateProperties(e, clearPushtokenMap);
+                    }
+                    // uuid
+                    query = new Query();
+                    query.addEqualityFilter(notifier.getUuid()
+                            + NOTIFIER_ID_POSTFIX, entry.getKey());
+                    results = em.searchCollection(em.getApplication(),
+                            "devices", query);
+                    for (Entity e : results.getEntities()) {
+                        em.updateProperties(e, clearPushtokenMap);
+                    }
+                }
+            }
+            LOG.debug("finished checking notifier {} for inactive devices",
+                    notifier);
+        }
+    }
+
+    private boolean isOkToSend(Notification notification,
+                               JobExecution jobExecution) {
+        String autoExpireAfterString = props.getProperty(PUSH_AUTO_EXPIRE_AFTER_PROPNAME);
+
+        if (autoExpireAfterString != null) {
+            pushAutoExpireAfter = Long.parseLong(autoExpireAfterString);
+        }
+        if (pushAutoExpireAfter != null) {
+            if (notification.getCreated() < System.currentTimeMillis() - pushAutoExpireAfter) {
+                notification.setExpire(System.currentTimeMillis() - 1L);
+            }
+        }
+
+        if (notification.getFinished() != null) {
+            LOG.info("notification {} already processed. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        if (notification.getCanceled() == Boolean.TRUE) {
+            LOG.info("notification {} canceled. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        if (notification.isExpired()) {
+            LOG.info("notification {} expired. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+        if (jobExecution != null
+                && notification.getDeliver() != null
+                && !notification.getDeliver().equals(jobExecution.getJobData().getProperty("deliver"))
+                ) {
+            LOG.info("notification {} was rescheduled. not sending.",
+                    notification.getUuid());
+            return false;
+        }
+
+        return true;
+    }
+
+    private List<EntityRef> getDevices(EntityRef ref) throws Exception {
+        List<EntityRef> devices = Collections.EMPTY_LIST;
+        if ("device".equals(ref.getType())) {
+            devices = Collections.singletonList(ref);
+        } else if ("user".equals(ref.getType())) {
+            devices = em.getCollection(ref, "devices", null, Query.MAX_LIMIT, Query.Level.REFS, false).getRefs();
+        } else if ("group".equals(ref.getType())) {
+            devices = new ArrayList<EntityRef>();
+            for (EntityRef r : em.getCollection(ref, "users", null,  Query.MAX_LIMIT, Query.Level.REFS, false).getRefs()) {
+                devices.addAll(getDevices(r));
+            }
+        }
+        return devices;
+    }
+
+
+    private String getProviderId(EntityRef device, Notifier notifier) throws Exception {
+        try {
+            Object value = em.getProperty(device, notifier.getName() + NOTIFIER_ID_POSTFIX);
+            if (value == null) {
+                value = em.getProperty(device, notifier.getUuid() + NOTIFIER_ID_POSTFIX);
+            }
+            return value != null ? value.toString() : null;
+        } catch (Exception e) {
+            LOG.error("Errer getting provider ID, proceding with rest of batch", e);
+            return null;
+        }
+    }
+
+
+    private boolean isNotificationDeliveryComplete(Notification notification) throws Exception {
+        if(notification.getQueued() == null){
+            return false;
+        }
+        String queuePath = getJobQueueName(notification);
+        return !qm.hasPendingReads(queuePath, null)
+                && !qm.hasOutstandingTransactions(queuePath, null)
+                && !qm.hasMessagesInQueue(queuePath, null);
+    }
+
+    private String getJobQueueName(EntityRef entityRef) {
+        return utils.pluralize(entityRef.getType()) + "/" + entityRef.getUuid();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
new file mode 100644
index 0000000..7dd6503
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -0,0 +1,327 @@
+/*
+ * 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.usergrid.services.notifications;
+
+import java.util.*;
+
+import com.codahale.metrics.*;
+import com.codahale.metrics.Timer;
+import org.apache.usergrid.metrics.MetricsFactory;
+import org.apache.usergrid.mq.Message;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.index.query.Identifier;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.persistence.exceptions.RequiredPropertyNotFoundException;
+import org.apache.usergrid.services.exceptions.ForbiddenServiceOperationException;
+import static org.apache.usergrid.utils.InflectionUtils.pluralize;
+
+import org.apache.usergrid.services.notifications.apns.APNsAdapter;
+import org.apache.usergrid.services.notifications.gcm.GCMAdapter;
+import rx.Observable;
+import rx.functions.Func1;
+import rx.schedulers.Schedulers;
+
+public class NotificationsService extends AbstractCollectionService {
+
+
+    private MetricsFactory metricsService;
+    private Meter sendMeter;
+    private Meter postMeter;
+    private Timer postTimer;
+    private Histogram queueSize;
+    private Counter outstandingQueue;
+
+    private static final int PAGE = 100;
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsService.class);
+
+
+    public static final String NOTIFIER_ID_POSTFIX = ".notifier.id";
+
+    static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
+
+    static {
+        Message.MESSAGE_PROPERTIES.put(
+                MESSAGE_PROPERTY_DEVICE_UUID, UUID.class);
+    }
+
+    // these 2 can be static, but GCM can't. future: would be nice to get gcm
+    // static as well...
+    public static ProviderAdapter APNS_ADAPTER = new APNsAdapter();
+    public static ProviderAdapter TEST_ADAPTER = new TestAdapter();
+
+    public final Map<String, ProviderAdapter> providerAdapters =
+            new HashMap<String, ProviderAdapter>(3);
+    {
+        providerAdapters.put("apple", APNS_ADAPTER);
+        providerAdapters.put("google", new GCMAdapter());
+        providerAdapters.put("noop", TEST_ADAPTER);
+    }
+
+    private NotificationsQueueManager notificationQueueManager;
+    private long gracePeriod;
+
+    public NotificationsService() {
+        LOG.info("/notifications");
+    }
+
+    @Override
+    public void init( ServiceInfo info ) {
+        super.init(info);
+        metricsService = getApplicationContext().getBean(MetricsFactory.class);
+        sendMeter = metricsService.getMeter(NotificationsService.class, "send");
+        postMeter = metricsService.getMeter(NotificationsService.class, "requests");
+        postTimer = metricsService.getTimer(this.getClass(), "execution_rest");
+        queueSize = metricsService.getHistogram(NotificationsService.class, "queue_size");
+        outstandingQueue = metricsService.getCounter(NotificationsService.class,"current_queue");
+        JobScheduler jobScheduler = new JobScheduler(sm,em);
+        notificationQueueManager = new NotificationsQueueManager(jobScheduler,em,sm.getProperties(),sm.getQueueManager(),metricsService);
+        gracePeriod = jobScheduler.SCHEDULER_GRACE_PERIOD;
+    }
+
+    public NotificationsQueueManager getQueueManager(){
+        return notificationQueueManager;
+    }
+
+    @Override
+    public ServiceContext getContext(ServiceAction action,
+            ServiceRequest request, ServiceResults previousResults,
+            ServicePayload payload) throws Exception {
+
+        ServiceContext context = super.getContext(action, request, previousResults, payload);
+
+        if (action == ServiceAction.POST) {
+            context.setQuery(null); // we don't use this, and it must be null to
+                                    // force the correct execution path
+        }
+        return context;
+    }
+
+    @Override
+    public ServiceResults postCollection(ServiceContext context) throws Exception {
+        Timer.Context timer = postTimer.time();
+        postMeter.mark();
+        try {
+            validate(null, context.getPayload());
+            PathQuery<Device> pathQuery = getPathQuery(context.getRequest().getOriginalParameters());
+            context.getProperties().put("state", Notification.State.CREATED);
+            context.getProperties().put("pathQuery", pathQuery);
+            context.setOwner(sm.getApplication());
+            ServiceResults results = super.postCollection(context);
+            Notification notification = (Notification) results.getEntity();
+            if(!notificationQueueManager.scheduleQueueJob(notification)){
+                notificationQueueManager.queueNotification(notification, null);
+            }
+            outstandingQueue.inc();
+            // future: somehow return 202?
+            return results;
+        }finally {
+            timer.stop();
+        }
+    }
+
+    private PathQuery<Device> getPathQuery(List<ServiceParameter> parameters)
+            throws Exception {
+
+        PathQuery pathQuery = null;
+        for (int i = 0; i < parameters.size() - 1; i += 2) {
+            String collection = pluralize(parameters.get(i).getName());
+            ServiceParameter sp = parameters.get(i + 1);
+            org.apache.usergrid.persistence.index.query.Query query = sp.getQuery();
+            if (query == null) {
+                query = new Query();
+                query.addIdentifier(sp.getIdentifier());
+            }
+            query.setLimit(PAGE);
+            query.setCollection(collection);
+
+            if (pathQuery == null) {
+                pathQuery = new PathQuery(em.getApplicationRef(), query);
+            } else {
+                pathQuery = pathQuery.chain(query);
+            }
+        }
+
+        return pathQuery;
+    }
+
+    @Override
+    public ServiceResults postItemsByQuery(ServiceContext context, Query query) throws Exception {
+        return postCollection(context);
+    }
+
+    @Override
+    public Entity updateEntity(ServiceRequest request, EntityRef ref,
+            ServicePayload payload) throws Exception {
+
+        validate(ref, payload);
+
+        Notification notification = em.get(ref, Notification.class);
+
+        if ("restart".equals(payload.getProperty("restart"))) { // for emergency
+                                                                // use only
+            payload.getProperties().clear();
+            payload.setProperty("restart", "");
+            payload.setProperty("errorMessage", "");
+            payload.setProperty("deliver", System.currentTimeMillis() + gracePeriod);
+
+            // once finished, immutable
+        } else if (notification.getFinished() != null) {
+            throw new ForbiddenServiceOperationException(request,
+                    "Notification immutable once sent.");
+
+            // once started, only cancel is allowed
+        } else if (notification.getStarted() != null) {
+            if (payload.getProperty("canceled") != Boolean.TRUE) {
+                throw new ForbiddenServiceOperationException(request,
+                        "Notification has started. You may only set canceled.");
+            }
+            payload.getProperties().clear();
+            payload.setProperty("canceled", Boolean.TRUE);
+        }
+
+        Entity response = super.updateEntity(request, ref, payload);
+
+        Long deliver = (Long) payload.getProperty("deliver");
+        if (deliver != null) {
+            if (!deliver.equals(notification.getDeliver())) {
+                notificationQueueManager.processBatchAndReschedule((Notification) response, null);
+            }
+        }
+        return response;
+    }
+
+    @Override
+    protected boolean isDeleteAllowed(ServiceContext context, Entity entity) {
+        Notification notification = (Notification) entity;
+        return (notification.getStarted() == null);
+    }
+
+    public Set<String> getProviders() {
+        return providerAdapters.keySet();
+    }
+
+    // validate payloads
+    private void validate(EntityRef ref, ServicePayload servicePayload)
+            throws Exception {
+        Object obj_payloads = servicePayload.getProperty("payloads");
+        if (obj_payloads == null && ref == null) {
+            throw new RequiredPropertyNotFoundException("notification",
+                    "payloads");
+        }
+        if (obj_payloads != null) {
+            if (!(obj_payloads instanceof Map)) {
+                throw new IllegalArgumentException(
+                        "payloads must be a JSON Map");
+            }
+            final Map<String, Object> payloads = (Map<String, Object>) obj_payloads;
+            final Map<Object, Notifier> notifierMap = getNotifierMap(payloads);
+            Observable t = Observable.from(payloads.entrySet()).subscribeOn(Schedulers.io()).map(new Func1<Map.Entry<String, Object>, Object>() {
+                @Override
+                public Object call(Map.Entry<String, Object> entry) {
+                    String notifierId = entry.getKey();
+                    Notifier notifier = notifierMap.get(notifierId);
+                    if (notifier == null) {
+                        throw new IllegalArgumentException("notifier \""
+                                + notifierId + "\" not found");
+                    }
+                    ProviderAdapter providerAdapter = providerAdapters.get(notifier
+                            .getProvider());
+                    Object payload = entry.getValue();
+                    try {
+                        return providerAdapter.translatePayload(payload); // validate
+                        // specifically to
+                        // provider
+                    } catch (Exception e) {
+                        return e;
+                    }
+                }
+            });
+            Object e = t.toBlocking().lastOrDefault(null);
+            if(e instanceof Throwable){
+                throw new Exception((Exception)e);
+            }
+
+        }
+    }
+
+
+
+    public String getJobQueueName(EntityRef notification) {
+        return "notifications/" + notification.getUuid();
+    }
+
+
+
+    /* adds a single device for delivery - used only by tests */
+    public void addDevice(EntityRef notification, EntityRef device) throws Exception {
+
+        String jobQueueName = getJobQueueName(notification);
+        Message message = new Message();
+        message.setObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID,
+                device.getUuid());
+        sm.getQueueManager().postToQueue(jobQueueName, message);
+    }
+
+    public Notification getSourceNotification(EntityRef receipt)
+            throws Exception {
+        Receipt r = em.get(receipt.getUuid(), Receipt.class);
+        return em.get(r.getNotificationUUID(), Notification.class);
+    }
+
+
+    /* create a map of Notifier UUIDs and/or names to Notifiers */
+    protected Map<Object, Notifier> getNotifierMap(Map payloads)
+            throws Exception {
+        Map<Object, Notifier> notifiers = new HashMap<Object, Notifier>(
+                payloads.size() * 2);
+        for (Object id : payloads.keySet()) {
+            Identifier identifier = Identifier.from(id);
+            Notifier notifier;
+            if (identifier.isUUID()) {
+                notifier = em.get(identifier.getUUID(), Notifier.class);
+            } else {
+                EntityRef ref = em.getAlias("notifier", identifier.getName());
+                notifier = em.get(ref, Notifier.class);
+            }
+            if (notifier != null) {
+                notifiers.put(notifier.getUuid(), notifier);
+                notifiers.put(notifier.getUuid().toString(), notifier);
+                if (notifier.getName() != null) {
+                    notifiers.put(notifier.getName(), notifier);
+                }
+            }
+        }
+        return notifiers;
+    }
+
+
+    /**
+     * attempts to test the providers connections - throws an Exception on
+     * failure
+     */
+    public void testConnection(Notifier notifier) throws Exception {
+        ProviderAdapter providerAdapter = providerAdapters.get(notifier.getProvider());
+        if (providerAdapter != null) {
+            providerAdapter.testConnection(notifier);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d7901ae/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
new file mode 100644
index 0000000..5489c2d
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ProviderAdapter.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.services.notifications;
+
+import java.util.Date;
+import java.util.Map;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.Notification;
+import org.apache.usergrid.persistence.Notifier;
+import org.apache.usergrid.services.ServicePayload;
+
+/**
+ * To send a Notification, the following methods should be called in this order:
+ * 1) testConnection() for each notifier to be used 2) translatePayload() for
+ * each payload to be sent 3) sendNotification() for each target 4)
+ * doneSendingNotifications() when all #2 have been called If there is an
+ * Exception in #1 or #2, you should consider the entire Notification to be
+ * invalid. Also, getInactiveDevices() should be called occasionally and may be
+ * called at any time.
+ */
+public interface ProviderAdapter {
+
+    public void testConnection(Notifier notifier) throws ConnectionException;
+
+    public void sendNotification(String providerId, Notifier notifier,
+                                 Object payload, Notification notification, TaskTracker tracker)
+            throws Exception;
+
+    /**
+     * must be called when done calling sendNotification() so any open batches
+     * may be closed out
+     */
+    public void doneSendingNotifications() throws Exception;
+
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+                                                EntityManager em) throws Exception;
+
+    public Object translatePayload(Object payload) throws Exception;
+
+    public void validateCreateNotifier(ServicePayload payload) throws Exception;
+}


[27/33] git commit: Merge branch 'two-dot-o-push-notifications' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications

Posted by sn...@apache.org.
Merge branch 'two-dot-o-push-notifications' of https://git-wip-us.apache.org/repos/asf/incubator-usergrid into two-dot-o-push-notifications


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

Branch: refs/heads/two-dot-o
Commit: c4b1ae6c58a54ad0307baf03f886f5338ab78ec4
Parents: 06db9e7 cb668d2
Author: Shawn Feldman <sf...@apache.org>
Authored: Thu Sep 4 09:40:44 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Thu Sep 4 09:40:44 2014 -0600

----------------------------------------------------------------------
 .gitignore                                      |    22 +-
 DISCLAIMER                                      |     9 +
 LICENSE                                         |    26 +
 NOTICE                                          |    11 +-
 README.md                                       |    20 +-
 bower.json                                      |    39 -
 .../src/test/resources/install_cassandra.sh     |    19 -
 chop/stack/src/test/resources/install_es.sh     |    19 -
 .../stack/src/test/resources/setup_cassandra.sh |    19 -
 chop/stack/src/test/resources/setup_es.sh       |    19 -
 .../src/main/resources/jettyjam.properties      |    18 -
 portal/Gruntfile.js                             |   136 +-
 portal/README.md                                |    20 +-
 portal/archive/coming_soon.html                 |    31 -
 portal/archive/config.js                        |    72 -
 .../ui-bg_diagonals-thick_90_eeeeee_40x40.png   |   Bin 251 -> 0 bytes
 .../images/ui-bg_flat_100_deedf7_40x100.png     |   Bin 182 -> 0 bytes
 .../images/ui-bg_flat_100_e4f1fb_40x100.png     |   Bin 213 -> 0 bytes
 .../images/ui-bg_flat_100_f2f5f7_40x100.png     |   Bin 212 -> 0 bytes
 .../images/ui-bg_flat_15_cd0a0a_40x100.png      |   Bin 181 -> 0 bytes
 .../images/ui-bg_flat_50_3baae3_40x100.png      |   Bin 182 -> 0 bytes
 .../images/ui-bg_flat_80_d7ebf9_40x100.png      |   Bin 183 -> 0 bytes
 .../ui-bg_highlight-hard_70_000000_1x100.png    |   Bin 118 -> 0 bytes
 .../ui-bg_highlight-soft_25_ffef8f_1x100.png    |   Bin 153 -> 0 bytes
 .../images/ui-icons_000000_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_2694e8_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_2e83ff_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_3d80b3_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_72a7cf_256x240.png          |   Bin 4369 -> 0 bytes
 .../images/ui-icons_ffffff_256x240.png          |   Bin 4369 -> 0 bytes
 .../css/custom-theme/jquery-ui-1.8.9.custom.css |   573 -
 portal/archive/css/jquery-ui-timepicker.css     |    53 -
 portal/archive/css/jquery.ui.statusbar.css      |    25 -
 portal/archive/css/prettify.css                 |    52 -
 portal/archive/css/usergrid-stripped.css        |  5199 ----
 portal/archive/css/usergrid.css                 |  5203 ----
 portal/archive/dash/README.md                   |     3 -
 .../archive/dash/config/testacular-e2e.conf.js  |    22 -
 portal/archive/dash/config/testacular.conf.js   |    20 -
 portal/archive/dash/test/e2e/runner.html        |    10 -
 portal/archive/dash/test/e2e/scenarios.js       |    45 -
 .../dash/test/lib/angular/angular-mocks.js      |  1764 --
 .../dash/test/lib/angular/angular-scenario.js   | 26195 -----------------
 .../archive/dash/test/lib/angular/version.txt   |     1 -
 .../archive/dash/test/unit/controllersSpec.js   |    31 -
 portal/archive/dash/test/unit/directivesSpec.js |    19 -
 portal/archive/dash/test/unit/filtersSpec.js    |    19 -
 portal/archive/dash/test/unit/servicesSpec.js   |    14 -
 portal/archive/images/APNS_cert_upload.png      |   Bin 33956 -> 0 bytes
 portal/archive/images/APNS_certification.png    |   Bin 16855 -> 0 bytes
 portal/archive/images/android-notification.png  |   Bin 41629 -> 0 bytes
 portal/archive/images/android-sdk-download.png  |   Bin 4848 -> 0 bytes
 portal/archive/images/api-activity.gif          |   Bin 10819 -> 0 bytes
 portal/archive/images/apigee-logo.png           |   Bin 3647 -> 0 bytes
 portal/archive/images/apigeetopbar.png          |   Bin 4658 -> 0 bytes
 portal/archive/images/background_one_col.png    |   Bin 3126 -> 0 bytes
 portal/archive/images/btn-copyCurl-up.png       |   Bin 2762 -> 0 bytes
 portal/archive/images/clippy-bg.png             |   Bin 561 -> 0 bytes
 portal/archive/images/close.gif                 |   Bin 718 -> 0 bytes
 portal/archive/images/dotnet-sdk-download.png   |   Bin 7149 -> 0 bytes
 portal/archive/images/down_arrow.png            |   Bin 1285 -> 0 bytes
 portal/archive/images/error.png                 |   Bin 2009 -> 0 bytes
 portal/archive/images/faviconApigee.ico         |   Bin 1150 -> 0 bytes
 .../images/glyphicons-halflings-white.png       |   Bin 4352 -> 0 bytes
 portal/archive/images/glyphicons-halflings.png  |   Bin 4352 -> 0 bytes
 .../glyphicons_halflings_135_wrench-white2.pdn  |   Bin 5400 -> 0 bytes
 .../glyphicons_halflings_135_wrench-white2.png  |   Bin 296 -> 0 bytes
 .../images/glyphicons_halflings_135_wrench.png  |   Bin 228 -> 0 bytes
 .../glyphicons_halflings_135_wrench_white.png   |   Bin 251 -> 0 bytes
 .../glyphicons_halflings_wrench_white.png       |   Bin 1016 -> 0 bytes
 portal/archive/images/google_api_key.png        |   Bin 98118 -> 0 bytes
 portal/archive/images/green_dot.png             |   Bin 3472 -> 0 bytes
 portal/archive/images/grid.png                  |   Bin 166 -> 0 bytes
 portal/archive/images/icons.png                 |   Bin 13132 -> 0 bytes
 portal/archive/images/ios-sdk-download.png      |   Bin 4886 -> 0 bytes
 portal/archive/images/iphone_message.png        |   Bin 90307 -> 0 bytes
 .../archive/images/javascript-sdk-download.png  |   Bin 4618 -> 0 bytes
 portal/archive/images/left_arrow.png            |   Bin 1257 -> 0 bytes
 portal/archive/images/logo-white.png            |   Bin 2014 -> 0 bytes
 portal/archive/images/menuActiveTriangle.png    |   Bin 315 -> 0 bytes
 portal/archive/images/nodejs-sdk-download.png   |   Bin 5273 -> 0 bytes
 portal/archive/images/notice.png                |   Bin 2112 -> 0 bytes
 portal/archive/images/orange-arrow.png          |   Bin 242 -> 0 bytes
 .../archive/images/push_notifications_icon.png  |   Bin 338 -> 0 bytes
 portal/archive/images/red_dot.png               |   Bin 3482 -> 0 bytes
 portal/archive/images/right_arrow.png           |   Bin 1251 -> 0 bytes
 portal/archive/images/ruby-sdk-download.png     |   Bin 6343 -> 0 bytes
 portal/archive/images/step_1.png                |   Bin 1953 -> 0 bytes
 portal/archive/images/step_2.png                |   Bin 2117 -> 0 bytes
 portal/archive/images/step_3.png                |   Bin 2162 -> 0 bytes
 portal/archive/images/success.png               |   Bin 1863 -> 0 bytes
 portal/archive/images/swish_arrow.png           |   Bin 220 -> 0 bytes
 portal/archive/images/topbackground.png         |   Bin 2890 -> 0 bytes
 portal/archive/images/up_arrow.png              |   Bin 1292 -> 0 bytes
 portal/archive/images/user-photo.png            |   Bin 3849 -> 0 bytes
 portal/archive/images/user_profile.png          |   Bin 3775 -> 0 bytes
 portal/archive/images/usergrid_200.png          |   Bin 6397 -> 0 bytes
 portal/archive/images/usergrid_400.png          |   Bin 8746 -> 0 bytes
 portal/archive/images/warning.png               |   Bin 1179 -> 0 bytes
 portal/archive/images/yellow_dot.png            |   Bin 3475 -> 0 bytes
 portal/archive/index-stripped2.html             |  1795 --
 portal/archive/index.html                       |  1932 --
 portal/archive/js/app/app.js                    |   131 -
 portal/archive/js/app/console.js                |  5397 ----
 portal/archive/js/app/helpers.js                |   241 -
 portal/archive/js/app/navigation.js             |   251 -
 portal/archive/js/app/pages.js                  |   161 -
 portal/archive/js/app/params.js                 |    30 -
 portal/archive/js/app/quickLogin.js             |    30 -
 portal/archive/js/app/session.js                |   176 -
 portal/archive/js/app/sso.js                    |   135 -
 portal/archive/js/app/status.js                 |    37 -
 portal/archive/js/app/ui/collections.entity.js  |   320 -
 portal/archive/js/app/ui/collections.user.js    |   120 -
 portal/archive/js/app/ui/ui.js                  |   415 -
 portal/archive/js/app/usergrid.appSDK.js        |  2097 --
 portal/archive/js/app/usergrid.appSDK.orig.js   |  2070 --
 portal/archive/js/lib/MD5.min.js                |     1 -
 portal/archive/js/lib/backbone.js               |  1431 -
 portal/archive/js/lib/bootstrap.min.js          |     7 -
 portal/archive/js/lib/date.min.js               |     2 -
 portal/archive/js/lib/jquery-1.7.2.min.js       |     4 -
 portal/archive/js/lib/jquery-ui-1.8.18.min.js   |    15 -
 portal/archive/js/lib/jquery.dataset.min.js     |     1 -
 portal/archive/js/lib/jquery.dform-0.1.3.min.js |    16 -
 portal/archive/js/lib/jquery.jsonp-2.3.1.min.js |     3 -
 portal/archive/js/lib/jquery.tmpl.min.js        |    10 -
 .../archive/js/lib/jquery.ui.statusbar.min.js   |     1 -
 .../archive/js/lib/jquery.ui.timepicker.min.js  |     1 -
 portal/archive/js/lib/prettify.js               |  1477 -
 portal/archive/js/lib/underscore-min.js         |     5 -
 portal/archive/js/spec/client-tests.js          |   159 -
 portal/archive/js/spec/index.html               |    20 -
 portal/archive/js/spec/qunit-git.css            |   238 -
 portal/archive/js/spec/qunit-git.js             |  1865 --
 portal/archive/js/unit-tests/appSDK-tests.js    |   255 -
 portal/archive/js/unit-tests/ie-jquery-tests.js |   191 -
 portal/archive/js/unit-tests/qunit.css          |   231 -
 portal/archive/js/unit-tests/qunit.js           |  1934 --
 portal/archive/loading.html                     |     9 -
 portal/archive/max/index.html                   |     0
 portal/archive/planned_outage.html              |    48 -
 portal/archive/push/index.html                  |    34 -
 portal/archive/service_down.html                |    48 -
 .../apigee.ui.activities.table_rows.html        |    14 -
 .../templates/apigee.ui.admins.table_rows.html  |     8 -
 .../apigee.ui.applications.table_rows.html      |     4 -
 .../apigee.ui.collection.table_rows.html        |    67 -
 .../apigee.ui.collections.query.indexes.html    |     5 -
 .../apigee.ui.collections.table_rows.html       |     9 -
 .../apigee.ui.collections.user.header.html      |    21 -
 .../templates/apigee.ui.curl.detail.html        |    11 -
 .../templates/apigee.ui.feed.table_rows.html    |    15 -
 .../templates/apigee.ui.groups.table_rows.html  |    14 -
 .../apigee.ui.panels.group.activities.html      |    28 -
 .../apigee.ui.panels.group.details.html         |    97 -
 .../apigee.ui.panels.group.memberships.html     |    40 -
 .../apigee.ui.panels.group.permissions.html     |    99 -
 ...pigee.ui.panels.notifications.configure.html |    14 -
 .../apigee.ui.panels.role.permissions.html      |    58 -
 .../templates/apigee.ui.panels.role.users.html  |    38 -
 .../apigee.ui.panels.user.activities.html       |    40 -
 .../templates/apigee.ui.panels.user.graph.html  |    80 -
 .../apigee.ui.panels.user.memberships.html      |    40 -
 .../apigee.ui.panels.user.permissions.html      |   105 -
 .../apigee.ui.panels.user.profile.html          |   113 -
 .../apigee.ui.role.groups.table_rows.html       |    44 -
 .../templates/apigee.ui.roles.table_rows.html   |    15 -
 .../templates/apigee.ui.users.table_rows.html   |    18 -
 portal/archive/templates/test/modalForm2.html   |    32 -
 portal/archive/test/autocomplete.html           |    25 -
 portal/archive/test/modalForm.html              |    32 -
 portal/bower.json                               |     6 +-
 portal/build.sh                                 |    24 +-
 portal/config.js                                |    49 +-
 portal/css/apigeeGlobalNavigation.css           |   291 -
 portal/css/dash.min.css                         |     1 -
 portal/css/main.css                             |    94 +-
 portal/css/main.min.css                         |     1 +
 portal/favicon.ico                              |   Bin 1150 -> 3989 bytes
 portal/helpJson.json                            |    47 +
 portal/img/green_dot.png                        |   Bin 3472 -> 0 bytes
 portal/img/logo.gif                             |   Bin 2279 -> 0 bytes
 portal/img/logo.png                             |   Bin 0 -> 7758 bytes
 portal/img/push/APNS_cert_upload.png            |   Bin 33956 -> 0 bytes
 portal/img/push/APNS_certification.png          |   Bin 16855 -> 0 bytes
 portal/img/push/android-notification.png        |   Bin 41629 -> 0 bytes
 portal/img/push/google_api_key.png              |   Bin 98118 -> 0 bytes
 portal/img/push/iphone_message.png              |   Bin 90307 -> 0 bytes
 portal/img/push/step_1.png                      |   Bin 1953 -> 0 bytes
 portal/img/push/step_2.png                      |   Bin 2117 -> 0 bytes
 portal/img/push/step_3.png                      |   Bin 2162 -> 0 bytes
 portal/img/red_dot.png                          |   Bin 3482 -> 0 bytes
 portal/img/yellow_dot.png                       |   Bin 3475 -> 0 bytes
 portal/index-template.html                      |    44 +-
 portal/js/activities/activities.html            |    56 +-
 .../js/app-overview/app-overview-controller.js  |    61 +-
 portal/js/app-overview/app-overview.html        |    60 +-
 .../js/app-overview/doc-includes/android.html   |   401 +-
 portal/js/app-overview/doc-includes/ios.html    |   364 +-
 .../app-overview/doc-includes/javascript.html   |   216 +-
 portal/js/app-overview/doc-includes/net.html    |    16 +
 portal/js/app-overview/doc-includes/node.html   |    16 +
 portal/js/app-overview/doc-includes/ruby.html   |    16 +
 .../app-overview/getting-started-controller.js  |   107 -
 portal/js/app-overview/getting-started.html     |   119 -
 portal/js/app.js                                |    21 +-
 portal/js/charts/chart-controller.js            |     6 -
 portal/js/charts/chart-directives.js            |   141 -
 portal/js/charts/chart-service.js               |   494 -
 portal/js/charts/highcharts.json                |   329 -
 portal/js/charts/sparklines.js                  |     2 -
 portal/js/data/data.html                        |   261 +-
 portal/js/data/display-generic.html             |   168 +-
 portal/js/data/display-groups.html              |    16 +
 portal/js/data/display-roles.html               |    18 +-
 portal/js/data/display-users.html               |   257 +-
 portal/js/data/entity.html                      |    31 +-
 portal/js/dialogs/modal.html                    |    49 +-
 portal/js/global/app-switcher-directive.js      |    53 -
 portal/js/global/appswitcher-template.html      |    34 -
 portal/js/global/help-service.js                |    22 +-
 portal/js/global/insecure-banner.html           |    30 +-
 portal/js/global/page-controller.js             |    17 +-
 portal/js/global/page-title.html                |    44 +-
 portal/js/global/ug-service.js                  |    45 +-
 portal/js/groups/groups-activities.html         |    44 +-
 portal/js/groups/groups-details.html            |    83 +-
 portal/js/groups/groups-members.html            |   101 +-
 portal/js/groups/groups-roles.html              |   247 +-
 portal/js/groups/groups-tabs.html               |    45 +-
 portal/js/groups/groups.html                    |   196 +-
 portal/js/libs/Highcharts-2.3.5/index.htm       |    79 -
 .../js/adapters/mootools-adapter.js             |    13 -
 .../js/adapters/mootools-adapter.src.js         |   328 -
 .../js/adapters/prototype-adapter.js            |    16 -
 .../js/adapters/prototype-adapter.src.js        |   385 -
 .../libs/Highcharts-2.3.5/js/highcharts-more.js |    35 -
 .../Highcharts-2.3.5/js/highcharts-more.src.js  |  1581 -
 .../js/libs/Highcharts-2.3.5/js/highcharts.js   |   250 -
 .../libs/Highcharts-2.3.5/js/highcharts.src.js  | 15281 ----------
 .../Highcharts-2.3.5/js/modules/canvas-tools.js |   133 -
 .../js/modules/canvas-tools.src.js              |  3113 --
 .../js/libs/Highcharts-2.3.5/js/modules/data.js |    14 -
 .../Highcharts-2.3.5/js/modules/data.src.js     |   512 -
 .../Highcharts-2.3.5/js/modules/exporting.js    |    23 -
 .../js/modules/exporting.src.js                 |   752 -
 .../Highcharts-2.3.5/js/themes/dark-blue.js     |   263 -
 .../Highcharts-2.3.5/js/themes/dark-green.js    |   263 -
 .../js/libs/Highcharts-2.3.5/js/themes/gray.js  |   262 -
 .../js/libs/Highcharts-2.3.5/js/themes/grid.js  |    95 -
 .../js/libs/Highcharts-2.3.5/js/themes/skies.js |    89 -
 portal/js/libs/angular-1.0.5/angular-cookies.js |   183 -
 .../libs/angular-1.0.5/angular-cookies.min.js   |     7 -
 portal/js/libs/angular-1.0.5/angular-loader.js  |   276 -
 .../js/libs/angular-1.0.5/angular-loader.min.js |     7 -
 portal/js/libs/angular-1.0.5/angular-mocks.js   |  1886 --
 .../js/libs/angular-1.0.5/angular-resource.js   |   445 -
 .../libs/angular-1.0.5/angular-resource.min.js  |    10 -
 .../js/libs/angular-1.0.5/angular-sanitize.js   |   535 -
 .../libs/angular-1.0.5/angular-sanitize.min.js  |    13 -
 portal/js/libs/angular-1.0.5/angular.js         | 14733 ---------
 portal/js/libs/angular-1.0.5/angular.min.js     |   161 -
 portal/js/libs/angular-1.0.5/version.txt        |     1 -
 portal/js/libs/angular-1.1.5/angular-1.1.5.js   | 16876 -----------
 .../js/libs/angular-1.1.5/angular-merge.min.js  |     8 -
 .../angular-1.1.5/angular-resource-1.1.5.js     |   537 -
 .../angularitics-0.8.5-google-analytics.js      |     7 -
 .../js/libs/angularitics/angularitics-0.8.5.js  |     6 -
 portal/js/login/forgot-password.html            |    27 +-
 portal/js/login/loading.html                    |    20 +-
 portal/js/login/login.html                      |   114 +-
 portal/js/login/logout.html                     |    18 +-
 portal/js/login/register.html                   |    80 +-
 portal/js/menu.html                             |    32 +-
 portal/js/menus/appMenu.html                    |    88 +-
 portal/js/menus/orgMenu.html                    |    39 +-
 portal/js/org-overview/org-overview.html        |   269 +-
 portal/js/profile/account.html                  |    31 +-
 portal/js/profile/organizations.html            |   136 +-
 portal/js/profile/profile.html                  |   105 +-
 portal/js/roles/roles-groups.html               |    99 +-
 portal/js/roles/roles-settings.html             |   173 +-
 portal/js/roles/roles-tabs.html                 |    48 +-
 portal/js/roles/roles-users.html                |   100 +-
 portal/js/roles/roles.html                      |   184 +-
 portal/js/shell/shell.html                      |    37 +-
 portal/js/users/users-activities.html           |    75 +-
 portal/js/users/users-feed.html                 |    63 +-
 portal/js/users/users-graph.html                |   125 +-
 portal/js/users/users-groups.html               |   116 +-
 portal/js/users/users-profile.html              |   154 +-
 portal/js/users/users-roles.html                |   258 +-
 portal/js/users/users-tabs.html                 |    17 +-
 portal/js/users/users.html                      |   272 +-
 portal/package.json                             |     7 +-
 portal/scripts/e2e-test.bat                     |    15 +
 portal/scripts/e2e-test.sh                      |    15 +
 portal/scripts/test.bat                         |    15 +
 portal/scripts/test.sh                          |    15 +
 portal/scripts/watchr.rb                        |    15 +
 portal/scripts/web-server.js                    |    19 +
 portal/sdk/usergrid.0.10.4.js                   |  1402 -
 portal/sdk/usergrid.0.10.5.js                   |  1755 --
 portal/sdk/usergrid.0.10.7.js                   |  2265 --
 portal/server.js                                |    19 +
 portal/tests/karma.conf.js                      |    23 +-
 portal/tests/protractor-ignore/profile.spec.js  |    97 +
 portal/tests/protractor/applications.spec.js    |    20 +
 portal/tests/protractor/data.spec.js            |    20 +
 portal/tests/protractor/forgotPassword.spec.js  |    20 +
 portal/tests/protractor/login.spec.js           |    20 +
 portal/tests/protractor/organization.spec.js    |    20 +
 portal/tests/protractor/profile.spec.js         |    77 -
 portal/tests/protractor/roles.spec.js           |    20 +
 portal/tests/protractor/shell.spec.js           |    20 +
 portal/tests/protractor/users.spec.js           |    20 +
 portal/tests/protractor/util.js                 |    24 +-
 portal/tests/protractorConf.js                  |    24 +-
 portal/tests/selenium/chromedriver              |   Bin 22034760 -> 0 bytes
 .../selenium-server-standalone-2.37.0.jar       |   Bin 34730734 -> 0 bytes
 portal/tests/unit/sample.spec.js                |    19 +
 release/pom.xml                                 |    65 +
 release/sign-release.sh                         |    30 +
 release/src/main/assembly/source.xml            |    57 +
 sdks/android/.gitignore                         |    20 -
 sdks/android/README.txt                         |     2 +
 sdks/android/dist/jackson-core-asl-1.9.1.jar    |   Bin 228286 -> 0 bytes
 sdks/android/dist/jackson-mapper-asl-1.9.1.jar  |   Bin 764465 -> 0 bytes
 .../dist/spring-android-core-1.0.0.M4.jar       |   Bin 83065 -> 0 bytes
 .../spring-android-rest-template-1.0.0.M4.jar   |   Bin 137368 -> 0 bytes
 sdks/android/doc/allclasses-frame.html          |    27 -
 sdks/android/doc/allclasses-noframe.html        |    27 -
 sdks/android/doc/constant-values.html           |   153 -
 sdks/android/doc/deprecated-list.html           |   117 -
 sdks/android/doc/help-doc.html                  |   222 -
 sdks/android/doc/index-all.html                 |   371 -
 sdks/android/doc/index.html                     |    68 -
 .../apache/usergrid/android/client/Client.html  |   989 -
 .../client/callbacks/ApiResponseCallback.html   |   224 -
 .../client/callbacks/ClientAsyncTask.html       |   338 -
 .../client/callbacks/ClientCallback.html        |   227 -
 .../callbacks/DeviceRegistrationCallback.html   |   220 -
 .../callbacks/GroupsRetrievedCallback.html      |   220 -
 .../client/callbacks/QueryResultsCallback.html  |   220 -
 .../class-use/ApiResponseCallback.html          |   282 -
 .../callbacks/class-use/ClientAsyncTask.html    |   117 -
 .../callbacks/class-use/ClientCallback.html     |   180 -
 .../class-use/DeviceRegistrationCallback.html   |   171 -
 .../class-use/GroupsRetrievedCallback.html      |   160 -
 .../class-use/QueryResultsCallback.html         |   219 -
 .../android/client/callbacks/package-frame.html |    28 -
 .../client/callbacks/package-summary.html       |   166 -
 .../android/client/callbacks/package-tree.html  |   145 -
 .../android/client/callbacks/package-use.html   |   178 -
 .../android/client/class-use/Client.html        |   117 -
 .../usergrid/android/client/package-frame.html  |    20 -
 .../android/client/package-summary.html         |   137 -
 .../usergrid/android/client/package-tree.html   |   134 -
 .../usergrid/android/client/package-use.html    |   117 -
 .../android/client/utils/DeviceUuidFactory.html |   352 -
 .../android/client/utils/ObjectUtils.html       |   258 -
 .../utils/class-use/DeviceUuidFactory.html      |   117 -
 .../client/utils/class-use/ObjectUtils.html     |   117 -
 .../android/client/utils/package-frame.html     |    21 -
 .../android/client/utils/package-summary.html   |   142 -
 .../android/client/utils/package-tree.html      |   131 -
 .../android/client/utils/package-use.html       |   117 -
 sdks/android/doc/overview-frame.html            |    23 -
 sdks/android/doc/overview-summary.html          |   139 -
 sdks/android/doc/overview-tree.html             |   154 -
 sdks/android/doc/package-list                   |     3 -
 sdks/android/doc/resources/background.gif       |   Bin 2313 -> 0 bytes
 sdks/android/doc/resources/tab.gif              |   Bin 291 -> 0 bytes
 sdks/android/doc/resources/titlebar.gif         |   Bin 10701 -> 0 bytes
 sdks/android/doc/resources/titlebar_end.gif     |   Bin 849 -> 0 bytes
 sdks/android/doc/stylesheet.css                 |   474 -
 .../0.0.6/usergrid-java-client-0.0.6.jar        |   Bin 46389 -> 0 bytes
 .../0.0.6/usergrid-java-client-0.0.6.jar.sha1   |     1 -
 .../0.0.6/usergrid-java-client-0.0.6.pom        |    95 -
 .../0.0.6/usergrid-java-client-0.0.6.pom.sha1   |     1 -
 .../maven-metadata-local.xml                    |    12 -
 sdks/android/pom.xml                            |    43 +-
 .../apache/usergrid/android/client/Client.java  |   185 +-
 .../client/callbacks/ApiResponseCallback.java   |    16 +
 .../client/callbacks/ClientAsyncTask.java       |    16 +
 .../client/callbacks/ClientCallback.java        |    16 +
 .../callbacks/DeviceRegistrationCallback.java   |    16 +
 .../callbacks/GroupsRetrievedCallback.java      |    16 +
 .../client/callbacks/QueryResultsCallback.java  |    16 +
 .../android/client/utils/DeviceUuidFactory.java |    16 +
 .../android/client/utils/ObjectUtils.java       |    16 +
 .../NSubstitute.1.6.0.0/BreakingChanges.txt     |   131 -
 .../packages/NSubstitute.1.6.0.0/CHANGELOG.txt  |   103 -
 .../packages/NSubstitute.1.6.0.0/README.txt     |   119 -
 sdks/dotnet/packages/NUnit.2.6.2/README.txt     |     3 +
 .../packages/Newtonsoft.Json.4.5.11/README.txt  |     3 +
 sdks/dotnet/packages/RestSharp.104.1/readme.txt |    19 -
 .../LocationDotNetSample/Form1.cs               |    18 +-
 .../packages/Geocoder.0.1.0.0/README.txt        |     3 +
 sdks/html5-javascript/README.md                 |    76 +-
 .../examples/all-calls/all-calls.html           |    18 +-
 sdks/html5-javascript/examples/all-calls/app.js |    19 +-
 sdks/html5-javascript/examples/dogs/app.js      |    17 +
 sdks/html5-javascript/examples/dogs/dogs.html   |    19 +-
 sdks/html5-javascript/examples/facebook/app.js  |    17 +
 .../examples/facebook/facebook.html             |    19 +-
 .../examples/facebook/guide.html                |    17 +
 .../examples/persistence/test.html              |    19 +-
 .../examples/persistence/test.js                |    17 +
 sdks/html5-javascript/examples/test/test.html   |    19 +-
 .../extensions/usergrid.validation.js           |    30 +-
 sdks/html5-javascript/index.html                |    17 +
 sdks/html5-javascript/lib/Module.js             |    19 +-
 sdks/html5-javascript/lib/Usergrid.js           |    36 +-
 sdks/html5-javascript/lib/modules/Asset.js      |   168 +-
 sdks/html5-javascript/lib/modules/Client.js     |     8 +-
 sdks/html5-javascript/lib/modules/Entity.js     |   179 +-
 sdks/html5-javascript/lib/modules/Group.js      |     2 +-
 sdks/html5-javascript/tests/mocha/index.html    |    25 +-
 sdks/html5-javascript/tests/mocha/test.js       |    17 +
 .../tests/qunit/apigee_test.html                |    17 +
 sdks/html5-javascript/tests/qunit/tests.js      |    17 +
 sdks/html5-javascript/tests/test.html           |    17 +
 sdks/html5-javascript/tests/test.js             |    17 +
 sdks/html5-javascript/usergrid.js               |   268 +-
 sdks/html5-javascript/usergrid.min.js           |    35 +-
 sdks/ios/Nukefile                               |    17 +
 sdks/ios/UGAPI/v2/UGConnection.h                |    16 +
 sdks/ios/UGAPI/v2/UGConnection.m                |    18 +-
 sdks/ios/UGAPI/v2/UGHTTPClient.h                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPClient.m                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPHelpers.h               |    19 +-
 sdks/ios/UGAPI/v2/UGHTTPHelpers.m               |    17 +-
 sdks/ios/UGAPI/v2/UGHTTPResult.h                |    16 +
 sdks/ios/UGAPI/v2/UGHTTPResult.m                |    16 +
 .../samples/Books/books/AddBookViewController.h |    31 +
 .../samples/Books/books/AddBookViewController.m |    17 +
 sdks/ios/samples/Books/books/AppDelegate.h      |    31 +
 sdks/ios/samples/Books/books/AppDelegate.m      |    17 +
 .../samples/Books/books/BooksViewController.h   |    31 +
 .../samples/Books/books/BooksViewController.m   |    17 +
 .../Books/books/UGSignInViewController.h        |    14 +
 .../Books/books/UGSignInViewController.m        |    17 +
 sdks/ios/samples/Books/books/books-Info.plist   |    18 +
 sdks/ios/samples/Books/books/books-Prefix.pch   |    17 +
 .../Books/books/en.lproj/InfoPlist.strings      |    19 +
 sdks/ios/samples/Books/books/main.m             |    17 +
 .../ios/samples/Browser/browser/UGAppDelegate.h |    14 +
 .../ios/samples/Browser/browser/UGAppDelegate.m |    17 +
 .../Browser/browser/UGAppViewController.h       |    14 +
 .../Browser/browser/UGAppViewController.m       |    17 +
 .../browser/UGCollectionViewController.h        |    14 +
 .../browser/UGCollectionViewController.m        |    17 +
 .../Browser/browser/UGEntityViewController.h    |    14 +
 .../Browser/browser/UGEntityViewController.m    |    17 +
 .../Browser/browser/UGSignInViewController.h    |    14 +
 .../Browser/browser/UGSignInViewController.m    |    17 +
 .../Browser/browser/UGTextViewController.h      |    14 +
 .../Browser/browser/UGTextViewController.m      |    17 +
 .../samples/Browser/browser/browser-Info.plist  |    18 +
 sdks/ios/samples/Browser/browser/main.m         |    17 +
 sdks/ios/samples/parties/parties/AppDelegate.h  |    14 +-
 sdks/ios/samples/parties/parties/AppDelegate.m  |    17 +
 .../parties/parties/PartiesViewController.h     |    14 +-
 .../parties/parties/PartiesViewController.m     |    17 +
 .../parties/parties/PartyViewController.h       |    14 +-
 .../parties/parties/PartyViewController.m       |    17 +
 sdks/ios/samples/parties/parties/main.m         |    17 +
 .../samples/parties/parties/parties-Info.plist  |    18 +
 sdks/ios/test/test_client.nu                    |    17 +
 sdks/ios/test/test_connection.nu                |    17 +
 sdks/java/.gitignore                            |    20 -
 sdks/java/dist/jackson-core-asl-1.9.1.jar       |   Bin 228286 -> 0 bytes
 sdks/java/dist/jackson-mapper-asl-1.9.1.jar     |   Bin 764465 -> 0 bytes
 sdks/java/dist/spring-android-core-1.0.0.M4.jar |   Bin 83065 -> 0 bytes
 .../spring-android-rest-template-1.0.0.M4.jar   |   Bin 137368 -> 0 bytes
 .../usergrid-android-client-0.0.1-SNAPSHOT.jar  |   Bin 66123 -> 0 bytes
 sdks/java/doc/allclasses-frame.html             |    40 -
 sdks/java/doc/allclasses-noframe.html           |    40 -
 sdks/java/doc/constant-values.html              |   731 -
 sdks/java/doc/deprecated-list.html              |   117 -
 sdks/java/doc/help-doc.html                     |   222 -
 sdks/java/doc/index-all.html                    |  1299 -
 sdks/java/doc/index.html                        |    68 -
 .../usergrid/java/client/Client.Query.html      |   238 -
 .../java/client/Client.QueuePosition.html       |   381 -
 .../org/apache/usergrid/java/client/Client.html |  1652 --
 .../java/client/class-use/Client.Query.html     |   246 -
 .../client/class-use/Client.QueuePosition.html  |   192 -
 .../usergrid/java/client/class-use/Client.html  |   175 -
 .../entities/Activity.ActivityCollection.html   |   408 -
 .../entities/Activity.ActivityObject.html       |   720 -
 .../client/entities/Activity.MediaLink.html     |   434 -
 .../usergrid/java/client/entities/Activity.html |  1449 -
 .../usergrid/java/client/entities/Device.html   |   387 -
 .../usergrid/java/client/entities/Entity.html   |   599 -
 .../usergrid/java/client/entities/Group.html    |   427 -
 .../usergrid/java/client/entities/Message.html  |   641 -
 .../usergrid/java/client/entities/User.html     |   707 -
 .../class-use/Activity.ActivityCollection.html  |   117 -
 .../class-use/Activity.ActivityObject.html      |   231 -
 .../entities/class-use/Activity.MediaLink.html  |   191 -
 .../client/entities/class-use/Activity.html     |   203 -
 .../java/client/entities/class-use/Device.html  |   169 -
 .../java/client/entities/class-use/Entity.html  |   415 -
 .../java/client/entities/class-use/Group.html   |   159 -
 .../java/client/entities/class-use/Message.html |   183 -
 .../java/client/entities/class-use/User.html    |   248 -
 .../java/client/entities/package-frame.html     |    28 -
 .../java/client/entities/package-summary.html   |   169 -
 .../java/client/entities/package-tree.html      |   141 -
 .../java/client/entities/package-use.html       |   219 -
 .../java/client/exception/ClientException.html  |   263 -
 .../exception/class-use/ClientException.html    |   117 -
 .../java/client/exception/package-frame.html    |    20 -
 .../java/client/exception/package-summary.html  |   137 -
 .../java/client/exception/package-tree.html     |   142 -
 .../java/client/exception/package-use.html      |   117 -
 .../usergrid/java/client/package-frame.html     |    28 -
 .../usergrid/java/client/package-summary.html   |   167 -
 .../usergrid/java/client/package-tree.html      |   146 -
 .../usergrid/java/client/package-use.html       |   158 -
 .../java/client/response/AggregateCounter.html  |   316 -
 .../client/response/AggregateCounterSet.html    |   444 -
 .../java/client/response/ApiResponse.html       |  1148 -
 .../client/response/ClientCredentialsInfo.html  |   316 -
 .../java/client/response/QueueInfo.html         |   297 -
 .../response/class-use/AggregateCounter.html    |   191 -
 .../response/class-use/AggregateCounterSet.html |   170 -
 .../client/response/class-use/ApiResponse.html  |   365 -
 .../class-use/ClientCredentialsInfo.html        |   170 -
 .../client/response/class-use/QueueInfo.html    |   187 -
 .../java/client/response/package-frame.html     |    24 -
 .../java/client/response/package-summary.html   |   151 -
 .../java/client/response/package-tree.html      |   134 -
 .../java/client/response/package-use.html       |   178 -
 .../usergrid/java/client/utils/JsonUtils.html   |   480 -
 .../usergrid/java/client/utils/MapUtils.html    |   260 -
 .../usergrid/java/client/utils/ObjectUtils.html |   258 -
 .../usergrid/java/client/utils/UrlUtils.html    |   314 -
 .../java/client/utils/class-use/JsonUtils.html  |   117 -
 .../java/client/utils/class-use/MapUtils.html   |   117 -
 .../client/utils/class-use/ObjectUtils.html     |   117 -
 .../java/client/utils/class-use/UrlUtils.html   |   117 -
 .../java/client/utils/package-frame.html        |    23 -
 .../java/client/utils/package-summary.html      |   147 -
 .../java/client/utils/package-tree.html         |   133 -
 .../usergrid/java/client/utils/package-use.html |   117 -
 sdks/java/doc/overview-frame.html               |    25 -
 sdks/java/doc/overview-summary.html             |   147 -
 sdks/java/doc/overview-tree.html                |   184 -
 sdks/java/doc/package-list                      |     5 -
 sdks/java/doc/resources/background.gif          |   Bin 2313 -> 0 bytes
 sdks/java/doc/resources/tab.gif                 |   Bin 291 -> 0 bytes
 sdks/java/doc/resources/titlebar.gif            |   Bin 10701 -> 0 bytes
 sdks/java/doc/resources/titlebar_end.gif        |   Bin 849 -> 0 bytes
 sdks/java/doc/serialized-form.html              |   134 -
 sdks/java/doc/stylesheet.css                    |   474 -
 sdks/java/pom.xml                               |    21 +-
 sdks/nodejs/.gitignore                          |     2 -
 sdks/nodejs/.npmignore                          |     1 -
 sdks/nodejs/lib/usergrid.js                     |   195 +-
 sdks/nodejs/test.js                             |    17 +
 sdks/nodejs/test/client.js                      |    18 +
 sdks/nodejs/test/collection.js                  |    17 +
 sdks/nodejs/test/entity.js                      |    17 +
 sdks/perl/Build.PL                              |    46 +
 sdks/perl/LICENSE                               |   202 +
 sdks/perl/MANIFEST                              |    23 +
 sdks/perl/Makefile.PL                           |    41 +
 sdks/perl/README.md                             |   341 +
 sdks/perl/examples/books.pl                     |    48 +
 sdks/perl/lib/Usergrid/Client.pm                |   492 +
 sdks/perl/lib/Usergrid/Collection.pm            |   212 +
 sdks/perl/lib/Usergrid/Entity.pm                |    92 +
 sdks/perl/lib/Usergrid/Request.pm               |   249 +
 sdks/perl/t/01_init.t                           |    27 +
 sdks/perl/t/02_login.t                          |    64 +
 sdks/perl/t/03_update.t                         |   102 +
 sdks/perl/t/04_collection.t                     |   104 +
 sdks/perl/t/05_query.t                          |   108 +
 sdks/perl/t/06_batch_update.t                   |   107 +
 sdks/perl/t/07_batch_delete.t                   |    87 +
 sdks/perl/t/08_connections.t                    |    94 +
 sdks/perl/t/09_paging.t                         |   140 +
 sdks/perl/t/10_auto_paging.t                    |    94 +
 sdks/php/kessel/config.ini                      |    18 -
 sdks/php/kessel/kessel.rb                       |   188 -
 sdks/ruby-on-rails/.gitignore                   |    18 -
 sdks/ruby-on-rails/.rspec                       |     1 -
 sdks/ruby-on-rails/.rvmrc                       |     2 -
 sdks/usergrid-java-sdk-0.0.6/README.txt         |     5 +
 sdks/usergrid-java-sdk-0.0.6/pom.xml            |   114 +
 .../java/org/usergrid/java/client/Client.java   |  1292 +
 .../usergrid/java/client/entities/Activity.java |   626 +
 .../usergrid/java/client/entities/Device.java   |    68 +
 .../usergrid/java/client/entities/Entity.java   |   191 +
 .../usergrid/java/client/entities/Group.java    |    79 +
 .../usergrid/java/client/entities/Message.java  |   148 +
 .../org/usergrid/java/client/entities/User.java |   158 +
 .../java/client/exception/ClientException.java  |    42 +
 .../java/client/response/AggregateCounter.java  |    52 +
 .../client/response/AggregateCounterSet.java    |   111 +
 .../java/client/response/ApiResponse.java       |   421 +
 .../client/response/ClientCredentialsInfo.java  |    58 +
 .../java/client/response/QueueInfo.java         |    44 +
 .../usergrid/java/client/utils/JsonUtils.java   |   182 +
 .../usergrid/java/client/utils/MapUtils.java    |    39 +
 .../usergrid/java/client/utils/ObjectUtils.java |    36 +
 .../usergrid/java/client/utils/UrlUtils.java    |   124 +
 stack/README.md                                 |    14 +-
 stack/awscluster/aws-sample.properties          |    17 +
 stack/awscluster/src/main/cql/create_locks.cql  |    17 +
 .../awscluster/src/main/cql/create_usergrid.cql |    17 +
 .../main/cql/create_usergrid_applications.cql   |    17 +
 .../main/dist/init_instance/init_rest_server.sh |    17 +-
 stack/awscluster/ugcluster-cf.json              |    10 +-
 stack/cloudbees.xml                             |    18 +
 .../main/resources/usergrid-default.properties  |    29 +-
 stack/config/src/test/resources/cassandra.yaml  |    25 +-
 .../src/test/resources/usergrid-test.properties |    14 +
 stack/core/pom.xml                              |    56 +-
 .../java/org/apache/usergrid/batch/Job.java     |    12 +-
 .../org/apache/usergrid/batch/JobFactory.java   |     2 +-
 .../usergrid/batch/UsergridJobFactory.java      |     6 +-
 .../batch/service/JobSchedulerService.java      |   302 +-
 .../corepersistence/CpEntityManager.java        |   117 +-
 .../corepersistence/CpEntityMapUtils.java       |     2 +-
 .../corepersistence/CpRelationManager.java      |   169 +-
 .../apache/usergrid/metrics/MetricsFactory.java |     8 -
 .../java/org/apache/usergrid/mq/Message.java    |    10 +-
 .../usergrid/mq/cassandra/QueueManagerImpl.java |    38 +-
 .../mq/cassandra/io/AbstractSearch.java         |     5 +-
 .../mq/cassandra/io/ConsumerTransaction.java    |    12 +-
 .../usergrid/persistence/CredentialsInfo.java   |    13 +-
 .../apache/usergrid/persistence/EntityRef.java  |     1 -
 .../persistence/ObservableIterator.java         |    82 +
 .../apache/usergrid/persistence/PathQuery.java  |     8 +-
 .../usergrid/persistence/SimpleEntityRef.java   |    36 +-
 .../cassandra/CassandraPersistenceUtils.java    |     9 +-
 .../persistence/cassandra/CassandraService.java |   137 +-
 .../cassandra/EntityManagerFactoryImpl.java     |     5 +-
 .../cassandra/EntityManagerImpl.java            |    58 +-
 .../persistence/cassandra/GeoIndexManager.java  |    21 +-
 .../persistence/cassandra/QueryProcessor.java   |     3 +-
 .../cassandra/RelationManagerImpl.java          |    55 +-
 .../persistence/cassandra/Serializers.java      |    14 +-
 .../persistence/hector/CountingMutator.java     |   344 +
 .../usergrid/persistence/query/ir/AllNode.java  |    12 +
 .../persistence/query/ir/BooleanNode.java       |    16 +
 .../query/ir/EmailIdentifierNode.java           |    12 +
 .../query/ir/NameIdentifierNode.java            |    12 +
 .../usergrid/persistence/query/ir/NotNode.java  |    12 +
 .../persistence/query/ir/OrderByNode.java       |    16 +-
 .../persistence/query/ir/QueryNode.java         |    12 +
 .../persistence/query/ir/SliceNode.java         |    12 +
 .../query/ir/UuidIdentifierNode.java            |    12 +
 .../persistence/query/ir/WithinNode.java        |    12 +
 .../query/ir/result/SubtractionIterator.java    |     8 +-
 .../org/apache/usergrid/utils/JsonUtils.java    |     8 +-
 .../org/apache/usergrid/utils/UUIDUtils.java    |    11 +
 .../main/resources/usergrid-core-context.xml    |     2 +-
 .../apache/usergrid/batch/BulkTestUtils.java    |    10 +-
 .../usergrid/batch/UsergridJobFactoryTest.java  |     3 +-
 .../usergrid/batch/job/CountdownLatchJob.java   |     6 +
 .../usergrid/batch/job/DelayExecution.java      |     6 +
 .../usergrid/batch/job/DelayHeartbeat.java      |     6 +
 .../batch/job/FailureJobExceuction.java         |    74 -
 .../usergrid/batch/job/FailureJobExecution.java |    87 +
 .../usergrid/batch/job/OnlyOnceExceution.java   |     6 +
 .../job/OnlyOnceUnlockOnFailExceution.java      |     6 +
 .../usergrid/batch/job/SchedulerRuntime1IT.java |     5 +-
 .../usergrid/batch/job/SchedulerRuntime2IT.java |    61 +-
 .../usergrid/batch/job/SchedulerRuntime3IT.java |    39 +-
 .../usergrid/batch/job/SchedulerRuntime4IT.java |    11 +-
 .../usergrid/batch/job/SchedulerRuntime5IT.java |     4 +-
 .../usergrid/batch/job/SchedulerRuntime6IT.java |    14 +-
 .../usergrid/batch/job/SchedulerRuntime7IT.java |    14 +-
 .../usergrid/batch/job/SchedulerRuntime8IT.java |     4 +-
 .../batch/job/SchedulerRuntimeIntervalIT.java   |   115 +
 .../usergrid/batch/job/TestJobListener.java     |    67 +-
 .../usergrid/batch/job/TestJobListenerTest.java |     7 +-
 .../corepersistence/CpEntityMapUtilsTest.java   |   119 +
 .../usergrid/persistence/CollectionIT.java      |    66 +
 .../usergrid/persistence/CountingMutatorIT.java |   119 +
 .../org/apache/usergrid/persistence/GeoIT.java  |    95 +-
 .../persistence/GeoQueryBooleanTest.java        |   190 +
 .../apache/usergrid/persistence/IndexIT.java    |    21 +-
 .../usergrid/persistence/PathQueryIT.java       |     4 +-
 .../cassandra/QueryProcessorTest.java           |    93 +-
 .../query/IntersectionTransitivePagingIT.java   |   163 +
 .../query/IntersectionUnionPagingIT.java        |     4 +-
 .../persistence/query/NotSubPropertyIT.java     |   177 +
 stack/core/src/test/resources/cassandra.yaml    |    17 +
 .../core/src/test/resources/project.properties  |    24 +-
 .../resources/usergrid-properties-context.xml   |    17 +
 .../usergrid-scheduler-test.properties          |    20 +-
 .../test/resources/usergrid-test-context.xml    |    16 +
 .../exception/CollectionRuntimeException.java   |     1 -
 .../exception/WriteUniqueVerifyException.java   |    18 -
 .../mvcc/entity/impl/MvccLogEntryImpl.java      |     3 +-
 .../UniqueValueSerializationStrategyImpl.java   |     2 +-
 .../mvcc/stage/write/WriteUniqueVerify.java     |     7 +-
 .../MvccEntitySerializationStrategyImpl.java    |    25 +-
 .../collection/guice/TestModule.java            |     2 +
 .../mvcc/stage/delete/MarkStartTest.java        |     3 +
 .../collection/mvcc/stage/load/LoadTest.java    |     7 +
 ...MvccEntitySerializationStrategyImplTest.java |    13 +-
 .../collection/util/InvalidIdGenerator.java     |    14 -
 .../src/test/resources/usergrid-UNIT.properties |     1 +
 .../core/astyanax/ColumnNameIterator.java       |    27 +-
 .../persistence/core/astyanax/ColumnSearch.java |    46 +
 .../persistence/core/astyanax/ColumnTypes.java  |     3 +
 .../astyanax/MultiKeyColumnNameIterator.java    |   235 +
 .../core/astyanax/MultiRowColumnIterator.java   |   253 +
 .../core/astyanax/MultiTennantColumnFamily.java |    13 +-
 .../core/hystrix/HystrixCassandra.java          |    73 +-
 .../persistence/core/rx/ObservableIterator.java |     2 +-
 .../persistence/core/rx/OrderedMerge.java       |   194 +-
 .../core/scope/ApplicationScopeImpl.java        |     3 +-
 .../persistence/core/util/ValidationUtils.java  |     2 +-
 .../core/astyanax/ColumnNameIteratorTest.java   |   205 +
 .../MultiKeyColumnNameIteratorTest.java         |   330 +
 .../astyanax/MultiRowColumnIteratorTest.java    |   502 +
 .../persistence/core/astyanax/TestUtils.java    |    76 +
 .../core/cassandra/CassandraRule.java           |    24 +-
 .../persistence/core/rx/OrderedMergeTest.java   |   146 +-
 .../common/src/test/resources/log4j.properties  |    39 +
 .../src/test/resources/usergrid-UNIT.properties |    14 +
 .../src/test/resources/usergrid.properties      |     1 +
 stack/corepersistence/graph/pom.xml             |     7 +
 .../apache/usergrid/persistence/graph/Edge.java |     1 -
 .../usergrid/persistence/graph/GraphFig.java    |    90 +-
 .../persistence/graph/SearchByEdge.java         |     8 +-
 .../persistence/graph/SearchByEdgeType.java     |    18 +-
 .../persistence/graph/guice/GraphModule.java    |    51 +-
 .../persistence/graph/guice/MergedProxy.java    |    34 -
 .../graph/guice/StorageEdgeSerialization.java   |    34 -
 .../graph/impl/CollectionIndexObserver.java     |     2 +-
 .../graph/impl/GraphManagerImpl.java            |    54 +-
 .../persistence/graph/impl/SimpleEdge.java      |     7 +-
 .../graph/impl/SimpleMarkedEdge.java            |     4 +-
 .../graph/impl/SimpleSearchByEdge.java          |    20 +-
 .../graph/impl/SimpleSearchByEdgeType.java      |    22 +-
 .../graph/impl/SimpleSearchByIdType.java        |     6 +-
 .../impl/stage/EdgeDeleteListenerImpl.java      |     3 -
 .../graph/impl/stage/EdgeDeleteRepairImpl.java  |    16 +-
 .../graph/impl/stage/EdgeMetaRepair.java        |     2 -
 .../graph/impl/stage/EdgeMetaRepairImpl.java    |    67 +-
 .../impl/stage/NodeDeleteListenerImpl.java      |    26 +-
 .../EdgeMetadataSerialization.java              |     3 +-
 .../graph/serialization/EdgeSerialization.java  |     3 +-
 .../graph/serialization/NodeSerialization.java  |     3 +-
 .../impl/EdgeMetadataSerializationImpl.java     |     8 +-
 .../impl/EdgeSerializationImpl.java             |  1037 +-
 .../impl/NodeSerializationImpl.java             |    86 +-
 .../serialization/impl/shard/DirectedEdge.java  |    41 +
 .../impl/shard/DirectedEdgeMeta.java            |   575 +
 .../impl/shard/EdgeColumnFamilies.java          |    60 +
 .../serialization/impl/shard/EdgeRowKey.java    |    44 +
 .../impl/shard/EdgeShardSerialization.java      |    24 +-
 .../impl/shard/EdgeShardStrategy.java           |    45 +-
 .../impl/shard/NodeShardAllocation.java         |    21 +-
 .../impl/shard/NodeShardApproximation.java      |    31 +-
 .../impl/shard/NodeShardCache.java              |    21 +-
 .../serialization/impl/shard/NodeType.java      |    66 +
 .../graph/serialization/impl/shard/RowKey.java  |    55 +
 .../serialization/impl/shard/RowKeyType.java    |    66 +
 .../graph/serialization/impl/shard/Shard.java   |   143 +
 .../impl/shard/ShardEntryGroup.java             |   324 +
 .../impl/shard/ShardGroupCompaction.java        |    71 +
 .../impl/shard/ShardedEdgeSerialization.java    |   186 +
 .../serialization/impl/shard/count/Counter.java |     8 +-
 .../shard/count/NodeShardApproximationImpl.java |   177 +-
 .../count/NodeShardCounterSerialization.java    |     2 +-
 .../NodeShardCounterSerializationImpl.java      |    98 +-
 .../impl/shard/count/ShardKey.java              |    53 +-
 .../impl/shard/impl/EdgeRowKey.java             |    46 -
 .../impl/shard/impl/EdgeRowKeySerializer.java   |    58 -
 .../impl/shard/impl/EdgeSearcher.java           |   162 +
 .../shard/impl/EdgeShardSerializationImpl.java  |    90 +-
 .../shard/impl/NodeShardAllocationImpl.java     |   288 +-
 .../impl/shard/impl/NodeShardCacheImpl.java     |   254 +-
 .../shard/impl/ShardEntryGroupIterator.java     |   123 +
 .../shard/impl/ShardGroupColumnIterator.java    |   130 +
 .../shard/impl/ShardGroupCompactionImpl.java    |   618 +
 .../impl/ShardedEdgeSerializationImpl.java      |  1006 +
 .../impl/shard/impl/ShardsColumnIterator.java   |   127 +
 .../shard/impl/SizebasedEdgeColumnFamilies.java |   154 +
 .../shard/impl/SizebasedEdgeShardStrategy.java  |    51 +-
 .../impl/shard/impl/SourceEdgeSearcher.java     |    22 +
 .../DescendingTimestampComparator.java          |    43 +
 .../DirectedEdgeDescendingComparator.java       |    69 +
 .../impl/comparators/OrderedComparator.java     |    52 +
 .../SourceDirectedEdgeDescendingComparator.java |    42 +
 .../TargetDirectedEdgeDescendingComparator.java |    42 +
 .../impl/serialize/EdgeRowKeySerializer.java    |    63 +
 .../shard/impl/serialize/EdgeSerializer.java    |    77 +
 .../serialize/EdgeShardRowKeySerializer.java    |   103 +
 .../shard/impl/serialize/RowSerializer.java     |    63 +
 .../shard/impl/serialize/RowTypeSerializer.java |    62 +
 .../graph/serialization/util/EdgeHasher.java    |    86 -
 .../graph/serialization/util/EdgeUtils.java     |   132 -
 .../serialization/util/GraphValidation.java     |   189 +
 .../graph/ComittedGraphManagerIT.java           |   138 -
 .../graph/CommittedGraphManagerIT.java          |   135 +
 .../persistence/graph/GraphManagerIT.java       |     3 -
 .../persistence/graph/GraphManagerLoadTest.java |     7 +-
 .../graph/GraphManagerShardConsistencyIT.java   |   563 +
 .../graph/GraphManagerShardingIT.java           |    48 +-
 .../graph/GraphManagerStressTest.java           |     9 +-
 .../usergrid/persistence/graph/SimpleTest.java  |    18 +-
 .../graph/StorageGraphManagerIT.java            |     2 +-
 .../graph/impl/EdgeDeleteListenerTest.java      |     4 +-
 .../graph/impl/NodeDeleteListenerTest.java      |     2 -
 .../graph/impl/stage/EdgeDeleteRepairTest.java  |     7 +-
 .../graph/impl/stage/EdgeMetaRepairTest.java    |     2 -
 .../EdgeMetadataSerializationTest.java          |     2 +-
 .../EdgeSerializationChopTest.java              |     7 +-
 .../serialization/NodeSerializationTest.java    |     3 +-
 .../PermanentSerializationTest.java             |     3 -
 .../graph/serialization/TestCount.java          |     1 -
 .../impl/shard/EdgeShardSerializationTest.java  |   108 +-
 .../impl/shard/NodeShardAllocationTest.java     |   620 +-
 .../impl/shard/NodeShardCacheTest.java          |   235 +-
 .../impl/shard/ShardEntryGroupTest.java         |   409 +
 .../impl/shard/ShardGroupCompactionTest.java    |   226 +
 .../shard/count/NodeShardApproximationTest.java |   130 +-
 .../NodeShardCounterSerializationTest.java      |     8 +-
 .../shard/impl/ShardEntryGroupIteratorTest.java |   276 +
 ...rceDirectedEdgeDescendingComparatorTest.java |   136 +
 ...getDirectedEdgeDescendingComparatorTest.java |   136 +
 .../serialization/util/EdgeHasherTest.java      |   501 -
 .../graph/test/util/EdgeTestUtils.java          |    12 +-
 .../graph/src/test/resources/log4j.properties   |     1 +
 .../test/resources/usergrid-SHARD.properties    |    23 +
 .../src/test/resources/usergrid-UNIT.properties |     3 +
 .../persistence/model/entity/Entity.java        |     2 +-
 .../persistence/model/field/AbstractField.java  |     2 +-
 .../persistence/model/field/ArrayField.java     |     4 +
 .../usergrid/persistence/model/field/Field.java |     2 +-
 .../persistence/model/field/SetField.java       |     1 +
 .../model/field/value/EntityObject.java         |    12 +-
 .../persistence/model/entity/SimpleIdTest.java  |    73 +
 .../model/src/test/resources/log4j.properties   |    29 +
 stack/corepersistence/pom.xml                   |     4 +-
 .../src/main/java/CpQueryFilter.tokens          |    47 +
 .../usergrid/persistence/index/query/Query.java |    19 +-
 .../persistence/index/utils/JsonUtils.java      |   329 -
 .../persistence/index/impl/EntityIndexTest.java |    19 +
 .../src/test/resources/log4j.properties         |     6 +-
 .../apache/usergrid/launcher/AppleUtils.java    |    21 +-
 .../launcher/src/main/resources/cassandra.yaml  |    25 +-
 .../1.5.4/AppleJavaExtensions-1.5.4.jar         |   Bin 23531 -> 0 bytes
 .../1.5.4/AppleJavaExtensions-1.5.4.pom         |     9 -
 .../maven-metadata-local.xml                    |    12 -
 .../recaptcha4j/0.0.8/recaptcha4j-0.0.8.jar     |   Bin 10344 -> 0 bytes
 .../recaptcha4j/0.0.8/recaptcha4j-0.0.8.pom     |     9 -
 .../recaptcha4j/maven-metadata-local.xml        |    12 -
 .../0.0.3/usergrid-java-client-0.0.3.jar        |   Bin 45750 -> 0 bytes
 .../usergrid-java-client-0.0.3.jar.lastUpdated  |     5 -
 .../0.0.3/usergrid-java-client-0.0.3.jar.sha1   |     1 -
 .../0.0.3/usergrid-java-client-0.0.3.pom        |    87 -
 .../usergrid-java-client-0.0.3.pom.lastUpdated  |     5 -
 .../0.0.3/usergrid-java-client-0.0.3.pom.sha1   |     1 -
 .../maven-metadata-local.xml                    |    13 -
 stack/mongo-emulator/pom.xml                    |     2 +-
 .../test/resources/usergrid-test-context.xml    |    78 +-
 stack/pom.xml                                   |    73 +-
 stack/query-validator/pom.xml                   |     2 +-
 .../test/resources/usergrid-test-context.xml    |     3 +-
 stack/rest/pom.xml                              |    40 +-
 .../exceptions/JsonParseExceptionMapper.java    |    35 +
 .../apache/usergrid/rest/AbstractRestIT.java    |    11 +
 .../applications/users/MatrixQueryTests.java    |   202 +
 .../users/PermissionsResourceIT.java            |     1 +
 .../rest/applications/utils/UserRepo.java       |     9 +
 .../rest/management/ExportResourceIT.java       |   131 +-
 .../rest/test/resource/MatrixResource.java      |    64 +
 .../rest/test/resource/NamedResource.java       |     5 +
 .../rest/test/resource/SetResource.java         |    12 +
 .../rest/test/resource/ValueResource.java       |    18 +-
 .../resources/usergrid-properties-context.xml   |    17 +
 .../resources/usergrid-rest-deploy-context.xml  |    16 +
 .../test/resources/usergrid-test-context.xml    |    16 +
 stack/services/pom.xml                          |    38 +-
 .../management/AccountCreationProps.java        |     6 +-
 .../cassandra/ManagementServiceImpl.java        |     8 +-
 .../usergrid/management/export/ExportJob.java   |     6 +
 .../management/export/ExportServiceImpl.java    |     5 +
 .../usergrid/services/ServiceRequest.java       |    11 +-
 .../notifications/NotificationBatchJob.java     |     5 +
 .../services/notifications/NotificationJob.java |     3 +
 .../NotificationsQueueManager.java              |     2 +-
 .../notifications/NotificationsService.java     |     2 +-
 .../services/notifications/QueueJob.java        |     4 +
 .../services/notifications/TestAdapter.java     |    30 +-
 .../apache/usergrid/management/EmailFlowIT.java |    17 +-
 .../usergrid/management/OrganizationIT.java     |     2 +
 .../usergrid/services/ServiceInvocationIT.java  |    49 +-
 .../apns/NotificationsServiceIT.java            |    34 +-
 .../resources/usergrid-properties-context.xml   |    17 +
 stack/test-utils/pom.xml                        |     2 +-
 .../usergrid/cassandra/CassandraMain.java       |     2 +-
 .../usergrid/cassandra/CassandraResource.java   |     4 +-
 .../src/main/resources/cassandra.yaml           |    25 +-
 .../src/test/resources/project.properties       |    21 +-
 .../resources/usergrid-custom-test.properties   |    16 +
 .../resources/usergrid-properties-context.xml   |    17 +
 stack/tools/pom.xml                             |     2 +-
 .../org/apache/usergrid/tools/AppNameFix.java   |    59 +-
 .../RepairingMismatchedApplicationMetadata.java |    92 +-
 .../src/main/resources/apidoc/applications.yaml |    21 +-
 .../src/main/resources/apidoc/management.yaml   |    21 +-
 stack/tools/src/main/resources/log4j.properties |    45 +
 stack/websocket/pom.xml                         |     2 +-
 ugc/features/step_definitions/ugc_steps.rb      |    23 +-
 ugc/features/support/env.rb                     |    23 +-
 ugc/lib/ugc.rb                                  |    23 +-
 ugc/lib/ugc/application.rb                      |    23 +-
 ugc/lib/ugc/commands/delete.rb                  |    23 +-
 ugc/lib/ugc/commands/get.rb                     |    23 +-
 ugc/lib/ugc/commands/logout.rb                  |    16 +
 ugc/lib/ugc/commands/post.rb                    |    23 +-
 ugc/lib/ugc/commands/profile.rb                 |    23 +-
 ugc/lib/ugc/commands/put.rb                     |    23 +-
 ugc/lib/ugc/commands/query.rb                   |    23 +-
 ugc/lib/ugc/commands/target.rb                  |    23 +-
 ugc/lib/ugc/helpers/curl.rb                     |    23 +-
 ugc/lib/ugc/helpers/format.rb                   |    23 +-
 ugc/lib/ugc/helpers/history.rb                  |    23 +-
 ugc/lib/ugc/helpers/parse.rb                    |    23 +-
 ugc/lib/ugc/helpers/rest.rb                     |    23 +-
 ugc/lib/ugc/management.rb                       |    23 +-
 ugc/lib/ugc/settings.rb                         |    23 +-
 ugc/lib/ugc/version.rb                          |    23 +-
 ugc/test/default_test.rb                        |    23 +-
 ugc/test/test_helper.rb                         |    23 +-
 939 files changed, 28334 insertions(+), 168234 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/c4b1ae6c/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------


[12/33] move tests

Posted by sn...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
new file mode 100644
index 0000000..87bed27
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationTest.java
@@ -0,0 +1,107 @@
+package org.apache.usergrid.services.notifications;
+
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.rules.TestName;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.usergrid.services.AbstractServiceIT;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+public class AbstractServiceNotificationTest extends AbstractServiceIT {
+    private NotificationsService ns;
+
+    @Rule
+    public TestName name = new TestName();
+
+    @BeforeClass
+    public static void beforeClass() {
+    }
+
+    @Before
+    public void before() throws Exception {
+
+    }
+
+    protected NotificationsService getNotificationService(){
+        ns = (NotificationsService) app.getSm().getService("notifications");
+        return ns;
+    }
+
+    protected Notification scheduleNotificationAndWait(Notification notification)
+            throws Exception {
+        getNotificationService().getQueueManager().processBatchAndReschedule(notification,null);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            notification = app.getEm().get(notification.getUuid(),
+                    Notification.class);
+            if (notification.getFinished() != null) {
+                return notification;
+            }
+        }
+        fail("Notification failed to complete");
+        return null;
+    }
+
+    protected List<EntityRef> getNotificationReceipts(EntityRef notification)
+            throws Exception {
+        Results r = app.getEm().getCollection(notification,
+                Notification.RECEIPTS_COLLECTION, null, 1000000,
+                Query.Level.REFS, false);
+        List<EntityRef> list =new ArrayList<EntityRef>();//get all
+        PagingResultsIterator it = new PagingResultsIterator(r);
+        while(it.hasNext()){
+           list.add((EntityRef)it.next());
+        }
+        return list;
+    }
+
+    protected void checkReceipts(Notification notification, int expected)
+            throws Exception {
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            receipts =getNotificationReceipts(notification);
+            if (receipts.size()==expected) {
+                 break;
+            }
+        }
+        assertEquals(expected, receipts.size());
+        for (EntityRef receipt : receipts) {
+            Receipt r = app.getEm().get(receipt, Receipt.class);
+            assertNotNull(r.getSent());
+            assertNotNull(r.getPayload());
+            assertNotNull(r.getNotifierId());
+            EntityRef source = getNotificationService().getSourceNotification(r);
+            assertEquals(source.getUuid(), notification.getUuid());
+        }
+    }
+
+    protected void checkStatistics(Notification notification, long sent,  long errors) throws Exception{
+        Map<String, Long> statistics = null;
+        long timeout = System.currentTimeMillis() + 60000;
+        while (System.currentTimeMillis() < timeout) {
+            Thread.sleep(200);
+            statistics = app.getEm().get(notification.getUuid(), Notification.class).getStatistics();
+            if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
+                break;
+            }
+        }
+        assertEquals(sent, statistics.get("sent").longValue());
+        assertEquals(errors, statistics.get("errors").longValue());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
new file mode 100644
index 0000000..84b0125
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
@@ -0,0 +1,99 @@
+package org.apache.usergrid.services.notifications.apns;
+
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.util.Date;
+import java.util.Map;
+import java.util.Random;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.ServicePayload;
+
+public class MockSuccessfulProviderAdapter implements ProviderAdapter {
+
+    private static ProviderAdapter realProviderAdapter;
+
+    public static void install(NotificationsService ns) {
+        install(ns, false);
+    }
+
+    public static void install(NotificationsService ns, boolean doAsync) {
+        if (realProviderAdapter != null)
+            realProviderAdapter = ns.providerAdapters.get("apple");
+        ns.providerAdapters.put("apple", new MockSuccessfulProviderAdapter(
+                doAsync));
+    }
+
+    public static void uninstall(NotificationsService ns) {
+        if (realProviderAdapter != null) {
+            ns.providerAdapters.put("apple", realProviderAdapter);
+        }
+    }
+
+    private ExecutorService pool;
+
+    public MockSuccessfulProviderAdapter() {
+    }
+
+    public MockSuccessfulProviderAdapter(boolean async) {
+        if (async) {
+            pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+        }
+    }
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+    }
+
+    @Override
+    public String translatePayload(Object payload) throws Exception {
+        return payload.toString();
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        return null;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+    }
+
+    @Override
+    public void sendNotification(final String providerId,
+            final Notifier notifier, final Object payload,
+            final Notification notification, final TaskTracker tracker)
+            throws Exception {
+
+        final APNsNotification apnsNotification = APNsNotification.create(
+                providerId, payload.toString(), notification, tracker);
+
+        if (pool == null) {
+            apnsNotification.messageSent();
+        } else {
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        Thread.sleep(new Random().nextInt(100));
+                        apnsNotification.messageSent();
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            });
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
new file mode 100644
index 0000000..c30edb7
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceTest.java
@@ -0,0 +1,868 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.services.notifications.apns;
+
+import com.relayrides.pushy.apns.*;
+import com.relayrides.pushy.apns.util.*;
+import org.apache.commons.io.IOUtils;
+import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.services.notifications.AbstractServiceNotificationTest;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.entities.*;
+import org.apache.usergrid.persistence.index.query.Query;
+import org.apache.usergrid.services.notifications.*;
+import org.junit.After;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.net.SocketException;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+// todo: test reschedule on delivery time change
+// todo: test restart of queuing
+public class NotificationsServiceTest extends AbstractServiceNotificationTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(NotificationsServiceTest.class);
+
+    /**
+     * set to true to run tests against actual Apple servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "apple" : "noop";
+
+    private static final String PUSH_TOKEN = "29026b5a4d2761ef13843e8bcab9fc83b47f1dfbd1d977d225ab296153ce06d6";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private Group group1;
+    private User user1;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+        // create apns notifier //
+        NotificationsQueueManager.IS_TEST = true;
+
+        app.clear();
+        app.put("name", "apns");
+        app.put("provider",PROVIDER);
+        app.put("environment", USE_REAL_CONNECTIONS ? "development" : "mock");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream("pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+        final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device1");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(notifierKey), PUSH_TOKEN);
+
+        app.clear();
+        app.put(notifierKey, PUSH_TOKEN);
+        app.put("name", "device2");
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+
+        // create User
+        app.put( "username", "edanuff" );
+        app.put( "email", "ed@anuff.com" );
+//        user1 = (User)app.testRequest( ServiceAction.POST, 1, "users" ).getEntity();
+//        app.getEm().createConnection(user1, "devices", device1);
+//        app.getEm().createConnection(user1, "devices", device2);
+
+        // create Group
+        app.put( "path", "path" );
+        app.put( "title", "group" );
+        group1 = (Group) app.testRequest( ServiceAction.POST, 1, "groups" ).getEntity();
+
+//        app.getEm().createConnection(group1, "users", user1);
+
+        ns = getNotificationService();
+    }
+
+    @After
+    public void after() throws Exception {
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+//        // verify Query for CREATED state
+        Query query = new Query();
+        query.addFilter("state='"+Notification.State.STARTED.toString()+"'");
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        // perform push //
+
+        notification = scheduleNotificationAndWait(notification);
+
+        // verify Query for FINISHED state
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        checkReceipts(notification, 1);
+        checkStatistics(notification, 1, 0);
+    }
+
+    @Test
+    public void pushWithNoValidDevicesShouldComplete() throws Exception {
+
+        // create unrelated notifier
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", "xxx");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+
+        app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = "gcm" + NOTIFIER_ID_POSTFIX;
+
+        // create unrelated device
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        Device device = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device.getProperty(key), PUSH_TOKEN);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+
+
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("started", System.currentTimeMillis());
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device);
+
+        // verify Query for CREATED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        // perform push //
+
+        ns.getQueueManager().processBatchAndReschedule(notification, null);
+
+        // verify Query for FINISHED state
+        query = new Query();
+        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
+                "notifications", query);
+        entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        notification = (Notification) entity.toTypedEntity();
+        checkReceipts(notification, 0);
+        checkStatistics(notification, 0, 0);
+    }
+
+    @Test
+    public void scheduledNotification() throws Exception {
+
+        // create push notification //
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("deliver", System.currentTimeMillis() + 240000);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // delay until the scheduler has time to run
+        Thread.sleep(500);
+
+        // verify Query for SCHEDULED state
+        Query query = new Query();
+        query.addEqualityFilter("state",
+                Notification.State.SCHEDULED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+
+        try {
+            e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
+                    e.getUuid()).getEntity();
+        }catch (Exception deleteException){
+            LOG.error("Couldn't delete",deleteException);
+        }
+        app.getEm().get(e.getUuid(), Notification.class);
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        MockSuccessfulProviderAdapter.uninstall(ns);
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                    .getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", "apple");
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 255) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals(ex.getMessage(),
+                    "java.lang.IllegalArgumentException: Apple APNs payloads must be 256 characters or less");
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            APNsNotification apnsNotification = APNsNotification
+                                    .create(providerId, payload.toString(),
+                                            notification, tracker);
+                            apnsNotification.messageSent();
+                            apnsNotification
+                                    .messageSendFailed( RejectedNotificationReason.INVALID_TOKEN);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkStatistics(notification, 0, 1);
+
+        notification = (Notification) app.getEm().get(notification)
+                .toTypedEntity();
+        checkReceipts(notification, 1);
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals(8, ((Long) receipt.getErrorCode()).longValue());
+    }
+
+    @Test
+    public void twoDevicesOneNotifier() throws Exception {
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Test
+    public void twoDevicesTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        app.clear();
+        app.put("name", "apns2");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", "apns2");
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), "apns2");
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), "development");
+
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device2.setProperty(key, null);
+        device2.setProperty(key2, null);
+        app.getEm().update(device2);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
+    }
+
+    @Test
+    public void oneDeviceTwoNotifiers() throws Exception {
+
+        // create a 2nd notifier //
+        Object nameValue = "apns2";
+        Object environValue = "development";
+
+        app.clear();
+        app.put("name", nameValue);
+        app.put("provider", PROVIDER);
+        app.put("environment", environValue);
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "pushtest_dev_recent.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
+
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+        assertEquals(notifier2.getName(), nameValue);
+        assertEquals(notifier2.getProvider(), PROVIDER);
+        assertEquals(notifier2.getEnvironment(), environValue);
+
+        String key2 = notifier2.getName() + NOTIFIER_ID_POSTFIX;
+        device1.setProperty(key2, PUSH_TOKEN);
+        app.getEm().update(device1);
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        payloads.put(notifier2.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        checkReceipts(notification, 2);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badCertificate() throws Exception {
+
+        // create an apns notifier with the wrong certificate //
+
+        app.clear();
+        app.put("name", "prod_apns");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+
+        InputStream fis = getClass().getClassLoader().getResourceAsStream(
+                "empty.p12");
+        byte[] certBytes = IOUtils.toByteArray(fis);
+        app.put("p12Certificate", certBytes);
+        fis.close();
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        notifier = app.getEm().get(e.getUuid(), Notifier.class);
+
+        // mock error (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void testConnection(Notifier notifier)
+                                throws ConnectionException {
+                            Exception e = new SocketException(
+                                    "Connection closed by remote host");
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification,null);
+            fail("testConnection() should have failed");
+        } catch (Exception ex) {
+            // good, there should be an error
+        }
+
+        // verify Query for FAILED state
+        Query query = new Query();
+        query.addEqualityFilter("state", Notification.State.FAILED.toString());
+        Results results = app.getEm().searchCollection(
+                app.getEm().getApplicationRef(), "notifications", query);
+        Entity entity = results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(entity);
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void inactiveDeviceUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("apple",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public Map<String, Date> getInactiveDevices(
+                                Notifier notifier, EntityManager em)
+                                throws Exception {
+                            return Collections.singletonMap(PUSH_TOKEN,
+                                    new Date());
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+        ns.addDevice(notification, device2);
+
+        assertNotNull(device1.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+        assertNotNull(device2.getProperty(notifier.getName()
+                + NOTIFIER_ID_POSTFIX));
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        // check provider IDs //
+
+        device1 = app.getEm().get(device1, Device.class);
+        assertNull(device1
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+        device2 = app.getEm().get(device2, Device.class);
+        assertNull(device2
+                .getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void batchTest() throws Exception {
+
+        final int NUM_DEVICES = 50;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        final Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        // perform push //
+        int oldBatchSize = NotificationsQueueManager.BATCH_SIZE;
+        NotificationsQueueManager.BATCH_SIZE = 10;
+        try {
+            ExecutorService pool = Executors
+                    .newFixedThreadPool(APNsAdapter.MAX_CONNECTION_POOL_SIZE);
+            pool.submit(new Runnable() {
+                @Override
+                public void run() {
+                        try {
+                             scheduleNotificationAndWait(notification);
+                        }catch (Exception e){}
+                }});
+        } finally {
+            NotificationsQueueManager.BATCH_SIZE = oldBatchSize;
+        }
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        MockSuccessfulProviderAdapter.install(ns, true);
+
+        final int NUM_DEVICES = 10000;
+
+        app.clear();
+        String payload = getPayload();
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        // create a notification
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+        Notification notification = (Notification) e.toTypedEntity();
+
+        // create a bunch of devices and add them to the notification
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", app.getProperties());
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    private String getPayload(){
+        ApnsPayloadBuilder builder = new ApnsPayloadBuilder();
+        builder.setAlertBody("Hello, World!");
+        builder.setSoundFileName("chime");
+        String payload = builder.buildWithDefaultMaximumLength();
+        return payload;
+    }
+    // todo: can't do the following tests here. do it in the REST tier...
+    // private Notification postNotification(String path) throws Exception {
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // path).getEntity();
+    // Thread.sleep(1000); // this sucks
+    // Notification notification = app.getEm().get(e, Notification.class);
+    // return notification;
+    // }
+    //
+    // @Test
+    // public void matrixPushDevice() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaUser() throws Exception {
+    //
+    // Notification notification = postNotification("users/" + user1.getName() +
+    // "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushViaGroup() throws Exception {
+    //
+    // Notification notification = postNotification("devices/" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushDeviceQuery() throws Exception {
+    //
+    // Notification notification = postNotification("devices;ql=name=" +
+    // device1.getName() + "/notifications");
+    // checkReceipts(notification, 1);
+    // checkStatistics(notification, 1, 0);
+    // }
+    //
+    // @Test
+    // public void matrixPushUserQuery() throws Exception {
+    //
+    // Notification notification = postNotification("users;ql=/notifications");
+    // checkReceipts(notification, 2);
+    // checkStatistics(notification, 2, 0);
+    // }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
new file mode 100644
index 0000000..656beae
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
@@ -0,0 +1,72 @@
+package org.apache.usergrid.services.notifications.gcm;
+
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.util.Date;
+import java.util.Map;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.services.ServicePayload;
+
+public class MockSuccessfulProviderAdapter implements ProviderAdapter {
+
+    private static ProviderAdapter realProviderAdapter;
+
+    public static void install(NotificationsService ns) {
+        if (realProviderAdapter != null)
+            realProviderAdapter = ns.providerAdapters.get("google");
+        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter());
+    }
+
+    public static void uninstall(NotificationsService ns) {
+        if (realProviderAdapter != null) {
+            ns.providerAdapters.put("google", realProviderAdapter);
+        }
+    }
+
+    public MockSuccessfulProviderAdapter() {
+    }
+
+    @Override
+    public void testConnection(Notifier notifier) throws ConnectionException {
+    }
+
+    @Override
+    public String translatePayload(Object payload) throws Exception {
+        return payload.toString();
+    }
+
+    @Override
+    public Map<String, Date> getInactiveDevices(Notifier notifier,
+            EntityManager em) throws Exception {
+        return null;
+    }
+
+    @Override
+    public void validateCreateNotifier(ServicePayload payload) throws Exception {
+    }
+
+    @Override
+    public void doneSendingNotifications() throws Exception {
+    }
+
+    @Override
+    public void sendNotification(String providerId, Notifier notifier,
+            Object payload, Notification notification, final TaskTracker tracker)
+            throws Exception {
+        new Thread() {
+            @Override
+            public void run() {
+                try {
+                    tracker.completed();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }.start();
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/3c761ff4/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
new file mode 100644
index 0000000..7be8e88
--- /dev/null
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceTest.java
@@ -0,0 +1,546 @@
+/*******************************************************************************
+ * Copyright 2012 Apigee Corporation
+ *
+ * Licensed 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.usergrid.services.notifications.gcm;
+
+import org.apache.usergrid.services.notifications.AbstractServiceNotificationTest;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Notifier;
+import org.apache.usergrid.persistence.entities.Receipt;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ConnectionException;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.util.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.entities.Device;
+import org.apache.usergrid.services.ServiceAction;
+
+import static org.junit.Assert.*;
+import static org.apache.usergrid.services.notifications.NotificationsService.NOTIFIER_ID_POSTFIX;
+
+public class NotificationsServiceTest extends AbstractServiceNotificationTest {
+
+    private static final Logger LOG = LoggerFactory
+            .getLogger(NotificationsServiceTest.class);
+
+    /**
+     * set to true to run tests against actual GCM servers - but they may not
+     * all run correctly
+     */
+    private static final boolean USE_REAL_CONNECTIONS = false;
+    private static final String PROVIDER = USE_REAL_CONNECTIONS ? "google"
+            : "noop";
+
+    private static final String API_KEY = "AIzaSyCIH_7WC0mOqBGMOXyQnFgrBpOePgHvQJM";
+    private static final String PUSH_TOKEN = "APA91bGxRGnMK8tKgVPzSlxtCFvwSVqx0xEPjA06sBmiK0kQsiwUt6ipSYF0iPRHyUgpXle0P8OlRWJADkQrcN7yxG4pLMg1CVmrqDu8tfSe63mZ-MRU2IW0cOhmosqzC9trl33moS3OvT7qjDjkP4Qq8LYdwwYC5A";
+
+    private Notifier notifier;
+    private Device device1, device2;
+    private NotificationsService ns;
+
+    @Override
+    @Before
+    public void before() throws Exception {
+        super.before();
+
+        // create gcm notifier //
+
+        app.clear();
+        app.put("name", "gcm");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+
+        notifier = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+        String key = notifier.getName() + NOTIFIER_ID_POSTFIX;
+
+        // create devices //
+
+        app.clear();
+        app.put(key, PUSH_TOKEN);
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "devices", e.getUuid());
+
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+        assertEquals(device1.getProperty(key), PUSH_TOKEN);
+
+        app.put(key, PUSH_TOKEN);
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device2 = app.getEm().get(e.getUuid(), Device.class);
+        ns = getNotificationService();
+    }
+
+    @Test
+    public void emptyPushNotification() throws Exception {
+
+        app.clear();
+        app.put("name", "foo");
+        app.put("provider", PROVIDER);
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Notifier n = (Notifier) app
+                .testRequest(ServiceAction.POST, 1, "notifiers").getEntity()
+                .toTypedEntity();
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put("foo", payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 0);
+    }
+
+    @Test
+    public void singlePushNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void singlePushNotificationViaUser() throws Exception {
+
+        app.clear();
+
+        app.put("username", "asdf");
+        app.put("email", "asdf@adsf.com");
+        Entity user = app.testRequest(ServiceAction.POST, 1, "users")
+                .getEntity();
+        assertNotNull(user);
+        Entity device = app.testRequest(ServiceAction.POST, 1, "users",
+                user.getUuid(), "devices", device1.getUuid()).getEntity();
+        assertEquals(device.getUuid(), device1.getUuid());
+
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+    }
+
+    @Test
+    public void twoBatchNotification() throws Exception {
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device2);
+        ns.addDevice(notification, device1);
+
+        // reduce Batch size to 1
+        Field field = GCMAdapter.class.getDeclaredField("BATCH_SIZE");
+        field.setAccessible(true);
+        int multicastSize = field.getInt(GCMAdapter.class);
+        try {
+            field.setInt(GCMAdapter.class, 1);
+
+            // perform push //
+            notification = scheduleNotificationAndWait(notification);
+
+            checkReceipts(notification, 2);
+        } finally {
+            field.setInt(GCMAdapter.class, multicastSize);
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void providerIdUpdate() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        final String newProviderId = "newProviderId";
+        ns.providerAdapters.put("google", new MockSuccessfulProviderAdapter() {
+            @Override
+            public void sendNotification(String providerId, Notifier notifier,
+                    Object payload, Notification notification,
+                    TaskTracker tracker) throws Exception {
+                tracker.completed(newProviderId);
+            }
+        });
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        checkReceipts(notification, 1);
+
+        Device device = (Device) app.getEm().get(device1).toTypedEntity();
+        assertEquals(newProviderId,
+                device.getProperty(notifier.getName() + NOTIFIER_ID_POSTFIX));
+    }
+
+    @Test
+    public void badPayloads() throws Exception {
+
+        // bad payloads format
+
+        app.clear();
+        app.put("payloads", "{asdf}");
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // bad notifier
+
+        Map<String, String> payloads = new HashMap<String, String>(2);
+        app.put("payloads", payloads);
+        payloads.put("xxx", "");
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (IllegalArgumentException ex) {
+            // ok
+        }
+
+        // payload too long
+
+        // need the real provider for this one...
+        app.clear();
+        app.put("name", "gcm2");
+        app.put("provider", "google");
+        app.put("environment", "development");
+        app.put("apiKey", API_KEY);
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
+                .getEntity();
+        Notifier notifier2 = app.getEm().get(e.getUuid(), Notifier.class);
+
+        payloads.clear();
+        StringBuilder sb = new StringBuilder();
+        sb.append("{\"x\":\"");
+        while (sb.length() < 4080) {
+            sb.append("x");
+        }
+        sb.append("\"}");
+        payloads.put(notifier2.getUuid().toString(), sb.toString());
+
+        app.clear();
+        app.put("payloads", payloads);
+
+        try {
+            app.testRequest(ServiceAction.POST, 1, "notifications");
+            fail("invalid payload should have been rejected");
+        } catch (Exception ex) {
+            assertEquals("java.lang.IllegalArgumentException: GCM payloads must be 4096 characters or less",
+                    ex.getMessage());
+            // ok
+        }
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badToken() throws Exception {
+
+        // mock action (based on verified actual behavior) //
+        if (!USE_REAL_CONNECTIONS) {
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            tracker.failed("InvalidRegistration",
+                                    "InvalidRegistration");
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // device w/ bad token
+        app.clear();
+        app.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN + "x");
+
+        e = app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
+        device1 = app.getEm().get(e.getUuid(), Device.class);
+
+        ns.addDevice(notification, device1);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+
+        List<EntityRef> receipts = getNotificationReceipts(notification);
+        assertEquals(1, receipts.size());
+        Receipt receipt = app.getEm().get(receipts.get(0), Receipt.class);
+        assertEquals("InvalidRegistration", receipt.getErrorCode());
+    }
+
+    @Ignore
+    // todo: how can I mock this?
+    @Test
+    public void badAPIKey() throws Exception {
+
+        if (!USE_REAL_CONNECTIONS) {
+            // mock action (based on verified actual behavior) //
+            ns.providerAdapters.put("google",
+                    new MockSuccessfulProviderAdapter() {
+                        @Override
+                        public void sendNotification(String providerId,
+                                Notifier notifier, Object payload,
+                                Notification notification, TaskTracker tracker)
+                                throws Exception {
+                            Exception e = new IOException();
+                            throw new ConnectionException(e.getMessage(), e);
+                        }
+                    });
+        }
+
+        // create push notification //
+
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        ns.addDevice(notification, device1);
+
+        // save bad API key
+        app.getEm().setProperty(notifier, "apiKey", API_KEY + "x");
+
+        // perform push //
+
+        try {
+            ns.getQueueManager().processBatchAndReschedule(notification, null);
+            fail("Should have received a ConnectionException");
+        } catch (ConnectionException ex) {
+            // good
+        }
+    }
+
+    @Ignore("Run only if you need to.")
+    @Test
+    public void loadTest() throws Exception {
+
+        final int NUM_DEVICES = 10000;
+
+        // create notification //
+
+        HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        properties.put("payloads", payloads);
+        properties.put("queued", System.currentTimeMillis());
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
+                .getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEm().get(e.getUuid(),
+                Notification.class);
+        assertEquals(
+                notification.getPayloads().get(notifier.getUuid().toString()),
+                payload);
+
+        // create a bunch of devices and add them to the notification
+        properties = new LinkedHashMap<String, Object>();
+        properties.put(notifier.getName() + NOTIFIER_ID_POSTFIX, PUSH_TOKEN);
+        for (int i = 0; i < NUM_DEVICES; i++) {
+            Entity entity = app.getEm().create("device", properties);
+            ns.addDevice(notification, entity);
+        }
+
+        long time = System.currentTimeMillis();
+        LOG.error("START DELIVERY OF {} NOTIFICATIONS", NUM_DEVICES);
+
+        // perform push //
+        notification = scheduleNotificationAndWait(notification);
+        LOG.error("END DELIVERY OF {} NOTIFICATIONS ({})", NUM_DEVICES,
+                System.currentTimeMillis() - time);
+
+        // check receipts //
+        checkReceipts(notification, NUM_DEVICES);
+        checkStatistics(notification, NUM_DEVICES, 0);
+    }
+
+    // @Test
+    // public void inactiveDeviceUpdate() throws Exception {
+    //
+    // if (!USE_REAL_CONNECTIONS) {
+    // // mock action (based on verified actual behavior) //
+    // NotificationsService.providerAdapters.put("apple", new
+    // MockSuccessfulProviderAdapter() {
+    // public Map<String,Date> getInactiveDevices(Notifier notifier,
+    // EntityManager em) throws Exception {
+    // return Collections.singletonMap(PUSH_TOKEN, new Date());
+    // }
+    // });
+    // }
+    //
+    // // create push notification //
+    //
+    // HashMap<String, Object> properties = new LinkedHashMap<String, Object>();
+    // String payload =
+    // APNS.newPayload().alertBody("Hello, World!").sound("chime").build();
+    // Map<String, String> payloads = new HashMap<String, String>(1);
+    // payloads.put(notifier.getUuid().toString(), payload);
+    // properties.put("payloads", payloads);
+    // properties.put("queued", System.currentTimeMillis());
+    //
+    // Entity e = testRequest(sm, ServiceAction.POST, 1, properties,
+    // "notifications").getEntity();
+    // testRequest(sm, ServiceAction.GET, 1, null, "notifications",
+    // e.getUuid());
+    //
+    // Notification notification = em.get(e.getUuid(), Notification.class);
+    // assertEquals(notification.getPayloads().get(notifier.getUuid().toString()),
+    // payload);
+    //
+    // ns.addDevice(notification, device1);
+    // ns.addDevice(notification, device2);
+    //
+    // assertNotNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // assertNotNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    //
+    // // perform push //
+    // notification = scheduleNotificationAndWait(notification);
+    //
+    // // check provider IDs //
+    //
+    // device1 = em.get(device1, Device.class);
+    // assertNull(device1.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // device2 = em.get(device2, Device.class);
+    // assertNull(device2.getProperty(notifier.getName() +
+    // NOTIFIER_ID_POSTFIX));
+    // }
+}


[33/33] git commit: Fixes to get the singlePushNotification test (and other push tests) running. There were problems serializing enums, problems deserializing UUIDs, incorrect use of message UUID as a device UUID and some refresh index issues.

Posted by sn...@apache.org.
Fixes to get the singlePushNotification test (and other push tests) running. There were problems serializing enums, problems deserializing UUIDs, incorrect use of message UUID as a device UUID and some refresh index issues.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/55e5c163
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/55e5c163
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/55e5c163

Branch: refs/heads/two-dot-o
Commit: 55e5c163c08d8351dfefc24cdd40e0bc3c32f51d
Parents: 93477bc
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Sep 5 17:08:07 2014 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Sep 5 17:08:07 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityMapUtils.java       |  3 +++
 .../notifications/ApplicationQueueManager.java  |  4 ++-
 .../notifications/ApplicationQueueMessage.java  | 28 +++++++++++++++++++-
 .../apns/NotificationsServiceIT.java            | 20 ++++++++------
 4 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
index 18eb7f9..6003093 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
@@ -109,6 +109,9 @@ public class CpEntityMapUtils {
 
             } else if ( value instanceof Map ) {
                 processMapValue( value, fieldName, entity, entityType);
+
+            } else if ( value instanceof Enum ) {
+                entity.setField( new StringField( fieldName, value.toString(), unique && topLevel ));
 	
 			} else if ( value != null ) {
                 byte[] valueSerialized;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
index c88702e..50b17bb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
@@ -289,7 +289,9 @@ public class ApplicationQueueManager implements QueueManager {
                             @Override
                             public ApplicationQueueMessage call(ApplicationQueueMessage message) {
                                 try {
-                                    UUID deviceUUID = message.getUuid();
+
+                                    UUID deviceUUID = message.getDeviceId();
+
                                     Notification notification = notificationMap.get(message.getNotificationId());
                                     if (notification == null) {
                                         notification = em.get(message.getNotificationId(), Notification.class);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
index f66fbf7..68c62d9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
@@ -16,15 +16,21 @@
  */
 package org.apache.usergrid.services.notifications;
 
+import java.nio.ByteBuffer;
+import java.util.Arrays;
 import org.apache.usergrid.mq.Message;
 
 import java.util.UUID;
+import org.elasticsearch.common.primitives.Longs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by ApigeeCorporation on 9/4/14.
  */
 public class ApplicationQueueMessage extends Message {
 
+    private static final Logger log = LoggerFactory.getLogger(ApplicationQueueMessage.class);
 
     static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
     static final String MESSAGE_PROPERTY_APPLICATION_UUID = "applicationUUID";
@@ -44,9 +50,29 @@ public class ApplicationQueueMessage extends Message {
         setNotifierId(notifierId);
     }
 
+    public static UUID bytesToUuid( byte[] sixteenBytes ) {
+        byte[] msBytes = Arrays.copyOfRange( sixteenBytes, 0, 8 );
+        byte[] lsBytes = Arrays.copyOfRange( sixteenBytes, 8, 16 );
+        long msb = Longs.fromByteArray( msBytes ); 
+        long lsb = Longs.fromByteArray( lsBytes ); 
+        return new UUID( msb, lsb );
+    }
 
     public static ApplicationQueueMessage generate(Message message) {
-        return new ApplicationQueueMessage(UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_APPLICATION_UUID)), UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_NOTIFICATION_ID)), UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_DEVICE_UUID)), message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME), message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID));
+
+        // this crazyness may indicate that Core Persistence is not storing UUIDs correctly
+        byte[] mpaBytes = (byte[])message.getObjectProperty(MESSAGE_PROPERTY_APPLICATION_UUID);
+        UUID mpaUuid = bytesToUuid(mpaBytes);
+        byte[] mpnBytes = (byte[])message.getObjectProperty(MESSAGE_PROPERTY_NOTIFICATION_ID);
+        UUID mpnUuid = bytesToUuid(mpnBytes);
+        // end of crazyness
+
+        UUID mpdUuid = (UUID)message.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID);
+
+        return new ApplicationQueueMessage(
+                mpaUuid, mpnUuid, mpdUuid,
+                message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME), 
+                message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID));
     }
 
     public UUID getApplicationId() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index c0b8cdd..41eb376 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -31,8 +31,6 @@ import org.slf4j.LoggerFactory;
 import java.io.InputStream;
 import java.net.SocketException;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 import org.apache.usergrid.services.ServiceAction;
 
@@ -147,6 +145,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // create push notification //
 
+        app.getEm().refreshIndex();
+
+        // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
         Query pQuery = new Query();
         pQuery.setLimit(100);
@@ -155,24 +156,25 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         pQuery.addIdentifier(new ServiceParameter.NameParameter(device1.getUuid().toString()).getIdentifier());
         ns.getQueueManager().TEST_PATH_QUERY =  new PathQuery( new SimpleEntityRef(app.getEm().getApplicationRef()), pQuery);
 
-
+        // create a "hellow world" notification
         String payload = getPayload();
         Map<String, String> payloads = new HashMap<String, String>(1);
         payloads.put(notifier.getName().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
 
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
+        // post notification to service manager
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+
+        // ensure notification it was created
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
+        // ensure notification has expected name
+        Notification notification = app.getEm().get(e.getUuid(), Notification.class);
         assertEquals(
                 notification.getPayloads().get(notifier.getName().toString()),
                 payload);
 
-
         // verify Query for CREATED state
         Query query = new Query();
         query.addEqualityFilter("state", Notification.State.STARTED.toString());
@@ -185,6 +187,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         notification = scheduleNotificationAndWait(notification);
 
+        app.getEm().refreshIndex();
+
         // verify Query for FINISHED state
         query = new Query();
         query.addEqualityFilter("state", Notification.State.FINISHED.toString());


[26/33] git commit: Fixed notification errors

Posted by sn...@apache.org.
Fixed notification errors


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

Branch: refs/heads/two-dot-o
Commit: cb668d2a2f4f9c814084d5ee8f62ffa85b717d5f
Parents: 1d8dd2f
Author: grey <gr...@apigee.com>
Authored: Wed Sep 3 15:02:48 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Wed Sep 3 15:02:48 2014 -0700

----------------------------------------------------------------------
 .../usergrid/services/notifications/NotificationBatchJob.java   | 5 +++++
 .../apache/usergrid/services/notifications/NotificationJob.java | 3 +++
 .../services/notifications/NotificationsQueueManager.java       | 2 +-
 .../usergrid/services/notifications/NotificationsService.java   | 2 +-
 .../org/apache/usergrid/services/notifications/QueueJob.java    | 4 ++++
 5 files changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb668d2a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
index 05fd360..b9ea73e 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationBatchJob.java
@@ -122,4 +122,9 @@ public class NotificationBatchJob implements Job {
         logger.info( "execute NotificationBatch completed normally" );
     }
 
+
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb668d2a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
index 4cf8c2f..35051bc 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationJob.java
@@ -125,5 +125,8 @@ public class NotificationJob extends OnlyOnceJob {
     }
 
 
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
 
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb668d2a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
index f36a3de..8a15090 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
@@ -98,7 +98,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
                     Query query = new Query();
                     query.setCollection("notifiers");
                     query.setLimit(100);
-                    PathQuery<Notifier> pathQuery = new PathQuery<Notifier>(em.getApplicationRef(), query);
+                    PathQuery<Notifier> pathQuery = new PathQuery<Notifier>((SimpleEntityRef)em.getApplicationRef(), query);
                     Iterator<Notifier> notifierIterator = pathQuery.iterator(em);
                     while (notifierIterator.hasNext()) {
                         Notifier notifier = notifierIterator.next();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb668d2a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
index ae289ed..e347f98 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsService.java
@@ -157,7 +157,7 @@ public class NotificationsService extends AbstractCollectionService {
             query.setCollection(collection);
 
             if (pathQuery == null) {
-                pathQuery = new PathQuery(em.getApplicationRef(), query);
+                pathQuery = new PathQuery((SimpleEntityRef)em.getApplicationRef(), query);
             } else {
                 pathQuery = pathQuery.chain(query);
             }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb668d2a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
index e34c816..9f756a4 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueJob.java
@@ -124,4 +124,8 @@ public class QueueJob extends OnlyOnceJob {
     }
 
 
+    @Override
+    public void dead( final JobExecution execution ) throws Exception {
+
+    }
 }


[16/33] git commit: updating queue manager with latest; add license headers

Posted by sn...@apache.org.
updating queue manager with latest; add license headers


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

Branch: refs/heads/two-dot-o
Commit: 9d4b70e4228c533e573f23a3f17b1f2053985c76
Parents: dd4e765
Author: Shawn Feldman <sf...@apache.org>
Authored: Wed Aug 20 16:21:52 2014 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Wed Aug 20 16:21:52 2014 -0600

----------------------------------------------------------------------
 stack/services/pom.xml                          |   7 +
 .../NotificationsQueueManager.java              | 178 +++++++++++--------
 .../AbstractServiceNotificationIT.java          |  16 ++
 .../notifications/NotifiersServiceIT.java       |  16 ++
 .../apns/MockSuccessfulProviderAdapter.java     |  16 ++
 .../apns/NotificationsServiceIT.java            |  17 +-
 .../gcm/MockSuccessfulProviderAdapter.java      |  16 ++
 .../gcm/NotificationsServiceIT.java             |  17 +-
 8 files changed, 188 insertions(+), 95 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/pom.xml
----------------------------------------------------------------------
diff --git a/stack/services/pom.xml b/stack/services/pom.xml
index ef5ed5c..2d4fb09 100644
--- a/stack/services/pom.xml
+++ b/stack/services/pom.xml
@@ -562,5 +562,12 @@
       <artifactId>gcm-server</artifactId>
       <version>1.0.2</version>
     </dependency>
+
+    <dependency>
+      <groupId>com.clearspring.analytics</groupId>
+      <artifactId>stream</artifactId>
+      <version>2.7.0</version>
+    </dependency>
+
   </dependencies>
 </project>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
index e7ea96c..f36a3de 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/NotificationsQueueManager.java
@@ -15,7 +15,8 @@
  * limitations under the License.
  */
 package org.apache.usergrid.services.notifications;
-
+import com.clearspring.analytics.hash.MurmurHash;
+import com.clearspring.analytics.stream.frequency.CountMinSketch;
 import com.codahale.metrics.Counter;
 import com.codahale.metrics.Histogram;
 import com.codahale.metrics.Meter;
@@ -45,7 +46,7 @@ import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
 /**
- * Created by ApigeeCorporation on 8/13/14.
+ * manages queues for notifications
  */
 public class NotificationsQueueManager implements NotificationServiceProxy {
     private static final String NOTIFICATION_CONCURRENT_BATCHES = "notification.concurrent.batches";
@@ -76,11 +77,11 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
     static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
 
     public final Map<String, ProviderAdapter> providerAdapters =   new HashMap<String, ProviderAdapter>(3);
-            {
-                providerAdapters.put("apple", APNS_ADAPTER);
-                providerAdapters.put("google", new GCMAdapter());
-                providerAdapters.put("noop", TEST_ADAPTER);
-            };
+    {
+        providerAdapters.put("apple", APNS_ADAPTER);
+        providerAdapters.put("google", new GCMAdapter());
+        providerAdapters.put("noop", TEST_ADAPTER);
+    };
     // these 2 can be static, but GCM can't. future: would be nice to get gcm
     // static as well...
     public static ProviderAdapter APNS_ADAPTER = new APNsAdapter();
@@ -89,22 +90,23 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
     //cache to retrieve push manager, cached per notifier, so many notifications will get same push manager
     private static LoadingCache<EntityManager, HashMap<Object,Notifier>> notifierCacheMap = CacheBuilder
             .newBuilder()
-            .expireAfterWrite(5, TimeUnit.MINUTES)
+            .expireAfterWrite(90, TimeUnit.SECONDS)
             .build(new CacheLoader<EntityManager, HashMap<Object, Notifier>>() {
                 @Override
                 public HashMap<Object, Notifier> load(EntityManager em) {
                     HashMap<Object, Notifier> notifierHashMap = new HashMap<Object, Notifier>();
                     Query query = new Query();
                     query.setCollection("notifiers");
-                    query.setLimit(50);
+                    query.setLimit(100);
                     PathQuery<Notifier> pathQuery = new PathQuery<Notifier>(em.getApplicationRef(), query);
                     Iterator<Notifier> notifierIterator = pathQuery.iterator(em);
                     while (notifierIterator.hasNext()) {
                         Notifier notifier = notifierIterator.next();
-                        notifierHashMap.put(notifier.getName().toLowerCase(), notifier);
-                        notifierHashMap.put(notifier.getUuid(), notifier);
-                        notifierHashMap.put(notifier.getUuid().toString(), notifier);
-
+                        String name = notifier.getName() != null ? notifier.getName() : "" ;
+                        UUID uuid = notifier.getUuid() != null ? notifier.getUuid() : UUID.randomUUID();
+                        notifierHashMap.put(name.toLowerCase(), notifier);
+                        notifierHashMap.put(uuid, notifier);
+                        notifierHashMap.put(uuid.toString(), notifier);
                     }
                     return notifierHashMap;
                 }
@@ -140,7 +142,6 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         final AtomicInteger deviceCount = new AtomicInteger(); //count devices so you can make a judgement on batching
         final AtomicInteger batchCount = new AtomicInteger(); //count devices so you can make a judgement on batching
         final int numCurrentBatchesConfig = getNumConcurrentBatches();
-
         final ConcurrentLinkedQueue<String> errorMessages = new ConcurrentLinkedQueue<String>(); //build up list of issues
 
         //get devices in querystring, and make sure you have access
@@ -151,21 +152,30 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
                 jobScheduler.scheduleQueueJob(notification, true);
                 return;
             }
+            final CountMinSketch sketch = new CountMinSketch(0.0001,.99,7364181); //add probablistic counter to find dups
 
-            Observable.create(new IteratorObservable<Entity>(iterator)).parallel(new Func1<Observable<Entity>, Observable<Entity>>() {
+            rx.Observable.create(new IteratorObservable<Entity>(iterator)).parallel(new Func1<rx.Observable<Entity>, rx.Observable<Entity>>() {
                 @Override
-                public Observable<Entity> call(Observable<Entity> deviceObservable) {
+                public rx.Observable<Entity> call(rx.Observable<Entity> deviceObservable) {
                     return deviceObservable.map( new Func1<Entity,Entity>() {
                         @Override
                         public Entity call(Entity entity) {
                             try {
                                 List<EntityRef> devicesRef = getDevices(entity); // resolve group
+                                String queueName = getJobQueueName(notification);
                                 boolean maySchedule = false;
                                 for (EntityRef deviceRef : devicesRef) {
+                                    long hash = MurmurHash.hash(deviceRef.getUuid());
+                                    if(sketch.estimateCount(hash)>0){
+                                        LOG.debug("Maybe Found duplicate device: {}", deviceRef.getUuid());
+                                        continue;
+                                    }else {
+                                        sketch.add(hash,1);
+                                    }
                                     maySchedule |= deviceCount.incrementAndGet() % BATCH_SIZE == 0;
                                     Message message = new Message();
                                     message.setProperty(MESSAGE_PROPERTY_DEVICE_UUID, deviceRef.getUuid());
-                                    qm.postToQueue( getJobQueueName(notification), message);
+                                    qm.postToQueue(queueName, message);
                                     if(notification.getQueued() == null){
                                         // update queued time
                                         notification.setQueued(System.currentTimeMillis());
@@ -175,10 +185,10 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
 
                                 //start working if you are on a large batch,
                                 if (maySchedule && numCurrentBatchesConfig >= batchCount.incrementAndGet()) {
-                                    processBatchAndReschedule(notification, jobExecution);
+                                    processBatchAndReschedule(notification, null);
                                 }
 
-                                if(devicesRef.size() <=0){
+                                if(devicesRef.size() <= 0){
                                     errorMessages.add("Could not find devices for entity: "+entity.getUuid());
                                 }
 
@@ -191,7 +201,6 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
                     });
                 }
             }, Schedulers.io()).toBlocking().lastOrDefault(null);
-
         }
 
         batchCount.set(Math.min(numCurrentBatchesConfig, batchCount.get()));
@@ -231,60 +240,20 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
             LOG.info(sb.toString());
         }
     }
-    public void finishedBatch(Notification notification, long successes, long failures) throws Exception {
-        finishedBatch(notification,successes,failures,false);
-    }
-    public void finishedBatch(Notification notification, long successes, long failures, boolean overrideComplete) throws Exception {
-        if (LOG.isDebugEnabled()) {
-            StringBuilder sb = new StringBuilder();
-            sb.append("finishedBatch ").append(notification.getUuid());
-            sb.append(" successes: ").append(successes);
-            sb.append(" failures: ").append(failures);
-            LOG.info(sb.toString());
-        }
-
-        notification = em.get(notification, Notification.class); // refresh data
-        notification.updateStatistics(successes, failures);
-        notification.setModified(System.currentTimeMillis());
-        Map<String, Object> properties = new HashMap<String, Object>(4);
-        properties.put("statistics", notification.getStatistics());
-        properties.put("modified", notification.getModified());
-
-        if (isNotificationDeliveryComplete(notification) || overrideComplete) {
-            notification.setFinished(notification.getModified());
-            properties.put("finished", notification.getModified());
-            properties.put("state", notification.getState());
-            long elapsed = notification.getFinished()
-                    - notification.getStarted();
-            long sent = notification.getStatistics().get("sent");
-            long errors = notification.getStatistics().get("errors");
 
-            if (LOG.isInfoEnabled()) {
-                StringBuilder sb = new StringBuilder();
-                sb.append("notification ").append(notification.getUuid());
-                sb.append(" done sending to ").append(sent + errors);
-                sb.append(" devices in ").append(elapsed).append(" ms");
-                LOG.info(sb.toString());
-            }
-
-        } else {
-            LOG.info("notification finished batch: {}",
-                    notification.getUuid());
-        }
-        em.updateProperties(notification, properties);
-
-        Set<Notifier> notifiers = new HashSet<Notifier>(getNotifierMap().values()); // remove dups
-        asyncCheckForInactiveDevices(notifiers);
-    }
 
     private HashMap<Object,Notifier> getNotifierMap(){
         try{
-            return notifierCacheMap.get(em);
+            HashMap<Object,Notifier> map = notifierCacheMap.get(em);
+            return map;
         }catch (ExecutionException ee){
             LOG.error("failed to get from cache",ee);
             return new HashMap<Object, Notifier>();
         }
     }
+    private void clearNotifierMap(){
+        notifierCacheMap.invalidate(em);
+    }
     /*
         * returns partial list of Device EntityRefs (up to BATCH_SIZE) - empty when
         * done w/ delivery
@@ -295,8 +264,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         qq.setLimit(batchSize);
         qq.setTimeout(MESSAGE_TRANSACTION_TIMEOUT);
         QueueResults results = qm.getFromQueue(getJobQueueName(notification), qq);
-        LOG.debug("got batch of {} devices for notification {}",
-                results.size(), notification.getUuid());
+        LOG.debug("got batch of {} devices for notification {}", results.size(), notification.getUuid());
         return results;
     }
     /**
@@ -324,8 +292,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         }else{
             consecutiveEmptyQueues.incrementAndGet();
         }
-
-        if (!isNotificationDeliveryComplete(notification) && consecutiveEmptyQueues.get() <= CONSECUTIVE_EMPTY_QUEUES) {
+        if (qm.hasPendingReads(getJobQueueName(notification), null) && consecutiveEmptyQueues.get() <= CONSECUTIVE_EMPTY_QUEUES) {
             if(jobExecution==null) {
                 jobScheduler.scheduleBatchJob(notification, reschedule_delay);
             }else{
@@ -354,11 +321,11 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         final Map<String, Object> payloads = notification.getPayloads();
         final Map<String, Object> translatedPayloads = translatePayloads(payloads, notifierMap);
         try {
-            Observable
+            rx.Observable
                     .from(queueResults)
-                    .parallel(new Func1<Observable<Message>, Observable<Message>>() {
+                    .parallel(new Func1<rx.Observable<Message>, rx.Observable<Message>>() {
                         @Override
-                        public Observable<Message> call(Observable<Message> messageObservable) {
+                        public rx.Observable<Message> call(rx.Observable<Message> messageObservable) {
                             return messageObservable.map(new Func1<Message, Message>() {
                                 @Override
                                 public Message call(Message message) {
@@ -449,6 +416,54 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
 
     }
 
+    public void finishedBatch(Notification notification, long successes, long failures) throws Exception {
+        finishedBatch(notification,successes,failures,false);
+    }
+    public void finishedBatch(Notification notification, long successes, long failures, boolean overrideComplete) throws Exception {
+        if (LOG.isDebugEnabled()) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("finishedBatch ").append(notification.getUuid());
+            sb.append(" successes: ").append(successes);
+            sb.append(" failures: ").append(failures);
+            LOG.info(sb.toString());
+        }
+
+        notification = em.get(notification, Notification.class); // refresh data
+        notification.updateStatistics(successes, failures);
+        notification.setModified(System.currentTimeMillis());
+        Map<String, Object> properties = new HashMap<String, Object>(4);
+        properties.put("statistics", notification.getStatistics());
+        properties.put("modified", notification.getModified());
+
+        if (isNotificationDeliveryComplete(notification) || overrideComplete) {
+            notification.setFinished(notification.getModified());
+            properties.put("finished", notification.getModified());
+            properties.put("state", notification.getState());
+            long elapsed = notification.getFinished()
+                    - notification.getStarted();
+            long sent = notification.getStatistics().get("sent");
+            long errors = notification.getStatistics().get("errors");
+
+            if (LOG.isInfoEnabled()) {
+                StringBuilder sb = new StringBuilder();
+                sb.append("notification ").append(notification.getUuid());
+                sb.append(" done sending to ").append(sent + errors);
+                sb.append(" devices in ").append(elapsed).append(" ms");
+                LOG.info(sb.toString());
+            }
+
+        } else {
+            LOG.info("notification finished batch: {}",
+                    notification.getUuid());
+        }
+        em.updateProperties(notification, properties);
+
+        Set<Notifier> notifiers = new HashSet<Notifier>(getNotifierMap().values()); // remove dups
+        asyncCheckForInactiveDevices(notifiers);
+    }
+    /**
+     * Call the adapter with the notifier
+     */
     private Map<String, Object> translatePayloads(Map<String, Object> payloads, Map<Object, Notifier> notifierMap) throws Exception {
         Map<String, Object> translatedPayloads = new HashMap<String, Object>(
                 payloads.size());
@@ -456,12 +471,15 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
             String payloadKey = entry.getKey();
             Object payloadValue = entry.getValue();
             Notifier notifier = notifierMap.get(payloadKey);
+            if(notifier==null){
+                clearNotifierMap();
+                notifierMap = getNotifierMap();
+                notifier = notifierMap.get(payloadKey);
+            }
             if (notifier != null) {
-                ProviderAdapter providerAdapter = providerAdapters.get(notifier
-                        .getProvider());
+                ProviderAdapter providerAdapter = providerAdapters.get(notifier.getProvider());
                 if (providerAdapter != null) {
-                    Object translatedPayload = payloadValue != null ? providerAdapter
-                            .translatePayload(payloadValue) : null;
+                    Object translatedPayload = payloadValue != null ? providerAdapter.translatePayload(payloadValue) : null;
                     if (translatedPayload != null) {
                         translatedPayloads.put(payloadKey, translatedPayload);
                     }
@@ -475,7 +493,7 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         return Integer.parseInt(props.getProperty(NOTIFICATION_CONCURRENT_BATCHES, "1"));
     }
 
-    private static final class IteratorObservable<T> implements Observable.OnSubscribe<T> {
+    private static final class IteratorObservable<T> implements rx.Observable.OnSubscribe<T> {
         private final Iterator<T> input;
         private IteratorObservable( final Iterator input ) {this.input = input;}
 
@@ -613,10 +631,12 @@ public class NotificationsQueueManager implements NotificationServiceProxy {
         if ("device".equals(ref.getType())) {
             devices = Collections.singletonList(ref);
         } else if ("user".equals(ref.getType())) {
-            devices = em.getCollection(ref, "devices", null, Query.MAX_LIMIT, Query.Level.REFS, false).getRefs();
+            devices = em.getCollection(ref, "devices", null, Query.MAX_LIMIT,
+                    Query.Level.REFS, false).getRefs();
         } else if ("group".equals(ref.getType())) {
             devices = new ArrayList<EntityRef>();
-            for (EntityRef r : em.getCollection(ref, "users", null,  Query.MAX_LIMIT, Query.Level.REFS, false).getRefs()) {
+            for (EntityRef r : em.getCollection(ref, "users", null,
+                    Query.MAX_LIMIT, Query.Level.REFS, false).getRefs()) {
                 devices.addAll(getDevices(r));
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index 5cef8a8..bfa52e7 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -1,3 +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.
+ */
 package org.apache.usergrid.services.notifications;
 
 import org.apache.usergrid.persistence.*;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
index a0dc60c..ca3cf7a 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/NotifiersServiceIT.java
@@ -1,3 +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.
+ */
 package org.apache.usergrid.services.notifications;
 
 import org.apache.commons.io.IOUtils;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
index 84b0125..8c26ef4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/MockSuccessfulProviderAdapter.java
@@ -1,3 +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.
+ */
 package org.apache.usergrid.services.notifications.apns;
 
 import org.apache.usergrid.persistence.entities.Notification;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index fd00d39..0f89b21 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.services.notifications.apns;
 
 import com.relayrides.pushy.apns.*;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
index 656beae..4c258fe 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/MockSuccessfulProviderAdapter.java
@@ -1,3 +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.
+ */
 package org.apache.usergrid.services.notifications.gcm;
 
 import org.apache.usergrid.persistence.entities.Notification;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9d4b70e4/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 989c2ce..937b53d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -1,18 +1,19 @@
-/*******************************************************************************
- * Copyright 2012 Apigee Corporation
+/*
+ * 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
  *
- * Licensed 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
+ *      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.usergrid.services.notifications.gcm;
 
 import org.apache.usergrid.services.notifications.AbstractServiceNotificationIT;


[24/33] git commit: Fixed queries in tests

Posted by sn...@apache.org.
Fixed queries in tests


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/646b98c0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/646b98c0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/646b98c0

Branch: refs/heads/two-dot-o
Commit: 646b98c0e20571784d048251fc3347fa8ef18798
Parents: 8a20936
Author: grey <gr...@apigee.com>
Authored: Sat Aug 30 13:52:45 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Sat Aug 30 13:52:45 2014 -0700

----------------------------------------------------------------------
 .../apns/NotificationsServiceIT.java            | 34 ++++++++++++--------
 1 file changed, 20 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/646b98c0/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index ed15eeb..cba47c4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -225,26 +225,31 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         ns.addDevice(notification, device);
 
         // verify Query for CREATED state
-        Query query = new Query();
-        query.addEqualityFilter("state", Notification.State.STARTED.toString());
+        Query query = Query.fromQL("select * where type = 'notification'");
+//        Query query = new Query();
+//        query.addEqualityFilter("state", Notification.State.STARTED.toString());
         Results results = app.getEm().searchCollection(
                 app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
+        Notification note = (Notification) results.getEntitiesMap().get(notification.getUuid());
+        assertEquals(Notification.State.STARTED,note.getState());
 
         // perform push //
 
         ns.getQueueManager().processBatchAndReschedule(notification, null);
 
+        //app.getEm().refreshIndex();
         // verify Query for FINISHED state
-        query = new Query();
-        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
+        query = Query.fromQL("select * where type = 'notification'");
+
+//        query = new Query();
+//        query.addEqualityFilter("state", Notification.State.FINISHED.toString());
         results = app.getEm().searchCollection(app.getEm().getApplicationRef(),
                 "notifications", query);
-        entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
 
-        notification = (Notification) entity.toTypedEntity();
+        note = (Notification) results.getEntitiesMap().get(notification.getUuid());
+        assertEquals(Notification.State.FINISHED,note.getState());
+
+        notification = note;
         checkReceipts(notification, 0);
         checkStatistics(notification, 0, 0);
     }
@@ -277,13 +282,14 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Thread.sleep(500);
 
         // verify Query for SCHEDULED state
-        Query query = new Query();
-        query.addEqualityFilter("state",
-                Notification.State.SCHEDULED.toString());
+        Query query = Query.fromQL("select * where type = 'notification'");
+//        Query query = new Query();
+//        query.addEqualityFilter("state",
+//                Notification.State.SCHEDULED.toString());
         Results results = app.getEm().searchCollection(
                 app.getEm().getApplicationRef(), "notifications", query);
-        Entity entity = results.getEntitiesMap().get(notification.getUuid());
-        assertNotNull(entity);
+        Notification note = (Notification)results.getEntitiesMap().get(notification.getUuid());
+        assertNotNull(note);
 
         try {
             e = app.testRequest(ServiceAction.DELETE, 1, "notifications",