use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class BinaryMetadataUpdatesFlowTest method startListening.
/**
* @param idx Index.
* @param deafClient Deaf client.
* @param observedIds Observed ids.
*/
private void startListening(int idx, boolean deafClient, Set<Integer> observedIds) throws Exception {
clientMode = true;
ContinuousQuery qry = new ContinuousQuery();
qry.setLocalListener(new CQListener(observedIds));
if (deafClient) {
applyDiscoveryHook = true;
discoveryHook = new DiscoveryHook() {
@Override
public void handleDiscoveryMessage(DiscoverySpiCustomMessage msg) {
DiscoveryCustomMessage customMsg = msg == null ? null : (DiscoveryCustomMessage) IgniteUtils.field(msg, "delegate");
if (customMsg instanceof MetadataUpdateProposedMessage) {
if (((MetadataUpdateProposedMessage) customMsg).typeId() == BINARY_TYPE_ID)
GridTestUtils.setFieldValue(customMsg, "typeId", 1);
} else if (customMsg instanceof MetadataUpdateAcceptedMessage) {
if (((MetadataUpdateAcceptedMessage) customMsg).typeId() == BINARY_TYPE_ID)
GridTestUtils.setFieldValue(customMsg, "typeId", 1);
}
}
};
IgniteEx client = startGrid(idx);
client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
} else {
applyDiscoveryHook = false;
IgniteEx client = startGrid(idx);
client.cache(DEFAULT_CACHE_NAME).withKeepBinary().query(qry);
}
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class IgniteCacheContinuousQueryClientReconnectTest method testReconnectClientAndLeftRouter.
/**
* @throws Exception If failed.
*/
public void testReconnectClientAndLeftRouter() throws Exception {
Ignite client = grid(serverCount());
final Ignite srv = clientRouter(client);
final String clnRouterName = srv.name();
assertTrue(client.cluster().localNode().isClient());
final CacheEventListener lsnr = new CacheEventListener();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
IgniteCache<Object, Object> clnCache = client.cache(DEFAULT_CACHE_NAME);
QueryCursor<?> cur = clnCache.query(qry);
int keyCnt = 100;
lsnr.latch = new CountDownLatch(keyCnt);
for (int key = 0; key < keyCnt; key++) clnCache.put(key, key);
assertTrue("Failed to wait for event.", lsnr.latch.await(5, SECONDS));
reconnectClientNode(client, srv, new Runnable() {
@Override
public void run() {
stopGrid(clnRouterName);
}
});
assertFalse("Client connected to the same server node.", clnRouterName.equals(clientRouter(client).name()));
lsnr.latch = new CountDownLatch(keyCnt);
for (int key = 0; key < keyCnt; key++) clnCache.put(key, key);
assertTrue("Failed to wait for event.", lsnr.latch.await(5, SECONDS));
cur.close();
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class IgniteCacheContinuousQueryClientTest method testNodeJoins.
/**
* @throws Exception If failed.
*/
public void testNodeJoins() throws Exception {
startGrids(2);
client = true;
final int CLIENT_ID = 3;
Ignite clientNode = startGrid(CLIENT_ID);
client = false;
final CacheEventListener lsnr = new CacheEventListener();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
QueryCursor<?> cur = clientNode.cache(DEFAULT_CACHE_NAME).query(qry);
for (int i = 0; i < 10; i++) {
log.info("Start iteration: " + i);
lsnr.latch = new CountDownLatch(1);
Ignite joined1 = startGrid(4);
IgniteCache<Object, Object> joinedCache1 = joined1.cache(DEFAULT_CACHE_NAME);
joinedCache1.put(primaryKey(joinedCache1), 1);
assertTrue("Failed to wait for event.", lsnr.latch.await(5, SECONDS));
lsnr.latch = new CountDownLatch(1);
Ignite joined2 = startGrid(5);
IgniteCache<Object, Object> joinedCache2 = joined2.cache(DEFAULT_CACHE_NAME);
joinedCache2.put(primaryKey(joinedCache2), 2);
assertTrue("Failed to wait for event.", lsnr.latch.await(5, SECONDS));
stopGrid(4);
stopGrid(5);
}
cur.close();
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class IgniteCacheContinuousQueryClientTest method testServerNodeLeft.
/**
* @throws Exception If failed.
*/
public void testServerNodeLeft() throws Exception {
startGrids(3);
client = true;
final int CLIENT_ID = 3;
Ignite clnNode = startGrid(CLIENT_ID);
client = false;
IgniteOutClosure<IgniteCache<Integer, Integer>> rndCache = new IgniteOutClosure<IgniteCache<Integer, Integer>>() {
int cnt = 0;
@Override
public IgniteCache<Integer, Integer> apply() {
++cnt;
return grid(CLIENT_ID).cache(DEFAULT_CACHE_NAME);
}
};
final CacheEventListener lsnr = new CacheEventListener();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
QueryCursor<?> cur = clnNode.cache(DEFAULT_CACHE_NAME).query(qry);
boolean first = true;
int keyCnt = 1;
for (int i = 0; i < 10; i++) {
log.info("Start iteration: " + i);
if (first)
first = false;
else {
for (int srv = 0; srv < CLIENT_ID - 1; srv++) startGrid(srv);
}
lsnr.latch = new CountDownLatch(keyCnt);
for (int key = 0; key < keyCnt; key++) rndCache.apply().put(key, key);
assertTrue("Failed to wait for event. Left events: " + lsnr.latch.getCount(), lsnr.latch.await(10, SECONDS));
for (int srv = 0; srv < CLIENT_ID - 1; srv++) stopGrid(srv);
}
tryClose(cur);
}
use of org.apache.ignite.cache.query.ContinuousQuery in project ignite by apache.
the class IgniteCacheContinuousQueryClientTest method testNodeJoinsRestartQuery.
/**
* @throws Exception If failed.
*/
public void testNodeJoinsRestartQuery() throws Exception {
startGrids(2);
client = true;
final int CLIENT_ID = 3;
Ignite clientNode = startGrid(CLIENT_ID);
client = false;
for (int i = 0; i < 10; i++) {
log.info("Start iteration: " + i);
final CacheEventListener lsnr = new CacheEventListener();
ContinuousQuery<Object, Object> qry = new ContinuousQuery<>();
qry.setLocalListener(lsnr);
QueryCursor<?> cur = clientNode.cache(DEFAULT_CACHE_NAME).query(qry);
lsnr.latch = new CountDownLatch(1);
Ignite joined1 = startGrid(4);
IgniteCache<Object, Object> joinedCache1 = joined1.cache(DEFAULT_CACHE_NAME);
joinedCache1.put(primaryKey(joinedCache1), 1);
assertTrue("Failed to wait for event.", lsnr.latch.await(5, SECONDS));
cur.close();
lsnr.latch = new CountDownLatch(1);
Ignite joined2 = startGrid(5);
IgniteCache<Object, Object> joinedCache2 = joined2.cache(DEFAULT_CACHE_NAME);
joinedCache2.put(primaryKey(joinedCache2), 2);
assertFalse("Unexpected event received.", GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return 1 != lsnr.latch.getCount();
}
}, 1000));
stopGrid(4);
stopGrid(5);
}
}
Aggregations