You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/06/09 18:16:43 UTC

[3/6] incubator-usergrid git commit: refactor refresh for a single index

refactor refresh for a single index


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

Branch: refs/heads/USERGRID-652
Commit: 9af1637ea3bbe69ec8b6449a4d83ca5bb9e0b88b
Parents: d936cf3
Author: Shawn Feldman <sf...@apache.org>
Authored: Mon Jun 8 17:39:08 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Mon Jun 8 17:39:08 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManagerFactory.java | 39 +-------
 .../index/ApplicationIndexLocationStrategy.java | 18 ++++
 .../index/ManagementIndexLocationStrategy.java  | 23 ++++-
 .../persistence/EntityManagerFactory.java       | 15 +--
 .../org/apache/usergrid/CoreApplication.java    |  2 +-
 .../org/apache/usergrid/CoreITSetupImpl.java    |  5 +-
 .../org/apache/usergrid/TestEntityIndex.java    |  4 +-
 .../index/AsyncIndexServiceTest.java            |  8 +-
 .../corepersistence/index/IndexNamingTest.java  |  4 +-
 .../persistence/query/IteratingQueryIT.java     |  1 +
 .../usergrid/persistence/index/IndexFig.java    |  2 +-
 .../index/impl/EsEntityIndexImpl.java           |  7 +-
 .../persistence/index/impl/EntityIndexTest.java |  2 -
 .../org/apache/usergrid/ServiceApplication.java | 16 ++--
 .../org/apache/usergrid/ServiceITSetup.java     |  3 +-
 .../org/apache/usergrid/ServiceITSetupImpl.java |  6 +-
 .../migration/AppInfoMigrationPluginTest.java   |  6 +-
 .../apache/usergrid/management/EmailFlowIT.java | 10 +-
 .../usergrid/management/OrganizationIT.java     |  9 +-
 .../org/apache/usergrid/management/RoleIT.java  |  4 +-
 .../cassandra/ApplicationCreatorIT.java         |  2 +-
 .../cassandra/ManagementServiceIT.java          | 22 ++---
 .../management/export/ExportServiceIT.java      | 12 +--
 .../management/importer/ImportCollectionIT.java | 10 +-
 .../usergrid/services/ConnectionsServiceIT.java |  4 +-
 .../usergrid/services/GroupServiceIT.java       |  4 +-
 .../usergrid/services/RolesServiceIT.java       |  2 +-
 .../usergrid/services/UsersServiceIT.java       |  2 +-
 .../apns/NotificationsServiceIT.java            | 99 ++++----------------
 .../gcm/NotificationsServiceIT.java             |  4 +-
 30 files changed, 141 insertions(+), 204 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
index 549426e..6ce17f0 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManagerFactory.java
@@ -91,9 +91,7 @@ import static org.apache.usergrid.persistence.Schema.TYPE_APPLICATION;
 public class CpEntityManagerFactory implements EntityManagerFactory, ApplicationContextAware {
 
     private static final Logger logger = LoggerFactory.getLogger( CpEntityManagerFactory.class );
-    private final EntityIndexFactory entityIndexFactory;
     private final EntityManagerFig entityManagerFig;
-    private final IndexLocationStrategyFactory indexLocationFactory;
 
     private ApplicationContext applicationContext;
 
@@ -128,7 +126,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.injector = injector;
         this.reIndexService = injector.getInstance(ReIndexService.class);
         this.entityManagerFig = injector.getInstance(EntityManagerFig.class);
-        this.entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
         this.managerCache = injector.getInstance( ManagerCache.class );
         this.metricsFactory = injector.getInstance( MetricsFactory.class );
         this.indexService = injector.getInstance( AsyncEventService.class );
@@ -136,8 +133,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         this.graphManagerFactory = injector.getInstance( GraphManagerFactory.class );
         this.applicationIdCache = injector.getInstance(ApplicationIdCacheFactory.class).getInstance(
             getManagementEntityManager() );
-        this.indexLocationFactory = injector.getInstance(IndexLocationStrategyFactory.class);
-
 
     }
 
@@ -262,7 +257,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
         EntityManager appEm = getEntityManager(applicationId);
         appEm.create(applicationId, TYPE_APPLICATION, properties);
         appEm.resetRoles();
-     //   entityIndex.refreshAsync();//.toBlocking().last();
 
 
         // create application info entity in the management app
@@ -666,19 +660,8 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     /**
      * TODO, these 3 methods are super janky.  During refactoring we should clean this model up
      */
-    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes() {
-
-        try {
-            final Map<String, UUID> applications = getApplications();
-
-            Observable<IndexRefreshCommand.IndexRefreshCommandInfo> appRefreshes =
-                Observable.merge( Observable.from(applications.values()),Observable.just(getManagementAppId()))
-                .map((UUID appId) -> getEntityManager(appId).refreshIndex());
-
-            return appRefreshes.toList().toBlocking().last();
-        }catch (Exception e){
-            throw new RuntimeException(e);
-        }
+    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex(UUID applicationId) {
+        return getEntityManager(applicationId).refreshIndex();
     }
 
 
@@ -719,24 +702,6 @@ public class CpEntityManagerFactory implements EntityManagerFactory, Application
     }
 
 
-    @Override
-    public UUID createApplication(String organizationName, String name) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
-
-    @Override
-    public UUID createApplication(
-        String organizationName, String name, Map<String, Object> properties) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
-    @Override
-    public UUID initializeApplication(
-        String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception {
-        throw new UnsupportedOperationException("Not supported in v2");
-    }
-
 
     @Override
     public Health getIndexHealth() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
index 4c5d7a5..cad7e10 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ApplicationIndexLocationStrategy.java
@@ -92,4 +92,22 @@ class ApplicationIndexLocationStrategy implements IndexLocationStrategy {
         return applicationScope;
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ApplicationIndexLocationStrategy that = (ApplicationIndexLocationStrategy) o;
+
+        if (!applicationScope.equals(that.applicationScope)) return false;
+        return prefix.equals(that.prefix);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = applicationScope.hashCode();
+        result = 31 * result + prefix.hashCode();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
index 969da1c..5dbaa54 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/index/ManagementIndexLocationStrategy.java
@@ -40,9 +40,8 @@ class ManagementIndexLocationStrategy implements IndexLocationStrategy {
         this.indexFig = indexFig;
         this.managementAppId = CpNamingUtils.getManagementApplicationId();
         //remove usergrid
-        this.prefix = StringUtils.isNotEmpty(indexFig.getIndexPrefix())
-            ? indexFig.getIndexPrefix().toLowerCase() + "_" + indexFig.getManagementAppIndexName()  ////use lowercase value
-             :indexFig.getManagementAppIndexName() ;
+        this.prefix = indexFig.getManagementAppIndexName().toLowerCase();  ////use lowercase value
+
 
     }
     @Override
@@ -64,4 +63,22 @@ class ManagementIndexLocationStrategy implements IndexLocationStrategy {
         return new ApplicationScopeImpl(managementAppId);
     }
 
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        ManagementIndexLocationStrategy that = (ManagementIndexLocationStrategy) o;
+
+        if (!managementAppId.equals(that.managementAppId)) return false;
+        return prefix.equals(that.prefix);
+
+    }
+
+    @Override
+    public int hashCode() {
+        int result = managementAppId.hashCode();
+        result = 31 * result + prefix.hashCode();
+        return result;
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
index 6e77e6e..1ae2377 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/EntityManagerFactory.java
@@ -65,9 +65,6 @@ public interface EntityManagerFactory {
          */
     Entity createApplicationV2( String organizationName, String name ) throws Exception;
 
-    @Deprecated
-    UUID createApplication( String organizationName, String name ) throws Exception;
-
     /**
      * Creates a Application entity. All entities except for applications must be attached to a
      * Application.
@@ -82,9 +79,6 @@ public interface EntityManagerFactory {
     Entity createApplicationV2(
         String organizationName, String name, Map<String, Object> properties ) throws Exception;
 
-    @Deprecated
-    UUID createApplication(
-        String organizationName, String name, Map<String, Object> properties ) throws Exception;
 
     /**
      * Delete Application.
@@ -158,14 +152,11 @@ public interface EntityManagerFactory {
     public Entity initializeApplicationV2(
         String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
 
-    @Deprecated
-    public UUID initializeApplication(
-        String orgName, UUID appId, String appName, Map<String, Object> props) throws Exception;
 
-    public UUID getManagementAppId();
 
-    public List<IndexRefreshCommand.IndexRefreshCommandInfo> refreshIndexes();
+    public UUID getManagementAppId();
 
+    public IndexRefreshCommand.IndexRefreshCommandInfo refreshIndex(UUID applicationId);
 
     /**
      * Perform a realtime count of every entity in the system.  This can be slow as it traverses the entire system graph
@@ -184,7 +175,7 @@ public interface EntityManagerFactory {
 
     public interface ProgressObserver {
 
-     public void onProgress( EntityRef entity);
+        public void onProgress(EntityRef entity);
 
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
index e85077f..f431a93 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -232,7 +232,7 @@ public class CoreApplication implements Application, TestRule {
     @Override
     public synchronized void refreshIndex() {
         //Insert test entity and find it
-        setup.getEmf().refreshIndexes();
+        setup.getEmf().refreshIndex(em.getApplicationId());
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
index 3688934..3b01d3c 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreITSetupImpl.java
@@ -148,14 +148,13 @@ public class CoreITSetupImpl implements CoreITSetup, TestEntityIndex {
     }
 
     @Override
-    public void refresh(){
+    public void refresh(UUID appId){
         try {
             Thread.sleep(50);
         } catch (InterruptedException ie){
 
         }
-
-        emf.refreshIndexes();
+        emf.refreshIndex(appId);
 
         try {
             Thread.sleep(50);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java b/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
index cdbae3f..7da187a 100644
--- a/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
+++ b/stack/core/src/test/java/org/apache/usergrid/TestEntityIndex.java
@@ -19,9 +19,11 @@
  */
 package org.apache.usergrid;
 
+import java.util.UUID;
+
 /**
  * abstract refresh implementation
  */
 public interface TestEntityIndex {
-    void refresh();
+    void refresh(UUID appId);
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
index 7096a4b..17c012e 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/AsyncIndexServiceTest.java
@@ -23,6 +23,7 @@ package org.apache.usergrid.corepersistence.index;
 import java.util.List;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.EntityManagerFactory;
 import org.apache.usergrid.persistence.index.*;
 import org.junit.Before;
 import org.junit.Rule;
@@ -81,12 +82,13 @@ public abstract class AsyncIndexServiceTest {
     @Inject
     public EntityIndexFactory entityIndexFactory;
 
-    @Inject
-    public EntityIndex entityIndex;
 
     @Inject
     public IndexLocationStrategyFactory indexLocationStrategyFactory;
 
+    @Inject
+    public EntityManagerFactory emf;
+
 
     private AsyncEventService asyncEventService;
 
@@ -143,7 +145,7 @@ public abstract class AsyncIndexServiceTest {
 
         asyncEventService.queueEntityIndexUpdate( applicationScope, testEntity );
 
-        entityIndex.refreshAsync().toBlocking().last();
+        emf.refreshIndex(applicationScope.getApplication().getUuid());
 
         //        Thread.sleep( 1000000000000l );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
index e3b1d3f..893359e 100644
--- a/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
+++ b/stack/core/src/test/java/org/apache/usergrid/corepersistence/index/IndexNamingTest.java
@@ -71,13 +71,13 @@ public class IndexNamingTest {
     @Test
     public void managementNaming(){
         IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(managementApplicationScope);
-        assertTrue(indexLocationStrategy.getIndex(null) == managementLocationStrategy.getIndex(null));
+        assertTrue(indexLocationStrategy.getIndex(null).equals(managementLocationStrategy.getIndex(null)));
 
     }
     @Test
     public void applicationNaming(){
         IndexLocationStrategy indexLocationStrategy = indexLocationStrategyFactory.getIndexLocationStrategy(applicationScope);
-        assertTrue(indexLocationStrategy.getIndex(null) == applicationLocationStrategy.getIndex(null));
+        assertTrue(indexLocationStrategy.getIndex(null).equals(applicationLocationStrategy.getIndex(null)));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
index c4a16b6..d882f78 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/query/IteratingQueryIT.java
@@ -438,6 +438,7 @@ public class IteratingQueryIT {
             }
         }
 
+        this.app.refreshIndex();
         long stop = System.currentTimeMillis();
 
         LOG.info( "Writes took {} ms", stop - start );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
index 651dc68..5c61928 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/IndexFig.java
@@ -199,7 +199,7 @@ public interface IndexFig extends GuicyFig {
     @Key( ELASTICSEARCH_WRITE_TIMEOUT )
     long getWriteTimeout();
 
-    @Default( "management" )
+    @Default( "usergrid_management" )
     @Key( "elasticsearch.managment_index" )
     String getManagementAppIndexName();
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
index 9b39069..1fd20e9 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexImpl.java
@@ -262,11 +262,12 @@ public class EsEntityIndexImpl implements AliasedEntityIndex,VersionedData {
             }
             aliasesRequestBuilder = adminClient.indices().prepareAliases();
             //Added For Graphite Metrics
-            // add read alias
-            aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());
-            //Added For Graphite Metrics
             //add write alias
             aliasesRequestBuilder.addAlias(indexName, alias.getWriteAlias());
+            //Added For Graphite Metrics
+            // add read alias
+            aliasesRequestBuilder.addAlias(indexName, alias.getReadAlias());
+
             isAck = aliasesRequestBuilder.execute().actionGet().isAcknowledged();
             logger.info("Created new read and write aliases ACK=[{}]", isAck);
             aliasCache.invalidate(alias);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
index bbd248e..55b61ac 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityIndexTest.java
@@ -96,8 +96,6 @@ public class EntityIndexTest extends BaseIT {
 
         IndexLocationStrategy strategy =  new TestIndexIdentifier(cassandraFig,fig,new ApplicationScopeImpl(appId));
 
-
-
         entityIndex = eif.createEntityIndex( strategy );
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
index 801a640..2c34deb 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
@@ -105,7 +105,7 @@ public class ServiceApplication extends CoreApplication {
         dumpResults( results );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(this.id);
         }
 
         return results;
@@ -131,14 +131,14 @@ public class ServiceApplication extends CoreApplication {
         put( "name", name );
 
         Entity entity = testRequest( ServiceAction.POST, 1, pluralize( entityType ) ).getEntity();
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
         return entity;
     }
 
 
     public void createConnection( Entity subject, String verb, Entity noun ) throws Exception {
         sm.getEntityManager().createConnection( subject, verb, noun );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 
@@ -153,7 +153,7 @@ public class ServiceApplication extends CoreApplication {
         dumpResults( results );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(id);
         }
 
         return results;
@@ -169,7 +169,7 @@ public class ServiceApplication extends CoreApplication {
         assertNotNull( results.getData() );
 
         if ( !action.name().equals( ServiceAction.GET )) {
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(id);
         }
 
         // dump( results.getData() );
@@ -179,20 +179,20 @@ public class ServiceApplication extends CoreApplication {
 
     public Entity createRole( String name, String title, int inactivity ) throws Exception {
         Entity createRole = sm.getEntityManager().createRole( name, title, inactivity );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
         return createRole;
     }
 
 
     public void grantRolePermission( String role, String permission ) throws Exception {
         sm.getEntityManager().grantRolePermission( role, permission );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 
     public void grantUserPermission( UUID uuid, String permission ) throws Exception {
         sm.getEntityManager().grantUserPermission( uuid, permission );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(id);
     }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
index 07a6fe5..e9bb248 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetup.java
@@ -27,6 +27,7 @@ import org.apache.usergrid.security.tokens.TokenService;
 import org.apache.usergrid.services.ServiceManagerFactory;
 
 import java.util.Properties;
+import java.util.UUID;
 
 
 public interface ServiceITSetup extends CoreITSetup {
@@ -44,7 +45,7 @@ public interface ServiceITSetup extends CoreITSetup {
 
     ImportService getImportService();
 
-    void refreshIndex();
+    void refreshIndex(UUID appid);
 
     /**
      * Convenience method to set a property in the Properties object returned by getProps();

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
index 8ae5322..c17ee92 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceITSetupImpl.java
@@ -43,6 +43,7 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.config.PropertiesFactoryBean;
 
 import java.util.Properties;
+import java.util.UUID;
 
 
 /** A {@link org.junit.rules.TestRule} that sets up services. */
@@ -180,8 +181,7 @@ public class ServiceITSetupImpl extends CoreITSetupImpl implements ServiceITSetu
         return appInfoMigrationPlugin;
     }
 
-    @Override
-    public void refreshIndex(){
-        this.getEntityIndex().refresh();
+    public void refreshIndex(UUID appid){
+        this.getEntityIndex().refresh(appid);
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
index 9c8f40f..0fd1e52 100644
--- a/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
+++ b/stack/services/src/test/java/org/apache/usergrid/corepersistence/migration/AppInfoMigrationPluginTest.java
@@ -101,9 +101,9 @@ public class AppInfoMigrationPluginTest {
             }
         }
 
-        setup.refreshIndex();
 
         UUID mgmtAppId = setup.getEmf().getManagementAppId();
+        setup.refreshIndex(mgmtAppId);
         EntityManager rootEm = setup.getEmf().getEntityManager( mgmtAppId );
 
         checkApplicationsOk( orgName );
@@ -143,7 +143,7 @@ public class AppInfoMigrationPluginTest {
             }
         }
 
-        setup.refreshIndex();
+        setup.refreshIndex(mgmtAppId);
 
         setup.getEmf().flushEntityManagerCaches();
 
@@ -165,7 +165,7 @@ public class AppInfoMigrationPluginTest {
         // test that expected calls were made the to progress observer (use mock library)
 
         Mockito.verify( po, Mockito.times(10) ).update( Mockito.anyInt(), Mockito.anyString() );
-        setup.refreshIndex();
+        setup.refreshIndex(mgmtAppId);
 
         final Results appInfoResults = rootEm.searchCollection(
             new SimpleEntityRef("application", mgmtAppId), "appinfos", Query.fromQL("select *"));

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
index b158568..d75638d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/EmailFlowIT.java
@@ -285,7 +285,7 @@ public class EmailFlowIT {
         String activation_url = String.format( setup.get( PROPERTIES_USER_ACTIVATION_URL ), orgName, appName,
             appUser.getUuid().toString() );
 
-        setup.refreshIndex();
+        setup.refreshIndex(app.getId());
 
         // Activation
         setup.getMgmtSvc().startAppUserActivationFlow( app.getId(), appUser );
@@ -358,15 +358,15 @@ public class EmailFlowIT {
         orgOwner = createOwnerAndOrganization( orgName, appName, userName, email, passwd, false, false );
         assertNotNull( orgOwner );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         ApplicationInfo app = setup.getMgmtSvc().createApplication( orgOwner.getOrganization().getUuid(), appName );
-        setup.refreshIndex();
+        setup.refreshIndex(app.getId());
         assertNotNull( app );
         enableEmailConfirmation( app.getId() );
         enableAdminApproval( app.getId() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         final String appUserEmail = uniqueEmail();
         final String appUserUsername = uniqueUsername();
@@ -470,7 +470,7 @@ public class EmailFlowIT {
         userProps.put( "activated", activated );
 
         User user = em.create( User.ENTITY_TYPE, User.class, userProps );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         return user;
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
index 3c93fa3..e0561a2 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/OrganizationIT.java
@@ -22,6 +22,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.UUID;
 
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
@@ -70,7 +71,7 @@ public class OrganizationIT {
         //createOrganization( orgName, user, false );
         assertNotNull( organization );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         Map<UUID, String> userOrganizations = setup.getMgmtSvc().getOrganizationsForAdminUser(
             organization.getOwner().getUuid() );
         assertEquals("wrong number of organizations", 1, userOrganizations.size());
@@ -83,7 +84,7 @@ public class OrganizationIT {
         assertNotNull(applicationInfo.getId());
 
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationInfo.getId());
 
         Map<UUID, String> applications = setup.getMgmtSvc().getApplicationsForOrganization( organization.getOrganization().getUuid() );
         assertEquals( "wrong number of applications", 1, applications.size() );
@@ -97,7 +98,7 @@ public class OrganizationIT {
 
         setup.getMgmtSvc().activateOrganization( organization2 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
 
         UserInfo u = setup.getMgmtSvc().verifyAdminUserPasswordCredentials( organization.getOwner().getUuid().toString(), "test" );
         assertNotNull( u );
@@ -215,7 +216,7 @@ public class OrganizationIT {
         OrganizationInfo organization2 = setup.getMgmtSvc().createOrganization(uniqueOrg(), user, false );
         assertNotNull( organization2 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(CpNamingUtils.MANAGEMENT_APPLICATION_ID);
         Map<UUID, String> userOrganizations = setup.getMgmtSvc().getOrganizationsForAdminUser( user.getUuid() );
         assertEquals( "wrong number of organizations", 2, userOrganizations.size() );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
index 64109b2..783e67c 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
@@ -66,7 +66,7 @@ public class RoleIT {
         UUID applicationId = setup.getMgmtSvc().createApplication( organization.getUuid(), "test-app" ).getId();
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
         Map<String, Object> properties = new LinkedHashMap<String, Object>();
         properties.put( "username", "edanuff5" );
@@ -75,7 +75,7 @@ public class RoleIT {
         User user = em.create( User.ENTITY_TYPE, User.class, properties );
 
         em.createRole( "logged-in", "Logged In", 1000 );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
         em.addUserToRole( user.getUuid(), "logged-in" );
 
         String accessToken = setup.getMgmtSvc().getAccessTokenForAppUser( applicationId, user.getUuid(), 0 );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
index 0de8220..fd509c8 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ApplicationCreatorIT.java
@@ -88,7 +88,7 @@ public class ApplicationCreatorIT {
         customCreator.setSampleAppName(sampleAppName);
         ApplicationInfo appInfo = customCreator.createSampleFor( orgOwner.getOrganization() );
         if(appInfo == null){
-            setup.refreshIndex();
+            setup.refreshIndex(setup.getEmf().getManagementAppId());
         }
         assertNotNull( appInfo );
         assertEquals( expectedName, appInfo.getName() );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
index 884bfec..196400f 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/cassandra/ManagementServiceIT.java
@@ -98,7 +98,7 @@ public class ManagementServiceIT {
         adminUser = orgAppAdminRule.getAdminInfo();
         applicationId = orgAppAdminRule.getApplicationInfo().getId();
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
     }
 
 
@@ -196,7 +196,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().activateAppUser( applicationId, user.getUuid() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         user = em.get( entity.getUuid(), User.class );
 
@@ -492,7 +492,7 @@ public class ManagementServiceIT {
                                           false, false );
 
         EntityManager em = setup.getEmf().getEntityManager( setup.getSmf().getManagementAppId() );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UserInfo authedUser = setup.getMgmtSvc().verifyAdminUserPasswordCredentials( username, password );
 
@@ -543,7 +543,7 @@ public class ManagementServiceIT {
 
         em.addToDictionary( storedUser, DICTIONARY_CREDENTIALS, "password", info );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
 
         //verify authorization works
@@ -581,7 +581,7 @@ public class ManagementServiceIT {
         EntityManager em = setup.getEmf().getEntityManager( setup.getEmf().getManagementAppId() );
 
         User storedUser = em.create( user );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
 
         UUID userId = storedUser.getUuid();
@@ -650,7 +650,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -667,7 +667,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );
@@ -696,7 +696,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -726,7 +726,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );
@@ -757,7 +757,7 @@ public class ManagementServiceIT {
 
         User storedUser = em.create( user );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         UUID userId = storedUser.getUuid();
 
@@ -794,7 +794,7 @@ public class ManagementServiceIT {
 
         setup.getMgmtSvc().setAppUserPassword( appId, userId, password, newPassword );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //verify authorization works
         authedUser = setup.getMgmtSvc().verifyAppUserPasswordCredentials( appId, username, newPassword );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
index 0e69d21..95e8c7d 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/export/ExportServiceIT.java
@@ -118,7 +118,7 @@ public class ExportServiceIT {
         organization = newOrgAppAdminRule.getOrganizationInfo();
         applicationId = newOrgAppAdminRule.getApplicationInfo().getId();
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
     }
 
 
@@ -272,7 +272,7 @@ public class ExportServiceIT {
 
             entity[i] = em.create( "users", userProperties );
         }
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
         //creates connections
         em.createConnection( em.get( new SimpleEntityRef( "user", entity[0].getUuid() ) ), "Vibrations",
             em.get( new SimpleEntityRef( "user", entity[1].getUuid() ) ) );
@@ -506,7 +506,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-       setup.getEntityIndex().refresh();
+       setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 
@@ -577,7 +577,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 
@@ -612,7 +612,7 @@ public class ExportServiceIT {
 
         EntityManager em = setup.getEmf().getEntityManager( applicationId );
         em.createApplicationCollection( "baconators" );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         //initialize user object to be posted
         Map<String, Object> userProperties = null;
@@ -645,7 +645,7 @@ public class ExportServiceIT {
         JobExecution jobExecution = mock( JobExecution.class );
         when( jobExecution.getJobData() ).thenReturn( jobData );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(applicationId);
 
         exportService.doExport( jobExecution );
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
index 4c78a1e..10b6d28 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/importer/ImportCollectionIT.java
@@ -239,7 +239,7 @@ public class ImportCollectionIT {
             for ( Entity importedThing : importedThings ) {
                 emApp1.delete( importedThing );
             }
-            setup.getEntityIndex().refresh();
+            setup.getEntityIndex().refresh(appId2);
 
 
             importedThings = emApp2.getCollection(
@@ -532,7 +532,7 @@ public class ImportCollectionIT {
         if ( retries >= maxRetries ) {
             throw new RuntimeException("Max retries reached");
         }
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         return importEntity.getUuid();
@@ -547,7 +547,7 @@ public class ImportCollectionIT {
 
         logger.debug("\n\nExporting {} collection from application {}\n",
             collectionName, em.getApplication().getName() );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         ExportService exportService = setup.getExportService();
@@ -591,7 +591,7 @@ public class ImportCollectionIT {
         logger.debug("\n\nCreating new {} collection in application {}\n",
             type, em.getApplication().getName());
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
 
         List<Entity> created = new ArrayList<>();
@@ -613,7 +613,7 @@ public class ImportCollectionIT {
         em.createConnection(new SimpleEntityRef(type, created.get(1).getUuid()),
             "related", new SimpleEntityRef(type, created.get(0).getUuid()));
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(em.getApplicationId());
 
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
index 57fadca..a1f19d4 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/ConnectionsServiceIT.java
@@ -99,13 +99,13 @@ public class ConnectionsServiceIT extends AbstractServiceIT {
       Entity bar = app.testRequest( ServiceAction.POST, 1, "bars" ).getEntity();
       assertNotNull( bar );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         //POST users/conn-user1/user2/UUID
       app.testRequest( ServiceAction.POST, 1, "foos", "foo", "bars", bar.getUuid() ); // should succeed
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
index 8fd5da3..d3c2436 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/GroupServiceIT.java
@@ -68,13 +68,13 @@ public class GroupServiceIT extends AbstractServiceIT {
         app.createGroupRole( group.getUuid(), "admin", 0 );
         app.createGroupRole( group.getUuid(), "author", 0 );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         app.grantGroupRolePermission( group.getUuid(), "admin", "users:access:*" );
         app.grantGroupRolePermission( group.getUuid(), "admin", "groups:access:*" );
         app.grantGroupRolePermission( group.getUuid(), "author", "assets:access:*" );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "rolenames" );
         app.testDataRequest( ServiceAction.GET, "groups", group.getUuid(), "roles", "admin", "permissions" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
index a6723b7..8a0560a 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/RolesServiceIT.java
@@ -199,7 +199,7 @@ public class RolesServiceIT extends AbstractServiceIT {
         ServiceResults results = app.invokeService( ServiceAction.DELETE, "roles", "manager" );
         assertEquals( 1, results.size() );
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         // check role is gone
         Role role = app.get( app.getAlias( "role", "manager" ), Role.class );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
index 94271ce..3bb996c 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/UsersServiceIT.java
@@ -37,7 +37,7 @@ public class UsersServiceIT extends AbstractServiceIT {
 
         Entity user = app.create( "user" );
         assertNotNull( user );
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
 
         app.testRequest( ServiceAction.POST, 1, "users", user.getUuid(), "roles", "admin" );

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9af1637e/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 9c2385f..fc80fdf 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
@@ -103,7 +103,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device2 = app.getEntityManager().get(e.getUuid(), Device.class);
         Map<String, Object> props = app.getEntityManager().getProperties(e);
         assertEquals(device2.getProperty(notifierKey), PUSH_TOKEN);
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create User
         user1 = new User();
@@ -121,7 +121,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         DefaultQueueManager qm = new DefaultQueueManager();
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(), new Properties());
         listener.TEST_QUEUE_MANAGER = qm;
@@ -142,7 +142,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         // create push notification //
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
@@ -177,7 +177,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // verify Query for FINISHED state
         query = Query.fromEquals("state", Notification.State.FINISHED.toString());
@@ -282,7 +282,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
                 .getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),
                 Notification.class);
@@ -302,7 +302,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity entity = results.getEntitiesMap().get(notification.getUuid());
         assertNotNull(entity);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         try {
             e = app.testRequest(ServiceAction.DELETE, 1, "notifications",
@@ -463,7 +463,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers")
                 .getEntity();
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         app.testRequest(ServiceAction.GET, 1, "notifiers", "apNs2");
 
@@ -478,7 +478,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device2.setProperty(key2, PUSH_TOKEN);
         app.getEntityManager().update(device2);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create push notification //
 
@@ -494,7 +494,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         e = app.testRequest(ServiceAction.POST, 1, "devices","notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),  Notification.class);
         assertEquals(notification.getPayloads().get(notifierName), payload);
@@ -502,7 +502,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         // perform push //
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 2); //the second notifier isn't associated correctly so its 3 instead of 4
     }
@@ -527,7 +527,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity e = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifiers", nameValue);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notifier notifier2 = app.getEntityManager().get(e.getUuid(), Notifier.class);
         assertEquals(notifier2.getName(), nameValue);
@@ -538,7 +538,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         device1.setProperty(key2, PUSH_TOKEN);
         app.getEntityManager().update(device1);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create push notification //
 
@@ -554,7 +554,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         e = app.testRequest(ServiceAction.POST, 1,"devices",device1.getUuid(), "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         Notification notification = app.getEntityManager().get(e.getUuid(),
                 Notification.class);
@@ -564,12 +564,12 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         ns.addDevice(notification, device1);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // perform push //
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 2);
     }
@@ -711,7 +711,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         assertEquals(user1Devices.size(),2);
         // create push notification //
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
@@ -746,7 +746,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
 
         notification = scheduleNotificationAndWait(notification);
 
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // verify Query for FINISHED state
         query = Query.fromEquals("state", Notification.State.FINISHED.toString());
@@ -775,7 +775,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity entity = app.testRequest(ServiceAction.POST, 1, "notifiers").getEntity();
         Notifier notifier = app.getEntityManager().get(entity.getUuid(), Notifier.class);
         final String notifierKey = notifier.getName() + NOTIFIER_ID_POSTFIX;
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         // create a bunch of devices and add them to the notification
 
@@ -784,7 +784,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
             app.put(notifierKey, PUSH_TOKEN);
             app.put("name", "device"+i*10);
             app.testRequest(ServiceAction.POST, 1, "devices").getEntity();
-                    setup.getEntityIndex().refresh();
+                    setup.getEntityIndex().refresh(app.getId());
 
         }
 
@@ -799,7 +799,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         // create a notification
         entity = app.testRequest(ServiceAction.POST, 1,  "devices","notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", entity.getUuid());
-                setup.getEntityIndex().refresh();
+                setup.getEntityIndex().refresh(app.getId());
 
         final Notification notification = (Notification) entity.toTypedEntity();
 
@@ -823,63 +823,4 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
     }
 
 
-    // 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.getEntityManager().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/9af1637e/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 8dafddd..63869ca 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
@@ -192,13 +192,13 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT {
         Entity e = app.testRequest(ServiceAction.POST, 1,"users",user.getUuid(), "notifications").getEntity();
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         // perform push //
         Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
         notification = scheduleNotificationAndWait(notification);
 
-        setup.getEntityIndex().refresh();
+        setup.getEntityIndex().refresh(app.getId());
 
         checkReceipts(notification, 1);
     }