Skip to content

Commit

Permalink
Implemented unit test for sync on incoming batch and fixed the funky …
Browse files Browse the repository at this point in the history
…data type test for Oracle.
  • Loading branch information
chenson42 committed Jul 19, 2009
1 parent 6f76dc0 commit c63e1a8
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 21 deletions.
Expand Up @@ -64,27 +64,27 @@
*/
public class ExtensionProcessor implements BeanFactoryPostProcessor {

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

IDataLoaderService dataLoaderService;
private IDataLoaderService dataLoaderService;

IDataService dataService;
private IDataService dataService;

IDataExtractorService dataExtractorService;
private IDataExtractorService dataExtractorService;

IParameterService parameterService;
private IParameterService parameterService;

INodeService nodeService;
private INodeService nodeService;

IBootstrapService bootstrapService;
private IBootstrapService bootstrapService;

IAcknowledgeService acknowledgeService;
private IAcknowledgeService acknowledgeService;

IRegistrationService registrationService;
private IRegistrationService registrationService;

ITransportManager transportManager;
private ITransportManager transportManager;

IRoutingService routingService;
private IRoutingService routingService;

@SuppressWarnings("unchecked")
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
Expand Down
Expand Up @@ -10,7 +10,6 @@
import org.jumpmind.symmetric.model.Trigger;
import org.jumpmind.symmetric.test.AbstractDatabaseTest;
import org.jumpmind.symmetric.test.TestConstants;
import org.jumpmind.symmetric.test.ParameterizedSuite.ParameterExcluder;
import org.junit.Test;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.TransactionStatus;
Expand Down Expand Up @@ -180,12 +179,36 @@ public void testSubSelectNonTransactionalRoutingToNode1() {

@Test
public void syncIncomingBatchTest() throws Exception {
resetBatches();

}
Trigger trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.setSyncOnIncomingBatch(true);
trigger1.setRouterExpression(null);
trigger1.setRouterName(null);
getConfigurationService().saveTrigger(trigger1);

NodeChannel testChannel = getConfigurationService().getChannel(TestConstants.TEST_CHANNEL_ID);
testChannel.setMaxBatchToSend(1000);
testChannel.setMaxBatchSize(50);
testChannel.setBatchAlgorithm("default");
getConfigurationService().saveChannel(testChannel);

getBootstrapService().syncTriggers();

insert(TEST_TABLE_1, 10, true, NODE_GROUP_NODE_1);

getRoutingService().routeData();

List<OutgoingBatch> batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1);
filterForChannels(batches, testChannel);
Assert.assertEquals("Should have been 0. We did the insert as if the data had come from node 1." ,0 , batches.size());

batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3);
filterForChannels(batches, testChannel);
Assert.assertEquals(1, batches.size());

resetBatches();

@Test
@ParameterExcluder("postgres")
public void validateTransactionFunctionailty() throws Exception {
}

protected void filterForChannels(List<OutgoingBatch> batches, NodeChannel... channels) {
Expand Down Expand Up @@ -220,12 +243,27 @@ protected int countBatchesForChannel(List<OutgoingBatch> batches, NodeChannel ch
}

protected void insert(final String tableName, final int count, boolean transactional) {
insert(tableName, count, transactional, null);
}

protected void insert(final String tableName, final int count, boolean transactional, final String node2disable) {
TransactionCallbackWithoutResult callback = new TransactionCallbackWithoutResult() {
protected void doInTransactionWithoutResult(TransactionStatus status) {
SimpleJdbcTemplate t = new SimpleJdbcTemplate(getJdbcTemplate());
for (int i = 0; i < count; i++) {
t.update(String.format("insert into %s (ROUTING_VARCHAR) values(?)", tableName), NODE_GROUP_NODE_1);
try {
if (node2disable != null) {
getDbDialect().disableSyncTriggers(node2disable);
}
for (int i = 0; i < count; i++) {
t.update(String.format("insert into %s (ROUTING_VARCHAR) values(?)", tableName),
NODE_GROUP_NODE_1);
}
} finally {
if (node2disable != null) {
getDbDialect().enableSyncTriggers();
}
}

}
};

Expand Down
Expand Up @@ -35,6 +35,7 @@
import org.junit.AfterClass;
import org.junit.Assert;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.transaction.support.TransactionTemplate;

public class AbstractDatabaseTest {
Expand Down Expand Up @@ -97,6 +98,10 @@ protected TransactionTemplate getTransactionTemplate() {
protected JdbcTemplate getJdbcTemplate() {
return new JdbcTemplate((DataSource) AppUtils.find(Constants.DATA_SOURCE, getSymmetricEngine()));
}

protected SimpleJdbcTemplate getSimpleJdbcTemplate() {
return new SimpleJdbcTemplate((DataSource)AppUtils.find(Constants.DATA_SOURCE, getSymmetricEngine()));
}

@SuppressWarnings("unchecked")
protected <T> T find(String name) {
Expand Down
Expand Up @@ -27,7 +27,7 @@
import org.jumpmind.symmetric.test.ParameterizedSuite.ParameterMatcher;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;

public class FunkyDataTypesTest extends AbstractDatabaseTest {

Expand All @@ -45,7 +45,7 @@ public FunkyDataTypesTest() throws Exception {
@Test
@ParameterMatcher("oracle")
public void testOraclePrecisionTimestamp() {
JdbcTemplate jdbcTemplate = getJdbcTemplate();
SimpleJdbcTemplate jdbcTemplate = getSimpleJdbcTemplate();
try {
jdbcTemplate.update("drop table " + TABLE_NAME + "");
} catch (Exception ex) {
Expand All @@ -63,9 +63,11 @@ public void testOraclePrecisionTimestamp() {
trigger.setSyncOnDelete(true);
configService.saveTrigger(trigger);
getSymmetricEngine().syncTriggers();
Assert.assertEquals("There should not be any data captured at this point.", jdbcTemplate.queryForInt("select count(*) from sym_data where table_name=?", TABLE_NAME),
0);
jdbcTemplate.update("insert into " + TABLE_NAME
+ " values('00000',timestamp'2008-01-01 00:00:00.000',timestamp'2008-01-01 00:00:00.000')");
Assert.assertEquals("The data event from the other database's other_table was not captured.", jdbcTemplate.queryForInt("select count(*) from sym_data_event where channel_id='other'"),
Assert.assertEquals("The data event from the other database's other_table was not captured.", jdbcTemplate.queryForInt("select count(*) from sym_data where table_name=?", TABLE_NAME),
1);
}
}

0 comments on commit c63e1a8

Please sign in to comment.