21 #include <ndb_global.h>
23 #include <ArrayList.hpp>
31 void print (NdbOut & out) {
32 out <<
"A_Poolable_Object: next = " << next << endl;
46 #define BPool ArrayPool<A_Poolable_Object>
48 #define BPool ArrayPool(A_Poolable_Object, next)
53 static void tryPool1(
int poolSize,
int iterations){
56 if(!aPool.setSize(poolSize)){
57 ndbout <<
"Failed to do aPool.setSize(" << poolSize <<
")" << endl;
61 ndbout <<
"Seizing/Releaseing " << iterations
62 <<
" times over pool with " << poolSize <<
" elements" << endl;
64 int * anArray =
new int[poolSize];
65 int arrayElements = 0;
71 for(
int i = 0;
i<iterations;
i++){
72 if(!((arrayElements <= poolSize) &&
73 (aPool.noOfFree() == aPool.noOfFree2()) &&
74 (aPool.noOfFree() == (poolSize - arrayElements)))){
75 ndbout <<
"Assertion!!"
76 <<
" iteration=" <<
i << endl;
77 const int f1 = aPool.noOfFree();
78 const int f2 = aPool.noOfFree2();
79 ndbout <<
"noOfFree() = " << f1 << endl;
80 ndbout <<
"noOfFree2() = " << f2 << endl;
81 ndbout <<
"poolSize = " << poolSize << endl;
82 ndbout <<
"arrayElemts = " << arrayElements << endl;
87 const int r = rand() % (10 * poolSize);
88 if(r < (arrayElements - 1)){
93 aPool.release(anArray[r]);
95 for(
int j = r; j<arrayElements; j++)
96 anArray[j] = anArray[j+1];
102 A_Poolable_ObjectPtr p;
103 const int ret = aPool.seize(p);
104 if(ret == RNIL && arrayElements != poolSize){
105 ndbout <<
"Failed to seize!!"
106 <<
" iteration=" <<
i << endl;
107 ndbout <<
"Have seized " << arrayElements
108 <<
" out of " << poolSize << endl;
109 ndbout <<
"Terminating..." << endl;
112 if(arrayElements >= poolSize && ret != RNIL){
113 ndbout <<
"Seize did not fail when it should have"
114 <<
" iteration=" <<
i << endl;
115 ndbout <<
"Have seized " << arrayElements
116 <<
" out of " << poolSize << endl;
117 ndbout <<
"Terminating..." << endl;
122 anArray[arrayElements] =
ret;
124 memset(p.p,
i,
sizeof(p.p->somedata));
132 ndbout <<
"Seized: " << noOfSeize
133 <<
" Seized with buffer full: " << noFailSeize
134 <<
" Release: " << noOfRelease <<
" --- ";
135 ndbout <<
"(" << noOfSeize <<
" + " << noFailSeize <<
" + " << noOfRelease
136 <<
" = " << (noOfSeize + noFailSeize + noOfRelease) <<
")" << endl;
142 if(!aPool.setSize(size)){
143 ndbout <<
"Failed to do aPool.setSize(" << size <<
")" << endl;
147 ndbout <<
"doing getPtr(i) where i > size(" << size <<
") "
148 << fail <<
" times mixed with " << iter
149 <<
" ordinary seize/release" << endl;
151 int * anArray =
new int[
size];
152 int arrayElements = 0;
158 for(
int i = 0;
i<iter;
i++){
159 if(!((arrayElements <= size) &&
160 (aPool.noOfFree() == aPool.noOfFree2()) &&
161 (aPool.noOfFree() == (size - arrayElements)))){
162 ndbout <<
"Assertion!!"
163 <<
" iteration=" <<
i << endl;
164 const int f1 = aPool.noOfFree();
165 const int f2 = aPool.noOfFree2();
166 ndbout <<
"noOfFree() = " << f1 << endl;
167 ndbout <<
"noOfFree2() = " << f2 << endl;
168 ndbout <<
"poolSize = " << size << endl;
169 ndbout <<
"arrayElemts = " << arrayElements << endl;
173 const int r = rand() % (10 *
size);
175 if((
i + 1)%(iter/fail) == 0){
176 aPool.getPtr(size + r);
180 if(r < (arrayElements - 1)){
185 aPool.release(anArray[r]);
187 for(
int j = r; j<arrayElements; j++)
188 anArray[j] = anArray[j+1];
194 A_Poolable_ObjectPtr p;
195 const int ret = aPool.seize(p);
196 if(ret == RNIL && arrayElements != size){
197 ndbout <<
"Failed to seize!!"
198 <<
" iteration=" <<
i << endl;
199 ndbout <<
"Have seized " << arrayElements
200 <<
" out of " << size << endl;
201 ndbout <<
"Terminating..." << endl;
204 if(arrayElements >= size && ret != RNIL){
205 ndbout <<
"Seize did not fail when it should have"
206 <<
" iteration=" <<
i << endl;
207 ndbout <<
"Have seized " << arrayElements
208 <<
" out of " << size << endl;
209 ndbout <<
"Terminating..." << endl;
214 anArray[arrayElements] =
ret;
216 memset(p.p, p.i,
sizeof(p.p->somedata));
227 ndbout <<
"Failing " << fail <<
" times " << endl;
229 for(
int i = 0;
i<fail;
i++){
231 if(!aPool.setSize(size)){
232 ndbout <<
"Failed to do aPool.setSize(" << size <<
")" << endl;
236 const int noOfElementsInBufferWhenFail = (
i + 1) * (size /(fail + 1));
238 int * anArray =
new int[
size];
241 int arrayElements = 0;
248 assert(arrayElements <= size);
249 if(arrayElements == noOfElementsInBufferWhenFail){
250 ndbout <<
"++ You should get a ErrorReporter::handle... " << endl;
251 aPool.release(anArray[arrayElements]);
252 ndbout <<
"++ Inbetween these lines" << endl << endl;
255 const int r = rand() % (10 *
size);
256 if(r < (arrayElements - 1)){
261 aPool.release(anArray[r]);
263 for(
int j = r; j<arrayElements; j++)
264 anArray[j] = anArray[j+1];
270 A_Poolable_ObjectPtr p;
271 const int ret = aPool.seize(p);
272 if(ret == RNIL && arrayElements != size){
273 ndbout <<
"Failed to seize!!" << endl;
274 ndbout <<
"Have seized " << arrayElements
275 <<
" out of " << size << endl;
276 ndbout <<
"Terminating..." << endl;
279 if(arrayElements >= size && ret != RNIL){
280 ndbout <<
"Seize did not fail when it should have" << endl;
281 ndbout <<
"Have seized " << arrayElements
282 <<
" out of " << size << endl;
283 ndbout <<
"Terminating..." << endl;
288 anArray[arrayElements] =
ret;