Search in sources :

Example 46 with GridTestKernalContext

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

the class InlineIndexColumnTest method testStringTruncate.

/**
 */
@Test
public void testStringTruncate() 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;
        IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.STRING, keyTypeSettings);
        keyType.put(pageAddr, off, idxKey(ValueString.get("aaaaaaa")), 3 + 5);
        assertEquals("aaaaa", keyType.get(pageAddr, off, 3 + 5).key());
        keyType.put(pageAddr, off, idxKey(ValueString.get("aaa")), 3 + 5);
        assertEquals("aaa", keyType.get(pageAddr, off, 3 + 5).key());
        keyType.put(pageAddr, off, idxKey(ValueString.get("\u20acaaa")), 3 + 2);
        assertNull(keyType.get(pageAddr, off, 3 + 2));
    } 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) 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) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 47 with GridTestKernalContext

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

the class InlineIndexColumnTest method testJavaObjectInlineBytes.

/**
 */
@Test
public void testJavaObjectInlineBytes() throws Exception {
    DataRegionConfiguration plcCfg = new DataRegionConfiguration().setInitialSize(1024 * MB).setMaxSize(1024 * MB);
    DataRegionMetricsImpl dataRegionMetrics = new DataRegionMetricsImpl(plcCfg, new GridTestKernalContext(log()));
    PageMemory pageMem = new PageMemoryNoStoreImpl(log, new UnsafeMemoryProvider(log), null, PAGE_SIZE, plcCfg, dataRegionMetrics, 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;
        IndexKeyTypeSettings keyTypeSettings = new IndexKeyTypeSettings().inlineObjHash(false).stringOptimizedCompare(false);
        InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
        ValueJavaObject exp = ValueJavaObject.getNoCopy(new TestPojo(4, 3L), null, null);
        int maxSize = 3 + 3;
        int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
        assertTrue(savedBytesCnt > 0);
        assertTrue(savedBytesCnt <= maxSize);
        maxSize = 3 + exp.getBytesNoCopy().length;
        assertTrue(Arrays.equals(Arrays.copyOf(exp.getBytesNoCopy(), 3), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
        savedBytesCnt = keyType.put(pageAddr, off, idxKey(ValueJavaObject.getNoCopy(null, exp.getBytesNoCopy(), null)), maxSize);
        assertTrue(savedBytesCnt > 0);
        assertTrue(savedBytesCnt <= maxSize);
        assertTrue(Arrays.equals(exp.getBytesNoCopy(), ((JavaObjectIndexKey) keyType.get(pageAddr, off, maxSize)).bytesNoCopy()));
    } finally {
        if (page != 0L)
            pageMem.releasePage(CACHE_ID, pageId, page);
        pageMem.stop(true);
    }
}
Also used : PageMemoryNoStoreImpl(org.apache.ignite.internal.pagemem.impl.PageMemoryNoStoreImpl) StringInlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.types.StringInlineIndexKeyType) InlineIndexKeyType(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) PageMemory(org.apache.ignite.internal.pagemem.PageMemory) DataRegionMetricsImpl(org.apache.ignite.internal.processors.cache.persistence.DataRegionMetricsImpl) JavaObjectIndexKey(org.apache.ignite.internal.cache.query.index.sorted.keys.JavaObjectIndexKey) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) ValueJavaObject(org.h2.value.ValueJavaObject) UnsafeMemoryProvider(org.apache.ignite.internal.mem.unsafe.UnsafeMemoryProvider) IndexKeyTypeSettings(org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings) AbstractIndexingCommonTest(org.apache.ignite.internal.processors.cache.index.AbstractIndexingCommonTest) Test(org.junit.Test)

Example 48 with GridTestKernalContext

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

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);
        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) 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)

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