1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.ken.services.impl;
17
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
21 import org.kuali.rice.ken.service.NotificationMessageDeliveryAutoRemovalService;
22 import org.kuali.rice.ken.service.ProcessingResult;
23 import org.kuali.rice.ken.test.KENTestCase;
24 import org.kuali.rice.ken.util.NotificationConstants;
25 import org.kuali.rice.test.BaselineTestCase;
26
27 import java.util.Collection;
28 import java.util.HashMap;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33
34
35
36
37
38
39
40 @Ignore
41 public class NotificationMessageDeliveryAutoRemovalServiceImplTest extends KENTestCase {
42
43 private static final int EXPECTED_SUCCESSES = 6;
44
45 protected void assertProcessResults() {
46
47 Collection<NotificationMessageDelivery> lockedDeliveries = services.getNotificationMessegDeliveryDao().getLockedDeliveries(NotificationMessageDelivery.class, services.getGenericDao());
48
49 assertEquals(0, lockedDeliveries.size());
50
51
52 HashMap<String, String> queryCriteria = new HashMap<String, String>();
53 queryCriteria.put(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS, NotificationConstants.MESSAGE_DELIVERY_STATUS.AUTO_REMOVED);
54 Collection<NotificationMessageDelivery> unprocessedDeliveries = services.getGenericDao().findMatching(NotificationMessageDelivery.class, queryCriteria);
55 assertEquals(EXPECTED_SUCCESSES, unprocessedDeliveries.size());
56 }
57
58
59
60
61 @Test
62 public void testAutoRemovedNotificationMessageDeliveries() {
63 NotificationMessageDeliveryAutoRemovalService nSvc = services.getNotificationMessageDeliveryAutoRemovalService();
64
65 services.getNotificationMessageDeliveryResolverService().resolveNotificationMessageDeliveries();
66
67 ProcessingResult result = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
68
69 assertEquals(0, result.getFailures().size());
70 assertEquals(EXPECTED_SUCCESSES, result.getSuccesses().size());
71
72 assertProcessResults();
73 }
74
75
76
77
78 @Test
79 public void testAutoRemovalConcurrency() throws InterruptedException {
80 final NotificationMessageDeliveryAutoRemovalService nSvc = services.getNotificationMessageDeliveryAutoRemovalService();
81
82 services.getNotificationMessageDeliveryResolverService().resolveNotificationMessageDeliveries();
83
84 final ProcessingResult[] results = new ProcessingResult[2];
85 Thread t1 = new Thread(new Runnable() {
86 public void run() {
87 results[0] = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
88 }
89 });
90 Thread t2 = new Thread(new Runnable() {
91 public void run() {
92 results[1] = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
93 }
94 });
95
96 t1.start();
97 t2.start();
98
99 t1.join();
100 t2.join();
101
102
103 LOG.info("Results of thread #1: " + results[0]);
104 LOG.info("Results of thread #2: " + results[1]);
105 assertTrue((results[0].getSuccesses().size() == EXPECTED_SUCCESSES && results[0].getFailures().size() == 0 && results[1].getSuccesses().size() == 0 && results[1].getFailures().size() == 0) ||
106 (results[1].getSuccesses().size() == EXPECTED_SUCCESSES && results[1].getFailures().size() == 0 && results[0].getSuccesses().size() == 0 && results[0].getFailures().size() == 0));
107
108 assertProcessResults();
109 }
110 }