1 /*****************************************************************************\
3 * Name : entity_data_bin tester *
4 * Author : Chris Koeritz *
8 * Checks that the entity_data_bin class is behaving as expected. *
10 *******************************************************************************
11 * Copyright (c) 2002-$now By Author. This program is free software; you can *
12 * redistribute it and/or modify it under the terms of the GNU General Public *
13 * License as published by the Free Software Foundation; either version 2 of *
14 * the License or (at your option) any later version. This is online at: *
15 * http://www.fsf.org/copyleft/gpl.html *
16 * Please send any updates to: fred@gruntose.com *
17 \*****************************************************************************/
19 #include <application/hoople_main.h>
20 #include <basis/byte_array.h>
21 #include <mathematics/chaos.h>
22 #include <basis/functions.h>
23 #include <basis/guards.h>
24 #include <basis/astring.h>
25 #include <application/application_shell.h>
26 #include <loggers/console_logger.h>
27 #include <loggers/program_wide_logger.h>
28 #include <structures/static_memory_gremlin.h>
29 #include <octopus/entity_data_bin.h>
30 #include <octopus/entity_defs.h>
31 #include <tentacles/security_infoton.h>
32 #include <textual/string_manipulation.h>
36 using namespace application;
37 using namespace basis;
38 using namespace loggers;
39 using namespace octopi;
40 using namespace textual;
42 const int ITEM_COUNT = 10000;
43 // the number of times to repeat each test operation.
45 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger().get(), astring(s))
46 #define BASE_LOG(s) EMERGENCY_LOG(program_wide_logger().get(), astring(s))
48 class test_bin : public application_shell
51 test_bin() : application_shell() {}
52 DEFINE_CLASS_NAME("test_bin");
58 int test_bin::execute()
63 array<octopus_request_id> item_list;
65 entity_data_bin *bing = new entity_data_bin(10 * MEGABYTE);
67 enum test_types { ANY = 1, ENT, ID };
69 for (int q = ANY; q <= ID; q++) {
70 LOG(a_sprintf("test type %d beginning...%c", q, c));
71 // using c just shuts up warnings.
72 //LOG("note memory usage and hit a key:");
75 program_wide_logger().get().eol(parser_bits::NO_ENDING);
76 for (int i = 1; i <= ITEM_COUNT; i++) {
77 // test the basic filling of the values in an entity.
78 octopus_request_id req_id;
79 int sequencer = randomizer().inclusive(1, MAXINT32 - 10);
80 int add_in = randomizer().inclusive(0, MAXINT32 - 10);
81 int process_id = randomizer().inclusive(0, MAXINT32 - 10);
82 req_id._entity = octopus_entity(string_manipulation::make_random_name(),
83 process_id, sequencer, add_in);
84 req_id._request_num = randomizer().inclusive(1, MAXINT32 - 10);
85 infoton *torp = new security_infoton;
86 bing->add_item(torp, req_id);
94 program_wide_logger().get().eol(parser_bits::CRLF_AT_END);
99 program_wide_logger().get().eol(parser_bits::NO_ENDING);
101 while (item_list.length()) {
102 octopus_request_id id;
103 infoton *found = bing->acquire_for_any(id);
105 deadly_error(class_name(), "ANY", "item was missing");
108 if (! (items_seen % 50) ) {
110 fflush(NULL_POINTER);
113 for (int q = 0; q < item_list.length(); q++) {
114 if (item_list[q] == id) {
121 deadly_error(class_name(), "ANY", "didn't see id for the item");
123 } else if (q == ENT) {
124 while (item_list.length()) {
125 octopus_request_id id;
126 infoton *found = bing->acquire_for_entity(item_list[0]._entity, id);
128 deadly_error(class_name(), "ENT", "item was missing");
131 if (! (items_seen % 50) ) {
133 fflush(NULL_POINTER);
136 for (int q = 0; q < item_list.length(); q++) {
137 if (item_list[q] == id) {
144 deadly_error(class_name(), "ENT", "didn't see id for the item");
146 } else if (q == ID) {
147 for (int j = 0; j < item_list.length(); j++) {
148 infoton *found = bing->acquire_for_identifier(item_list[j]);
150 deadly_error(class_name(), "ENT", "item was missing");
153 if (! (items_seen % 50) ) {
155 fflush(NULL_POINTER);
161 deadly_error(class_name(), "looping", "bad enum value");
163 program_wide_logger().get().eol(parser_bits::CRLF_AT_END);
168 if (bing->entities())
169 deadly_error(class_name(), "check left", "there are still contents in table!");
171 bing->clean_out_deadwood();
173 LOG(a_sprintf("test type %d ending...", q));
174 //LOG("note memory usage and hit a key:");
179 LOG("done testing, zapped bin, now should be low memory.");
182 LOG("octopus_entity:: works for those functions tested.");
186 HOOPLE_MAIN(test_bin, )