use of org.apache.ignite.events.CacheQueryReadEvent in project ignite by apache.
the class PlatformContextImpl method writeEvent.
/**
* {@inheritDoc}
*/
@Override
public void writeEvent(BinaryRawWriterEx writer, Event evt) {
assert writer != null;
if (evt == null) {
writer.writeInt(-1);
return;
}
EventAdapter evt0 = (EventAdapter) evt;
if (evt0 instanceof CacheEvent) {
writer.writeInt(2);
writeCommonEventData(writer, evt0);
CacheEvent event0 = (CacheEvent) evt0;
writer.writeString(event0.cacheName());
writer.writeInt(event0.partition());
writer.writeBoolean(event0.isNear());
writeNode(writer, event0.eventNode());
writer.writeObject(event0.key());
writer.writeObject(event0.xid());
writer.writeObject(event0.newValue());
writer.writeObject(event0.oldValue());
writer.writeBoolean(event0.hasOldValue());
writer.writeBoolean(event0.hasNewValue());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.closureClassName());
writer.writeString(event0.taskName());
} else if (evt0 instanceof CacheQueryExecutedEvent) {
writer.writeInt(3);
writeCommonEventData(writer, evt0);
CacheQueryExecutedEvent event0 = (CacheQueryExecutedEvent) evt0;
writer.writeString(event0.queryType());
writer.writeString(event0.cacheName());
writer.writeString(event0.className());
writer.writeString(event0.clause());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.taskName());
} else if (evt0 instanceof CacheQueryReadEvent) {
writer.writeInt(4);
writeCommonEventData(writer, evt0);
CacheQueryReadEvent event0 = (CacheQueryReadEvent) evt0;
writer.writeString(event0.queryType());
writer.writeString(event0.cacheName());
writer.writeString(event0.className());
writer.writeString(event0.clause());
writer.writeUuid(event0.subjectId());
writer.writeString(event0.taskName());
writer.writeObject(event0.key());
writer.writeObject(event0.value());
writer.writeObject(event0.oldValue());
writer.writeObject(event0.row());
} else if (evt0 instanceof CacheRebalancingEvent) {
writer.writeInt(5);
writeCommonEventData(writer, evt0);
CacheRebalancingEvent event0 = (CacheRebalancingEvent) evt0;
writer.writeString(event0.cacheName());
writer.writeInt(event0.partition());
writeNode(writer, event0.discoveryNode());
writer.writeInt(event0.discoveryEventType());
writer.writeString(event0.discoveryEventName());
writer.writeLong(event0.discoveryTimestamp());
} else if (evt0 instanceof CheckpointEvent) {
writer.writeInt(6);
writeCommonEventData(writer, evt0);
CheckpointEvent event0 = (CheckpointEvent) evt0;
writer.writeString(event0.key());
} else if (evt0 instanceof DiscoveryEvent) {
writer.writeInt(7);
writeCommonEventData(writer, evt0);
DiscoveryEvent event0 = (DiscoveryEvent) evt0;
writeNode(writer, event0.eventNode());
writer.writeLong(event0.topologyVersion());
writeNodes(writer, event0.topologyNodes());
} else if (evt0 instanceof JobEvent) {
writer.writeInt(8);
writeCommonEventData(writer, evt0);
JobEvent event0 = (JobEvent) evt0;
writer.writeString(event0.taskName());
writer.writeString(event0.taskClassName());
writer.writeObject(event0.taskSessionId());
writer.writeObject(event0.jobId());
writeNode(writer, event0.taskNode());
writer.writeUuid(event0.taskSubjectId());
} else if (evt0 instanceof TaskEvent) {
writer.writeInt(10);
writeCommonEventData(writer, evt0);
TaskEvent event0 = (TaskEvent) evt0;
writer.writeString(event0.taskName());
writer.writeString(event0.taskClassName());
writer.writeObject(event0.taskSessionId());
writer.writeBoolean(event0.internal());
writer.writeUuid(event0.subjectId());
} else
throw new IgniteException("Unsupported event: " + evt);
}
use of org.apache.ignite.events.CacheQueryReadEvent in project ignite by apache.
the class IgniteCacheAbstractQuerySelfTest method testTextQueryEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testTextQueryEvents() throws Exception {
final Map<UUID, Person> map = new ConcurrentHashMap<>();
final IgniteCache<UUID, Person> cache = jcache(UUID.class, Person.class);
final boolean evtsDisabled = cache.getConfiguration(CacheConfiguration.class).isEventsDisabled();
final CountDownLatch latch = new CountDownLatch(evtsDisabled ? 0 : 2);
final CountDownLatch execLatch = new CountDownLatch(evtsDisabled ? 0 : cacheMode() == REPLICATED ? 1 : gridCount());
IgnitePredicate[] objReadLsnrs = new IgnitePredicate[gridCount()];
IgnitePredicate[] qryExecLsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> objReadPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryReadEvent;
if (evtsDisabled)
fail("Cache events are disabled");
CacheQueryReadEvent<UUID, Person> qe = (CacheQueryReadEvent<UUID, Person>) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
map.put(qe.key(), qe.value());
latch.countDown();
return true;
}
};
grid(i).events().localListen(objReadPred, EVT_CACHE_QUERY_OBJECT_READ);
objReadLsnrs[i] = objReadPred;
IgnitePredicate<Event> qryExecPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
if (evtsDisabled)
fail("Cache events are disabled");
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(FULL_TEXT.name(), qe.queryType());
assertEquals(cache.getName(), qe.cacheName());
assertEquals("Person", qe.className());
assertEquals("White", qe.clause());
assertNull(qe.scanQueryFilter());
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
execLatch.countDown();
return true;
}
};
grid(i).events().localListen(qryExecPred, EVT_CACHE_QUERY_EXECUTED);
qryExecLsnrs[i] = qryExecPred;
}
try {
UUID k1 = UUID.randomUUID();
UUID k2 = UUID.randomUUID();
UUID k3 = UUID.randomUUID();
cache.put(k1, new Person("Bob White", 1000));
cache.put(k2, new Person("Tom White", 1000));
cache.put(k3, new Person("Mike Green", 1000));
QueryCursor<Cache.Entry<UUID, Person>> q = cache.query(new TextQuery<UUID, Person>(Person.class, "White"));
q.getAll();
assert latch.await(1000, MILLISECONDS);
assert execLatch.await(1000, MILLISECONDS);
if (!evtsDisabled) {
assertEquals(2, map.size());
assertEquals("Bob White", map.get(k1).name());
assertEquals("Tom White", map.get(k2).name());
}
} finally {
for (int i = 0; i < gridCount(); i++) {
grid(i).events().stopLocalListen(objReadLsnrs[i]);
grid(i).events().stopLocalListen(qryExecLsnrs[i]);
}
}
}
use of org.apache.ignite.events.CacheQueryReadEvent in project ignite by apache.
the class IgniteCacheConfigVariationsQueryTest method registerEventListeners.
/**
* Registers event listeners.
* @param expMap Expected read events count.
* @param filterExp Scan query uses filter.
*/
private void registerEventListeners(Map<Object, Object> expMap, final boolean filterExp) {
this.expMap = expMap != null ? expMap : Collections.emptyMap();
Set<ClusterNode> affNodes = new HashSet<>();
if (cacheMode() != REPLICATED) {
Affinity<Object> aff = testedGrid().affinity(cacheName());
for (Object key : this.expMap.keySet()) affNodes.add(aff.mapKeyToNode(key));
}
int execEvtCnt = cacheMode() == REPLICATED || (cacheMode() == PARTITIONED && affNodes.isEmpty()) ? 1 : affNodes.size();
evtMap = new ConcurrentHashMap<>();
readEvtLatch = new CountDownLatch(this.expMap.size());
execEvtLatch = new CountDownLatch(execEvtCnt);
objReadLsnrs = new IgnitePredicate[gridCount()];
qryExecLsnrs = new IgnitePredicate[gridCount()];
for (int i = 0; i < gridCount(); i++) {
IgnitePredicate<Event> pred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assertTrue("Event: " + evt, evt instanceof CacheQueryReadEvent);
CacheQueryReadEvent<Object, Object> qe = (CacheQueryReadEvent<Object, Object>) evt;
assertEquals(SCAN.name(), qe.queryType());
assertEquals(cacheName(), qe.cacheName());
assertNull(qe.className());
assertNull(qe.clause());
assertEquals(filterExp, qe.scanQueryFilter() != null);
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
evtMap.put(qe.key(), qe.value());
assertFalse(readEvtLatch.getCount() == 0);
readEvtLatch.countDown();
return true;
}
};
grid(i).events().localListen(pred, EVT_CACHE_QUERY_OBJECT_READ);
objReadLsnrs[i] = pred;
IgnitePredicate<Event> execPred = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assertTrue("Event: " + evt, evt instanceof CacheQueryExecutedEvent);
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(SCAN.name(), qe.queryType());
assertEquals(cacheName(), qe.cacheName());
assertNull(qe.className());
assertNull(qe.clause());
assertEquals(filterExp, qe.scanQueryFilter() != null);
assertNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
assertFalse("Too many events.", execEvtLatch.getCount() == 0);
execEvtLatch.countDown();
return true;
}
};
grid(i).events().localListen(execPred, EVT_CACHE_QUERY_EXECUTED);
qryExecLsnrs[i] = execPred;
}
}
use of org.apache.ignite.events.CacheQueryReadEvent in project ignite by apache.
the class GridCacheContinuousQueryAbstractSelfTest method testEvents.
/**
* @throws Exception If failed.
*/
@Test
public void testEvents() throws Exception {
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(50);
final CountDownLatch execLatch = new CountDownLatch(cacheMode() == REPLICATED ? 1 : gridCount());
IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryReadEvent;
CacheQueryReadEvent qe = (CacheQueryReadEvent) evt;
assertEquals(CONTINUOUS.name(), qe.queryType());
assertEquals(DEFAULT_CACHE_NAME, qe.cacheName());
assertEquals(grid(0).localNode().id(), qe.subjectId());
assertNull(qe.className());
assertNull(qe.clause());
assertNull(qe.scanQueryFilter());
assertNotNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
cnt.incrementAndGet();
latch.countDown();
return true;
}
};
IgnitePredicate<Event> execLsnr = new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
assert evt instanceof CacheQueryExecutedEvent;
CacheQueryExecutedEvent qe = (CacheQueryExecutedEvent) evt;
assertEquals(CONTINUOUS.name(), qe.queryType());
assertEquals(DEFAULT_CACHE_NAME, qe.cacheName());
assertEquals(grid(0).localNode().id(), qe.subjectId());
assertNull(qe.className());
assertNull(qe.clause());
assertNull(qe.scanQueryFilter());
assertNotNull(qe.continuousQueryFilter());
assertNull(qe.arguments());
execLatch.countDown();
return true;
}
};
try {
for (int i = 0; i < gridCount(); i++) {
grid(i).events().localListen(lsnr, EVT_CACHE_QUERY_OBJECT_READ);
grid(i).events().localListen(execLsnr, EVT_CACHE_QUERY_EXECUTED);
}
IgniteCache<Integer, Integer> cache = grid(0).cache(DEFAULT_CACHE_NAME);
ContinuousQuery<Integer, Integer> qry = new ContinuousQuery<>();
qry.setLocalListener(new CacheEntryUpdatedListener<Integer, Integer>() {
@Override
public void onUpdated(Iterable<CacheEntryEvent<? extends Integer, ? extends Integer>> evts) {
// No-op.
}
});
qry.setRemoteFilter(new CacheEntryEventSerializableFilter<Integer, Integer>() {
@Override
public boolean evaluate(CacheEntryEvent<? extends Integer, ? extends Integer> evt) {
return evt.getValue() >= 50;
}
});
try (QueryCursor<Cache.Entry<Integer, Integer>> ignored = cache.query(qry)) {
for (int i = 0; i < 100; i++) cachePut(cache, i, i);
assert latch.await(LATCH_TIMEOUT, MILLISECONDS);
assert execLatch.await(LATCH_TIMEOUT, MILLISECONDS);
assertEquals(50, cnt.get());
}
} finally {
for (int i = 0; i < gridCount(); i++) {
grid(i).events().stopLocalListen(lsnr, EVT_CACHE_QUERY_OBJECT_READ);
grid(i).events().stopLocalListen(execLsnr, EVT_CACHE_QUERY_EXECUTED);
}
}
}
use of org.apache.ignite.events.CacheQueryReadEvent in project ignite by apache.
the class AbstractEventSecurityContextTest method checkEvents.
/**
* Checks that all expected events listened on the specified node contain security subject id that belongs to user
* with specified login.
*/
protected void checkEvents(ClusterNode node, Collection<Integer> expEvtTypes, String expLogin) throws Exception {
assertTrue(waitForCondition(() -> {
Collection<Event> evts = LISTENED_EVTS.get(node);
if (evts == null)
return false;
return evts.stream().map(Event::type).collect(Collectors.toList()).containsAll(expEvtTypes);
}, getTestTimeout()));
assertTrue(LISTENED_EVTS.get(node).stream().map(evt -> {
if (evt instanceof CacheEvent)
return ((CacheEvent) evt).subjectId();
else if (evt instanceof CacheQueryExecutedEvent)
return ((CacheQueryExecutedEvent<?, ?>) evt).subjectId();
else if (evt instanceof CacheQueryReadEvent)
return ((CacheQueryReadEvent<?, ?>) evt).subjectId();
else if (evt instanceof TaskEvent)
return ((TaskEvent) evt).subjectId();
else if (evt instanceof JobEvent)
return ((JobEvent) evt).taskSubjectId();
else
throw new IgniteException();
}).map(subjId -> {
try {
return ((IgniteEx) grid(node)).context().security().authenticatedSubject(subjId).login();
} catch (IgniteCheckedException e) {
throw new IgniteException(e);
}
}).allMatch(expLogin::equals));
}
Aggregations