use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class ProtocolDataReaderTest method testSimpleRead.
@Test
public void testSimpleRead() {
String nodeId = "055";
long batchId = 123;
String channelId = "nbc";
StringBuilder builder = beginCsv(nodeId);
beginBatch(builder, batchId, channelId);
putTableN(builder, 1, true);
putInsert(builder, 4);
endCsv(builder);
ProtocolDataReader reader = new ProtocolDataReader(BatchType.LOAD, "test", builder);
DataContext ctx = new DataContext(reader);
reader.open(ctx);
Batch batch = reader.nextBatch();
assertNotNull(batch);
assertEquals(batchId, batch.getBatchId());
Table table = reader.nextTable();
assertNotNull(table);
assertEquals("test1", table.getName());
assertEquals(2, table.getColumnCount());
assertEquals(1, table.getPrimaryKeyColumns().length);
assertEquals("id", table.getColumn(0).getName());
assertEquals("text", table.getColumn(1).getName());
CsvData data = reader.nextData();
assertNotNull(data);
assertEquals(DataEventType.INSERT, data.getDataEventType());
assertEquals("0", data.getParsedData(CsvData.ROW_DATA)[0]);
assertEquals("test", data.getParsedData(CsvData.ROW_DATA)[1]);
data = reader.nextData();
assertNotNull(data);
assertEquals(DataEventType.INSERT, data.getDataEventType());
assertEquals("1", data.getParsedData(CsvData.ROW_DATA)[0]);
assertEquals("test", data.getParsedData(CsvData.ROW_DATA)[1]);
data = reader.nextData();
assertNotNull(data);
assertEquals(DataEventType.INSERT, data.getDataEventType());
assertEquals("2", data.getParsedData(CsvData.ROW_DATA)[0]);
assertEquals("test", data.getParsedData(CsvData.ROW_DATA)[1]);
data = reader.nextData();
assertNotNull(data);
assertEquals(DataEventType.INSERT, data.getDataEventType());
assertEquals("3", data.getParsedData(CsvData.ROW_DATA)[0]);
assertEquals("test", data.getParsedData(CsvData.ROW_DATA)[1]);
data = reader.nextData();
assertNull(data);
table = reader.nextTable();
assertNull(table);
batch = reader.nextBatch();
assertNull(batch);
reader.close();
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class XmlDataReaderTest method testNilDataElement.
@Test
public void testNilDataElement() {
XmlDataReader reader = new XmlDataReader(getClass().getResourceAsStream("xmldatareadertest1.xml"));
TestableDataWriter writer = new TestableDataWriter();
DataProcessor processor = new DataProcessor(reader, writer, "test");
processor.process();
List<CsvData> dataRead = writer.getDatas();
assertEquals(4, dataRead.size());
Map<String, String> data1 = dataRead.get(1).toColumnNameValuePairs(writer.getLastTableRead().getColumnNames(), CsvData.ROW_DATA);
assertEquals("1", data1.get("id"));
assertEquals("A", data1.get("my_value"));
Map<String, String> data2 = dataRead.get(2).toColumnNameValuePairs(writer.getLastTableRead().getColumnNames(), CsvData.ROW_DATA);
assertEquals("2", data2.get("id"));
assertEquals(null, data2.get("my_value"));
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testStringQuotes.
@Test
public void testStringQuotes() throws Exception {
String[] values = new String[TEST_COLUMNS.length];
values[0] = getNextId();
values[1] = "It's \"quoted,\" with a comma";
values[2] = "two 'ticks'";
values[3] = "One quote\"";
values[4] = "One comma,";
writeData(new CsvData(DataEventType.INSERT, values), values);
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testBenchmark.
@Test
public void testBenchmark() throws Exception {
Table table = buildSourceTable(TEST_TABLE, TEST_KEYS, TEST_COLUMNS);
int startId = Integer.parseInt(getId()) + 1;
List<CsvData> datas = new ArrayList<CsvData>();
for (int i = 0; i < 1600; i++) {
String[] values = { getNextId(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), "2007-01-02 03:20:10.0", "2007-02-03 04:05:06.0", "0", "47", "67.89", "-0.0747663" };
datas.add(new CsvData(DataEventType.INSERT, values));
}
for (int i = startId; i < 1600 + startId; i++) {
String[] values = { Integer.toString(i) };
datas.add(new CsvData(DataEventType.DELETE, values, null));
}
long startTime = System.currentTimeMillis();
long statementCount = writeData(new TableCsvData(table, datas));
double totalSeconds = (System.currentTimeMillis() - startTime) / 1000.0;
double targetTime = 15.0;
if (platform instanceof InformixDatabasePlatform) {
targetTime = 20.0;
}
Assert.assertEquals(3200, statementCount);
// TODO: this used to run in 1 second; can we do some optimization?
Assert.assertTrue("DataLoader running in " + totalSeconds + " is too slow", totalSeconds <= targetTime);
}
use of org.jumpmind.symmetric.io.data.CsvData in project symmetric-ds by JumpMind.
the class DatabaseWriterTest method testStringOneSpace.
@Test
public void testStringOneSpace() throws Exception {
String[] values = new String[TEST_COLUMNS.length];
values[0] = getNextId();
values[2] = values[4] = " ";
writeData(new CsvData(DataEventType.INSERT, values), values);
}
Aggregations