Skip to content

Commit

Permalink
Fix multidatabase integration test by consolidating the integration t…
Browse files Browse the repository at this point in the history
…est to "one" method :-(
  • Loading branch information
chenson42 committed Dec 19, 2007
1 parent f2d6f37 commit b900272
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 110 deletions.
2 changes: 1 addition & 1 deletion symmetric/pom.xml
Expand Up @@ -399,7 +399,7 @@
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.5</version>
<version>5.6</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
Expand Down
42 changes: 22 additions & 20 deletions symmetric/src/main/java/org/jumpmind/symmetric/db/SqlTemplate.java
Expand Up @@ -195,29 +195,31 @@ private String replaceTemplateVariables(IDbDialect dialect, DataEventType dml, T
}

private String eval(boolean condition, String prop, String ddl) {
String ifStmt = "$(if:" + prop + ")";
String elseStmt = "$(else:" + prop + ")";
String endStmt = "$(end:" + prop + ")";
int ifIndex = ddl.indexOf(ifStmt);
if (ifIndex >= 0) {
int endIndex = ddl.indexOf(endStmt);
if (endIndex >= 0) {
String onTrue = ddl.substring(ifIndex + ifStmt.length(), endIndex);
String onFalse = "";
int elseIndex = onTrue.indexOf(elseStmt);
if (elseIndex >= 0) {
onFalse = onTrue.substring(elseIndex + elseStmt.length());
onTrue = onTrue.substring(0, elseIndex);
}
if (ddl != null) {
String ifStmt = "$(if:" + prop + ")";
String elseStmt = "$(else:" + prop + ")";
String endStmt = "$(end:" + prop + ")";
int ifIndex = ddl.indexOf(ifStmt);
if (ifIndex >= 0) {
int endIndex = ddl.indexOf(endStmt);
if (endIndex >= 0) {
String onTrue = ddl.substring(ifIndex + ifStmt.length(), endIndex);
String onFalse = "";
int elseIndex = onTrue.indexOf(elseStmt);
if (elseIndex >= 0) {
onFalse = onTrue.substring(elseIndex + elseStmt.length());
onTrue = onTrue.substring(0, elseIndex);
}

if (condition) {
ddl = ddl.substring(0, ifIndex) + onTrue + ddl.substring(endIndex + endStmt.length());
} else {
ddl = ddl.substring(0, ifIndex) + onFalse + ddl.substring(endIndex + endStmt.length());
}

if (condition) {
ddl = ddl.substring(0, ifIndex) + onTrue + ddl.substring(endIndex + endStmt.length());
} else {
ddl = ddl.substring(0, ifIndex) + onFalse + ddl.substring(endIndex + endStmt.length());
throw new IllegalStateException(ifStmt + " has to have a " + endStmt);
}

} else {
throw new IllegalStateException(ifStmt + " has to have a " + endStmt);
}
}
return ddl;
Expand Down
Expand Up @@ -6,6 +6,6 @@
<listEntry value="org.eclipse.ui.externaltools.launchGroup"/>
</listAttribute>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${system_path:/mvn.bat}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="clean eclipse:eclipse docbkx:generate-html package"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="clean eclipse:eclipse package"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/symmetric}"/>
</launchConfiguration>
Expand Up @@ -19,25 +19,34 @@ abstract public class AbstractIntegrationTest extends AbstractTest {

private SymmetricEngine rootEngine;

private String clientDatabaseType;

private String rootDatabaseType;

protected SymmetricEngine getClientEngine() {
if (this.clientEngine == null) {
this.clientEngine = createEngine(getClientFile());
dropAndCreateDatabaseTables(getClientDatabaseName(), clientEngine);
}
return this.clientEngine;
}

protected String getRootDatabaseName() {
IDbDialect dialect = (IDbDialect)getRootEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
return dialect.getName().toLowerCase();
if (rootDatabaseType == null) {
IDbDialect dialect = (IDbDialect) getRootEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
rootDatabaseType = dialect.getName().toLowerCase();
}
return rootDatabaseType;
}

protected String getClientDatabaseName() {
IDbDialect dialect = (IDbDialect)getClientEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
return dialect.getName().toLowerCase();
if (clientDatabaseType == null) {
IDbDialect dialect = (IDbDialect) getClientEngine().getApplicationContext().getBean(Constants.DB_DIALECT);
clientDatabaseType = dialect.getName().toLowerCase();
}
return clientDatabaseType;
}


protected SymmetricEngine getRootEngine() {
if (this.rootEngine == null) {
this.rootEngine = createEngine(getRootFile());
Expand All @@ -49,7 +58,7 @@ protected SymmetricEngine getRootEngine() {
}
return this.rootEngine;
}

File getClientFile() {
Properties properties = MultiDatabaseTestFactory.getTestProperties();
String[] databaseTypes = StringUtils.split(properties.getProperty("test.client"), ",");
Expand All @@ -61,5 +70,13 @@ File getRootFile() {
String[] databaseTypes = StringUtils.split(properties.getProperty("test.root"), ",");

return MultiDatabaseTestFactory.writeTempPropertiesFileFor(databaseTypes[0], DatabaseRole.ROOT);
}
}

public void setClientDatabaseType(String clientDatabaseType) {
this.clientDatabaseType = clientDatabaseType;
}

public void setRootDatabaseType(String rootDatabaseType) {
this.rootDatabaseType = rootDatabaseType;
}
}
100 changes: 43 additions & 57 deletions symmetric/src/test/java/org/jumpmind/symmetric/IntegrationTest.java
Expand Up @@ -19,57 +19,64 @@
import org.springframework.jdbc.core.JdbcTemplate;
import org.testng.Assert;
import org.testng.ITest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

@Test(sequential=true)
public class IntegrationTest extends AbstractIntegrationTest implements ITest {

private JdbcTemplate rootJdbcTemplate;

private JdbcTemplate clientJdbcTemplate;

// TODO: move this data access somewhere else
static final String insertOrderHeaderSql = "insert into test_order_header (order_id, customer_id, status, deliver_date) values(?,?,?,?)";

static final String updateOrderHeaderStatusSql = "update test_order_header set status = ? where order_id = ?";

static final String selectOrderHeaderSql = "select order_id, customer_id, status, deliver_date from test_order_header where order_id = ?";

static final String insertOrderDetailSql = "insert into test_order_detail (order_id, line_number, item_type, item_id, quantity, price) values(?,?,?,?,?,?)";

static final String insertCustomerSql = "insert into test_customer (customer_id, name, is_active, address, city, state, zip, entry_time, notes, icon) values(?,?,?,?,?,?,?,?,?,?)";

static final String insertTestTriggerTableSql = "insert into test_triggers_table (string_one_value, string_two_value) values(?,?)";

static final String updateTestTriggerTableSql = "update test_triggers_table set string_one_value=?";

static final byte[] BINARY_DATA = new byte[] { 0x01, 0x02, 0x03 };

public String getTestName() {
return "Test from " + getRootDatabaseName() + " to " + getClientDatabaseName();
}

@BeforeTest(groups="continuous")
public void init() {

@Test(testName = "Integration Test", groups = "continuous", timeOut = 60000)
public void testLifecycle() throws Exception {
init();
register();
testSyncToClient();
testSyncToRootAutoGeneratedPrimaryKey();
testSyncToRoot();
testSyncInsertCondition();
testSyncUpdateCondition();
testIgnoreNodeChannel();
testPurge();
testHeartbeat();

}

protected void init() {
BeanFactory rootBeanFactory = getRootEngine().getApplicationContext();
rootJdbcTemplate = new JdbcTemplate((DataSource) rootBeanFactory.getBean(Constants.DATA_SOURCE));

BeanFactory clientBeanFactory = getClientEngine().getApplicationContext();
clientJdbcTemplate = new JdbcTemplate((DataSource) clientBeanFactory.getBean(Constants.DATA_SOURCE));

}

@Test(groups="continuous", timeOut=60000)
public void testRegistration() {

protected void register() {
getRootEngine().openRegistration(TestConstants.TEST_CLIENT_NODE_GROUP, TestConstants.TEST_CLIENT_EXTERNAL_ID);
getClientEngine().start();
Assert.assertTrue(getClientEngine().isRegistered(), "The client did not register.");
}

@Test(groups="continuous",dependsOnMethods="testRegistration")
public void testSyncToClient() {
protected void testSyncToClient() {
// test pulling no data
getClientEngine().pull();

Expand All @@ -89,31 +96,25 @@ public void testSyncToClient() {

}

@Test
public void testRejectedRegistration() {

}

@Test(groups="continuous",dependsOnMethods = "testSyncToClient")
public void testSyncToRootAutoGeneratedPrimaryKey() {
protected void testSyncToRootAutoGeneratedPrimaryKey() {
final String NEW_VALUE = "unique new value one value";
clientJdbcTemplate.update(insertTestTriggerTableSql, new Object[] { "value one", "value \" two" });
getClientEngine().push();
clientJdbcTemplate.update(updateTestTriggerTableSql, new Object[] { NEW_VALUE });
getClientEngine().push();
Assert.assertEquals(rootJdbcTemplate.queryForInt("select count(*) from test_triggers_table where string_one_value=?", new Object[] {NEW_VALUE}), 1, "The update on test_triggers_table did not work.");
Assert.assertEquals(rootJdbcTemplate.queryForInt(
"select count(*) from test_triggers_table where string_one_value=?", new Object[] { NEW_VALUE }), 1,
"The update on test_triggers_table did not work.");
}

@Test(groups="continuous",dependsOnMethods = "testSyncToClient")
public void testSyncToRoot() throws ParseException {
protected void testSyncToRoot() throws ParseException {
Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
clientJdbcTemplate.update(insertOrderHeaderSql, new Object[] { "10", 100, null, date });
clientJdbcTemplate.update(insertOrderDetailSql, new Object[] { "10", 1, "STK", "110000065", 3, 3.33 });
getClientEngine().push();
}

@Test(groups="continuous",dependsOnMethods="testSyncToRoot")
public void testSyncInsertCondition() throws ParseException {
protected void testSyncInsertCondition() throws ParseException {
// Should not sync when status = null
Date date = DateUtils.parseDate("2007-01-02", new String[] { "yyyy-MM-dd" });
rootJdbcTemplate.update(insertOrderHeaderSql, new Object[] { "11", 100, null, date });
Expand All @@ -136,8 +137,7 @@ public void testSyncInsertCondition() throws ParseException {
}

@SuppressWarnings("unchecked")
@Test(groups="continuous",dependsOnMethods="testSyncToRoot")
public void testSyncUpdateCondition() {
protected void testSyncUpdateCondition() {
rootJdbcTemplate.update(updateOrderHeaderStatusSql, new Object[] { null, "1" });
getClientEngine().pull();
Assert.assertEquals(clientJdbcTemplate.queryForList(selectOrderHeaderSql, new Object[] { "1" }).size(), 0,
Expand All @@ -153,8 +153,7 @@ public void testSyncUpdateCondition() {
}

@SuppressWarnings("unchecked")
@Test(groups="continuous",dependsOnMethods = "testSyncUpdateCondition")
public void testIgnoreNodeChannel() {
protected void testIgnoreNodeChannel() {
INodeService nodeService = (INodeService) getRootEngine().getApplicationContext().getBean("nodeService");
nodeService.ignoreNodeChannelForExternalId(true, TestConstants.TEST_CHANNEL_ID,
TestConstants.TEST_ROOT_NODE_GROUP, TestConstants.TEST_ROOT_EXTERNAL_ID);
Expand All @@ -168,9 +167,7 @@ public void testIgnoreNodeChannel() {

}

@Test(groups="continuous",dependsOnMethods = { "testSyncUpdateCondition", "testSyncInsertCondition",
"testSyncToRoot", "testSyncToClient" })
public void testPurge() throws Exception {
protected void testPurge() throws Exception {
Thread.sleep(1000);
getRootEngine().purge();
getClientEngine().purge();
Expand All @@ -182,8 +179,7 @@ public void testPurge() throws Exception {

}

@Test(groups="continuous", dependsOnMethods="testRegistration")
public void testHeartbeat() throws Exception {
protected void testHeartbeat() throws Exception {
long ts = System.currentTimeMillis();
Thread.sleep(1000);
getClientEngine().heartbeat();
Expand All @@ -194,41 +190,31 @@ public void testHeartbeat() throws Exception {
"The client node was not sync'd to the root as expected.");
}

@Test
public void testMultipleChannels() {
protected void testMultipleChannels() {
}

@Test
public void testChannelInError() {
protected void testChannelInError() {
}

@Test
public void testTableSyncConfigChangeForRoot() {
protected void testTableSyncConfigChangeForRoot() {
}

@Test
public void testTableSyncConfigChangeForClient() {
protected void testTableSyncConfigChangeForClient() {
}

@Test
public void testDataChangeTableChangeDataChangeThenSync() {
protected void testDataChangeTableChangeDataChangeThenSync() {
}

@Test
public void testTransactionalCommit() {
protected void testTransactionalCommit() {
}

@Test
public void testTransactionalCommitPastBatchBoundary() {
protected void testTransactionalCommitPastBatchBoundary() {
}

@Test
public void testSyncingGlobalParametersFromRoot() {

protected void testSyncingGlobalParametersFromRoot() {
}

@AfterClass()
public void tearDown() {
protected void testRejectedRegistration() {
}

}

0 comments on commit b900272

Please sign in to comment.