Search in sources :

Example 11 with NodeChannel

use of org.jumpmind.symmetric.model.NodeChannel 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 12 with NodeChannel

use of org.jumpmind.symmetric.model.NodeChannel 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 13 with NodeChannel

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

the class AbstractRouterServiceTest method testColumnMatchOnNotNull.

public void testColumnMatchOnNotNull() {
    NodeChannel testChannel = getConfigurationService().getNodeChannel(TestConstants.TEST_CHANNEL_ID, false);
    TriggerRouter trigger = getTestRoutingTableTrigger(TEST_TABLE_1);
    trigger.getRouter().setRouterType("column");
    trigger.getRouter().setRouterExpression("ROUTING_VARCHAR!=NULL");
    getTriggerRouterService().saveTriggerRouter(trigger);
    getTriggerRouterService().syncTriggers();
    resetBatches();
    update(TEST_TABLE_1, "Not Routed");
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    getRouterService().routeData(true);
    Assert.assertEquals(1, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    resetBatches();
    update(TEST_TABLE_1, null);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
    getRouterService().routeData(true);
    Assert.assertEquals(0, countBatchesForChannel(getOutgoingBatchService().getOutgoingBatches(NODE_GROUP_NODE_1.getNodeId(), false), testChannel));
}
Also used : TriggerRouter(org.jumpmind.symmetric.model.TriggerRouter) NodeChannel(org.jumpmind.symmetric.model.NodeChannel)

Example 14 with NodeChannel

use of org.jumpmind.symmetric.model.NodeChannel 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();
    assertTrue("Client data was not batched and pushed", pushedData);
    assertNotNull(serverTestService.getOrder(order.getOrderId()));
    IConfigurationService rootConfigurationService = getServer().getConfigurationService();
    IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
    NodeChannel c = rootConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    rootConfigurationService.saveNodeChannel(c, true);
    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);
    clientPush();
    OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be one outgoing batches.", 1, batches.getBatches().size());
    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", 0, 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();
}
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)

Example 15 with NodeChannel

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

the class SimpleIntegrationTest method test12SuspendIgnorePushLocalBatches.

@Test(timeout = 120000)
public void test12SuspendIgnorePushLocalBatches() throws Exception {
    // test suspend / ignore with local database specifying the suspends
    // and ignores
    logTestRunning();
    Date date = DateUtils.parseDate("2007-01-03", new String[] { "yyyy-MM-dd" });
    Order order = new Order("105", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("105", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    assertNull(serverTestService.getOrder(order.getOrderId()));
    clientTestService.insertOrder(order);
    clientPush();
    assertNotNull(serverTestService.getOrder(order.getOrderId()));
    IConfigurationService clientConfigurationService = getClient().getConfigurationService();
    IOutgoingBatchService clientOutgoingBatchService = getClient().getOutgoingBatchService();
    NodeChannel c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    order = new Order("106", 100, null, date);
    order.getOrderDetails().add(new OrderDetail("106", 1, "STK", "110000065", 3, new BigDecimal("3.33")));
    clientPush();
    OutgoingBatches batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches since suspended locally", 0, batches.getBatches().size());
    assertNull(serverTestService.getOrder(order.getOrderId()));
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setIgnoreEnabled(true);
    clientConfigurationService.saveNodeChannel(c, true);
    clientPush();
    batches = clientOutgoingBatchService.getOutgoingBatches(TestConstants.TEST_ROOT_NODE.getNodeId(), false);
    assertEquals("There should be no outgoing batches since suspended locally", 0, batches.getBatches().size());
    assertNull(serverTestService.getOrder(order.getOrderId()));
    // Cleanup!
    c = clientConfigurationService.getNodeChannel(TestConstants.TEST_CHANNEL_ID, TestConstants.TEST_CLIENT_EXTERNAL_ID, false);
    c.setSuspendEnabled(false);
    c.setIgnoreEnabled(false);
    clientConfigurationService.saveNodeChannel(c, true);
    clientPush();
}
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

NodeChannel (org.jumpmind.symmetric.model.NodeChannel)39 Test (org.junit.Test)15 TriggerRouter (org.jumpmind.symmetric.model.TriggerRouter)14 OutgoingBatches (org.jumpmind.symmetric.model.OutgoingBatches)13 Node (org.jumpmind.symmetric.model.Node)12 HashSet (java.util.HashSet)11 Data (org.jumpmind.symmetric.model.Data)10 Table (org.jumpmind.db.model.Table)9 DataMetaData (org.jumpmind.symmetric.model.DataMetaData)9 Router (org.jumpmind.symmetric.model.Router)9 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)9 Date (java.util.Date)7 IConfigurationService (org.jumpmind.symmetric.service.IConfigurationService)6 IOutgoingBatchService (org.jumpmind.symmetric.service.IOutgoingBatchService)5 FixMethodOrder (org.junit.FixMethodOrder)5 ArrayList (java.util.ArrayList)4 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)3 BigDecimal (java.math.BigDecimal)2 List (java.util.List)2 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)2