use of org.apache.ignite.internal.metastorage.watch.WatchAggregator 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;
}
use of org.apache.ignite.internal.metastorage.watch.WatchAggregator in project ignite-3 by apache.
the class WatchAggregatorTest method testOneCriterionInference.
@Test
public void testOneCriterionInference() {
var watchAggregator = new WatchAggregator();
watchAggregator.add(new ByteArray("key"), null);
var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
assertEquals(new KeyCriterion.ExactCriterion(new ByteArray("key")), keyCriterion);
}
use of org.apache.ignite.internal.metastorage.watch.WatchAggregator in project ignite-3 by apache.
the class WatchAggregatorTest method testCancel.
@Test
public void testCancel() {
var watchAggregator = new WatchAggregator();
var lsnr1 = mock(WatchListener.class);
when(lsnr1.onUpdate(any())).thenReturn(true);
var lsnr2 = mock(WatchListener.class);
when(lsnr2.onUpdate(any())).thenReturn(true);
final var id1 = watchAggregator.add(new ByteArray("1"), lsnr1);
var id2 = watchAggregator.add(new ByteArray("2"), lsnr2);
var entryEvt1 = new EntryEvent(entry("1", "value1", 1, 1), entry("1", "value1n", 1, 1));
var entryEvt2 = new EntryEvent(entry("2", "value2", 1, 1), entry("2", "value2n", 1, 1));
watchAggregator.watch(1, (v1, v2) -> {
}).get().listener().onUpdate(new WatchEvent(List.of(entryEvt1, entryEvt2)));
verify(lsnr1, times(1)).onUpdate(any());
verify(lsnr2, times(1)).onUpdate(any());
watchAggregator.cancel(id1);
watchAggregator.watch(1, (v1, v2) -> {
}).get().listener().onUpdate(new WatchEvent(List.of(entryEvt1, entryEvt2)));
verify(lsnr1, times(1)).onUpdate(any());
verify(lsnr2, times(2)).onUpdate(any());
}
use of org.apache.ignite.internal.metastorage.watch.WatchAggregator in project ignite-3 by apache.
the class WatchAggregatorTest method testNullKeyAsEndOfRangeCriterion.
@Test
public void testNullKeyAsEndOfRangeCriterion() {
var watchAggregator = new WatchAggregator();
watchAggregator.add(new ByteArray("key3"), null);
watchAggregator.add(new ByteArray("key1"), null, null);
var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
var expKeyCriterion = new KeyCriterion.RangeCriterion(new ByteArray("key1"), null);
assertEquals(expKeyCriterion, keyCriterion);
}
use of org.apache.ignite.internal.metastorage.watch.WatchAggregator in project ignite-3 by apache.
the class WatchAggregatorTest method testExactInTheMiddleAndRangeCriteriaOnTheEdgesUnion.
@Test
public void testExactInTheMiddleAndRangeCriteriaOnTheEdgesUnion() {
var watchAggregator = new WatchAggregator();
watchAggregator.add(new ByteArray("key1"), null);
watchAggregator.add(new ByteArray("key0"), new ByteArray("key2"), null);
var keyCriterion = watchAggregator.watch(0, null).get().keyCriterion();
var expKeyCriterion = new KeyCriterion.RangeCriterion(new ByteArray("key0"), new ByteArray("key2"));
assertEquals(expKeyCriterion, keyCriterion);
}
Aggregations