Search in sources :

Example 1 with PE

use of org.apache.ignite.internal.util.typedef.PE in project ignite by apache.

the class GridCacheMarshallingNodeJoinSelfTest method testNodeJoin.

/**
     * @throws Exception If failed.
     */
public void testNodeJoin() throws Exception {
    final CountDownLatch allowJoin = new CountDownLatch(1);
    final CountDownLatch joined = new CountDownLatch(2);
    for (int i = 0; i < 2; i++) {
        ignite(i).events().localListen(new PE() {

            @Override
            public boolean apply(Event evt) {
                assert evt.type() == EventType.EVT_NODE_JOINED;
                info(">>> Event: " + evt);
                joined.countDown();
                return true;
            }
        }, EventType.EVT_NODE_JOINED);
    }
    IgniteInternalFuture<?> oneMoreGrid = multithreadedAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            allowJoin.await();
            startGrid("oneMoreGrid");
            return null;
        }
    }, 1);
    IgniteCache<Integer, TestObject> cache = ignite(0).cache(DEFAULT_CACHE_NAME);
    try (Transaction tx = ignite(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
        cache.get(0);
        allowJoin.countDown();
        joined.await();
        assertNotNull(cache.get(1));
        tx.commit();
    }
    oneMoreGrid.get();
    assertNotNull(cache.get(1));
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) CacheLoaderException(javax.cache.integration.CacheLoaderException) CacheWriterException(javax.cache.integration.CacheWriterException) Transaction(org.apache.ignite.transactions.Transaction) PE(org.apache.ignite.internal.util.typedef.PE) Event(org.apache.ignite.events.Event)

Example 2 with PE

use of org.apache.ignite.internal.util.typedef.PE in project ignite by apache.

the class GridTaskTimeoutSelfTest method checkTimedOutEvents.

/**
     * @param execId Execution ID.
     */
private void checkTimedOutEvents(final IgniteUuid execId) {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    Collection<Event> evts = ignite.events().localQuery(new PE() {

        @Override
        public boolean apply(Event evt) {
            return ((TaskEvent) evt).taskSessionId().equals(execId);
        }
    }, EVT_TASK_TIMEDOUT);
    assert evts.size() == 1 : "Invalid number of timed out tasks: " + evts.size();
}
Also used : PE(org.apache.ignite.internal.util.typedef.PE) TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) Ignite(org.apache.ignite.Ignite)

Aggregations

Event (org.apache.ignite.events.Event)2 PE (org.apache.ignite.internal.util.typedef.PE)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 CacheLoaderException (javax.cache.integration.CacheLoaderException)1 CacheWriterException (javax.cache.integration.CacheWriterException)1 Ignite (org.apache.ignite.Ignite)1 TaskEvent (org.apache.ignite.events.TaskEvent)1 Transaction (org.apache.ignite.transactions.Transaction)1