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/03/07 23:21:08 UTC
[3/4] git commit: Better stress test for EntityManagerFacade.
Better stress test for EntityManagerFacade.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/e89b3435
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/e89b3435
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/e89b3435
Branch: refs/heads/two-dot-o
Commit: e89b34354ce9a694ba7253ccd1ce761447335380
Parents: a59ced6
Author: Dave Johnson <dm...@apigee.com>
Authored: Fri Mar 7 16:27:59 2014 -0500
Committer: Dave Johnson <dm...@apigee.com>
Committed: Fri Mar 7 16:27:59 2014 -0500
----------------------------------------------------------------------
.../collection/EntityCollectionManagerST.java | 89 ----------------
.../EntityCollectionManagerStressTest.java | 104 +++++++++++++++++++
stack/corepersistence/queryindex/README.md | 4 +-
.../index/EntityCollectionIndex.java | 5 +
.../index/impl/EsEntityCollectionIndex.java | 6 +-
.../persistence/index/impl/CollectionIT.java | 6 +-
.../impl/EntityCollectionIndexStressTest.java | 75 ++++++++++---
.../usergrid/persistence/index/impl/GeoIT.java | 27 ++---
.../persistence/index/impl/IndexIT.java | 13 +--
.../index/legacy/EntityManagerFacade.java | 50 +++++++--
10 files changed, 237 insertions(+), 142 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
deleted file mode 100644
index e989942..0000000
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerST.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. 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. For additional information regarding
- * copyright in this work, please see the NOTICE file in the top level
- * directory of this distribution.
- */
-package org.apache.usergrid.persistence.collection;
-
-import com.google.inject.Inject;
-import org.apache.commons.lang3.time.StopWatch;
-import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
-import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
-import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
-import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.model.entity.Entity;
-import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.jukito.JukitoRunner;
-import org.jukito.UseModules;
-import static org.junit.Assert.assertNotNull;
-import org.junit.ClassRule;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import rx.Observable;
-
-
-@RunWith(JukitoRunner.class)
-@UseModules(TestCollectionModule.class)
-public class EntityCollectionManagerST {
- private static final Logger log = LoggerFactory.getLogger( EntityCollectionManagerST.class );
-
- @Inject
- private EntityCollectionManagerFactory factory;
-
- @ClassRule
- public static CassandraRule rule = new CassandraRule();
-
- @Inject
- @Rule
- public MigrationManagerRule migrationManagerRule;
-
- @Test
- public void writeThousands() {
-
- CollectionScope context = new CollectionScopeImpl(
- new SimpleId("organization"), new SimpleId("test"), "test");
-
- EntityCollectionManager manager = factory.createCollectionManager(context);
-
- int limit = 10000;
-
- StopWatch timer = new StopWatch();
- timer.start();
-
- for (int i = 0; i < limit; i++) {
-
- Entity newEntity = new Entity(new SimpleId("test"));
- Observable<Entity> observable = manager.write(newEntity);
- Entity returned = observable.toBlockingObservable().lastOrDefault(null);
- assertNotNull("Returned has a id", returned.getId());
- assertNotNull("Returned has a version", returned.getVersion());
-
- Entity fetched = manager.load( returned.getId() ).toBlockingObservable().last();
- assertNotNull("Returned has a id", fetched.getId());
- assertNotNull("Returned has a version", fetched.getVersion());
-
- if ( i % 1000 == 0 ) {
- log.info(" Wrote: " + i);
- }
- }
-
- timer.stop();
- log.info( "Total time to write {} entries {}ms, average {}ms/entry",
- limit, timer.getTime(), timer.getTime() / limit );
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java
new file mode 100644
index 0000000..426a3ff
--- /dev/null
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/EntityCollectionManagerStressTest.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.collection;
+
+import com.google.inject.Inject;
+import java.util.HashSet;
+import java.util.Set;
+import org.apache.commons.lang3.time.StopWatch;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
+import org.apache.usergrid.persistence.collection.guice.TestCollectionModule;
+import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
+import org.apache.usergrid.persistence.model.entity.Entity;
+import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.apache.usergrid.persistence.model.field.LocationField;
+import org.apache.usergrid.persistence.model.field.StringField;
+import org.apache.usergrid.persistence.model.field.value.Location;
+import org.jukito.JukitoRunner;
+import org.jukito.UseModules;
+import static org.junit.Assert.assertNotNull;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+@RunWith(JukitoRunner.class)
+@UseModules(TestCollectionModule.class)
+public class EntityCollectionManagerStressTest {
+ private static final Logger log = LoggerFactory.getLogger(
+ EntityCollectionManagerStressTest.class );
+
+ @Inject
+ private EntityCollectionManagerFactory factory;
+
+ @ClassRule
+ public static CassandraRule rule = new CassandraRule();
+
+ @Inject
+ @Rule
+ public MigrationManagerRule migrationManagerRule;
+
+ @Test
+ public void writeThousands() {
+
+ CollectionScope context = new CollectionScopeImpl(
+ new SimpleId("organization"), new SimpleId("test"), "test");
+
+ EntityCollectionManager manager = factory.createCollectionManager(context);
+
+ int limit = 10000;
+
+ StopWatch timer = new StopWatch();
+ timer.start();
+ Set<Id> ids = new HashSet<Id>();
+ for (int i = 0; i < limit; i++) {
+
+ Entity newEntity = new Entity(new SimpleId("test"));
+ newEntity.setField(new StringField("name", String.valueOf(i)));
+ newEntity.setField(new LocationField("location", new Location(120,40)));
+
+ Entity returned = manager.write(newEntity).toBlockingObservable().last();
+
+ assertNotNull("Returned has a id", returned.getId());
+ assertNotNull("Returned has a version", returned.getVersion());
+
+ ids.add(returned.getId());
+
+ if ( i % 1000 == 0 ) {
+ log.info(" Wrote: " + i);
+ }
+ }
+ timer.stop();
+ log.info( "Total time to write {} entries {}ms", limit, timer.getTime());
+ timer.reset();
+
+ timer.start();
+ for ( Id id : ids ) {
+ Entity entity = manager.load( id ).toBlockingObservable().last();
+ assertNotNull("Returned has a id", entity.getId());
+ assertNotNull("Returned has a version", entity.getVersion());
+ }
+ timer.stop();
+ log.info( "Total time to read {} entries {}ms", limit, timer.getTime());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/README.md
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/README.md b/stack/corepersistence/queryindex/README.md
index 018eef8..769bda1 100644
--- a/stack/corepersistence/queryindex/README.md
+++ b/stack/corepersistence/queryindex/README.md
@@ -53,7 +53,7 @@ Issues and work remaining
__Work remaining:__
-- Figure out why some tests are running out of memory and hanging the build
+- Figure out why some GeoIT tests cause subsequent tests to fail
- Create CHOP-style test cases to stress system
@@ -63,4 +63,4 @@ __Work remaining:__
- Use Entity Validation utils from Collection instead of my own checks
-- Use mutli-get for fetching entities for results
+- Use muli-get for fetching entities for results
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
index f8194cd..7cf318b 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityCollectionIndex.java
@@ -54,4 +54,9 @@ public interface EntityCollectionIndex {
* Execute query in Usergrid syntax.
*/
public Results execute( Query query );
+
+ /**
+ * Force refresh of index.
+ */
+ public void refresh();
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
index 17eb1d1..443c1cc 100644
--- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
+++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityCollectionIndex.java
@@ -116,7 +116,6 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
this.cursorTimeout = config.getQueryCursorTimeout();
// if new index then create it
- // TODO: should we allow (optional) authentication here? Consensus: no.
AdminClient admin = client.admin();
if (!admin.indices().exists(
new IndicesExistsRequest(indexName)).actionGet().isExists()) {
@@ -475,4 +474,9 @@ public class EsEntityCollectionIndex implements EntityCollectionIndex {
return builder;
}
+ @Override
+ public void refresh() {
+ client.admin().indices().prepareRefresh( indexName ).execute().actionGet();
+ }
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
index 3a8fc2d..8589452 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CollectionIT.java
@@ -79,10 +79,10 @@ public class CollectionIT {
public CoreApplication app = new CoreApplication( setup );
@Inject
- public EntityCollectionManagerFactory collectionManagerFactory;
+ public EntityCollectionManagerFactory cmf;
@Inject
- public EntityCollectionIndexFactory collectionIndexFactory;
+ public EntityCollectionIndexFactory cif;
private EntityManagerFacade em;
@@ -93,7 +93,7 @@ public class CollectionIT {
Id orgId = new SimpleId("organization");
em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ cmf, cif );
app.setEntityManager( em );
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
index 48a9bbf..62cf7da 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityCollectionIndexStressTest.java
@@ -19,21 +19,28 @@ package org.apache.usergrid.persistence.index.impl;
import com.google.inject.Inject;
import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.time.StopWatch;
import org.apache.usergrid.persistence.collection.CollectionScope;
+import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory;
+import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
+import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
import org.apache.usergrid.persistence.collection.impl.CollectionScopeImpl;
-import org.apache.usergrid.persistence.collection.util.EntityUtils;
-import org.apache.usergrid.persistence.index.EntityCollectionIndex;
import org.apache.usergrid.persistence.index.EntityCollectionIndexFactory;
import org.apache.usergrid.persistence.index.guice.TestIndexModule;
+import org.apache.usergrid.persistence.index.legacy.EntityManagerFacade;
import org.apache.usergrid.persistence.model.entity.Entity;
import org.apache.usergrid.persistence.model.entity.Id;
import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
+import org.apache.usergrid.persistence.query.Query;
+import org.apache.usergrid.persistence.query.Results;
import org.jukito.JukitoRunner;
import org.jukito.UseModules;
+import static org.junit.Assert.assertNotNull;
+import org.junit.ClassRule;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
@@ -43,36 +50,70 @@ import org.slf4j.LoggerFactory;
@RunWith(JukitoRunner.class)
@UseModules(TestIndexModule.class)
public class EntityCollectionIndexStressTest {
- private static final Logger log = LoggerFactory.getLogger( EntityCollectionIndexStressTest.class );
+
+ private static final Logger log = LoggerFactory.getLogger(
+ EntityCollectionIndexStressTest.class );
+
+ @ClassRule
+ public static CassandraRule cass = new CassandraRule();
+
+ @Inject
+ @Rule
+ public MigrationManagerRule migrationManagerRule;
@Inject
- public EntityCollectionIndexFactory collectionIndexFactory;
+ public EntityCollectionManagerFactory cmf;
+
+ @Inject
+ public EntityCollectionIndexFactory cif;
@Test
public void indexThousands() throws IOException {
Id appId = new SimpleId("application");
Id orgId = new SimpleId("organization");
- CollectionScope scope = new CollectionScopeImpl( appId, orgId, "contacts" );
- EntityCollectionIndex index = collectionIndexFactory.createCollectionIndex( scope );
+ CollectionScope scope = new CollectionScopeImpl( appId, orgId, "characters" );
int limit = 10000;
StopWatch timer = new StopWatch();
timer.start();
- for ( int i = 0; i < limit; i++ ) {
- Entity entity = new Entity(new SimpleId(UUIDGenerator.newTimeUUID(), scope.getName()));
- EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() );
- entity.setField( new StringField( "name", RandomStringUtils.randomAlphabetic(20)) );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
+
+ for ( int i = 1; i <= limit; i++ ) {
+ em.create("character", new LinkedHashMap<String, Object>() {{
+ put( "username", RandomStringUtils.random(20) );
+ put( "email", RandomStringUtils.random(20) );
+ put( "location", new HashMap<String, Object>() {{
+ put("latitude", 140 );
+ put("longitude", 40 );
+ }});
+ }});
+ if ( i % 1000 == 0 ) {
+ log.info(" Wrote and indexed: " + i);
+ }
+ }
+ timer.stop();
+ log.info( "Total time to index {} entries {}ms", limit, timer.getTime() );
+ timer.reset();
+
+ em.refreshIndex();
- index.index( entity );
+ timer.start();
- if ( i % 1000 == 0 ) {
- log.info(" Indexed: " + i);
+ Results results = em.searchCollection(
+ null, "characters", Query.fromQL("location > 10") );
+
+ int count = 0;
+ for ( Entity entity : results.getEntities() ) {
+ assertNotNull("Returned has a id", entity.getId());
+ assertNotNull("Returned has a version", entity.getVersion());
+ count++;
+ if ( count % 1000 == 0 ) {
+ log.info(" Wrote and indexed: " + count);
}
}
timer.stop();
- log.info( "Total time to index {} entries {}ms, average {}ms/entry",
- limit, timer.getTime(), timer.getTime() / limit );
+ log.info( "Total time to query & read {} entries {}ms", count, timer.getTime() );
}
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
index ee2ceca..dafa389 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/GeoIT.java
@@ -77,10 +77,10 @@ public class GeoIT {
public CoreApplication app = new CoreApplication( setup );
@Inject
- public EntityCollectionManagerFactory collectionManagerFactory;
+ public EntityCollectionManagerFactory cmf;
@Inject
- public EntityCollectionIndexFactory collectionIndexFactory;
+ public EntityCollectionIndexFactory cif;
public GeoIT() {
@@ -94,8 +94,7 @@ public class GeoIT {
Id appId = new SimpleId("testGeo");
Id orgId = new SimpleId("testOrganization");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
assertNotNull( em );
// Two intersections two blocks apart
@@ -236,13 +235,13 @@ public class GeoIT {
Id appId = new SimpleId("testGeo");
Id orgId = new SimpleId("testPointPaging");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
assertNotNull( em );
// save objects in a diagonal line from -90 -180 to 90 180
- int numEntities = 500;
+ // TODO: use a larger count here
+ int numEntities = 10;
float minLattitude = -90;
float maxLattitude = 90;
@@ -299,7 +298,7 @@ public class GeoIT {
Id appId = new SimpleId("testGeo");
Id orgId = new SimpleId("testSamePointPaging");
EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ cmf, cif );
assertNotNull( em );
// save objects in a diagonal line from -90 -180 to 90 180
@@ -339,7 +338,7 @@ public class GeoIT {
assertEquals( numEntities, count );
}
-
+
@Ignore
@Test
public void testDistanceByLimit() throws Exception {
@@ -347,7 +346,7 @@ public class GeoIT {
Id appId = new SimpleId("testGeo");
Id orgId = new SimpleId("testDistanceByLimit");
EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ cmf, cif );
assertNotNull( em );
// save objects in a diagonal line from -90 -180 to 90 180
@@ -390,11 +389,13 @@ public class GeoIT {
for ( Entity entity : results.getEntities() ) {
count++;
}
+ query.setCursor( results.getCursor() );
}
while ( query.getCursor() != null );
// check we got back all entities
assertEquals( numEntities, count );
+
}
@@ -404,8 +405,9 @@ public class GeoIT {
Id appId = new SimpleId("testGeo");
Id orgId = new SimpleId("testGeoWithIntersection");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
+
assertNotNull( em );
int size = 100;
@@ -454,6 +456,7 @@ public class GeoIT {
while ( r.hasCursor() );
assertEquals( startDelta - ( size - max ), count );
+
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
index 9e924cc..674aa3a 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/IndexIT.java
@@ -70,10 +70,10 @@ public class IndexIT {
public CoreApplication app = new CoreApplication( setup );
@Inject
- public EntityCollectionManagerFactory collectionManagerFactory;
+ public EntityCollectionManagerFactory cmf;
@Inject
- public EntityCollectionIndexFactory collectionIndexFactory;
+ public EntityCollectionIndexFactory cif;
public static final String[] alphabet = {
"Alpha", "Bravo", "Charlie", "Delta", "Echo", "Foxtrot", "Golf", "Hotel", "India", "Juliet", "Kilo", "Lima",
@@ -87,8 +87,7 @@ public class IndexIT {
Id appId = new SimpleId("application");
Id orgId = new SimpleId("testCollectionOrdering");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
for ( int i = alphabet.length - 1; i >= 0; i-- ) {
String name = alphabet[i];
@@ -157,8 +156,7 @@ public class IndexIT {
Id appId = new SimpleId("application");
Id orgId = new SimpleId("testCollectionFilters");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
for ( int i = alphabet.length - 1; i >= 0; i-- ) {
String name = alphabet[i];
@@ -278,8 +276,7 @@ public class IndexIT {
Id appId = new SimpleId("application");
Id orgId = new SimpleId("testSecondarySorts");
- EntityManagerFacade em = new EntityManagerFacade( orgId, appId,
- collectionManagerFactory, collectionIndexFactory );
+ EntityManagerFacade em = new EntityManagerFacade( orgId, appId, cmf, cif );
for ( int i = alphabet.length - 1; i >= 0; i-- ) {
String name = alphabet[i];
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/e89b3435/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
index bad4343..fa341bc 100644
--- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
+++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/legacy/EntityManagerFacade.java
@@ -51,6 +51,9 @@ public class EntityManagerFacade {
private final EntityCollectionManagerFactory ecmf;
private final EntityCollectionIndexFactory ecif;
private final Map<String, String> typesByCollectionNames = new HashMap<String, String>();
+
+ private final Map<CollectionScope, EntityCollectionManager> managers = new HashMap<>();
+ private final Map<CollectionScope, EntityCollectionIndex> indexes = new HashMap<>();
public EntityManagerFacade(
Id orgId,
@@ -64,11 +67,29 @@ public class EntityManagerFacade {
this.ecif = ecif;
}
+ private EntityCollectionIndex getIndex( CollectionScope scope ) {
+ EntityCollectionIndex eci = indexes.get( scope );
+ if ( eci == null ) {
+ eci = ecif.createCollectionIndex( scope );
+ indexes.put( scope, eci );
+ }
+ return eci;
+ }
+
+ private EntityCollectionManager getManager( CollectionScope scope ) {
+ EntityCollectionManager ecm = managers.get( scope );
+ if ( ecm == null ) {
+ ecm = ecmf.createCollectionManager( scope );
+ managers.put( scope, ecm);
+ }
+ return ecm;
+ }
+
public Entity create( String type, Map<String, Object> properties ) {
CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
- EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
- EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+ EntityCollectionManager ecm = getManager( scope );
+ EntityCollectionIndex eci = getIndex( scope );
final String collectionName;
if ( type.endsWith("y") ) {
@@ -95,14 +116,14 @@ public class EntityManagerFacade {
}
CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
- EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+ EntityCollectionIndex eci = getIndex( scope );
Results results = eci.execute( query );
return results;
}
public Entity get( Id id ) {
CollectionScope scope = new CollectionScopeImpl( appId, orgId, id.getType() );
- EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
+ EntityCollectionManager ecm = getManager( scope );
return ecm.load( id ).toBlockingObservable().last();
}
@@ -120,8 +141,8 @@ public class EntityManagerFacade {
String type = entity.getId().getType();
CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
- EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
- EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+ EntityCollectionManager ecm = getManager( scope );
+ EntityCollectionIndex eci = getIndex( scope );
final String collectionName;
if ( type.endsWith("y") ) {
@@ -142,20 +163,21 @@ public class EntityManagerFacade {
String type = entity.getId().getType();
CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
- EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
- EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+ EntityCollectionManager ecm = getManager( scope );
+ EntityCollectionIndex eci = getIndex( scope );
eci.deindex( entity );
ecm.delete( entity.getId() );
}
+
public void setProperty( EntityRef entityRef, String fieldName, double lat, double lon ) {
String type = entityRef.getId().getType();
CollectionScope scope = new CollectionScopeImpl( appId, orgId, type );
- EntityCollectionManager ecm = ecmf.createCollectionManager( scope );
- EntityCollectionIndex eci = ecif.createCollectionIndex( scope );
+ EntityCollectionManager ecm = getManager( scope );
+ EntityCollectionIndex eci = getIndex( scope );
Entity entity = ecm.load( entityRef.getId() ).toBlockingObservable().last();
entity.setField( new LocationField( fieldName, new Location( lat, lon )));
@@ -164,4 +186,12 @@ public class EntityManagerFacade {
eci.index(entity);
}
+
+ public void refreshIndex() {
+ CollectionScope scope = new CollectionScopeImpl( appId, orgId, "dummy" );
+ EntityCollectionManager ecm = getManager( scope );
+ EntityCollectionIndex eci = getIndex( scope );
+ eci.refresh();
+ }
+
}