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 2015/04/06 22:50:56 UTC
[8/9] incubator-usergrid git commit: Fix to lookupApplication() and
some initial test code.
Fix to lookupApplication() and some initial test code.
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/a5a014cf
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/a5a014cf
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/a5a014cf
Branch: refs/heads/USERGRID-533-create-app-test
Commit: a5a014cfd6a9c7834e1e528f559db2cc86721200
Parents: 35e0453
Author: Dave Johnson <dm...@apigee.com>
Authored: Mon Apr 6 14:14:35 2015 -0400
Committer: Dave Johnson <dm...@apigee.com>
Committed: Mon Apr 6 14:14:35 2015 -0400
----------------------------------------------------------------------
.../corepersistence/ApplicationIdCacheImpl.java | 22 ++++++-
.../cassandra/EntityManagerFactoryImplIT.java | 16 +++++
.../rest/applications/ApplicationCreateIT.java | 68 +++++++++++++++-----
3 files changed, 88 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
index e2d1f5a..657f662 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/ApplicationIdCacheImpl.java
@@ -29,15 +29,19 @@ import org.apache.usergrid.persistence.EntityManagerFactory;
import org.apache.usergrid.persistence.Schema;
import org.apache.usergrid.persistence.collection.EntityCollectionManager;
import org.apache.usergrid.persistence.core.scope.ApplicationScopeImpl;
+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.utils.UUIDUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import rx.Observable;
import java.util.UUID;
+import static org.apache.usergrid.persistence.Schema.PROPERTY_APPLICATION_ID;
+
/**
* Implements the org app cache for faster runtime lookups. These values are immutable, so this LRU cache can stay
@@ -89,7 +93,8 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
final UUID value;
EntityCollectionManager ecm = emf.getManagerCache().getEntityCollectionManager(
- new ApplicationScopeImpl( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
+ new ApplicationScopeImpl(
+ new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, Schema.TYPE_APPLICATION ) ) );
try {
if ( rootEm.getApplication() == null ) {
@@ -100,11 +105,22 @@ public class ApplicationIdCacheImpl implements ApplicationIdCache {
}
try {
+
+ // look up application_info ID for application using unique "name" field
final Observable<Id> idObs = ecm.getIdField(
- Schema.TYPE_APPLICATION, new StringField( Schema.PROPERTY_NAME, applicationName ));
+ CpNamingUtils.APPLICATION_INFO, new StringField(Schema.PROPERTY_NAME, applicationName));
Id id = idObs.toBlocking().lastOrDefault(null);
- value = id.getUuid();
+ UUID applicationInfoId = id.getUuid();
+
+ // get the application_info by ID
+ Entity applicationInfo = ecm.load(
+ new SimpleId( applicationInfoId, CpNamingUtils.APPLICATION_INFO ))
+ .toBlocking().lastOrDefault( null );
+
+ // extract application UUID from application_info
+ value = UUIDUtils.tryExtractUUID(
+ applicationInfo.getField( PROPERTY_APPLICATION_ID ).getValue().toString() );
logger.debug("Loaded for key {} value {}", applicationName, value );
return value;
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
index b64f0b5..da3fde6 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/cassandra/EntityManagerFactoryImplIT.java
@@ -23,6 +23,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
+import junit.framework.Assert;
import org.apache.usergrid.persistence.*;
import org.apache.usergrid.utils.UUIDUtils;
import org.junit.AfterClass;
@@ -309,4 +310,19 @@ public class EntityManagerFactoryImplIT extends AbstractCoreIT {
*/
traceTagReporter.report( traceTagManager.detach() );
}
+
+
+ @Test
+ public void testCreateAndImmediateGet() throws Exception {
+
+ String random = RandomStringUtils.randomAlphabetic(10);
+ String orgName = "org_" + random;
+ String appName = "app_" + random;
+ String orgAppName = orgName + "/" + appName;
+
+ UUID appId = setup.createApplication(orgName, appName);
+ UUID lookedUpId = setup.getEmf().lookupApplication( orgAppName );
+
+ Assert.assertEquals(appId, lookedUpId);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/a5a014cf/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
index ba5e1d9..2dfdf78 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationCreateIT.java
@@ -20,6 +20,7 @@ package org.apache.usergrid.rest.applications;
import com.fasterxml.jackson.databind.JsonNode;
import com.sun.jersey.api.client.UniformInterfaceException;
+import org.apache.commons.lang3.RandomStringUtils;
import org.apache.usergrid.rest.test.resource2point0.AbstractRestIT;
import org.apache.usergrid.rest.test.resource2point0.endpoints.mgmt.ManagementResponse;
import org.apache.usergrid.rest.test.resource2point0.model.ApiResponse;
@@ -32,11 +33,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ws.rs.core.MediaType;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
+import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@@ -45,24 +44,62 @@ public class ApplicationCreateIT extends AbstractRestIT {
/**
- * Ensure that we can create many apps and successfully page through them.
+ * Test that we can create and then immediately retrieve an app by name.
* https://issues.apache.org/jira/browse/USERGRID-491
- *
- * <pre>
- * </pre>
*/
@Test
- public void testCreateAndRetreieveApps() throws Exception {
+ public void testCreateAndImmediateGet() throws Exception {
- // create app with a collection of "things"
+ // create app
String orgName = clientSetup.getOrganization().getName();
- String appToDeleteName = clientSetup.getAppName() + "_appToDelete";
- Token orgAdminToken = getAdminToken( clientSetup.getUsername(), clientSetup.getUsername());
+ String appName = clientSetup.getAppName() + "_new_app";
+ Token orgAdminToken = getAdminToken(clientSetup.getUsername(), clientSetup.getUsername());
- List<Entity> entities = new ArrayList<>();
+ ApiResponse appCreateResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).app().getResource()
+ .queryParam( "access_token", orgAdminToken.getAccessToken() )
+ .type( MediaType.APPLICATION_JSON )
+ .post(ApiResponse.class, new Application(appName));
+ appCreateResponse.getEntities().get(0).getUuid();
+
+ // should be able to immediate get the application's roles collection
+
+ String response = clientSetup.getRestClient().getResource()
+ .path("/" + clientSetup.getOrganizationName() + "/" + appName + "/roles" )
+ .get(String.class);
+ logger.error( response );
- UUID appToDeleteId = createAppWithCollection(orgName, appToDeleteName, orgAdminToken, entities);
+ }
+
+
+ /**
+ * Test that we can create applications and the immediately retrieve them all.
+ */
+ @Test
+ public void testCreateAndImmediateList() throws Exception {
+
+ int appCount = 40;
+
+ String random = RandomStringUtils.randomAlphabetic(10);
+ String orgName = "org_" + random;
+ String appName = "app_" + random;
+ Token orgAdminToken = getAdminToken(clientSetup.getUsername(), clientSetup.getUsername());
+
+ for ( int i=0; i<appCount; i++ ) {
+ createAppWithCollection( orgName, appName + i, orgAdminToken, new ArrayList<>() );
+ }
+
+ // test that we get all applications back from the management end-point
+
+ ManagementResponse orgAppResponse = clientSetup.getRestClient()
+ .management().orgs().organization( orgName ).apps().getOrganizationApplications();
+
+ int count = 0;
+ for ( String name : orgAppResponse.getData().keySet() ) {
+ count++;
+ }
+ assertEquals( appCount, count );
}
@@ -76,7 +113,8 @@ public class ApplicationCreateIT extends AbstractRestIT {
.post( ApiResponse.class, new Application( appName ) );
UUID appId = appCreateResponse.getEntities().get(0).getUuid();
- for ( int i=0; i<10; i++ ) {
+
+ for ( int i=0; i<5; i++ ) {
final String entityName = "entity" + i;
Entity entity = new Entity();