Search in sources :

Example 11 with OutgoingBatches

use of org.jumpmind.symmetric.model.OutgoingBatches in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method testSyncIncomingBatch.

public void testSyncIncomingBatch() throws Exception {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getTrigger().setSyncOnIncomingBatch(true);
    trigger1.getRouter().setRouterExpression(null);
    trigger1.getRouter().setRouterType(null);
    getTriggerRouterService().saveTriggerRouter(trigger1);
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(1000);
    testChannel.setMaxBatchSize(50);
    testChannel.setBatchAlgorithm("default");
    getConfigurationService().saveChannel(testChannel, true);
    getTriggerRouterService().syncTriggers();
    insert(TEST_TABLE_1, 10, true, NODE_GROUP_NODE_1.getNodeId());
    getRouterService().routeData(true);
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals("Should have been 0.  We did the insert as if the data had come from node 1.", 0, batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(1, batches.getBatches().size());
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 12 with OutgoingBatches

use of org.jumpmind.symmetric.model.OutgoingBatches in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method testBshTransactionalRoutingOnUpdate.

public void testBshTransactionalRoutingOnUpdate() {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("bsh");
    trigger1.getRouter().setRouterExpression("targetNodes.add(ROUTING_VARCHAR); targetNodes.add(OLD_ROUTING_VARCHAR);");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(1000);
    testChannel.setMaxBatchSize(5);
    testChannel.setBatchAlgorithm("transactional");
    getConfigurationService().saveChannel(testChannel, true);
    long ts = System.currentTimeMillis();
    ISqlTransaction transaction = null;
    int count = 0;
    try {
        transaction = getSqlTemplate().startSqlTransaction();
        count = transaction.prepareAndExecute(String.format("update %s set routing_varchar=?", TEST_TABLE_1), NODE_GROUP_NODE_3.getNodeId());
        transaction.commit();
    } finally {
        transaction.close();
    }
    logger.info("Just recorded a change to " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
    ts = System.currentTimeMillis();
    getRouterService().routeData(true);
    logger.info("Just routed " + count + " rows in " + TEST_TABLE_1 + " in " + (System.currentTimeMillis() - ts) + "ms");
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
    Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Node 2 has sync disabled
    Assert.assertEquals(0, batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 510, batches.getBatches().size());
    Assert.assertEquals(getDbDialect().supportsTransactionId() ? count : 1, (int) batches.getBatches().get(0).getDataEventCount());
    resetBatches();
}
Also used : ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 13 with OutgoingBatches

use of org.jumpmind.symmetric.model.OutgoingBatches in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method testColumnMatchTransactionalOnlyRoutingToNode1.

public void testColumnMatchTransactionalOnlyRoutingToNode1() {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("column");
    trigger1.getRouter().setRouterExpression("ROUTING_VARCHAR=:NODE_ID");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(10000);
    testChannel.setBatchAlgorithm("transactional");
    getConfigurationService().saveChannel(testChannel, true);
    // should be 51 batches for table 1
    insert(TEST_TABLE_1, 500, true);
    insert(TEST_TABLE_1, 50, false);
    getRouterService().routeData(true);
    final int EXPECTED_BATCHES = getDbDialect().supportsTransactionId() ? 51 : 550;
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(EXPECTED_BATCHES, batches.getBatches().size());
    Assert.assertEquals(EXPECTED_BATCHES, countBatchesForChannel(batches, testChannel));
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Node 2 has sync disabled
    Assert.assertEquals(0, batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Batch was targeted only at node 1
    Assert.assertEquals(0, batches.getBatches().size());
    resetBatches();
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    execute("delete from " + TEST_TABLE_1, null);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    getRouterService().routeData(true);
    Assert.assertEquals(getDbDialect().supportsTransactionId() ? 1 : 705, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 14 with OutgoingBatches

use of org.jumpmind.symmetric.model.OutgoingBatches in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method testBshRoutingDeletesToNode3.

public void testBshRoutingDeletesToNode3() {
    resetBatches();
    TriggerRouter trigger1 = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger1.getRouter().setRouterType("bsh");
    trigger1.getRouter().setRouterExpression("targetNodes.add(ROUTING_VARCHAR); if (OLD_ROUTING_VARCHAR != void) { targetNodes.add(OLD_ROUTING_VARCHAR); }");
    getTriggerRouterService().saveTriggerRouter(trigger1);
    getTriggerRouterService().syncTriggers();
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    testChannel.setMaxBatchToSend(10000);
    final int MAX_BATCH_SIZE = 100;
    testChannel.setMaxBatchSize(MAX_BATCH_SIZE);
    testChannel.setBatchAlgorithm("nontransactional");
    getConfigurationService().saveChannel(testChannel, true);
    int count = getSqlTemplate().update(String.format("delete from %s", TEST_TABLE_1));
    getRouterService().routeData(true);
    OutgoingBatches batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_3.getNodeId(), false);
    filterForChannels(batches, testChannel);
    Assert.assertEquals(count / MAX_BATCH_SIZE + (count % MAX_BATCH_SIZE > 0 ? 1 : 0), batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_2.getNodeId(), false);
    // Node 2 has sync disabled
    Assert.assertEquals(0, batches.getBatches().size());
    batches = getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false);
    filterForChannels(batches, testChannel);
    // Batch was targeted only at node 3
    Assert.assertEquals(0, batches.getBatches().size());
    resetBatches();
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 15 with OutgoingBatches

use of org.jumpmind.symmetric.model.OutgoingBatches in project symmetric-ds by JumpMind.

the class SimpleIntegrationTest method test11SuspendIgnorePushRemoteBatches.

@Test(timeout = 120000)
public void test11SuspendIgnorePushRemoteBatches() throws Exception {
    // test suspend / ignore with remote database specifying the suspends
    // and ignores
    logTestRunning();
    Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    Order order = new Order("101", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("101", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    boolean pushedData = clientPush();
    logger.error("Done pushing data");
    assertTrue("Client data was not batched and pushed", pushedData);
    assertNotNull(serverTestService.getOrder(order.getOrderId()));
    IConfigurationService rootConfigurationService = getServer().getConfigurationService();
    IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
    date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    order = new Order("102", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("102", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    getClient().route();
    NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    rootConfigurationService.saveNodeChannel(c, true);
    OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be 1 outgoing batches.", 1, batches.getBatches().size());
    pushedData = clientPush();
    assertNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
    c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setIgnoreEnabled(true);
    rootConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches", 1, batches.getBatches().size());
    assertNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
    // Cleanup!
    c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(false);
    c.setIgnoreEnabled(false);
    rootConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches", 0, batches.getBatches().size());
    assertNotNull("The order record was synchronized when it should not have been", serverTestService.getOrder(order.getOrderId()));
}
Also used : FixMethodOrder(org.junit.FixMethodOrder) IConfigurationService(org.jumpmind.symmetric.service.IConfigurationService) IOutgoingBatchService(org.jumpmind.symmetric.service.IOutgoingBatchService) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) NodeChannel(org.jumpmind.symmetric.model.NodeChannel) Date(java.util.Date) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Aggregations

OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)34 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)15 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)14 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)8 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 Date (java.util.Date)5 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)5 FixMethodOrder (org.junit.FixMethodOrder)5 File (java.io.File)3 ProtocolDataWriter (org.jumpmind.symmetric.io.data.writer.ProtocolDataWriter)3 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 IOutgoingBatchFilter (org.jumpmind.symmetric.ext.IOutgoingBatchFilter)2 IDataWriter (org.jumpmind.symmetric.io.data.IDataWriter)2 Channel (org.jumpmind.symmetric.model.Channel)2 FileTriggerRouter (org.jumpmind.symmetric.model.FileTriggerRouter)2 IFileSyncService (org.jumpmind.symmetric.service.IFileSyncService)2