1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| package org.jboss.cache.pojo; |
9 |
| |
10 |
| import org.jboss.cache.CacheImpl; |
11 |
| |
12 |
| import java.util.List; |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| |
19 |
| |
20 |
| public class TestingUtil |
21 |
| { |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| |
29 |
0
| public static void blockUntilViewsReceived(PojoCache[] caches, long timeout)
|
30 |
| { |
31 |
0
| long failTime = System.currentTimeMillis() + timeout;
|
32 |
| |
33 |
0
| while (System.currentTimeMillis() < failTime)
|
34 |
| { |
35 |
0
| org.jboss.cache.pojo.TestingUtil.sleepThread(100);
|
36 |
0
| if (org.jboss.cache.pojo.TestingUtil.areCacheViewsComplete(caches))
|
37 |
0
| return;
|
38 |
| } |
39 |
| |
40 |
0
| throw new RuntimeException("timed out before caches had complete views");
|
41 |
| } |
42 |
| |
43 |
| |
44 |
| |
45 |
0
| public static void blockUntilViewReceived(PojoCache cache, int groupSize, long timeout)
|
46 |
| { |
47 |
0
| long failTime = System.currentTimeMillis() + timeout;
|
48 |
| |
49 |
0
| CacheImpl tcache = (CacheImpl) cache.getCache();
|
50 |
0
| while (System.currentTimeMillis() < failTime)
|
51 |
| { |
52 |
0
| org.jboss.cache.pojo.TestingUtil.sleepThread(100);
|
53 |
0
| if (org.jboss.cache.pojo.TestingUtil.isCacheViewComplete(tcache, groupSize))
|
54 |
0
| return;
|
55 |
| } |
56 |
| |
57 |
0
| throw new RuntimeException("timed out before caches had complete views");
|
58 |
| } |
59 |
| |
60 |
| |
61 |
| |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
0
| public static boolean areCacheViewsComplete(PojoCache[] caches)
|
72 |
| { |
73 |
0
| int memberCount = caches.length;
|
74 |
| |
75 |
0
| for (int i = 0; i < memberCount; i++)
|
76 |
| { |
77 |
0
| CacheImpl cache = (CacheImpl) caches[i].getCache();
|
78 |
0
| return org.jboss.cache.pojo.TestingUtil.isCacheViewComplete(cache, memberCount);
|
79 |
| } |
80 |
| |
81 |
0
| return true;
|
82 |
| } |
83 |
| |
84 |
| |
85 |
| |
86 |
| |
87 |
| |
88 |
| |
89 |
| |
90 |
0
| public static boolean isCacheViewComplete(CacheImpl cache, int memberCount)
|
91 |
| { |
92 |
0
| List members = cache.getMembers();
|
93 |
0
| if (members == null || memberCount > members.size())
|
94 |
| { |
95 |
0
| return false;
|
96 |
| } |
97 |
0
| else if (memberCount < members.size())
|
98 |
| { |
99 |
| |
100 |
0
| StringBuffer sb = new StringBuffer("Cache at address ");
|
101 |
0
| sb.append(cache.getLocalAddress());
|
102 |
0
| sb.append(" had ");
|
103 |
0
| sb.append(members.size());
|
104 |
0
| sb.append(" members; expecting ");
|
105 |
0
| sb.append(memberCount);
|
106 |
0
| sb.append(". Members were (");
|
107 |
0
| for (int j = 0; j < members.size(); j++)
|
108 |
| { |
109 |
0
| if (j > 0)
|
110 |
0
| sb.append(", ");
|
111 |
0
| sb.append(members.get(j));
|
112 |
| } |
113 |
0
| sb.append(')');
|
114 |
| |
115 |
0
| throw new IllegalStateException(sb.toString());
|
116 |
| } |
117 |
| |
118 |
0
| return true;
|
119 |
| } |
120 |
| |
121 |
| |
122 |
| |
123 |
| |
124 |
| |
125 |
| |
126 |
| |
127 |
| |
128 |
1962
| public static void sleepThread(long sleeptime)
|
129 |
| { |
130 |
1962
| try
|
131 |
| { |
132 |
1962
| Thread.sleep(sleeptime);
|
133 |
| } |
134 |
| catch (InterruptedException ie) |
135 |
| { |
136 |
| } |
137 |
| } |
138 |
| } |