def test_clearing_non_empty_queue(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') queue.clear(['q2']) assert_false(queue.empty(['q1'])) queue.clear(['q1']) assert_true(queue.empty(['q1']))
def test_select_queue_to_get_from(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') queue.put(2, 'q2') value, from_queue = queue.get(['q2']) assert_equal(value, 2) assert_equal(from_queue, 'q2')
def test_noarg_multiqueue_works_like_standard_queue(): queue = MultiQueue() queue.put(1) queue.put(2) value, _ = queue.get() assert_equal(value, 1) value, _ = queue.get() assert_equal(value, 2)
def test_bidirectional_put(): queue = MultiQueue() queue.put(1) queue.append(2) queue.appendleft(3) assert_equal(queue.get(), (2, 'default')) assert_equal(queue.get(), (1, 'default')) assert_equal(queue.get(), (3, 'default'))
def test_get_from_many_queues(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') queue.put(2, 'q2') value, from_queue = queue.get(['q1', 'q2']) assert_equal(value, 1) assert_equal(from_queue, 'q1') value, from_queue = queue.get(['q1', 'q2']) assert_equal(value, 2) assert_equal(from_queue, 'q2')
def test_blocked_if_selected_queue_is_empty(): queue = MultiQueue(['q1', 'q2']) output = [] def consumer(): output.append(queue.get(['q2'])) queue.put(1, 'q1') tconsumer = threading.Thread(target=consumer) tconsumer.start() time.sleep(0.5) assert_equal(len(output), 0) queue.put(2, 'q2') time.sleep(0.5) assert_equal(len(output), 1) value, from_queue = output[0] assert_equal(value, 2) assert_equal(from_queue, 'q2') tconsumer.join()
def _get_ready_for_service(self): """Perform further initialization. Here are initialized those components that need any information available at runtime and thus couldn't be initialized by the constructor. """ # TODO: do we need this at all? self.logger.debug(u"Initializing Warebox...") self._warebox = Warebox(self.cfg) self.logger.debug(u"Initializing Warebox Cache...") session_queue = MultiQueue([ 'servermessage', # Messages sent by the server 'operation', # PathnameOperation objects to handle 'usercommand', # Commands sent by the user 'sessioncommand', # ServerSession internal use commands 'systemcommand' # Commands sent by other client components ]) self.logger.debug(u"Initializing Event Queue...") self.queue = EventsQueue(self._internal_facade, session_queue) self.logger.debug(u"Initializing Storage Connector...") self.connector = StorageConnector(self._warebox, self.cfg) self.logger.debug(u"Initializing FileSystem Watcher...") self.FSWatcher = filesystemwatcher.watcher_class(self._warebox, self.queue, start_suspended=True) self.logger.debug(u"Initializing Startup Synchronization...") self.startup_synchronization = StartupSynchronization( self._warebox, self.storage_cache, self.queue) self.logger.debug(u"Initializing Server Session...") self._server_session = ServerSession(self.cfg, self._warebox, self.storage_cache, self.startup_synchronization, self.FSWatcher, self.linker, self._metadata_db, self.hashesDB, self._internal_facade, self._ui_controller, self.lockfile_fd, auto_start=self.auto_start, input_queue=session_queue, scheduler=self._scheduler) self.logger.debug(u"Initialization completed successfully")
def test_get_from_nonexistent_queue(): queue = MultiQueue(['q1']) queue.get(['q1', 'q2'])
def test_queue_emptiness(): queue = MultiQueue(['q1', 'q2']) assert_true(queue.empty(['q1'])) assert_true(queue.empty(['q2'])) assert_true(queue.empty(['q1', 'q2']))
def test_put_to_nonexistent_queue(): queue = MultiQueue(['q1']) queue.put(1, 'q2')
def test_access_specific_queue(): queue = MultiQueue(['myqueue']) queue.put(1, 'myqueue') value, from_queue = queue.get(['myqueue']) assert_equal(value, 1) assert_equal(from_queue, 'myqueue')
def test_queue_non_emptiness(): queue = MultiQueue(['q1', 'q2']) queue.put(1, 'q1') assert_false(queue.empty(['q1'])) assert_true(queue.empty(['q2'])) assert_false(queue.empty(['q1', 'q2']))
def test_unsuccessful_nonblocking_get(): queue = MultiQueue() with assert_raises(Empty): queue.get(blocking=False)
def test_clearing_empty_queue(): queue = MultiQueue() queue.clear() assert_true(True)
def test_successful_nonblocking_get(): queue = MultiQueue() queue.put(1) assert_equal(queue.get(blocking=False), (1, 'default'))