Search in sources :

Example 41 with Event

use of org.apache.ignite.events.Event 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)

Example 42 with Event

use of org.apache.ignite.events.Event in project ignite by apache.

the class GridRuntimeExceptionSelfTest method testResultFailed.

/**
 * @throws Exception If failed.
 */
@Test
public void testResultFailed() throws Exception {
    Ignite ignite = G.ignite(getTestIgniteInstanceName());
    ignite.compute().localDeployTask(GridTaskFailedTestTask.class, GridTaskFailedTestTask.class.getClassLoader());
    ComputeTaskFuture<?> fut = executeAsync(ignite.compute(), GridTaskFailedTestTask.class.getName(), FailType.RESULT);
    try {
        fut.get();
        assert false;
    } catch (IgniteException e) {
        info("Got expected grid exception: " + e);
    }
    IgniteUuid sesId = fut.getTaskSession().getId();
    // Query for correct events.
    List<Event> evts = ignite.events().remoteQuery(new TaskFailedEventFilter(sesId), 0);
    assert evts.size() == 1;
    info("Task failed event: " + evts.get(0));
}
Also used : IgniteException(org.apache.ignite.IgniteException) IgniteUuid(org.apache.ignite.lang.IgniteUuid) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) 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)

Example 43 with Event

use of org.apache.ignite.events.Event in project ignite by apache.

the class GridEventStorageSelfTest method testGridInternalEvents.

/**
 * @throws Exception In case of error.
 */
@Test
public void testGridInternalEvents() throws Exception {
    IgnitePredicate<Event> lsnr = new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            checkGridInternalEvent(evt);
            return true;
        }
    };
    ignite1.events().localListen(lsnr, EVTS_TASK_EXECUTION);
    ignite1.events().localListen(lsnr, EVTS_JOB_EXECUTION);
    ignite2.events().localListen(lsnr, EVTS_TASK_EXECUTION);
    ignite2.events().localListen(lsnr, EVTS_JOB_EXECUTION);
    executeGridInternalTask(ignite1);
    Collection<Event> evts1 = ignite1.events().localQuery(F.<Event>alwaysTrue());
    Collection<Event> evts2 = ignite2.events().localQuery(F.<Event>alwaysTrue());
    assert evts1 != null;
    assert evts2 != null;
    for (Event evt : evts1) checkGridInternalEvent(evt);
    for (Event evt : evts2) checkGridInternalEvent(evt);
    assert ignite1.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
    assert ignite1.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
    assert ignite2.events().stopLocalListen(lsnr, EVTS_TASK_EXECUTION);
    assert ignite2.events().stopLocalListen(lsnr, EVTS_JOB_EXECUTION);
}
Also used : IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 44 with Event

use of org.apache.ignite.events.Event in project ignite by apache.

the class GridEventStorageSelfTest method testRemoteNodeEventStorage.

/**
 * @throws Exception In case of error.
 */
@Test
public void testRemoteNodeEventStorage() throws Exception {
    IgnitePredicate<Event> filter = new TestEventFilter();
    generateEvents(ignite2);
    ClusterGroup prj = ignite1.cluster().forPredicate(F.remoteNodes(ignite1.cluster().localNode().id()));
    Collection<Event> evts = events(prj).remoteQuery(filter, 0);
    assert evts != null;
    assert evts.size() == 1;
}
Also used : JobEvent(org.apache.ignite.events.JobEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Event(org.apache.ignite.events.Event) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) GridCommonTest(org.apache.ignite.testframework.junits.common.GridCommonTest) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 45 with Event

use of org.apache.ignite.events.Event in project ignite by apache.

the class IgniteNodeValidationFailedEventTest method testNodeValidationFailedEvent.

/**
 */
@Test
public void testNodeValidationFailedEvent() throws Exception {
    startGrid(0);
    CountDownLatch evtLatch = new CountDownLatch(1);
    AtomicReference<Event> listenedEvtRef = new AtomicReference<>();
    grid(0).events().localListen(evt -> {
        assertTrue(listenedEvtRef.compareAndSet(null, evt));
        evtLatch.countDown();
        return true;
    }, EVT_NODE_VALIDATION_FAILED);
    startGrid(1);
    String invalidNodeName = getTestIgniteInstanceName(2);
    IgniteConfiguration invalidCfg = getConfiguration(invalidNodeName).setPluginProviders(new TestSecurityPluginProvider("login", "", ALLOW_ALL, false));
    assertThrowsWithCause(() -> startGrid(optimize(invalidCfg)), IgniteSpiException.class);
    evtLatch.await();
    Event listenedEvt = listenedEvtRef.get();
    assertTrue(listenedEvt instanceof NodeValidationFailedEvent);
    NodeValidationFailedEvent validationEvt = (NodeValidationFailedEvent) listenedEvt;
    assertEquals(invalidNodeName, validationEvt.eventNode().attribute(ATTR_NODE_CONSISTENT_ID));
    IgniteNodeValidationResult validationRes = validationEvt.validationResult();
    assertNotNull(validationRes);
    String errMsg = validationRes.message();
    assertNotNull(errMsg);
    assertTrue(errMsg.contains("Local node's grid security processor class is not equal to remote node's grid security processor class"));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestSecurityPluginProvider(org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) NodeValidationFailedEvent(org.apache.ignite.events.NodeValidationFailedEvent) Event(org.apache.ignite.events.Event) NodeValidationFailedEvent(org.apache.ignite.events.NodeValidationFailedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Event (org.apache.ignite.events.Event)273 Test (org.junit.Test)148 CountDownLatch (java.util.concurrent.CountDownLatch)146 Ignite (org.apache.ignite.Ignite)144 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)125 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)103 UUID (java.util.UUID)87 IgnitePredicate (org.apache.ignite.lang.IgnitePredicate)76 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)50 ClusterNode (org.apache.ignite.cluster.ClusterNode)48 IgniteException (org.apache.ignite.IgniteException)34 ArrayList (java.util.ArrayList)33 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)31 JobEvent (org.apache.ignite.events.JobEvent)28 GridLocalEventListener (org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener)28 HashMap (java.util.HashMap)27 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)26 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)26 Collection (java.util.Collection)23 Map (java.util.Map)23