Search in sources :

Example 21 with IncomingBatch

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);
}
Also used : CsvWriter(org.jumpmind.symmetric.csv.CsvWriter) ConflictNodeGroupLink(org.jumpmind.symmetric.service.impl.DataLoaderService.ConflictNodeGroupLink) Level(org.apache.log4j.Level) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Test(org.junit.Test)

Example 22 with IncomingBatch

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);
}
Also used : CsvWriter(org.jumpmind.symmetric.csv.CsvWriter) Level(org.apache.log4j.Level) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Test(org.junit.Test)

Example 23 with IncomingBatch

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);
}
Also used : CsvWriter(org.jumpmind.symmetric.csv.CsvWriter) Level(org.apache.log4j.Level) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Test(org.junit.Test)

Example 24 with IncomingBatch

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;
}
Also used : IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch)

Example 25 with IncomingBatch

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);
}
Also used : Level(org.apache.log4j.Level) IncomingBatch(org.jumpmind.symmetric.model.IncomingBatch) Test(org.junit.Test)

Aggregations

IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)26 Test (org.junit.Test)9 IOException (java.io.IOException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 Level (org.apache.log4j.Level)7 CsvWriter (org.jumpmind.symmetric.csv.CsvWriter)7 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)7 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)7 IoException (org.jumpmind.exception.IoException)6 Node (org.jumpmind.symmetric.model.Node)6 NodeSecurity (org.jumpmind.symmetric.model.NodeSecurity)4 MalformedURLException (java.net.MalformedURLException)3 SymmetricException (org.jumpmind.symmetric.SymmetricException)3 ArrayList (java.util.ArrayList)2 UniqueKeyException (org.jumpmind.db.sql.UniqueKeyException)2 FileConflictException (org.jumpmind.symmetric.file.FileConflictException)2 TransformPoint (org.jumpmind.symmetric.io.data.transform.TransformPoint)2 RegistrationRequiredException (org.jumpmind.symmetric.service.RegistrationRequiredException)2 IIncomingTransport (org.jumpmind.symmetric.transport.IIncomingTransport)2 InternalIncomingTransport (org.jumpmind.symmetric.transport.internal.InternalIncomingTransport)2