1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kim.test.service;
17
18 import java.util.ArrayList;
19 import java.util.Collections;
20 import java.util.List;
21 import java.util.UUID;
22
23 import org.junit.Ignore;
24 import org.junit.Test;
25 import org.kuali.rice.core.config.ConfigContext;
26 import org.kuali.rice.kim.bo.entity.dto.KimEntityDefaultInfo;
27 import org.kuali.rice.kim.bo.entity.dto.KimPrincipalInfo;
28 import org.kuali.rice.kim.bo.entity.impl.KimEntityDefaultInfoCacheImpl;
29 import org.kuali.rice.kim.service.IdentityArchiveService;
30 import org.kuali.rice.kim.service.KIMServiceLocator;
31 import org.kuali.rice.kim.service.impl.IdentityArchiveServiceImpl;
32 import org.kuali.rice.kim.test.KIMTestCase;
33 import org.kuali.rice.kns.service.KNSServiceLocator;
34
35
36
37
38
39
40 @Ignore
41 public class IdentityArchiveServiceTest extends KIMTestCase {
42
43 private IdentityArchiveService identityArchiveService;
44
45 public void setUp() throws Exception {
46 super.setUp();
47 KNSServiceLocator.getBusinessObjectService().deleteMatching(KimEntityDefaultInfoCacheImpl.class, Collections.emptyMap());
48 if (null == identityArchiveService) {
49 identityArchiveService = KIMServiceLocator.getIdentityArchiveService();
50 }
51 }
52
53
54
55
56
57
58
59
60 @Test
61 public void testArchiveFlushesWhenQueueIsFull() throws Exception {
62 final int maxWriteQueueSize =
63 Integer.valueOf(ConfigContext.getCurrentContextConfig().getProperty("kim.identityArchiveServiceImpl.maxWriteQueueSize"));
64
65 List<KimEntityDefaultInfo> added = new ArrayList<KimEntityDefaultInfo>();
66
67
68 for (int i=1; i<=maxWriteQueueSize; i++) {
69 MinimalKEDIBuilder builder = new MinimalKEDIBuilder("bogusUser" + i);
70 builder.setEntityId("bogusUser" + i);
71 KimEntityDefaultInfo bogusUserInfo = builder.build();
72
73 KimEntityDefaultInfo retrieved = identityArchiveService.getEntityDefaultInfoFromArchiveByPrincipalId(builder.getPrincipalId());
74 assertNull(retrieved);
75 retrieved = identityArchiveService.getEntityDefaultInfoFromArchiveByPrincipalName(builder.getPrincipalName());
76 assertNull(retrieved);
77 retrieved = identityArchiveService.getEntityDefaultInfoFromArchive(builder.getEntityId());
78 assertNull(retrieved);
79
80 identityArchiveService.saveDefaultInfoToArchive(bogusUserInfo);
81 added.add(bogusUserInfo);
82 }
83
84
85 log.info("Sleeping, hoping for a flush to occur!");
86 Thread.sleep(1000);
87 log.info("Done sleeping!");
88
89
90
91 for (KimEntityDefaultInfo kedi : added) {
92
93 KimEntityDefaultInfo retrieved = identityArchiveService.getEntityDefaultInfoFromArchiveByPrincipalId(kedi.getPrincipals().get(0).getPrincipalId());
94 assertTrue(kedi.getPrincipals().get(0).getPrincipalId().equals(retrieved.getPrincipals().get(0).getPrincipalId()));
95 retrieved = identityArchiveService.getEntityDefaultInfoFromArchiveByPrincipalName(kedi.getPrincipals().get(0).getPrincipalName());
96 assertTrue(kedi.getPrincipals().get(0).getPrincipalId().equals(retrieved.getPrincipals().get(0).getPrincipalId()));
97 retrieved = identityArchiveService.getEntityDefaultInfoFromArchive(kedi.getEntityId());
98 assertTrue(kedi.getPrincipals().get(0).getPrincipalId().equals(retrieved.getPrincipals().get(0).getPrincipalId()));
99 }
100 }
101
102 private static class MinimalKEDIBuilder {
103 private String entityId;
104 private String principalId;
105 private String principalName;
106 private Boolean active;
107
108 public MinimalKEDIBuilder(String name) {
109 entityId = UUID.randomUUID().toString();
110 principalId = principalName = name;
111 }
112
113 public KimEntityDefaultInfo build() {
114 if (entityId == null) entityId = UUID.randomUUID().toString();
115 if (principalId == null) principalId = UUID.randomUUID().toString();
116 if (principalName == null) principalName = principalId;
117 if (active == null) active = true;
118
119 KimPrincipalInfo principal = new KimPrincipalInfo();
120 principal.setActive(active);
121 principal.setEntityId(entityId);
122 principal.setPrincipalId(principalId);
123 principal.setPrincipalName(principalName);
124
125 KimEntityDefaultInfo kedi = new KimEntityDefaultInfo();
126 kedi.setPrincipals(Collections.singletonList(principal));
127 kedi.setEntityId(entityId);
128
129 return kedi;
130 }
131
132
133
134
135 public String getEntityId() {
136 return this.entityId;
137 }
138
139
140
141
142 public void setEntityId(String entityId) {
143 this.entityId = entityId;
144 }
145
146
147
148
149 public String getPrincipalId() {
150 return this.principalId;
151 }
152
153
154
155
156 public void setPrincipalId(String principalId) {
157 this.principalId = principalId;
158 }
159
160
161
162
163 public String getPrincipalName() {
164 return this.principalName;
165 }
166
167
168
169
170 public void setPrincipalName(String principalName) {
171 this.principalName = principalName;
172 }
173
174
175
176
177 public Boolean getActive() {
178 return this.active;
179 }
180
181
182
183
184 public void setActive(Boolean active) {
185 this.active = active;
186 }
187
188
189 }
190
191 }