diff options
author | harrisb <harrisb@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2013-01-14 19:54:37 +0000 |
---|---|---|
committer | harrisb <harrisb@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2013-01-14 19:54:37 +0000 |
commit | 8df96f7a09d317e7762bd704c99ee3cda76e78ee (patch) | |
tree | 1d06b5ce3a73042a465312187dea1926b4a27341 | |
parent | 0b634dcc4fcf3f1080d555bb2f36d6316039cb68 (diff) | |
download | ATCD-8df96f7a09d317e7762bd704c99ee3cda76e78ee.tar.gz |
Mon Jan 14 19:51:29 UTC 2013 Byron Harris <harrisb@ociweb.com>
-rw-r--r-- | TAO/OCI_RE_ChangeLog | 19 | ||||
-rw-r--r-- | TAO/bin/tao_orb_tests.lst | 1 | ||||
-rw-r--r-- | TAO/bin/tao_other_tests.lst | 8 | ||||
-rw-r--r-- | TAO/tests/Storable/README | 14 | ||||
-rw-r--r-- | TAO/tests/Storable/Savable.cpp | 115 | ||||
-rw-r--r-- | TAO/tests/Storable/Savable.h | 34 | ||||
-rwxr-xr-x | TAO/tests/Storable/run_test.pl | 24 | ||||
-rw-r--r-- | TAO/tests/Storable/test.cpp | 115 |
8 files changed, 227 insertions, 103 deletions
diff --git a/TAO/OCI_RE_ChangeLog b/TAO/OCI_RE_ChangeLog index 24665e7ffbd..69e0590688c 100644 --- a/TAO/OCI_RE_ChangeLog +++ b/TAO/OCI_RE_ChangeLog @@ -1,3 +1,22 @@ +Mon Jan 14 19:51:29 UTC 2013 Byron Harris <harrisb@ociweb.com> + + * tests/Storable/README: + * tests/Storable/Savable.h: + * tests/Storable/Savable.cpp: + * tests/Storable/run_test.pl: + * tests/Storable/test.cpp: + + Clean up of the test. + + * bin/tao_orb_tests.lst: + + Added Storable test to the list. + + * bin/tao_other_tests.lst: + + Removed restriction that FT_Naming tests + are not to run for static builds. + Sun Jan 13 01:53:16 UTC 2013 "Kevin Stanley" <stanleyk@ociweb.com> * orbsvcs/Naming_Service/README.FT_Naming: diff --git a/TAO/bin/tao_orb_tests.lst b/TAO/bin/tao_orb_tests.lst index 3b092a56fa7..c1c04c99e0b 100644 --- a/TAO/bin/tao_orb_tests.lst +++ b/TAO/bin/tao_orb_tests.lst @@ -470,6 +470,7 @@ TAO/tests/Bug_3853_Regression/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MI TAO/tests/Multiple_Retry_Tests/Retry_On_Connection_Failure/run_test.pl: TAO/tests/Multiple_Retry_Tests/Retry_On_Connection_Failure/run_test.pl -oneway: TAO/tests/Multiple_Retry_Tests/Retry_On_Reply_Failure/run_test.pl: +TAO/tests/Storable/run_test.pl: TAO/DevGuideExamples/BiDirectionalGIOP/run_test.pl: !MINIMUM !CORBA_E_MICRO TAO/DevGuideExamples/GettingStarted/run_test.pl: TAO/DevGuideExamples/LocalObjects/Messenger/run_test.pl: diff --git a/TAO/bin/tao_other_tests.lst b/TAO/bin/tao_other_tests.lst index 92eee5f16a6..1a204a05a38 100644 --- a/TAO/bin/tao_other_tests.lst +++ b/TAO/bin/tao_other_tests.lst @@ -265,7 +265,7 @@ TAO/orbsvcs/DevGuideExamples/ValueTypes/Notify/run_test.pl: !ST !MINIMUM !CORBA_ TAO/orbsvcs/DevGuideExamples/InterfaceRepo/run_test.pl: !MINIMUM !NO_IFR !CORBA_E_COMPACT !CORBA_E_MICRO !WCHAR !ACE_FOR_TAO TAO/orbsvcs/DevGuideExamples/PortableInterceptors/PICurrent_NameService/run_test.pl: !MINIMUM !DISABLE_INTERCEPTORS !LynxOS !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO TAO/utils/nsgroup/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !STATIC !ACE_FOR_TAO !LynxOS !ST -TAO/orbsvcs/tests/FT_Naming/Load_Balancing/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !STATIC !ACE_FOR_TAO !LynxOS !ST -TAO/orbsvcs/tests/FT_Naming/Replication/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !STATIC !ACE_FOR_TAO !LynxOS !ST -TAO/orbsvcs/tests/FT_Naming/FaultTolerant/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !STATIC !ACE_FOR_TAO !LynxOS !ST -TAO/orbsvcs/tests/FT_Naming/Federation/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !STATIC !ACE_FOR_TAO !LynxOS !ST +TAO/orbsvcs/tests/FT_Naming/Load_Balancing/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !ACE_FOR_TAO !LynxOS !ST +TAO/orbsvcs/tests/FT_Naming/Replication/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !ACE_FOR_TAO !LynxOS !ST +TAO/orbsvcs/tests/FT_Naming/FaultTolerant/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !ACE_FOR_TAO !LynxOS !ST +TAO/orbsvcs/tests/FT_Naming/Federation/run_test.pl: !MINIMUM !CORBA_E_COMPACT !CORBA_E_MICRO !DISABLE_INTERCEPTORS !ACE_FOR_TAO !LynxOS !ST diff --git a/TAO/tests/Storable/README b/TAO/tests/Storable/README new file mode 100644 index 00000000000..b5086ded191 --- /dev/null +++ b/TAO/tests/Storable/README @@ -0,0 +1,14 @@ +$Id$ + +This test verifies that TAO::Storable_FlatFileStream along +with TAO::Storable_File_Guard can be used to save/restore +the state of an object (an instance of Savable) to the +file system. To verifing Storable_File_Guard's file locking, +two processes that read/write from the persistent store run +in parallel. + +Note that this test does not explicitly validate the code in +Storable_File_Guard that deals with the persistent store +being obsolete. + + diff --git a/TAO/tests/Storable/Savable.cpp b/TAO/tests/Storable/Savable.cpp index 3514728f2ad..0024f00bf18 100644 --- a/TAO/tests/Storable/Savable.cpp +++ b/TAO/tests/Storable/Savable.cpp @@ -56,7 +56,7 @@ Savable_File_Guard::get_object_last_changed () void Savable_File_Guard::load_from_stream () { - savable_.load (this->peer ()); + savable_.read (this->peer ()); savable_.loaded_from_stream_ = true; this->peer ().rewind (); } @@ -76,14 +76,18 @@ Savable_File_Guard::create_stream (const char * mode) Savable::Savable (TAO::Storable_Factory & storable_factory) : storable_factory_(storable_factory) , loaded_from_stream_ (false) - , i_(42) - , bytes_size_(0) { - this->bytes_ = new char [this->bytes_size_max]; - for (int i = 0; i < this->bytes_size_max; ++i) + for (int index = 0; index < 2; ++index) { - this->bytes_[i] = 255; + this->i_[index] = 0; + this->ui_[index] = 0; + this->bytes_size_[index] = 0; + this->bytes_[index] = new char [this->bytes_size_max]; + for (int i = 0; i < this->bytes_size_max; ++i) + { + this->bytes_[index][i] = 255; + } } ACE_Auto_Ptr<TAO::Storable_Base> stream (storable_factory_.create_stream("test.dat", "r")); @@ -100,6 +104,10 @@ Savable::Savable (TAO::Storable_Factory & storable_factory) Savable::~Savable () { + for (int index = 0; index < 2; ++index) + { + delete []this->bytes_[index]; + } } bool @@ -109,26 +117,31 @@ Savable::is_loaded_from_stream () } void -Savable::load (TAO::Storable_Base & stream) +Savable::read (TAO::Storable_Base & stream) { stream.rewind (); if (!stream.good ()) throw Storable_Exception (stream.rdstate ()); - for (int i = 0; i < 2; ++i) + for (int index = 0; index < 2; ++index) { - stream >> string_[i]; + stream >> this->string_[index]; if (!stream.good ()) throw Storable_Exception (stream.rdstate ()); - } - stream >> i_; - if (!stream.good ()) - throw Storable_Exception (stream.rdstate ()); - stream >> this->bytes_size_; - stream.read (this->bytes_size_, this->bytes_); - if (!stream.good ()) - throw Storable_Exception (stream.rdstate ()); + stream >> this->i_[index]; + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + + stream >> this->ui_[index]; + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + + stream >> this->bytes_size_[index]; + stream.read (this->bytes_size_[index], this->bytes_[index]); + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + } } void @@ -138,22 +151,27 @@ Savable::write (TAO::Storable_Base & stream) if (!stream.good ()) throw Storable_Exception (stream.rdstate ()); - for (int i = 0; i < 2; ++i) + for (int index = 0; index < 2; ++index) { - stream << string_[i]; + stream << this->string_[index]; if (!stream.good ()) throw Storable_Exception (stream.rdstate ()); - } - stream << i_; - if (!stream.good ()) - throw Storable_Exception (stream.rdstate ()); - stream << this->bytes_size_; - if (!stream.good ()) - throw Storable_Exception (stream.rdstate ()); - stream.write (this->bytes_size_, this->bytes_); - if (!stream.good ()) - throw Storable_Exception (stream.rdstate ()); + stream << this->i_[index]; + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + + stream << this->ui_[index]; + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + + stream << this->bytes_size_[index]; + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + stream.write (this->bytes_size_[index], this->bytes_[index]); + if (!stream.good ()) + throw Storable_Exception (stream.rdstate ()); + } stream.flush (); } @@ -174,39 +192,54 @@ Savable::string_get (int index) } void -Savable::int_set (int i) +Savable::int_set (int index, int i) { Savable_File_Guard fg(*this, "rw"); - this->i_ = i; + this->i_[index] = i; this->write (fg.peer ()); } int -Savable::int_get () +Savable::int_get (int index) +{ + Savable_File_Guard fg(*this, "r"); + return this->i_[index]; +} + +void +Savable::unsigned_int_set (int index, unsigned int ui) +{ + Savable_File_Guard fg(*this, "rw"); + this->ui_[index] = ui; + this->write (fg.peer ()); +} + +unsigned int +Savable::unsigned_int_get (int index) { Savable_File_Guard fg(*this, "r"); - return this->i_; + return this->ui_[index]; } void -Savable::bytes_set (int size, char * bytes) +Savable::bytes_set (int index, int size, char * bytes) { Savable_File_Guard fg(*this, "rw"); - bytes_size_ = size; - for (int i = 0; i < this->bytes_size_; ++i) + this->bytes_size_[index] = size; + for (int i = 0; i < this->bytes_size_[index]; ++i) { - this->bytes_[i] = bytes[i]; + this->bytes_[index][i] = bytes[i]; } this->write (fg.peer ()); } int -Savable::bytes_get (char *& bytes) +Savable::bytes_get (int index, char * bytes) { Savable_File_Guard fg(*this, "r"); - for (int i = 0; i < this->bytes_size_; ++i) + for (int i = 0; i < this->bytes_size_[index]; ++i) { - bytes[i] = this->bytes_[i]; + bytes[i] = this->bytes_[index][i]; } - return this->bytes_size_; + return this->bytes_size_[index]; } diff --git a/TAO/tests/Storable/Savable.h b/TAO/tests/Storable/Savable.h index c4dc849a306..1eccc1ed6de 100644 --- a/TAO/tests/Storable/Savable.h +++ b/TAO/tests/Storable/Savable.h @@ -14,20 +14,26 @@ class Storable_Exception public: Storable_Exception(TAO::Storable_Base::Storable_State state) - : state_(state) + : stream_state_(state) { } TAO::Storable_Base::Storable_State get_state () { - return state_; + return stream_state_; } private: - TAO::Storable_Base::Storable_State state_; + TAO::Storable_Base::Storable_State stream_state_; }; -/// A class whose contents are to be saved +/// A simple class to use for testing whose contents +/// are to be persisted. It has attributes for each basic +/// type that can be saved. +/// There are two attributes for each type so that +/// one process can write one attribute of the same +/// type while another process reads another attribute +/// of the same type. class Savable { public: @@ -38,11 +44,14 @@ class Savable void string_set (int index, const ACE_CString &s); const ACE_CString & string_get (int index); - void int_set (int i); - int int_get (); + void int_set (int index, int i); + int int_get (int index); - void bytes_set (int size, char * bytes); - int bytes_get (char *& bytes); + void unsigned_int_set (int index, unsigned int ui); + unsigned int unsigned_int_get (int index); + + void bytes_set (int index, int size, char * bytes); + int bytes_get (int index, char * bytes); bool is_loaded_from_stream (); @@ -50,15 +59,16 @@ class Savable TAO::Storable_Factory & storable_factory_; bool loaded_from_stream_; time_t last_changed_; - void load (TAO::Storable_Base & stream); + void read (TAO::Storable_Base & stream); void write (TAO::Storable_Base & stream); ACE_CString string_[2]; - int i_; + int i_[2]; + unsigned int ui_[2]; static const int bytes_size_max; - int bytes_size_; - char * bytes_; + int bytes_size_[2]; + char * bytes_[2]; friend class Savable_File_Guard; }; diff --git a/TAO/tests/Storable/run_test.pl b/TAO/tests/Storable/run_test.pl index d816cd4ebb2..ce8de975046 100755 --- a/TAO/tests/Storable/run_test.pl +++ b/TAO/tests/Storable/run_test.pl @@ -20,8 +20,26 @@ my $test2 = PerlACE::TestTarget::create_target (2) || die "Create target 1 faile $T2 = $test2->CreateProcess ("test", "-i 1"); -$T1->Spawn (); -$T2->SpawnWaitKill ($test2->ProcessStartWaitInterval()); -$T1->WaitKill ($test1->ProcessStopWaitInterval()); +$test1_status = $T1->Spawn (); + +if ($test1_status != 0) { + print STDERR "ERROR: test 1 returned $test1_status\n"; + exit 1; +} + +$test2_status = $T2->SpawnWaitKill ($test2->ProcessStartWaitInterval()); + +if ($test2_status != 0) { + print STDERR "ERROR: test 2 returned $test2_status\n"; + exit 1; +} + + +$test1_status = $T1->WaitKill ($test1->ProcessStopWaitInterval()); + +if ($test1_status != 0) { + print STDERR "ERROR: test 1 returned $test1_status\n"; + exit 1; +} $test1->DeleteFile ($persistent_file); diff --git a/TAO/tests/Storable/test.cpp b/TAO/tests/Storable/test.cpp index 2edfc91f9ee..c9ed11132df 100644 --- a/TAO/tests/Storable/test.cpp +++ b/TAO/tests/Storable/test.cpp @@ -1,9 +1,11 @@ // $Id$ -// Writes/reads a string to file multiple times with a -// sleep after each write. Indented to be ran in -// multiple processes to verify file locking is done -// properly. +// Assumed to be one of two processes that +// writes/reads from persistent store. +// Each process writes one group of attributes +// and reads from the group written by the +// other process. After reading a check is +// made that expected values are read. #include "Savable.h" @@ -19,7 +21,7 @@ const ACE_TCHAR *persistence_file = ACE_TEXT("test.dat"); int num_loops = 10; int sleep_msecs = 100; -int string_index = 0; +int write_index = 0; int parse_args (int argc, ACE_TCHAR *argv[]) @@ -39,20 +41,29 @@ parse_args (int argc, ACE_TCHAR *argv[]) break; case 'i': - string_index = ACE_OS::atoi (get_opts.opt_arg ()); + write_index = ACE_OS::atoi (get_opts.opt_arg ()); break; case '?': default: ACE_ERROR_RETURN ((LM_ERROR, - "usage: %s " - "-n <number-of-loops>" - "-s <milliseconds-to-sleep-in-loop>" - "-i <0 to modify string1, 1 to modify string2>" - "\n", + ACE_TEXT("usage: %s ") + ACE_TEXT("-n <number-of-loops> ") + ACE_TEXT("-s <milliseconds-to-sleep-in-loop> ") + ACE_TEXT("-i <index-used-for-writing> ") + ACE_TEXT("\n"), argv [0]), -1); } + + if (write_index != 0 && write_index != 1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT("Error: Value passed to -i should be ") + ACE_TEXT("0 or 1.")), + -1); + } + // Indicates successful parsing of the command line return 0; } @@ -63,57 +74,78 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) if (parse_args (argc, argv) != 0) return 1; + int read_index = write_index ? 0 : 1; + TAO::Storable_FlatFileFactory factory ("./"); + ACE_CString str_write_value = "test_string"; + int int_write_value = -100; + unsigned int unsigned_int_write_value = 100; + const int bytes_size = 8; - char * bytes_set = new char [bytes_size]; - char * bytes_get = new char [bytes_size]; + char bytes_write_value[bytes_size]; + char bytes_read[bytes_size]; // Set 1st byte to 32 (ASCII space) to // make sure fscanf doesn't consume it // when reading the size. - bytes_set[0] = 32; + bytes_write_value[0] = 32; for (int i = 1; i < bytes_size; ++i) { - bytes_set[i] = i; + bytes_write_value[i] = i; } try { - Savable savable(factory); - - // In case the file was read, bytes better match up - if (savable.is_loaded_from_stream ()) + for (int j = 0; j < num_loops; ++j) { - int bytes_read_size = savable.bytes_get (bytes_get); - ACE_ASSERT (bytes_read_size == bytes_size); - for (int k = 0; k < bytes_size; ++k) + + // Constructor called num_loops times. + // Each time state read from persistent store. + Savable savable(factory); + + // If the file was read, verify what was + // written from other process is correct. + if (savable.is_loaded_from_stream ()) { - ACE_ASSERT (bytes_get[k] == bytes_set[k]); - } - } - ACE_Time_Value sleep_time (0, 1000*sleep_msecs); + int int_read = savable.int_get(read_index); + // If value read is not 0 then the other + // process have written to persistent store. + // If not, it's too soon test. + if (int_read != 0) + { + ACE_ASSERT (int_read == int_write_value); + + const ACE_CString & str_read = savable.string_get(read_index); + ACE_ASSERT (str_read == str_write_value); + + unsigned int unsigned_int_read = savable.unsigned_int_get (read_index); + ACE_ASSERT (unsigned_int_read == unsigned_int_write_value); + + int bytes_read_size = savable.bytes_get (read_index, bytes_read); + ACE_ASSERT (bytes_read_size == bytes_size); + for (int k = 0; k < bytes_size; ++k) + { + ACE_ASSERT (bytes_read[k] == bytes_write_value[k]); + } + } + } - char index_str[2]; - ACE_OS::sprintf (index_str, "%d", string_index); - ACE_CString str_write = ACE_CString("string") + ACE_CString(index_str); - ACE_CString str_read; + ACE_Time_Value sleep_time (0, 1000*sleep_msecs); - for (int j = 0; j < num_loops; ++j) - { - savable.string_set(string_index, str_write); - savable.int_set(j); - savable.bytes_set(bytes_size, bytes_set); + // Write out state + savable.string_set(write_index, str_write_value); + savable.int_set(write_index, int_write_value); + savable.unsigned_int_set(write_index, unsigned_int_write_value); + savable.bytes_set(write_index, bytes_size, bytes_write_value); ACE_OS::sleep (sleep_time); - str_read = savable.string_get (string_index); - ACE_ASSERT (str_write == str_read); - int bytes_read_size = savable.bytes_get (bytes_get); - ACE_ASSERT (bytes_read_size == bytes_size); + int bytes_size = savable.bytes_get (write_index, bytes_read); for (int k = 0; k < bytes_size; ++k) { - ACE_ASSERT (bytes_get[k] == bytes_set[k]); + ACE_ASSERT (bytes_read[k] == bytes_write_value[k]); } } + } catch (Storable_Exception &ex) @@ -122,8 +154,5 @@ ACE_TMAIN(int argc, ACE_TCHAR *argv[]) ex.get_state () << std::endl; } - delete [] bytes_set; - delete [] bytes_get; - return 0; } |