~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/storage_engine_api_tester/storage_engine_api_tester.cc

  • Committer: Package Import Robot
  • Author(s): Clint Byrum
  • Date: 2012-06-19 10:46:49 UTC
  • mfrom: (1.1.6)
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20120619104649-e2l0ggd4oz3um0f4
Tags: upstream-7.1.36-stable
ImportĀ upstreamĀ versionĀ 7.1.36-stable

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <drizzled/session.h> // for mark_transaction_to_rollback
24
24
#include <string>
25
25
#include <map>
 
26
#include <iostream>
26
27
#include <fstream>
27
28
#include <drizzled/message/table.pb.h>
28
29
#include <drizzled/internal/m_string.h>
29
30
 
30
 
#include <drizzled/global_charset_info.h>
 
31
#include <drizzled/charset.h>
31
32
 
32
33
#include <boost/unordered_map.hpp>
33
34
 
47
48
void load_engine_state_transitions(state_multimap &states);
48
49
void load_cursor_state_transitions(state_multimap &states);
49
50
 
 
51
uint64_t next_cursor_id;
 
52
 
50
53
plugin::TransactionalStorageEngine *realEngine;
51
54
 
52
55
/* ERROR INJECTION For SEAPITESTER
113
116
  state_multimap_iter cur= engine_state_transitions.find(engine_state);
114
117
  if (engine_state_transitions.count(engine_state) == 0)
115
118
  {
116
 
    cerr << "ERROR: Invalid engine state: " << engine_state << endl
117
 
         << "This should *NEVER* happen."
118
 
         << endl
119
 
         << "i.e. you've really screwed it up and you should be ashamed of "
120
 
         << "yourself." << endl;
 
119
    std::cerr << "ERROR: Invalid engine state: " << engine_state << std::endl
 
120
      << "This should *NEVER* happen."
 
121
      << std::endl
 
122
      << "i.e. you've really screwed it up and you should be ashamed of "
 
123
      << "yourself." << std::endl;
121
124
    assert(engine_state_transitions.count(engine_state));
122
125
  }
123
126
 
132
135
  if (cur == engine_state_transitions.end()
133
136
      || new_state.compare((*cur).second))
134
137
  {
135
 
    cerr << "ERROR: Invalid Storage Engine state transition!" << endl
136
 
         << "Cannot go from " << engine_state << " to " << new_state << endl;
 
138
    std::cerr << "ERROR: Invalid Storage Engine state transition!" << std::endl
 
139
      << "Cannot go from " << engine_state << " to " << new_state << std::endl;
137
140
    assert(false);
138
141
  }
139
142
 
140
143
  engine_state= new_state;
141
144
  engine_state_history.push_back(new_state);
142
145
 
143
 
  cerr << "\tENGINE STATE : " << engine_state << endl;
 
146
  std::cerr << "\tENGINE STATE : " << engine_state << std::endl;
144
147
}
145
148
 
146
149
static const string engine_name("STORAGE_ENGINE_API_TESTER");
154
157
  SEAPITesterCursor(drizzled::plugin::StorageEngine &engine_arg,
155
158
                    drizzled::Table &table_arg)
156
159
    : Cursor(engine_arg, table_arg)
157
 
    { cursor_state= "Cursor()"; realCursor= NULL;}
 
160
    {
 
161
      cursor_state= "Cursor()";
 
162
      realCursor= NULL;
 
163
      id= ++next_cursor_id;
 
164
      CURSOR_NEW_STATE("Cursor()");
 
165
    }
158
166
 
159
167
  ~SEAPITesterCursor()
160
 
    { delete realCursor;}
 
168
    { CURSOR_NEW_STATE("~Cursor()"); delete realCursor;}
161
169
 
162
170
  int close();
163
171
  int rnd_next(unsigned char *buf) {
255
263
  string cursor_state;
256
264
  void CURSOR_NEW_STATE(const string &new_state);
257
265
  Session* user_session;
 
266
  uint64_t id;
258
267
};
259
268
 
260
269
int SEAPITesterCursor::doOpen(const identifier::Table &identifier, int mode, uint32_t test_if_locked)
423
432
  state_multimap_iter cur= cursor_state_transitions.find(cursor_state);
424
433
  if (cursor_state_transitions.count(cursor_state) == 0)
425
434
  {
426
 
    cerr << "ERROR: Invalid Cursor state: " << cursor_state << endl
427
 
         << "This should *NEVER* happen."
428
 
         << endl
429
 
         << "i.e. you've really screwed it up and you should be ashamed of "
430
 
         << "yourself." << endl;
 
435
    std::cerr << "ERROR: Invalid Cursor state: " << cursor_state << std::endl
 
436
      << "This should *NEVER* happen."
 
437
      << std::endl
 
438
      << "i.e. you've really screwed it up and you should be ashamed of "
 
439
      << "yourself." << std::endl;
431
440
    assert(cursor_state_transitions.count(cursor_state));
432
441
  }
433
442
 
442
451
  if (cur == cursor_state_transitions.end()
443
452
      || new_state.compare((*cur).second))
444
453
  {
445
 
    cerr << "ERROR: Invalid Cursor state transition!" << endl
 
454
    std::cerr << "ERROR: Invalid Cursor state transition!" << std::endl
446
455
         << "Cursor " << this << "Cannot go from "
447
 
         << cursor_state << " to " << new_state << endl;
 
456
         << cursor_state << " to " << new_state << std::endl;
448
457
    assert(false);
449
458
  }
450
459
 
451
460
  cursor_state= new_state;
452
461
 
453
 
  cerr << "\t\tCursor " << this << " STATE : " << cursor_state << endl;
 
462
  std::string cursor_state_str("Cursor ");
 
463
  char nr[50];
 
464
  snprintf(nr, sizeof(nr), "%"PRIu64, this->id);
 
465
  cursor_state_str.append(nr);
 
466
  cursor_state_str.append(" ");
 
467
  cursor_state_str.append(cursor_state);
 
468
 
 
469
  engine_state_history.push_back(cursor_state_str);
 
470
 
 
471
  std::cerr << "\t\tCursor " << this << " STATE : " << cursor_state << std::endl;
454
472
}
455
473
 
456
474
} /* namespace drizzled */
518
536
 
519
537
  void doGetTableIdentifiers(drizzled::CachedDirectory &,
520
538
                             const drizzled::identifier::Schema &,
521
 
                             drizzled::identifier::Table::vector &);
 
539
                             drizzled::identifier::table::vector &);
522
540
 
523
541
  virtual int doStartTransaction(Session *session,
524
542
                                 start_transaction_option_t options);
591
609
 
592
610
void SEAPITester::doGetTableIdentifiers(drizzled::CachedDirectory &cd,
593
611
                                        const drizzled::identifier::Schema &si,
594
 
                                        drizzled::identifier::Table::vector &ti)
 
612
                                        drizzled::identifier::table::vector &ti)
595
613
{
596
614
  return getRealEngine()->doGetTableIdentifiers(cd, si, ti);
597
615
}
697
715
  "SEAPITESTER",
698
716
  "1.0",
699
717
  "Stewart Smith",
700
 
  "Test the Storage Engine API callls are in correct order",
 
718
  N_("StorageEngine module for testing call order"),
701
719
  PLUGIN_LICENSE_GPL,
702
 
  seapi_tester_init,     /* Plugin Init */
703
 
  NULL, /* depends */
704
 
  NULL                /* config options   */
 
720
  seapi_tester_init,
 
721
  NULL,
 
722
  NULL
705
723
}
706
724
DRIZZLE_DECLARE_PLUGIN_END;