use of org.apache.hive.hcatalog.api.repl.Command in project hive by apache.
the class TestCommands method testDropPartitionCommand.
@Test
public void testDropPartitionCommand() throws HCatException, CommandNeedRetryException, MetaException {
String dbName = "cmd_testdb";
String tableName = "cmd_testtable";
int evid = 789;
List<HCatFieldSchema> pcols = HCatSchemaUtils.getHCatSchema("b:string").getFields();
List<HCatFieldSchema> cols = HCatSchemaUtils.getHCatSchema("a:int").getFields();
Map<String, String> ptnDesc = new HashMap<String, String>();
ptnDesc.put("b", "test");
Command testReplicatedDropPtnCmd = new DropPartitionCommand(dbName, tableName, ptnDesc, true, evid);
assertEquals(evid, testReplicatedDropPtnCmd.getEventId());
assertEquals(1, testReplicatedDropPtnCmd.get().size());
assertEquals(true, testReplicatedDropPtnCmd.isRetriable());
assertEquals(false, testReplicatedDropPtnCmd.isUndoable());
CommandTestUtils.testCommandSerialization(testReplicatedDropPtnCmd);
Command testNormalDropPtnCmd = new DropPartitionCommand(dbName, tableName, ptnDesc, false, evid);
assertEquals(evid, testNormalDropPtnCmd.getEventId());
assertEquals(1, testNormalDropPtnCmd.get().size());
assertEquals(true, testNormalDropPtnCmd.isRetriable());
assertEquals(false, testNormalDropPtnCmd.isUndoable());
CommandTestUtils.testCommandSerialization(testNormalDropPtnCmd);
client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE);
client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build());
Map<String, String> props = new HashMap<String, String>();
props.put(ReplicationUtils.REPL_STATE_ID, String.valueOf(evid + 5));
HCatTable table = (new HCatTable(dbName, tableName)).tblProps(props).cols(cols).partCols(pcols);
client.createTable(HCatCreateTableDesc.create(table).build());
HCatTable tableCreated = client.getTable(dbName, tableName);
assertNotNull(tableCreated);
HCatPartition ptnToAdd = (new HCatPartition(tableCreated, ptnDesc, TestHCatClient.makePartLocation(tableCreated, ptnDesc))).parameters(props);
client.addPartition(HCatAddPartitionDesc.create(ptnToAdd).build());
HCatPartition p1 = client.getPartition(dbName, tableName, ptnDesc);
assertNotNull(p1);
// Test replicated drop, should not drop, because evid < repl.state.id
LOG.info("About to run :" + testReplicatedDropPtnCmd.get().get(0));
driver.run(testReplicatedDropPtnCmd.get().get(0));
HCatPartition p2 = client.getPartition(dbName, tableName, ptnDesc);
assertNotNull(p2);
// Test normal drop, should drop unconditionally.
LOG.info("About to run :" + testNormalDropPtnCmd.get().get(0));
driver.run(testNormalDropPtnCmd.get().get(0));
Exception onfe = null;
try {
HCatPartition p_del = client.getPartition(dbName, tableName, ptnDesc);
} catch (Exception e) {
onfe = e;
}
assertNotNull(onfe);
assertTrue(onfe instanceof ObjectNotFoundException);
Map<String, String> props2 = new HashMap<String, String>();
props2.put(ReplicationUtils.REPL_STATE_ID, String.valueOf(evid - 5));
HCatPartition ptnToAdd2 = (new HCatPartition(tableCreated, ptnDesc, TestHCatClient.makePartLocation(tableCreated, ptnDesc))).parameters(props2);
client.addPartition(HCatAddPartitionDesc.create(ptnToAdd2).build());
HCatPartition p3 = client.getPartition(dbName, tableName, ptnDesc);
assertNotNull(p3);
// Test replicated drop, should drop this time, since repl.state.id < evid.
LOG.info("About to run :" + testReplicatedDropPtnCmd.get().get(0));
driver.run(testReplicatedDropPtnCmd.get().get(0));
Exception onfe2 = null;
try {
HCatPartition p_del = client.getPartition(dbName, tableName, ptnDesc);
} catch (Exception e) {
onfe2 = e;
}
assertNotNull(onfe2);
assertTrue(onfe2 instanceof ObjectNotFoundException);
}
use of org.apache.hive.hcatalog.api.repl.Command in project hive by apache.
the class TestNoopCommand method testCommand.
@Test
public static void testCommand() {
int evid = 999;
Command testCmd = new NoopCommand(evid);
assertEquals(evid, testCmd.getEventId());
assertEquals(0, testCmd.get().size());
assertEquals(true, testCmd.isRetriable());
assertEquals(true, testCmd.isUndoable());
assertEquals(0, testCmd.getUndo().size());
CommandTestUtils.testCommandSerialization(testCmd);
}
use of org.apache.hive.hcatalog.api.repl.Command in project hive by apache.
the class TestEximReplicationTasks method verifyCreateDbReplicationTask.
private static void verifyCreateDbReplicationTask(ReplicationTask rtask) {
assertEquals(CreateDatabaseReplicationTask.class, rtask.getClass());
assertTrue("CreateDatabaseReplicationTask should be a noop", rtask instanceof NoopReplicationTask);
assertEquals(false, rtask.needsStagingDirs());
assertEquals(true, rtask.isActionable());
for (Command c : rtask.getSrcWhCommands()) {
assertEquals(NoopCommand.class, c.getClass());
}
for (Command c : rtask.getDstWhCommands()) {
assertEquals(NoopCommand.class, c.getClass());
}
}
use of org.apache.hive.hcatalog.api.repl.Command in project hive by apache.
the class TestEximReplicationTasks method verifyDropPartitionReplicationTask.
private static void verifyDropPartitionReplicationTask(ReplicationTask rtask, Table table, Partition ptn) {
assertEquals(DropPartitionReplicationTask.class, rtask.getClass());
assertEquals(false, rtask.needsStagingDirs());
assertEquals(true, rtask.isActionable());
rtask.withDbNameMapping(debugMapping).withTableNameMapping(debugMapping);
assertEquals(true, rtask.isActionable());
for (Command c : rtask.getSrcWhCommands()) {
assertEquals(NoopCommand.class, c.getClass());
}
List<? extends Command> dstCommands = Lists.newArrayList(rtask.getDstWhCommands());
assertEquals(1, dstCommands.size());
assertEquals(DropPartitionCommand.class, dstCommands.get(0).getClass());
DropPartitionCommand dropPartitionCommand = new DropPartitionCommand(debugMapping.apply(rtask.getEvent().getDbName()), debugMapping.apply(rtask.getEvent().getTableName()), getPtnDesc(table, ptn), true, rtask.getEvent().getEventId());
CommandTestUtils.compareCommands(dropPartitionCommand, dstCommands.get(0), true);
}
use of org.apache.hive.hcatalog.api.repl.Command in project hive by apache.
the class TestCommands method testDropTableCommand2.
@Test
public void testDropTableCommand2() throws HCatException, CommandNeedRetryException, MetaException {
// Secondary DropTableCommand test for testing repl-drop-tables' effect on partitions inside a partitioned table
// when there exist partitions inside the table which are older than the drop event.
// Our goal is this : Create a table t, with repl.last.id=157, say.
// Create 2 partitions inside it, with repl.last.id=150 and 160, say.
// Now, process a drop table command with eventid=155.
// It should result in the table and the partition with repl.last.id=160 continuing to exist,
// but dropping the partition with repl.last.id=150.
String dbName = "cmd_testdb";
String tableName = "cmd_testtable";
int evid = 157;
List<HCatFieldSchema> pcols = HCatSchemaUtils.getHCatSchema("b:string").getFields();
List<HCatFieldSchema> cols = HCatSchemaUtils.getHCatSchema("a:int").getFields();
Command testReplicatedDropCmd = new DropTableCommand(dbName, tableName, true, evid);
client.dropDatabase(dbName, true, HCatClient.DropDBMode.CASCADE);
client.createDatabase(HCatCreateDBDesc.create(dbName).ifNotExists(false).build());
Map<String, String> tprops = new HashMap<String, String>();
tprops.put(ReplicationUtils.REPL_STATE_ID, String.valueOf(evid + 2));
HCatTable table = (new HCatTable(dbName, tableName)).tblProps(tprops).cols(cols).partCols(pcols);
client.createTable(HCatCreateTableDesc.create(table).build());
HCatTable tableCreated = client.getTable(dbName, tableName);
assertNotNull(tableCreated);
Map<String, String> ptnDesc1 = new HashMap<String, String>();
ptnDesc1.put("b", "test-older");
Map<String, String> props1 = new HashMap<String, String>();
props1.put(ReplicationUtils.REPL_STATE_ID, String.valueOf(evid - 5));
HCatPartition ptnToAdd1 = (new HCatPartition(tableCreated, ptnDesc1, TestHCatClient.makePartLocation(tableCreated, ptnDesc1))).parameters(props1);
client.addPartition(HCatAddPartitionDesc.create(ptnToAdd1).build());
Map<String, String> ptnDesc2 = new HashMap<String, String>();
ptnDesc2.put("b", "test-newer");
Map<String, String> props2 = new HashMap<String, String>();
props2.put(ReplicationUtils.REPL_STATE_ID, String.valueOf(evid + 5));
HCatPartition ptnToAdd2 = (new HCatPartition(tableCreated, ptnDesc2, TestHCatClient.makePartLocation(tableCreated, ptnDesc2))).parameters(props2);
client.addPartition(HCatAddPartitionDesc.create(ptnToAdd2).build());
HCatPartition p1 = client.getPartition(dbName, tableName, ptnDesc1);
assertNotNull(p1);
HCatPartition p2 = client.getPartition(dbName, tableName, ptnDesc2);
assertNotNull(p2);
LOG.info("About to run :" + testReplicatedDropCmd.get().get(0));
driver.run(testReplicatedDropCmd.get().get(0));
HCatTable t_stillExists = client.getTable(dbName, tableName);
assertNotNull(t_stillExists);
HCatPartition p2_stillExists = client.getPartition(dbName, tableName, ptnDesc2);
Exception onfe = null;
try {
HCatPartition p1_del = client.getPartition(dbName, tableName, ptnDesc1);
} catch (Exception e) {
onfe = e;
}
assertNotNull(onfe);
assertTrue(onfe instanceof ObjectNotFoundException);
}
Aggregations