1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.test.cluster; |
21 |
|
|
22 |
|
import org.junit.Assert; |
23 |
|
import org.junit.Test; |
24 |
|
import org.xwiki.model.reference.AttachmentReference; |
25 |
|
import org.xwiki.model.reference.DocumentReference; |
26 |
|
import org.xwiki.model.reference.LocalDocumentReference; |
27 |
|
import org.xwiki.rest.model.jaxb.Attachment; |
28 |
|
import org.xwiki.rest.model.jaxb.Attachments; |
29 |
|
import org.xwiki.rest.model.jaxb.Page; |
30 |
|
import org.xwiki.rest.resources.attachments.AttachmentsResource; |
31 |
|
import org.xwiki.test.cluster.framework.AbstractClusterHttpTest; |
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
@version |
37 |
|
|
|
|
| 70.7% |
Uncovered Elements: 24 (82) |
Complexity: 11 |
Complexity Density: 0.17 |
|
38 |
|
public class DocumentCacheTest extends AbstractClusterHttpTest |
39 |
|
{ |
40 |
|
private final static String TEST_SPACE = "Test"; |
41 |
|
|
|
|
| 68% |
Uncovered Elements: 8 (25) |
Complexity: 3 |
Complexity Density: 0.14 |
1PASS
|
|
42 |
1 |
@Test... |
43 |
|
public void testDocumentModifiedCacheSync() throws Exception |
44 |
|
{ |
45 |
1 |
Page page = new Page(); |
46 |
1 |
page.setSpace(TEST_SPACE); |
47 |
1 |
page.setName("CacheSync"); |
48 |
|
|
49 |
1 |
LocalDocumentReference documentReference = new LocalDocumentReference(page.getSpace(), page.getName()); |
50 |
|
|
51 |
|
|
52 |
1 |
getUtil().switchExecutor(0); |
53 |
1 |
page.setContent("content"); |
54 |
1 |
getUtil().rest().save(page); |
55 |
1 |
Assert.assertEquals("content", getUtil().rest().<Page>get(documentReference).getContent()); |
56 |
|
|
57 |
|
|
58 |
1 |
getUtil().switchExecutor(1); |
59 |
1 |
page.setContent("modified content"); |
60 |
1 |
getUtil().rest().save(page); |
61 |
1 |
Assert.assertEquals("modified content", getUtil().rest().<Page>get(documentReference).getContent()); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
1 |
getUtil().switchExecutor(0); |
66 |
1 |
long t1 = System.currentTimeMillis(); |
67 |
1 |
long t2; |
68 |
1 |
String result; |
69 |
? |
while (!(result = getUtil().rest().<Page>get(documentReference).getContent()) |
70 |
|
.equalsIgnoreCase("modified content")) { |
71 |
0 |
t2 = System.currentTimeMillis(); |
72 |
0 |
if (t2 - t1 > 10000L) { |
73 |
0 |
Assert.fail("Content should have been [modified content] but was [" + result + "]"); |
74 |
|
} |
75 |
0 |
Thread.sleep(100); |
76 |
|
} |
77 |
|
} |
78 |
|
|
|
|
| 70.8% |
Uncovered Elements: 7 (24) |
Complexity: 3 |
Complexity Density: 0.15 |
1PASS
|
|
79 |
1 |
@Test... |
80 |
|
public void testDocumentDeletedCacheSync() throws Exception |
81 |
|
{ |
82 |
1 |
Page page = new Page(); |
83 |
1 |
page.setSpace(TEST_SPACE); |
84 |
1 |
page.setName("CacheSync"); |
85 |
|
|
86 |
1 |
LocalDocumentReference documentReference = new LocalDocumentReference(page.getSpace(), page.getName()); |
87 |
|
|
88 |
|
|
89 |
1 |
getUtil().switchExecutor(0); |
90 |
1 |
page.setContent("content"); |
91 |
1 |
getUtil().rest().save(page); |
92 |
1 |
Assert.assertEquals("content", getUtil().rest().<Page>get(documentReference).getContent()); |
93 |
|
|
94 |
|
|
95 |
1 |
getUtil().switchExecutor(1); |
96 |
|
|
97 |
1 |
getUtil().loginAsSuperAdmin(); |
98 |
1 |
getUtil().rest().delete(documentReference); |
99 |
1 |
Assert.assertFalse(getUtil().rest().exists(documentReference)); |
100 |
|
|
101 |
|
|
102 |
|
|
103 |
1 |
getUtil().switchExecutor(0); |
104 |
1 |
long t1 = System.currentTimeMillis(); |
105 |
1 |
long t2; |
106 |
1 |
while (getUtil().rest().exists(documentReference)) { |
107 |
0 |
t2 = System.currentTimeMillis(); |
108 |
0 |
if (t2 - t1 > 10000L) { |
109 |
0 |
Assert.fail("Document shoud not exist anymore"); |
110 |
|
} |
111 |
0 |
Thread.sleep(100); |
112 |
|
} |
113 |
|
} |
114 |
|
|
|
|
| 66.7% |
Uncovered Elements: 7 (21) |
Complexity: 3 |
Complexity Density: 0.18 |
1PASS
|
|
115 |
1 |
@Test... |
116 |
|
public void testDocumentCacheSyncForAttachments() throws Exception |
117 |
|
{ |
118 |
1 |
Page page = new Page(); |
119 |
1 |
page.setSpace(TEST_SPACE); |
120 |
1 |
page.setName("AttachementCacheSync"); |
121 |
|
|
122 |
1 |
AttachmentReference attachmentReference = new AttachmentReference("file.ext", |
123 |
|
new DocumentReference(getUtil().getCurrentWiki(), page.getSpace(), page.getName())); |
124 |
|
|
125 |
|
|
126 |
1 |
getUtil().switchExecutor(0); |
127 |
1 |
page.setContent("content"); |
128 |
1 |
getUtil().rest().save(page); |
129 |
|
|
130 |
|
|
131 |
1 |
getUtil().switchExecutor(1); |
132 |
1 |
getUtil().rest().attachFile(attachmentReference, "content".getBytes(), true); |
133 |
|
|
134 |
|
|
135 |
|
|
136 |
1 |
getUtil().switchExecutor(0); |
137 |
1 |
long t1 = System.currentTimeMillis(); |
138 |
1 |
long t2; |
139 |
1 |
while (!hasAttachment(attachmentReference)) { |
140 |
0 |
t2 = System.currentTimeMillis(); |
141 |
0 |
if (t2 - t1 > 10000L) { |
142 |
0 |
Assert.fail("Failed to find attachment"); |
143 |
|
} |
144 |
0 |
Thread.sleep(100); |
145 |
|
} |
146 |
|
} |
147 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
148 |
1 |
private boolean hasAttachment(AttachmentReference attachmentReference) throws Exception... |
149 |
|
{ |
150 |
1 |
Attachments attachments = |
151 |
|
getUtil().rest().get(AttachmentsResource.class, attachmentReference.getDocumentReference()); |
152 |
1 |
for (Attachment attachment : attachments.getAttachments()) { |
153 |
1 |
System.out.println(attachment.getName()); |
154 |
1 |
if (attachment.getName().equals(attachmentReference.getName())) { |
155 |
1 |
return true; |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
0 |
return false; |
160 |
|
} |
161 |
|
} |