use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class ZookeeperIpFinderTest method testFourNodesKillRestartZookeeper.
/**
* @throws Exception If failed.
*/
public void testFourNodesKillRestartZookeeper() throws Exception {
allowDuplicateRegistrations = false;
// start 4 nodes
System.setProperty(TcpDiscoveryZookeeperIpFinder.PROP_ZK_CONNECTION_STRING, zkCluster.getConnectString());
startGrids(4);
// wait until all grids are started
waitForRemoteNodes(grid(0), 3);
// each node will only register itself
assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
// remember ZK server configuration and stop the cluster
Collection<InstanceSpec> instances = zkCluster.getInstances();
zkCluster.stop();
Thread.sleep(1000);
// start the cluster with the previous configuration
zkCluster = new TestingCluster(instances);
zkCluster.start();
// block the client until connected
zkCurator.blockUntilConnected();
// check that the nodes have registered again
assertEquals(4, zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size());
// stop all grids
stopAllGrids();
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
return 0 == zkCurator.getChildren().forPath(SERVICES_IGNITE_ZK_PATH).size();
} catch (Exception e) {
U.error(log, "Failed to wait for zk condition", e);
return false;
}
}
}, 20000));
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgfsProcessorSelfTest method testFormatNonEmpty.
/**
* Test format operation on non-empty file system.
*
* @throws Exception If failed.
*/
public void testFormatNonEmpty() throws Exception {
String dirPath = "/A/B/C";
igfs.mkdirs(path(dirPath));
String filePath = "/someFile";
create(filePath, false, "Some text.");
igfs.clear();
assert !igfs.exists(path(dirPath));
assert !igfs.exists(path(filePath));
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
int metaSize = 0;
for (Object metaId : grid(0).cachex(igfs.configuration().getMetaCacheConfiguration().getName()).keySet()) {
if (!IgfsUtils.isRootOrTrashId((IgniteUuid) metaId))
metaSize++;
}
return metaSize == 0;
}
}, 5000);
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class IgniteClientDataStructuresAbstractTest method testSequence.
/**
* @param creator Creator node.
* @param other Other node.
* @throws Exception If failed.
*/
private void testSequence(Ignite creator, Ignite other) throws Exception {
assertNull(creator.atomicSequence("seq1", 1L, false));
assertNull(other.atomicSequence("seq1", 1L, false));
List<IgniteAtomicSequence> sequences = new ArrayList<>(2);
try (IgniteAtomicSequence seq = creator.atomicSequence("seq1", 1L, true)) {
sequences.add(seq);
assertNotNull(seq);
assertEquals(1L, seq.get());
assertEquals(1L, seq.getAndAdd(1));
assertEquals(2L, seq.get());
IgniteAtomicSequence seq0 = other.atomicSequence("seq1", 1L, false);
sequences.add(seq0);
assertNotNull(seq0);
}
for (IgniteAtomicSequence seq : sequences) {
try {
seq.getAndAdd(seq.batchSize());
fail("Operations with closed sequence must fail");
} catch (Throwable ignore) {
// No-op.
}
}
for (Ignite ignite : F.asList(creator, other)) {
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite.atomicSequence("seq1", 1L, false) == null;
}
}, 3_000L));
}
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class GridEventStorageCheckAllEventsSelfTest method testTaskUndeployEvents.
/**
* @throws Exception If test failed.
*/
@Test
public void testTaskUndeployEvents() throws Exception {
final long tstamp = startTimestamp();
generateEvents(null, new GridAllEventsSuccessTestJob()).get();
// TODO: IGNITE-3099 (hotfix the test to check the event order in common case).
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
try {
List<Event> evts = pullEvents(tstamp, 10);
return evts.get(evts.size() - 1).type() == EVT_JOB_FINISHED;
} catch (Exception ignored) {
return false;
}
}
}, 500);
ignite.compute().undeployTask(GridAllEventsTestTask.class.getName());
ignite.compute().localDeployTask(GridAllEventsTestTask.class, GridAllEventsTestTask.class.getClassLoader());
List<Event> evts = pullEvents(tstamp, 12);
assertEvent(evts.get(0).type(), EVT_TASK_STARTED, evts);
assertEvent(evts.get(1).type(), EVT_JOB_MAPPED, evts);
assertEvent(evts.get(2).type(), EVT_JOB_QUEUED, evts);
assertEvent(evts.get(3).type(), EVT_JOB_STARTED, evts);
assertEvent(evts.get(4).type(), EVT_CHECKPOINT_SAVED, evts);
assertEvent(evts.get(5).type(), EVT_CHECKPOINT_REMOVED, evts);
assertEvent(evts.get(6).type(), EVT_JOB_RESULTED, evts);
assertEvent(evts.get(7).type(), EVT_TASK_REDUCED, evts);
assertEvent(evts.get(8).type(), EVT_TASK_FINISHED, evts);
assertEvent(evts.get(9).type(), EVT_JOB_FINISHED, evts);
assertEvent(evts.get(10).type(), EVT_TASK_UNDEPLOYED, evts);
assertEvent(evts.get(11).type(), EVT_TASK_DEPLOYED, evts);
assertNotNull(((JobEvent) evts.get(6)).resultPolicy());
assertEquals(WAIT, ((JobEvent) evts.get(6)).resultPolicy());
}
use of org.apache.ignite.internal.util.lang.GridAbsPredicate in project ignite by apache.
the class ClusterNodeMetricsSelfTest method testClusterNodeMetrics.
/**
* @throws Exception If failed.
*/
@Test
public void testClusterNodeMetrics() throws Exception {
final Ignite ignite0 = grid();
final Ignite ignite1 = startGrid(1);
GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return ignite0.cluster().nodes().size() == 2 && ignite1.cluster().nodes().size() == 2;
}
}, 3000L);
ClusterMetrics metrics0 = ignite0.cluster().localNode().metrics();
ClusterMetrics nodesMetrics = ignite0.cluster().forNode(ignite0.cluster().localNode(), ignite1.cluster().localNode()).metrics();
assertEquals(metrics0.getTotalCpus(), nodesMetrics.getTotalCpus());
assertEquals(1, metrics0.getTotalNodes());
assertEquals(2, nodesMetrics.getTotalNodes());
assert metrics0.getHeapMemoryUsed() > 0;
assert metrics0.getHeapMemoryTotal() > 0;
}
Aggregations