indexing description: "[ Test for Eiffel-GigaSpaces wrapper loosely based on POCO benchmark example ]" status: "See notice at end of class." legal: "See notice at end of class." date: "$Date$" revision: "$Revision$" class APPLICATION inherit EGS_SPACE_FINDER ARGUMENTS BENCHMARK_PARAMETERS EXCEPTION_MANAGER_FACTORY create make feature -- Initialization make is -- local benchmark_parameters: BENCHMARK_PARAMETERS; test_name: STRING tmp_url: STRING do create test_name.make_empty print ("BenchMark running...%N") if argument_count = 0 then create benchmark_parameters print ("Running Benchmark with Default parameters.%N") benchmark_parameters.set_url ("/./mySpace") benchmark_parameters.set_warmups (1) benchmark_parameters.set_repeats (2) benchmark_parameters.set_threads (1) benchmark_parameters.set_payload_size (1000) benchmark_parameters.set_iterations (10000) benchmark_parameters.set_batch_size (100) benchmark_parameters.set_object_type ("Payload") benchmark_parameters.set_transaction_mode (benchmark_parameters.transaction_mode) elseif argument_count < 8 then print ("Usage of benchmark:%N") print (" - space url%N") print (" - number of runs before timing%N") print (" - number of repeats%N") print (" - number of Iterations we use%N") print (" - object payload, if it has fields of payload%N") print (" - size of batch for batch commands%N") print (" - class name of object [Base, Mixed, Payload, PayloadFifo, Doubles]%N") print (" - type of transaction [false,true,jini]%N") print (" - specific test name [write,read,take,query,readmultiple,writeMultiple]%N") else create benchmark_parameters benchmark_parameters.set_url (argument (1)) benchmark_parameters.set_warmups (argument (2).to_integer) benchmark_parameters.set_repeats (argument (3).to_integer) benchmark_parameters.set_threads (1) benchmark_parameters.set_iterations (argument (4).to_integer) benchmark_parameters.set_payload_size (argument (5).to_integer) benchmark_parameters.set_batch_size (argument (6).to_integer) benchmark_parameters.set_object_type (argument (7)) benchmark_parameters.set_transaction_mode (string_to_transaction_mode (argument (8))) -- Workaround for running with Local Cache in TGrid if benchmark_parameters.url.has_substring ("&useLocalCache=true") then benchmark_parameters.set_using_local_cache (True) create tmp_url.make_from_string (benchmark_parameters.url) tmp_url.replace_substring_all ("&useLocalCache=true","") benchmark_parameters.set_local_cache_remote_url (tmp_url) end end if benchmark_parameters /= Void then if argument_count > 8 then test_name := argument (9); end perform_benchmark (benchmark_parameters, test_name) end --------------------------------------- -- the end --------------------------------------- print ("Benchmark application finished%N") end perform_benchmark (parameters: BENCHMARK_PARAMETERS; test_name: STRING) is local benchmark: BENCHMARK space_proxy, cache_proxy: EGS_SPACE_PROXY number_of_retry: INTEGER do benchmark := create_benchmark (parameters) if benchmark /= Void then print ("-----------B E N C H M A R K S T A R T E D ! -----%N") print ("---------------------------------------------------%N") print ("SpaceURL :") print (parameters.url) print ("%N") print ("Warmups :") print (parameters.warmups) print ("%N") print ("Repeats :") print (parameters.repeats) print ("%N") print ("iterations :") print (parameters.iterations) print ("%N") print ("Payload Size :") print (parameters.payload_size) print ("%N") print ("Batch Size :") print (parameters.batch_size) print ("%N") print ("Object type :") print (parameters.object_type) print ("%N") print ("Use Transaction :") print (transaction_mode_to_string (parameters.transaction_mode)) print ("%N") print ("Test name :") print (test_name) print ("%N") -- Find the space proxy print ("Connecting to Space...%N") from number_of_retry := 0 until number_of_retry > 10 or space_proxy /= Void loop space_proxy := find_space (benchmark.url) number_of_retry := number_of_retry + 1; end if space_proxy /= Void then if benchmark.is_using_local_cache then benchmark.set_space_proxy_cache (find_space(parameters.local_cache_remote_url)) end print ("Connected to: ") print (benchmark.url) print (" OK!%N") benchmark.init (space_proxy) if test_name.is_empty then run_all_tests (benchmark) else run_test (benchmark, test_name) end else print ("Failed Connecting to: ") print (benchmark.url) print ("%N") end end end run_all_tests (benchmark: BENCHMARK) is -- do run_test (benchmark, "write") run_test (benchmark, "update"); run_test (benchmark, "read"); run_test (benchmark, "take"); run_test (benchmark, "writeMultiple"); run_test (benchmark, "readMultiple"); run_test (benchmark, "takeMultiple"); run_test (benchmark, "notify"); run_test (benchmark, "GSIterator"); run_test (benchmark, "query"); end run_test (benchmark: BENCHMARK; test_name: STRING) is local test: BENCHMARK_TEST do test := create_test (test_name) if test /= Void then test.set_benchmark (benchmark) perform_base_test_cycle (test) end end create_test (test_name: STRING): BENCHMARK_TEST is do if test_name.is_equal ("read") then create {BENCHMARK_TEST_READ} Result elseif test_name.is_equal ("readMultiple") then create {BENCHMARK_TEST_READ_MULTIPLE} Result elseif test_name.is_equal ("write") then create {BENCHMARK_TEST_WRITE} Result elseif test_name.is_equal ("writeMultiple") then create {BENCHMARK_TEST_WRITE_MULTIPLE} Result elseif test_name.is_equal ("take") then create {BENCHMARK_TEST_TAKE} Result elseif test_name.is_equal ("takeMultiple") then create {BENCHMARK_TEST_TAKE_MULTIPLE} Result elseif test_name.is_equal ("update") then create {BENCHMARK_TEST_UPDATE} Result elseif test_name.is_equal ("notify") then create {BENCHMARK_TEST_NOTIFY} Result elseif test_name.is_equal ("query") then -- TODO elseif test_name.is_equal ("GSIterator") then -- TODO end end create_benchmark (parameters: BENCHMARK_PARAMETERS): BENCHMARK is require parameters_not_void: parameters /= Void local obj_type: STRING do obj_type := parameters.object_type if obj_type /= Void then if obj_type.is_equal ("Base") then create {BENCHMARK_BASE} Result.make (parameters) elseif obj_type.is_equal ("Mixed") then create {BENCHMARK_WITH_PAYLOAD_AND_PRIMITIVES} Result.make (parameters) elseif obj_type.is_equal ("Payload") then create {BENCHMARK_WITH_PAYLOAD} Result.make (parameters) elseif obj_type.is_equal ("PayloadFifo") then create {BENCHMARK_WITH_PAYLOAD_FIFO} Result.make (parameters) elseif obj_type.is_equal ("Doubles") then create {BENCHMARK_WITH_DOUBLES} Result.make (parameters) end end if Result = Void then create {BENCHMARK_BASE} Result.make (parameters) end end perform_base_test_cycle (test: BENCHMARK_TEST) is local failed: BOOLEAN i: INTEGER do print ("start test ") print (test.name) print ("%N") test.set_proxy (test.benchmark.space_proxy) if test.benchmark.is_using_local_cache then test.set_proxy_cache (test.benchmark.space_proxy_cache) end from i := 1 until failed or i > test.benchmark.repeats loop test.set_up test.run test.tear_down failed := test_exception or test.failed clean_data (test) i := i + 1 end if failed then print ("%Ttest ") print (test.name) print (" failed") print ("%N") else print ("%Ttest ") print (test.name) print (" passed") print (" duration = " + test.duration.out) print ("%N") end print ("end test ") print (test.name) print ("%N") end find_space (an_url: STRING): EGS_SPACE_PROXY is -- Find space proxy by space url local was_error: BOOLEAN do if not was_error then Result := find_space_by_string (an_url) -- Test and clear the possible exception occured -- Note that this code is only for record_xap_exception exceptions_handling_discipline if was_exception then handle_exception (last_exception) clear_exception end end rescue -- Note that this code is only for raise_xap_exception exceptions_handling_discipline handle_exception (exception_manager.last_exception) was_error := true retry end test_exception: BOOLEAN is -- Test and clear the possible exception occured do if was_exception then Result := True print ("%TException occured, ExceptionName = " + last_exception.name + "%N") clear_exception end end handle_exception (an_exception: EXCEPTION) is -- Report the exception occured local xap_exception: EGS_XAP_EXCEPTION do xap_exception ?= an_exception if xap_exception /= Void then print ("XAP Exception occured, ExceptionName = " + xap_exception.name + "%N") end end clean_data (test: BENCHMARK_TEST) is -- local tmpl: BENCHMARK_BASE_OBJECT do tmpl := test.benchmark.create_new_object_template if test.benchmark.is_using_local_cache then test.space_proxy.clean if test.benchmark.is_using_local_cache then test.space_proxy_cache.clean end else test.space_proxy.clear (tmpl, Void) end end indexing copyright: "Copyright (c) 2008, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software 356 Storke Road, Goleta, CA 93117 USA Telephone 805-685-1006, Fax 805-685-6869 Website http://www.eiffel.com Customer support http://support.eiffel.com ]" end -- class APPLICATION