Skip to content

Commit

Permalink
Fixed the ExperimentTimeoutTest class.
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelRoeder committed Jan 5, 2024
1 parent 4199dd0 commit daa699c
Showing 1 changed file with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package org.hobbit.controller;

import java.util.HashMap;
import java.util.concurrent.Semaphore;

import org.apache.commons.compress.utils.IOUtils;
import org.apache.commons.configuration2.Configuration;
import org.apache.commons.configuration2.EnvironmentConfiguration;
import org.apache.commons.configuration2.MapConfiguration;
import org.apache.jena.rdf.model.Model;
import org.hobbit.controller.data.ExperimentConfiguration;
import org.hobbit.controller.mocks.DummyImageManager;
import org.hobbit.controller.mocks.DummyPlatformController;
import org.hobbit.controller.mocks.DummyStorageServiceClient;
import org.hobbit.controller.utils.RabbitMQConnector;
import org.hobbit.core.Constants;
import org.hobbit.core.data.status.ControllerStatus;
import org.hobbit.utils.config.HobbitConfiguration;
import org.hobbit.vocab.HOBBIT;
Expand Down Expand Up @@ -37,15 +43,31 @@ public class ExperimentTimeoutTest {
@Before
public void init() {
// set max execution time to 1s
System.setProperty("MAX_EXECUTION_TIME", "1000");
controller = new DummyPlatformController(benchmarkControllerTerminated);
controller.queue.add(new ExperimentConfiguration(EXPERIMENT_ID, DummyImageManager.BENCHMARK_NAME, "{}", DummyImageManager.SYSTEM_URI));
Configuration config = new MapConfiguration(new HashMap<>());
config.addProperty("MAX_EXECUTION_TIME", "1000");
config.addProperty("HOBBIT_RABBIT_IMAGE", "rabbitmq:management");
HobbitConfiguration configuration = new HobbitConfiguration();
manager = new ExperimentManager(controller, configuration, 1000, 1000);
configuration.addConfiguration(config);
configuration.addConfiguration(new EnvironmentConfiguration());

controller = new DummyPlatformController(benchmarkControllerTerminated);
controller.queue.add(new ExperimentConfiguration(EXPERIMENT_ID, DummyImageManager.BENCHMARK_NAME, "{}",
DummyImageManager.SYSTEM_URI));
manager = new ExperimentManager(controller, configuration, 1000, 1000) {
// We have to override the creation of the RabbitMQ connector to the
// experiment's RabbitMQ broker. Instead, we connect to the already running
// RabbitMQ.
protected void createRabbitMQ(ExperimentConfiguration config) throws Exception {
RabbitMQConnector rabbitMQConnector = new RabbitMQConnector(controller,
this.hobbitConfig.getString(Constants.RABBIT_MQ_HOST_NAME_KEY));
controller.setExpRabbitMQConnector(rabbitMQConnector);
rabbitMQConnector.init();
};
};
controller.expManager = manager;
}

@Test (timeout = 10000)
@Test(timeout = 20000)
public void test() throws Exception {
benchmarkControllerTerminated.acquire();
// Give the system some time to tidy up
Expand All @@ -58,8 +80,8 @@ public void test() throws Exception {
Assert.assertNull("Status of the running experiment", status.experiment);
Model resultModel = ((DummyStorageServiceClient) controller.storage).insertedModel;
Assert.assertTrue("Result model contains the error information about the failed experiment.",
resultModel.contains(HobbitExperiments.getExperiment(EXPERIMENT_ID),
HOBBIT.terminatedWithError, HobbitErrors.ExperimentTookTooMuchTime));
resultModel.contains(HobbitExperiments.getExperiment(EXPERIMENT_ID), HOBBIT.terminatedWithError,
HobbitErrors.ExperimentTookTooMuchTime));
}

@After
Expand Down

0 comments on commit daa699c

Please sign in to comment.