Search in sources :

Example 1 with SegmentationPolicy

use of org.apache.ignite.plugin.segmentation.SegmentationPolicy in project ignite by apache.

the class TcpDiscoverySelfTest method checkFailedCoordinatorNode.

/**
 * @param segPlc Segmentation policy.
 * @throws Exception If failed.
 */
private void checkFailedCoordinatorNode(SegmentationPolicy segPlc) throws Exception {
    try {
        this.segPlc = segPlc;
        IgniteEx coord = (IgniteEx) startGridsMultiThreaded(3);
        UUID coordId = coord.localNode().id();
        IgniteEx ignite1 = grid(1);
        AtomicBoolean coordSegmented = new AtomicBoolean();
        coord.events().localListen(evt -> {
            assertEquals(EVT_NODE_SEGMENTED, evt.type());
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            if (coordId.equals(nodeId))
                coordSegmented.set(true);
            return true;
        }, EVT_NODE_SEGMENTED);
        CountDownLatch failedLatch = new CountDownLatch(2);
        IgnitePredicate<Event> failLsnr = evt -> {
            assertEquals(EVT_NODE_FAILED, evt.type());
            UUID nodeId = ((DiscoveryEvent) evt).eventNode().id();
            if (coordId.equals(nodeId))
                failedLatch.countDown();
            return true;
        };
        ignite1.events().localListen(failLsnr, EVT_NODE_FAILED);
        grid(2).events().localListen(failLsnr, EVT_NODE_FAILED);
        ignite1.configuration().getDiscoverySpi().failNode(coordId, null);
        assertTrue(failedLatch.await(2000, MILLISECONDS));
        assertTrue(coordSegmented.get());
        if (segPlc == SegmentationPolicy.STOP) {
            assertTrue(coord.context().isStopping());
            waitNodeStop(coord.name());
        } else
            assertFalse(coord.context().isStopping());
        assertEquals(2, ignite1.context().discovery().allNodes().size());
    } finally {
        stopAllGrids();
    }
}
Also used : IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) Arrays(java.util.Arrays) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) EVT_NODE_LEFT(org.apache.ignite.events.EventType.EVT_NODE_LEFT) TcpDiscoveryNodeAddFinishedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddFinishedMessage) IgniteEx(org.apache.ignite.internal.IgniteEx) EVT_NODE_SEGMENTED(org.apache.ignite.events.EventType.EVT_NODE_SEGMENTED) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) GridPortRecord(org.apache.ignite.internal.processors.port.GridPortRecord) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) X(org.apache.ignite.internal.util.typedef.X) TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryNodeLeftMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeLeftMessage) IgniteKernal(org.apache.ignite.internal.IgniteKernal) IgniteInClosure(org.apache.ignite.lang.IgniteInClosure) TcpDiscoveryConnectionCheckMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryConnectionCheckMessage) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) EventType(org.apache.ignite.events.EventType) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) Event(org.apache.ignite.events.Event) GridComponent(org.apache.ignite.internal.GridComponent) EVT_TASK_FINISHED(org.apache.ignite.events.EventType.EVT_TASK_FINISHED) UUID(java.util.UUID) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) EVT_JOB_MAPPED(org.apache.ignite.events.EventType.EVT_JOB_MAPPED) InetSocketAddress(java.net.InetSocketAddress) IgniteCache(org.apache.ignite.IgniteCache) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) CountDownLatch(java.util.concurrent.CountDownLatch) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) EVT_NODE_FAILED(org.apache.ignite.events.EventType.EVT_NODE_FAILED) TcpDiscoveryNodeAddedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeAddedMessage) TcpDiscoveryNode(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryNode) NotNull(org.jetbrains.annotations.NotNull) TcpDiscoveryMetricsUpdateMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryMetricsUpdateMessage) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) LogListener(org.apache.ignite.testframework.LogListener) EVT_NODE_METRICS_UPDATED(org.apache.ignite.events.EventType.EVT_NODE_METRICS_UPDATED) Socket(java.net.Socket) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) MARSHALLER_PROC(org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.MARSHALLER_PROC) ArrayList(java.util.ArrayList) TcpDiscoveryStatistics(org.apache.ignite.spi.discovery.tcp.internal.TcpDiscoveryStatistics) DiscoveryDataPacket(org.apache.ignite.spi.discovery.tcp.internal.DiscoveryDataPacket) StartRoutineAckDiscoveryMessage(org.apache.ignite.internal.processors.continuous.StartRoutineAckDiscoveryMessage) ClusterNode(org.apache.ignite.cluster.ClusterNode) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteIllegalStateException(org.apache.ignite.IgniteIllegalStateException) SocketTimeoutException(java.net.SocketTimeoutException) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) SegmentationPolicy(org.apache.ignite.plugin.segmentation.SegmentationPolicy) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) DiscoverySpiDataExchange(org.apache.ignite.spi.discovery.DiscoverySpiDataExchange) LinkedHashSet(java.util.LinkedHashSet) OutputStream(java.io.OutputStream) G(org.apache.ignite.internal.util.typedef.G) F(org.apache.ignite.internal.util.typedef.F) EVT_NODE_JOINED(org.apache.ignite.events.EventType.EVT_NODE_JOINED) TcpDiscoveryNodeFailedMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryNodeFailedMessage) JAVA_ID(org.apache.ignite.internal.MarshallerPlatformIds.JAVA_ID) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IOException(java.io.IOException) Test(org.junit.Test) EVT_TASK_FAILED(org.apache.ignite.events.EventType.EVT_TASK_FAILED) Ignite(org.apache.ignite.Ignite) GridStringLogger(org.apache.ignite.testframework.GridStringLogger) TimeUnit(java.util.concurrent.TimeUnit) Ignition(org.apache.ignite.Ignition) UDP(org.apache.ignite.spi.IgnitePortProtocol.UDP) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) PA(org.apache.ignite.internal.util.typedef.PA) Collections(java.util.Collections) IgniteUuid(org.apache.ignite.lang.IgniteUuid) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteEx(org.apache.ignite.internal.IgniteEx) Event(org.apache.ignite.events.Event) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) DiscoveryEvent(org.apache.ignite.events.DiscoveryEvent) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 InetSocketAddress (java.net.InetSocketAddress)1 Socket (java.net.Socket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 UUID (java.util.UUID)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 TimeUnit (java.util.concurrent.TimeUnit)1 MILLISECONDS (java.util.concurrent.TimeUnit.MILLISECONDS)1