indexing description: "Test case for testing the concurrent queue" library: "elogger" copyright: "Copyright (c) 2006, AXA Rosenberg, and others (see copyright.txt)" author: "Ulrich Weiss, and others" license: "Eiffel Forum License v2 (see forum.txt)" date: "$Date: $" revision: "$Revision: $" archive: "$Archive: $" deferred class TEST_ELOG_CONCURRENT_QUEUE inherit TS_TEST_CASE undefine name_of_id, execute_i_th end feature -- Test test_queue_nonthreaded is -- Test the concurrent queue. -- Threaded tests are done in the logging-testcases. (TODO) local q: ELOG_CONCURRENT_LINKED_QUEUE [INTEGER] -- expanded type q2: ELOG_CONCURRENT_LINKED_QUEUE [STRING] -- non-expanded type i: INTEGER s: STRING do create q.make q.put (34) q.put (0) i := q.remove assert_equal ("Remove", 34, i) q.put(4) i := q.remove assert_booleans_equal ("is_empty", false, q.is_empty) assert_equal ("Remove", 0, i) i := q.remove assert_booleans_equal ("is_empty", true, q.is_empty) assert_equal ("Remove", 4, i) i := q.remove assert_equal ("Remove", 0, i) assert_booleans_equal ("is_empty", true, q.is_empty) create q2.make q2.put ("a string") q2.put ("uh, another string!") s := q2.remove assert_equal ("Remove", "a string", s) q2.put ("yep, thats right") s := q2.remove assert_booleans_equal ("is_empty", false, q2.is_empty) assert_equal ("Remove", "uh, another string!", s) s := q2.remove assert_booleans_equal ("is_empty", true, q2.is_empty) assert_equal ("Remove", "yep, thats right", s) s := q2.remove assert_equal ("Remove", Void, s) assert_booleans_equal ("is_empty", true, q2.is_empty) end test_cv_queue_nonthreaded is -- Test the concurrent queue. -- Threaded tests are done in the logging-testcases. (TODO) local q: ELOG_CONCURRENT_LINKED_QUEUE_CV [INTEGER] -- expanded type q2: ELOG_CONCURRENT_LINKED_QUEUE_CV [STRING] -- non-expanded type i: INTEGER s: STRING do -- simple test 1 create q.make q.put (34) q.put (0) i := q.get assert_equal ("Remove", 34, i) q.put(4) i := q.get assert_booleans_equal ("is_empty", false, q.is_empty) assert_equal ("Remove", 0, i) i := q.get assert_booleans_equal ("is_empty", true, q.is_empty) assert_equal ("Remove", 4, i) -- simple test 2 create q2.make q2.put ("a string") q2.put ("uh, another string!") s := q2.get assert_equal ("Remove", "a string", s) q2.put ("yep, thats right") s := q2.get assert_booleans_equal ("is_empty", false, q2.is_empty) assert_equal ("Remove", "uh, another string!", s) s := q2.get assert_booleans_equal ("is_empty", true, q2.is_empty) assert_equal ("Remove", "yep, thats right", s) end test_producer_consumer is -- test producer-consumer (manual test with infinite puts & gets) local q2: ELOG_CONCURRENT_LINKED_QUEUE_CV [STRING] p1: T_ELOG_QUEUE_PRODUCER c1, c2, c3: T_ELOG_QUEUE_CONSUMER a: THREAD_ATTRIBUTES do -- create q2.make -- -- q2.set_max_size (100) -- create c1.make (q2, 1) -- create a.make -- a.set_detached (True) -- c1.launch_with_attributes (a) -- create c2.make (q2, 2) -- c2.launch_with_attributes (a) -- create c3.make (q2, 3) -- c3.launch_with_attributes (a) -- create p1.make (q2) -- p1.launch_with_attributes (a) -- c1.join end end