use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestReplicationScenarios method createDummyEvent.
private NotificationEvent createDummyEvent(String dbname, String tblname, long evid) {
MessageFactory msgFactory = MessageFactory.getInstance();
Table t = new Table();
t.setDbName(dbname);
t.setTableName(tblname);
NotificationEvent event = new NotificationEvent(evid, (int) System.currentTimeMillis(), MessageFactory.CREATE_TABLE_EVENT, msgFactory.buildCreateTableMessage(t, Arrays.asList("/tmp/").iterator()).toString());
event.setDbName(t.getDbName());
event.setTableName(t.getTableName());
event.setMessageFormat(msgFactory.getMessageFormat());
return event;
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestReplicationScenarios method testEventFilters.
@Test
public void testEventFilters() {
// Test testing that the filters introduced by EventUtils are working correctly.
// The current filters we use in ReplicationSemanticAnalyzer is as follows:
// IMetaStoreClient.NotificationFilter evFilter = EventUtils.andFilter(
// EventUtils.getDbTblNotificationFilter(dbNameOrPattern, tblNameOrPattern),
// EventUtils.getEventBoundaryFilter(eventFrom, eventTo),
// EventUtils.restrictByMessageFormat(MessageFactory.getInstance().getMessageFormat()));
// So, we test each of those three filters, and then test andFilter itself.
String dbname = "testfilter_db";
String tblname = "testfilter_tbl";
// Test EventUtils.getDbTblNotificationFilter - this is supposed to restrict
// events to those that match the dbname and tblname provided to the filter.
// If the tblname passed in to the filter is null, then it restricts itself
// to dbname-matching alone.
IMetaStoreClient.NotificationFilter dbTblFilter = EventUtils.getDbTblNotificationFilter(dbname, tblname);
IMetaStoreClient.NotificationFilter dbFilter = EventUtils.getDbTblNotificationFilter(dbname, null);
assertFalse(dbTblFilter.accept(null));
assertTrue(dbTblFilter.accept(createDummyEvent(dbname, tblname, 0)));
assertFalse(dbTblFilter.accept(createDummyEvent(dbname, tblname + "extra", 0)));
assertFalse(dbTblFilter.accept(createDummyEvent(dbname + "extra", tblname, 0)));
assertFalse(dbFilter.accept(null));
assertTrue(dbFilter.accept(createDummyEvent(dbname, tblname, 0)));
assertTrue(dbFilter.accept(createDummyEvent(dbname, tblname + "extra", 0)));
assertFalse(dbFilter.accept(createDummyEvent(dbname + "extra", tblname, 0)));
// Test EventUtils.getEventBoundaryFilter - this is supposed to only allow events
// within a range specified.
long evBegin = 50;
long evEnd = 75;
IMetaStoreClient.NotificationFilter evRangeFilter = EventUtils.getEventBoundaryFilter(evBegin, evEnd);
assertTrue(evBegin < evEnd);
assertFalse(evRangeFilter.accept(null));
assertFalse(evRangeFilter.accept(createDummyEvent(dbname, tblname, evBegin - 1)));
assertTrue(evRangeFilter.accept(createDummyEvent(dbname, tblname, evBegin)));
assertTrue(evRangeFilter.accept(createDummyEvent(dbname, tblname, evBegin + 1)));
assertTrue(evRangeFilter.accept(createDummyEvent(dbname, tblname, evEnd - 1)));
assertTrue(evRangeFilter.accept(createDummyEvent(dbname, tblname, evEnd)));
assertFalse(evRangeFilter.accept(createDummyEvent(dbname, tblname, evEnd + 1)));
// Test EventUtils.restrictByMessageFormat - this restricts events generated to those
// that match a provided message format
IMetaStoreClient.NotificationFilter restrictByDefaultMessageFormat = EventUtils.restrictByMessageFormat(MessageFactory.getInstance().getMessageFormat());
IMetaStoreClient.NotificationFilter restrictByArbitraryMessageFormat = EventUtils.restrictByMessageFormat(MessageFactory.getInstance().getMessageFormat() + "_bogus");
NotificationEvent dummyEvent = createDummyEvent(dbname, tblname, 0);
assertEquals(MessageFactory.getInstance().getMessageFormat(), dummyEvent.getMessageFormat());
assertFalse(restrictByDefaultMessageFormat.accept(null));
assertTrue(restrictByDefaultMessageFormat.accept(dummyEvent));
assertFalse(restrictByArbitraryMessageFormat.accept(dummyEvent));
// Test andFilter operation.
IMetaStoreClient.NotificationFilter yes = new IMetaStoreClient.NotificationFilter() {
@Override
public boolean accept(NotificationEvent notificationEvent) {
return true;
}
};
IMetaStoreClient.NotificationFilter no = new IMetaStoreClient.NotificationFilter() {
@Override
public boolean accept(NotificationEvent notificationEvent) {
return false;
}
};
assertTrue(EventUtils.andFilter(yes, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(yes, no).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, no).accept(dummyEvent));
assertTrue(EventUtils.andFilter(yes, yes, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(yes, yes, no).accept(dummyEvent));
assertFalse(EventUtils.andFilter(yes, no, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(yes, no, no).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, yes, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, yes, no).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, no, yes).accept(dummyEvent));
assertFalse(EventUtils.andFilter(no, no, no).accept(dummyEvent));
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestEximReplicationTasks method testDropTable.
@Test
public void testDropTable() throws IOException {
Table t = new Table();
t.setDbName("testdb");
t.setTableName("testtable");
NotificationEvent event = new NotificationEvent(getEventId(), getTime(), HCatConstants.HCAT_DROP_TABLE_EVENT, msgFactory.buildDropTableMessage(t).toString());
event.setDbName(t.getDbName());
event.setTableName(t.getTableName());
HCatNotificationEvent hev = new HCatNotificationEvent(event);
ReplicationTask rtask = ReplicationTask.create(client, hev);
assertEquals(hev.toString(), rtask.getEvent().toString());
verifyDropTableReplicationTask(rtask);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestEximReplicationTasks method testAlterPartition.
@Test
public void testAlterPartition() throws HCatException {
Table t = new Table();
t.setDbName("testdb");
t.setTableName("testtable");
List<FieldSchema> pkeys = HCatSchemaUtils.getFieldSchemas(HCatSchemaUtils.getHCatSchema("a:int,b:string").getFields());
t.setPartitionKeys(pkeys);
Partition p = createPtn(t, Arrays.asList("102", "lmn"));
NotificationEvent event = new NotificationEvent(getEventId(), getTime(), HCatConstants.HCAT_ALTER_PARTITION_EVENT, msgFactory.buildAlterPartitionMessage(t, p, p).toString());
event.setDbName(t.getDbName());
event.setTableName(t.getTableName());
HCatNotificationEvent hev = new HCatNotificationEvent(event);
ReplicationTask rtask = ReplicationTask.create(client, hev);
assertEquals(hev.toString(), rtask.getEvent().toString());
verifyAlterPartitionReplicationTask(rtask, t, p);
}
use of org.apache.hadoop.hive.metastore.api.NotificationEvent in project hive by apache.
the class TestEximReplicationTasks method testDropDb.
@Test
public void testDropDb() throws IOException {
Database db = new Database();
db.setName("testdb");
NotificationEvent event = new NotificationEvent(getEventId(), getTime(), HCatConstants.HCAT_DROP_DATABASE_EVENT, msgFactory.buildCreateDatabaseMessage(db).toString());
event.setDbName(db.getName());
HCatNotificationEvent hev = new HCatNotificationEvent(event);
ReplicationTask rtask = ReplicationTask.create(client, hev);
assertEquals(hev.toString(), rtask.getEvent().toString());
verifyDropDbReplicationTask(rtask);
}
Aggregations