Skip to content

Commit

Permalink
Added subselect, nontransactional test
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jul 18, 2009
1 parent 746197e commit 6cf050f
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 4 deletions.
@@ -0,0 +1,37 @@
/*
* SymmetricDS is an open source database synchronization solution.
*
* Copyright (C) Chris Henson <chenson42@users.sourceforge.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*/
package org.jumpmind.symmetric.route;

import org.jumpmind.symmetric.model.DataMetaData;
import org.jumpmind.symmetric.model.OutgoingBatch;
import org.jumpmind.symmetric.model.OutgoingBatchHistory;

public class NonTransactionalBatchAlgorithm implements IBatchAlgorithm {

public boolean isBatchComplete(OutgoingBatchHistory history, OutgoingBatch batch, DataMetaData dataMetaData,
IRoutingContext routingContext) {
return history.getDataEventCount() >= dataMetaData.getChannel().getMaxBatchSize();
}

public boolean isAutoRegister() {
return true;
}

}
7 changes: 5 additions & 2 deletions symmetric/src/main/resources/symmetric-routers.xml
Expand Up @@ -10,7 +10,7 @@
<entry key="subselect">
<bean class="org.jumpmind.symmetric.route.SubSelectDataRouter">
<property name="sql"
value="select c.node_id from $[sym.sync.table.prefix]_node c where c.node_group_id=? and c.sync_enabled=1 and " />
value="select c.node_id from $[sym.sync.table.prefix]_node c where c.node_group_id=:NODE_GROUP_ID and c.sync_enabled=1 and " />
<property name="jdbcTemplate" ref="jdbcTemplate" />
<property name="dbDialect" ref="dbDialect" />
</bean>
Expand All @@ -30,9 +30,12 @@
<entry key="default">
<bean class="org.jumpmind.symmetric.route.DefaultBatchAlgorithm" />
</entry>
<entry key="transaction">
<entry key="transactional">
<bean class="org.jumpmind.symmetric.route.TransactionalBatchAlgorithm" />
</entry>
<entry key="nontransactional">
<bean class="org.jumpmind.symmetric.route.NonTransactionalBatchAlgorithm" />
</entry>
</util:map>

</beans>
Expand Up @@ -111,14 +111,13 @@ public void testColumnMatchTransactionalOnlyRoutingToNode1() {
getBootstrapService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getChannel(TestConstants.TEST_CHANNEL_ID);
testChannel.setMaxBatchToSend(100);
testChannel.setBatchAlgorithm("transaction");
testChannel.setBatchAlgorithm("transactional");
getConfigurationService().saveChannel(testChannel);

// should be 51 batches for table 1
insert(TEST_TABLE_1, 500, true);
insert(TEST_TABLE_1, 50, false);
getRoutingService().routeData();
getRoutingService().routeData();

final int EXPECTED_BATCHES = 51;

Expand All @@ -139,6 +138,45 @@ public void testColumnMatchTransactionalOnlyRoutingToNode1() {

resetBatches();
}

@Test
public void testSubSelectNonTransactionalRoutingToNode1() {
resetBatches();

Trigger trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
trigger1.setRouterName("subselect");
trigger1.setRouterExpression("c.node_id=:ROUTING_VARCHAR");
getConfigurationService().saveTrigger(trigger1);
getBootstrapService().syncTriggers();
NodeChannel testChannel = getConfigurationService().getChannel(TestConstants.TEST_CHANNEL_ID);
testChannel.setMaxBatchToSend(1000);
testChannel.setMaxBatchSize(5);
testChannel.setBatchAlgorithm("nontransactional");
getConfigurationService().saveChannel(testChannel);

// should be 51 batches for table 1
insert(TEST_TABLE_1, 500, true);
getRoutingService().routeData();

final int EXPECTED_BATCHES = 100;

List<OutgoingBatch> batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1);
filterForChannels(batches, testChannel);
Assert.assertEquals(EXPECTED_BATCHES, batches.size());
Assert.assertEquals(EXPECTED_BATCHES, countBatchesForChannel(batches, testChannel));

batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2);
filterForChannels(batches, testChannel);
// Node 2 has sync disabled
Assert.assertEquals(0, batches.size());

batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3);
filterForChannels(batches, testChannel);
// Batch was targeted only at node 1
Assert.assertEquals(0, batches.size());

resetBatches();
}

@Test
public void syncIncomingBatchTest() throws Exception {
Expand Down

0 comments on commit 6cf050f

Please sign in to comment.