Skip to content

Commit

Permalink
Check in parameter service test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Apr 30, 2008
1 parent 2bfd1b0 commit e30daf6
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 28 deletions.
20 changes: 10 additions & 10 deletions symmetric/src/main/java/org/jumpmind/symmetric/SymmetricEngine.java
Expand Up @@ -33,7 +33,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.PropertiesConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.config.IRuntimeConfig;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.job.PullJob;
Expand Down Expand Up @@ -204,31 +204,31 @@ private void registerEngine() {
*/
private void startJobs() {
if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PUSH_JOB))) {
properties.getProperty(ParameterConstants.START_PUSH_JOB))) {
applicationContext.getBean(Constants.PUSH_JOB_TIMER);
}
if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PULL_JOB))) {
properties.getProperty(ParameterConstants.START_PULL_JOB))) {
applicationContext.getBean(Constants.PULL_JOB_TIMER);
}

if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PURGE_JOB))) {
properties.getProperty(ParameterConstants.START_PURGE_JOB))) {
applicationContext.getBean(Constants.PURGE_JOB_TIMER);
}

if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_HEARTBEAT_JOB))) {
properties.getProperty(ParameterConstants.START_HEARTBEAT_JOB))) {
applicationContext.getBean(Constants.HEARTBEAT_JOB_TIMER);
}

if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_SYNCTRIGGERS_JOB))) {
properties.getProperty(ParameterConstants.START_SYNCTRIGGERS_JOB))) {
applicationContext.getBean(Constants.SYNC_TRIGGERS_JOB_TIMER);
}

if (Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_STATISTIC_FLUSH_JOB))) {
properties.getProperty(ParameterConstants.START_STATISTIC_FLUSH_JOB))) {
applicationContext.getBean(Constants.STATISTIC_FLUSH_JOB_TIMER);
}

Expand Down Expand Up @@ -291,7 +291,7 @@ public void reloadNode(String nodeId) {
*/
public void push() {
if (!Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PUSH_JOB))) {
properties.getProperty(ParameterConstants.START_PUSH_JOB))) {
((IPushService) applicationContext.getBean(Constants.PUSH_SERVICE)).pushData();
} else {
throw new UnsupportedOperationException("Cannot actuate a push if it is already scheduled.");
Expand All @@ -313,7 +313,7 @@ public void syncTriggers() {
*/
public void pull() {
if (!Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PULL_JOB))) {
properties.getProperty(ParameterConstants.START_PULL_JOB))) {
((IPullService) applicationContext.getBean(Constants.PULL_SERVICE)).pullData();
} else {
throw new UnsupportedOperationException("Cannot actuate a push if it is already scheduled.");
Expand All @@ -326,7 +326,7 @@ public void pull() {
*/
public void purge() {
if (!Boolean.TRUE.toString().equalsIgnoreCase(
properties.getProperty(PropertiesConstants.START_PURGE_JOB))) {
properties.getProperty(ParameterConstants.START_PURGE_JOB))) {
purgeService.purge();
} else {
throw new UnsupportedOperationException("Cannot actuate a purge if it is already scheduled.");
Expand Down
Expand Up @@ -28,7 +28,7 @@
import org.jumpmind.symmetric.ActivityListenerSupport;
import org.jumpmind.symmetric.SymmetricEngine;
import org.jumpmind.symmetric.common.Constants;
import org.jumpmind.symmetric.common.PropertiesConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.db.IDbDialect;
import org.jumpmind.symmetric.model.Channel;
import org.jumpmind.symmetric.model.NodeChannel;
Expand Down Expand Up @@ -70,12 +70,12 @@ public boolean connect(IAppController c) {
this.controller = c;
try {
synchronized (SymmetricDatabase.class) {
System.setProperty(PropertiesConstants.DBPOOL_URL, jdbcUrl);
System.setProperty(PropertiesConstants.DBPOOL_DRIVER, driverName);
System.setProperty(PropertiesConstants.DBPOOL_USER, username == null ? "" : username);
System.setProperty(PropertiesConstants.DBPOOL_PASSWORD, password == null ? "" : password);
System.setProperty(PropertiesConstants.DBPOOL_INITIAL_SIZE, "1");
System.setProperty(PropertiesConstants.RUNTIME_CONFIG_TABLE_PREFIX, tablePrefix);
System.setProperty(ParameterConstants.DBPOOL_URL, jdbcUrl);
System.setProperty(ParameterConstants.DBPOOL_DRIVER, driverName);
System.setProperty(ParameterConstants.DBPOOL_USER, username == null ? "" : username);
System.setProperty(ParameterConstants.DBPOOL_PASSWORD, password == null ? "" : password);
System.setProperty(ParameterConstants.DBPOOL_INITIAL_SIZE, "1");
System.setProperty(ParameterConstants.RUNTIME_CONFIG_TABLE_PREFIX, tablePrefix);
engine = new SymmetricEngine(new ActivityListenerSupport() {
@Override
public boolean createConfigurationTables(IDbDialect dbDialect) {
Expand Down
Expand Up @@ -20,7 +20,7 @@

package org.jumpmind.symmetric.common;

public class PropertiesConstants {
public class ParameterConstants {

public final static String START_PULL_JOB = "symmetric.runtime.start.pull.job";
public final static String START_PUSH_JOB = "symmetric.runtime.start.push.job";
Expand All @@ -33,6 +33,8 @@ public class PropertiesConstants {
public final static String START_RUNTIME_MY_URL = "symmetric.runtime.my.url";
public final static String START_RUNTIME_ENGINE_NAME = "symmetric.runtime.engine.name";

public final static String CONCURRENT_WORKERS = "symmetric.http.concurrent.workers.max";

public final static String DBPOOL_URL = "db.url";
public final static String DBPOOL_DRIVER ="db.driver";
public final static String DBPOOL_USER = "db.user";
Expand Down
Expand Up @@ -28,6 +28,8 @@
* Get and set application wide configuration information.
*/
public interface IParameterService {

public static final String ALL = "ALL";

public BigDecimal getDecimal(String key);

Expand Down
Expand Up @@ -42,8 +42,6 @@ public class ParameterService extends AbstractService implements IParameterServi

static final Log logger = LogFactory.getLog(ParameterService.class);

static final String ALL = "ALL";

private Map<String, String> parameters;

private BeanFactory beanFactory;
Expand Down
1 change: 0 additions & 1 deletion symmetric/src/main/resources/ddl-config.xml
Expand Up @@ -281,7 +281,6 @@
<column name="external_id" type="VARCHAR" size="50" required="true" primaryKey="true" />
<column name="node_group_id" type="VARCHAR" size="50" required="true" primaryKey="true" />
<column name="param_key" type="VARCHAR" size="100" required="true" primaryKey="true" />
<column name="param_type" type="CHAR" size="1" required="true" />
<column name="param_value" type="VARCHAR" size="1000" />
</table>

Expand Down
Expand Up @@ -33,7 +33,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jumpmind.symmetric.common.PropertiesConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TestConstants;
import org.jumpmind.symmetric.load.DataLoaderTest;
import org.jumpmind.symmetric.service.impl.DataLoaderServiceTest;
Expand Down Expand Up @@ -145,12 +145,12 @@ protected static File writeTempPropertiesFileFor(String databaseType, DatabaseRo
newProperties.setProperty("symmetric.runtime.external.id",
databaseRole == DatabaseRole.ROOT ? TestConstants.TEST_ROOT_EXTERNAL_ID
: TestConstants.TEST_CLIENT_EXTERNAL_ID);
newProperties.setProperty(PropertiesConstants.START_RUNTIME_MY_URL, "internal://"
newProperties.setProperty(ParameterConstants.START_RUNTIME_MY_URL, "internal://"
+ databaseRole.name().toLowerCase());
newProperties.setProperty(PropertiesConstants.START_RUNTIME_REGISTRATION_URL,
newProperties.setProperty(ParameterConstants.START_RUNTIME_REGISTRATION_URL,
databaseRole == DatabaseRole.CLIENT ? ("internal://" + DatabaseRole.ROOT.name()
.toLowerCase()) : "");
newProperties.setProperty(PropertiesConstants.START_RUNTIME_ENGINE_NAME, databaseRole.name().toLowerCase());
newProperties.setProperty(ParameterConstants.START_RUNTIME_ENGINE_NAME, databaseRole.name().toLowerCase());

File propertiesFile = File.createTempFile("symmetric-test.", ".properties");
FileOutputStream os = new FileOutputStream(propertiesFile);
Expand Down
@@ -1,15 +1,44 @@
package org.jumpmind.symmetric.service.impl;

import org.jumpmind.symmetric.AbstractDatabaseTest;
import org.jumpmind.symmetric.common.PropertiesConstants;
import org.jumpmind.symmetric.common.ParameterConstants;
import org.jumpmind.symmetric.common.TestConstants;
import org.jumpmind.symmetric.service.IParameterService;
import org.testng.Assert;
import org.testng.annotations.Test;

public class ParameterServiceTest extends AbstractDatabaseTest {


@Test(groups="continuous")
public void testParameterGetFromDefaults() {
Assert.assertEquals(getParameterService().getString(PropertiesConstants.RUNTIME_CONFIG_TABLE_PREFIX), "sym", "Unexpected default table prefix found.");
Assert.assertEquals(getParameterService().getString(ParameterConstants.RUNTIME_CONFIG_TABLE_PREFIX), "sym", "Unexpected default table prefix found.");
}


@Test(groups="continuous")
public void testParameterGetFromDatabase() {
Assert.assertEquals(getParameterService().getInt(ParameterConstants.CONCURRENT_WORKERS), 20);
getParameterService().saveParameter(TestConstants.TEST_CLIENT_EXTERNAL_ID, TestConstants.TEST_CLIENT_NODE_GROUP, ParameterConstants.CONCURRENT_WORKERS, 10);
getParameterService().rereadParameters();

// make sure we are not picking up someone else's parameter
Assert.assertEquals(getParameterService().getInt(ParameterConstants.CONCURRENT_WORKERS), 20);

getParameterService().saveParameter(IParameterService.ALL, TestConstants.TEST_ROOT_NODE_GROUP, ParameterConstants.CONCURRENT_WORKERS, 5);

// make sure the parameters are cached
Assert.assertEquals(getParameterService().getInt(ParameterConstants.CONCURRENT_WORKERS), 20);

// make sure we pick up the new parameter for us
getParameterService().rereadParameters();
Assert.assertEquals(getParameterService().getInt(ParameterConstants.CONCURRENT_WORKERS), 5);

getParameterService().saveParameter(TestConstants.TEST_ROOT_EXTERNAL_ID, TestConstants.TEST_ROOT_NODE_GROUP, ParameterConstants.CONCURRENT_WORKERS, 10);

// make sure we pick up the new parameter for us
getParameterService().rereadParameters();
Assert.assertEquals(getParameterService().getInt(ParameterConstants.CONCURRENT_WORKERS), 10);
}


}

0 comments on commit e30daf6

Please sign in to comment.