Skip to content

Commit

Permalink
don't expect rows to already exist for a test; create the rows as needed
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed May 13, 2008
1 parent 28a9b06 commit d302d26
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
Expand Up @@ -40,14 +40,6 @@

public class DataLoaderTest extends AbstractDataLoaderTest {

protected static final String INSERT_EXISTING_ID = "1";

protected static final String DELETE_EXISTING_ID = "5";

protected static final String DELETE_NOT_EXISTING_ID = "6";

protected static final String UPDATE_NOT_EXISTING_ID = "7";

public DataLoaderTest() {
}

Expand All @@ -57,17 +49,22 @@ public DataLoaderTest(String db) {

@Test(groups = "continuous")
public void testInsertExisting() throws Exception {
String[] values = { INSERT_EXISTING_ID, "string2", "string not null2", "char2", "char not null2",
String[] values = { getNextId(), "string2", "string not null2", "char2", "char not null2",
"2007-01-02 03:20:10.0", "2007-02-03 04:05:06.0", "0", "47", "67.89" };
massageExpectectedResultsForDialect(values);
testSimple(CsvConstants.INSERT, values, values);

values[1] = "insert fallback to update";
massageExpectectedResultsForDialect(values);
testSimple(CsvConstants.INSERT, values, values);
}

@Test(groups = "continuous")
public void testUpdateNotExisting() throws Exception {
String[] values = { UPDATE_NOT_EXISTING_ID, "it's /a/ string", "it's -not- null",
String id = getNextId();
String[] values = { id, "it's /a/ string", "it's -not- null",
"You're a \"character\"", "Where are you?", "2007-12-31 02:33:45.0", "2007-12-31 23:59:59.0",
"1", "13", "9.95", UPDATE_NOT_EXISTING_ID };
"1", "13", "9.95", id };
String[] expectedValues = (String[]) ArrayUtils.subarray(values, 0, values.length - 1);
massageExpectectedResultsForDialect(expectedValues);
testSimple(CsvConstants.UPDATE, values, expectedValues);
Expand Down Expand Up @@ -133,12 +130,16 @@ public void testStringBackslash() throws Exception {

@Test(groups = "continuous")
public void testDeleteExisting() throws Exception {
testSimple(CsvConstants.DELETE, new String[] { DELETE_EXISTING_ID }, null);
String[] values = { getNextId(), "a row to be deleted", "testDeleteExisting", "char2", "char not null2",
"2007-01-02 03:20:10.0", "2007-02-03 04:05:06.0", "0", "47", "67.89" };
massageExpectectedResultsForDialect(values);
testSimple(CsvConstants.INSERT, values, values);
testSimple(CsvConstants.DELETE, new String[] { getId() }, null);
}

@Test(groups = "continuous")
public void testDeleteNotExisting() throws Exception {
testSimple(CsvConstants.DELETE, new String[] { DELETE_NOT_EXISTING_ID }, null);
testSimple(CsvConstants.DELETE, new String[] { getNextId() }, null);
}

@Test(groups = "continuous")
Expand Down
Expand Up @@ -138,13 +138,16 @@ public void testStatistics() throws Exception {
}

@Test(groups = "continuous")
public void testUpdateCollision() throws Exception {
public void testUpdateCollision() throws Exception {
Level old = setLoggingLevelForTest(Level.OFF);
String[] insertValues = new String[11];
insertValues[0] = getNextId();
insertValues[2] = insertValues[4] = "inserted row for testUpdateCollision";

String[] updateValues = new String[11];
// pick an id we won't hit
updateValues[10] = "699996";
updateValues[0] = "1";
updateValues[2] = updateValues[4] = "required string";
updateValues[0] = getId();
updateValues[10] = getNextId();
updateValues[2] = updateValues[4] = "update will become an insert that violates PK";

ByteArrayOutputStream out = new ByteArrayOutputStream();
CsvWriter writer = getWriter(out);
Expand All @@ -155,7 +158,11 @@ public void testUpdateCollision() throws Exception {

writer.writeRecord(new String[] { CsvConstants.BATCH, nextBatchId });

// Update becomes fallback insert
// 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);

Expand Down
12 changes: 0 additions & 12 deletions symmetric/src/test/resources/test-continuous-setup.sql
Expand Up @@ -24,15 +24,3 @@ values('test_triggers_table','test-root-group','test-root-group','testchannel',
insert into sym_trigger
(source_table_name,source_node_group_id,target_node_group_id,channel_id,sync_on_update,sync_on_insert,sync_on_delete,sync_on_update_condition,sync_on_insert_condition,sync_on_delete_condition,initial_load_select,node_select,tx_id_expression,initial_load_order,last_updated_by,last_updated_time,create_time)
values('sym_node_group','symmetric','test-root-group','config', 1, 1, 1, null, null, null, null, null, null, 1, 'chenson', current_timestamp, current_timestamp);

insert into test_dataloader_table
(string_value, string_required_value, char_value, char_required_value,
date_value, time_value, boolean_value, integer_value, decimal_value)
values ('string', 'string not null', 'char', 'char not null',
{d '2007-02-03'}, {ts '2007-01-02 03:04:05.06'}, '1', 42, 99.99);

insert into test_dataloader_table
(string_value, string_required_value, char_value, char_required_value,
date_value, time_value, boolean_value, integer_value, decimal_value)
values ('string', 'string not null', 'char', 'char not null',
{d '2007-02-03'}, {ts '2007-01-02 03:04:05.06'}, '1', 42, 99.99);

0 comments on commit d302d26

Please sign in to comment.