From 461c1928beae05c78646ac727f20e0afe7d6f3fb Mon Sep 17 00:00:00 2001 From: Shawn Feldman Date: Mon, 8 Dec 2014 11:03:48 -0700 Subject: [PATCH 1/4] remove queue manager --- .../queue/DefaultQueueManager.java} | 39 ++++++++++--------- .../apns/NotificationsServiceIT.java | 4 +- .../gcm/NotificationsServiceIT.java | 4 +- 3 files changed, 25 insertions(+), 22 deletions(-) rename stack/{services/src/test/java/org/apache/usergrid/services/TestQueueManager.java => corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java} (55%) diff --git a/stack/services/src/test/java/org/apache/usergrid/services/TestQueueManager.java b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java similarity index 55% rename from stack/services/src/test/java/org/apache/usergrid/services/TestQueueManager.java rename to stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java index 37fef408b3..354aa7bc2f 100644 --- a/stack/services/src/test/java/org/apache/usergrid/services/TestQueueManager.java +++ b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java @@ -1,23 +1,24 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. The ASF licenses this file to You + * * under the Apache License, Version 2.0 (the "License"); you may not + * * use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. For additional information regarding + * * copyright in this work, please see the NOTICE file in the top level + * * directory of this distribution. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. */ -package org.apache.usergrid.services; -import org.apache.usergrid.persistence.queue.QueueManager; -import org.apache.usergrid.persistence.queue.QueueMessage; +package org.apache.usergrid.persistence.queue; import java.io.IOException; import java.util.ArrayList; @@ -25,8 +26,10 @@ import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; - -public class TestQueueManager implements QueueManager { +/** + * Default queue manager implementation, uses in memory linked queue + */ +public class DefaultQueueManager implements QueueManager { public ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue<>(); @Override public synchronized List getMessages(int limit, int transactionTimeout, int waitTime, Class klass) { @@ -62,4 +65,4 @@ public synchronized void sendMessage(Object body) throws IOException { String uuid = UUID.randomUUID().toString(); queue.add(new QueueMessage(uuid,"handle_"+uuid,body)); } -} +} \ No newline at end of file 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 0a5375fda2..3f42777610 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 @@ -21,7 +21,7 @@ import org.apache.usergrid.persistence.*; import org.apache.usergrid.persistence.entities.*; import org.apache.usergrid.persistence.index.query.Query; -import org.apache.usergrid.services.TestQueueManager; +import org.apache.usergrid.persistence.queue.DefaultQueueManager; import org.apache.usergrid.services.notifications.*; import org.junit.*; import org.slf4j.Logger; @@ -121,7 +121,7 @@ public void before() throws Exception { ns = getNotificationService(); - TestQueueManager qm = new TestQueueManager(); + DefaultQueueManager qm = new DefaultQueueManager(); ns.TEST_QUEUE_MANAGER = qm; app.getEntityManager().refreshIndex(); 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 52284641c8..4b41d13cdc 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 @@ -18,7 +18,7 @@ import org.apache.usergrid.persistence.*; import org.apache.usergrid.persistence.entities.*; -import org.apache.usergrid.services.TestQueueManager; +import org.apache.usergrid.persistence.queue.DefaultQueueManager; import org.apache.usergrid.services.notifications.*; import org.junit.*; import org.slf4j.Logger; @@ -93,7 +93,7 @@ public void before() throws Exception { device2 = app.getEntityManager().get(e.getUuid(), Device.class); ns = getNotificationService(); - TestQueueManager qm = new TestQueueManager(); + DefaultQueueManager qm = new DefaultQueueManager(); ns.TEST_QUEUE_MANAGER = qm; listener = new QueueListener(ns.getServiceManagerFactory(), ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties()); From 622491547fe0ea42a7c7bbd63611c804023caa7f Mon Sep 17 00:00:00 2001 From: Shawn Feldman Date: Mon, 8 Dec 2014 12:34:14 -0700 Subject: [PATCH 2/4] fix apns --- .../services/notifications/apns/NotificationsServiceIT.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 3f42777610..3b9206e656 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 @@ -191,8 +191,8 @@ public void singlePushNotification() throws Exception { entity = results.getEntitiesMap().get(notification.getUuid()); assertNotNull(entity); - checkReceipts(notification, 1); - checkStatistics(notification, 1, 0); + checkReceipts(notification, 2); + checkStatistics(notification, 2, 0); } @Test @@ -579,7 +579,7 @@ public void oneDeviceTwoNotifiers() throws Exception { app.getEntityManager().refreshIndex(); - checkReceipts(notification, 1); + checkReceipts(notification, 2); } @Ignore("todo: how can I mock this?") From e9cecff1d0df14691c021fb682a9f84bdb3382ed Mon Sep 17 00:00:00 2001 From: Shawn Feldman Date: Mon, 8 Dec 2014 12:36:24 -0700 Subject: [PATCH 3/4] fix gcm --- .../services/notifications/gcm/NotificationsServiceIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 4b41d13cdc..ce0dca762a 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 @@ -163,7 +163,7 @@ public void singlePushNotification() throws Exception { // perform push // notification = scheduleNotificationAndWait(notification); - checkReceipts(notification, 1); + checkReceipts(notification, 2); } @Test From 4bf4d715fc11877d672541e0aa04714f7f0c2a9d Mon Sep 17 00:00:00 2001 From: Shawn Feldman Date: Mon, 8 Dec 2014 15:15:00 -0700 Subject: [PATCH 4/4] fixed abstract class name --- .../persistence/queue/DefaultQueueManager.java | 4 ++-- .../AbstractServiceNotificationIT.java | 16 +--------------- .../apns/NotificationsServiceIT.java | 2 -- .../gcm/NotificationsServiceIT.java | 9 +++++++-- 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java index 354aa7bc2f..d9fddd39ef 100644 --- a/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java +++ b/stack/corepersistence/queue/src/main/java/org/apache/usergrid/persistence/queue/DefaultQueueManager.java @@ -24,13 +24,13 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.ArrayBlockingQueue; /** * Default queue manager implementation, uses in memory linked queue */ public class DefaultQueueManager implements QueueManager { - public ConcurrentLinkedQueue queue = new ConcurrentLinkedQueue<>(); + public ArrayBlockingQueue queue = new ArrayBlockingQueue<>(10000); @Override public synchronized List getMessages(int limit, int transactionTimeout, int waitTime, Class klass) { List returnQueue = new ArrayList<>(); 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 1fd6f3e271..55bb91f398 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 @@ -39,28 +39,14 @@ import static org.junit.Assert.fail; -public class AbstractServiceNotificationIT extends AbstractServiceIT { +public abstract class AbstractServiceNotificationIT extends AbstractServiceIT { private NotificationsService ns; - @Rule - public TestName name = new TestName(); - - @BeforeClass - public static void beforeClass() { - } - - @Before - public void before() throws Exception { - - } - protected NotificationsService getNotificationService(){ ns = (NotificationsService) app.getSm().getService("notifications"); return ns; } - - protected Notification scheduleNotificationAndWait(Notification notification) throws Exception { long timeout = System.currentTimeMillis() + 60000; 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 3b9206e656..5fda74b832 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 @@ -68,11 +68,9 @@ public static void setup(){ } - @Override @Before public void before() throws Exception { - super.before(); // create apns notifier // app.clear(); app.put("name", notifierName); 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 ce0dca762a..8d6fb7077d 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 @@ -21,6 +21,7 @@ import org.apache.usergrid.persistence.queue.DefaultQueueManager; import org.apache.usergrid.services.notifications.*; import org.junit.*; +import org.junit.rules.TestName; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +35,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT { + private static final Logger logger = LoggerFactory .getLogger(NotificationsServiceIT.class); @@ -54,15 +56,18 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT { private NotificationsService ns; private QueueListener listener; + + + + @BeforeClass public static void setup(){ + } - @Override @Before public void before() throws Exception { - super.before(); // create gcm notifier //