Subscription subs = new Subscription("public", "rep_foo",
"public.rep_foo", "attachuser", 1, "srvname",
"SELECT * FROM public.foo", Timestamp
.valueOf("2010-01-01 12:34:56"), "F");
Subscriber suber = null;
try {
suber = SyncDatabaseDAO.getSubscriber(masterConn, 5);
} catch (Exception e) {
fail("exception thrown");
}
Method method = PrivateAccessor.getPrivateMethod(com, "fullRefresh");
// null argument
try {
method.invoke(com, null, replicaConn, suber, subs, true);
fail("no exception");
} catch (InvocationTargetException e) {
actual = e.getTargetException().getMessage();
assertEquals("argument error", actual);
} catch (Exception e) {
fail("exception thrown");
}
try {
method.invoke(com, masterConn, null, suber, subs, true);
fail("no exception");
} catch (InvocationTargetException e) {
actual = e.getTargetException().getMessage();
assertEquals("argument error", actual);
} catch (Exception e) {
fail("exception thrown");
}
try {
method.invoke(com, masterConn, replicaConn, suber, null, true);
fail("no exception");
} catch (InvocationTargetException e) {
actual = e.getTargetException().getMessage();
assertEquals("argument error", actual);
} catch (Exception e) {
fail("exception thrown");
}
Statement stmt = null;
ResultSet rset = null;
try {
stmt = replicaConn.createStatement();
rset = stmt.executeQuery("SELECT relfilenode FROM "
+ "pg_catalog.pg_class WHERE relname = 'rep_foo'");
assertTrue(rset.next());
String beforeFilenode = rset.getString(1);
String result = RefreshCommand.fullRefresh(masterConn, replicaConn,
suber, subs, false);
assertEquals("full refresh (insert:7)", result);
rset.close();
rset = stmt.executeQuery("SELECT relfilenode FROM "
+ "pg_catalog.pg_class WHERE relname = 'rep_foo'");
assertTrue(rset.next());
String afterFilenode = rset.getString(1);
assertFalse(beforeFilenode.equalsIgnoreCase(afterFilenode));
rset.close();
rset = stmt.executeQuery("SELECT * FROM public.rep_foo");
assertTrue(rset.next());
assertEquals(1, rset.getInt(1));
assertEquals("A", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:01"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(2, rset.getInt(1));
assertEquals("B", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:02"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(3, rset.getInt(1));
assertEquals("C", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:03"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(4, rset.getInt(1));
assertEquals("D", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:04"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(5, rset.getInt(1));
assertEquals("E", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:05"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(6, rset.getInt(1));
assertEquals("F", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:06"), rset
.getTimestamp(3));
assertTrue(rset.next());
assertEquals(7, rset.getInt(1));
assertEquals("G", rset.getString(2));
assertEquals(Timestamp.valueOf("2010-01-01 00:00:07"), rset
.getTimestamp(3));
assertFalse(rset.next());
// Subscriber
assertEquals(5, suber.getSubsID());
assertEquals("public.foo", suber.getMasterTableName());
assertEquals("mlog.mlog$", suber.getMlogName().substring(0, 10));
assertEquals(
"resource name:\"postgres2\", DBMS:\"PostgreSQL\", URL:\"jdbc:postgresql://\"",
suber.getDescription());
assertEquals(Timestamp.valueOf("2010-01-01 12:34:56"), suber
.getLastTime());
assertEquals("F", suber.getLastType());
assertEquals(0, suber.getLastMlogID());
assertEquals(7, suber.getLastCount());
// Subscription
assertEquals("public", subs.getSchema());
assertEquals("rep_foo", subs.getTable());
assertEquals(1, subs.getSubsID());