You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by to...@apache.org on 2015/04/13 19:45:55 UTC
[30/50] incubator-usergrid git commit: refresh issues should be better
refresh issues should be better
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/15db4e88
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/15db4e88
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/15db4e88
Branch: refs/heads/USERGRID-536
Commit: 15db4e88fdd5d445be84579b238abb2b647029f5
Parents: 8856f05
Author: Shawn Feldman <sf...@apache.org>
Authored: Tue Apr 7 14:37:31 2015 -0600
Committer: Shawn Feldman <sf...@apache.org>
Committed: Tue Apr 7 14:37:31 2015 -0600
----------------------------------------------------------------------
.../org/apache/usergrid/CoreApplication.java | 55 ++++++++++++++------
1 file changed, 39 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/15db4e88/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 110e8ac..266388f 100644
--- a/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
+++ b/stack/core/src/test/java/org/apache/usergrid/CoreApplication.java
@@ -17,13 +17,24 @@
package org.apache.usergrid;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import com.google.inject.Injector;
-import org.apache.usergrid.persistence.index.EntityIndex;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
+import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+import org.apache.usergrid.persistence.geo.GeoIndexSearcher;
+import org.apache.usergrid.persistence.index.*;
+import org.apache.usergrid.persistence.index.impl.IndexScopeImpl;
+import org.apache.usergrid.persistence.index.impl.IndexingUtils;
+import org.apache.usergrid.persistence.index.query.CandidateResults;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@@ -31,11 +42,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.usergrid.mq.QueueManager;
-import org.apache.usergrid.persistence.Entity;
-import org.apache.usergrid.persistence.EntityManager;
-import org.apache.usergrid.persistence.EntityRef;
-import org.apache.usergrid.persistence.Results;
-import org.apache.usergrid.persistence.SimpleEntityRef;
import org.apache.usergrid.persistence.index.query.Query;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -52,6 +58,9 @@ public class CoreApplication implements Application, TestRule {
protected EntityManager em;
protected Map<String, Object> properties = new LinkedHashMap<String, Object>();
private EntityIndex entityIndex;
+ private EntityIndexFactory entityIndexFactory;
+ private ApplicationEntityIndex applicationIndex;
+ private EntityManager managementEm;
public CoreApplication( CoreITSetup setup ) {
@@ -165,11 +174,14 @@ public class CoreApplication implements Application, TestRule {
this.orgName = orgName;
this.appName = appName;
id = setup.createApplication( orgName, appName );
- assertNotNull( id );
+ managementEm = setup.getEmf().getEntityManager(setup.getEmf().getManagementAppId());
+ assertNotNull(id);
- em = setup.getEmf().getEntityManager( id );
+ em = setup.getEmf().getEntityManager(id);
Injector injector = setup.getInjector();
entityIndex = injector.getInstance(EntityIndex.class);
+ entityIndexFactory = injector.getInstance(EntityIndexFactory.class);
+ applicationIndex = entityIndexFactory.createApplicationEntityIndex(CpNamingUtils.getApplicationScope(id));
assertNotNull(em);
LOG.info( "Created new application {} in organization {}", appName, orgName );
@@ -216,15 +228,26 @@ public class CoreApplication implements Application, TestRule {
@Override
public synchronized void refreshIndex() {
- try{
- Thread.sleep(50);
- }catch (InterruptedException ie){}
-
- entityIndex.refresh();
+ //Insert test entity and find it
+ String type = "unittests";
+ Id id = new SimpleId(UUID.randomUUID(), type);
+ Map<String, Object> fields = new HashMap<>();
+ fields.put("name", "unit" + id.getUuid());
+ try {
+ Entity find = em.create(id, fields);
+ Query query = new Query().fromQL("name='" + find.getName() + "'");
+ for (int i = 0; i < 20; i++) {
+ Results results = em.searchCollection(em.getApplicationRef(), type, query);
+ if (results.size() > 0) {
+ break;
+ }
+ entityIndex.refresh();
+ Thread.sleep(200);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
- try{
- Thread.sleep(100);
- }catch (InterruptedException ie){}
}