Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 24681 allow to run new data upgrade tasks (#24710)
* #24681 Adding support to run data upgrade tasks * #24681 Adding integration tests * #24681 Applying code style
- Loading branch information
1 parent
b5c4721
commit 2b7a146
Showing
6 changed files
with
302 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
dotCMS/src/integration-test/java/com/dotmarketing/startup/StartupTasksExecutorDataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.dotmarketing.startup; | ||
|
||
import com.dotcms.IntegrationTestBase; | ||
import com.dotcms.business.CloseDBIfOpened; | ||
import com.dotcms.util.IntegrationTestInitService; | ||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.util.Logger; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class StartupTasksExecutorDataTest extends IntegrationTestBase { | ||
|
||
@BeforeClass | ||
public static void prepare() throws Exception { | ||
//Setting web app environment | ||
IntegrationTestInitService.getInstance().init(); | ||
} | ||
|
||
/** | ||
* Drops the db_version table | ||
*/ | ||
private void dropDBVersionTable() { | ||
|
||
try { | ||
final DotConnect dotConnect = new DotConnect(); | ||
dotConnect.setSQL("DROP TABLE IF EXISTS db_version"); | ||
dotConnect.loadResult(); | ||
} catch (DotDataException e) { | ||
Logger.error(this, "Error dropping db_version table", e); | ||
fail(String.format("Error dropping db_version table: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
/** | ||
* Drops the data_version table | ||
*/ | ||
private void dropDataVersionTable() { | ||
|
||
try { | ||
final DotConnect dotConnect = new DotConnect(); | ||
dotConnect.setSQL("DROP TABLE IF EXISTS data_version"); | ||
dotConnect.loadResult(); | ||
} catch (DotDataException e) { | ||
Logger.error(this, "Error dropping data_version table", e); | ||
fail(String.format("Error dropping data_version table: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
/** | ||
* <b>Method to test:</b> StartupTasksExecutor.getInstance().insureDataVersionTable() | ||
* <p> | ||
* <b>Given scenario:</b> Drop the data_version table, run the StartupTasksExecutor.getInstance().insureDataVersionTable() | ||
* <p> | ||
* <b>Expected result:</b> The data_version table should exist | ||
*/ | ||
@Test | ||
@CloseDBIfOpened | ||
public void testStartupTasksExecutorGetDataVersionTable() throws Exception { | ||
|
||
// Drop the data_version table | ||
dropDataVersionTable(); | ||
|
||
// Create the table | ||
var executor = StartupTasksExecutor.getInstance(); | ||
executor.insureDataVersionTable(); | ||
|
||
try { | ||
// Checking the latest version | ||
var dataVersion = executor.currentDataVersion(); | ||
assertEquals(0, dataVersion); | ||
} catch (Exception e) { | ||
Logger.error(this, "Error checking latest version in data_version table", e); | ||
fail(String.format("Error checking latest version in data_version table: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
/** | ||
* <b>Method to test:</b> StartupTasksExecutor.getInstance().executeDataUpgrades() | ||
* <p> | ||
* <b>Given scenario:</b> Drop the data_version table, run the StartupTasksExecutor.getInstance().insureDataVersionTable(), | ||
* to finally execute the data upgrades. | ||
* <p> | ||
* <b>Expected result:</b> The data_version table should exist and the data_version table current version should be greater | ||
* than 1 | ||
*/ | ||
@Test | ||
@CloseDBIfOpened | ||
public void testStartupTasksExecutorExecuteDataUpgrades() throws Exception { | ||
|
||
// Drop the version tables | ||
dropDataVersionTable(); | ||
dropDBVersionTable(); | ||
|
||
// Create the table | ||
var executor = StartupTasksExecutor.getInstance(); | ||
executor.insureDataVersionTable(); | ||
|
||
// Run the data upgrades | ||
executor.executeDataUpgrades(); | ||
|
||
try { | ||
// Checking the latest version | ||
var dataVersion = executor.currentDataVersion(); | ||
assertTrue(dataVersion > 1); | ||
} catch (Exception e) { | ||
Logger.error(this, "Error checking latest version in data_version table", e); | ||
fail(String.format("Error checking latest version in data_version table: %s", e.getMessage())); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.