Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ [Test] Added new set of test cases to test JobEngine basic operations #4160

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/kapua-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
with:
tag: '@jobs or @scheduler'
needs-docker-images: 'false'
test-jobsIntegrationBase:
test-jobService:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 45
Expand All @@ -171,7 +171,18 @@ jobs:
uses: actions/checkout@v4
- uses: ./.github/actions/runTestsTaggedAs
with:
tag: '@jobsIntegrationBase'
tag: '@job and @it'
needs-docker-images: 'true'
test-jobEngineOperations:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- name: Clones Kapua repo inside the runner
uses: actions/checkout@v4
- uses: ./.github/actions/runTestsTaggedAs
with:
tag: '@jobEngineOperations'
needs-docker-images: 'true'
test-jobsIntegration:
needs: build
Expand Down
2 changes: 1 addition & 1 deletion qa/RunKapuaTests_asGitAction.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#RUNS BOTH UNIT AND INTEGRATION TESTS AND FINALLY BUILDS THE PROJECT
#FIRT, JUNIT TESTS ARE LAUNCHED, IF THEY PASS CUCUMBER TESTS ARE THEN EXECUTED

cucumberTags=('@brokerAcl' '@tag' '@broker' '@device' '@deviceManagement' '@connection' '@datastore' '@user' '@userIntegrationBase' '@userIntegration' '@security' '@jobs' '@scheduler' '@jobsIntegrationBase' '@triggerService' '@account' '@translator' '@jobEngineStepDefinitions' '@jobEngineStartOfflineDevice' '@jobEngineRestartOnlineDevice' '@jobEngineStartOnlineDevice' '@jobEngineRestartOfflineDevice' '@jobEngineRestartOnlineDeviceSecondPart' '@jobsIntegration' '@jobEngineServiceStop' '@endpoint' '@deviceRegistry' '@role' '@group')
cucumberTags=('@brokerAcl' '@tag' '@broker' '@device' '@deviceManagement' '@connection' '@datastore' '@user' '@userIntegrationBase' '@userIntegration' '@security' '@jobs' '@scheduler' '@jobService' '@triggerService' '@account' '@translator' '@jobEngineStepDefinitions' '@jobEngineStartOfflineDevice' '@jobEngineRestartOnlineDevice' '@jobEngineStartOnlineDevice' '@jobEngineRestartOfflineDevice' '@jobEngineRestartOnlineDeviceSecondPart' '@jobsIntegration' '@jobEngineServiceStop' '@endpoint' '@deviceRegistry' '@role' '@group')
exitCodesTests=() #will contain exit code for each batch of tests

#checks if the last build command exited normally and exits if necessary
Expand Down
197 changes: 111 additions & 86 deletions qa/common/src/main/java/org/eclipse/kapua/qa/common/BasicSteps.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Red Hat Inc and others.
* Copyright (c) 2017, 2024 Red Hat Inc and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -76,7 +76,6 @@ public class BasicSteps extends TestBase {
public static final String LIFECYCLE_CONSUMER_CONTAINER_NAME = "lifecycle-consumer";
public static final String AUTH_SERVICE_CONTAINER_NAME = "auth-service";
public static final String API_CONTAINER_NAME = "rest-api";
public static final int JOB_ENGINE_CONTAINER_PORT = 8080;

public static final String LAST_CREDENTIAL_ID = "LastCredentialId";

Expand All @@ -93,30 +92,114 @@ public class BasicSteps extends TestBase {
private static final String ASSERT_ERROR_NAME = "AssertErrorName";
private static final String ASSERT_ERROR_CAUGHT = "AssertErrorCaught";

private DBHelper database;
private final DBHelper database;

@Inject
public BasicSteps(StepData stepData, DBHelper database) {
super(stepData);

this.database = database;
}

@Before(value = "@setup and (@env_docker or @env_docker_base)", order = 0)
public void initParametersDocker(Scenario scenario) {
logger.info("=====> Init parameters for docker environment...");
setProperties(scenario, "kapuadb", "true", "localhost", "3306", "DEFAULT", "org.h2.Driver",
"jdbc:h2:tcp", "certificates/jwt/test.key", "certificates/jwt/test.cert", "localhost", "http://job-engine:8080/v1", "trusted", "MODE=MySQL");
setProperties(scenario,
"kapuadb",
"true",
"localhost",
"3306",
"DEFAULT",
"org.h2.Driver",
"jdbc:h2:tcp",
"certificates/jwt/test.key",
"certificates/jwt/test.cert",
"localhost",
"http://job-engine:8080/v1",
"trusted",
"MODE=MySQL");
logger.info("=====> Init parameters for docker environment... DONE");
}

@Before(value = "@setup and @env_none", order = 0)
public void initParametersEmbedded(Scenario scenario) {
logger.info("=====> Init parameters for embedded environment...");
setProperties(scenario, "kapuadb", "true", "", "", "H2", "org.h2.Driver", "jdbc:h2:mem:",
"certificates/jwt/test.key", "certificates/jwt/test.cert", "localhost", "http://localhost:8080/v1", "trusted", null);
setProperties(scenario,
"kapuadb",
"true",
"",
"",
"H2",
"org.h2.Driver",
"jdbc:h2:mem:",
"certificates/jwt/test.key",
"certificates/jwt/test.cert",
"localhost",
"http://localhost:8080/v1",
"trusted",
null);
logger.info("=====> Init parameters for embedded environment... DONE");
}

@Before(value = "(@env_docker or @env_docker_base) and not (@setup or @teardown)", order = 0)
public void beforeScenarioDockerFull(Scenario scenario) {
beforeCommon(scenario);
}

@Before(value = "@env_none and not (@setup or @teardown)", order = 0)
public void beforeScenarioDockerBase(Scenario scenario) {
beforeCommon(scenario);

databaseInit();
}

@After(value = "@env_docker_base and @setup", order = 0)
public void afterScenarioDockerBaseSetup(Scenario scenario) {
databaseInit();
}

@After(value = "(@env_docker or @env_docker_base) and not (@setup or @teardown)", order = 0)
public void afterScenarioDockerFull(Scenario scenario) {
// afterScenarioDocker(scenario);
logger.info("Database cleanup...");
database.deleteAll();
logger.info("Database cleanup... DONE");
SecurityUtils.getSubject().logout();
KapuaSecurityUtils.clearSession();
}

@After(value = "@env_none and not (@setup or @teardown)", order = 0)
public void afterScenarioNone(Scenario scenario) {
logger.info("Database drop...");
try {
database.dropAll();
database.close();
} catch (Exception e) {
logger.error("Failed execute @After", e);
}
logger.info("Database drop... DONE");
KapuaSecurityUtils.clearSession();
}

protected void beforeCommon(Scenario scenario) {
this.scenario = scenario;
stepData.clear();
}

protected void databaseInit() {
database.init();
// Create KapuaSession using KapuaSecurityUtils and kapua-sys user as logged in user.
// All operations on database are performed using system user.
// Only for unit tests. Integration tests assume that a real login is performed.
KapuaSession kapuaSession = new KapuaSession(null, SYS_SCOPE_ID, SYS_USER_ID);
KapuaSecurityUtils.setSession(kapuaSession);
}


//
// Data Table Types
//

@DataTableType
public CucAccount cucAccount(Map<String, String> entry) {
return new CucAccount(
Expand Down Expand Up @@ -330,20 +413,36 @@ public CucUserProfile cucUserProfile(Map<String, String> entry) {
entry.get("email"));
}

//
// Parameter Types
//
@ParameterType(".*")
public org.eclipse.kapua.transport.message.jms.JmsTopic topic(String topic) {
return new JmsTopic(topic);
}

@ParameterType(value = "true|True|TRUE|false|False|FALSE")
public boolean booleanValue(String value) {
return Boolean.valueOf(value);
}
return Boolean.parseBoolean(value);
}

private void setProperties(Scenario scenario,
String schema,
String updateSchema,
String dbHost,
String dbPort,
String dbConnResolver,
String dbDriver,
String jdbcConnection,
String jwtKey,
String jwtCertificate,
String brokerHost,
String jobEngineUrl,
String jobEngineAuthMode,
String additionalOptions) {

private void setProperties(Scenario scenario, String schema, String updateSchema,
String dbHost, String dbPort, String dbConnResolver, String dbDriver, String jdbcConnection,
String jwtKey, String jwtCertificate, String brokerHost, String jobEngineUrl, String jobEngineAuthMode, String additionalOptions) {
SystemSetting.resetInstance();

System.setProperty(SystemSettingKey.DB_SCHEMA.key(), schema);
System.setProperty(SystemSettingKey.DB_SCHEMA_UPDATE.key(), updateSchema);
System.setProperty(SystemSettingKey.DB_CONNECTION_HOST.key(), dbHost);
Expand Down Expand Up @@ -392,80 +491,6 @@ private void setSpecificProperties(Scenario scenario) {
}
}

@Before
public void checkWaitMultipier() {
if (WAIT_MULTIPLIER != 1.0d) {
logger.info("Wait multiplier active: {}", WAIT_MULTIPLIER);
}
}

@Before(value = "(@env_docker or @env_docker_base) and not (@setup or @teardown)", order = 0)
public void beforeScenarioDockerFull(Scenario scenario) {
beforeCommon(scenario);
}

@Before(value = "@env_none and not (@setup or @teardown)", order = 0)
public void beforeScenarioDockerBase(Scenario scenario) {
beforeCommon(scenario);
databaseInit();
}

@After(value = "(@env_docker or @env_docker_base) and not (@setup or @teardown)", order = 0)
public void afterScenarioDockerFull(Scenario scenario) {
afterScenarioDocker(scenario);
}

@After(value = "@env_docker_base and @setup", order = 0)
public void afterScenarioDockerBaseSetup(Scenario scenario) {
databaseInit();
}

@After(value = "@env_none and not (@setup or @teardown)", order = 0)
public void afterScenarioNone(Scenario scenario) {
afterScenarioNoDocker(scenario);
}

protected void beforeCommon(Scenario scenario) {
this.scenario = scenario;
stepData.clear();
}

protected void databaseInit() {
database.init();
// Create KapuaSession using KapuaSecurtiyUtils and kapua-sys user as logged in user.
// All operations on database are performed using system user.
// Only for unit tests. Integration tests assume that a real login is performed.
KapuaSession kapuaSession = new KapuaSession(null, SYS_SCOPE_ID, SYS_USER_ID);
KapuaSecurityUtils.setSession(kapuaSession);
}

protected void afterScenarioDocker(Scenario scenario) {
logger.info("Database cleanup...");
database.deleteAll();
logger.info("Database cleanup... DONE");
SecurityUtils.getSubject().logout();
KapuaSecurityUtils.clearSession();
}

protected void afterScenarioNoDocker(Scenario scenario) {
logger.info("Database drop...");
try {
database.dropAll();
database.close();
} catch (Exception e) {
logger.error("Failed execute @After", e);
}
logger.info("Database drop... DONE");
KapuaSecurityUtils.clearSession();
}

@Given("A placeholder step")
public void doNothing() {
// An empty placeholder step. Just a breakpoint anchor point. Used to pause
// test execution by placing a breakpoint into.
Integer a = 10;
}

@Given("Scope with ID {int}")
public void setSpecificScopeId(Integer id) {
stepData.put(LAST_ACCOUNT_ID, getKapuaId(id));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2017, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -100,7 +100,7 @@ public void deleteAllAndClose() {
*/
public void deleteAll() {
KapuaConfigurableServiceSchemaUtilsWithResources.scriptSession(FULL_SCHEMA_PATH, DELETE_SCRIPT);
Optional.ofNullable(cacheManager).ifPresent(cm -> cm.invalidateAll());
Optional.ofNullable(cacheManager).ifPresent(KapuaCacheManager::invalidateAll);
}

public void dropAll() throws SQLException {
Expand All @@ -118,7 +118,7 @@ public void dropAll() throws SQLException {
} else {
logger.warn("================================> invoked drop all on closed connection!");
}
Optional.ofNullable(cacheManager).ifPresent(cm -> cm.invalidateAll());
Optional.ofNullable(cacheManager).ifPresent(KapuaCacheManager::invalidateAll);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2016, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -14,7 +14,17 @@

import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.configuration.metatype.TscalarImpl;
import org.eclipse.kapua.commons.rest.model.IsJobRunningResponse;
import org.eclipse.kapua.commons.rest.model.errors.ExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobAlreadyRunningExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobInvalidTargetExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobMissingStepExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobMissingTargetExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobNotRunningExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobResumingExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobRunningExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobStartingExceptionInfo;
import org.eclipse.kapua.commons.rest.model.errors.JobStoppingExceptionInfo;
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordCreator;
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordListResult;
import org.eclipse.kapua.commons.service.event.store.api.EventStoreRecordQuery;
Expand Down Expand Up @@ -133,13 +143,28 @@ public JAXBContext getJAXBContext() throws KapuaException {

// Jobs
Job.class,
JobStartOptionsClient.class,
JobStartOptions.class,
JobListResult.class,
JobXmlRegistry.class,

// Job Engine
JobStartOptionsClient.class,
JobStartOptions.class,
JobTargetSublist.class,
IsJobRunningResponse.class,
JobStepPropertiesOverrides.class,

// Job Engine Client
JobAlreadyRunningExceptionInfo.class,
JobInvalidTargetExceptionInfo.class,
JobMissingStepExceptionInfo.class,
JobMissingTargetExceptionInfo.class,
JobNotRunningExceptionInfo.class,
JobResumingExceptionInfo.class,
JobRunningExceptionInfo.class,
JobStartingExceptionInfo.class,
JobStoppingExceptionInfo.class,

// Device Management Command
DeviceCommandInput.class,
DeviceCommandOutput.class,

Expand Down
Loading
Loading