use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class MockWalIteratorFactory method iterator.
/**
* Creates iterator
* @param wal WAL directory without node consistent id
* @param walArchive WAL archive without node consistent id
* @return iterator
* @throws IgniteCheckedException if IO failed
*/
@SuppressWarnings("unchecked")
public WALIterator iterator(File wal, File walArchive) throws IgniteCheckedException {
final DataStorageConfiguration persistentCfg1 = Mockito.mock(DataStorageConfiguration.class);
when(persistentCfg1.getWalPath()).thenReturn(wal.getAbsolutePath());
when(persistentCfg1.getWalArchivePath()).thenReturn(walArchive.getAbsolutePath());
when(persistentCfg1.getWalSegments()).thenReturn(segments);
when(persistentCfg1.getWalBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_BUFF_SIZE);
when(persistentCfg1.getWalRecordIteratorBufferSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_RECORD_ITERATOR_BUFFER_SIZE);
when(persistentCfg1.getWalSegmentSize()).thenReturn(DataStorageConfiguration.DFLT_WAL_SEGMENT_SIZE);
final FileIOFactory fileIOFactory = new DataStorageConfiguration().getFileIOFactory();
when(persistentCfg1.getFileIOFactory()).thenReturn(fileIOFactory);
final IgniteConfiguration cfg = Mockito.mock(IgniteConfiguration.class);
when(cfg.getDataStorageConfiguration()).thenReturn(persistentCfg1);
final GridKernalContext ctx = Mockito.mock(GridKernalContext.class);
when(ctx.config()).thenReturn(cfg);
when(ctx.clientNode()).thenReturn(false);
when(ctx.pdsFolderResolver()).thenReturn(new PdsFoldersResolver() {
@Override
public PdsFolderSettings resolveFolders() {
return new PdsFolderSettings(new File("."), subfolderName, consistentId, null, false);
}
});
final GridDiscoveryManager disco = Mockito.mock(GridDiscoveryManager.class);
when(ctx.discovery()).thenReturn(disco);
final IgniteWriteAheadLogManager mgr = new FileWriteAheadLogManager(ctx);
final GridCacheSharedContext sctx = Mockito.mock(GridCacheSharedContext.class);
when(sctx.kernalContext()).thenReturn(ctx);
when(sctx.discovery()).thenReturn(disco);
when(sctx.gridConfig()).thenReturn(cfg);
final GridCacheDatabaseSharedManager db = Mockito.mock(GridCacheDatabaseSharedManager.class);
when(db.pageSize()).thenReturn(pageSize);
when(sctx.database()).thenReturn(db);
when(sctx.logger(any(Class.class))).thenReturn(log);
mgr.start(sctx);
return mgr.replay(null);
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class RetryCauseMessageSelfTest method testPartitionedCacheReserveFailureMessage.
/**
* Failed to reserve partitions for query (partition of PARTITIONED cache cannot be reserved)
*/
@Test
public void testPartitionedCacheReserveFailureMessage() {
GridMapQueryExecutor mapQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "mapQryExec");
final GridKernalContext ctx = GridTestUtils.getFieldValue(mapQryExec, GridMapQueryExecutor.class, "ctx");
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", new MockGridMapQueryExecutor() {
@Override
public void onQueryRequest(ClusterNode node, GridH2QueryRequest qryReq) throws IgniteCheckedException {
GridCacheContext<?, ?> cctx = ctx.cache().context().cacheContext(qryReq.caches().get(0));
GridDhtLocalPartition part = cctx.topology().localPartition(0, NONE, false);
AtomicLong aState = GridTestUtils.getFieldValue(part, GridDhtLocalPartition.class, "state");
long stateVal = aState.getAndSet(2);
startedExecutor.onQueryRequest(node, qryReq);
aState.getAndSet(stateVal);
}
}.insertRealExecutor(mapQryExec));
SqlQuery<String, Person> qry = new SqlQuery<String, Person>(Person.class, JOIN_SQL).setArgs("Organization #0");
qry.setDistributedJoins(true);
try {
personCache.query(qry).getAll();
} catch (CacheException e) {
assertTrue(e.getMessage().contains("Failed to reserve partitions for query (partition of PARTITIONED " + "cache is not found or not in OWNING state) "));
return;
} finally {
GridTestUtils.setFieldValue(h2Idx, "mapQryExec", mapQryExec);
}
fail();
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class RetryCauseMessageSelfTest method testUpdateQueryMappingFailureMessage.
/**
* Test update query remap failure reason.
*/
@Test
public void testUpdateQueryMappingFailureMessage() {
final GridReduceQueryExecutor rdcQryExec = GridTestUtils.getFieldValue(h2Idx, IgniteH2Indexing.class, "rdcQryExec");
final ReducePartitionMapper mapper = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "mapper");
final IgniteLogger logger = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "log");
final GridKernalContext ctx = GridTestUtils.getFieldValue(rdcQryExec, GridReduceQueryExecutor.class, "ctx");
GridTestUtils.setFieldValue(rdcQryExec, "mapper", new ReducePartitionMapper(ctx, logger) {
@Override
public ReducePartitionMapResult nodesForPartitions(List<Integer> cacheIds, AffinityTopologyVersion topVer, int[] parts, boolean isReplicatedOnly) {
final ReducePartitionMapResult res = super.nodesForPartitions(cacheIds, topVer, parts, isReplicatedOnly);
return new ReducePartitionMapResult(Collections.emptyList(), res.partitionsMap(), res.queryPartitionsMap());
}
});
try {
final SqlFieldsQueryEx qry = new SqlFieldsQueryEx(UPDATE_SQL, false).setArgs("New Name");
GridTestUtils.assertThrows(log, () -> {
return personCache.query(qry).getAll();
}, CacheException.class, "Failed to map SQL query to topology during timeout");
qry.setArgs("Another Name");
qry.setSkipReducerOnUpdate(true);
GridTestUtils.assertThrows(log, () -> {
return personCache.query(qry).getAll();
}, CacheException.class, "Failed to determine nodes participating in the update. ");
} finally {
GridTestUtils.setFieldValue(rdcQryExec, "mapper", mapper);
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class GridH2IndexBase method initDistributedJoinMessaging.
/**
* @param tbl Table.
*/
protected final void initDistributedJoinMessaging(GridH2Table tbl) {
final GridH2RowDescriptor desc = tbl.rowDescriptor();
if (desc != null && desc.context() != null) {
ctx = desc.context();
GridKernalContext ctx = desc.context().kernalContext();
log = ctx.log(getClass());
msgTopic = new IgniteBiTuple<>(GridTopic.TOPIC_QUERY, tbl.identifierString() + '.' + getName());
msgLsnr = new GridMessageListener() {
@Override
public void onMessage(UUID nodeId, Object msg, byte plc) {
GridSpinBusyLock l = desc.indexing().busyLock();
if (!l.enterBusy())
return;
try {
onMessage0(nodeId, msg);
} finally {
l.leaveBusy();
}
}
};
ctx.io().addMessageListener(msgTopic, msgLsnr);
} else {
msgTopic = null;
msgLsnr = null;
log = new NullLogger();
}
}
use of org.apache.ignite.internal.GridKernalContext in project ignite by apache.
the class IgfsServerManagerIpcEndpointRegistrationAbstractSelfTest method checkRegisteredIpcEndpoints.
/**
* Counts all registered IPC endpoints.
*
* @return Tuple2 where (tcp endpoints count, shmem endpoints count).
* @throws Exception If failed.
*/
protected T2<Integer, Integer> checkRegisteredIpcEndpoints() throws Exception {
GridKernalContext ctx = ((IgniteKernal) grid()).context();
int tcp = 0;
int shmem = 0;
for (GridPortRecord record : ctx.ports().records()) {
if (record.clazz() == IpcSharedMemoryServerEndpoint.class)
shmem++;
else if (record.clazz() == IpcServerTcpEndpoint.class)
tcp++;
}
return new T2<>(tcp, shmem);
}
Aggregations