Commits

Guillermo Szeliga committed 7b211b5

- Finally, all tests pass but still need to perform heavy load testing

Comments (0)

Files changed (22)

longtang/actors/actors.py

 import weakref
 
 from evasion.common import net
-from longtang.system import systemref
+from longtang.system import systemref, exceptions as systemexcep
 from longtang.actors import messages
 
 class Address:
 
                 self.logger().debug('Child actor {2} finished...[actor_id: {0}, message: {1}]'.format(self.unique_id(), message.__class__.__name__, message.actor_id()))
 
-                self.__get_system_ref().find_by_id(message.actor_id()).wait()
+                try:
+                    self.__get_system_ref().find_by_id(message.actor_id()).wait()
+                except systemexcep.ActorAlreadyKilled, e:
+                    pass
 
                 children = self.__get_system_ref().get_children(self.unique_id())
 

longtang/actors/actorstestutils.py

 
 from cStringIO import StringIO
 from longtang.actors import actors, messages
-from longtang.system import system, domain as sys_domain, properties
+from longtang.system import system, domain as sys_domain, properties, exceptions
 from longtang.common import interactions
 
 class TestActor(actors.Actor):
 			if self.__config.termination_type is not None:
 				if isinstance(message, self.__config.termination_type):
 					self.logger().debug('Termination message type received....terminating')
-					self.context().get_by_id(self.__config.unique_id).tell(messages.PoisonPill(), self.myself())
-
-	#FIXME Most of this funtionality need to be moved somewhere, potentially to the TestActorRef.tell() method
-	# def test(self,message, sender=None):
-
-	# 	self.logger().debug('Tester.....{0}'.format(message))
-
-	# 	actor_ref = self.context().get_by_id(self.__config.unique_id)
-
-	# 	actor_ref.tell(message, self)
-
-	# 	if self.__config.termination_type is None:
-	# 		actor_ref.tell(messages.PoisonPill(), self)
-	# 	else:
-	# 		moratorium = gevent.Greenlet(self.__force_termination)
-	# 		moratorium.start_later(self.__config.termination_moratorium)
-
-	# 	#TODO Should be able to work with system
-	# 	gevent.joinall([actor_ref._instance()])
-
-	# def inspector(self):
-	# 	return MessageSetInspector(self.messages)
+					self.context().find_by_id(self.__config.unique_id).tell(messages.PoisonPill(), self.myself())
 
 	class TestActorContext():
 
 		self.__unique_id='random-id-to-be-generated'
 		self.__termination_message_type=None
 		self.__termination_moratorium=1 #Seconds
-		self.__terminate_system=True
+		self.__terminate_system=False
 		self.__verbosity=properties.VerbosityLevel.CRITICAL
 
 	def terminate_system(self, value):
 		self.__test_actor_ref=actor_ref
 		self.__hosted_actor_config=hosted_actor_config
 		self.__inspector=None
+		self.__must_terminate_system=terminate
 
 	def tell(self, message, sender=None):
 
 		else:
 
 			def force_termination(moratorium, hosted_actor_ref, test_actor_ref):
-				print '..................Moratorium started'
 				time.sleep(moratorium)
-				print '..................Moratorium expired'
 				hosted_actor_ref.tell(messages.PoisonPill(), test_actor_ref)
 
 			moratorium_daemon = multiprocessing.Process(target=force_termination, args=(self.__hosted_actor_config.termination_moratorium, \
 																					self.__test_actor_ref,))
 			moratorium_daemon.start()			
 
-		self.__system.wait_for(hosted_actor_ref)
+		try:
+			self.__system.wait_for(hosted_actor_ref)
+		except exceptions.ActorAlreadyKilled, e:
+			pass
+			#Hosted actor has already been killed
+
 		self.__inspector = interactions.InteractionPatterns.ask(self.__system, \
 																self.__test_actor_ref, \
 																NeedMessagesSnapshot()).inspector()
 		if moratorium_daemon is not None:
 			moratorium_daemon.terminate()
 
+		if self.__must_terminate_system:
+			self.__system.shutdown()
+
 	def inspector(self):
 		return self.__inspector
 

longtang/actors/domain.py

     def child(self, child_unique_id):
         return self.__system_ref.get_child(child_unique_id, self.__actor_ref.unique_id())
 
-    def get_by_id(self,unique_id):
+    def find_by_id(self,unique_id):
         return self.__system_ref.find_by_id(unique_id)
 
     def _system_ref(self):

longtang/actors/inbound/filepoller.py

 
 						self.__inflate_requests[full_path]=None
 
-						self.context().get_by_id('filepump-actor').tell(fp_messages.InflateFile(full_path), self.myself())
+						self.context().find_by_id('filepump-actor').tell(fp_messages.InflateFile(full_path), self.myself())
 
 				self.__notify_polling_done_if_possible()
 

longtang/actors/logger/test/test_logger.py

 	def test_console_debug_message(self):
 		logger_tester = actorstestutils.TestActorBuilder().with_factory(factory.LoggerActorFactory('DEBUG')).with_id('logger-tester').build()
 
-		logger_tester.tell(messages.FileDebugEventMessage('logger-tester','dummy.mp3','This is a simple error message'))
+		logger_tester.tell(messages.FileDebugEventMessage('logger-tester','dummy.mp3','This is a simple debug message'))
 
 		assert_that(logger_tester.system().marooned_messages().snapshot().reported_by('logger-tester'), is_(not_none()),'logger-tester actor marooned messages list is not none')
 		assert_that(logger_tester.system().marooned_messages().snapshot().reported_by('logger-tester').size(), is_(equal_to(0)),'logger-tester actor marooned messages list has elements')

longtang/actors/supervisors/filepackaging/filepackaging.py

 			
 			self.logger().info('File to be packaged received', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.PackagingStarted())
-			self.context().get_by_id('id3-folder-manager-actor').tell(filesystem_messages.CreateFolderFromMetadata(message.source_file(),\
+			self.context().find_by_id('id3-folder-manager-actor').tell(filesystem_messages.CreateFolderFromMetadata(message.source_file(),\
 																													message.metadata(), \
-																													message.target_dir(), message.tracking()), self)
+																													message.target_dir(), message.tracking()), self.myself())
 
 		elif isinstance(message, filesystem_messages.FolderFromMetadataSuccessfullyCreated):
 
 			self.logger().info('Target folder has been succesfully created', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.TargetFolderCreated())
-			self.context().get_by_id('id3-file-manager-actor').tell(filesystem_messages.CopyFileTo(message.source_file(),\
+			self.context().find_by_id('id3-file-manager-actor').tell(filesystem_messages.CopyFileTo(message.source_file(),\
 																									message.metadata(),\
-																									message.new_dir_path(), message.tracking()), self)
+																									message.new_dir_path(), message.tracking()), self.myself())
 		elif isinstance(message, filesystem_messages.FileSuccessfullyCopied):
 
 			self.logger().info('Media file succesfully copied', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MediaFileCopied())
-			self.context().get_by_id('id3-file-tagger-actor').tell(id3tag_messages.WriteFileMetadata(message.copied_file(),\
-																										message.metadata(), message.tracking()), self)
+			self.context().find_by_id('id3-file-tagger-actor').tell(id3tag_messages.WriteFileMetadata(message.copied_file(),\
+																										message.metadata(), message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataUpdated):
 			
 			self.logger().info('Media file succesfully updated with metadata', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataUpdated())
-			self.context().get_by_id('id3-file-manager-actor').tell(filesystem_messages.RenameFileFromMetadata(message.source(),\
-																												 message.metadata(), message.tracking()), self)
+			self.context().find_by_id('id3-file-manager-actor').tell(filesystem_messages.RenameFileFromMetadata(message.source(),\
+																												 message.metadata(), message.tracking()), self.myself())
 		elif isinstance(message, filesystem_messages.FileSuccessfullyRenamed):
 
 			self.logger().info('Media file succesfully renamed according to metadata', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FilePackagingFinished(message.new_file()))
-			self.parent().tell(messages.FilePackagingFinished(message.source_file(), message.tracking()), self)
+			self.parent().tell(messages.FilePackagingFinished(message.source_file(), message.tracking()), self.myself())
 
 		elif isinstance(message, filesystem_messages.CopyFileToFailed):
 
 			self.logger().error('Media file could not be copied. Reason: {0}'.format(message.reason()), message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FileCopyFailed())
-			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self)
+			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self.myself())
 
 		elif isinstance(message, filesystem_messages.RenameFileFromMetadataFailed):
 
 			self.logger().error('Media file could not be renamed. Reason: {0}'.format(message.reason()), message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FileRenamingFailed())
-			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self)
+			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self.myself())
 
 		elif isinstance(message, filesystem_messages.CreateFolderFromMetadataFailed):
 
 			self.logger().error('Target folder could not be created. Reason: {0}'.format(message.reason()), message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FolderCreationFailed())
-			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self)
+			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self.myself())
 
 		elif isinstance(message, id3tag_messages.WriteFileMetadataFailed):
 			
 			self.logger().error('Id3 tags could not be saved. Reason: {0}'.format(message.reason()), message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataWritingFailed())
-			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self)
+			self.parent().tell(messages.FilePackagingFailure(message.source_file(), message.metadata(), message.reason(), message.tracking()), self.myself())
 
 		else: 
 			self.notify_marooned_message(message)

longtang/actors/supervisors/filepackaging/test/test_filepackaging.py

 
 	def test_creation(self):
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		filepackaging_actor = actor_system.from_type(filepackaging.FilePackagingSupervisor,'file-packaging-supervisor')
 
 		try:
 															.with_id('test-filepackaging')\
 															.termination_moratorium(10)\
 															.terminate_system(False)\
+															.verbosity('DEBUG')\
 															.termination_type(messages.FilePackagingFinished).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(filepackaging_actor.system())
 															.with_id('test-filepackaging-failure')\
 															.termination_moratorium(10)\
 															.terminate_system(False)\
+															.verbosity('DEBUG')\
 															.termination_type(messages.FilePackagingFailure).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(filepackaging_actor.system())
 															.with_id('test-filepackaging-failure')\
 															.termination_moratorium(10)\
 															.terminate_system(False)\
+															.verbosity('DEBUG')\
 															.termination_type(messages.FilePackagingFailure).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(filepackaging_actor.system())
 															.with_id('test-filepackaging-failure')\
 															.termination_moratorium(10)\
 															.terminate_system(False)\
+															.verbosity('DEBUG')\
 															.termination_type(messages.FilePackagingFailure).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(filepackaging_actor.system())

longtang/actors/supervisors/flowconductor/flowconductor.py

 	
 	def receive(self, message):
 		if isinstance(message, messages.MediaFileAvailable):
-			self.context().get_by_id('id3taghandler-actor').tell(id3tag_messages.InspectFileMetadata(message.filepath(), message.tracking()), self)
+			self.context().find_by_id('id3taghandler-actor').tell(id3tag_messages.InspectFileMetadata(message.filepath(), message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataAvailable):
-			self.context().get_by_id('filepackaging-actor').tell(packaging_messages.PerformFilePackaging(message.source_file(), message.metadata(), self.__config.generate_at, message.tracking()), self)
+			self.context().find_by_id('filepackaging-actor').tell(packaging_messages.PerformFilePackaging(message.source_file(), message.metadata(), self.__config.generate_at, message.tracking()), self.myself())
 		elif isinstance(message, packaging_messages.FilePackagingFinished):
 			self.parent().tell(messages.MediaFileHasBeenProcessed(message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataCouldNotBeEvaluated):

longtang/actors/supervisors/flowconductor/test/test_flowconductor.py

 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(base_from_test_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_actor = actor_system.with_factory(factory.FlowConductorSupervisorFactory(config),'flowconductor-test-actor')
 		
 		try:		
 		flowconductor_actor = actorstestutils.TestActorBuilder().with_factory(factory.FlowConductorSupervisorFactory(config))\
 															.with_id('flowconductor-test-actor')\
 															.termination_moratorium(10)\
-															.terminate_system(True)\
+															.terminate_system(False)\
 															.termination_type(messages.MediaFileProcessingFailed).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(flowconductor_actor.system())
 		flowconductor_actor = actorstestutils.TestActorBuilder().with_factory(factory.FlowConductorSupervisorFactory(config))\
 															.with_id('flowconductor-test-actor')\
 															.termination_moratorium(10)\
-															.terminate_system(True)\
+															.terminate_system(False)\
 															.termination_type(messages.MediaFileProcessingFailed).build()
 
 		tracking_facade = facade.MediaTrackingFacade.create_within(flowconductor_actor.system())

longtang/actors/supervisors/id3taghandler/id3taghandler.py

 		if isinstance(message, messages.InspectFileMetadata):
 			self.logger().info(u'Starting metadata inspection on file .....', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataInspectionStarted())
-			self.context().get_by_id('id3tag-reader-actor').tell(id3tag_messages.CheckFileMetadata(message.source_file(), message.tracking()), self.myself())
+			self.context().find_by_id('id3tag-reader-actor').tell(id3tag_messages.CheckFileMetadata(message.source_file(), message.tracking()), self.myself())
 
 		elif isinstance(message, id3tag_messages.FileMetadataIsComplete):
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataAvailable())
 
 			if self.__config.override_tags:
-				self.context().get_by_id('musicbrainz-actor').tell(mb_messages.OverrideFileMetadata(message.source(), message.metadata(), message.tracking()), self.myself())				
+				self.context().find_by_id('musicbrainz-actor').tell(mb_messages.OverrideFileMetadata(message.source(), message.metadata(), message.tracking()), self.myself())				
 			else:
 				self.parent().tell(messages.FileMetadataAvailable(message.source(), message.metadata(), message.tracking()), self.myself())
 
 			if not self.__config.offline_mode:
 				self.logger().info('There\'re some metadata fields missing. Trying with musicbrainz .....', message.tracking())
 				facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FileMetadataIncomplete())
-				self.context().get_by_id('musicbrainz-actor').tell(mb_messages.FillUpMissingMetadataFields(message.source(), message.metadata(), message.tracking()), self.myself())
+				self.context().find_by_id('musicbrainz-actor').tell(mb_messages.FillUpMissingMetadataFields(message.source(), message.metadata(), message.tracking()), self.myself())
 			else:
 				self.logger().error('File metadata could not be fulfilled and offline mode is active.', message.tracking())
 				facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataNotAvailable())

longtang/actors/supervisors/id3taghandler/test/test_id3taghandler.py

 
 	def test_creation(self):
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 
 		config = configuration.Id3TagHandlerConfigurationBuilder().override_tags(False)\
 																  .offline_mode(False)\

longtang/actors/supervisors/main/main.py

 		if isinstance(message, messages.KickOffMediaProcessing):
 			self.__caller.append(self.sender())
 			self.logger().info('Media processing has just started. [From: {0}, To: {1}]'.format(self.__config.read_from, self.__config.generate_at))
-			self.context().get_by_id('file-poller-actor').tell(fp_messages.StartPolling(self.__config.read_from), self)
+			self.context().find_by_id('file-poller-actor').tell(fp_messages.StartPolling(self.__config.read_from), self.myself())
 
 		elif isinstance(message, fp_messages.CompressedAudioFileFound):
 			tracking_id, parent_tracking_id = facade.MediaTrackingFacade.from_context(self.context()).create_compressed_audio_tracking(message.filepath(), message.compressed_parent_filepath())
 																												  message.compressed_parent_filepath(),\
 																												  tracking_id))
 
-			self.context().get_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self)
+			self.context().find_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
 
 		elif isinstance(message, fp_messages.AudioFileFound):
 			tracking_id = facade.MediaTrackingFacade.from_context(self.context()).create_audio_tracking(message.filepath())
 
 			self.logger().debug(u'Audio file tracked. [path: {0}, tracking_id: {1}]'.format(message.filepath(), tracking_id))
 
-			self.context().get_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self)
+			self.context().find_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
 
 		elif isinstance(message, fp_messages.CompressedFileCouldNotBeOpened):
 
 		if len(self.__filecount) == 0:
 			self.logger().info('Terminating execution.....')
 			summary = facade.MediaTrackingFacade.from_context(self.context()).retrieve_summary()
-			self.__caller[0].tell(messages.MediaProcessingFinished(summary), self)
+			self.__caller[0].tell(messages.MediaProcessingFinished(summary), self.myself())

longtang/actors/supervisors/main/test/test_main.py

 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(base_from_test_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_actor = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 		
 		try:		
 			assert_that(actor_system.find_by_id('file-poller-actor').parent(), is_(equal_to(actor_system.find_by_id('main-actor'))),'Parent actor is not correctly assigned')
 			assert_that(actor_system.find_by_id('flowconductor-actor').parent(), is_(equal_to(actor_system.find_by_id('main-actor'))),'Parent actor is not correctly assigned')
 
-			assert_that(actor_system.find_by_id('file-poller-actor')._instance(), is_(instance_of(filepoller.FilePoller)), 'File poller actor is not of the right type')
-			assert_that(actor_system.find_by_id('flowconductor-actor')._instance(), is_(instance_of(flowconductor.FlowConductorSupervisor)), 'Flow conductor actor is not of the right type')
+			#assert_that(actor_system.find_by_id('file-poller-actor')._instance(), is_(instance_of(filepoller.FilePoller)), 'File poller actor is not of the right type')
+			#assert_that(actor_system.find_by_id('flowconductor-actor')._instance(), is_(instance_of(flowconductor.FlowConductorSupervisor)), 'Flow conductor actor is not of the right type')
 
 		except exceptions.ActorNotFound as e:
 			self.fail(str(e))
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(base_from_test_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing())		
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(data_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing())	
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(data_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing()) 
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(data_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		summary = interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing()).summary()
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(data_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		summary = interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing()).summary()
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(data_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		summary = interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing()).summary() 
 		config_builder = configuration.LongTangConfigurationBuilder()
 		config = config_builder.read_from(base_from_test_dir).generate_at(base_to_test_dir).build()
 
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		main_ref = actor_system.with_factory(factory.MainSupervisorFactory(config),'main-actor')
 
 		summary = interactions.InteractionPatterns.ask(actor_system, main_ref, messages.KickOffMediaProcessing()).summary() 

longtang/actors/tracking/facade.py

 
 	@staticmethod
 	def from_system(system_ref):
-		actor_ref = system_ref.get_by_id('mediatracking-actor')
+		actor_ref = system_ref.find_by_id('mediatracking-actor')
 		return MediaTrackingFacade(system_ref, actor_ref)
 
 	@staticmethod

longtang/actors/tracking/summary.py

 
 	def find(self, tracking_id):
 		#I think I need to review go to perform this instead of linear cost
-		result = [entry for entry in self.__entries if entry[0] is tracking_id]
+		result = [entry for entry in self.__entries if entry[0] == tracking_id]
 
 		if len(result) > 0:
 			return result[0]

longtang/actors/tracking/test/test_facade.py

 class TestTrackingActorFacade(unittest.TestCase):
 
 	def test_create_audio_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))
 		actor_system.shutdown()	
 
 	def test_create_compressed_audio_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))
 		actor_system.shutdown()	
 
 	def test_create_compressed_file_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))
 		actor_system.shutdown()			
 
 	def test_lookup(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))
 		assert_that(tracking_info.mediafile.sourcepath, is_('/dummy.mp3'),'Tracking sourcepath information is not right')
 
 	def test_notify(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))		
 		assert_that(tracking_info.tracking_events.of_type('NONALTERING').get(0), is_(not_none()),'Tracked events does not exist')
 
 	def test_notify_compressed(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'mediatracking-actor')
 
 		tracking_facade = facade.MediaTrackingFacade.from_system(sys_domain.SystemRef(actor_system))

longtang/actors/tracking/test/test_tracking.py

 class TestMediaTrackingActor(unittest.TestCase):
 
 	def test_creation(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		try:
 		actor_system.shutdown()
 
 	def test_add_single_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		response = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy.mp3'))
 		actor_system.shutdown()
 
 	def test_retrieve_single_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy-2.mp3')).tracking_id()
 		actor_system.shutdown()
 
 	def test_retrieve_single_tracking_notfound(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy-2.mp3')).tracking_id()
 		actor_system.shutdown()
 
 	def test_notify_non_altering_tracking_event(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy-non-tracking.mp3')).tracking_id()
 		actor_system.shutdown()
 
 	def test_notify_altering_tracking_event(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy-non-tracking.mp3')).tracking_id()
 		actor_system.shutdown()
 	
 	def test_add_compressed_file_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		response = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedFileTrackingEntry('/dummy.zip'))
 		actor_system.shutdown()
 
 	def test_add_compressed_audio_file_tracking(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		response = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedAudioFileTrackingEntry('mymusic.mp3', '/dummy.zip'))
 		actor_system.shutdown()
 
 	def test_notity_compressed_file_tracking_event(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedFileTrackingEntry('/dummy.zip')).tracking_id()
 		actor_system.shutdown()
 
 	def test_check_audiofiles_list_from_compressed_file(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')
 
 		audio1_response = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedAudioFileTrackingEntry('mymusic1.mp3', '/dummy.zip'))
 		assert_that(response.tracking_info().mediafile.audiofiles.all(), has_items(audio1_response.tracking_id(), audio2_response.tracking_id()), 'Compressed audio files are not accurately related to the compressed file')
 
 	def test_notify_compressed_audio_file_non_altering_tracking_event(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedAudioFileTrackingEntry('mymusic.mp3', '/dummy.zip')).tracking_id()
 		actor_system.shutdown()
 
 	def test_notify_compressed_audio_file_altering_tracking_event(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateCompressedAudioFileTrackingEntry('mymusic.mp3', '/dummy.zip')).tracking_id()
 		assert_that(response.tracking_info().mediafile.destinationpath, is_(equal_to('/target/path/dummy.mp3')),'Mediafile information has not been updated')
 
 	def test_retrieve_summary_without_compressed_files(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		audio1_tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy1.mp3')).tracking_id()
 		assert_that(summary.audio().successes().find(audio3_tracking_id), is_(not_none()), 'Audio3 tracking id could not be found')
 
 	def test_retrieve_summary_without_compressed_files_and_single_failure(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		audio1_tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy1.mp3')).tracking_id()
 		assert_that(summary.audio().failures().find(audio3_tracking_id), is_(none()), 'Audio3 tracking id was found within failures!!')		
 
 	def test_retrieve_summary_with_compressed_files(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		audio1_tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy1.mp3')).tracking_id()
 			assert_that(mediatracking.mediafile.inflated, is_(equal_to(True)), 'All compressed files are not marked as inflated')
 
 	def test_retrieve_summary_with_compressed_files_and_single_compressed_file_failure(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(tracking.TrackingActor,'tracking-actor')		
 
 		audio1_tracking_id = interactions.InteractionPatterns.ask(actor_system,tracking_actor, messages.CreateTrackingEntry('/dummy1.mp3')).tracking_id()

longtang/common/interactions.py

+import uuid
+
 from longtang.actors import actors, messages
 from multiprocessing.managers import BaseManager
 from evasion.common import net
-from longtang.system import domain as sys_domain
+from longtang.system import domain as sys_domain, exceptions as systemexcep
 
 
 class InteractionPatterns:
 
 		#TODO The name could be dynamic i think
 		#TODO WE should remove this actor from the registry
-		host_actor = system_ref.with_factory(HostActorFactory(port),'interactions-actor', None)
+		host_actor = system_ref.with_factory(HostActorFactory(port),'int-act-' + str(uuid.uuid4()), None)
 		actor_ref.tell(message,host_actor)
 
-		host_actor.wait()
+		try:
+			host_actor.wait()
+		except systemexcep.ActorAlreadyKilled, e:
+			pass
+			#Our hot actor is already dead, there's no need to wait for it
 
 		response = ResponseManager.connect_to(port).get_ref().get()
 
 		manager.shutdown()
 
+		#system_ref.killme(host_actor.unique_id())
+
 		return response
 
 class HostActor(actors.Actor):

longtang/common/test/test_interactions.py

 #https://github.com/hamcrest/PyHamcrest
 #http://packages.python.org/PyHamcrest/
 
-import gevent
+import time
 import unittest
 from longtang.common import interactions
 
 class TestInteractions(unittest.TestCase):
 
 	def test_ask_method(self):
-		actor_system = system.ActorSystem()
+		actor_system = system.ActorSystemFactory.create()
 		tracking_actor = actor_system.from_type(InteractionTestActor,'interactions-test-actor')
 
 		response = interactions.InteractionPatterns.ask(actor_system,tracking_actor, SimpleRequest())
 class InteractionTestActor(actors.Actor):
 
     def receive(self, message):
-        gevent.sleep(1)
+        time.sleep(1)
         self.sender().tell(SimpleResponse('This is my test response'), self.myself())
 
 class SimpleRequest(messages.ActorMessage):

longtang/system/domain.py

 	def get_parent(self, unique_id):
 		return self.__system_instance.get_parent(unique_id)
 
-	def get_by_id(self,unique_id):
+	def find_by_id(self,unique_id):
 		return self.__system_instance.find_by_id(unique_id)
 
 	def from_type(self, actor_type, unique_id, parent):

longtang/system/exceptions.py

 		self.__msg = msg
 
 	def __str__(self):
-		return repr("Actor '{0}' could not be found within the system. {1}".format(self.__actor_id, self.__msg if self.__msg is not None else ''))
+		return repr("Actor '{0}' could not be found within the system. {1}".format(self.__actor_id, self.__msg if self.__msg is not None else ''))
+
+class ActorAlreadyKilled(Exception):
+	#Had to include default value for actor_id if we want system manager to return an exception
+	#http://bugs.python.org/issue15440
+	def __init__(self, actor_id=None, msg=None):
+		self.__actor_id = actor_id
+		self.__msg = msg
+
+	def __str__(self):
+		return repr("Actor '{0}' is already dead. {1}".format(self.__actor_id, self.__msg if self.__msg is not None else ''))		

longtang/system/system.py

 			return self.__dead_letters_actor_ref
 
 	def shutdown(self):
-		for actor in self.__actors_ref.itervalues():
-			self.killme(actor.unique_id())
+		#Using instances we get sure that the existing actors are still alive
+		for actor_id in self.__actors_instances.keys():
+			self.killme(actor_id)
 
 	def wait_for(self, actor_ref):
-		self.__get_actor_instance(actor_ref).join(None)
+		try:
+			self.__get_actor_instance(actor_ref).join(None)
+		except exceptions.ActorNotFound, e:
+			#Actor instance has been kiled and resources released, so only metadata is available
+			raise exceptions.ActorAlreadyKilled(actor_ref.unique_id())
+
 
 	def killme(self, actor_id):
 
-		actor = self.__get_actor_instance(self.find_by_id(actor_id))
+		try:
+			actor = self.__get_actor_instance(self.find_by_id(actor_id))
+
+			if actor.is_alive():
+				actor.terminate()
 
-		if actor.is_alive():
-			actor.terminate()
+			#We release resources but leave metadata to be browsed
+			del self.__actors_instances[actor_id]
+		
+		except exceptions.ActorNotFound,e:
+			raise exceptions.ActorAlreadyKilled(actor_id)
 
 	def create_actor_instance(self, actor_factory, unique_id, parent):
 
 		except KeyError as e:
 			raise exceptions.ActorNotFound(actor_ref.unique_id())			
 
+	def __unregister_actor_ref(self, actor_ref):
+		del self.__actors_instances[actor_ref.unique_id()]
+		del self.__actors_ref[actor_ref.unique_id()]
+
 	def get_parent(self, unique_id):
 		return self.find_by_id(unique_id).parent()