feisty meow concerns codebase  2.140
t_bin.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : entity_data_bin tester *
4 * Author : Chris Koeritz *
5 * *
6 * Purpose: *
7 * *
8 * Checks that the entity_data_bin class is behaving as expected. *
9 * *
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 \*****************************************************************************/
18 
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>
26 #include <loggers/console_logger.h>
30 #include <octopus/entity_defs.h>
33 
34 #include <stdio.h>
35 
36 using namespace application;
37 using namespace basis;
38 using namespace loggers;
39 using namespace octopi;
40 using namespace textual;
41 
42 const int ITEM_COUNT = 10000;
43  // the number of times to repeat each test operation.
44 
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))
47 
48 class test_bin : public application_shell
49 {
50 public:
51  test_bin() : application_shell() {}
52  DEFINE_CLASS_NAME("test_bin");
53  int execute();
54 };
55 
57 
58 int test_bin::execute()
59 {
60  FUNCDEF("execute");
61  char c = '\0';
62 
63  array<octopus_request_id> item_list;
64 
65  entity_data_bin *bing = new entity_data_bin(10 * MEGABYTE);
66 
67  enum test_types { ANY = 1, ENT, ID };
68 
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:");
73 //c = getchar();
74 
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);
87  item_list += req_id;
88 
89  if (! (i % 50) ) {
90  printf("^");
91  fflush(NULL_POINTER);
92  }
93  }
94  program_wide_logger().get().eol(parser_bits::CRLF_AT_END);
95  LOG("");
96 
97  int items_seen = 0;
98 
99  program_wide_logger().get().eol(parser_bits::NO_ENDING);
100  if (q == ANY) {
101  while (item_list.length()) {
103  infoton *found = bing->acquire_for_any(id);
104  if (!found)
105  deadly_error(class_name(), "ANY", "item was missing");
106  WHACK(found);
107  items_seen++;
108  if (! (items_seen % 50) ) {
109  printf("v");
110  fflush(NULL_POINTER);
111  }
112  bool saw_it = false;
113  for (int q = 0; q < item_list.length(); q++) {
114  if (item_list[q] == id) {
115  saw_it = true;
116  item_list.zap(q, q);
117  break;
118  }
119  }
120  if (!saw_it)
121  deadly_error(class_name(), "ANY", "didn't see id for the item");
122  }
123  } else if (q == ENT) {
124  while (item_list.length()) {
126  infoton *found = bing->acquire_for_entity(item_list[0]._entity, id);
127  if (!found)
128  deadly_error(class_name(), "ENT", "item was missing");
129  WHACK(found);
130  items_seen++;
131  if (! (items_seen % 50) ) {
132  printf("v");
133  fflush(NULL_POINTER);
134  }
135  bool saw_it = false;
136  for (int q = 0; q < item_list.length(); q++) {
137  if (item_list[q] == id) {
138  saw_it = true;
139  item_list.zap(q, q);
140  break;
141  }
142  }
143  if (!saw_it)
144  deadly_error(class_name(), "ENT", "didn't see id for the item");
145  }
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]);
149  if (!found)
150  deadly_error(class_name(), "ENT", "item was missing");
151  WHACK(found);
152  items_seen++;
153  if (! (items_seen % 50) ) {
154  printf("v");
155  fflush(NULL_POINTER);
156  }
157  item_list.zap(j, j);
158  j--; // skip back.
159  }
160  } else {
161  deadly_error(class_name(), "looping", "bad enum value");
162  }
163  program_wide_logger().get().eol(parser_bits::CRLF_AT_END);
164  LOG("");
165  item_list.reset();
166  item_list.shrink();
167 
168  if (bing->entities())
169  deadly_error(class_name(), "check left", "there are still contents in table!");
170 
171  bing->clean_out_deadwood();
172 
173 LOG(a_sprintf("test type %d ending...", q));
174 //LOG("note memory usage and hit a key:");
175 //c = getchar();
176  }
177 
178  WHACK(bing);
179 LOG("done testing, zapped bin, now should be low memory.");
180 //c = getchar();
181 
182  LOG("octopus_entity:: works for those functions tested.");
183  return 0;
184 }
185 
186 HOOPLE_MAIN(test_bin, )
187 
The application_shell is a base object for console programs.
a_sprintf is a specialization of astring that provides printf style support.
Definition: astring.h:440
Represents a sequential, ordered, contiguous collection of objects.
Definition: array.h:54
void reset(int number=0, const contents *initial_contents=NULL_POINTER)
Resizes this array and sets the contents from an array of contents.
Definition: array.h:349
outcome shrink()
Cuts loose any allocated space that is beyond the real length.
Definition: array.h:463
int length() const
Returns the current reported length of the allocated C array.
Definition: array.h:115
outcome zap(int start, int end)
Deletes from "this" the objects inclusively between "start" and "end".
Definition: array.h:769
virtual textual::parser_bits::line_ending eol()
observes how line endings are to be printed.
Definition: eol_aware.h:34
A class that provides logging facilities vertically to all of hoople.
static loggers::standard_log_base & get()
Provided by the startup code within each application for logging.
Stores a set of infotons grouped by the entity that owns them.
bool add_item(infoton *to_add, const octopus_request_id &id)
infoton * acquire_for_any(octopus_request_id &id)
infoton * acquire_for_identifier(const octopus_request_id &id)
void clean_out_deadwood(int decay_interval=4 *basis::MINUTE_ms)
infoton * acquire_for_entity(const octopus_entity &requester, octopus_request_id &id)
An infoton is an individual request parcel with accompanying information.
Definition: infoton.h:32
Provides a way of identifying users of an octopus object.
Definition: entity_defs.h:35
Identifies requests made on an octopus by users.
Definition: entity_defs.h:114
int _request_num
the item number from the entity.
Definition: entity_defs.h:117
octopus_entity _entity
the entity.
Definition: entity_defs.h:116
Encapsulates security activities (login, logout, refresh).
#define deadly_error(c, f, i)
#define NULL_POINTER
The value representing a pointer to nothing.
Definition: definitions.h:32
#define MAXINT32
Maximum 32-bit integer value.
Definition: definitions.h:75
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition: enhance_cpp.h:45
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition: enhance_cpp.h:57
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Definition: hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition: functions.h:121
const int MEGABYTE
Number of bytes in a megabyte.
Definition: definitions.h:135
A logger that sends to the console screen using the standard output device.
#define LOG(s)
Definition: t_bin.cpp:45
const int ITEM_COUNT
Definition: t_bin.cpp:42
#define randomizer()