use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractDataLoaderServiceTest method test03UpdateCollision.
@Test
public void test03UpdateCollision() throws Exception {
Level old = setLoggingLevelForTest(Level.OFF);
String[] insertValues = new String[TEST_COLUMNS.length];
insertValues[0] = getNextId();
insertValues[2] = insertValues[4] = "inserted row for testUpdateCollision";
String[] updateValues = new String[TEST_COLUMNS.length + 1];
updateValues[0] = getId();
updateValues[TEST_COLUMNS.length] = getNextId();
updateValues[2] = updateValues[4] = "update will become an insert that violates PK";
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);
// This insert will be OK
writer.write(CsvConstants.INSERT);
writer.writeRecord(insertValues, true);
// Update becomes fallback insert, and then violate the primary key
writer.write(CsvConstants.UPDATE);
writer.writeRecord(updateValues, true);
writer.writeRecord(new String[] { CsvConstants.COMMIT, nextBatchId });
writer.close();
load(out);
IncomingBatch batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
load(out);
assertEquals(batch.getStatus(), IncomingBatch.Status.OK, "Wrong status");
batch = getIncomingBatchService().findIncomingBatch(batchId, TestConstants.TEST_CLIENT_EXTERNAL_ID);
assertNotNull(batch);
assertEquals(batch.getStatus(), IncomingBatch.Status.OK, "Wrong status");
setLoggingLevelForTest(old);
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class AbstractTest method loadConfigAtRegistrationServer.
/**
* Loads configuration in the format of classname.csv at the registration
* server
*/
protected void loadConfigAtRegistrationServer() throws Exception {
ISymmetricEngine regEngine = getRegServer().getEngine();
IDataLoaderService dataLoaderService = regEngine.getDataLoaderService();
boolean inError = false;
String fileName = getClass().getSimpleName() + ".csv";
log.info("Loading " + fileName + " on " + regEngine.getEngineName());
InputStream is = getClass().getResourceAsStream(fileName);
assertNotNull("Could not find configuration as a resource", is);
List<IncomingBatch> batches = dataLoaderService.loadDataBatch(IOUtils.toString(is));
for (IncomingBatch batch : batches) {
if (batch.getStatus() == Status.ER) {
inError = true;
}
}
assertFalse("Failed to load configuration", inError);
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class MonitorTypeBatchError method check.
@Override
public long check(Monitor monitor) {
int outgoingErrorCount = 0;
OutgoingBatches outgoingBatches = outgoingBatchService.getOutgoingBatchErrors(1000);
for (OutgoingBatch batch : outgoingBatches.getBatches()) {
int batchErrorMinutes = (int) (System.currentTimeMillis() - batch.getCreateTime().getTime()) / 60000;
if (batchErrorMinutes >= monitor.getThreshold()) {
outgoingErrorCount++;
}
}
int incomingErrorCount = 0;
List<IncomingBatch> incomingBatches = incomingBatchService.findIncomingBatchErrors(1000);
for (IncomingBatch batch : incomingBatches) {
int batchErrorMinutes = (int) (System.currentTimeMillis() - batch.getCreateTime().getTime()) / 60000;
if (batchErrorMinutes >= monitor.getThreshold()) {
incomingErrorCount++;
}
}
return outgoingErrorCount + incomingErrorCount;
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class DataLoaderService method logDataReceivedFromPush.
private void logDataReceivedFromPush(Node sourceNode, List<IncomingBatch> batchList) {
int okBatchesCount = 0;
int errorBatchesCount = 0;
int okDataCount = 0;
for (IncomingBatch incomingBatch : batchList) {
if (incomingBatch.getStatus() == Status.OK) {
okBatchesCount++;
okDataCount += incomingBatch.getStatementCount();
} else if (incomingBatch.getStatus() == Status.ER) {
errorBatchesCount++;
}
}
if (okBatchesCount > 0) {
if (errorBatchesCount > 0) {
log.info("{} data and {} batches loaded during push request from {}. There were {} batches in error", new Object[] { okDataCount, okBatchesCount, sourceNode.toString(), errorBatchesCount });
} else {
log.info("{} data and {} batches loaded during push request from {}.", new Object[] { okDataCount, okBatchesCount, sourceNode.toString() });
}
}
}
use of org.jumpmind.symmetric.model.IncomingBatch in project symmetric-ds by JumpMind.
the class DataLoaderService method loadDataBatch.
public List<IncomingBatch> loadDataBatch(String batchData) {
String nodeId = nodeService.findIdentityNodeId();
if (StringUtils.isNotBlank(nodeId)) {
ProcessInfo processInfo = statisticManager.newProcessInfo(new ProcessInfoKey(nodeId, nodeId, ProcessInfoKey.ProcessType.MANUAL_LOAD));
try {
InternalIncomingTransport transport = new InternalIncomingTransport(new BufferedReader(new StringReader(batchData)));
List<IncomingBatch> list = loadDataFromTransport(processInfo, nodeService.findIdentity(), transport, null);
processInfo.setStatus(ProcessInfo.Status.OK);
return list;
} catch (IOException ex) {
processInfo.setStatus(ProcessInfo.Status.ERROR);
throw new IoException();
} catch (RuntimeException ex) {
processInfo.setStatus(ProcessInfo.Status.ERROR);
throw ex;
}
} else {
return new ArrayList<IncomingBatch>(0);
}
}
Aggregations