Search in sources :

Example 26 with GridTestKernalContext

use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.

the class BPlusTreeReuseSelfTest method createReuseList.

/**
 * {@inheritDoc}
 */
@Override
protected ReuseList createReuseList(int cacheId, PageMemory pageMem, long rootId, boolean initNew) throws IgniteCheckedException {
    PageLockTrackerManager pageLockTrackerManager = mock(PageLockTrackerManager.class);
    when(pageLockTrackerManager.createPageLockTracker(anyString())).thenReturn(new TestPageLockListener());
    return new TestReuseList(cacheId, "test", pageMem, rootId, pageLockTrackerManager, new GridTestKernalContext(log), initNew);
}
Also used : GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) PageLockTrackerManager(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTrackerManager)

Example 27 with GridTestKernalContext

use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.

the class GridTcpCommunicationSpiConcurrentConnectSelfTest method startSpis.

/**
 * @param lsnr Message listener.
 * @throws Exception If failed.
 */
private void startSpis(MessageListener lsnr) throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < SPI_CNT; i++) {
        CommunicationSpi<Message> spi = createSpi();
        IgniteTestResources rsrcs = new IgniteTestResources();
        GridTestNode node = new GridTestNode(rsrcs.getNodeId());
        node.setAttribute(IgniteNodeAttributes.ATTR_CLIENT_MODE, false);
        node.order(i + 1);
        GridSpiTestContext ctx = initSpiContext();
        MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {

            @Override
            public void registerAll(IgniteMessageFactory factory) {
                factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
            }
        };
        ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
        ctx.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        info(">>> Initialized context: nodeId=" + ctx.localNode().id());
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(lsnr);
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        node.setAttributes(spi.getNodeAttributes());
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.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) 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) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) 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) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 28 with GridTestKernalContext

use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.

the class GridTcpCommunicationSpiRecoverySelfTest method startSpis.

/**
 * @throws Exception If failed.
 */
private void startSpis() throws Exception {
    spis.clear();
    nodes.clear();
    spiRsrcs.clear();
    Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
    timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
    timeoutProcessor.start();
    timeoutProcessor.onKernalStart(true);
    for (int i = 0; i < SPI_CNT; i++) {
        TcpCommunicationSpi spi = getSpi(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.setLocalNode(node);
        ctx.timeoutProcessor(timeoutProcessor);
        spiRsrcs.add(rsrcs);
        rsrcs.inject(spi);
        GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
        if (useSsl) {
            IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
            IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
            ignite.setStaticCfg(cfg);
        }
        spi.setListener(new TestListener());
        nodes.add(node);
        spi.spiStart(getTestIgniteInstanceName() + (i + 1));
        node.setAttributes(spi.getNodeAttributes());
        spis.add(spi);
        spi.onContextInitialized(ctx);
        ctxs.put(node, ctx);
    }
    // For each context set remote nodes.
    for (Map.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) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) U(org.apache.ignite.internal.util.typedef.internal.U) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) BindException(java.net.BindException) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) ArrayList(java.util.ArrayList) GridSpiTest(org.apache.ignite.testframework.junits.spi.GridSpiTest) ClusterNode(org.apache.ignite.cluster.ClusterNode) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) Map(java.util.Map) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) 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) GridNioServer(org.apache.ignite.internal.util.nio.GridNioServer) Collection(java.util.Collection) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridSpiAbstractTest(org.apache.ignite.testframework.junits.spi.GridSpiAbstractTest) Test(org.junit.Test) UUID(java.util.UUID) GridTestNode(org.apache.ignite.testframework.GridTestNode) GridTestUtils(org.apache.ignite.testframework.GridTestUtils) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock) CountDownLatch(java.util.concurrent.CountDownLatch) CommunicationSpi(org.apache.ignite.spi.communication.CommunicationSpi) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteSpiAdapter(org.apache.ignite.spi.IgniteSpiAdapter) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) Message(org.apache.ignite.plugin.extensions.communication.Message) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) 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) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with GridTestKernalContext

use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.

the class GridFutureAdapterSelfTest method testListenNotify.

/**
 * @throws Exception If failed.
 */
@Test
public void testListenNotify() throws Exception {
    GridTestKernalContext ctx = new GridTestKernalContext(log);
    ctx.add(new NoOpIgniteSecurityProcessor(ctx));
    ctx.add(new PoolProcessor(ctx) {

        final ExecutorService execSvc = Executors.newSingleThreadExecutor(new IgniteThreadFactory("testscope", "exec-svc"));

        final ExecutorService sysExecSvc = Executors.newSingleThreadExecutor(new IgniteThreadFactory("testscope", "system-exec"));

        @Override
        public ExecutorService getSystemExecutorService() {
            return sysExecSvc;
        }

        @Override
        public ExecutorService getExecutorService() {
            return execSvc;
        }
    });
    ctx.add(new GridClosureProcessor(ctx));
    ctx.start();
    try {
        GridFutureAdapter<String> fut = new GridFutureAdapter<>();
        int lsnrCnt = 10;
        final CountDownLatch latch = new CountDownLatch(lsnrCnt);
        final Thread runThread = Thread.currentThread();
        for (int i = 0; i < lsnrCnt; i++) {
            fut.listen(new CI1<IgniteInternalFuture<String>>() {

                @Override
                public void apply(IgniteInternalFuture<String> t) {
                    assert Thread.currentThread() == runThread;
                    latch.countDown();
                }
            });
        }
        fut.onDone();
        latch.await();
        final CountDownLatch doneLatch = new CountDownLatch(1);
        fut.listen(new CI1<IgniteInternalFuture<String>>() {

            @Override
            public void apply(IgniteInternalFuture<String> t) {
                assert Thread.currentThread() == runThread;
                doneLatch.countDown();
            }
        });
        assert doneLatch.getCount() == 0;
        doneLatch.await();
    } finally {
        ctx.stop(false);
    }
}
Also used : GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) NoOpIgniteSecurityProcessor(org.apache.ignite.internal.processors.security.NoOpIgniteSecurityProcessor) IgniteThreadFactory(org.apache.ignite.thread.IgniteThreadFactory) GridClosureProcessor(org.apache.ignite.internal.processors.closure.GridClosureProcessor) ExecutorService(java.util.concurrent.ExecutorService) PoolProcessor(org.apache.ignite.internal.processors.pool.PoolProcessor) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 30 with GridTestKernalContext

use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.

the class InlineIndexColumnTest method testPutGet.

/**
 */
private void testPutGet(Value v1, Value v2, Value v3) throws Exception {
    DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log())), false);
    pageMem.start();
    long pageId = 0L;
    long page = 0L;
    try {
        pageId = pageMem.allocatePage(CACHE_ID, 1, PageIdAllocator.FLAG_DATA);
        page = pageMem.acquirePage(CACHE_ID, pageId);
        long pageAddr = pageMem.readLock(CACHE_ID, pageId, page);
        int off = 0;
        int max = 255;
        IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(v1.getType(), keyTypeSettings);
        off += keyType.put(pageAddr, off, idxKey(v1), max - off);
        off += keyType.put(pageAddr, off, idxKey(v2), max - off);
        off += keyType.put(pageAddr, off, idxKey(v3), max - off);
        IndexKey v11 = keyType.get(pageAddr, 0, max);
        IndexKey v22 = keyType.get(pageAddr, keyType.inlineSize(pageAddr, 0), max);
        assertEquals(v1.getObject(), v11.key());
        assertEquals(v2.getObject(), v22.key());
        assertEquals(0, keyType.compare(pageAddr, 0, max, idxKey(v1)));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop(true);
    }
}
Also used : DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) IndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey) JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) StringInlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)

Aggregations

GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)48 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)22 Test (org.junit.Test)21 DataRegionMetricsImpl (org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl)20 DataRegionConfiguration (org.apache.ignite.configuration.DataRegionConfiguration)17 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)15 UnsafeMemoryProvider (org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider)14 PageMemory (org.apache.ignite.internal.pagemem.PageMemory)12 PageMemoryNoStoreImpl (org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl)11 DirectMemoryProvider (org.apache.ignite.internal.mem.DirectMemoryProvider)8 GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)8 HashMap (java.util.HashMap)7 GridSystemViewManager (org.apache.ignite.internal.managers.systemview.GridSystemViewManager)7 JmxSystemViewExporterSpi (org.apache.ignite.internal.managers.systemview.JmxSystemViewExporterSpi)7 GridRestResponse (org.apache.ignite.internal.processors.rest.GridRestResponse)7 GridRestLogRequest (org.apache.ignite.internal.processors.rest.request.GridRestLogRequest)7 NoopMetricExporterSpi (org.apache.ignite.spi.metric.noop.NoopMetricExporterSpi)7 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 DataStorageConfiguration (org.apache.ignite.configuration.DataStorageConfiguration)6 IndexKeyTypeSettings (org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings)6