Repository: incubator-usergrid Updated Branches: refs/heads/es-type-updates 418edde0f -> 10fbde020
Changed interface for types and updated internals Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/10fbde02 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/10fbde02 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/10fbde02 Branch: refs/heads/es-type-updates Commit: 10fbde020fea3f5ff5306befeb3110c76cb0d85f Parents: 418edde Author: Todd Nine <[email protected]> Authored: Thu Nov 6 11:48:20 2014 -0700 Committer: Todd Nine <[email protected]> Committed: Thu Nov 6 11:48:20 2014 -0700 ---------------------------------------------------------------------- .../usergrid/persistence/index/EntityIndex.java | 2 +- .../usergrid/persistence/index/SearchType.java | 66 -- .../usergrid/persistence/index/SearchTypes.java | 59 ++ .../index/impl/EsEntityIndexBatchImpl.java | 9 +- .../index/impl/EsEntityIndexImpl.java | 19 +- .../persistence/index/impl/IndexingUtils.java | 17 +- .../index/impl/CorePerformanceIT.java | 23 +- .../impl/EntityConnectionIndexImplTest.java | 120 ++- .../persistence/index/impl/EntityIndexTest.java | 774 +++++++++---------- 9 files changed, 589 insertions(+), 500 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java index bc192dc..1a6adb6 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/EntityIndex.java @@ -44,7 +44,7 @@ public interface EntityIndex { /** * Execute query in Usergrid syntax. */ - public CandidateResults search(final IndexScope indexScope, final SearchType searchType, Query query ); + public CandidateResults search(final IndexScope indexScope, final SearchTypes searchType, Query query ); /** * Get the candidate results of all versions of the entity for this id. http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java deleted file mode 100644 index 69137bf..0000000 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchType.java +++ /dev/null @@ -1,66 +0,0 @@ -package org.apache.usergrid.persistence.index;/* - * - * * Licensed to the Apache Software Foundation (ASF) under one - * * or more contributor license agreements. See the NOTICE file - * * distributed with this work for additional information - * * regarding copyright ownership. The ASF licenses this file - * * to you under the Apache License, Version 2.0 (the - * * "License"); you may not use this file except in compliance - * * with the License. You may obtain a copy of the License at - * * - * * http://www.apache.org/licenses/LICENSE-2.0 - * * - * * Unless required by applicable law or agreed to in writing, - * * software distributed under the License is distributed on an - * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * * KIND, either express or implied. See the License for the - * * specific language governing permissions and limitations - * * under the License. - * - */ - - -/** - * Interface for getting search types - */ -public interface SearchType { - - /** - * Get the type used for the search - * @return - */ - public String getTypeName(); - - /** - * Constant that defines searching all types - */ - public static final SearchType ALL_TYPES = new SearchType(){ - - @Override - public String getTypeName() { - return "_all"; - } - }; - - - /** - * Class to encapsulate search types - */ - public static class EntitySearchType implements SearchType{ - - private final String type; - - - public EntitySearchType( final String type ) {this.type = type;} - - - @Override - public String getTypeName() { - return type; - } - - public static SearchType fromType(final String type){ - return new EntitySearchType(type); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java new file mode 100644 index 0000000..584d65b --- /dev/null +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/SearchTypes.java @@ -0,0 +1,59 @@ +package org.apache.usergrid.persistence.index;/* + * + * * Licensed to the Apache Software Foundation (ASF) under one + * * or more contributor license agreements. See the NOTICE file + * * distributed with this work for additional information + * * regarding copyright ownership. The ASF licenses this file + * * to you under the Apache License, Version 2.0 (the + * * "License"); you may not use this file except in compliance + * * with the License. You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, + * * software distributed under the License is distributed on an + * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * * KIND, either express or implied. See the License for the + * * specific language governing permissions and limitations + * * under the License. + * + */ + + +/** + * Class to encapsulate search types + */ + +public class SearchTypes { + + private static final SearchTypes ALL_TYPES = new SearchTypes( ); + + private final String[] types; + + + private SearchTypes( final String... types ) {this.types = types;} + + + public String[] getTypeNames() { + return types; + } + + + /** + * Create a search that will search on the specified types + * @param types + * @return + */ + public static SearchTypes fromTypes( final String... types ) { + return new SearchTypes( types ); + } + + + /** + * Get a search that will search all types in the specified context + * @return + */ + public static SearchTypes allTypes(){ + return ALL_TYPES; + } +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java index 9964d0b..5a19d1e 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/EsEntityIndexBatchImpl.java @@ -126,8 +126,8 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch { Map<String, Object> entityAsMap = entityToMap( entity, context ); - // need prefix here becuase we index UUIDs as strings - entityAsMap.put( STRING_PREFIX + ENTITYID_FIELDNAME, entity.getId().getUuid().toString().toLowerCase() ); + // need prefix here because we index UUIDs as strings + // let caller add these fields if needed // entityAsMap.put("created", entity.getId().getUuid().timestamp(); @@ -251,12 +251,15 @@ public class EsEntityIndexBatchImpl implements EntityIndexBatch { * @param context The context this entity appears in * @return */ - private static Map entityToMap( final EntityObject entity, final String context ) { + private static Map entityToMap( final Entity entity, final String context ) { final Map entityMap = entityToMap( entity ); //add the context for filtering later entityMap.put( ENTITY_CONTEXT, context ); + //but the fieldname + entityMap.put( ENTITYID_FIELDNAME, entity.getId().getUuid().toString().toLowerCase() ); + return entityMap; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/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 d9cfb5b..7378ecd 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 @@ -63,7 +63,7 @@ import org.apache.usergrid.persistence.index.EntityIndex; import org.apache.usergrid.persistence.index.EntityIndexBatch; import org.apache.usergrid.persistence.index.IndexFig; import org.apache.usergrid.persistence.index.IndexScope; -import org.apache.usergrid.persistence.index.SearchType; +import org.apache.usergrid.persistence.index.SearchTypes; import org.apache.usergrid.persistence.index.query.CandidateResult; import org.apache.usergrid.persistence.index.query.CandidateResults; import org.apache.usergrid.persistence.index.query.Query; @@ -232,23 +232,24 @@ public class EsEntityIndexImpl implements EntityIndex { @Override - public CandidateResults search( final IndexScope indexScope, final SearchType searchType, final Query query ) { + public CandidateResults search( final IndexScope indexScope, final SearchTypes searchTypes, final Query query ) { final String context = IndexingUtils.createContextName( indexScope ); - final String entityType = searchType.getTypeName(); + final String[] entityTypes = searchTypes.getTypeNames(); QueryBuilder qb = query.createQueryBuilder(); if ( logger.isDebugEnabled() ) { logger.debug( "Searching index {}\n scope{} \n type {}\n query {} limit {}", new Object[] { - this.indexName, context, entityType, qb.toString().replace( "\n", " " ), query.getLimit() + this.indexName, context, entityTypes, qb.toString().replace( "\n", " " ), query.getLimit() } ); } SearchResponse searchResponse; + if ( query.getCursor() == null ) { SearchRequestBuilder srb = - esProvider.getClient().prepareSearch( indexName ).setTypes( entityType ).setScroll( + esProvider.getClient().prepareSearch( indexName ).setTypes( entityTypes ).setScroll( cursorTimeout + "m" ) .setQuery( qb ); @@ -260,14 +261,14 @@ public class EsEntityIndexImpl implements EntityIndex { //we have post filters, apply them if ( fb != null ) { - final FilterBuilder postFilters = FilterBuilders.andFilter(fb, contextFilter ); +// final FilterBuilder postFilters = FilterBuilders.andFilter(fb, contextFilter ); logger.debug( " Filter: {} ", fb.toString() ); - srb = srb.setPostFilter( postFilters ); +// srb = srb.setPostFilter( postFilters ); } //no other post filters, just the types else{ - srb.setPostFilter( contextFilter ); +// srb.setPostFilter( contextFilter ); } srb = srb.setFrom( 0 ).setSize( query.getLimit() ); @@ -401,7 +402,7 @@ public class EsEntityIndexImpl implements EntityIndex { public CandidateResults getEntityVersions( final IndexScope scope, final Id id ) { Query query = new Query(); query.addEqualityFilter( ENTITYID_FIELDNAME, id.getUuid().toString() ); - CandidateResults results = search( scope, SearchType.EntitySearchType.fromType( id.getType() ), query ); + CandidateResults results = search( scope, SearchTypes.fromTypes( id.getType() ), query ); return results; } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java index d9a3cde..c8e0b86 100644 --- a/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java +++ b/stack/corepersistence/queryindex/src/main/java/org/apache/usergrid/persistence/index/impl/IndexingUtils.java @@ -37,14 +37,13 @@ public class IndexingUtils { public static final String NUMBER_PREFIX = "nu_"; public static final String BOOLEAN_PREFIX = "bu_"; - public static final String ENTITYID_FIELDNAME = "zzz_entityid_zzz"; + public static final String ENTITYID_FIELDNAME = "entityId"; public static final String DOC_ID_SEPARATOR = "|"; public static final String DOC_ID_SEPARATOR_SPLITTER = "\\|"; // These are not allowed in document type names: _ . , | # public static final String DOC_TYPE_SEPARATOR = "^"; - public static final String DOC_TYPE_SEPARATOR_SPLITTER = "\\^"; public static final String INDEX_NAME_SEPARATOR = "^"; @@ -125,7 +124,7 @@ public class IndexingUtils { * * @throws java.io.IOException On JSON generation error. */ - public static XContentBuilder createDoubleStringIndexMapping( + public static XContentBuilder createDoubleStringIndexMapping( XContentBuilder builder, String type ) throws IOException { builder = builder @@ -150,6 +149,7 @@ public class IndexingUtils { // all other strings are not analyzed .startObject() .startObject( "template_2" ) + //todo, should be string prefix, remove 2 field mapping .field( "match", "*" ) .field( "match_mapping_type", "string" ) .startObject( "mapping" ) @@ -169,6 +169,17 @@ public class IndexingUtils { .endObject() .endObject() + //types for context direct string matching + .startObject( "context_template" ) + .field( "match", IndexingUtils.ENTITY_CONTEXT ) + .field( "match_mapping_type", "string" ) + .startObject( "mapping" ) + .field( "type", "string" ) + .field( "index", "not_analyzed" ) + .endObject() + .endObject() + .endObject() + .endArray() .endObject() http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java index 5ec9628..2f71e2e 100644 --- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java +++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/CorePerformanceIT.java @@ -17,8 +17,7 @@ */ package org.apache.usergrid.persistence.index.impl; -import com.google.inject.Guice; -import com.google.inject.Injector; + import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; @@ -26,7 +25,15 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Date; import java.util.List; + +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.apache.commons.lang3.math.NumberUtils; + import org.apache.usergrid.persistence.collection.CollectionScope; import org.apache.usergrid.persistence.collection.EntityCollectionManager; import org.apache.usergrid.persistence.collection.EntityCollectionManagerFactory; @@ -38,7 +45,7 @@ import org.apache.usergrid.persistence.index.EntityIndex; import org.apache.usergrid.persistence.index.EntityIndexBatch; import org.apache.usergrid.persistence.index.EntityIndexFactory; import org.apache.usergrid.persistence.index.IndexScope; -import org.apache.usergrid.persistence.index.SearchType; +import org.apache.usergrid.persistence.index.SearchTypes; import org.apache.usergrid.persistence.index.guice.TestIndexModule; import org.apache.usergrid.persistence.index.query.CandidateResults; import org.apache.usergrid.persistence.index.query.EntityResults; @@ -50,11 +57,9 @@ import org.apache.usergrid.persistence.model.field.DoubleField; import org.apache.usergrid.persistence.model.field.LongField; import org.apache.usergrid.persistence.model.field.StringField; import org.apache.usergrid.persistence.model.util.UUIDGenerator; -import org.junit.ClassRule; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import com.google.inject.Guice; +import com.google.inject.Injector; @@ -179,7 +184,7 @@ public class CorePerformanceIT extends BaseIT { Query query = Query.fromQL( "review_score > 0"); // get all reviews; query.withLimit( maxEntities < 1000 ? maxEntities : 1000 ); - final SearchType searchType = SearchType.EntitySearchType.fromType( "review" ); + final SearchTypes searchType = SearchTypes.fromTypes( "review" ); CandidateResults candidateResults = eci.search(indexScope, searchType, query ); int count = candidateResults.size(); http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java ---------------------------------------------------------------------- diff --git a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java index 47bc666..c1c075e 100644 --- a/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java +++ b/stack/corepersistence/queryindex/src/test/java/org/apache/usergrid/persistence/index/impl/EntityConnectionIndexImplTest.java @@ -21,7 +21,6 @@ package org.apache.usergrid.persistence.index.impl; import java.io.IOException; import java.util.HashMap; -import org.apache.usergrid.persistence.core.test.UseModules; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; @@ -29,18 +28,17 @@ import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.apache.usergrid.persistence.collection.CollectionScope; 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.core.cassandra.CassandraRule; import org.apache.usergrid.persistence.core.scope.ApplicationScope; import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl; +import org.apache.usergrid.persistence.core.test.UseModules; import org.apache.usergrid.persistence.index.EntityIndex; import org.apache.usergrid.persistence.index.EntityIndexBatch; import org.apache.usergrid.persistence.index.EntityIndexFactory; import org.apache.usergrid.persistence.index.IndexScope; -import org.apache.usergrid.persistence.index.SearchType; +import org.apache.usergrid.persistence.index.SearchTypes; import org.apache.usergrid.persistence.index.guice.TestIndexModule; import org.apache.usergrid.persistence.index.query.CandidateResults; import org.apache.usergrid.persistence.index.query.Query; @@ -53,7 +51,6 @@ import com.google.inject.Inject; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; @RunWith( EsRunner.class ) @@ -75,6 +72,7 @@ public class EntityConnectionIndexImplTest extends BaseIT { @Inject public EntityIndexFactory ecif; + @Test public void testBasicOperation() throws IOException { @@ -82,45 +80,123 @@ public class EntityConnectionIndexImplTest extends BaseIT { ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); // create a muffin - Entity muffin = new Entity( - new SimpleId( UUIDGenerator.newTimeUUID(), "muffin" ) ); + Entity muffin = new Entity( new SimpleId( UUIDGenerator.newTimeUUID(), "muffin" ) ); muffin = EntityIndexMapUtils.fromMap( muffin, new HashMap<String, Object>() {{ put( "size", "Large" ); put( "flavor", "Blueberry" ); + put( "stars", 5 ); }} ); EntityUtils.setVersion( muffin, UUIDGenerator.newTimeUUID() ); + Entity egg = new Entity( new SimpleId( UUIDGenerator.newTimeUUID(), "egg" ) ); - // create a person who likes muffins - Entity person = new Entity( new SimpleId( - UUIDGenerator.newTimeUUID(), "person" ) ); - person = EntityIndexMapUtils.fromMap( person, new HashMap<String, Object>() {{ - put( "name", "Dave" ); - put( "hometown", "Chapel Hill" ); + egg = EntityIndexMapUtils.fromMap( egg, new HashMap<String, Object>() {{ + put( "size", "Large" ); + put( "type", "scramble" ); + put( "stars", 5 ); + }} ); + EntityUtils.setVersion( egg, UUIDGenerator.newTimeUUID() ); + + Entity oj = new Entity( new SimpleId( UUIDGenerator.newTimeUUID(), "juice" ) ); + + oj = EntityIndexMapUtils.fromMap( oj, new HashMap<String, Object>() {{ + put( "size", "Large" ); + put( "type", "pulpy" ); + put( "stars", 3 ); }} ); - EntityUtils.setVersion( person, UUIDGenerator.newTimeUUID() ); + EntityUtils.setVersion( oj, UUIDGenerator.newTimeUUID() ); + + + // create a person who likes muffins + Id personId = new SimpleId( UUIDGenerator.newTimeUUID(), "person" ) ; - assertNotNull( person.getId() ); - assertNotNull( person.getId().getUuid() ); + assertNotNull( personId ); + assertNotNull( personId.getType() ); + assertNotNull( personId.getUuid() ); // index connection of "person Dave likes Large Blueberry muffin" - IndexScope scope = new IndexScopeImpl( person.getId(), "likes" ); + IndexScope searchScope = new IndexScopeImpl( personId, "likes" ); + + //create another scope we index in, want to be sure these scopes are filtered + IndexScope otherIndexScope = new IndexScopeImpl( new SimpleId( UUIDGenerator.newTimeUUID(), "person" ), "likes" ); EntityIndex personLikesIndex = ecif.createEntityIndex( applicationScope ); EntityIndexBatch batch = personLikesIndex.createBatch(); - batch.index( scope, muffin ); + //add to both scopes + + //add a muffin + batch.index( searchScope, muffin ); + batch.index( otherIndexScope, muffin ); + + //add the eggs + batch.index( searchScope, egg ); + batch.index( otherIndexScope, egg ); + + //add the oj + batch.index( searchScope, oj ); + batch.index( otherIndexScope, oj ); + batch.executeAndRefresh(); - // now, let's search for things that Dave likes - CandidateResults likes = personLikesIndex.search(scope, SearchType.ALL_TYPES, Query.fromQL( "select *" ) ); + // now, let's search for muffins + CandidateResults likes = personLikesIndex + .search( searchScope, SearchTypes.fromTypes( muffin.getId().getType() ), Query.fromQL( "select *" ) ); assertEquals( 1, likes.size() ); - assertEquals(muffin.getId(), likes.get(0).getId()); + assertEquals( muffin.getId(), likes.get( 0 ).getId() ); - } + // now, let's search for egg + likes = personLikesIndex + .search( searchScope, SearchTypes.fromTypes( egg.getId().getType() ), Query.fromQL( "select *" ) ); + assertEquals( 1, likes.size() ); + assertEquals( egg.getId(), likes.get( 0 ).getId() ); + + // search for OJ + likes = personLikesIndex + .search( searchScope, SearchTypes.fromTypes( oj.getId().getType() ), Query.fromQL( "select *" ) ); + assertEquals( 1, likes.size() ); + assertEquals( oj.getId(), likes.get( 0 ).getId() ); + + + //now lets search for all explicitly + likes = personLikesIndex.search( searchScope, + SearchTypes.fromTypes( muffin.getId().getType(), egg.getId().getType(), oj.getId().getType() ), + Query.fromQL( "select *" ) ); + assertEquals( 3, likes.size() ); + assertEquals( muffin.getId(), likes.get( 0 ).getId() ); + assertEquals( egg.getId(), likes.get( 1 ).getId() ); + assertEquals( oj.getId(), likes.get( 2 ).getId() ); + + //now lets search for all explicitly + likes = personLikesIndex.search( searchScope, + SearchTypes.allTypes(), + Query.fromQL( "select *" ) ); + assertEquals( 3, likes.size() ); + assertEquals( muffin.getId(), likes.get( 0 ).getId() ); + assertEquals( egg.getId(), likes.get( 1 ).getId() ); + assertEquals( oj.getId(), likes.get( 2 ).getId() ); + + + //now search all entity types with a query that returns a subset + likes = personLikesIndex.search( searchScope, + SearchTypes.fromTypes( muffin.getId().getType(), egg.getId().getType(), oj.getId().getType() ), + Query.fromQL( "select * where stars = 5" ) ); + assertEquals( 2, likes.size() ); + assertEquals( muffin.getId(), likes.get( 0 ).getId() ); + assertEquals( egg.getId(), likes.get( 1 ).getId() ); + + + + //now search with no types, we should get only the results that match + likes = personLikesIndex.search( searchScope, SearchTypes.allTypes(), Query.fromQL( "select * where stars = 5" ) ); + assertEquals( 2, likes.size() ); + assertEquals( muffin.getId(), likes.get( 0 ).getId() ); + assertEquals( egg.getId(), likes.get( 1 ).getId() ); + + } } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/10fbde02/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 e23ad3a..1bbb301 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 @@ -69,393 +69,393 @@ import static org.junit.Assert.assertNotEquals; @UseModules({ TestIndexModule.class }) public class EntityIndexTest extends BaseIT { - private static final Logger log = LoggerFactory.getLogger( EntityIndexTest.class ); - - @ClassRule - public static CassandraRule cass = new CassandraRule(); - - @Rule - public ElasticSearchResource elasticSearchResource = new ElasticSearchResource(); - - @Inject - @Rule - public MigrationManagerRule migrationManagerRule; - - @Inject - public EntityIndexFactory eif; - - - - @Test - public void testIndex() throws IOException { - - final int MAX_ENTITIES = 100; - - Id appId = new SimpleId( "application" ); - - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - IndexScope indexScope = new IndexScopeImpl( appId, "things" ); - - - EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); - entityIndex.initializeIndex(); - - InputStream is = this.getClass().getResourceAsStream( "/sample-large.json" ); - ObjectMapper mapper = new ObjectMapper(); - List<Object> sampleJson = mapper.readValue( is, new TypeReference<List<Object>>() {} ); - - int count = 0; - StopWatch timer = new StopWatch(); - timer.start(); - - final EntityIndexBatch batch = entityIndex.createBatch(); - - for ( Object o : sampleJson ) { - - Map<String, Object> item = ( Map<String, Object> ) o; - - Entity entity = new Entity( indexScope.getName() ); - entity = EntityIndexMapUtils.fromMap( entity, item ); - EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() ); - - batch.index( indexScope, entity ); - - if(count %1000 == 0){ - batch.execute(); - } - - - - if ( count++ > MAX_ENTITIES ) { - break; - } - } - - batch.execute(); - timer.stop(); - log.info( "Total time to index {} entries {}ms, average {}ms/entry", - new Object[] { count, timer.getTime(), timer.getTime() / count } ); - - entityIndex.refresh(); - - - testQueries( indexScope, entityIndex ); - } - - - @Test - public void testDeindex() { - - Id appId = new SimpleId( "application" ); - - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - IndexScope indexScope = new IndexScopeImpl( appId, "fastcars", entityType ); - - EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); - entityIndex.initializeIndex(); - - Map entityMap = new HashMap() {{ - put( "name", "Ferrari 212 Inter" ); - put( "introduced", 1952 ); - put( "topspeed", 215 ); - }}; - - - Entity entity = EntityIndexMapUtils.fromMap( entityMap ); - EntityUtils.setId( entity, new SimpleId( "fastcar" ) ); - EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() ); - entityIndex.createBatch().index(indexScope , entity ).executeAndRefresh(); - - CandidateResults candidateResults = entityIndex.search(indexScope, Query.fromQL( "name contains 'Ferrari*'" ) ); - assertEquals( 1, candidateResults.size() ); - - entityIndex.createBatch().deindex( indexScope, entity ).execute(); - - entityIndex.refresh(); - - candidateResults = entityIndex.search( indexScope, Query.fromQL( "name contains 'Ferrari*'" ) ); - assertEquals( 0, candidateResults.size() ); - } - - - private void testQuery(final IndexScope scope, final EntityIndex entityIndex, final String queryString, final int num ) { - - StopWatch timer = new StopWatch(); - timer.start(); - Query query = Query.fromQL( queryString ); - query.setLimit( 1000 ); - CandidateResults candidateResults = entityIndex.search( scope, query ); - timer.stop(); - - assertEquals( num, candidateResults.size() ); - log.debug( "Query time {}ms", timer.getTime() ); - } - - - private void testQueries(final IndexScope scope, final EntityIndex entityIndex ) { - - - testQuery(scope, entityIndex, "name = 'Morgan Pierce'", 1 ); - - testQuery(scope, entityIndex, "name = 'morgan pierce'", 1 ); - - testQuery(scope, entityIndex, "name = 'Morgan'", 0 ); - - testQuery(scope, entityIndex, "name contains 'Morgan'", 1 ); - - testQuery(scope, entityIndex, "company > 'GeoLogix'", 64 ); - - testQuery(scope, entityIndex, "gender = 'female'", 45 ); - - testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 39", 1 ); - - testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 39 and age < 41", 1 ); - - testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 40", 0 ); - - testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age >= 40", 1 ); - - testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age <= 40", 1 ); - - testQuery(scope, entityIndex, "name = 'Morgan* '", 1 ); - - testQuery(scope, entityIndex, "name = 'Morgan*'", 1 ); - - - // test a couple of array sub-property queries - - int totalUsers = 102; - - // nobody has a friend named Jack the Ripper - testQuery(scope, entityIndex, "friends.name = 'Jack the Ripper'", 0 ); - - // everybody doesn't have a friend named Jack the Ripper - testQuery(scope, entityIndex, "not (friends.name = 'Jack the Ripper')", totalUsers ); - - // one person has a friend named Shari Hahn - testQuery(scope, entityIndex, "friends.name = 'Wendy Moody'", 1 ); - - // everybody but 1 doesn't have a friend named Shari Hahh - testQuery(scope, entityIndex, "not (friends.name = 'Shari Hahn')", totalUsers - 1); - - } - - - /** - * Tests that Entity-to-map and Map-to-entity round trip works. - */ - @Test - public void testEntityIndexMapUtils() throws IOException { - - InputStream is = this.getClass().getResourceAsStream( "/sample-small.json" ); - ObjectMapper mapper = new ObjectMapper(); - List<Object> contacts = mapper.readValue( is, new TypeReference<List<Object>>() {} ); - - for ( Object o : contacts ) { - - Map<String, Object> map1 = ( Map<String, Object> ) o; - - // convert map to entity - Entity entity1 = EntityIndexMapUtils.fromMap( map1 ); - - // convert entity back to map - Map map2 = EntityIndexMapUtils.toMap( entity1 ); - - // the two maps should be the same - Map diff = Maps.difference( map1, map2 ).entriesDiffering(); - assertEquals( 0, diff.size() ); - } - } - - - @Test - public void getEntityVersions() throws Exception { - - Id appId = new SimpleId( "application" ); - Id ownerId = new SimpleId( "owner" ); - - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - IndexScope indexScope = new IndexScopeImpl( ownerId, "user", entityType ); - - - - EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); - entityIndex.initializeIndex(); - - final String middleName = "middleName" + UUIDUtils.newTimeUUID(); - Map<String, Object> properties = new LinkedHashMap<String, Object>(); - properties.put( "username", "edanuff" ); - properties.put( "email", "[email protected]" ); - properties.put( "middlename", middleName ); - - Map entityMap = new HashMap() {{ - put( "username", "edanuff" ); - put( "email", "[email protected]" ); - put( "middlename", middleName ); - }}; - - Entity user = EntityIndexMapUtils.fromMap( entityMap ); - EntityUtils.setId( user, new SimpleId( "edanuff" ) ); - EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); - - - final EntityIndexBatch batch = entityIndex.createBatch(); - - batch.index( indexScope, user ); - - user.setField( new StringField( "address1", "1782 address st" ) ); - batch.index( indexScope, user ); - user.setField( new StringField( "address2", "apt 508" ) ); - batch.index( indexScope, user ); - user.setField( new StringField( "address3", "apt 508" ) ); - batch.index( indexScope, user ); - batch.executeAndRefresh(); - - CandidateResults results = entityIndex.getEntityVersions(indexScope, user.getId() ); - - assertEquals(1, results.size()); - assertEquals( results.get( 0 ).getId(), user.getId() ); - assertEquals( results.get(0).getVersion(), user.getVersion()); - } - - - @Test - public void deleteVerification() throws Throwable { - - Id appId = new SimpleId( "application" ); - Id ownerId = new SimpleId( "owner" ); - - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - IndexScope appScope = new IndexScopeImpl( ownerId, "user", entityType ); - - EntityIndex ei = eif.createEntityIndex( applicationScope ); - ei.initializeIndex(); - - final String middleName = "middleName" + UUIDUtils.newTimeUUID(); - - Map entityMap = new HashMap() {{ - put( "username", "edanuff" ); - put( "email", "[email protected]" ); - put( "middlename", middleName ); - }}; - - Entity user = EntityIndexMapUtils.fromMap( entityMap ); - EntityUtils.setId( user, new SimpleId( "edanuff" ) ); - EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); - - - EntityIndexBatch batch = ei.createBatch(); - - batch.index( appScope, user ).executeAndRefresh(); - Query query = new Query(); - query.addEqualityFilter( "username", "edanuff" ); - CandidateResults r = ei.search( appScope, query ); - assertEquals( user.getId(), r.get( 0 ).getId() ); - - batch.deindex(appScope, user.getId(), user.getVersion() ).executeAndRefresh(); - - - // EntityRef - query = new Query(); - query.addEqualityFilter( "username", "edanuff" ); - r = ei.search(appScope, query ); - - assertFalse( r.iterator().hasNext() ); - } - - @Test - public void multiValuedTypes() { - - Id appId = new SimpleId( "entityindextest" ); - Id ownerId = new SimpleId( "multivaluedtype" ); - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - IndexScope appScope = new IndexScopeImpl( ownerId, "user", entityType ); - - EntityIndex ei = eif.createEntityIndex( applicationScope ); - ei.createBatch(); - - // Bill has favorites as string, age as string and retirement goal as number - Map billMap = new HashMap() {{ - put( "username", "bill" ); - put( "email", "[email protected]" ); - put( "age", "thirtysomething"); - put( "favorites", "scallops, croquet, wine"); - put( "retirementGoal", 100000); - }}; - Entity bill = EntityIndexMapUtils.fromMap( billMap ); - EntityUtils.setId( bill, new SimpleId( UUIDGenerator.newTimeUUID(), "user" ) ); - EntityUtils.setVersion( bill, UUIDGenerator.newTimeUUID() ); - - EntityIndexBatch batch = ei.createBatch(); - - batch.index( appScope, bill ); - - // Fred has age as int, favorites as object and retirement goal as object - Map fredMap = new HashMap() {{ - put( "username", "fred" ); - put( "email", "[email protected]" ); - put( "age", 41 ); - put( "favorites", new HashMap<String, Object>() {{ - put("food", "cheezewiz"); - put("sport", "nascar"); - put("beer", "budwizer"); - }}); - put( "retirementGoal", new HashMap<String, Object>() {{ - put("car", "Firebird"); - put("home", "Mobile"); - }}); - }}; - Entity fred = EntityIndexMapUtils.fromMap( fredMap ); - EntityUtils.setId( fred, new SimpleId( UUIDGenerator.newTimeUUID(), "user" ) ); - EntityUtils.setVersion( fred, UUIDGenerator.newTimeUUID() ); - batch.index( appScope, fred ); - - batch.executeAndRefresh(); - - Query query = new Query(); - query.addEqualityFilter( "username", "bill" ); - CandidateResults r = ei.search( appScope, query ); - assertEquals( bill.getId(), r.get( 0 ).getId() ); - - query = new Query(); - query.addEqualityFilter( "username", "fred" ); - r = ei.search( appScope, query ); - assertEquals( fred.getId(), r.get( 0 ).getId() ); - - query = new Query(); - query.addEqualityFilter( "age", 41 ); - r = ei.search( appScope, query ); - assertEquals( fred.getId(), r.get( 0 ).getId() ); - - query = new Query(); - query.addEqualityFilter( "age", "thirtysomething" ); - r = ei.search( appScope, query ); - assertEquals( bill.getId(), r.get( 0 ).getId() ); - } - - - @Test - public void healthTest() { - - Id appId = new SimpleId( "application" ); - ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); - - EntityIndex ei = eif.createEntityIndex( applicationScope ); - - assertNotEquals( "cluster should be ok", Health.RED, ei.getClusterHealth() ); - assertEquals( "index not be ready yet", Health.RED, ei.getIndexHealth() ); - - ei.initializeIndex(); - ei.refresh(); - - assertNotEquals( "cluster should be fine", Health.RED, ei.getIndexHealth() ); - assertNotEquals( "cluster should be ready now", Health.RED, ei.getClusterHealth() ); - } +// private static final Logger log = LoggerFactory.getLogger( EntityIndexTest.class ); +// +// @ClassRule +// public static CassandraRule cass = new CassandraRule(); +// +// @Rule +// public ElasticSearchResource elasticSearchResource = new ElasticSearchResource(); +// +// @Inject +// @Rule +// public MigrationManagerRule migrationManagerRule; +// +// @Inject +// public EntityIndexFactory eif; +// +// +// +// @Test +// public void testIndex() throws IOException { +// +// final int MAX_ENTITIES = 100; +// +// Id appId = new SimpleId( "application" ); +// +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// IndexScope indexScope = new IndexScopeImpl( appId, "things" ); +// +// +// EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); +// entityIndex.initializeIndex(); +// +// InputStream is = this.getClass().getResourceAsStream( "/sample-large.json" ); +// ObjectMapper mapper = new ObjectMapper(); +// List<Object> sampleJson = mapper.readValue( is, new TypeReference<List<Object>>() {} ); +// +// int count = 0; +// StopWatch timer = new StopWatch(); +// timer.start(); +// +// final EntityIndexBatch batch = entityIndex.createBatch(); +// +// for ( Object o : sampleJson ) { +// +// Map<String, Object> item = ( Map<String, Object> ) o; +// +// Entity entity = new Entity( indexScope.getName() ); +// entity = EntityIndexMapUtils.fromMap( entity, item ); +// EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() ); +// +// batch.index( indexScope, entity ); +// +// if(count %1000 == 0){ +// batch.execute(); +// } +// +// +// +// if ( count++ > MAX_ENTITIES ) { +// break; +// } +// } +// +// batch.execute(); +// timer.stop(); +// log.info( "Total time to index {} entries {}ms, average {}ms/entry", +// new Object[] { count, timer.getTime(), timer.getTime() / count } ); +// +// entityIndex.refresh(); +// +// +// testQueries( indexScope, entityIndex ); +// } +// +// +// @Test +// public void testDeindex() { +// +// Id appId = new SimpleId( "application" ); +// +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// IndexScope indexScope = new IndexScopeImpl( appId, "fastcars", entityType ); +// +// EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); +// entityIndex.initializeIndex(); +// +// Map entityMap = new HashMap() {{ +// put( "name", "Ferrari 212 Inter" ); +// put( "introduced", 1952 ); +// put( "topspeed", 215 ); +// }}; +// +// +// Entity entity = EntityIndexMapUtils.fromMap( entityMap ); +// EntityUtils.setId( entity, new SimpleId( "fastcar" ) ); +// EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() ); +// entityIndex.createBatch().index(indexScope , entity ).executeAndRefresh(); +// +// CandidateResults candidateResults = entityIndex.search(indexScope, Query.fromQL( "name contains 'Ferrari*'" ) ); +// assertEquals( 1, candidateResults.size() ); +// +// entityIndex.createBatch().deindex( indexScope, entity ).execute(); +// +// entityIndex.refresh(); +// +// candidateResults = entityIndex.search( indexScope, Query.fromQL( "name contains 'Ferrari*'" ) ); +// assertEquals( 0, candidateResults.size() ); +// } +// +// +// private void testQuery(final IndexScope scope, final EntityIndex entityIndex, final String queryString, final int num ) { +// +// StopWatch timer = new StopWatch(); +// timer.start(); +// Query query = Query.fromQL( queryString ); +// query.setLimit( 1000 ); +// CandidateResults candidateResults = entityIndex.search( scope, query ); +// timer.stop(); +// +// assertEquals( num, candidateResults.size() ); +// log.debug( "Query time {}ms", timer.getTime() ); +// } +// +// +// private void testQueries(final IndexScope scope, final EntityIndex entityIndex ) { +// +// +// testQuery(scope, entityIndex, "name = 'Morgan Pierce'", 1 ); +// +// testQuery(scope, entityIndex, "name = 'morgan pierce'", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Morgan'", 0 ); +// +// testQuery(scope, entityIndex, "name contains 'Morgan'", 1 ); +// +// testQuery(scope, entityIndex, "company > 'GeoLogix'", 64 ); +// +// testQuery(scope, entityIndex, "gender = 'female'", 45 ); +// +// testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 39", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 39 and age < 41", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age > 40", 0 ); +// +// testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age >= 40", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Minerva Harrell' and age <= 40", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Morgan* '", 1 ); +// +// testQuery(scope, entityIndex, "name = 'Morgan*'", 1 ); +// +// +// // test a couple of array sub-property queries +// +// int totalUsers = 102; +// +// // nobody has a friend named Jack the Ripper +// testQuery(scope, entityIndex, "friends.name = 'Jack the Ripper'", 0 ); +// +// // everybody doesn't have a friend named Jack the Ripper +// testQuery(scope, entityIndex, "not (friends.name = 'Jack the Ripper')", totalUsers ); +// +// // one person has a friend named Shari Hahn +// testQuery(scope, entityIndex, "friends.name = 'Wendy Moody'", 1 ); +// +// // everybody but 1 doesn't have a friend named Shari Hahh +// testQuery(scope, entityIndex, "not (friends.name = 'Shari Hahn')", totalUsers - 1); +// +// } +// +// +// /** +// * Tests that Entity-to-map and Map-to-entity round trip works. +// */ +// @Test +// public void testEntityIndexMapUtils() throws IOException { +// +// InputStream is = this.getClass().getResourceAsStream( "/sample-small.json" ); +// ObjectMapper mapper = new ObjectMapper(); +// List<Object> contacts = mapper.readValue( is, new TypeReference<List<Object>>() {} ); +// +// for ( Object o : contacts ) { +// +// Map<String, Object> map1 = ( Map<String, Object> ) o; +// +// // convert map to entity +// Entity entity1 = EntityIndexMapUtils.fromMap( map1 ); +// +// // convert entity back to map +// Map map2 = EntityIndexMapUtils.toMap( entity1 ); +// +// // the two maps should be the same +// Map diff = Maps.difference( map1, map2 ).entriesDiffering(); +// assertEquals( 0, diff.size() ); +// } +// } +// +// +// @Test +// public void getEntityVersions() throws Exception { +// +// Id appId = new SimpleId( "application" ); +// Id ownerId = new SimpleId( "owner" ); +// +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// IndexScope indexScope = new IndexScopeImpl( ownerId, "user", entityType ); +// +// +// +// EntityIndex entityIndex = eif.createEntityIndex( applicationScope ); +// entityIndex.initializeIndex(); +// +// final String middleName = "middleName" + UUIDUtils.newTimeUUID(); +// Map<String, Object> properties = new LinkedHashMap<String, Object>(); +// properties.put( "username", "edanuff" ); +// properties.put( "email", "[email protected]" ); +// properties.put( "middlename", middleName ); +// +// Map entityMap = new HashMap() {{ +// put( "username", "edanuff" ); +// put( "email", "[email protected]" ); +// put( "middlename", middleName ); +// }}; +// +// Entity user = EntityIndexMapUtils.fromMap( entityMap ); +// EntityUtils.setId( user, new SimpleId( "edanuff" ) ); +// EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); +// +// +// final EntityIndexBatch batch = entityIndex.createBatch(); +// +// batch.index( indexScope, user ); +// +// user.setField( new StringField( "address1", "1782 address st" ) ); +// batch.index( indexScope, user ); +// user.setField( new StringField( "address2", "apt 508" ) ); +// batch.index( indexScope, user ); +// user.setField( new StringField( "address3", "apt 508" ) ); +// batch.index( indexScope, user ); +// batch.executeAndRefresh(); +// +// CandidateResults results = entityIndex.getEntityVersions(indexScope, user.getId() ); +// +// assertEquals(1, results.size()); +// assertEquals( results.get( 0 ).getId(), user.getId() ); +// assertEquals( results.get(0).getVersion(), user.getVersion()); +// } +// +// +// @Test +// public void deleteVerification() throws Throwable { +// +// Id appId = new SimpleId( "application" ); +// Id ownerId = new SimpleId( "owner" ); +// +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// IndexScope appScope = new IndexScopeImpl( ownerId, "user", entityType ); +// +// EntityIndex ei = eif.createEntityIndex( applicationScope ); +// ei.initializeIndex(); +// +// final String middleName = "middleName" + UUIDUtils.newTimeUUID(); +// +// Map entityMap = new HashMap() {{ +// put( "username", "edanuff" ); +// put( "email", "[email protected]" ); +// put( "middlename", middleName ); +// }}; +// +// Entity user = EntityIndexMapUtils.fromMap( entityMap ); +// EntityUtils.setId( user, new SimpleId( "edanuff" ) ); +// EntityUtils.setVersion( user, UUIDGenerator.newTimeUUID() ); +// +// +// EntityIndexBatch batch = ei.createBatch(); +// +// batch.index( appScope, user ).executeAndRefresh(); +// Query query = new Query(); +// query.addEqualityFilter( "username", "edanuff" ); +// CandidateResults r = ei.search( appScope, query ); +// assertEquals( user.getId(), r.get( 0 ).getId() ); +// +// batch.deindex(appScope, user.getId(), user.getVersion() ).executeAndRefresh(); +// +// +// // EntityRef +// query = new Query(); +// query.addEqualityFilter( "username", "edanuff" ); +// r = ei.search(appScope, query ); +// +// assertFalse( r.iterator().hasNext() ); +// } +// +// @Test +// public void multiValuedTypes() { +// +// Id appId = new SimpleId( "entityindextest" ); +// Id ownerId = new SimpleId( "multivaluedtype" ); +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// IndexScope appScope = new IndexScopeImpl( ownerId, "user", entityType ); +// +// EntityIndex ei = eif.createEntityIndex( applicationScope ); +// ei.createBatch(); +// +// // Bill has favorites as string, age as string and retirement goal as number +// Map billMap = new HashMap() {{ +// put( "username", "bill" ); +// put( "email", "[email protected]" ); +// put( "age", "thirtysomething"); +// put( "favorites", "scallops, croquet, wine"); +// put( "retirementGoal", 100000); +// }}; +// Entity bill = EntityIndexMapUtils.fromMap( billMap ); +// EntityUtils.setId( bill, new SimpleId( UUIDGenerator.newTimeUUID(), "user" ) ); +// EntityUtils.setVersion( bill, UUIDGenerator.newTimeUUID() ); +// +// EntityIndexBatch batch = ei.createBatch(); +// +// batch.index( appScope, bill ); +// +// // Fred has age as int, favorites as object and retirement goal as object +// Map fredMap = new HashMap() {{ +// put( "username", "fred" ); +// put( "email", "[email protected]" ); +// put( "age", 41 ); +// put( "favorites", new HashMap<String, Object>() {{ +// put("food", "cheezewiz"); +// put("sport", "nascar"); +// put("beer", "budwizer"); +// }}); +// put( "retirementGoal", new HashMap<String, Object>() {{ +// put("car", "Firebird"); +// put("home", "Mobile"); +// }}); +// }}; +// Entity fred = EntityIndexMapUtils.fromMap( fredMap ); +// EntityUtils.setId( fred, new SimpleId( UUIDGenerator.newTimeUUID(), "user" ) ); +// EntityUtils.setVersion( fred, UUIDGenerator.newTimeUUID() ); +// batch.index( appScope, fred ); +// +// batch.executeAndRefresh(); +// +// Query query = new Query(); +// query.addEqualityFilter( "username", "bill" ); +// CandidateResults r = ei.search( appScope, query ); +// assertEquals( bill.getId(), r.get( 0 ).getId() ); +// +// query = new Query(); +// query.addEqualityFilter( "username", "fred" ); +// r = ei.search( appScope, query ); +// assertEquals( fred.getId(), r.get( 0 ).getId() ); +// +// query = new Query(); +// query.addEqualityFilter( "age", 41 ); +// r = ei.search( appScope, query ); +// assertEquals( fred.getId(), r.get( 0 ).getId() ); +// +// query = new Query(); +// query.addEqualityFilter( "age", "thirtysomething" ); +// r = ei.search( appScope, query ); +// assertEquals( bill.getId(), r.get( 0 ).getId() ); +// } +// +// +// @Test +// public void healthTest() { +// +// Id appId = new SimpleId( "application" ); +// ApplicationScope applicationScope = new ApplicationScopeImpl( appId ); +// +// EntityIndex ei = eif.createEntityIndex( applicationScope ); +// +// assertNotEquals( "cluster should be ok", Health.RED, ei.getClusterHealth() ); +// assertEquals( "index not be ready yet", Health.RED, ei.getIndexHealth() ); +// +// ei.initializeIndex(); +// ei.refresh(); +// +// assertNotEquals( "cluster should be fine", Health.RED, ei.getIndexHealth() ); +// assertNotEquals( "cluster should be ready now", Health.RED, ei.getClusterHealth() ); +// } }
