@Test public void testCalculateIndexInclusion_RepoBasedInclusion() { IndexRecordFilterData indexFilterData = mock(IndexRecordFilterData.class); IndexInfo inclusionA = createMockIndexInfo("inclusionA", true); IndexInfo exclusion = createMockIndexInfo("excludeA", false); IndexInfo inclusionB = createMockIndexInfo("inclusionB", true); ArrayList<IndexInfo> infos = Lists.newArrayList(inclusionA, exclusion, inclusionB); for (IndexInfo info : infos) { when(info.getRepositoryName()).thenReturn("someOtherRepo"); } when(this.indexesInfo.getIndexInfos()).thenReturn(infos); indexFilterHook.calculateIndexInclusion("someOtherRepo", Table.RECORD.name, oldRecord, newRecord, indexFilterData); verify(indexFilterData).setSubscriptionInclusions(ImmutableSet.of("inclusionA","inclusionB")); }
void calculateIndexInclusion(String repositoryName, String table, Record oldRecord, Record newRecord, IndexRecordFilterData indexFilterData) { Set<String> applicableIndexes = Sets.newHashSet(); Set<String> nonApplicableIndexes = Sets.newHashSet(); for (IndexInfo indexInfo : indexesInfo.getIndexInfos()) { String queueSubscriptionId = indexInfo.getIndexDefinition().getSubscriptionId(); if (indexMatchesRepository(repositoryName, indexInfo) && indexIsApplicable(indexInfo.getLilyIndexerConf().getRecordFilter(), table, oldRecord, newRecord)) { applicableIndexes.add(queueSubscriptionId); } else { nonApplicableIndexes.add(queueSubscriptionId); } } if (applicableIndexes.isEmpty()) { indexFilterData.setSubscriptionExclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (nonApplicableIndexes.isEmpty()) { indexFilterData.setSubscriptionInclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (applicableIndexes.size() > nonApplicableIndexes.size()) { indexFilterData.setSubscriptionInclusions(applicableIndexes); } else { indexFilterData.setSubscriptionExclusions(nonApplicableIndexes); } }
IndexRecordFilterHook implements RecordUpdateHook { void calculateIndexInclusion(String repositoryName, String table, Record oldRecord, Record newRecord, IndexRecordFilterData indexFilterData) { Set<String> applicableIndexes = Sets.newHashSet(); Set<String> nonApplicableIndexes = Sets.newHashSet(); for (IndexInfo indexInfo : indexesInfo.getIndexInfos()) { String queueSubscriptionId = indexInfo.getIndexDefinition().getSubscriptionId(); if (indexMatchesRepository(repositoryName, indexInfo) && indexIsApplicable(indexInfo.getLilyIndexerConf().getRecordFilter(), table, oldRecord, newRecord)) { applicableIndexes.add(queueSubscriptionId); } else { nonApplicableIndexes.add(queueSubscriptionId); } } if (applicableIndexes.isEmpty()) { indexFilterData.setSubscriptionExclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (nonApplicableIndexes.isEmpty()) { indexFilterData.setSubscriptionInclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (applicableIndexes.size() > nonApplicableIndexes.size()) { indexFilterData.setSubscriptionInclusions(applicableIndexes); } else { indexFilterData.setSubscriptionExclusions(nonApplicableIndexes); } } }
IndexRecordFilterHook implements RecordUpdateHook { void calculateIndexInclusion(String repositoryName, String table, Record oldRecord, Record newRecord, IndexRecordFilterData indexFilterData) { Set<String> applicableIndexes = Sets.newHashSet(); Set<String> nonApplicableIndexes = Sets.newHashSet(); for (IndexInfo indexInfo : indexesInfo.getIndexInfos()) { String queueSubscriptionId = indexInfo.getIndexDefinition().getSubscriptionId(); if (indexMatchesRepository(repositoryName, indexInfo) && indexIsApplicable(indexInfo.getLilyIndexerConf().getRecordFilter(), table, oldRecord, newRecord)) { applicableIndexes.add(queueSubscriptionId); } else { nonApplicableIndexes.add(queueSubscriptionId); } } if (applicableIndexes.isEmpty()) { indexFilterData.setSubscriptionExclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (nonApplicableIndexes.isEmpty()) { indexFilterData.setSubscriptionInclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (applicableIndexes.size() > nonApplicableIndexes.size()) { indexFilterData.setSubscriptionInclusions(applicableIndexes); } else { indexFilterData.setSubscriptionExclusions(nonApplicableIndexes); } } IndexRecordFilterHook(IndexesInfo indexesInfo);  IndexRecordFilterHook(PluginRegistry pluginRegistry, IndexesInfo indexesInfo); }
IndexRecordFilterHook implements RecordUpdateHook { void calculateIndexInclusion(String repositoryName, String table, Record oldRecord, Record newRecord, IndexRecordFilterData indexFilterData) { Set<String> applicableIndexes = Sets.newHashSet(); Set<String> nonApplicableIndexes = Sets.newHashSet(); for (IndexInfo indexInfo : indexesInfo.getIndexInfos()) { String queueSubscriptionId = indexInfo.getIndexDefinition().getSubscriptionId(); if (indexMatchesRepository(repositoryName, indexInfo) && indexIsApplicable(indexInfo.getLilyIndexerConf().getRecordFilter(), table, oldRecord, newRecord)) { applicableIndexes.add(queueSubscriptionId); } else { nonApplicableIndexes.add(queueSubscriptionId); } } if (applicableIndexes.isEmpty()) { indexFilterData.setSubscriptionExclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (nonApplicableIndexes.isEmpty()) { indexFilterData.setSubscriptionInclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (applicableIndexes.size() > nonApplicableIndexes.size()) { indexFilterData.setSubscriptionInclusions(applicableIndexes); } else { indexFilterData.setSubscriptionExclusions(nonApplicableIndexes); } } IndexRecordFilterHook(IndexesInfo indexesInfo);  IndexRecordFilterHook(PluginRegistry pluginRegistry, IndexesInfo indexesInfo); @PreDestroy void destroy(); @Override void beforeUpdate(Record record, Record originalRecord, Repository repository, FieldTypes fieldTypes,
            RecordEvent recordEvent); @Override void beforeCreate(Record newRecord, Repository repository, FieldTypes fieldTypes, RecordEvent recordEvent); @Override void beforeDelete(Record originalRecord, Repository repository, FieldTypes fieldTypes,
            RecordEvent recordEvent); }
IndexRecordFilterHook implements RecordUpdateHook { void calculateIndexInclusion(String repositoryName, String table, Record oldRecord, Record newRecord, IndexRecordFilterData indexFilterData) { Set<String> applicableIndexes = Sets.newHashSet(); Set<String> nonApplicableIndexes = Sets.newHashSet(); for (IndexInfo indexInfo : indexesInfo.getIndexInfos()) { String queueSubscriptionId = indexInfo.getIndexDefinition().getSubscriptionId(); if (indexMatchesRepository(repositoryName, indexInfo) && indexIsApplicable(indexInfo.getLilyIndexerConf().getRecordFilter(), table, oldRecord, newRecord)) { applicableIndexes.add(queueSubscriptionId); } else { nonApplicableIndexes.add(queueSubscriptionId); } } if (applicableIndexes.isEmpty()) { indexFilterData.setSubscriptionExclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (nonApplicableIndexes.isEmpty()) { indexFilterData.setSubscriptionInclusions(IndexRecordFilterData.ALL_INDEX_SUBSCRIPTIONS); } else if (applicableIndexes.size() > nonApplicableIndexes.size()) { indexFilterData.setSubscriptionInclusions(applicableIndexes); } else { indexFilterData.setSubscriptionExclusions(nonApplicableIndexes); } } IndexRecordFilterHook(IndexesInfo indexesInfo);  IndexRecordFilterHook(PluginRegistry pluginRegistry, IndexesInfo indexesInfo); @PreDestroy void destroy(); @Override void beforeUpdate(Record record, Record originalRecord, Repository repository, FieldTypes fieldTypes,
            RecordEvent recordEvent); @Override void beforeCreate(Record newRecord, Repository repository, FieldTypes fieldTypes, RecordEvent recordEvent); @Override void beforeDelete(Record originalRecord, Repository repository, FieldTypes fieldTypes,
            RecordEvent recordEvent);  }