Search in sources :

Example 1 with ClusterIdUpdatedEvent

use of org.apache.ignite.events.ClusterIdUpdatedEvent in project gridgain by gridgain.

the class IgniteClusterIdTagTest method testIdChangedEvent.

/**
 * Verifies that event is fired when ID change request sent by user is completed.
 *
 * @throws Exception If failed.
 */
@Test
public void testIdChangedEvent() throws Exception {
    IgniteEx ig = startGrid(0);
    UUID generatedId = ig.cluster().id();
    AtomicReference<UUID> previousIdFromEvent = new AtomicReference<>(null);
    AtomicReference<UUID> newIdFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig.events().localListen((evt) -> {
        evtFired.set(true);
        ClusterIdUpdatedEvent tagUpdatedEvt = (ClusterIdUpdatedEvent) evt;
        previousIdFromEvent.set(tagUpdatedEvt.previousId());
        newIdFromEvent.set(tagUpdatedEvt.newId());
        return true;
    }, EventType.EVT_CLUSTER_ID_UPDATED);
    ig.cluster().id(CUSTOM_ID_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(generatedId, previousIdFromEvent.get());
    assertEquals(CUSTOM_ID_0, newIdFromEvent.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with ClusterIdUpdatedEvent

use of org.apache.ignite.events.ClusterIdUpdatedEvent in project gridgain by gridgain.

the class IgniteClusterIdTagTest method testIdChangedEventMultinodeWithRemoteFilter.

/**
 * Verifies that event about cluster ID update is fired on remote nodes as well.
 *
 * @throws Exception If failed.
 */
@Test
public void testIdChangedEventMultinodeWithRemoteFilter() throws Exception {
    IgniteEx ig0 = startGrid(0);
    IgniteEx ig1 = startGrid(1);
    UUID generatedId = ig0.cluster().id();
    AtomicReference<UUID> eventNodeId = new AtomicReference<>(null);
    AtomicReference<UUID> previousIdFromEvent = new AtomicReference<>(null);
    AtomicReference<UUID> newIdFromEvent = new AtomicReference<>(null);
    AtomicBoolean evtFired = new AtomicBoolean(false);
    ig0.events(ig0.cluster().forRemotes()).remoteListen((IgniteBiPredicate<UUID, Event>) (uuid, event) -> {
        eventNodeId.set(uuid);
        evtFired.set(true);
        ClusterIdUpdatedEvent tagUpdatedEvt = (ClusterIdUpdatedEvent) event;
        previousIdFromEvent.set(tagUpdatedEvt.previousId());
        newIdFromEvent.set(tagUpdatedEvt.newId());
        return true;
    }, (IgnitePredicate<Event>) event -> event.type() == EventType.EVT_CLUSTER_ID_UPDATED);
    ig0.cluster().id(CUSTOM_ID_0);
    assertTrue(GridTestUtils.waitForCondition(evtFired::get, 10_000));
    assertEquals(ig1.localNode().id(), eventNodeId.get());
    assertEquals(generatedId, previousIdFromEvent.get());
    assertEquals(CUSTOM_ID_0, newIdFromEvent.get());
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgnitionEx(org.apache.ignite.internal.IgnitionEx) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ClusterState(org.apache.ignite.cluster.ClusterState) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) IgniteClusterMXBeanImpl(org.apache.ignite.internal.processors.cluster.IgniteClusterMXBeanImpl) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) IgniteKernal(org.apache.ignite.internal.IgniteKernal) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Event(org.apache.ignite.events.Event) Test(org.junit.Test) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) WithSystemProperty(org.apache.ignite.testframework.junits.WithSystemProperty) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteClusterMXBean(org.apache.ignite.mxbean.IgniteClusterMXBean) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) IGNITE_CLUSTER_ID_AND_TAG_FEATURE(org.apache.ignite.internal.SupportFeaturesUtils.IGNITE_CLUSTER_ID_AND_TAG_FEATURE) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) ClusterTagUpdatedEvent(org.apache.ignite.events.ClusterTagUpdatedEvent) Event(org.apache.ignite.events.Event) AtomicReference(java.util.concurrent.atomic.AtomicReference) UUID(java.util.UUID) ClusterIdUpdatedEvent(org.apache.ignite.events.ClusterIdUpdatedEvent) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

UUID (java.util.UUID)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 ClusterIdUpdatedEvent (org.apache.ignite.events.ClusterIdUpdatedEvent)2 IgniteEx (org.apache.ignite.internal.IgniteEx)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Test (org.junit.Test)2 Ignite (org.apache.ignite.Ignite)1 ClusterState (org.apache.ignite.cluster.ClusterState)1 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)1 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 ClusterTagUpdatedEvent (org.apache.ignite.events.ClusterTagUpdatedEvent)1 Event (org.apache.ignite.events.Event)1 EventType (org.apache.ignite.events.EventType)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 IgnitionEx (org.apache.ignite.internal.IgnitionEx)1 IGNITE_CLUSTER_ID_AND_TAG_FEATURE (org.apache.ignite.internal.SupportFeaturesUtils.IGNITE_CLUSTER_ID_AND_TAG_FEATURE)1 IgniteClusterMXBeanImpl (org.apache.ignite.internal.processors.cluster.IgniteClusterMXBeanImpl)1