Search in sources :

Example 21 with GridTimeoutProcessor

use of org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor in project gridgain by gridgain.

the class TxDeadlockOnEntryToStringTest method testDeadlockOnTimeoutWorkerAndToString.

/**
 * We removed locks from toString on Entry. The case, a thread X lock entry, after that trying to do a handshake
 * with connecting node. But, handshake fails on the first attempt. Between these events, timeout worked trying to
 * print this entry, but I locked. The thread X can't reconnect, because timeout worker hangs.
 */
@Test
public void testDeadlockOnTimeoutWorkerAndToString() throws Exception {
    // Setup
    TestDependencyResolver nearDepRslvr = new TestDependencyResolver();
    IgniteEx nearNode = startGrid(0, nearDepRslvr);
    TestDependencyResolver incomingDepRslvr = new TestDependencyResolver(this::resolve);
    IgniteEx incomingNode = startGrid(1, incomingDepRslvr);
    GridTimeoutProcessor tp = nearNode.context().timeout();
    ConnectionClientPool pool = nearDepRslvr.getDependency(ConnectionClientPool.class);
    GridCacheEntryEx ex = getEntry(nearNode, DEFAULT_CACHE_NAME, TEST_KEY);
    // Act
    // Lock entry in current thread
    ex.lockEntry();
    try {
        // Print the entry from another thread via timeObject.
        CountDownLatch entryPrinted = new CountDownLatch(1);
        CountDownLatch entryReadyToPrint = new CountDownLatch(1);
        tp.addTimeoutObject(new EntryPrinterTimeoutObject(ex, entryPrinted, entryReadyToPrint));
        entryReadyToPrint.await();
        // Try to do first handshake with hangs, after reconnect handshake should be passed.
        rejectHandshake.set(true);
        pool.forceCloseConnection(incomingNode.localNode().id());
        nearNode.configuration().getCommunicationSpi().sendMessage(incomingNode.localNode(), UUIDCollectionMessage.of(UUID.randomUUID()));
        // Check
        assertTrue(GridTestUtils.waitForCondition(() -> entryPrinted.getCount() == 0, 5_000));
    } finally {
        // Allow synchronous eviction on node stop.
        ex.unlockEntry();
    }
}
Also used : GridCacheEntryEx(org.apache.ignite.internal.processors.cache.GridCacheEntryEx) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) IgniteEx(org.apache.ignite.internal.IgniteEx) ConnectionClientPool(org.apache.ignite.spi.communication.tcp.internal.ConnectionClientPool) TestDependencyResolver(org.apache.ignite.testframework.TestDependencyResolver) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 22 with GridTimeoutProcessor

use of org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor in project gridgain by gridgain.

the class GridQueryCommandHandlerTest method testSupportedCommands.

/**
 * @throws Exception If failed.
 */
@Test
public void testSupportedCommands() throws Exception {
    GridTestKernalContext ctx = newContext(grid().configuration());
    ctx.add(new GridTimeoutProcessor(ctx));
    QueryCommandHandler cmdHnd = new QueryCommandHandler(ctx);
    Collection<GridRestCommand> commands = cmdHnd.supportedCommands();
    assertEquals(5, commands.size());
    assertTrue(commands.contains(GridRestCommand.EXECUTE_SQL_QUERY));
    assertTrue(commands.contains(GridRestCommand.EXECUTE_SQL_FIELDS_QUERY));
    assertTrue(commands.contains(GridRestCommand.EXECUTE_SCAN_QUERY));
    assertTrue(commands.contains(GridRestCommand.FETCH_SQL_QUERY));
    assertTrue(commands.contains(GridRestCommand.CLOSE_SQL_QUERY));
}
Also used : GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 23 with GridTimeoutProcessor

use of org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor in project gridgain by gridgain.

the class GridQueryCommandHandlerTest method testUnsupportedCommands.

/**
 * @throws Exception If failed.
 */
@Test
public void testUnsupportedCommands() throws Exception {
    GridTestKernalContext ctx = newContext(grid().configuration());
    ctx.add(new GridTimeoutProcessor(ctx));
    QueryCommandHandler cmdHnd = new QueryCommandHandler(ctx);
    Collection<GridRestCommand> commands = cmdHnd.supportedCommands();
    assertFalse(commands.contains(GridRestCommand.LOG));
}
Also used : GridRestCommand(org.apache.ignite.internal.processors.rest.GridRestCommand) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 24 with GridTimeoutProcessor

use of org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor in project gridgain by gridgain.

the class GridTcpCommunicationSpiMultithreadedSelfTest method beforeTestsStarted.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTestsStarted() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    lsnrs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < getSpiCount(); i++) {
        CommunicationSpi<Message> spi = newCommunicationSpi();
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.order(i);
        GridSpiTestContext ctx = initSpiContext();
        MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
        ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
        ctx.timeoutProcessor(timeoutProcessor);
        ctx.setLocalNode(node);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
        ignite.setCommunicationSpi(spi);
        MessageListener lsnr = new MessageListener(rsrcs.getNodeId());
        spi.setListener(lsnr);
        lsnrs.put(rsrcs.getNodeId(), lsnr);
        info("Lsnrs: " + lsnrs);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        nodes.add(node);
        node.setAttributes(spi.getNodeAttributes());
        node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
        spis.put(rsrcs.getNodeId(), spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
        for (ClusterNode n : nodes) {
            if (!n.equals(e.getKey()))
                e.getValue().remoteNodes().add(n);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridNioSession(org.apache.ignite.internal.util.nio.GridNioSession) CommunicationListener(org.apache.ignite.spi.communication.CommunicationListener) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) ATTR_MACS(org.apache.ignite.internal.IgniteNodeAttributes.ATTR_MACS) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Random(java.util.Random) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) Deque(java.util.Deque) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Map(java.util.Map) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) GridNioServerWrapper(org.apache.ignite.spi.communication.tcp.internal.GridNioServerWrapper) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) F(org.apache.ignite.internal.util.typedef.F) CyclicBarrier(java.util.concurrent.CyclicBarrier) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) Collection(java.util.Collection) IgniteException(org.apache.ignite.IgniteException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) UUID(java.util.UUID) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) AtomicLong(java.util.concurrent.atomic.AtomicLong) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) List(java.util.List) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) Entry(java.util.Map.Entry) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Aggregations

GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)24 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)16 ClusterNode (org.apache.ignite.cluster.ClusterNode)15 HashMap (java.util.HashMap)13 GridIoMessageFactory (org.apache.ignite.internal.managers.communication.GridIoMessageFactory)12 IgniteMessageFactoryImpl (org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl)12 MessageFactory (org.apache.ignite.plugin.extensions.communication.MessageFactory)12 MessageFactoryProvider (org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider)12 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)12 GridTestNode (org.apache.ignite.testframework.GridTestNode)12 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)12 Map (java.util.Map)11 Test (org.junit.Test)10 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)7 IgniteMock (org.apache.ignite.testframework.junits.IgniteMock)7 IgniteMessageFactory (org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 Message (org.apache.ignite.plugin.extensions.communication.Message)5