usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [33/33] git commit: Fixes to get the singlePushNotification test (and other push tests) running. There were problems serializing enums, problems deserializing UUIDs, incorrect use of message UUID as a device UUID and some refresh index issues.
Date Fri, 05 Sep 2014 21:11:36 GMT
Fixes to get the singlePushNotification test (and other push tests) running. There were problems
serializing enums, problems deserializing UUIDs, incorrect use of message UUID as a device
UUID and some refresh index issues.


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

Branch: refs/heads/two-dot-o
Commit: 55e5c163c08d8351dfefc24cdd40e0bc3c32f51d
Parents: 93477bc
Author: Dave Johnson <dmjohnson@apigee.com>
Authored: Fri Sep 5 17:08:07 2014 -0400
Committer: Dave Johnson <dmjohnson@apigee.com>
Committed: Fri Sep 5 17:08:07 2014 -0400

----------------------------------------------------------------------
 .../corepersistence/CpEntityMapUtils.java       |  3 +++
 .../notifications/ApplicationQueueManager.java  |  4 ++-
 .../notifications/ApplicationQueueMessage.java  | 28 +++++++++++++++++++-
 .../apns/NotificationsServiceIT.java            | 20 ++++++++------
 4 files changed, 45 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
index 18eb7f9..6003093 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityMapUtils.java
@@ -109,6 +109,9 @@ public class CpEntityMapUtils {
 
             } else if ( value instanceof Map ) {
                 processMapValue( value, fieldName, entity, entityType);
+
+            } else if ( value instanceof Enum ) {
+                entity.setField( new StringField( fieldName, value.toString(), unique &&
topLevel ));
 	
 			} else if ( value != null ) {
                 byte[] valueSerialized;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
index c88702e..50b17bb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueManager.java
@@ -289,7 +289,9 @@ public class ApplicationQueueManager implements QueueManager {
                             @Override
                             public ApplicationQueueMessage call(ApplicationQueueMessage message)
{
                                 try {
-                                    UUID deviceUUID = message.getUuid();
+
+                                    UUID deviceUUID = message.getDeviceId();
+
                                     Notification notification = notificationMap.get(message.getNotificationId());
                                     if (notification == null) {
                                         notification = em.get(message.getNotificationId(),
Notification.class);

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
index f66fbf7..68c62d9 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/ApplicationQueueMessage.java
@@ -16,15 +16,21 @@
  */
 package org.apache.usergrid.services.notifications;
 
+import java.nio.ByteBuffer;
+import java.util.Arrays;
 import org.apache.usergrid.mq.Message;
 
 import java.util.UUID;
+import org.elasticsearch.common.primitives.Longs;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * Created by ApigeeCorporation on 9/4/14.
  */
 public class ApplicationQueueMessage extends Message {
 
+    private static final Logger log = LoggerFactory.getLogger(ApplicationQueueMessage.class);
 
     static final String MESSAGE_PROPERTY_DEVICE_UUID = "deviceUUID";
     static final String MESSAGE_PROPERTY_APPLICATION_UUID = "applicationUUID";
@@ -44,9 +50,29 @@ public class ApplicationQueueMessage extends Message {
         setNotifierId(notifierId);
     }
 
+    public static UUID bytesToUuid( byte[] sixteenBytes ) {
+        byte[] msBytes = Arrays.copyOfRange( sixteenBytes, 0, 8 );
+        byte[] lsBytes = Arrays.copyOfRange( sixteenBytes, 8, 16 );
+        long msb = Longs.fromByteArray( msBytes ); 
+        long lsb = Longs.fromByteArray( lsBytes ); 
+        return new UUID( msb, lsb );
+    }
 
     public static ApplicationQueueMessage generate(Message message) {
-        return new ApplicationQueueMessage(UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_APPLICATION_UUID)),
UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_NOTIFICATION_ID)), UUID.fromString(message.getStringProperty(MESSAGE_PROPERTY_DEVICE_UUID)),
message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME), message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID));
+
+        // this crazyness may indicate that Core Persistence is not storing UUIDs correctly
+        byte[] mpaBytes = (byte[])message.getObjectProperty(MESSAGE_PROPERTY_APPLICATION_UUID);
+        UUID mpaUuid = bytesToUuid(mpaBytes);
+        byte[] mpnBytes = (byte[])message.getObjectProperty(MESSAGE_PROPERTY_NOTIFICATION_ID);
+        UUID mpnUuid = bytesToUuid(mpnBytes);
+        // end of crazyness
+
+        UUID mpdUuid = (UUID)message.getObjectProperty(MESSAGE_PROPERTY_DEVICE_UUID);
+
+        return new ApplicationQueueMessage(
+                mpaUuid, mpnUuid, mpdUuid,
+                message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_NAME), 
+                message.getStringProperty(MESSAGE_PROPERTY_NOTIFIER_ID));
     }
 
     public UUID getApplicationId() {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/55e5c163/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
index c0b8cdd..41eb376 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java
@@ -31,8 +31,6 @@ import org.slf4j.LoggerFactory;
 import java.io.InputStream;
 import java.net.SocketException;
 import java.util.*;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
 
 import org.apache.usergrid.services.ServiceAction;
 
@@ -147,6 +145,9 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
 
         // create push notification //
 
+        app.getEm().refreshIndex();
+
+        // give queue manager a query for loading 100 devices from an application (why?)
         app.clear();
         Query pQuery = new Query();
         pQuery.setLimit(100);
@@ -155,24 +156,25 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
         pQuery.addIdentifier(new ServiceParameter.NameParameter(device1.getUuid().toString()).getIdentifier());
         ns.getQueueManager().TEST_PATH_QUERY =  new PathQuery( new SimpleEntityRef(app.getEm().getApplicationRef()),
pQuery);
 
-
+        // create a "hellow world" notification
         String payload = getPayload();
         Map<String, String> payloads = new HashMap<String, String>(1);
         payloads.put(notifier.getName().toString(), payload);
         app.put("payloads", payloads);
         app.put("queued", System.currentTimeMillis());
 
-        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications")
-                .getEntity();
+        // post notification to service manager
+        Entity e = app.testRequest(ServiceAction.POST, 1, "notifications").getEntity();
+
+        // ensure notification it was created
         app.testRequest(ServiceAction.GET, 1, "notifications", e.getUuid());
 
-        Notification notification = app.getEm().get(e.getUuid(),
-                Notification.class);
+        // ensure notification has expected name
+        Notification notification = app.getEm().get(e.getUuid(), Notification.class);
         assertEquals(
                 notification.getPayloads().get(notifier.getName().toString()),
                 payload);
 
-
         // verify Query for CREATED state
         Query query = new Query();
         query.addEqualityFilter("state", Notification.State.STARTED.toString());
@@ -185,6 +187,8 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT
{
 
         notification = scheduleNotificationAndWait(notification);
 
+        app.getEm().refreshIndex();
+
         // verify Query for FINISHED state
         query = new Query();
         query.addEqualityFilter("state", Notification.State.FINISHED.toString());


Mime
View raw message