Skip to content
This repository has been archived by the owner on Jan 5, 2022. It is now read-only.

Commit

Permalink
Fixing EMF getApplications() and the all-apps observable to use the a…
Browse files Browse the repository at this point in the history
…pp ID and not the application_info ID, plus some section comments in related tests.
  • Loading branch information
Dave Johnson committed Mar 17, 2015
1 parent 9f3bb94 commit 7d7c54b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 33 deletions.
Expand Up @@ -449,16 +449,19 @@ public Map<String, UUID> getApplications(boolean deleted) throws Exception {
appScope.getApplication(),
scopeName);

org.apache.usergrid.persistence.model.entity.Entity e =
org.apache.usergrid.persistence.model.entity.Entity appInfo =
managerCache.getEntityCollectionManager( collScope ).load( targetId )
.toBlockingObservable().lastOrDefault(null);

if ( e == null ) {
if ( appInfo == null ) {
logger.warn("Application {} in index but not found in collections", targetId );
continue;
}

appMap.put( (String)e.getField( PROPERTY_NAME ).getValue(), e.getId().getUuid());
UUID applicationId = UUIDUtils.tryExtractUUID(
appInfo.getField( PROPERTY_APPLICATION_ID ).getValue().toString() );

appMap.put( (String)appInfo.getField( PROPERTY_NAME ).getValue(), applicationId);
}

return appMap;
Expand Down
Expand Up @@ -23,6 +23,8 @@
import java.util.Arrays;
import java.util.UUID;

import org.apache.usergrid.persistence.Schema;
import org.apache.usergrid.utils.UUIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -100,6 +102,7 @@ public Observable<ApplicationScope> getAllApplications() {
null ) ).flatMap( new Func1<Edge, Observable<ApplicationScope>>() {
@Override
public Observable<ApplicationScope> call( final Edge edge ) {

//get the app info and load it
final Id appInfo = edge.getTargetNode();

Expand All @@ -121,7 +124,8 @@ public Boolean call( final Entity entity ) {

@Override
public ApplicationScope call( final Entity entity ) {
final UUID uuid = entity.getId().getUuid();
final UUID uuid = UUIDUtils.tryExtractUUID(
entity.getField( Schema.PROPERTY_APPLICATION_ID ).getValue().toString());
return getApplicationScope( uuid );
}
} );
Expand Down
Expand Up @@ -55,22 +55,26 @@ public class AllEntitiesInSystemObservableIT extends AbstractCoreIT {

@Test
public void testEntities() throws Exception {

Injector injector = SpringResource.getInstance().getBean(Injector.class);
AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =injector.getInstance(AllEntitiesInSystemImpl.class);
AllEntitiesInSystemImpl allEntitiesInSystemObservableImpl =
injector.getInstance(AllEntitiesInSystemImpl.class);
TargetIdObservable targetIdObservable = injector.getInstance(TargetIdObservable.class);

final EntityManager em = app.getEntityManager();

// create two types of entities

final String type1 = "type1thing";
final String type2 = "type2thing";
final int size = 10;

final Set<Id> type1Identities = EntityWriteHelper.createTypes( em, type1, size );
final Set<Id> type2Identities = EntityWriteHelper.createTypes( em, type2, size );

//create a connection and put that in our connection types
final Id source = type1Identities.iterator().next();
// connect the first type1 entity to all type2 entities

final Id source = type1Identities.iterator().next();

final Set<Id> allEntities = new HashSet<>();
allEntities.addAll( type1Identities );
Expand All @@ -79,20 +83,17 @@ public void testEntities() throws Exception {
final Set<Id> connections = new HashSet<>();

for ( Id target : type2Identities ) {
em.createConnection( SimpleEntityRef.fromId( source ), "likes", SimpleEntityRef.fromId( target ) );
em.createConnection( SimpleEntityRef.fromId( source ),
"likes", SimpleEntityRef.fromId( target ) );
connections.add( target );
}

// use the all-entities-in-system observable to delete all type1 and type2 entities

//this is hacky, but our context integration b/t guice and spring is a mess. We need to clean this up when we
//clean up our wiring
//
ManagerCache managerCache = SpringResource.getInstance().getBean( Injector.class ).getInstance( ManagerCache.class );


// TODO: clean this up when we clean up our Guice and Spring wiring
ManagerCache managerCache = SpringResource.getInstance()
.getBean( Injector.class ).getInstance( ManagerCache.class );
final ApplicationScope scope = CpNamingUtils.getApplicationScope( app.getId() );


final GraphManager gm = managerCache.getGraphManager( scope );

allEntitiesInSystemObservableImpl.getData().doOnNext( new Action1<EntityIdScope>() {
Expand All @@ -102,22 +103,23 @@ public void call( final EntityIdScope entityIdScope ) {
assertNotNull(entityIdScope.getCollectionScope());
assertNotNull(entityIdScope.getId());

//we should only emit each node once
if ( entityIdScope.getId().getType().equals( type1 ) ) {
assertTrue( "Element should be present on removal", type1Identities.remove(entityIdScope.getId() ) );
}
else if ( entityIdScope.getId().getType().equals( type2 ) ) {
assertTrue( "Element should be present on removal", type2Identities.remove(entityIdScope.getId() ) );
}

// we should only emit each node once
if ( entityIdScope.getId().getType().equals( type1 ) ) {
assertTrue( "Element should be present on removal",
type1Identities.remove(entityIdScope.getId() ) );
}
else if ( entityIdScope.getId().getType().equals( type2 ) ) {
assertTrue( "Element should be present on removal",
type2Identities.remove(entityIdScope.getId() ) );
}
}
} ).toBlocking().lastOrDefault( null );

// there should now be no type1 or type2 entities

assertEquals( "Every element should have been encountered", 0, type1Identities.size() );
assertEquals( "Every element should have been encountered", 0, type2Identities.size() );


//test connections

targetIdObservable.getTargetNodes( gm, source ).doOnNext( new Action1<Id>() {
Expand Down
Expand Up @@ -174,8 +174,7 @@ public void rebuildOneCollectionIndex() throws Exception {

// ----------------- delete the system and application indexes

logger.debug("Deleting app index index");
//deleteIndex( CpNamingUtils.SYSTEM_APP_ID );
logger.debug("Deleting apps");
deleteIndex( em.getApplicationId() );

// ----------------- test that we can read them, should fail
Expand Down Expand Up @@ -311,13 +310,10 @@ public void rebuildIndex() throws Exception {

// ----------------- delete the system and application indexes

logger.debug("Deleting app index and system app index");
logger.debug("Deleting app index");

deleteIndex( em.getApplicationId() );

// deleting sytem app index will interfere with other concurrently running tests
//deleteIndex( CpNamingUtils.SYSTEM_APP_ID );


// ----------------- test that we can read them, should fail

Expand Down Expand Up @@ -373,14 +369,14 @@ public void onProgress( final EntityRef entity ) {
}

/**
* Delete index for all applications, just need the one to get started.
* Delete app index
*/
private void deleteIndex( UUID appUuid ) {

Injector injector = SpringResource.getInstance().getBean( Injector.class );
EntityIndexFactory eif = injector.getInstance( EntityIndexFactory.class );

Id appId = new SimpleId( appUuid, "application");
Id appId = new SimpleId( appUuid, Schema.TYPE_APPLICATION );
ApplicationScope scope = new ApplicationScopeImpl( appId );
EntityIndex ei = eif.createEntityIndex(scope);
EsEntityIndexImpl eeii = (EsEntityIndexImpl)ei;
Expand Down

0 comments on commit 7d7c54b

Please sign in to comment.