Search in sources :

Example 16 with Statistics

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"));
    }
}
Also used : ResolveConflict(org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict) DetectConflict(org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict) Statistics(org.jumpmind.util.Statistics) Map(java.util.Map) CsvData(org.jumpmind.symmetric.io.data.CsvData) AbstractWriterTest(org.jumpmind.symmetric.io.AbstractWriterTest) Test(org.junit.Test)

Aggregations

Statistics (org.jumpmind.util.Statistics)16 CsvData (org.jumpmind.symmetric.io.data.CsvData)6 IoException (org.jumpmind.exception.IoException)3 DataContext (org.jumpmind.symmetric.io.data.DataContext)3 DetectConflict (org.jumpmind.symmetric.io.data.writer.Conflict.DetectConflict)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Table (org.jumpmind.db.model.Table)2 AbstractWriterTest (org.jumpmind.symmetric.io.AbstractWriterTest)2 Batch (org.jumpmind.symmetric.io.data.Batch)2 DataEventType (org.jumpmind.symmetric.io.data.DataEventType)2 DataProcessor (org.jumpmind.symmetric.io.data.DataProcessor)2 IDataReader (org.jumpmind.symmetric.io.data.IDataReader)2 DataReaderStatistics (org.jumpmind.symmetric.io.data.reader.DataReaderStatistics)2 ResolveConflict (org.jumpmind.symmetric.io.data.writer.Conflict.ResolveConflict)2 IgnoreBatchException (org.jumpmind.symmetric.io.data.writer.IgnoreBatchException)2 IStagedResource (org.jumpmind.symmetric.io.stage.IStagedResource)2 Node (org.jumpmind.symmetric.model.Node)2 Test (org.junit.Test)2