Search in sources :

Example 16 with IParameterService

use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.

the class DefaultNodeIdCreatorTest method testGenerateNodeIdWithMultipleExistingWithUniqueParam.

@Test
public void testGenerateNodeIdWithMultipleExistingWithUniqueParam() throws Exception {
    final String EXPECTED_NODE_ID = "100-5";
    IParameterService paramService = mock(IParameterService.class);
    Mockito.when(paramService.is(ParameterConstants.EXTERNAL_ID_IS_UNIQUE)).thenReturn(false);
    Mockito.when(paramService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100)).thenReturn(100);
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(paramService, new MockNodeService() {

        @Override
        public Node findNode(String nodeId) {
            if (nodeId != null && !nodeId.equals("100-5")) {
                Node node = new Node();
                node.setNodeId(nodeId);
                return node;
            } else {
                return null;
            }
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    String selectedNodeId = generator.generateNodeId(node, null, null);
    assertEquals(EXPECTED_NODE_ID, selectedNodeId);
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) Node(org.jumpmind.symmetric.model.Node) IParameterService(org.jumpmind.symmetric.service.IParameterService) Test(org.junit.Test)

Example 17 with IParameterService

use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.

the class DefaultNodeIdCreatorTest method testGenerateNodeIdExistingAll.

@Test
public void testGenerateNodeIdExistingAll() throws Exception {
    IParameterService paramService = mock(IParameterService.class);
    Mockito.when(paramService.is(ParameterConstants.EXTERNAL_ID_IS_UNIQUE)).thenReturn(false);
    Mockito.when(paramService.getInt(ParameterConstants.NODE_ID_CREATOR_MAX_NODES, 100)).thenReturn(100);
    DefaultNodeIdCreator generator = new DefaultNodeIdCreator(paramService, new MockNodeService() {

        @Override
        public Node findNode(String nodeId) {
            Node node = new Node();
            node.setNodeId(nodeId);
            return node;
        }
    }, SecurityServiceFactory.create());
    Node node = new Node();
    node.setExternalId("100");
    try {
        generator.generateNodeId(node, null, null);
        fail("Should have received exception");
    } catch (Exception e) {
    // Expected
    }
}
Also used : MockNodeService(org.jumpmind.symmetric.service.impl.MockNodeService) Node(org.jumpmind.symmetric.model.Node) IParameterService(org.jumpmind.symmetric.service.IParameterService) Test(org.junit.Test)

Example 18 with IParameterService

use of org.jumpmind.symmetric.service.IParameterService in project symmetric-ds by JumpMind.

the class SimpleIntegrationTest method test25TestPurge.

@Test(timeout = 120000)
public void test25TestPurge() throws Exception {
    logTestRunning();
    // do an extra push & pull to make sure we have events cleared out
    clientPull();
    clientPush();
    Thread.sleep(2000);
    IParameterService parameterService = getServer().getParameterService();
    int purgeRetentionMinues = parameterService.getInt(ParameterConstants.PURGE_RETENTION_MINUTES);
    // set purge in the future just in case the database time is different
    // than the current time
    parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, -60 * 24, "test");
    int beforePurge = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data");
    getServer().purge();
    int afterPurge = getServer().getSqlTemplate().queryForInt("select count(*) from sym_data");
    Timestamp maxCreateTime = (Timestamp) getServer().getSqlTemplate().queryForObject("select max(create_time) from sym_data", Timestamp.class);
    Timestamp minCreateTime = (Timestamp) getServer().getSqlTemplate().queryForObject("select min(create_time) from sym_data", Timestamp.class);
    assertTrue("Expected data rows to have been purged at the root.  There were " + beforePurge + " row before and " + afterPurge + " rows after. The max create_time in sym_data was " + maxCreateTime + " and the min create_time in sym_data was " + minCreateTime + " and the current time of the server is " + new Date(), (beforePurge - afterPurge) > 0);
    parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, purgeRetentionMinues, "test");
    parameterService = getClient().getParameterService();
    purgeRetentionMinues = parameterService.getInt(ParameterConstants.PURGE_RETENTION_MINUTES);
    // set purge in the future just in case the database time is different
    // than the current time
    parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, -60 * 24, "test");
    beforePurge = getClient().getSqlTemplate().queryForInt("select count(*) from sym_data");
    getClient().purge();
    afterPurge = getClient().getSqlTemplate().queryForInt("select count(*) from sym_data");
    maxCreateTime = (Timestamp) getClient().getSqlTemplate().queryForObject("select max(create_time) from sym_data", Timestamp.class);
    minCreateTime = (Timestamp) getClient().getSqlTemplate().queryForObject("select min(create_time) from sym_data", Timestamp.class);
    assertTrue("Expected data rows to have been purged at the client.  There were " + beforePurge + " row before anf " + afterPurge + " rows after. . The max create_time in sym_data was " + maxCreateTime + " and the min create_time in sym_data was " + minCreateTime + " and the current time of the server is " + new Date(), (beforePurge - afterPurge) > 0);
    parameterService.saveParameter(ParameterConstants.PURGE_RETENTION_MINUTES, purgeRetentionMinues, "test");
}
Also used : IParameterService(org.jumpmind.symmetric.service.IParameterService) Timestamp(java.sql.Timestamp) Date(java.util.Date) Test(org.junit.Test)

Aggregations

IParameterService (org.jumpmind.symmetric.service.IParameterService)18 Table (org.jumpmind.db.model.Table)6 Node (org.jumpmind.symmetric.model.Node)6 Test (org.junit.Test)5 Date (java.util.Date)4 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)3 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)3 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)3 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)3 MockNodeService (org.jumpmind.symmetric.service.impl.MockNodeService)3 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)2 Trigger (org.jumpmind.symmetric.model.Trigger)2 TriggerHistory (org.jumpmind.symmetric.model.TriggerHistory)2 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)2 INodeService (org.jumpmind.symmetric.service.INodeService)2 ITriggerRouterService (org.jumpmind.symmetric.service.ITriggerRouterService)2 Before (org.junit.Before)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1