use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method test07DataIntregrityError.
@Test
public void test07DataIntregrityError() throws Exception {
Level old = setLoggingLevelForTest(Level.OFF);
String[] values = { getNextId(), "string3", "string not null3", "char3", "char not null3", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "0.474" };
ConflictNodeGroupLink conflictSettings = new ConflictNodeGroupLink();
conflictSettings.setNodeGroupLink(TestConstants.TEST_2_ROOT);
conflictSettings.setConflictId("dont_fallback");
conflictSettings.setResolveType(ResolveConflict.MANUAL);
getSymmetricEngine().getDataLoaderService().save(conflictSettings);
ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
writer.writeRecord(new String[] { CsvConstants.NODEID, TestConstants.TEST_CLIENT_EXTERNAL_ID });
writer.writeRecord(new String[] { CsvConstants.CHANNEL, TestConstants.TEST_CHANNEL_ID });
writer.writeRecord(new String[] { CsvConstants.BATCH, getNextBatchId() });
writeTable(writer, TEST_TABLE, TEST_KEYS, TEST_COLUMNS);
writer.write(CsvConstants.INSERT);
writer.writeRecord(values, true);
writer.write(CsvConstants.INSERT);
writer.writeRecord(values, true);
writer.writeRecord(new String[] { CsvConstants.COMMIT, getBatchId() });
writer.close();
load(out);
assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID), IncomingBatch.Status.ER, "Wrong status");
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.ER, "Wrong status");
assertEquals(batch.getFailedRowNumber(), 2l, "Wrong failed row number");
assertEquals(batch.getStatementCount(), 2l, "Wrong statement count");
load(out);
assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID), IncomingBatch.Status.ER, "Wrong status");
batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.ER, "Wrong status");
assertEquals(batch.getFailedRowNumber(), 2l, "Wrong failed row number");
assertEquals(batch.getStatementCount(), 2l, "Wrong statement count");
getSymmetricEngine().getDataLoaderService().delete(conflictSettings);
setLoggingLevelForTest(old);
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method test02Statistics.
@Test
public void test02Statistics() throws Exception {
Level old = setLoggingLevelForTest(Level.FATAL);
String[] updateValues = new String[TEST_COLUMNS.length + 1];
updateValues[0] = updateValues[updateValues.length - 1] = getNextId();
updateValues[2] = updateValues[4] = "required string";
String[] insertValues = (String[]) ArrayUtils.subarray(updateValues, 0, updateValues.length - 1);
ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
writer.writeRecord(new String[] { CsvConstants.NODEID, TestConstants.TEST_CLIENT_EXTERNAL_ID });
writer.writeRecord(new String[] { CsvConstants.CHANNEL, TestConstants.TEST_CHANNEL_ID });
String nextBatchId = getNextBatchId();
writer.writeRecord(new String[] { CsvConstants.BATCH, nextBatchId });
writeTable(writer, TEST_TABLE, TEST_KEYS, TEST_COLUMNS);
// Update becomes fallback insert
writer.write(CsvConstants.UPDATE);
writer.writeRecord(updateValues, true);
// Insert becomes fallback update
writer.write(CsvConstants.INSERT);
writer.writeRecord(insertValues, true);
// Insert becomes fallback update
writer.write(CsvConstants.INSERT);
writer.writeRecord(insertValues, true);
// Clean insert
insertValues[0] = getNextId();
writer.write(CsvConstants.INSERT);
writer.writeRecord(insertValues, true);
// Delete affects no rows
writer.writeRecord(new String[] { CsvConstants.DELETE, getNextId() }, true);
writer.writeRecord(new String[] { CsvConstants.DELETE, getNextId() }, true);
writer.writeRecord(new String[] { CsvConstants.DELETE, getNextId() }, true);
// Failing statement
insertValues[0] = getNextId();
insertValues[5] = "i am an invalid date";
writer.write(CsvConstants.INSERT);
writer.writeRecord(insertValues, true);
writer.writeRecord(new String[] { CsvConstants.COMMIT, nextBatchId });
writer.close();
load(out);
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.ER, "Wrong status. " + printDatabase());
assertEquals(batch.getFailedRowNumber(), 8l, "Wrong failed row number. " + batch.getSqlMessage() + ". " + printDatabase());
assertEquals(batch.getByteCount(), 483l, "Wrong byte count. " + printDatabase());
assertEquals(batch.getStatementCount(), 8l, "Wrong statement count. " + printDatabase());
assertEquals(batch.getFallbackInsertCount(), 1l, "Wrong fallback insert count. " + printDatabase());
assertEquals(batch.getFallbackUpdateCount(), 2l, "Wrong fallback update count. " + printDatabase());
assertEquals(batch.getMissingDeleteCount(), 3l, "Wrong missing delete count. " + printDatabase());
setLoggingLevelForTest(old);
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method test08ErrorWhileParsing.
@Test
public void test08ErrorWhileParsing() throws Exception {
Level old = setLoggingLevelForTest(Level.OFF);
String[] values = { getNextId(), "should not reach database", "string not null", "char", "char not null", "2007-01-02", "2007-02-03 04:05:06.000", "0", "47", "67.89", "0.474" };
ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
writer.writeRecord(new String[] { CsvConstants.NODEID, TestConstants.TEST_CLIENT_EXTERNAL_ID });
writer.writeRecord(new String[] { CsvConstants.CHANNEL, TestConstants.TEST_CHANNEL_ID });
String nextBatchId = getNextBatchId();
writer.write("UnknownTokenOutsideBatch");
writer.writeRecord(new String[] { CsvConstants.BATCH, nextBatchId });
writer.writeRecord(new String[] { CsvConstants.TABLE, TEST_TABLE });
writeTable(writer, TEST_TABLE, TEST_KEYS, TEST_COLUMNS);
writer.write(CsvConstants.INSERT);
writer.writeRecord(values, true);
writer.writeRecord(new String[] { CsvConstants.COMMIT, nextBatchId });
writer.close();
load(out);
assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID), null, "Wrong status");
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNull(batch);
setLoggingLevelForTest(old);
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method findIncomingBatchStatus.
protected IncomingBatch.Status findIncomingBatchStatus(int batchId, String nodeId) {
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, nodeId);
IncomingBatch.Status status = null;
if (batch != null) {
status = batch.getStatus();
}
return status;
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method test09ErrorThenSuccessBatch.
@Test
public void test09ErrorThenSuccessBatch() throws Exception {
Logger.getLogger(AbstractDataLoaderServiceTest.class).warn("testErrorThenSuccessBatch");
Level old = setLoggingLevelForTest(Level.OFF);
String[] values = { getNextId(), "This string is too large and will cause the statement to fail", "string not null2", "char2", "char not null2", "not a date", "2007-02-03 04:05:06.000", "0", "47", "123456789.00", "0.474" };
getNextBatchId();
int retries = 3;
for (int i = 0; i < retries; i++) {
batchId--;
testSimple(CsvConstants.INSERT, values, null);
assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID), IncomingBatch.Status.ER, "Wrong status");
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.ER, "Wrong status. " + printDatabase());
assertEquals(batch.getFailedRowNumber(), 1l, "Wrong failed row number. " + printDatabase());
assertEquals(batch.getStatementCount(), 1l, "Wrong statement count. " + printDatabase());
// pause to make sure we get a different start time on the incoming
// batch batch
Thread.sleep(10);
}
batchId--;
values[1] = "A smaller string that will succeed";
values[5] = "2007-01-02 00:00:00.000";
values[9] = "67.89";
testSimple(CsvConstants.INSERT, values, values);
assertEquals(findIncomingBatchStatus(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID), IncomingBatch.Status.OK, "Wrong status. " + printDatabase());
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.OK, "Wrong status. " + printDatabase());
assertEquals(batch.getFailedRowNumber(), 0l, "Wrong failed row number. " + printDatabase());
assertEquals(batch.getStatementCount(), 1l, "Wrong statement count. " + printDatabase());
setLoggingLevelForTest(old);
}
Aggregations