use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class IgniteClientCheckClusterGroupLocalIdAfterReconnect method testClusterGroupLocalIdAfterClientReconnect.
/**
* Test checks that local id in cluster group was change and client
* will be able to send the message to itself after reconnect.
*/
@Test
public void testClusterGroupLocalIdAfterClientReconnect() throws Exception {
Ignite server = startGrid(0);
Ignite client = startClientGrid(1);
UUID clientId = client.cluster().node().id();
ClusterGroup cg1 = client.cluster().forLocal();
assertNotNull("Local client ID is different with local ClusterGroup node id. ", cg1.node(clientId));
// check sending messages is possible while connected
IgniteMessaging messaging = client.message(client.cluster().forLocal());
CountDownLatch topicSignal = new CountDownLatch(2);
messaging.localListen("topic", (IgniteBiPredicate<UUID, Object>) (uuid, n) -> {
topicSignal.countDown();
return true;
});
// countDown latch = 1
messaging.send("topic", new External());
CountDownLatch discSignal = new CountDownLatch(1);
client.events().localListen((IgnitePredicate<DiscoveryEvent>) evt -> {
discSignal.countDown();
return true;
}, EventType.EVT_CLIENT_NODE_DISCONNECTED);
server.close();
assertTrue("client did not disconnect", discSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
startGrid(0);
// wait for client reconnect
IgniteFuture future = client.cluster().clientReconnectFuture();
assertNotNull(future);
// throws if times out
future.get(20_000);
ClusterGroup cg2 = client.cluster().forLocal();
UUID newClientId = client.cluster().localNode().id();
assertNotNull("Local client ID wasn't changed for local ClusterGroup.", cg2.node(newClientId));
awaitPartitionMapExchange();
// check sending messages is possible after reconnecting
// countDown latch = 0
messaging = client.message(client.cluster().forLocal());
messaging.send("topic", new External());
assertTrue("Message wasn't received", topicSignal.await(LATCH_TIMEOUT, TimeUnit.SECONDS));
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class TxPartitionCounterStateAbstractTest method createBackupMessagePredicate.
/**
* @param wrappedBackupSpi Wrapped backup spi.
* @param futMap Future map.
* @param cb Callback.
*/
private IgniteBiPredicate<ClusterNode, Message> createBackupMessagePredicate(TestRecordingCommunicationSpi wrappedBackupSpi, Map<IgniteUuid, GridCacheVersion> futMap, TxCallback cb) {
return (node, msg) -> {
if (msg instanceof GridDhtTxPrepareResponse) {
IgniteEx from = fromNode(wrappedBackupSpi);
IgniteEx to = IgnitionEx.gridxx(node.id());
GridDhtTxPrepareResponse resp = (GridDhtTxPrepareResponse) msg;
GridCacheVersion ver = futMap.get(resp.futureId());
if (ver == null)
// Message from parallel partition.
return false;
IgniteInternalTx backupTx = findTx(from, ver, false);
return cb.afterBackupPrepare(to, from, backupTx, ver.asIgniteUuid(), createSendFuture(wrappedBackupSpi, msg));
} else if (msg instanceof GridDhtTxFinishResponse) {
IgniteEx from = fromNode(wrappedBackupSpi);
IgniteEx to = IgnitionEx.gridxx(node.id());
GridDhtTxFinishResponse resp = (GridDhtTxFinishResponse) msg;
GridCacheVersion ver = futMap.get(resp.futureId());
if (ver == null)
// Message from parallel partition.
return false;
// Version is null if message is a response to checkCommittedRequest.
return cb.afterBackupFinish(to, from, ver.asIgniteUuid(), createSendFuture(wrappedBackupSpi, msg));
}
return false;
};
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class TxRollbackOnIncorrectParamsTest method testRollbackInsideLocalListenerAfterRemoteFilter.
/**
*/
@Test
public void testRollbackInsideLocalListenerAfterRemoteFilter() throws Exception {
Ignite ignite = startGrid(0);
Ignite remote = startGrid(1);
IgniteCache cacheLocal = ignite.getOrCreateCache(defaultCacheConfiguration());
IgniteCache cacheRemote = remote.getOrCreateCache(defaultCacheConfiguration());
AtomicBoolean rollbackFailed = new AtomicBoolean();
AtomicBoolean alreadyRolledBack = new AtomicBoolean();
ignite.events().remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, e) -> {
assert e instanceof TransactionStateChangedEvent;
TransactionStateChangedEvent evt = (TransactionStateChangedEvent) e;
Transaction tx = evt.tx();
try {
tx.setRollbackOnly();
} catch (IgniteException ignored) {
alreadyRolledBack.set(rollbackFailed.getAndSet(true));
}
return true;
}, (IgnitePredicate<Event>) e -> {
assert e instanceof TransactionStateChangedEvent;
return true;
}, EVT_TX_STARTED);
assertFalse(rollbackFailed.get());
assertFalse(alreadyRolledBack.get());
try (Transaction tx = ignite.transactions().txStart()) {
cacheLocal.put(1, 1);
tx.commit();
fail("Should fail prior this line.");
} catch (CacheException ex) {
if (MvccFeatureChecker.forcedMvcc())
assertTrue(ex.toString(), ex.getCause() instanceof TransactionAlreadyCompletedException);
else
assertTrue(ex.toString(), ex.getCause() instanceof TransactionRollbackException);
}
assertFalse(rollbackFailed.get());
assertFalse(alreadyRolledBack.get());
try (Transaction tx = remote.transactions().txStart()) {
cacheRemote.put(1, 2);
tx.commit();
}
assertTrue(GridTestUtils.waitForCondition(rollbackFailed::get, 5_000));
assertFalse(alreadyRolledBack.get());
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class CacheLateAffinityAssignmentTest method testNoForceKeysRequests.
/**
* @throws Exception If failed.
*/
@Test
public void testNoForceKeysRequests() throws Exception {
cacheC = new IgniteClosure<String, CacheConfiguration[]>() {
@Override
public CacheConfiguration[] apply(String s) {
return null;
}
};
final AtomicBoolean fail = new AtomicBoolean();
spiC = new IgniteClosure<String, TestRecordingCommunicationSpi>() {
@Override
public TestRecordingCommunicationSpi apply(String s) {
TestRecordingCommunicationSpi spi = new TestRecordingCommunicationSpi();
spi.blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode node, Message msg) {
if (msg instanceof GridDhtForceKeysRequest || msg instanceof GridDhtForceKeysResponse) {
fail.set(true);
U.dumpStack(log, "Unexpected message: " + msg);
}
return false;
}
});
return spi;
}
};
final int SRVS = 3;
for (int i = 0; i < SRVS; i++) startGrid(i);
startClientGrid(SRVS);
final List<CacheConfiguration> ccfgs = new ArrayList<>();
ccfgs.add(cacheConfiguration("tc1", TRANSACTIONAL, 0));
ccfgs.add(cacheConfiguration("tc2", TRANSACTIONAL, 1));
ccfgs.add(cacheConfiguration("tc3", TRANSACTIONAL, 2));
for (CacheConfiguration ccfg : ccfgs) ignite(0).createCache(ccfg);
final int NODES = SRVS + 1;
final AtomicInteger nodeIdx = new AtomicInteger();
final long stopTime = System.currentTimeMillis() + 60_000;
IgniteInternalFuture<?> updateFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int idx = nodeIdx.getAndIncrement();
Ignite node = grid(idx);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
while (!fail.get() && System.currentTimeMillis() < stopTime) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
return null;
}
}, NODES, "update-thread");
IgniteInternalFuture<?> srvRestartFut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
while (!fail.get() && System.currentTimeMillis() < stopTime) {
Ignite node = startGrid(NODES);
List<IgniteCache<Object, Object>> caches = new ArrayList<>();
for (CacheConfiguration ccfg : ccfgs) caches.add(node.cache(ccfg.getName()));
for (int i = 0; i < 2; i++) {
for (IgniteCache<Object, Object> cache : caches) cacheOperations(cache);
}
U.sleep(500);
stopGrid(NODES);
U.sleep(500);
}
return null;
}
}, "srv-restart");
srvRestartFut.get();
updateFut.get();
assertFalse("Unexpected messages.", fail.get());
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class GridP2PContinuousDeploymentClientDisconnectTest method testMessageRemoteListen.
/**
* Test starts 1 server node and 1 client node. Class-loading request for the {@link #P2P_TEST_OBJ_RSRC_NAME}
* resource blocks on the client node. The client node tries to deploy remote message listener for
* the cache {@link #DEFAULT_CACHE_NAME}.
* Expected that exception with 'Failed to unmarshal deployable object.' error message will be thrown and
* the server node wouldn't be failed.
*
* @throws Exception If failed.
*/
@Test
public void testMessageRemoteListen() throws Exception {
Class<IgniteBiPredicate<UUID, String>> rmtLsnrCls = (Class<IgniteBiPredicate<UUID, String>>) getExternalClassLoader().loadClass(MSG_REMOTE_LSNR_CLS_NAME);
LogListener lsnr = LogListener.matches("Failed to unmarshal deployable object.").build();
testLog.registerListener(lsnr);
assertThrowsWithCause(() -> grid(1).message().remoteListen("test", rmtLsnrCls.newInstance()), IgniteException.class);
assertTrue(lsnr.check());
// Check that the failure handler was not called.
assertFalse(failure.get());
}
Aggregations