usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [11/31] usergrid git commit: Added a test for counters that isn't correctly configured to work with other tests yet, and added the counters to the backend of notifications for further examination.
Date Mon, 02 May 2016 21:29:29 GMT
Added a test for counters that isn't correctly configured to work with other tests yet, and
added the counters to the backend of notifications for further examination.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/7a08296a
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/7a08296a
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/7a08296a

Branch: refs/heads/master
Commit: 7a08296aed6776c50aebc886f1a24074e78d3b5d
Parents: 9553d44
Author: George Reyes <grey@apache.org>
Authored: Wed Apr 20 15:50:39 2016 -0700
Committer: George Reyes <grey@apache.org>
Committed: Wed Apr 20 15:50:39 2016 -0700

----------------------------------------------------------------------
 .../services/notifications/TaskManager.java     | 25 +++++++
 .../gcm/NotificationsServiceIT.java             | 77 ++++++++++++++++++++
 2 files changed, 102 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/7a08296a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
index 531ca7c..e908c3b 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/TaskManager.java
@@ -26,6 +26,8 @@ import org.apache.usergrid.persistence.entities.Receipt;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.time.Instant;
+import java.time.LocalDateTime;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -54,7 +56,13 @@ public class TaskManager {
 
         successes.incrementAndGet();
 
+
         try {
+            //.{year}.{month}.{day}.{HH24} possibly minute.
+            //random date and time for format
+
+
+            incrementNotificationCounter( "completed" );
 
             EntityRef deviceRef = new SimpleEntityRef(Device.ENTITY_TYPE, deviceUUID);
 
@@ -91,6 +99,9 @@ public class TaskManager {
         failures.incrementAndGet();
 
         try {
+
+            incrementNotificationCounter( "failed" );
+
             if (logger.isDebugEnabled()) {
                 logger.debug("Notification {} for device {} got error {}", notification.getUuid(),
deviceUUID, code);
             }
@@ -156,6 +167,20 @@ public class TaskManager {
         }
     }
 
+    public void incrementNotificationCounter(String status){
+        em.incrementAggregateCounters( null,null,null,"counters.notifications."+notification.getUuid()+"."+status,1
);
+
+        LocalDateTime localDateTime = LocalDateTime.now();
+        StringBuilder currentDate = new StringBuilder(  );
+        currentDate.append( "counters.notifications.aggregate."+status+"." );
+        currentDate.append( localDateTime.getYear()+"." );
+        currentDate.append( localDateTime.getMonth()+"." );
+        currentDate.append( localDateTime.getDayOfMonth()+"." );
+        currentDate.append( localDateTime.getMinute() );
+        em.incrementAggregateCounters( null,null,null,currentDate.toString(),1 );
+
+    }
+
 
     public void finishedBatch() throws Exception {
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/7a08296a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
index 77abb56..1a9f4f7 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java
@@ -19,14 +19,19 @@ package org.apache.usergrid.services.notifications.gcm;
 import com.google.android.gcm.server.Constants;
 import com.google.android.gcm.server.InvalidRequestException;
 import net.jcip.annotations.NotThreadSafe;
+
+import org.apache.usergrid.ServiceApplication;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.entities.*;
+import org.apache.usergrid.persistence.index.query.CounterResolution;
+import org.apache.usergrid.services.ServiceResults;
 import org.apache.usergrid.services.notifications.*;
 import org.junit.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.lang.reflect.Field;
+import java.time.LocalDateTime;
 import java.util.*;
 
 import org.apache.usergrid.services.ServiceAction;
@@ -304,6 +309,78 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
         checkReceipts(notification, 1);
     }
 
+    @Ignore("turn this on and run individually when you want to verify. there is an issue
with the aggregate counter, because of all the other tests"
+        + "AND, there is an issue with the batcher where we have to turn it up/down to see
the results in time. ")
+    @Test
+    public void singlePushNotificationWithCounters() throws Exception {
+
+        long ts = System.currentTimeMillis() - ( 24 * 60 * 60 * 1000 );
+        app.clear();
+        String payload = "Hello, World!";
+        Map<String, String> payloads = new HashMap<String, String>(1);
+        payloads.put(notifier.getUuid().toString(), payload);
+        app.put("payloads", payloads);
+        app.put("queued", System.currentTimeMillis());
+        app.put("debug", false);
+        app.put("expire", System.currentTimeMillis() + 300000); // add 5 minutes to current
time
+
+        Entity e = app.testRequest(ServiceAction.POST, 1, "devices", device1.getUuid(), "notifications").getEntity();
+        app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
+
+        Notification notification = app.getEntityManager().get(e.getUuid(), Notification.class);
+        assertEquals(
+            notification.getPayloads().get(notifier.getUuid().toString()),
+            payload);
+
+        // perform push //
+        notification = notificationWaitForComplete(notification);
+        //        checkReceipts(notification, 1);
+
+
+        verifyNotificationCounter( notification,"completed",ts,1 );
+        verifyNotificationCounter( notification,"failed",ts, 0 );
+
+
+
+
+    }
+
+    public void verifyNotificationCounter(Notification notification,String status,Long timestamp,
int expected){
+
+        Results countersResults = app.getEntityManager().getAggregateCounters( null,null,null,"counters.notifications."+notification.getUuid()+"."+status,
+            CounterResolution.ALL,timestamp,System.currentTimeMillis(),false ) ;
+
+        assertEquals( 1, countersResults.getCounters().size() );
+        if(expected > 0) {
+            assertEquals( expected, countersResults.getCounters().get( 0 ).getValues().get(
0 ).getValue() );
+        }else if (expected == 0){
+            assertEquals( 0,countersResults.getCounters().get( 0 ).getValues().size());
+        }
+
+        LocalDateTime localDateTime = LocalDateTime.now();
+        StringBuilder currentDate = new StringBuilder(  );
+        currentDate.append( "counters.notifications.aggregate."+status+"." );
+        currentDate.append( localDateTime.getYear()+"." );
+        currentDate.append( localDateTime.getMonth()+"." );
+        currentDate.append( localDateTime.getDayOfMonth()); //+"." );
+
+        countersResults = app.getEntityManager().getAggregateCounters( null,null,null,currentDate.toString(),
+            CounterResolution.ALL,timestamp,System.currentTimeMillis(),false ) ;
+
+        //checks to see that it exists
+        assertEquals( 1, countersResults.getCounters().size() );
+        if(expected > 0) {
+            assertEquals( expected, countersResults.getCounters().get( 0 ).getValues().get(
0 ).getValue() );
+
+        }
+        else if (expected == 0){
+            assertEquals( 0,countersResults.getCounters().get( 0 ).getValues().size());
+        }
+
+    }
+
+
+
     @Test
     public void singlePushNotificationMultipleDevices() throws Exception {
 


Mime
View raw message