-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #25184 adding the support for the system table config * #25184 adding the support for the system table config * #25184 avoid recursive issues on system table/config * #25184 adding fixes and unit test * #25184 adding fixes and unit test * #25184 adding feedback * #25184 adding more coverage test * #25184 trying some fixes for the init fail * #25184 reverting undesired changes * #25184 reverting undesired changes * #25184 reverting undesired changes * #25184 decoupling the task from config * #25184 trying to avoid issues when the db is no ready * #25184 trying to avoid issues when the db is no ready * #25184 adding a fix to avoid to run the system table on test * #25184 adding an event when update the system table * #25184 making lazy the system table on the config source * #25184 lazyness of the config dependency * Attempt to fix Integration Test run * Attempt to fix Integration Test run * Attempting to fix Unit Test run * Attempting to fix Unit Test run * Reverting unnecessary file changes. * Implementing SonarQube feedback * Merging changes from master. --------- Co-authored-by: Jose Castro <jose.castro@dotcms.com>
- Loading branch information
1 parent
0a4a8f8
commit 26f0c52
Showing
17 changed files
with
528 additions
and
72 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
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
91 changes: 91 additions & 0 deletions
91
dotCMS/src/integration-test/java/com/dotmarketing/util/ITConfigTest.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,91 @@ | ||
package com.dotmarketing.util; | ||
|
||
import com.dotcms.IntegrationTestBase; | ||
import com.dotmarketing.business.APILocator; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test for the ConfigTest. | ||
*/ | ||
public class ITConfigTest extends IntegrationTestBase { | ||
|
||
@BeforeClass | ||
public static void beforeInit() throws Exception { | ||
IntegrationTestBase.beforeInit(); | ||
Config.enableSystemTableConfigSource = true; | ||
} | ||
|
||
@AfterClass | ||
public static void afterInit() throws Exception { | ||
Config.enableSystemTableConfigSource = false; | ||
} | ||
|
||
/** | ||
* Method to test: {@link Config#getStringProperty(String, String)} | ||
* Given Scenario: Will request a property that does not exist on config nor system table | ||
* ExpectedResult: Should return default value | ||
*/ | ||
@Test | ||
public void test_404_on_system_table () { | ||
|
||
final String value = Config.getStringProperty("NON_EXISTING_KEY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return default value", "DEFAULT_VALUE", value); | ||
} | ||
|
||
/** | ||
* Method to test: {@link Config#getStringProperty(String, String)} | ||
* Given Scenario: Will request a property that exist on the system table | ||
* ExpectedResult: Should return value from the system table | ||
*/ | ||
@Test | ||
public void test_resolving_config_on_system_table () { | ||
|
||
APILocator.getSystemAPI().getSystemTable().set("NEW_PROPERTY", "NEW_VALUE"); | ||
final String value = Config.getStringProperty("NEW_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE", value); | ||
final Object valueFromCache = APILocator.getSystemAPI().getSystemCache().get("NEW_PROPERTY"); | ||
Assert.assertNotNull("Should be on the cache", valueFromCache); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE", valueFromCache); | ||
} | ||
|
||
/** | ||
* Method to test: {@link Config#getStringProperty(String, String)} | ||
* Given Scenario: Will request a property that exist on the system table and it is updated | ||
* ExpectedResult: Should return latest value twice | ||
*/ | ||
@Test | ||
public void test_resolving_config_on_system_table_and_update () { | ||
|
||
APILocator.getSystemAPI().getSystemTable().set("SECOND_PROPERTY", "NEW_VALUE_1"); | ||
String value = Config.getStringProperty("SECOND_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE_1", value); | ||
APILocator.getSystemAPI().getSystemTable().set("SECOND_PROPERTY", "NEW_VALUE_2"); | ||
value = Config.getStringProperty("SECOND_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE_2", value); | ||
final Object valueFromCache = APILocator.getSystemAPI().getSystemCache().get("SECOND_PROPERTY"); | ||
Assert.assertNotNull("Should be on the cache", valueFromCache); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE_2", valueFromCache); | ||
} | ||
|
||
/** | ||
* Method to test: {@link Config#getStringProperty(String, String)} | ||
* Given Scenario: Will request a property that exist on the system table, then updated, finally removed | ||
* ExpectedResult: Should return latest value twice and finally removed | ||
*/ | ||
@Test | ||
public void test_resolving_config_on_system_table_update_and_update () { | ||
|
||
APILocator.getSystemAPI().getSystemTable().set("THIRD_PROPERTY", "NEW_VALUE_1"); | ||
String value = Config.getStringProperty("THIRD_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE_1", value); | ||
APILocator.getSystemAPI().getSystemTable().set("THIRD_PROPERTY", "NEW_VALUE_2"); | ||
value = Config.getStringProperty("THIRD_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return the value from the system table", "NEW_VALUE_2", value); | ||
APILocator.getSystemAPI().getSystemTable().delete("THIRD_PROPERTY"); | ||
value = Config.getStringProperty("THIRD_PROPERTY", "DEFAULT_VALUE"); | ||
Assert.assertEquals("Should return default value since the property has been removed", "DEFAULT_VALUE", value); | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
dotCMS/src/main/java/com/dotcms/business/SystemTableInitializer.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,18 @@ | ||
package com.dotcms.business; | ||
|
||
import com.dotcms.config.DotInitializer; | ||
import com.dotmarketing.util.Config; | ||
|
||
/** | ||
* | ||
* @author Jose Castro | ||
* @since Oct 12th, 2023 | ||
*/ | ||
public class SystemTableInitializer implements DotInitializer { | ||
|
||
@Override | ||
public void init() { | ||
Config.initSystemTableConfigSource(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
dotCMS/src/main/java/com/dotcms/business/SystemTableUpdatedKeyEvent.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,19 @@ | ||
package com.dotcms.business; | ||
|
||
import java.io.Serializable; | ||
|
||
/** | ||
* This is a local event to notify that a system table has been updated. | ||
* @author jsanca | ||
*/ | ||
public class SystemTableUpdatedKeyEvent implements Serializable { | ||
|
||
private final String key; | ||
public SystemTableUpdatedKeyEvent(final String key) { | ||
this.key = key; | ||
} | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
} |
Oops, something went wrong.