Search in sources :

Example 1 with MetaStorageManager

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;
}
Also used : Optional(java.util.Optional) MetaStorageManager(org.apache.ignite.internal.metastorage.MetaStorageManager) WatchAggregator(org.apache.ignite.internal.metastorage.watch.WatchAggregator) AggregatedWatch(org.apache.ignite.internal.metastorage.watch.AggregatedWatch)

Aggregations

Optional (java.util.Optional)1 MetaStorageManager (org.apache.ignite.internal.metastorage.MetaStorageManager)1 AggregatedWatch (org.apache.ignite.internal.metastorage.watch.AggregatedWatch)1 WatchAggregator (org.apache.ignite.internal.metastorage.watch.WatchAggregator)1