下面列出了org.mockito.internal.matchers.apachecommons.ReflectionEquals#org.apache.ignite.internal.IgniteEx 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** @throws Exception If failed. */
@Test
public void testFailureHandledOnFailPerformMasterKeyChange() throws Exception {
T2<IgniteEx, IgniteEx> grids = startTestGrids(true);
assertTrue(checkMasterKeyName(DEFAULT_MASTER_KEY_NAME));
grids.get2().context().discovery().setCustomEventListener(FullMessage.class,
(topVer, snd, msg) -> simulateSetMasterKeyError.set(true));
// Expected successful completing the future in case of successful completition of prepare phase and fail
// of the perform phase.
grids.get1().encryption().changeMasterKey(MASTER_KEY_NAME_2).get();
assertNotNull(failure.get());
assertTrue(X.hasCause(failure.get(), "Test error.", IgniteSpiException.class));
}
/**
* Test imports CSV file into a table on not affinity node and checks the created entries using SELECT statement.
*
* @throws SQLException If failed.
*/
@Test
public void testBulkLoadToNonAffinityNode() throws Exception {
IgniteEx client = startClientGrid(getConfiguration("client"));
try (Connection con = connect(client, null)) {
con.setSchema('"' + DEFAULT_CACHE_NAME + '"');
try (Statement stmt = con.createStatement()) {
int updatesCnt = stmt.executeUpdate(
"copy from '" + BULKLOAD_UTF8_CSV_FILE + "' into " + TBL_NAME +
" (_key, age, firstName, lastName)" +
" format csv");
assertEquals(2, updatesCnt);
checkNationalCacheContents(TBL_NAME);
}
}
stopGrid(client.name());
}
/** */
private void checkNextSegmentType(WALMode mode, boolean disableArch) throws Exception {
walMode = mode;
disableWALArchiving = disableArch;
IgniteEx ig = startGrid(0);
ig.cluster().active(true);
IgniteWriteAheadLogManager walMgr = ig.context().cache().context().wal();
ig.context().cache().context().database().checkpointReadLock();
try {
WALPointer ptr = walMgr.log(new AdHocWALRecord(), NEXT_SEGMENT);
assertEquals(1, ((FileWALPointer)ptr).index());
}
finally {
ig.context().cache().context().database().checkpointReadUnlock();
}
}
/**
*
*/
@Test
public void testExchangeOnNodeJoin() throws Exception {
for (int i = 0; i < SF.applyLB(5, 2); i++) {
startGrids(2);
IgniteEx ignite = grid(1);
ignite.active(true);
awaitPartitionMapExchange();
IgniteEx ex = startGrid(2);
awaitPartitionMapExchange();
ex.context().cache().context().database().wakeupForCheckpoint("test").get(10000);
afterTest();
}
}
/**
* Tests that thread dumps will get for every failure for disabled throttling.
*/
@Test
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE, value = "true")
@WithSystemProperty(key = IgniteSystemProperties.IGNITE_DUMP_THREADS_ON_FAILURE_THROTTLING_TIMEOUT, value = "0")
public void testNoThrottling() throws Exception {
LogListener lsnr = LogListener.matches(THREAD_DUMP_MSG).times(2).build();
testLog.registerListener(lsnr);
IgniteEx ignite = ignite(0);
FailureContext failureCtx =
new FailureContext(SYSTEM_WORKER_BLOCKED, new Throwable("Failure context error"));
for (int i = 0; i < 2; i++)
ignite.context().failure().process(failureCtx);
assertTrue(lsnr.check());
}
/** Start node from builder */
public IgniteEx start() throws Exception {
IgniteConfiguration cfg = getConfiguration(gridName);
cfg.setConsistentId(gridName);
DataStorageConfiguration storageCfg = new DataStorageConfiguration();
storageCfg.setDataRegionConfigurations(regions.toArray(new DataRegionConfiguration[regions.size()]));
cfg.setDataStorageConfiguration(storageCfg);
if (dfltRegionConfiguration != null)
storageCfg.setDefaultDataRegionConfiguration(dfltRegionConfiguration);
cfg.setCacheConfiguration(caches.toArray(new CacheConfiguration[caches.size()]));
return startGrid(cfg);
}
/**
* Test OOME in IgniteCompute.
*/
@Test
public void testComputeOomError() throws Exception {
IgniteEx ignite0 = startGrid(0);
IgniteEx ignite1 = startGrid(1);
try {
IgniteFuture<Boolean> res = ignite0.compute(ignite0.cluster().forNodeId(ignite1.cluster().localNode().id()))
.callAsync(new IgniteCallable<Boolean>() {
@Override public Boolean call() throws Exception {
throw new OutOfMemoryError();
}
});
res.get();
}
catch (Throwable ignore) {
// Expected.
}
assertFailureState(ignite0, ignite1);
}
/**
* Check cleanup running queries on node stop.
*
* @throws Exception Exception in case of failure.
*/
@Test
public void testCloseRunningQueriesOnNodeStop() throws Exception {
IgniteEx ign = startGrid(super.getConfiguration("TST"));
IgniteCache<Integer, Integer> cache = ign.getOrCreateCache(new CacheConfiguration<Integer, Integer>()
.setName("TST")
.setQueryEntities(Collections.singletonList(new QueryEntity(Integer.class, Integer.class)))
);
for (int i = 0; i < 10000; i++)
cache.put(i, i);
cache.query(new SqlFieldsQuery("SELECT * FROM Integer order by _key"));
Assert.assertEquals("Should be one running query",
1,
ign.context().query().runningQueries(-1).size());
ign.close();
Assert.assertEquals(0, ign.context().query().runningQueries(-1).size());
}
/**
* Resets all io statistics.
*
* @param ignite Ignite.
*/
public static void resetAllIoMetrics(IgniteEx ignite) throws MalformedObjectNameException {
GridMetricManager mmgr = ignite.context().metric();
StreamSupport.stream(mmgr.spliterator(), false)
.map(ReadOnlyMetricRegistry::name)
.filter(name -> {
for (IoStatisticsType type : IoStatisticsType.values()) {
if (name.startsWith(type.metricGroupName()))
return true;
}
return false;
})
.forEach(grpName -> resetMetric(ignite, grpName));
}
/**
* Registers a security subject referred for {@code localIgnite} with the passed operation name and increments
* invoke counter.
*
* @param opName Operation name.
*/
public void register(String opName) {
if (expSecSubjId == null) {
error("SubjectId cannot be null.");
return;
}
IgniteEx ignite = localIgnite();
UUID actualSubjId = secSubjectId(ignite);
if (!expSecSubjId.equals(actualSubjId)) {
error("Actual subjectId does not equal expected subjectId " + "[expected=" + expSecSubjId +
", actual=" + actualSubjId + "].");
return;
}
T2<Integer, AtomicInteger> v = expInvokes.get(new T2<>(ignite.name(), opName));
if (v != null)
v.get2().incrementAndGet();
else
error("Unexpected registration parameters [node=" + ignite.name() + ", opName=" + opName + "].");
}
/**
* Blocks sending full message from coordinator to non-coordinator node.
*
* @param from Coordinator node.
* @param pred Non-coordinator node predicate.
* If predicate returns {@code true} a full message will not be send to that node.
*/
private void blockSendingFullMessage(IgniteEx from, Predicate<ClusterNode> pred) {
// Block FullMessage for newly joined nodes.
TestRecordingCommunicationSpi spi = TestRecordingCommunicationSpi.spi(from);
// Delay sending full messages (without exchange id).
spi.blockMessages((node, msg) -> {
if (msg instanceof GridDhtPartitionsFullMessage) {
GridDhtPartitionsFullMessage fullMsg = (GridDhtPartitionsFullMessage) msg;
if (fullMsg.exchangeId() != null && pred.test(node)) {
log.warning("Blocked sending " + msg + " to " + node);
return true;
}
}
return false;
});
}
/**
* Checks that cache contexts have consistent parameters after recovery finished and nodes have joined to topology.
*/
private void checkCacheContextsConsistencyAfterRecovery() throws Exception {
IgniteEx crd = grid(0);
Collection<String> cacheNames = crd.cacheNames();
for (String cacheName : cacheNames) {
for (int nodeIdx = 1; nodeIdx < 3; nodeIdx++) {
IgniteEx node = grid(nodeIdx);
GridCacheContext one = cacheContext(crd, cacheName);
GridCacheContext other = cacheContext(node, cacheName);
checkCacheContextsConsistency(one, other);
}
}
}
/**
* @param name Name.
* @throws Exception If failed.
*/
private void checkSingletonUpdateTopology(String name) throws Exception {
IgniteEx g = randomGrid();
startExtraNodes(2, 2);
try {
assertEquals(name, 0, DummyService.started(name));
assertEquals(name, 0, DummyService.cancelled(name));
info(">>> Passed checks.");
checkCount(name, g, 1);
}
finally {
stopExtraNodes(4);
}
}
/**
* @param ignite Ignite to execute task on.
* @param delFoundGarbage If clearing mode should be used.
* @return Result of task run.
*/
private VisorFindAndDeleteGarbageInPersistenceTaskResult executeTaskViaControlConsoleUtil(
IgniteEx ignite,
boolean delFoundGarbage
) {
CommandHandler hnd = new CommandHandler();
List<String> args = new ArrayList<>(Arrays.asList("--yes", "--port", "11212", "--cache", "find_garbage",
ignite.localNode().id().toString()));
if (delFoundGarbage)
args.add(FindAndDeleteGarbageArg.DELETE.argName());
hnd.execute(args);
return hnd.getLastOperationResult();
}
/**
* @throws Exception On error.
*/
@Test
public void testPut() throws Exception {
IgniteEx ign = startGrid(0);
IgniteCache<Object, Object> cache = ign.createCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME)
.setAtomicityMode(atomicity())
.setIndexedTypes(Integer.class, Integer.class));
Thread t = new Thread(() -> {
cache.put(1, 1);
});
t.start();
t.interrupt();
t.join();
assertEquals(cache.size(), cache.query(new SqlFieldsQuery("select * from Integer")).getAll().size());
}
/** {@inheritDoc} */
@Override protected void updateCache(IgniteEx ignite, IgniteCache cache) {
final int k = ThreadLocalRandom.current().nextInt(RANGE);
final String[] keys = new String[KEYS_CNT];
for (int i = 0; i < keys.length; i++)
keys[i] = "key-" + k + "-" + i;
for (String key : keys) {
cache.invoke(key, new IncrementCacheEntryProcessor());
AtomicLong prevVal = map.putIfAbsent(key, new AtomicLong(0));
if (prevVal != null)
prevVal.incrementAndGet();
}
}
/**
*
*/
private void assertCaches(IgniteEx igniteEx) {
for (int i = 0; i < GROUPS_COUNT; i++) {
Collection<GridCacheContext> caches = igniteEx
.context()
.cache()
.cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME + i))
.caches();
assertEquals(CACHES_COUNT / GROUPS_COUNT, caches.size());
@Nullable CacheGroupContext cacheGrp = igniteEx
.context()
.cache()
.cacheGroup(CU.cacheId(STATIC_CACHE_CACHE_GROUP_NAME + i));
for (GridCacheContext cacheContext : caches)
assertEquals(cacheContext.group(), cacheGrp);
}
}
/**
* @param skipCheckpointOnStop Skip checkpoint on stop.
* @param name Grid instance.
*/
protected void stopGrid(boolean skipCheckpointOnStop, String name) {
IgniteEx grid = grid(name);
if (skipCheckpointOnStop) {
GridCacheDatabaseSharedManager db =
(GridCacheDatabaseSharedManager)grid.context().cache().context().database();
db.enableCheckpoints(false);
}
stopGrid(grid.name(), skipCheckpointOnStop);
}
/**
* @return Node ID message.
*/
private NodeIdMessage nodeIdMessage() {
final UUID locNodeId = (ignite instanceof IgniteEx) ? ((IgniteEx)ignite).context().localNodeId() :
safeLocalNodeId();
return new NodeIdMessage(locNodeId);
}
/**
* Verifies that affinity mappings are the same on clients and servers.
*/
private void verifyPartitionToNodeMappings() {
IgniteEx refSrv = grid(0);
String cacheName;
for (int i = 0; i < CACHES; i++) {
cacheName = "cache-" + i;
Affinity<Object> refAffinity = refSrv.affinity(cacheName);
for (int j = 0; j < PARTITIONS_CNT; j++) {
ClusterNode refAffNode = refAffinity.mapPartitionToNode(j);
assertNotNull("Affinity node for " + j + " partition is null", refAffNode);
for (int k = SRV_CNT; k < SRV_CNT + CLIENTS_CNT; k++) {
ClusterNode clAffNode = grid(k).affinity(cacheName).mapPartitionToNode(j);
assertNotNull("Affinity node for " + k + " client and " + j + " partition is null", clAffNode);
assertEquals("Affinity node for "
+ k
+ " client and "
+ j
+ " partition is different on client",
refAffNode.id(),
clAffNode.id());
}
}
}
}
/** {@inheritDoc} */
@Override protected void beforeTestsStarted() throws Exception {
super.beforeTestsStarted();
IgniteEx grid = startGrid(0);
execute(grid, "CREATE TABLE " + DEC_TAB_NAME +
"(id LONG PRIMARY KEY, " + VALUE + " DECIMAL(" + PRECISION + ", " + SCALE + "))");
String insertQry = "INSERT INTO " + DEC_TAB_NAME + " VALUES (?, ?)";
execute(grid, insertQry, 1, VAL_1);
execute(grid, insertQry, 2, VAL_2);
execute(grid, insertQry, 3, VAL_3);
}
/**
*
*/
private void disableCheckpoints(IgniteEx g) throws Exception {
GridCacheDatabaseSharedManager dbMgr = (GridCacheDatabaseSharedManager)g.context()
.cache().context().database();
dbMgr.enableCheckpoints(false).get();
}
/**
* @param ignite An ignite instance.
* @param cacheName Cache name.
* @return The cache working directory.
*/
private File cacheWorkDir(IgniteEx ignite, String cacheName) {
// Resolve cache directory.
IgniteInternalCache<?, ?> cache = ignite.cachex(cacheName);
FilePageStoreManager pageStoreMgr = (FilePageStoreManager)cache.context()
.shared()
.pageStore();
return pageStoreMgr.cacheWorkDir(cache.configuration());
}
/**
* Checks simple launch with native IO.
* @throws Exception if failed
*/
@Test
public void testDirectIoHandlesNoPersistentGrid() throws Exception {
IgniteEx ignite = startGrid(0);
ignite.active(true);
IgniteCache<Object, Object> cache = ignite.getOrCreateCache("cache");
for (int i = 0; i < 100; i++)
cache.put(i, valueForKey(i));
stopAllGrids();
}
/**
* @param grids Number of ignite instances.
* @return Coordinator ignite instance.
* @throws Exception If fails.
*/
protected IgniteEx startGridsWithoutCache(int grids) throws Exception {
for (int i = 0; i < grids; i++)
startGrid(optimize(getConfiguration(getTestIgniteInstanceName(i)).setCacheConfiguration()));
IgniteEx ignite = grid(0);
ignite.cluster().baselineAutoAdjustEnabled(false);
ignite.cluster().state(ClusterState.ACTIVE);
return ignite;
}
/** */
@Test
public void testLocalPreloadPartitionClientMvcc() throws Exception {
cfgFactory = () -> cacheConfiguration(TRANSACTIONAL_SNAPSHOT).setDataRegionName(MEM);
startGridsMultiThreaded(GRIDS_CNT);
IgniteEx client = startClientGrid(CLIENT_GRID_NAME);
assertNotNull(client.cache(DEFAULT_CACHE_NAME));
assertFalse(client.cache(DEFAULT_CACHE_NAME).localPreloadPartition(0));
assertFalse(grid(0).cache(DEFAULT_CACHE_NAME).localPreloadPartition(0));
}
/**
* @param ignite Ignite.
*/
public AggregateCacheLoader(IgniteEx ignite) {
this.ignite = ignite;
List<CacheLoader> cacheLoaders = new ArrayList<>();
for (String cacheName : ignite.cacheNames())
cacheLoaders.add(new CacheLoader(ignite, cacheName));
this.cacheLoaders = cacheLoaders;
}
/** */
@Test
public void testSelectDecimal() throws Exception {
IgniteEx grid = grid(0);
List rows = execute(grid, "SELECT id, value FROM " + DEC_TAB_NAME + " order by id");
assertEquals(rows.size(), 3);
assertEquals(asList(1L, VAL_1), rows.get(0));
assertEquals(asList(2L, VAL_2), rows.get(1));
assertEquals(asList(3L, VAL_3), rows.get(2));
}
/**
* @throws Exception If failed.
*/
@Test
public void testSelectProducesTransaction() throws Exception {
ccfg = cacheConfiguration(cacheMode(), FULL_SYNC, 2, DFLT_PARTITION_COUNT)
.setIndexedTypes(Integer.class, MvccTestSqlIndexValue.class);
startGridsMultiThreaded(4);
Random rnd = ThreadLocalRandom.current();
Ignite node = grid(rnd.nextInt(4));
IgniteCache<Object, Object> cache = node.cache(DEFAULT_CACHE_NAME);
SqlFieldsQuery qry = new SqlFieldsQuery("INSERT INTO MvccTestSqlIndexValue (_key, idxVal1) values (1,1),(2,2),(3,3)");
try (FieldsQueryCursor<List<?>> cur = cache.query(qry)) {
assertEquals(3L, cur.iterator().next().get(0));
}
SqlFieldsQueryEx qryEx = new SqlFieldsQueryEx("SELECT * FROM MvccTestSqlIndexValue", true);
qryEx.setAutoCommit(false);
try (FieldsQueryCursor<List<?>> cur = cache.query(qryEx)) {
assertEquals(3, cur.getAll().size());
}
try (GridNearTxLocal tx = cache.unwrap(IgniteEx.class).context().cache().context().tm().userTx()) {
assertNotNull(tx);
}
}
/**
* @throws Exception if failed.
*/
@Test
public void testLostPartitionsOnLeaveBaseline() throws Exception {
try {
final IgniteEx gridFirst = startGrid(0);
startGrid(1);
gridFirst.cluster().active(true);
gridFirst.getOrCreateCaches(Arrays.asList(
cacheConfiguration("cache-no-persistence", PARTITIONED, ATOMIC, "no-persistence"),
cacheConfiguration("cache-persistence", PARTITIONED, ATOMIC, null)
));
IgniteInternalCache<Object, Object> cacheNoPersistence = gridFirst.cachex("cache-no-persistence");
IgniteInternalCache<Object, Object> cachePersistence = gridFirst.cachex("cache-persistence");
for (int i = 0; i < 10; i++) {
cacheNoPersistence.put(i, i);
cachePersistence.put(i, i);
}
stopGrid(1);
resetBaselineTopology();
assertTrue("List of lost partitions for cache without persistence should not be empty.",
!cacheNoPersistence.context().topology().lostPartitions().isEmpty());
assertTrue("List of lost partitions for cache with persistence should not be empty.",
!cachePersistence.context().topology().lostPartitions().isEmpty());
} finally {
stopAllGrids();
}
}