Skip to content

Commit

Permalink
0001249: Add REST API methods to allow a "Pull Only" client
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Jun 12, 2013
1 parent af50b14 commit d78f114
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 9 deletions.
Expand Up @@ -113,16 +113,12 @@ public void write(CsvData data) {
sql = data.getParsedData(CsvData.ROW_DATA)[0];
break;
case CREATE:
// TODO: figure out what to do with these
// TODO: we should be able to generate the ddl for this event
break;
default:
break;
}

// TODO: change the ? to the actual data
// platform.replaceSql(dml.getSql(), BinaryEncoding.NONE, currentTable,
// data.getParsedData(CsvData.ROW_DATA),
// true);
if (sql != null) {
this.payloadMap.get(this.currentBatch).add(sql);
}
Expand All @@ -135,6 +131,7 @@ protected String makeDynamic(String sql, String[] values, Column[] columns) {
for (int i = 0; i < columns.length; i++) {
row.put(columns[i].getName(), objects[i]);
}

return platform.replaceSql(sql, binaryEncoding, currentTable, row, false);
}

Expand Down
6 changes: 3 additions & 3 deletions symmetric-jdbc/src/test/resources/db-test.properties
Expand Up @@ -19,9 +19,9 @@
# under the License.
#

test.server=sqlite
test.root=sqlite
test.client=sqlite
test.server=h2
test.root=h2
test.client=h2

mysql.db.driver=com.mysql.jdbc.Driver
mysql.db.user=root
Expand Down
Expand Up @@ -15,6 +15,7 @@
import org.jumpmind.symmetric.web.rest.RestService;
import org.jumpmind.symmetric.web.rest.model.PullDataResults;
import org.jumpmind.symmetric.web.rest.model.RegistrationInfo;
import org.jumpmind.util.FormatUtils;
import org.junit.Assert;

public class RestServiceTest extends AbstractTest {
Expand All @@ -24,6 +25,7 @@ protected Table[] getTables(String name) {
Table a = new Table("a");
a.addColumn(new Column("id", true, Types.INTEGER, -1, -1));
a.addColumn(new Column("notes", false, Types.VARCHAR, 255, -1));
a.addColumn(new Column("created", false, Types.TIMESTAMP, -1, -1));
return new Table[] { a };
}

Expand Down Expand Up @@ -83,17 +85,40 @@ protected void test(ISymmetricEngine rootServer, ISymmetricEngine clientServer)
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(0, results.getNbrBatches());

engine.getSqlTemplate().update("insert into a values(?, ?)", 1, "this is a test");
engine.getSqlTemplate().update("insert into a values(?, ?, ?)", 1, "this is a test", FormatUtils.parseDate("2013-06-08 00:00:00.000", FormatUtils.TIMESTAMP_PATTERNS));

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword());
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(1, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());

log.info(results.getBatches().get(0).getSqlStatements().get(0));

// pull a second time without acking. should get the same results
results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword());
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(1, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());

engine.getSqlTemplate().update("update a set notes=? where id=?", "changed", 1);
engine.getSqlTemplate().update("update a set notes=? where id=?", "changed again", 1);

engine.route();

results = restService.pullData("server", registrationInfo.getNodeId(),
registrationInfo.getNodePassword());
Assert.assertNotNull("Should have a non null results object", results);
Assert.assertEquals(2, results.getNbrBatches());
Assert.assertEquals(3, results.getBatches().get(0).getBatchId());
Assert.assertEquals(4, results.getBatches().get(1).getBatchId());
Assert.assertEquals(2, results.getBatches().get(1).getSqlStatements().size());

log.info(results.getBatches().get(1).getSqlStatements().get(0));
log.info(results.getBatches().get(1).getSqlStatements().get(1));
}

}

0 comments on commit d78f114

Please sign in to comment.