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 BENCHMARK_TEST_NOTIFY inherit BENCHMARK_TEST redefine run end THREAD_CONTROL undefine print end feature name: STRING is -- do Result := "notify" end feature {NONE} -- Implementation run is local template: BENCHMARK_BASE_OBJECT write_object: BENCHMARK_BASE_OBJECT factory: EGS_EVENT_SESSION_FACTORY config: EGS_EVENT_SESSION_CONFIG session: EGS_DATA_EVENT_SESSION listener: BENCHMARK_TEST_NOTIFY_LISTENER registration: EGS_EVENT_REGISTRATION condition: CONDITION_VARIABLE mutex: MUTEX total_number_of_operations: INTEGER operations_per_second_expectation: INTEGER timeout_factor: INTEGER timeout_secs: INTEGER timeout: BOOLEAN do if not failed then -- create a template for the listener template := create_new_object_template -- fill the template with the needed information to retrieve the data set_id (template, 1); -- create an object to write write_object := create_new_object_for_benchmark create factory.make (space_proxy) create config.make (space_proxy) config.set_communication_type ({EGS_EVENT_SESSION_CONFIG}.unicast) session := factory.new_data_event_session (config, Void) -- Create the listener that just counts a received events -- and signals when expected number of notification events is -- received create mutex.make create condition.make create listener.make (benchmark.iterations, condition) -- register the listener to the session (to the space) --print ("%Tbefore add_listener%N") registration := session.add_listener (template, listener, {EGS_LEASE}.forever, {EGS_NOTIFY_MODIFIERS}.notify_write) failed := test_exception if not failed then --print ("%Tafter add_listener%N") total_number_of_operations := benchmark.iterations * benchmark.threads operations_per_second_expectation := 1000; timeout_factor := 2 + benchmark.payload_size // 1000; timeout_secs := timeout_factor * (total_number_of_operations // operations_per_second_expectation + 1); -- Wait for all notification events are received --print ("%TExpected timeout for all callbacks received = " + timeout_secs.out + " seconds%N") --print ("%Tstart writing entries%N") write --print ("%Twrote entries%N") -- Wait for all notification events are received --print ("%Twaiting for callbacks, timeout = "+timeout_secs.out+" seconds%N") mutex.lock from timeout := false until listener.is_finished or timeout loop timeout := not condition.wait_with_timeout (mutex, timeout_secs*1000) end mutex.unlock -- unregister the listener to the session (to the space) session.remove_listener (registration) -- Check the possible exception occured failed := test_exception -- Release listener to allow the garbage collection listener.stop session.close -- NOTE !! We need to destroy it right now. Delaying it to GC leads to the crash registration.dispose -- NOTE !! We need to destroy it right now. Delaying it to GC leads to the crash factory.dispose -- NOTE !! We need to destroy it right now. Delaying it to GC leads to the crash config.dispose -- NOTE !! We need to destroy it right now. Delaying it to GC leads to the crash session.dispose -- Check the possible exception occured failed := test_exception failed := failed or not listener.is_finished --print ("%Tfinished waiting for callbacks. listener.received_notifications_count = " + listener.received_notifications_count.out+ "%N") --print ("%Tstart taking entries%N") --take --print ("%Ttook entries%N") end end rescue -- Note that this code is only for raise_xap_exception exceptions_handling_discipline handle_raised_exception (exception_manager.last_exception) failed := True retry end write is local batch_count: INTEGER tmp_lease: ANY i: INTEGER batch: ARRAY[BENCHMARK_BASE_OBJECT] object: BENCHMARK_BASE_OBJECT do if not failed then batch_count := benchmark.iterations // benchmark.batch_size create batch.make (1, benchmark.batch_size) from i := batch.lower until i > batch.upper loop object := create_new_object_for_benchmark set_uid (object, ""); set_id (object, 1); batch.put (object, i) i := i+1 end start_timing create_transaction from i := 1 until failed or i > batch_count loop tmp_lease := space_proxy.write_multiple (batch, transaction, {EGS_LEASE}.forever); failed := test_exception i := i + 1 end commit_transaction end_timing end rescue -- Note that this code is only for raise_xap_exception exceptions_handling_discipline handle_raised_exception (exception_manager.last_exception) failed := True retry end take is local batch_count: INTEGER template: BENCHMARK_BASE_OBJECT i: INTEGER res: ARRAY[EGS_ENTRY] do if not failed then batch_count := benchmark.iterations // benchmark.batch_size template := create_new_object_template set_id (template, 1); from i := 1 until failed or i > batch_count loop res := space_proxy.take_multiple (template, transaction, benchmark.batch_size); failed := test_exception i := i + 1 end end rescue -- Note that this code is only for raise_xap_exception exceptions_handling_discipline handle_raised_exception (exception_manager.last_exception) failed := True retry end run_iteration (index: INTEGER) is -- do end feature 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