use of org.apache.ignite.internal.metastorage.MetaStorageManager in project ignite-3 by apache.
the class WatchListenerInhibitor method metastorageEventsInhibitor.
/**
* Creates the specific listener which can inhibit events for real metastorage listener.
*
* @param ignite Ignite.
* @return Listener inhibitor.
* @throws Exception If something wrong when creating the listener inhibitor.
*/
public static WatchListenerInhibitor metastorageEventsInhibitor(Ignite ignite) throws Exception {
// TODO: IGNITE-15723 After a component factory will be implemented, need to got rid of reflection here.
MetaStorageManager metaMngr = (MetaStorageManager) ReflectionUtils.tryToReadFieldValue(IgniteImpl.class, "metaStorageMgr", (IgniteImpl) ignite).get();
assertNotNull(metaMngr);
WatchAggregator aggregator = (WatchAggregator) ReflectionUtils.tryToReadFieldValue(MetaStorageManager.class, "watchAggregator", metaMngr).get();
assertNotNull(aggregator);
WatchAggregator aggregatorSpy = Mockito.spy(aggregator);
WatchListenerInhibitor inhibitor = new WatchListenerInhibitor();
doAnswer(mock -> {
Optional<AggregatedWatch> op = (Optional<AggregatedWatch>) mock.callRealMethod();
assertTrue(op.isPresent());
inhibitor.setRealListener(op.get().listener());
return Optional.of(new AggregatedWatch(op.get().keyCriterion(), op.get().revision(), inhibitor));
}).when(aggregatorSpy).watch(anyLong(), any());
IgniteTestUtils.setFieldValue(metaMngr, "watchAggregator", aggregatorSpy);
// Redeploy metastorage watch. The Watch inhibitor will be used after.
metaMngr.unregisterWatch(-1);
return inhibitor;
}
Aggregations