/// <summary> /// Initializes a new instance of the <see cref="EvaluationActorTest"/> class. /// </summary> public EvaluationActorTest() : base(ConfigurationFactory.Load().WithFallback(TestKit.DefaultConfig)) { TestUtils.InitializeLogger(); // Initialize a genome adhering to the parameter tree. var genomeData = new Genome(); genomeData.SetGene("value", new Allele <int>(1)); this._genome = new ImmutableGenome(genomeData); // Initialize the actors. var targetAlgorithmFactory = new TargetAlgorithmFactory <NoOperation, TestInstance, TestResult>( targetAlgorithmCreator: () => new NoOperation(TimeSpan.FromSeconds(1))); var resultStorage = this.Sys.ActorOf <ResultStorageActor <TestInstance, TestResult> >(); this._generationEvaluationActorRef = this.Sys.ActorOf( Props.Create( () => new GenerationEvaluationActor <NoOperation, TestInstance, TestResult>( targetAlgorithmFactory, new KeepSuggestedOrder <TestInstance, TestResult>(), new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().Build(1), resultStorage, new ParameterTree(new ValueNode <int>("value", new IntegerDomain(0, 10, new Allele <int>(0)))), null))); this._evaluationActorRef = this.Sys.ActorOf( props: new EvaluationActorPropsBuilder().Build(this._generationEvaluationActorRef), name: "EvaluationActor"); }
public void EvaluationsAreCancelledOnActorStop() { // Create an evaluation actor with a long running target algorithm. // Remember target algorithm factory to later check the created evaluation runs. var targetAlgorithmFactory = new TargetAlgorithmFactory <NoOperation, TestInstance, TestResult>( targetAlgorithmCreator: () => new NoOperation(TimeSpan.FromSeconds(30))); // Build evaluation actor itself using the created target algorithm factory. var actorRef = this.Sys.ActorOf( new EvaluationActorPropsBuilder() .SetConfiguration( new AlgorithmTunerConfiguration.AlgorithmTunerConfigurationBuilder().Build(maximumNumberParallelEvaluations: 1)) .SetTargetAlgorithmFactory(targetAlgorithmFactory) .Build(this._generationEvaluationActorRef)); // Start evaluation. ((ICanTell)actorRef).Tell(new Poll(), this._generationEvaluationActorRef); ((ICanTell)actorRef).Tell( new GenomeInstancePairEvaluation <TestInstance>(new GenomeInstancePair <TestInstance>(this._genome, this._testInstance), 0, 0, false), this._generationEvaluationActorRef); // Wait a while to make sure the evaluation really started. this.ExpectNoMsg(TimeSpan.FromMilliseconds(1000)); // Stop the actor. this.Sys.Stop(actorRef); // Wait a while for PostStop to get called. System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); // Check evaluation was really cancelled. Assert.True( targetAlgorithmFactory.CreatedTargetAlgorithms.Single().IsCancellationRequested, "Evaluation should have been cancelled."); }
/// <summary> /// Creates an <see cref="EvaluationActor{NoOperation, TestInstance, TestResult}"/> that uses a target /// algorithm factory which always produces target algorithms with the specified runtime. /// </summary> /// <param name="config"><see cref="AlgorithmTunerConfiguration"/> to use.</param> /// <param name="runtime">The target algorithm's desired runtime.</param> /// <returns>An <see cref="IActorRef"/> to the evaluation actor.</returns> private IActorRef CreateEvaluationActorWithLongRunningTargetAlgorithm( AlgorithmTunerConfiguration config, TimeSpan runtime) { // Create target algorithm factory with correct target algorithm runtime. var targetAlgorithmFactory = new TargetAlgorithmFactory <NoOperation, TestInstance, TestResult>( targetAlgorithmCreator: () => new NoOperation(runtime)); // Create evaluation actor, using the correct configuration and target algorithm factory. return(this.Sys.ActorOf( new EvaluationActorPropsBuilder() .SetConfiguration(config) .SetTargetAlgorithmFactory(targetAlgorithmFactory) .Build(this._generationEvaluationActorRef))); }