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.core.api.criteria.QueryByCriteria;
21 import org.kuali.rice.ken.bo.NotificationMessageDelivery;
22 import org.kuali.rice.ken.service.NotificationMessageDeliveryAutoRemovalService;
23 import org.kuali.rice.ken.service.ProcessingResult;
24 import org.kuali.rice.ken.test.KENTestCase;
25 import org.kuali.rice.ken.util.NotificationConstants;
26 import org.kuali.rice.krad.service.KRADServiceLocator;
27
28 import java.util.Collection;
29
30 import static org.junit.Assert.assertEquals;
31 import static org.junit.Assert.assertTrue;
32
33 import static org.kuali.rice.core.api.criteria.PredicateFactory.equal;
34 import static org.kuali.rice.core.api.criteria.PredicateFactory.isNotNull;
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 = getLockedDeliveries();
48
49 assertEquals(0, lockedDeliveries.size());
50
51
52 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
53 criteria.setPredicates(equal(NotificationConstants.BO_PROPERTY_NAMES.MESSAGE_DELIVERY_STATUS,
54 NotificationConstants.MESSAGE_DELIVERY_STATUS.AUTO_REMOVED));
55 Collection<NotificationMessageDelivery> unprocessedDeliveries =
56 KRADServiceLocator.getDataObjectService().findMatching(NotificationMessageDelivery.class,
57 criteria.build()).getResults();
58
59 assertEquals(EXPECTED_SUCCESSES, unprocessedDeliveries.size());
60 }
61
62
63
64
65 @Test
66 public void testAutoRemovedNotificationMessageDeliveries() {
67 NotificationMessageDeliveryAutoRemovalService nSvc = services.getNotificationMessageDeliveryAutoRemovalService();
68
69 services.getNotificationMessageDeliveryResolverService().resolveNotificationMessageDeliveries();
70
71 ProcessingResult result = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
72
73 assertEquals(0, result.getFailures().size());
74 assertEquals(EXPECTED_SUCCESSES, result.getSuccesses().size());
75
76 assertProcessResults();
77 }
78
79
80
81
82 @Test
83 public void testAutoRemovalConcurrency() throws InterruptedException {
84 final NotificationMessageDeliveryAutoRemovalService nSvc = services.getNotificationMessageDeliveryAutoRemovalService();
85
86 services.getNotificationMessageDeliveryResolverService().resolveNotificationMessageDeliveries();
87
88 final ProcessingResult[] results = new ProcessingResult[2];
89 Thread t1 = new Thread(new Runnable() {
90 public void run() {
91 results[0] = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
92 }
93 });
94 Thread t2 = new Thread(new Runnable() {
95 public void run() {
96 results[1] = nSvc.processAutoRemovalOfDeliveredNotificationMessageDeliveries();
97 }
98 });
99
100 t1.start();
101 t2.start();
102
103 t1.join();
104 t2.join();
105
106
107 LOG.info("Results of thread #1: " + results[0]);
108 LOG.info("Results of thread #2: " + results[1]);
109 assertTrue((results[0].getSuccesses().size() == EXPECTED_SUCCESSES && results[0].getFailures().size() == 0 &&
110 results[1].getSuccesses().size() == 0 && results[1].getFailures().size() == 0) ||
111 (results[1].getSuccesses().size() == EXPECTED_SUCCESSES && results[1].getFailures().size() == 0 &&
112 results[0].getSuccesses().size() == 0 && results[0].getFailures().size() == 0));
113
114 assertProcessResults();
115
116 }
117
118
119
120
121
122 protected Collection<NotificationMessageDelivery> getLockedDeliveries() {
123 QueryByCriteria.Builder criteria = QueryByCriteria.Builder.create();
124 criteria.setPredicates(isNotNull(NotificationConstants.BO_PROPERTY_NAMES.LOCKED_DATE));
125 Collection<NotificationMessageDelivery> lockedDeliveries = KRADServiceLocator.getDataObjectService().findMatching(
126 NotificationMessageDelivery.class, criteria.build()).getResults();
127
128 return null;
129 }
130 }