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