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);
}
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
}
}
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");
}
Aggregations