use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class GridP2PComputeWithNestedEntryProcessorTest method scanByCopositeFirstPredicate.
/**
* @param cache Ignite cache.
* @throws Exception If failed.
*/
private void scanByCopositeFirstPredicate(IgniteCache cache) throws Exception {
IgniteBiPredicate firstFilter = (IgniteBiPredicate) TEST_CLASS_LOADER.loadClass(FIRST_FILTER_NAME).getConstructor().newInstance();
IgniteBiPredicate compositeFilter = (IgniteBiPredicate) TEST_CLASS_LOADER.loadClass(COMPOSITE_FILTER_NAME).getConstructor().newInstance();
U.invoke(TEST_CLASS_LOADER.loadClass(COMPOSITE_FILTER_NAME), compositeFilter, "addPredicate", firstFilter);
List list = cache.query(new ScanQuery().setFilter(compositeFilter)).getAll();
assertEquals(list.size(), ENTRIES / 2);
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class RebalanceAfterResettingLostPartitionTest method testRebalanceAfterPartitionsWereLost.
/**
* Test to restore lost partitions and rebalance data on working grid with two nodes.
*
* @throws Exception if fail.
*/
@SuppressWarnings("unchecked")
@Test
public void testRebalanceAfterPartitionsWereLost() throws Exception {
startGrids(2);
grid(0).cluster().active(true);
for (int j = 0; j < CACHE_SIZE; j++) grid(0).cache(CACHE_NAME).put(j, "Value" + j);
String g1Name = grid(1).name();
// Stopping the the second node.
stopGrid(1);
// Cleaning the persistence for second node.
cleanPersistenceDir(g1Name);
AtomicInteger msgCntr = new AtomicInteger();
TestRecordingCommunicationSpi.spi(ignite(0)).blockMessages(new IgniteBiPredicate<ClusterNode, Message>() {
@Override
public boolean apply(ClusterNode clusterNode, Message msg) {
if (msg instanceof GridDhtPartitionSupplyMessage && ((GridCacheGroupIdMessage) msg).groupId() == CU.cacheId(CACHE_NAME)) {
if (msgCntr.get() > 3)
return true;
else
msgCntr.incrementAndGet();
}
return false;
}
});
// Starting second node again(with the same consistent id).
startGrid(1);
// Waitting for rebalance.
TestRecordingCommunicationSpi.spi(ignite(0)).waitForBlocked();
// Killing the first node at the moment of rebalancing.
stopGrid(0);
// Returning first node to the cluster.
IgniteEx g0 = startGrid(0);
assertTrue(Objects.requireNonNull(grid(0).cachex(CACHE_NAME)).context().topology().localPartitions().stream().allMatch(p -> p.state() == GridDhtPartitionState.LOST));
// Verify that partition loss is detected.
assertTrue(Objects.requireNonNull(grid(1).cachex(CACHE_NAME)).context().topology().localPartitions().stream().allMatch(p -> p.state() == GridDhtPartitionState.LOST));
// Reset lost partitions and wait for PME.
grid(1).resetLostPartitions(Arrays.asList(CACHE_NAME, "ignite-sys-cache"));
awaitPartitionMapExchange();
assertTrue(Objects.requireNonNull(grid(0).cachex(CACHE_NAME)).context().topology().localPartitions().stream().allMatch(p -> p.state() == GridDhtPartitionState.OWNING));
// Verify that partitions are in owning state.
assertTrue(Objects.requireNonNull(grid(1).cachex(CACHE_NAME)).context().topology().localPartitions().stream().allMatch(p -> p.state() == GridDhtPartitionState.OWNING));
// Verify that data was successfully rebalanced.
for (int i = 0; i < CACHE_SIZE; i++) assertEquals("Value" + i, grid(0).cache(CACHE_NAME).get(i));
for (int i = 0; i < CACHE_SIZE; i++) assertEquals("Value" + i, grid(1).cache(CACHE_NAME).get(i));
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class GridCacheQueryTransformerSelfTest method testLocalKeepBinaryFiltered.
/**
* @throws Exception If failed.
*/
@Test
public void testLocalKeepBinaryFiltered() throws Exception {
IgniteCache<Integer, Value> cache = grid().createCache("test-cache");
try {
for (int i = 0; i < 50; i++) cache.put(i, new Value("str" + i, i * 100));
Collection<List<Integer>> lists = grid().compute().broadcast(new IgniteCallable<List<Integer>>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public List<Integer> call() throws Exception {
IgniteBiPredicate<Integer, BinaryObject> filter = new IgniteBiPredicate<Integer, BinaryObject>() {
@Override
public boolean apply(Integer k, BinaryObject v) {
return v.<Integer>field("idx") % 1000 == 0;
}
};
IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer> transformer = new IgniteClosure<Cache.Entry<Integer, BinaryObject>, Integer>() {
@Override
public Integer apply(Cache.Entry<Integer, BinaryObject> e) {
return e.getValue().field("idx");
}
};
return ignite.cache("test-cache").withKeepBinary().query(new ScanQuery<>(filter).setLocal(true), transformer).getAll();
}
});
List<Integer> res = new ArrayList<>(F.flatCollections(lists));
assertEquals(5, res.size());
Collections.sort(res);
for (int i = 0; i < 5; i++) assertEquals(i * 1000, res.get(i).intValue());
} finally {
cache.destroy();
}
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class GridClosureProcessorRemoteTest method testAnonymousUnicastRequest.
/**
* @throws Exception Thrown in case of failure.
*/
@Test
public void testAnonymousUnicastRequest() throws Exception {
Ignite g = grid(0);
assert g.cluster().nodes().size() == NODES_CNT;
execCntr.set(0);
ClusterNode rmt = F.first(g.cluster().forRemotes().nodes());
final ClusterNode loc = g.cluster().localNode();
compute(g.cluster().forNode(rmt)).run(new CARemote() {
@Override
public void apply() {
message(grid(1).cluster().forNode(loc)).localListen(null, new IgniteBiPredicate<UUID, String>() {
@Override
public boolean apply(UUID uuid, String s) {
log.info("Received test message [nodeId: " + uuid + ", s=" + s + ']');
ignite.countDownLatch("messagesPending", 1, false, true).countDown();
execCntr.incrementAndGet();
return false;
}
});
}
});
message(g.cluster().forNode(rmt)).send(null, "TESTING...");
assertTrue(g.countDownLatch("messagesPending", 1, false, true).await(2000));
assertEquals(0, execCntr.get());
}
use of org.apache.ignite.lang.IgniteBiPredicate in project ignite by apache.
the class IgniteClientReconnectApiExceptionTest method igniteOperationsTest.
/**
* @throws Exception If failed.
*/
private void igniteOperationsTest() throws Exception {
final Ignite client = startClientGrid(serverCount());
final IgniteCache<Object, Object> dfltCache = client.cache(DEFAULT_CACHE_NAME);
final CountDownLatch recvLatch = new CountDownLatch(1);
assertNotNull(dfltCache);
doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check compute.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.compute();
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.compute();
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
IgniteCompute comp = (IgniteCompute) o;
Collection<UUID> uuids = comp.broadcast(new IgniteCallable<UUID>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public UUID call() throws Exception {
return ignite.cluster().localNode().id();
}
});
assertFalse(uuids.isEmpty());
for (UUID uuid : uuids) assertNotNull(uuid);
return true;
}
}), // Check ping node.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.cluster().pingNode(new UUID(0, 0));
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.cluster().pingNode(new UUID(0, 0));
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
Boolean pingNode = (Boolean) o;
assertFalse(pingNode);
return true;
}
}), // Check register remote listener.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.events().remoteListen(null, new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
return true;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.events().remoteListen(null, new IgnitePredicate<Event>() {
@Override
public boolean apply(Event event) {
return true;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
UUID remoteId = (UUID) o;
assertNotNull(remoteId);
client.events().stopRemoteListen(remoteId);
return true;
}
}), // Check message operation.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {
@Override
public boolean apply(UUID uuid, Object o) {
if (o.equals("Test message."))
recvLatch.countDown();
return true;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {
@Override
public boolean apply(UUID uuid, Object o) {
if (o.equals("Test message."))
recvLatch.countDown();
return true;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
IgniteMessaging msg = client.message();
msg.send(null, "Test message.");
try {
assertTrue(recvLatch.await(2, SECONDS));
} catch (InterruptedException ignored) {
fail("Message wasn't received.");
}
return true;
}
}), // Check executor.
new T2<Callable, C1<Object, Boolean>>(new Callable() {
@Override
public Object call() throws Exception {
boolean failed = false;
try {
client.executorService().submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 42;
}
});
} catch (IgniteClientDisconnectedException e) {
failed = true;
checkAndWait(e);
}
assertTrue(failed);
return client.executorService().submit(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
return 42;
}
});
}
}, new C1<Object, Boolean>() {
@Override
public Boolean apply(Object o) {
assertNotNull(o);
Future<Integer> fut = (Future<Integer>) o;
try {
assertEquals(42, (int) fut.get());
} catch (Exception ignored) {
fail("Failed submit task.");
}
return true;
}
})));
}
Aggregations