use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.
the class BPlusTreeSelfTest method createPageMemory.
/**
* @return Page memory.
*/
protected PageMemory createPageMemory() 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())), true);
pageMem.start();
return pageMem;
}
use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.
the class ServiceReassignmentFunctionSelfTest method mockServiceProcessor.
/**
* Mocks IgniteServiceProcessor to test method {@link IgniteServiceProcessor#reassign(IgniteUuid,
* ServiceConfiguration, AffinityTopologyVersion, TreeMap)} AffinityTopologyVersion, Map)} )}.
*/
private IgniteServiceProcessor mockServiceProcessor() {
GridTestKernalContext spyCtx = spy(new GridTestKernalContext(new GridTestLog4jLogger()));
GridEventStorageManager mockEvt = mock(GridEventStorageManager.class);
GridIoManager mockIo = mock(GridIoManager.class);
GridSystemViewManager sysViewMgr = mock(GridSystemViewManager.class);
when(spyCtx.event()).thenReturn(mockEvt);
when(spyCtx.io()).thenReturn(mockIo);
when(spyCtx.systemView()).thenReturn(sysViewMgr);
GridDiscoveryManager mockDisco = mock(GridDiscoveryManager.class);
when(mockDisco.nodes(any(AffinityTopologyVersion.class))).thenReturn(new ArrayList<>(nodes));
spyCtx.add(mockDisco);
return new IgniteServiceProcessor(spyCtx);
}
use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method startSpis.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param queueLimit Message queue limit.
* @throws Exception If failed.
*/
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) 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(ackCnt, idleTimeout, queueLimit);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
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);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
spi.setListener(new TestListener());
node.order(i);
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);
}
}
}
use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.
the class GridAbstractCommunicationSelfTest 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 < getSpiCount(); i++) {
CommunicationSpi<Message> spi = getSpi(i);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
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(new MessageListener(rsrcs.getNodeId()));
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
node.order(i + 1);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
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);
}
}
}
use of org.apache.ignite.testframework.junits.GridTestKernalContext in project ignite by apache.
the class InlineIndexColumnTest method testJavaObjectInlineHash.
/**
*/
@Test
public void testJavaObjectInlineHash() 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().stringOptimizedCompare(false);
InlineIndexKeyType keyType = InlineIndexKeyTypeRegistry.get(Value.JAVA_OBJECT, keyTypeSettings);
Value exp = wrap(new TestPojo(4, 3L), TestPojo.class);
{
int maxSize = 3;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
Assert.assertEquals(0, savedBytesCnt);
}
{
int maxSize = 7;
int savedBytesCnt = keyType.put(pageAddr, off, idxKey(exp), maxSize);
Assert.assertEquals(5, savedBytesCnt);
Assert.assertEquals(exp.getObject().hashCode(), keyType.get(pageAddr, off, maxSize).key().hashCode());
Assert.assertEquals(CANT_BE_COMPARE, keyType.compare(pageAddr, off, maxSize, idxKey(exp)));
}
} finally {
if (page != 0L)
pageMem.releasePage(CACHE_ID, pageId, page);
pageMem.stop(true);
}
}
Aggregations