use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class TaskCommandHandlerSelfTest method testManyTasksRun.
/**
* @throws Exception If failed.
*/
public void testManyTasksRun() throws Exception {
GridClientCompute compute = client.compute();
for (int i = 0; i < 1000; i++) assertEquals(new Integer("executing".length()), compute.execute(TestTask.class.getName(), "executing"));
GridClientFactory.stop(client.id(), true);
IgniteKernal g = (IgniteKernal) grid(0);
Map<GridRestCommand, GridRestCommandHandler> handlers = U.field(g.context().rest(), "handlers");
GridTaskCommandHandler taskHnd = (GridTaskCommandHandler) F.find(handlers.values(), null, new P1<GridRestCommandHandler>() {
@Override
public boolean apply(GridRestCommandHandler e) {
return e instanceof GridTaskCommandHandler;
}
});
assertNotNull("GridTaskCommandHandler was not found", taskHnd);
ConcurrentLinkedHashMap taskDesc = U.field(taskHnd, "taskDescs");
assertTrue("Task result map size exceeded max value [mapSize=" + taskDesc.sizex() + ", " + "maxSize=" + MAX_TASK_RESULTS + ']', taskDesc.sizex() <= MAX_TASK_RESULTS);
}
use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class GridEventConsumeSelfTest method testApi.
/**
* @throws Exception If failed.
*/
public void testApi() throws Exception {
try {
grid(0).events().stopRemoteListen(null);
} catch (NullPointerException ignored) {
// No-op.
}
grid(0).events().stopRemoteListen(UUID.randomUUID());
UUID consumeId = null;
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
}, EVTS_DISCOVERY);
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, DiscoveryEvent>() {
@Override
public boolean apply(UUID uuid, DiscoveryEvent evt) {
return false;
}
}, new P1<DiscoveryEvent>() {
@Override
public boolean apply(DiscoveryEvent e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
try {
consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {
@Override
public boolean apply(UUID uuid, Event evt) {
return false;
}
}, new P1<Event>() {
@Override
public boolean apply(Event e) {
return false;
}
});
assertNotNull(consumeId);
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class GridCachePartitionedExplicitLockNodeFailureSelfTest method testLockFromNearOrBackup.
/** @throws Exception If check failed. */
@SuppressWarnings("ErrorNotRethrown")
public void testLockFromNearOrBackup() throws Exception {
startGrids(GRID_CNT);
int idx = 0;
info("Grid will be stopped: " + idx);
Integer key = 0;
while (grid(idx).affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key).id().equals(grid(0).localNode().id())) key++;
ClusterNode node = grid(idx).affinity(DEFAULT_CACHE_NAME).mapKeyToNode(key);
info("Primary node for key [id=" + node.id() + ", order=" + node.order() + ", key=" + key + ']');
IgniteCache<Integer, String> cache = jcache(idx);
cache.put(key, "val");
Lock lock = cache.lock(key);
assert lock.tryLock();
for (int checkIdx = 1; checkIdx < GRID_CNT; checkIdx++) {
info("Check grid index: " + checkIdx);
IgniteCache<Integer, String> checkCache = jcache(checkIdx);
assert !checkCache.lock(key).tryLock();
}
Collection<IgniteFuture<?>> futs = new LinkedList<>();
for (int i = 1; i < GRID_CNT; i++) {
futs.add(waitForLocalEvent(grid(i).events(), new P1<Event>() {
@Override
public boolean apply(Event e) {
info("Received grid event: " + e);
return true;
}
}, EVT_NODE_LEFT));
}
stopGrid(idx);
for (IgniteFuture<?> fut : futs) fut.get();
for (int i = 0; i < 3; i++) {
try {
for (int checkIdx = 1; checkIdx < GRID_CNT; checkIdx++) {
info("Check grid index: " + checkIdx);
IgniteCache<Integer, String> checkCache = jcache(checkIdx);
assert !checkCache.isLocalLocked(key, false);
}
} catch (AssertionError e) {
if (i == 2)
throw e;
U.warn(log, "Check failed (will retry in 1000 ms): " + e.getMessage());
U.sleep(1000);
continue;
}
// Check passed on all grids.
break;
}
}
use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class ClientAbstractConnectivitySelfTest method testTwoNodesDefaultHostAndPort.
/**
* Tests correct behavior in case of 2 REST-enabled nodes with default
* settings.
*
* @throws Exception If error occurs.
*/
public void testTwoNodesDefaultHostAndPort() throws Exception {
startRestNode("grid1", null, null);
startRestNode("grid2", null, null);
GridClient cli = startClient(LOOPBACK_IP, defaultRestPort());
List<GridClientNode> nodes = cli.compute().refreshTopology(true, false);
assertEquals(2, nodes.size());
assertTrue(F.forAll(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
return node.tcpAddresses().contains(LOOPBACK_IP);
}
}));
GridTestUtils.assertOneToOne(nodes, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort()).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
}, new P1<GridClientNode>() {
@Override
public boolean apply(GridClientNode node) {
try {
return eqAddresses(getAllIps(), node) && Integer.valueOf(defaultRestPort() + 1).equals(node.attribute(restPortAttributeName()));
} catch (Exception ignored) {
return false;
}
}
});
}
use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class GridEventConsumeSelfTest method testNodeJoin.
/**
* @throws Exception If failed.
*/
public void testNodeJoin() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(GRID_CNT + 1);
UUID consumeId = grid(0).events().remoteListen(notSerializableProxy(new P2<UUID, Event>() {
@Override
public boolean apply(UUID nodeId, Event evt) {
info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
assertEquals(EVT_JOB_STARTED, evt.type());
nodeIds.add(nodeId);
cnt.incrementAndGet();
latch.countDown();
return true;
}
}), notSerializableProxy(new P1<Event>() {
@Override
public boolean apply(Event evt) {
return evt.type() == EVT_JOB_STARTED;
}
}), EVT_JOB_STARTED, EVT_JOB_FINISHED);
try {
assertNotNull(consumeId);
include = true;
startGrid("anotherGrid");
grid(0).compute().broadcast(F.noop());
assert latch.await(2, SECONDS);
assertEquals(GRID_CNT + 1, nodeIds.size());
assertEquals(GRID_CNT + 1, cnt.get());
} finally {
stopGrid("anotherGrid");
grid(0).events().stopRemoteListen(consumeId);
}
}
Aggregations