You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by md...@apache.org on 2016/05/05 16:59:40 UTC
[1/2] usergrid git commit: Changed notification object to accept both
Integers and Long in the map.
Repository: usergrid
Updated Branches:
refs/heads/9f45130_app_cache_fix 26959622a -> 4c1ece97c
Changed notification object to accept both Integers and Long in the map.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/a737708f
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/a737708f
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/a737708f
Branch: refs/heads/9f45130_app_cache_fix
Commit: a737708f12ff9d48ae69c122cecba943334b29c6
Parents: 2695962
Author: George Reyes <gr...@apache.org>
Authored: Wed May 4 16:54:33 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Wed May 4 16:54:33 2016 -0700
----------------------------------------------------------------------
.../persistence/entities/Notification.java | 37 +++++++----
.../impl/ApplicationQueueManagerImpl.java | 66 +++++++++++++++-----
.../AbstractServiceNotificationIT.java | 26 +++-----
3 files changed, 86 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
index 5c3ee89..26b6595 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/entities/Notification.java
@@ -17,16 +17,26 @@
package org.apache.usergrid.persistence.entities;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
import javax.xml.bind.annotation.XmlRootElement;
-import java.util.*;
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.TypedEntity;
import org.apache.usergrid.persistence.annotations.EntityCollection;
import org.apache.usergrid.persistence.annotations.EntityProperty;
import org.apache.usergrid.persistence.index.query.Identifier;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+
/**
* The entity class for representing Notifications.
*/
@@ -99,7 +109,7 @@ public class Notification extends TypedEntity {
/** Map containing a count for "sent" and "errors" */
@EntityProperty
- protected Map<String, Long> statistics;
+ protected Map<String, Object> statistics;
public Notification() {
@@ -228,23 +238,28 @@ public class Notification extends TypedEntity {
}
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
- public Map<String, Long> getStatistics() {
+ public Map<String, Object> getStatistics() {
return statistics;
}
- public void setStatistics(Map<String, Long> statistics) {
+ public void setStatistics(Map<String, Object> statistics) {
this.statistics = statistics;
}
public void updateStatistics(long sent, long errors) {
if (this.statistics == null) {
- this.statistics = new HashMap<String, Long>(2);
+ this.statistics = new HashMap<String, Object>(2);
this.statistics.put("sent", sent);
this.statistics.put("errors", errors);
} else {
- this.statistics.put("sent", sent + this.statistics.get("sent"));
- this.statistics.put("errors",
- errors + this.statistics.get("errors"));
+ if(this.statistics.get( "sent" ) instanceof Integer){
+ this.statistics.put( "sent", sent + (Integer) this.statistics.get( "sent" ) );
+ this.statistics.put( "errors", errors + (Integer) this.statistics.get( "errors" ) );
+ }
+ else if (this.statistics.get( "sent" ) instanceof Long ) {
+ this.statistics.put( "sent", sent + (Long) this.statistics.get( "sent" ) );
+ this.statistics.put( "errors", errors + (Long) this.statistics.get( "errors" ) );
+ }
}
}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
index 12a47b6..6a8a4c8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/impl/ApplicationQueueManagerImpl.java
@@ -16,28 +16,52 @@
*/
package org.apache.usergrid.services.notifications.impl;
-import com.codahale.metrics.Meter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import org.apache.usergrid.batch.JobExecution;
-import org.apache.usergrid.persistence.*;
+import org.apache.usergrid.persistence.Entity;
+import org.apache.usergrid.persistence.EntityManager;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.ResultsIterator;
+import org.apache.usergrid.persistence.SimpleEntityRef;
import org.apache.usergrid.persistence.core.metrics.MetricsFactory;
import org.apache.usergrid.persistence.entities.Device;
import org.apache.usergrid.persistence.entities.Notification;
import org.apache.usergrid.persistence.entities.Notifier;
import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.Query;
import org.apache.usergrid.persistence.queue.QueueManager;
import org.apache.usergrid.persistence.queue.QueueMessage;
-import org.apache.usergrid.services.notifications.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.apache.usergrid.services.notifications.ApplicationQueueManager;
+import org.apache.usergrid.services.notifications.ApplicationQueueMessage;
+import org.apache.usergrid.services.notifications.JobScheduler;
+import org.apache.usergrid.services.notifications.NotificationsService;
+import org.apache.usergrid.services.notifications.ProviderAdapter;
+import org.apache.usergrid.services.notifications.ProviderAdapterFactory;
+import org.apache.usergrid.services.notifications.TaskManager;
+import org.apache.usergrid.services.notifications.TaskTracker;
+
+import com.codahale.metrics.Meter;
+
import rx.Observable;
import rx.Subscriber;
import rx.functions.Func1;
-import java.util.*;
-import java.util.concurrent.*;
-import java.util.concurrent.atomic.AtomicInteger;
-
public class ApplicationQueueManagerImpl implements ApplicationQueueManager {
@@ -460,13 +484,23 @@ public class ApplicationQueueManagerImpl implements ApplicationQueueManager {
private boolean isOkToSend(Notification notification) {
- Map<String, Long> stats = notification.getStatistics();
- if (stats != null && notification.getExpectedCount() == (stats.get("sent") + stats.get("errors"))) {
- if (logger.isDebugEnabled()) {
- logger.debug("notification {} already processed. not sending.",
- notification.getUuid());
+ Map<String, Object> stats = notification.getStatistics();
+ if(stats!=null && stats.get( "sent" )instanceof Integer) {
+ if ( notification.getExpectedCount() == ( (Integer ) stats.get( "sent" ) + (Integer ) stats.get( "errors" ) ) ) {
+ if ( logger.isDebugEnabled() ) {
+ logger.debug( "notification {} already processed. not sending.", notification.getUuid() );
+ }
+ return false;
+ }
+ }
+
+ else if(stats !=null && stats.get( "sent" )instanceof Long) {
+ if ( notification.getExpectedCount() == ( ( Long ) stats.get( "sent" ) + ( Long ) stats.get( "errors" ) ) ) {
+ if ( logger.isDebugEnabled() ) {
+ logger.debug( "notification {} already processed. not sending.", notification.getUuid() );
+ }
+ return false;
}
- return false;
}
if (notification.getCanceled() == Boolean.TRUE) {
if (logger.isDebugEnabled()) {
http://git-wip-us.apache.org/repos/asf/usergrid/blob/a737708f/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
index 91b94b2..775827e 100644
--- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/AbstractServiceNotificationIT.java
@@ -16,24 +16,18 @@
*/
package org.apache.usergrid.services.notifications;
-import org.apache.usergrid.persistence.*;
-import org.apache.usergrid.persistence.entities.Notification;
-import org.apache.usergrid.persistence.entities.Receipt;
-import org.apache.usergrid.persistence.Query;
-import org.apache.usergrid.services.ServiceManagerFactory;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.rules.TestName;
-
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import org.apache.usergrid.persistence.EntityRef;
+import org.apache.usergrid.persistence.PathQuery;
+import org.apache.usergrid.persistence.Query;
+import org.apache.usergrid.persistence.SimpleEntityRef;
+import org.apache.usergrid.persistence.entities.Notification;
+import org.apache.usergrid.persistence.entities.Receipt;
import org.apache.usergrid.services.AbstractServiceIT;
-import org.springframework.beans.factory.annotation.Autowired;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -106,17 +100,17 @@ public abstract class AbstractServiceNotificationIT extends AbstractServiceIT {
}
protected void checkStatistics(Notification notification, long sent, long errors) throws Exception{
- Map<String, Long> statistics = null;
+ Map<String, Object> statistics = null;
long timeout = System.currentTimeMillis() + 10000;
while (System.currentTimeMillis() < timeout) {
Thread.sleep(200);
statistics = app.getEntityManager().get(notification.getUuid(), Notification.class).getStatistics();
- if (statistics.get("sent")==sent && statistics.get("errors")==errors) {
+ if ((Long)statistics.get("sent")==sent && (Long)statistics.get("errors")==errors) {
break;
}
}
- assertEquals(sent, statistics.get("sent").longValue());
- assertEquals(errors, statistics.get("errors").longValue());
+ assertEquals(sent, ((Long)statistics.get("sent")).longValue());
+ assertEquals(errors, ((Long)statistics.get("errors")).longValue());
}
}
[2/2] usergrid git commit: Added a test proving the issue was fixed.
Posted by md...@apache.org.
Added a test proving the issue was fixed.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/4c1ece97
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/4c1ece97
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/4c1ece97
Branch: refs/heads/9f45130_app_cache_fix
Commit: 4c1ece97c588b8f2c8edceaa70796da9873d714c
Parents: a737708
Author: George Reyes <gr...@apache.org>
Authored: Thu May 5 09:29:03 2016 -0700
Committer: George Reyes <gr...@apache.org>
Committed: Thu May 5 09:29:03 2016 -0700
----------------------------------------------------------------------
.../collection/CollectionsResourceIT.java | 70 ++++++++++++++++----
1 file changed, 58 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/4c1ece97/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
index 9752035..5c98f9c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/CollectionsResourceIT.java
@@ -17,29 +17,36 @@
package org.apache.usergrid.rest.applications.collection;
-import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+
+import javax.ws.rs.ClientErrorException;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.apache.usergrid.persistence.Schema;
import org.apache.usergrid.persistence.entities.Application;
+import org.apache.usergrid.persistence.index.utils.UUIDUtils;
import org.apache.usergrid.rest.test.resource.AbstractRestIT;
import org.apache.usergrid.rest.test.resource.model.ApiResponse;
import org.apache.usergrid.rest.test.resource.model.Collection;
import org.apache.usergrid.rest.test.resource.model.Entity;
import org.apache.usergrid.rest.test.resource.model.QueryParameters;
import org.apache.usergrid.rest.test.resource.model.Token;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.ws.rs.ClientErrorException;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
+import com.fasterxml.jackson.databind.JsonNode;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.fail;
/**
@@ -311,4 +318,43 @@ public class CollectionsResourceIT extends AbstractRestIT {
Assert.assertEquals( "Should not be more than one name property", -1, secondFred );
*/
}
+
+ @Test
+ public void testBeingAbleToRetreiveMigratedValues() throws Exception {
+
+
+ Entity notifier = new Entity().chainPut("name", "mynotifier").chainPut("provider", "noop");
+
+ ApiResponse notifierNode = this.pathResource(getOrgAppPath("notifier")).post(ApiResponse.class,notifier);
+
+ UUID uuid = UUIDUtils.newTimeUUID();
+ // create user
+
+ Map payloads = new HashMap<>( );
+ payloads.put( "mynotifier","hello world" );
+
+ Map statistics = new HashMap<>( );
+ statistics.put( "sent",1 );
+ statistics.put( "errors",0 );
+
+ Entity payload = new Entity();
+ payload.put("debug", false);
+ payload.put( "expectedCount",0 );
+ payload.put( "finished",1438279671229L);
+ payload.put( "payloads",payloads);
+ payload.put( "priority","normal");
+ payload.put( "state","FINISHED");
+ payload.put( "statistics",statistics);
+
+
+
+
+ ApiResponse user = this.app().collection("notifications/"+ UUIDUtils.newTimeUUID()).put(null,payload );
+ this.refreshIndex();
+
+ Collection user2 = this.app().collection("notifications").get();
+
+ assertEquals(1,user2.getNumOfEntities());
+
+ }
}