t_bin.cpp

Go to the documentation of this file.
00001 /*****************************************************************************\
00002 *                                                                             *
00003 *  Name   : entity_data_bin tester                                            *
00004 *  Author : Chris Koeritz                                                     *
00005 *                                                                             *
00006 *  Purpose:                                                                   *
00007 *                                                                             *
00008 *    Checks that the entity_data_bin class is behaving as expected.           *
00009 *                                                                             *
00010 *******************************************************************************
00011 * Copyright (c) 2002-$now By Author.  This program is free software; you can  *
00012 * redistribute it and/or modify it under the terms of the GNU General Public  *
00013 * License as published by the Free Software Foundation; either version 2 of   *
00014 * the License or (at your option) any later version.  This is online at:      *
00015 *     http://www.fsf.org/copyleft/gpl.html                                    *
00016 * Please send any updates to: fred@gruntose.com                               *
00017 \*****************************************************************************/
00018 
00019 #include <basis/byte_array.h>
00020 #include <basis/chaos.h>
00021 #include <basis/function.h>
00022 #include <basis/guards.h>
00023 #include <basis/istring.h>
00024 #include <opsystem/application_shell.h>
00025 #include <loggers/console_logger.h>
00026 #include <data_struct/static_memory_gremlin.h>
00027 #include <octopus/entity_data_bin.h>
00028 #include <octopus/entity_defs.h>
00029 #include <tentacles/security_infoton.h>
00030 #include <textual/string_manipulation.h>
00031 
00032 #include <stdio.h>
00033 
00034 const int ITEM_COUNT = 10000;
00035   // the number of times to repeat each test operation.
00036 
00037 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger(), s)
00038 #define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger(), s)
00039 
00040 class test_bin : public application_shell
00041 {
00042 public:
00043   test_bin() : application_shell(class_name()) {}
00044   IMPLEMENT_CLASS_NAME("test_bin");
00045   int execute();
00046 };
00047 
00049   
00050 int test_bin::execute()
00051 {
00052   FUNCDEF("execute");
00053   char c = '\0';
00054 
00055   array<octopus_request_id> item_list;
00056 
00057   entity_data_bin *bing = new entity_data_bin(10 * MEGABYTE);
00058 
00059   enum test_types { ANY = 1, ENT, ID };
00060 
00061   for (int q = ANY; q <= ID; q++) {
00062 LOG(isprintf("test type %d beginning...%c", q, c));
00063   // using c just shuts up warnings.
00064 //LOG("note memory usage and hit a key:");
00065 //c = getchar();
00066 
00067     program_wide_logger().eol(log_base::NO_ENDING);
00068     for (int i = 1; i <= ITEM_COUNT; i++) {
00069       // test the basic filling of the values in an entity.
00070       octopus_request_id req_id;
00071       int sequencer = randomizer().inclusive(1, MAXINT - 10);
00072       int add_in = randomizer().inclusive(0, MAXINT - 10);
00073       int process_id = randomizer().inclusive(0, MAXINT - 10);
00074       req_id._entity = octopus_entity(string_manipulation::make_random_name(),
00075           process_id, sequencer, add_in);
00076       req_id._request_num = randomizer().inclusive(1, MAXINT - 10);
00077       infoton *torp = new security_infoton;
00078       bing->add_item(torp, req_id);
00079       item_list += req_id;
00080 
00081       if (! (i % 50) ) {
00082         printf("^");
00083         fflush(NIL);
00084       }
00085     }
00086     program_wide_logger().eol(log_base::CRLF_AT_END);
00087     LOG("");
00088 
00089     int items_seen = 0;
00090 
00091     program_wide_logger().eol(log_base::NO_ENDING);
00092     if (q == ANY) {
00093       while (item_list.length()) {
00094         octopus_request_id id;
00095         infoton *found = bing->acquire_for_any(id);
00096         if (!found) 
00097           deadly_error(class_name(), "ANY", "item was missing");
00098         WHACK(found);
00099         items_seen++;
00100         if (! (items_seen % 50) ) {
00101           printf("v");
00102           fflush(NIL);
00103         }
00104         bool saw_it = false;
00105         for (int q = 0; q < item_list.length(); q++) {
00106           if (item_list[q] == id) {
00107             saw_it = true;
00108             item_list.zap(q, q);
00109             break;
00110           }
00111         }
00112         if (!saw_it)
00113           deadly_error(class_name(), "ANY", "didn't see id for the item");
00114       }
00115     } else if (q == ENT) {
00116       while (item_list.length()) {
00117         octopus_request_id id;
00118         infoton *found = bing->acquire_for_entity(item_list[0]._entity, id);
00119         if (!found) 
00120           deadly_error(class_name(), "ENT", "item was missing");
00121         WHACK(found);
00122         items_seen++;
00123         if (! (items_seen % 50) ) {
00124           printf("v");
00125           fflush(NIL);
00126         }
00127         bool saw_it = false;
00128         for (int q = 0; q < item_list.length(); q++) {
00129           if (item_list[q] == id) {
00130             saw_it = true;
00131             item_list.zap(q, q);
00132             break;
00133           }
00134         }
00135         if (!saw_it)
00136           deadly_error(class_name(), "ENT", "didn't see id for the item");
00137       }
00138     } else if (q == ID) {
00139       for (int j = 0; j < item_list.length(); j++) {
00140         infoton *found = bing->acquire_for_identifier(item_list[j]);
00141         if (!found) 
00142           deadly_error(class_name(), "ENT", "item was missing");
00143         WHACK(found);
00144         items_seen++;
00145         if (! (items_seen % 50) ) {
00146           printf("v");
00147           fflush(NIL);
00148         }
00149         item_list.zap(j, j);
00150         j--;  // skip back.
00151       }
00152     } else {
00153       deadly_error(class_name(), "looping", "bad enum value");
00154     }
00155     program_wide_logger().eol(log_base::CRLF_AT_END);
00156     LOG("");
00157     item_list.reset();
00158     item_list.shrink();
00159 
00160     if (bing->entities())
00161       deadly_error(class_name(), "check left", "there are still contents in table!");
00162 
00163     bing->clean_out_deadwood();
00164 
00165 LOG(isprintf("test type %d ending...", q));
00166 //LOG("note memory usage and hit a key:");
00167 //c = getchar();
00168   }
00169 
00170   WHACK(bing);
00171 LOG("done testing, zapped bin, now should be low memory.");
00172 //c = getchar();
00173 
00174   LOG("octopus_entity:: works for those functions tested.");
00175   return 0;
00176 }
00177 
00178 HOOPLE_MAIN(test_bin, )
00179 

Generated on Fri Nov 28 04:29:39 2008 for HOOPLE Libraries by  doxygen 1.5.1