Repository: airavata Updated Branches: refs/heads/master a6245bd58 -> 740bf8cd8
adding new integration tests to retrieve project and experiment related data Project: http://git-wip-us.apache.org/repos/asf/airavata/repo Commit: http://git-wip-us.apache.org/repos/asf/airavata/commit/740bf8cd Tree: http://git-wip-us.apache.org/repos/asf/airavata/tree/740bf8cd Diff: http://git-wip-us.apache.org/repos/asf/airavata/diff/740bf8cd Branch: refs/heads/master Commit: 740bf8cd88c95ee4ba3327a98a825ffd41084218 Parents: a6245bd Author: Saminda Wijeratne <[email protected]> Authored: Thu Apr 24 01:47:06 2014 -0700 Committer: Saminda Wijeratne <[email protected]> Committed: Thu Apr 24 01:47:06 2014 -0700 ---------------------------------------------------------------------- modules/integration-tests/pom.xml | 1 + .../integration/AbstractIntegrationTest.java | 100 +++++++++ .../airavata/integration/DataRetrievalIT.java | 216 +++++++++++++++++++ .../SingleAppIntegrationTestBase.java | 79 +------ 4 files changed, 320 insertions(+), 76 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/airavata/blob/740bf8cd/modules/integration-tests/pom.xml ---------------------------------------------------------------------- diff --git a/modules/integration-tests/pom.xml b/modules/integration-tests/pom.xml index 9075a60..85a5134 100644 --- a/modules/integration-tests/pom.xml +++ b/modules/integration-tests/pom.xml @@ -138,6 +138,7 @@ <includes> <!--include>**/*IT.java</include --> <include>**/SimpleEchoIT.java</include> + <!--include>**/DataRetrievalIT.java</include--> </includes> </configuration> <executions> http://git-wip-us.apache.org/repos/asf/airavata/blob/740bf8cd/modules/integration-tests/src/test/java/org/apache/airavata/integration/AbstractIntegrationTest.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/AbstractIntegrationTest.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/AbstractIntegrationTest.java new file mode 100644 index 0000000..24ac14d --- /dev/null +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/AbstractIntegrationTest.java @@ -0,0 +1,100 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.integration; + +import java.io.IOException; + +import org.apache.airavata.api.Airavata; +import org.apache.airavata.api.client.AiravataClientFactory; +import org.apache.airavata.client.AiravataAPIFactory; +import org.apache.airavata.client.api.AiravataAPI; +import org.apache.airavata.client.api.exception.AiravataAPIInvocationException; +import org.apache.airavata.common.utils.ClientSettings; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class AbstractIntegrationTest { + + private static String THRIFT_SERVER_HOST; + private static int THRIFT_SERVER_PORT; + protected AiravataAPI airavataAPI; + protected Airavata.Client client; + private final int TRIES = 5; + private final int TIME_OUT = 10000; + final static Logger log = LoggerFactory.getLogger(AbstractIntegrationTest.class); + + public AbstractIntegrationTest() { + super(); + } + + protected void init() { + + try { + THRIFT_SERVER_HOST = ClientSettings.getSetting("thrift.server.host"); + THRIFT_SERVER_PORT = Integer.parseInt(ClientSettings.getSetting("thrift.server.port")); + + //check the server startup + initialize the thrift client + initClient(); + + //getting the Airavata API ( to add the descriptors + this.airavataAPI = getAiravataAPI(); + } catch (IOException e) { + log.error("Error loading client-properties ..." + e.getMessage()); + } catch (AiravataAPIInvocationException e) { + log.error("Error initializing the Airavata API ... " + e.getMessage()); + } catch (Exception e) { + log.error(e.getMessage()); + } + } + + protected AiravataAPI getAiravataAPI() throws AiravataAPIInvocationException { + if (airavataAPI == null) { + airavataAPI = AiravataAPIFactory.getAPI("default", "admin"); + } + return airavataAPI; + } + + protected void initClient() throws Exception { + int tries = 0; + while (client==null) { + log.info("Waiting till server initializes ........[try "+ (++tries) + " of "+TRIES+"]"); + try { + client = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); + } catch (Exception e) { + if (tries == TRIES) { + log("Server not responding. Cannot continue with integration tests ..."); + throw e; + } else { + Thread.sleep(TIME_OUT); + } + } + } + } + + protected Airavata.Client getClient() { + return client; + } + + public void log(String message) { + log.info(message); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/airavata/blob/740bf8cd/modules/integration-tests/src/test/java/org/apache/airavata/integration/DataRetrievalIT.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/DataRetrievalIT.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/DataRetrievalIT.java new file mode 100644 index 0000000..46ab7e9 --- /dev/null +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/DataRetrievalIT.java @@ -0,0 +1,216 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.airavata.integration; + +import java.util.ArrayList; +import java.util.List; +import java.util.Random; + +import org.apache.airavata.api.Airavata.Client; +import org.apache.airavata.api.error.AiravataClientConnectException; +import org.apache.airavata.api.error.AiravataClientException; +import org.apache.airavata.api.error.AiravataSystemException; +import org.apache.airavata.api.error.ExperimentNotFoundException; +import org.apache.airavata.api.error.InvalidRequestException; +import org.apache.airavata.client.api.AiravataAPI; +import org.apache.airavata.client.api.exception.AiravataAPIInvocationException; +import org.apache.airavata.client.tools.DocumentCreator; +import org.apache.airavata.common.exception.ApplicationSettingsException; +import org.apache.airavata.model.util.ExperimentModelUtil; +import org.apache.airavata.model.workspace.Project; +import org.apache.airavata.model.workspace.experiment.ComputationalResourceScheduling; +import org.apache.airavata.model.workspace.experiment.DataObjectType; +import org.apache.airavata.model.workspace.experiment.Experiment; +import org.apache.airavata.model.workspace.experiment.UserConfigurationData; +import org.apache.airavata.schemas.gfac.DataType; +import org.apache.thrift.TException; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.hamcrest.Matcher; +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; + +public class DataRetrievalIT extends AbstractIntegrationTest { + private final static Logger log = LoggerFactory.getLogger(DataRetrievalIT.class); + + //this will keep a list of experiment that was executed. each element will contain {experiemntId, user, project} + private List<String[]> experimentDataList; + + private String[] users={"user1","user2","user3","user4"}; + private String[] projects={"project1","project2","project3"}; + + private static final int NUM_OF_EXPERIMENTS=10; + + public DataRetrievalIT() { + } + + @BeforeTest + public void setUp() throws Exception { + init(); + experimentDataList=new ArrayList<String[]>(); + addApplications(); + log.info("Setup Experiments"); + log.info("================="); + for(int i=1; i<=NUM_OF_EXPERIMENTS;i++){ + //we are using the last user or project to test data empty scenarios + String user=users[(new Random()).nextInt(users.length-1)]; + String project=projects[(new Random()).nextInt(projects.length-1)]; + String experimentId = runExperiment(user, project); + experimentDataList.add(new String[]{experimentId,user,project}); + log.info("Running experiment "+i+" of "+NUM_OF_EXPERIMENTS+" - "+experimentId); + } + } + + private List<String> getData(int searchIndex, String searchString, int returnIndexData){ + List<String> results=new ArrayList<String>(); + for (String[] record : experimentDataList) { + if (record[searchIndex].equals(searchString)){ + results.add(record[returnIndexData]); + } + } + return results; + } + + @Test + public void listingExperimentsByUser() throws Exception { + log.info("Testing user experiments..."); + for (String user : users) { + List<Experiment> listUserExperiments = listUserExperiments(user); + List<String> data = getData(1, user, 0); + log.info("\t"+user+" : "+data.size()+" experiments"); + Assert.assertEquals(listUserExperiments.size(), data.size()); + for (Experiment experiment : listUserExperiments) { + Assert.assertThat(experiment.getExperimentID(), isIn(data)); + } + } + } + + @Test + public void listingExperimentsByProject() throws Exception { + log.info("Testing project experiments..."); + for (String project : projects) { + List<Experiment> listProjectExperiments = listProjectExperiments(project); + List<String> data = getData(2, project, 0); + log.info("\t"+project+" : "+data.size()+" experiments"); + Assert.assertEquals(listProjectExperiments.size(), data.size()); + for (Experiment experiment : listProjectExperiments) { + Assert.assertThat(experiment.getExperimentID(), isIn(data)); + } + } + } + + @Test + public void listingUserProjects() throws Exception { + log.info("Testing user projects..."); + for (String user : users) { + List<Project> listUserProjects = listUserProjects(user); + List<String> data = getData(1, user, 2); + log.info("\t"+user+" : "+data.size()+" projects"); + Assert.assertEquals(listUserProjects.size(), data.size()); + for (Project project : listUserProjects) { + Assert.assertThat(project.getProjectID(), isIn(data)); + } + } + } + + private static Matcher<String> isIn(final List<String> expected){ + return new BaseMatcher<String>() { + protected List<String> theExpected = expected; + public boolean matches(Object o) { + return theExpected.contains((String)o); + } + @Override + public void describeTo(Description d) { + } + }; + } + + + public List<Experiment> listUserExperiments(String user) throws ApplicationSettingsException, + AiravataClientConnectException, InvalidRequestException, + AiravataClientException, AiravataSystemException, TException { + return getClient().getAllUserExperiments(user); + } + + public List<Experiment> listProjectExperiments(String projectName) throws ApplicationSettingsException, + AiravataClientConnectException, InvalidRequestException, + AiravataClientException, AiravataSystemException, TException { + return getClient().getAllExperimentsInProject(projectName); + } + + public List<Project> listUserProjects(String user) throws ApplicationSettingsException, + AiravataClientConnectException, InvalidRequestException, + AiravataClientException, AiravataSystemException, TException { + return getClient().getAllUserProjects(user); + } + + public String runExperiment(String user, String project) throws AiravataAPIInvocationException, + ApplicationSettingsException, AiravataClientConnectException, + InvalidRequestException, AiravataClientException, + AiravataSystemException, TException, ExperimentNotFoundException { + List<DataObjectType> exInputs = new ArrayList<DataObjectType>(); + DataObjectType input = new DataObjectType(); + input.setKey("echo_input"); + // input.setType(DataType.STRING.toString()); + input.setValue("echo_output=Hello World"); + exInputs.add(input); + + List<DataObjectType> exOut = new ArrayList<DataObjectType>(); + DataObjectType output = new DataObjectType(); + output.setKey("echo_output"); + output.setType(DataType.STRING.toString()); + output.setValue(""); + exOut.add(output); + + Experiment simpleExperiment = ExperimentModelUtil + .createSimpleExperiment(project, user, "echoExperiment", + "SimpleEcho0", "SimpleEcho0", exInputs); + simpleExperiment.setExperimentOutputs(exOut); + + ComputationalResourceScheduling scheduling = ExperimentModelUtil + .createComputationResourceScheduling("localhost", 1, 1, 1, + "normal", 0, 0, 1, "sds128"); + scheduling.setResourceHostId("localhost"); + UserConfigurationData userConfigurationData = new UserConfigurationData(); + userConfigurationData.setAiravataAutoSchedule(false); + userConfigurationData.setOverrideManualScheduledParams(false); + userConfigurationData.setComputationalResourceScheduling(scheduling); + simpleExperiment.setUserConfigurationData(userConfigurationData); + + Client client = getClient(); + final String expId = client.createExperiment(simpleExperiment); + + client.launchExperiment(expId, "testToken"); + return expId; + } + + private void addApplications() throws AiravataAPIInvocationException { + AiravataAPI airavataAPI = getAiravataAPI(); + DocumentCreator documentCreator = new DocumentCreator(airavataAPI); + documentCreator.createLocalHostDocs(); + } + + +} http://git-wip-us.apache.org/repos/asf/airavata/blob/740bf8cd/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java ---------------------------------------------------------------------- diff --git a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java index fd5578f..e136880 100644 --- a/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java +++ b/modules/integration-tests/src/test/java/org/apache/airavata/integration/SingleAppIntegrationTestBase.java @@ -20,19 +20,11 @@ */ package org.apache.airavata.integration; -import java.io.IOException; import java.util.Date; -import org.apache.airavata.api.Airavata; -import org.apache.airavata.api.client.AiravataClientFactory; -import org.apache.airavata.api.error.AiravataClientException; import org.apache.airavata.api.error.AiravataSystemException; import org.apache.airavata.api.error.ExperimentNotFoundException; import org.apache.airavata.api.error.InvalidRequestException; -import org.apache.airavata.client.AiravataAPIFactory; -import org.apache.airavata.client.api.AiravataAPI; -import org.apache.airavata.client.api.exception.AiravataAPIInvocationException; -import org.apache.airavata.common.utils.ClientSettings; import org.apache.airavata.model.workspace.experiment.Experiment; import org.apache.airavata.model.workspace.experiment.ExperimentState; import org.apache.airavata.model.workspace.experiment.ExperimentStatus; @@ -43,77 +35,16 @@ import org.slf4j.LoggerFactory; /** * this class contains the common utils across the single application integration tests */ -public class SingleAppIntegrationTestBase { +public class SingleAppIntegrationTestBase extends AbstractIntegrationTest { - private final static Logger log = LoggerFactory.getLogger(SingleAppIntegrationTestBase.class); - private static String THRIFT_SERVER_HOST; - private static int THRIFT_SERVER_PORT; - protected AiravataAPI airavataAPI; - protected Airavata.Client client; - private final int TRIES = 5; - private final int TIME_OUT = 10000; - - //initializes the server - protected void init() { - - try { - THRIFT_SERVER_HOST = ClientSettings.getSetting("thrift.server.host"); - THRIFT_SERVER_PORT = Integer.parseInt(ClientSettings.getSetting("thrift.server.port")); - - //check the server startup + initialize the thrift client - initClient(); - - //getting the Airavata API ( to add the descriptors - this.airavataAPI = getAiravataAPI(); - } catch (IOException e) { - log.error("Error loading client-properties ..." + e.getMessage()); - } catch (AiravataAPIInvocationException e) { - log.error("Error initializing the Airavata API ... " + e.getMessage()); - } catch (Exception e) { - log.error(e.getMessage()); - } - } - - protected AiravataAPI getAiravataAPI() throws AiravataAPIInvocationException { - if (airavataAPI == null) { - airavataAPI = AiravataAPIFactory.getAPI("default", "admin"); - } - return airavataAPI; - } - - /* - * Check if the thrift server has started. - * If so, initialize the client - * */ - protected void initClient() throws Exception { - int tries = 0; - while (client==null) { - log.info("Waiting till server initializes ........[try "+ (++tries) + " of "+TRIES+"]"); - try { - client = AiravataClientFactory.createAiravataClient(THRIFT_SERVER_HOST, THRIFT_SERVER_PORT); - } catch (Exception e) { - if (tries == TRIES) { - log("Server not responding. Cannot continue with integration tests ..."); - throw e; - } else { - Thread.sleep(TIME_OUT); - } - } - } - } - - protected String createExperiment(Experiment experiment) throws AiravataSystemException, InvalidRequestException, AiravataClientException, TException { + protected String createExperiment(Experiment experiment) throws AiravataSystemException, InvalidRequestException, TException { return getClient().createExperiment(experiment); } - protected void launchExperiment(String expId) throws ExperimentNotFoundException, AiravataSystemException, InvalidRequestException, AiravataClientException, TException { + protected void launchExperiment(String expId) throws ExperimentNotFoundException, AiravataSystemException, InvalidRequestException, TException { getClient().launchExperiment(expId, "testToken"); } - protected Airavata.Client getClient() { - return client; - } - //monitoring the job protected void monitorJob(final String expId) { Thread monitor = (new Thread() { @@ -147,8 +78,4 @@ public class SingleAppIntegrationTestBase { } } - public void log(String message) { - log.info(message); - } - }
