use of org.jumpmind.util.Statistics in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testUpdateDetectOldDataWithNullManual.
@Test
public void testUpdateDetectOldDataWithNullManual() {
Conflict setting = new Conflict();
setting.setConflictId("unit.test");
setting.setDetectType(DetectConflict.USE_OLD_DATA);
setting.setResolveRowOnly(false);
setting.setResolveChangesOnly(false);
setting.setResolveType(ResolveConflict.MANUAL);
writerSettings.setDefaultConflictSetting(setting);
String origId = getNextId();
String[] originalValues = massageExpectectedResultsForDialect(new String[] { origId, null, "changed value", "char2", "char not null2", "2007-01-02 03:20:10.000", "2012-03-12 07:00:00.000", "0", "2", "67.89", "-0.0747663" });
CsvData data = new CsvData(DataEventType.INSERT, originalValues);
writeData(data, originalValues);
String[] oldData = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
oldData[2] = "original value";
oldData = massageExpectectedResultsForDialect(oldData);
String[] newData = CollectionUtils.copyOfRange(originalValues, 0, originalValues.length);
newData[2] = "new value";
newData = massageExpectectedResultsForDialect(newData);
CsvData update = new CsvData(DataEventType.UPDATE);
update.putParsedData(CsvData.ROW_DATA, newData);
update.putParsedData(CsvData.OLD_DATA, oldData);
try {
writeData(update);
Assert.fail("Should have received a conflict exception");
} catch (ConflictException ex) {
Statistics stats = lastDataWriterUsed.getStatistics().values().iterator().next();
long statementNumber = stats.get(DataWriterStatisticConstants.STATEMENTCOUNT);
ResolvedData resolvedData = new ResolvedData(statementNumber, update.getCsvData(CsvData.ROW_DATA), false);
writerSettings.setResolvedData(resolvedData);
writeData(update);
Map<String, Object> row = queryForRow(origId);
Assert.assertNotNull(row);
Assert.assertEquals(newData[2], row.get("string_required_value"));
}
}
Aggregations