Search in sources :

Example 11 with GridAbsPredicate

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));
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) TestingCluster(org.apache.curator.test.TestingCluster) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 12 with GridAbsPredicate

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);
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate)

Example 13 with GridAbsPredicate

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));
    }
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) ArrayList(java.util.ArrayList) IgniteAtomicSequence(org.apache.ignite.IgniteAtomicSequence) Ignite(org.apache.ignite.Ignite)

Example 14 with GridAbsPredicate

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());
}
Also used : GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) CheckpointEvent(org.apache.ignite.events.CheckpointEvent) DeploymentEvent(org.apache.ignite.events.DeploymentEvent) List(java.util.List) ArrayList(java.util.ArrayList) IgniteException(org.apache.ignite.IgniteException) ComputeTaskTimeoutException(org.apache.ignite.compute.ComputeTaskTimeoutException) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 15 with GridAbsPredicate

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;
}
Also used : ClusterMetrics(org.apache.ignite.cluster.ClusterMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) Ignite(org.apache.ignite.Ignite) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)229 Ignite (org.apache.ignite.Ignite)109 Test (org.junit.Test)102 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)65 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)52 ClusterNode (org.apache.ignite.cluster.ClusterNode)37 IgniteEx (org.apache.ignite.internal.IgniteEx)34 IgniteException (org.apache.ignite.IgniteException)31 ArrayList (java.util.ArrayList)29 CountDownLatch (java.util.concurrent.CountDownLatch)28 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)28 Transaction (org.apache.ignite.transactions.Transaction)25 Map (java.util.Map)22 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)21 IgniteCache (org.apache.ignite.IgniteCache)19 IgniteKernal (org.apache.ignite.internal.IgniteKernal)19 HashMap (java.util.HashMap)17 Duration (javax.cache.expiry.Duration)15 TouchedExpiryPolicy (javax.cache.expiry.TouchedExpiryPolicy)13 UUID (java.util.UUID)12