21 #include <ndb_global.hpp>
23 #include <ArrayList.hpp>
32 void print (NdbOut & out) {
33 out <<
"ALO: next = " << next
34 <<
" prev = " << prev << endl;
49 #define APool ArrayPool<A_Listable_Object>
50 #define AList ArrayList<A_Listable_Object>
57 static void tryList0(
int listSize){
61 if(!aPool.setSize(listSize)){
62 ndbout <<
"Failed to do aPool.setSize(" << listSize <<
")" << endl;
66 int * anArray =
new int[listSize];
68 for(
int i = 1;
i<listSize;
i++){
69 int arrayElements = 0;
72 for(
int j = 0; j<
i; j++){
73 A_Listable_ObjectPtr p;
74 const int ret = aList.seize(p);
76 ndbout <<
"Failed to seize!!" << endl;
77 ndbout <<
"Have seized " << j
78 <<
" out of " << listSize << endl;
79 ndbout <<
"Terminating..." << endl;
82 anArray[arrayElements] =
ret;
85 assert(aList.noOfElements() ==
i);
86 assert(aPool.noOfFree() == (listSize -
i));
87 assert(arrayElements == i);
89 for(
int j = 0; j<
i; j++){
90 aList.release(anArray[j]);
93 assert(aList.noOfElements() == 0);
94 assert(aPool.noOfFree() == listSize);
98 static void tryList1(
int listSize,
int iterations){
102 if(!aPool.setSize(listSize)){
103 ndbout <<
"Failed to do aPool.setSize(" << listSize <<
")" << endl;
107 ndbout <<
"Seizing/Releaseing " << iterations
108 <<
" times over list with " << listSize <<
" elements" << endl;
110 int * anArray =
new int[listSize];
111 int arrayElements = 0;
117 for(
int i = 0;
i<iterations;
i++){
118 assert(arrayElements <= listSize);
119 const int r = rand() % (10 * listSize);
120 if(r < (arrayElements - 1)){
125 aList.release(anArray[r]);
127 for(
int j = r; j<arrayElements; j++)
128 anArray[j] = anArray[j+1];
134 A_Listable_ObjectPtr p;
135 const int ret = aList.seize(p);
136 if(ret == RNIL && arrayElements != listSize){
137 ndbout <<
"Failed to seize!!"
138 <<
" iteration=" <<
i << endl;
139 ndbout <<
"Have seized " << arrayElements
140 <<
" out of " << listSize << endl;
141 ndbout <<
"Terminating..." << endl;
144 if(arrayElements >= listSize && ret != RNIL){
145 ndbout <<
"Seize did not fail when it should have"
146 <<
" iteration=" <<
i << endl;
147 ndbout <<
"Have seized " << arrayElements
148 <<
" out of " << listSize << endl;
149 ndbout <<
"Terminating..." << endl;
154 anArray[arrayElements] =
ret;
163 ndbout <<
"Seized: " << noOfSeize
164 <<
" Seized with buffer full: " << noFailSeize
165 <<
" Release: " << noOfRelease <<
" --- ";
166 ndbout <<
"(" << noOfSeize <<
" + " << noFailSeize <<
" + " << noOfRelease
167 <<
" = " << (noOfSeize + noFailSeize + noOfRelease) <<
")" << endl;
174 if(!aPool.setSize(size)){
175 ndbout <<
"Failed to do aPool.setSize(" << size <<
")" << endl;
179 ndbout <<
"doing getPtr(i) where i > size(" << size <<
") "
180 << fail <<
" times mixed with " << iter
181 <<
" ordinary seize/release" << endl;
183 int * anArray =
new int[
size];
184 int arrayElements = 0;
190 for(
int i = 0;
i<iter;
i++){
191 assert(arrayElements <= size);
192 const int r = rand() % (10 *
size);
194 if((
i + 1)%(iter/fail) == 0){
195 aList.getPtr(size + r);
199 if(r < (arrayElements - 1)){
204 aList.release(anArray[r]);
206 for(
int j = r; j<arrayElements; j++)
207 anArray[j] = anArray[j+1];
213 A_Listable_ObjectPtr p;
214 const int ret = aList.seize(p);
215 if(ret == RNIL && arrayElements != size){
216 ndbout <<
"Failed to seize!!"
217 <<
" iteration=" <<
i << endl;
218 ndbout <<
"Have seized " << arrayElements
219 <<
" out of " << size << endl;
220 ndbout <<
"Terminating..." << endl;
223 if(arrayElements >= size && ret != RNIL){
224 ndbout <<
"Seize did not fail when it should have"
225 <<
" iteration=" <<
i << endl;
226 ndbout <<
"Have seized " << arrayElements
227 <<
" out of " << size << endl;
228 ndbout <<
"Terminating..." << endl;
233 anArray[arrayElements] =
ret;
245 ndbout <<
"Failing " << fail <<
" times " << endl;
247 for(
int i = 0;
i<fail;
i++){
251 if(!aPool.setSize(size)){
252 ndbout <<
"Failed to do aPool.setSize(" << size <<
")" << endl;
256 const int noOfElementsInBufferWhenFail = (
i + 1) * (size /(fail + 1));
258 int * anArray =
new int[
size];
261 int arrayElements = 0;
268 assert(arrayElements <= size);
269 if(arrayElements == noOfElementsInBufferWhenFail){
270 ndbout <<
"++ You should get a ErrorReporter::handle... " << endl;
271 aList.release(anArray[arrayElements]);
272 ndbout <<
"++ Inbetween these lines" << endl << endl;
275 const int r = rand() % (10 *
size);
276 if(r < (arrayElements - 1)){
281 aList.release(anArray[r]);
283 for(
int j = r; j<arrayElements; j++)
284 anArray[j] = anArray[j+1];
290 A_Listable_ObjectPtr p;
291 const int ret = aList.seize(p);
292 if(ret == RNIL && arrayElements != size){
293 ndbout <<
"Failed to seize!!" << endl;
294 ndbout <<
"Have seized " << arrayElements
295 <<
" out of " << size << endl;
296 ndbout <<
"Terminating..." << endl;
299 if(arrayElements >= size && ret != RNIL){
300 ndbout <<
"Seize did not fail when it should have" << endl;
301 ndbout <<
"Have seized " << arrayElements
302 <<
" out of " << size << endl;
303 ndbout <<
"Terminating..." << endl;
308 anArray[arrayElements] =
ret;