Hive hive = Hive.load(getConnectString(getHiveDatabaseName()), CachingDataSourceProvider.getInstance());
String primaryKey = new String("Asia");
Integer secondaryKey = new Integer(7);
Pair<Node, Node> nodes = initializeTestData(hive, primaryKey, secondaryKey);
Node origin = nodes.getKey();
Node destination = nodes.getValue();
NodeResolver dir = new DbDirectory(hive.getPartitionDimension(), getDataSource(getConnectString(getHiveDatabaseName())));
PartitionKeyMover<String> pMover = new PrimaryMover(origin.getUri());
// This mover just craps out on delete
Mover<Integer> failingMover = new Mover<Integer>() {
public void copy(Integer item, Node node) {
SimpleJdbcDaoSupport dao = new SimpleJdbcDaoSupport();
dao.setDataSource(CachingDataSourceProvider.getInstance().getDataSource(node.getUri()));
dao.getJdbcTemplate().update("insert into secondary_table values (?)", new Object[]{item});
}
public void delete(Integer item, Node node) {
throw new RuntimeException("Ach!");
}
public Integer get(Object id, Node node) {
SimpleJdbcDaoSupport dao = new SimpleJdbcDaoSupport();
dao.setDataSource(CachingDataSourceProvider.getInstance().getDataSource(node.getUri()));
return dao.getJdbcTemplate().queryForInt("select id from secondary_table where id = ?", new Object[]{id});
}
};
Migrator m = new HiveMigrator(hive);
pMover.getDependentMovers().clear();
pMover.getDependentMovers().add(new Pair<Mover, KeyLocator>(failingMover, new SecondaryKeyLocator(origin.getUri())));
try {
m.migrate(primaryKey, Arrays.asList(new String[]{destination.getName()}), pMover);
} catch (Exception e) {
//Quash
}
//Directory still points destination
assertNotNull(Filter.grepItemAgainstList(destination.getId(), Transform.map(DirectoryWrapper.semaphoreToId(), dir.getKeySemamphoresOfPrimaryIndexKey(primaryKey))));
//Records exist ondestination
assertEquals(primaryKey, pMover.get(primaryKey, destination));
assertEquals(secondaryKey, new SecondaryMover().get(secondaryKey, destination));
}