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/08/12 19:48:06 UTC
[3/4] incubator-usergrid git commit: Fixes aggregation check in test
Fixes aggregation check in test
Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/90e514ad
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/90e514ad
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/90e514ad
Branch: refs/heads/two-dot-o-dev
Commit: 90e514ad35a452e66ce62b7ec39eb88eb69ad0b3
Parents: 13f6d23
Author: Todd Nine <tn...@apigee.com>
Authored: Wed Aug 12 11:15:38 2015 -0600
Committer: Todd Nine <tn...@apigee.com>
Committed: Wed Aug 12 11:20:51 2015 -0600
----------------------------------------------------------------------
.../src/test/resources/usergrid-test.properties | 1 +
.../apache/usergrid/persistence/CounterIT.java | 83 +++++++++++---------
2 files changed, 45 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90e514ad/stack/config/src/test/resources/usergrid-test.properties
----------------------------------------------------------------------
diff --git a/stack/config/src/test/resources/usergrid-test.properties b/stack/config/src/test/resources/usergrid-test.properties
index c5e26cb..072ca0b 100644
--- a/stack/config/src/test/resources/usergrid-test.properties
+++ b/stack/config/src/test/resources/usergrid-test.properties
@@ -77,6 +77,7 @@ usergrid.version.properties=1.0.0
# build number for display
usergrid.version.build=0.1
+usergrid.counter.batch.interval=10
#usergrid.auth.token_secret_salt=super secret token value
#usergrid.auth.token_expires_from_last_use=false
#usergrid.auth.token_refresh_reuses_id=false
http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/90e514ad/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
----------------------------------------------------------------------
diff --git a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
index d1abde5..54302ad 100644
--- a/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
+++ b/stack/core/src/test/java/org/apache/usergrid/persistence/CounterIT.java
@@ -23,33 +23,28 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
-import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.commons.lang3.RandomStringUtils;
-
import org.apache.usergrid.AbstractCoreIT;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
import org.apache.usergrid.persistence.entities.Event;
import org.apache.usergrid.persistence.entities.Group;
import org.apache.usergrid.persistence.entities.User;
-import org.apache.usergrid.persistence.index.EntityIndex;
import org.apache.usergrid.persistence.index.query.CounterResolution;
-import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.model.util.UUIDGenerator;
import org.apache.usergrid.utils.ImmediateCounterRule;
import org.apache.usergrid.utils.JsonUtils;
import org.apache.usergrid.utils.UUIDUtils;
-import com.google.inject.Inject;
-
import net.jcip.annotations.NotThreadSafe;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
@NotThreadSafe
@@ -58,7 +53,7 @@ public class CounterIT extends AbstractCoreIT {
private static final Logger LOG = LoggerFactory.getLogger( CounterIT.class );
@Rule
- public ImmediateCounterRule counterRule = new ImmediateCounterRule( );
+ public ImmediateCounterRule counterRule = new ImmediateCounterRule();
long ts = System.currentTimeMillis() - ( 24 * 60 * 60 * 1000 );
@@ -68,8 +63,7 @@ public class CounterIT extends AbstractCoreIT {
}
-
- @Ignore("needs to have elasticsearch refreshes implemented")
+ @Ignore( "needs to have elasticsearch refreshes implemented" )
@Test
public void testIncrementAndDecrement() throws Exception {
@@ -115,7 +109,6 @@ public class CounterIT extends AbstractCoreIT {
assertNotNull( em );
-
UUID user1 = UUID.randomUUID();
UUID user2 = UUID.randomUUID();
// UUID groupId = UUID.randomUUID();
@@ -137,20 +130,19 @@ public class CounterIT extends AbstractCoreIT {
}
Results r = em.getAggregateCounters( null, null, null, "visits", CounterResolution.SIX_HOUR, ts,
- System.currentTimeMillis(), false );
+ System.currentTimeMillis(), false );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
r = em.getAggregateCounters( user1, null, null, "visits", CounterResolution.SIX_HOUR, ts,
- System.currentTimeMillis(), false );
+ System.currentTimeMillis(), false );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
r = em.getAggregateCounters( user1, null, null, "visits", CounterResolution.SIX_HOUR, ts,
- System.currentTimeMillis(), true );
+ System.currentTimeMillis(), true );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
- r = em.getAggregateCounters( user1, null, null, "visits", CounterResolution.ALL, ts,
- System.currentTimeMillis(),
- false );
+ r = em.getAggregateCounters( user1, null, null, "visits", CounterResolution.ALL, ts, System.currentTimeMillis(),
+ false );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
for ( int i = 0; i < 10; i++ ) {
@@ -161,7 +153,7 @@ public class CounterIT extends AbstractCoreIT {
}
r = em.getAggregateCounters( null, null, null, "clicks", CounterResolution.HALF_HOUR, ts,
- System.currentTimeMillis(), true );
+ System.currentTimeMillis(), true );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
Query query = new Query();
@@ -203,7 +195,8 @@ public class CounterIT extends AbstractCoreIT {
final long originalCount;
if ( or.getCounters().get( 0 ).getValues().isEmpty() ) {
originalCount = 0;
- } else {
+ }
+ else {
originalCount = or.getCounters().get( 0 ).getValues().get( 0 ).getValue();
}
@@ -211,7 +204,8 @@ public class CounterIT extends AbstractCoreIT {
final long originalAdminLoginsCount;
if ( counts.get( "admin.logins" ) == null ) {
originalAdminLoginsCount = 0;
- } else {
+ }
+ else {
originalAdminLoginsCount = counts.get( "admin.logins" );
}
@@ -224,16 +218,14 @@ public class CounterIT extends AbstractCoreIT {
organizationEntity.setProperty( "name", orgName );
organizationEntity = em.create( organizationEntity );
- Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName );
- UUID applicationId =
- appInfo.getUuid();
+ Entity appInfo = setup.getEmf().createApplicationV2( orgName, appName );
+ UUID applicationId = appInfo.getUuid();
Map<String, Object> properties = new LinkedHashMap<String, Object>();
properties.put( "name", orgName + "/" + appName );
- Entity applicationEntity = em.create(
- applicationId, CpNamingUtils.APPLICATION_INFO, properties );
+ Entity applicationEntity = em.create( applicationId, CpNamingUtils.APPLICATION_INFO, properties );
-//Creating connections like below doesn't work.
+ //Creating connections like below doesn't work.
em.createConnection( organizationEntity.toTypedEntity(), "owns", applicationEntity );
@@ -259,22 +251,18 @@ public class CounterIT extends AbstractCoreIT {
// how to "count" a login to a specific application?
// when org is provided, why is it returning 8? Is it 4 with one 'event'?
- Results r = em.getAggregateCounters( null, null, null, "admin.logins",
- CounterResolution.ALL, ts, System.currentTimeMillis(), false );
+ Results r = em.getAggregateCounters( null, null, null, "admin.logins", CounterResolution.ALL, ts,
+ System.currentTimeMillis(), false );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
- assertEquals( 1,
- r.getCounters().get( 0 ).getValues().get( 0 ).getValue() - originalAdminLoginsCount );
+ assertEquals( 1, r.getCounters().get( 0 ).getValues().get( 0 ).getValue() - originalAdminLoginsCount );
r = em.getAggregateCounters( query );
LOG.info( JsonUtils.mapToJsonString( r.getCounters() ) );
- assertEquals( 1,
- r.getCounters().get( 0 ).getValues().get( 0 ).getValue() - originalCount );
+ assertEquals( 1, r.getCounters().get( 0 ).getValues().get( 0 ).getValue() - originalCount );
}
-
-
@Test
public void testTimedFlush() throws Exception {
LOG.info( "CounterIT.testCounters" );
@@ -309,16 +297,33 @@ public class CounterIT extends AbstractCoreIT {
//sleep to ensure the flush has executed
Thread.sleep( 30000 );
- Results r = em.getAggregateCounters( null, null, null, "visits", CounterResolution.SIX_HOUR, ts, System.currentTimeMillis(), false );
+
+ final long totalCount = returnCounts( em, "visits" );
+
+ assertEquals(200, totalCount);
+ }
+
+
+ private long returnCounts( final EntityManager em, final String counterName ) {
+ Results r = em.getAggregateCounters( null, null, null, counterName, CounterResolution.SIX_HOUR, ts,
+ System.currentTimeMillis(), false );
+
+
+
final AggregateCounterSet counter = r.getCounters().get( 0 );
- final long count = counter.getValues().get( 0 ).getValue();
+ assertEquals(counterName, counter.getName());
+
+ long count = 0;
+
+ for(final AggregateCounter value: counter.getValues()){
+ count += value.getValue();
+ }
+
+ return count;
- final String name = counter.getName();
- assertEquals("visits", name);
- assertEquals(200, count);
}
}