You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ir...@apache.org on 2020/06/05 18:01:18 UTC
[ignite] branch master updated: IGNITE-13071 Improve test coverage
for read-only cluster state - Fixes #7853.
This is an automated email from the ASF dual-hosted git repository.
irakov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push:
new 7dd45dd IGNITE-13071 Improve test coverage for read-only cluster state - Fixes #7853.
7dd45dd is described below
commit 7dd45dd494d5ff2bfc63c0a53bb6429ba9b4345e
Author: Sergey Antonov <an...@gmail.com>
AuthorDate: Fri Jun 5 21:00:26 2020 +0300
IGNITE-13071 Improve test coverage for read-only cluster state - Fixes #7853.
Signed-off-by: Ivan Rakov <iv...@gmail.com>
---
.../processors/cache/ClusterCachesInfo.java | 75 ++-
.../processors/cache/GridCacheAdapter.java | 6 +
.../processors/cache/GridCacheProcessor.java | 113 ++++-
.../dht/GridDhtTopologyFutureAdapter.java | 8 +-
.../GridCacheAtomicSequenceImpl.java | 9 +
.../main/resources/META-INF/classnames.properties | 1 +
...eateDestroyClusterReadOnlyModeAbstractTest.java | 45 ++
.../CacheCreateDestroyClusterReadOnlyModeTest.java | 186 ++++++++
.../cache/ClusterReadOnlyModeTestUtils.java | 87 ++--
...IgniteCacheClusterReadOnlyModeAbstractTest.java | 263 ++++++++++
.../IgniteCacheClusterReadOnlyModeSelfTest.java | 531 +++++++++++++++++++++
...niteCacheInvokeClusterReadOnlyModeSelfTest.java | 141 ++++++
...gniteCacheStoreClusterReadOnlyModeSelfTest.java | 302 ++++++++++++
...usterActivateDeactivateTestWithPersistence.java | 8 +-
...IgniteNearCacheClusterReadOnlyModeSelfTest.java | 33 ++
...NearCacheInvokeClusterReadOnlyModeSelfTest.java | 35 ++
.../IgniteAtomicLongClusterReadOnlyTest.java | 150 ++++++
.../IgniteAtomicReferenceClusterReadOnlyTest.java | 114 +++++
.../IgniteAtomicSequenceClusterReadOnlyTest.java | 126 +++++
.../IgniteAtomicStampedClusterReadOnlyTest.java | 132 +++++
...niteCollectionsClusterReadOnlyAbstractTest.java | 227 +++++++++
.../IgniteCountDownLatchClusterReadOnlyTest.java | 129 +++++
...tructuresCreateDeniedInClusterReadOnlyMode.java | 156 ++++++
.../IgniteDataStructuresTestUtils.java | 129 +++++
.../IgniteQueueClusterReadOnlyTest.java | 91 ++++
.../IgniteSetClusterReadOnlyTest.java | 62 +++
.../cluster/ClusterReadOnlyModeSelfTest.java | 57 ++-
.../GridServiceClusterReadOnlyModeTest.java | 114 +++++
.../GridServiceDeployClusterReadOnlyModeTest.java | 393 +++++++++++++++
.../IgniteCacheDataStructuresSelfTestSuite.java | 17 +
.../IgniteCacheFullApiSelfTestSuite.java | 11 +
.../testsuites/IgniteCacheMvccTestSuite5.java | 2 +
.../ignite/testsuites/IgniteCacheTestSuite5.java | 2 +
.../testsuites/IgniteServiceGridTestSuite.java | 4 +
.../GridCacheSqlDdlClusterReadOnlyModeTest.java | 172 +++++++
.../IgniteCacheWithIndexingTestSuite.java | 2 +
36 files changed, 3843 insertions(+), 90 deletions(-)
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
index a21fbc8..58e3afa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/ClusterCachesInfo.java
@@ -55,13 +55,13 @@ import org.apache.ignite.internal.managers.encryption.GridEncryptionManager;
import org.apache.ignite.internal.managers.systemview.walker.CacheGroupViewWalker;
import org.apache.ignite.internal.managers.systemview.walker.CacheViewWalker;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateFinishMessage;
import org.apache.ignite.internal.processors.cluster.ChangeGlobalStateMessage;
import org.apache.ignite.internal.processors.cluster.DiscoveryDataClusterState;
import org.apache.ignite.internal.processors.query.QuerySchema;
import org.apache.ignite.internal.processors.query.QuerySchemaPatch;
import org.apache.ignite.internal.processors.query.QueryUtils;
-import org.apache.ignite.internal.processors.query.schema.SchemaOperationException;
import org.apache.ignite.internal.util.lang.GridFunc;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.T2;
@@ -84,6 +84,7 @@ import static org.apache.ignite.cache.CacheMode.LOCAL;
import static org.apache.ignite.cache.CacheMode.PARTITIONED;
import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
import static org.apache.ignite.internal.GridComponent.DiscoveryDataExchangeType.CACHE_PROC;
+import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT;
import static org.apache.ignite.internal.processors.cache.persistence.snapshot.IgniteSnapshotManager.SNP_IN_PROGRESS_ERR_MSG;
/**
@@ -960,59 +961,53 @@ public class ClusterCachesInfo {
DynamicCacheChangeRequest req,
String cacheName
) {
- String conflictErr = checkCacheConflict(req.startCacheConfiguration());
-
- if (conflictErr != null) {
- U.warn(log, "Ignore cache start request. " + conflictErr);
-
- IgniteCheckedException err = new IgniteCheckedException("Failed to start " +
- "cache. " + conflictErr);
+ CacheConfiguration<?, ?> ccfg = req.startCacheConfiguration();
- if (persistedCfgs)
- res.errs.add(err);
- else
- ctx.cache().completeCacheStartFuture(req, false, err);
+ IgniteCheckedException err = null;
- return false;
+ if (ctx.cache().context().readOnlyMode()) {
+ err = new IgniteClusterReadOnlyException(
+ String.format(CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT, "start cache", ccfg.getGroupName(), cacheName)
+ );
}
- SchemaOperationException err = QueryUtils.checkQueryEntityConflicts(
- req.startCacheConfiguration(), registeredCaches.values());
+ if (err == null) {
+ String conflictErr = checkCacheConflict(req.startCacheConfiguration());
- if (err != null) {
- if (persistedCfgs)
- res.errs.add(err);
- else
- ctx.cache().completeCacheStartFuture(req, false, err);
+ if (conflictErr != null) {
+ U.warn(log, "Ignore cache start request. " + conflictErr);
- return false;
+ err = new IgniteCheckedException("Failed to start cache. " + conflictErr);
+ }
}
- CacheConfiguration<?, ?> ccfg = req.startCacheConfiguration();
+ if (err == null)
+ err = QueryUtils.checkQueryEntityConflicts(req.startCacheConfiguration(), registeredCaches.values());
- GridEncryptionManager encMgr = ctx.encryption();
+ if (err == null) {
+ GridEncryptionManager encMgr = ctx.encryption();
- if (ccfg.isEncryptionEnabled()) {
- IgniteCheckedException error = null;
+ if (ccfg.isEncryptionEnabled()) {
+ if (encMgr.isMasterKeyChangeInProgress())
+ err = new IgniteCheckedException("Cache start failed. Master key change is in progress.");
+ else if (encMgr.masterKeyDigest() != null &&
+ !Arrays.equals(encMgr.masterKeyDigest(), req.masterKeyDigest())) {
+ err = new IgniteCheckedException("Cache start failed. The request was initiated before " +
+ "the master key change and can't be processed.");
+ }
- if (encMgr.isMasterKeyChangeInProgress())
- error = new IgniteCheckedException("Cache start failed. Master key change is in progress.");
- else if (encMgr.masterKeyDigest() != null &&
- !Arrays.equals(encMgr.masterKeyDigest(), req.masterKeyDigest())) {
- error = new IgniteCheckedException("Cache start failed. The request was initiated before " +
- "the master key change and can't be processed.");
+ if (err != null)
+ U.warn(log, "Ignore cache start request during the master key change process.", err);
}
+ }
- if (error != null) {
- U.warn(log, "Ignore cache start request during the master key change process.", error);
-
- if (persistedCfgs)
- res.errs.add(error);
- else
- ctx.cache().completeCacheStartFuture(req, false, error);
+ if (err != null) {
+ if (persistedCfgs)
+ res.errs.add(err);
+ else
+ ctx.cache().completeCacheStartFuture(req, false, err);
- return false;
- }
+ return false;
}
assert req.cacheType() != null : req;
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index bb384d0..070ffdd 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -1239,6 +1239,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
//TODO IGNITE-7952
MvccUtils.verifyMvccOperationSupport(ctx, "Clear");
+ ctx.shared().cache().checkReadOnlyState("clear", ctx.config());
+
if (isLocal()) {
if (keys == null)
clearLocally(true, false, false);
@@ -1259,6 +1261,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
//TODO IGNITE-7952
MvccUtils.verifyMvccOperationSupport(ctx, "Clear");
+ ctx.shared().cache().checkReadOnlyState("clear", ctx.config());
+
if (isLocal())
return clearLocallyAsync(keys);
else
@@ -4754,6 +4758,8 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
* @param readers Whether to clear readers.
*/
private boolean clearLocally0(K key, boolean readers) {
+ ctx.shared().cache().checkReadOnlyState("clear", ctx.config());
+
//TODO IGNITE-7952
MvccUtils.verifyMvccOperationSupport(ctx, "Clear");
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index ef48b51..060555b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -40,6 +40,7 @@ import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
+import javax.cache.CacheException;
import javax.management.MBeanServer;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
@@ -53,6 +54,7 @@ import org.apache.ignite.cache.affinity.AffinityFunctionContext;
import org.apache.ignite.cache.store.CacheStore;
import org.apache.ignite.cache.store.CacheStoreSessionListener;
import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterState;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
@@ -85,6 +87,7 @@ import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProce
import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCache;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
import org.apache.ignite.internal.processors.cache.distributed.dht.atomic.GridDhtAtomicCache;
import org.apache.ignite.internal.processors.cache.distributed.dht.colocated.GridDhtColocatedCache;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.StopCachesOnClientReconnectExchangeTask;
@@ -163,6 +166,7 @@ import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgniteFuture;
import org.apache.ignite.lang.IgniteInClosure;
+import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.lifecycle.LifecycleAware;
@@ -180,6 +184,7 @@ import org.apache.ignite.spi.systemview.view.CachePagesListView;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
+import static java.lang.String.format;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_CACHE_REMOVED_ENTRIES_TTL;
import static org.apache.ignite.IgniteSystemProperties.IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK;
import static org.apache.ignite.IgniteSystemProperties.getBoolean;
@@ -206,6 +211,10 @@ import static org.apache.ignite.internal.util.IgniteUtils.doInParallel;
@SuppressWarnings({"unchecked", "TypeMayBeWeakened", "deprecation"})
public class GridCacheProcessor extends GridProcessorAdapter {
/** */
+ public static final String CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT =
+ "Failed to perform %s operation (cluster is in read-only mode) [cacheGrp=%s, cache=%s]";
+
+ /** */
private static final String CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT =
"Cannot start/stop cache within lock or transaction [cacheNames=%s, operation=%s]";
@@ -3439,7 +3448,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (checkThreadTx) {
sharedCtx.tm().checkEmptyTransactions(
- () -> String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicStartCache"));
+ () -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicStartCache"));
}
GridPlainClosure2<Collection<byte[]>, byte[], IgniteInternalFuture<Boolean>> startCacheClsr =
@@ -3485,6 +3494,93 @@ public class GridCacheProcessor extends GridProcessorAdapter {
}
/**
+ * Checks that cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ *
+ * @param opName Operation name.
+ * @param cfgs Stored cache configurations.
+ * @throws CacheException If cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+ private void checkReadOnlyState(String opName, Collection<StoredCacheData> cfgs) {
+ IgniteOutClosure<String> cacheNameClo = null;
+ IgniteOutClosure<String> cacheGrpNameClo = null;
+
+ if (!F.isEmpty(cfgs)) {
+ if (cfgs.size() == 1) {
+ CacheConfiguration cfg = cfgs.iterator().next().config();
+
+ cacheNameClo = cfg::getName;
+ cacheGrpNameClo = cfg::getGroupName;
+ }
+ else {
+ cacheNameClo = () -> cfgs.stream()
+ .map(StoredCacheData::config)
+ .map(CacheConfiguration::getName)
+ .collect(Collectors.toList()).toString();
+
+ cacheGrpNameClo = () -> cfgs.stream()
+ .map(StoredCacheData::config)
+ .map(CacheConfiguration::getGroupName)
+ .collect(Collectors.toList()).toString();
+ }
+ }
+
+ checkReadOnlyState(opName, cacheGrpNameClo, cacheNameClo);
+ }
+
+ /**
+ * Checks that cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ *
+ * @param opName Operation name.
+ * @param cfgs Cache configurations.
+ * @throws CacheException If cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+ public void checkReadOnlyState(String opName, CacheConfiguration... cfgs) {
+ IgniteOutClosure<String> cacheNameClo = null;
+ IgniteOutClosure<String> cacheGrpNameClo = null;
+
+ if (!F.isEmpty(cfgs)) {
+ if (cfgs.length == 1) {
+ cacheNameClo = () -> cfgs[0] == null ? null : cfgs[0].getName();
+ cacheGrpNameClo = () -> cfgs[0] == null ? null : cfgs[0].getGroupName();
+ }
+ else {
+ cacheNameClo = () -> Stream.of(cfgs)
+ .map(CacheConfiguration::getName)
+ .collect(Collectors.toList()).toString();
+
+ cacheGrpNameClo = () -> Stream.of(cfgs)
+ .map(CacheConfiguration::getGroupName)
+ .collect(Collectors.toList()).toString();
+ }
+ }
+
+ checkReadOnlyState(opName, cacheGrpNameClo, cacheNameClo);
+ }
+
+ /**
+ * Checks that cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ *
+ * @param opName Operation name.
+ * @param cacheGrpNameClo Closure for getting cache group name, if it needed (optional).
+ * @param cacheNameClo Closure for getting cache name, if it needed (optional).
+ * @throws CacheException If cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+ private void checkReadOnlyState(
+ String opName,
+ @Nullable IgniteOutClosure<String> cacheGrpNameClo,
+ @Nullable IgniteOutClosure<String> cacheNameClo
+ ) {
+ if (sharedCtx.readOnlyMode()) {
+ String cacheName = cacheNameClo == null ? null : cacheNameClo.apply();
+ String cacheGrpName = cacheGrpNameClo == null ? null : cacheGrpNameClo.apply();
+
+ String errorMsg = format(CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT, opName, cacheGrpName, cacheName);
+
+ throw new CacheException(new IgniteClusterReadOnlyException(errorMsg));
+ }
+ }
+
+ /**
* Send {@code GenerateEncryptionKeyRequest} and execute {@code after} closure if succeed.
*
* @param keyCnt Count of keys to generate.
@@ -3599,7 +3695,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
.map(CacheConfiguration::getName)
.collect(Collectors.toList());
- return String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "dynamicStartCachesByStoredConf");
+ return format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "dynamicStartCachesByStoredConf");
});
}
@@ -3707,9 +3803,11 @@ public class GridCacheProcessor extends GridProcessorAdapter {
if (checkThreadTx) {
sharedCtx.tm().checkEmptyTransactions(
- () -> String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicDestroyCache"));
+ () -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicDestroyCache"));
}
+ checkReadOnlyState("dynamic destroy cache", null, cacheName::toString);
+
DynamicCacheChangeRequest req = DynamicCacheChangeRequest.stopRequest(ctx, cacheName, sql, true);
req.stop(true);
@@ -3742,9 +3840,12 @@ public class GridCacheProcessor extends GridProcessorAdapter {
) {
if (checkThreadTx) {
sharedCtx.tm().checkEmptyTransactions(
- () -> String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "dynamicDestroyCaches"));
+ () -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "dynamicDestroyCaches"));
}
+ if (!F.isEmpty(cacheNames))
+ checkReadOnlyState("dynamic destroy caches", null, cacheNames::toString);
+
return dynamicChangeCaches(
cacheNames.stream().map(cacheName -> createStopRequest(cacheName, false, null, destroy))
.collect(Collectors.toList())
@@ -3794,7 +3895,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
return new GridFinishedFuture<>(); // No-op.
sharedCtx.tm().checkEmptyTransactions(
- () -> String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicCloseCache"));
+ () -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheName, "dynamicCloseCache"));
if (proxy.context().isLocal())
return dynamicDestroyCache(cacheName, false, true, false, null);
@@ -3810,7 +3911,7 @@ public class GridCacheProcessor extends GridProcessorAdapter {
*/
public IgniteInternalFuture<?> resetCacheState(Collection<String> cacheNames) throws ClusterTopologyCheckedException {
sharedCtx.tm().checkEmptyTransactions(
- () -> String.format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "resetCacheState"));
+ () -> format(CHECK_EMPTY_TRANSACTIONS_ERROR_MSG_FORMAT, cacheNames, "resetCacheState"));
Collection<DynamicCacheChangeRequest> reqs = new ArrayList<>(cacheNames.size());
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFutureAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFutureAdapter.java
index decc8d0..b5e5590 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFutureAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTopologyFutureAdapter.java
@@ -30,8 +30,10 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.jetbrains.annotations.Nullable;
+import static java.lang.String.format;
import static org.apache.ignite.cache.PartitionLossPolicy.READ_ONLY_ALL;
import static org.apache.ignite.cache.PartitionLossPolicy.READ_ONLY_SAFE;
+import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT;
import static org.apache.ignite.internal.processors.cache.GridCacheUtils.isSystemCache;
/**
@@ -93,9 +95,9 @@ public abstract class GridDhtTopologyFutureAdapter extends GridFutureAdapter<Aff
CacheGroupContext grp = cctx.group();
if (cctx.shared().readOnlyMode() && !read && !isSystemCache(cctx.name())) {
- return new CacheInvalidStateException(
- new IgniteClusterReadOnlyException("Failed to perform cache operation (cluster is in " +
- "read-only mode) [cacheGrp=" + cctx.group().name() + ", cache=" + cctx.name() + ']'));
+ return new CacheInvalidStateException(new IgniteClusterReadOnlyException(
+ format(CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT, "cache", cctx.group().name(), cctx.name())
+ ));
}
CacheGroupValidation validation = grpValidRes.get(grp.groupId());
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
index 6985110..f894aa5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicSequenceImpl.java
@@ -31,7 +31,9 @@ import org.apache.ignite.IgniteException;
import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheInvalidStateException;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxLocal;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.X;
@@ -43,6 +45,7 @@ import org.apache.ignite.internal.processors.cluster.IgniteChangeGlobalStateSupp
import org.apache.ignite.lang.IgniteBiTuple;
import org.jetbrains.annotations.Nullable;
+import static org.apache.ignite.internal.processors.cache.GridCacheProcessor.CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT;
import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
@@ -186,6 +189,12 @@ public final class GridCacheAtomicSequenceImpl extends AtomicDataStructureProxy<
assert l > 0;
+ if (ctx.shared().readOnlyMode()) {
+ throw new CacheInvalidStateException(new IgniteClusterReadOnlyException(
+ String.format(CLUSTER_READ_ONLY_MODE_ERROR_MSG_FORMAT, "sequence", ctx.group().name(), ctx.name())
+ ));
+ }
+
localUpdate.lock();
try {
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 55b277c..2763ce1 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -171,6 +171,7 @@ org.apache.ignite.events.CacheQueryReadEvent
org.apache.ignite.events.CacheRebalancingEvent
org.apache.ignite.events.CheckpointEvent
org.apache.ignite.events.ClusterActivationEvent
+org.apache.ignite.events.ClusterStateChangeEvent
org.apache.ignite.events.DeploymentEvent
org.apache.ignite.events.DiscoveryEvent
org.apache.ignite.events.Event
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeAbstractTest.java
new file mode 100644
index 0000000..84973f8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeAbstractTest.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ *
+ */
+public abstract class CacheCreateDestroyClusterReadOnlyModeAbstractTest extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ startGridsMultiThreaded(2);
+ startClientGridsMultiThreaded(3, 2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeTest.java
new file mode 100644
index 0000000..7587bf8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/CacheCreateDestroyClusterReadOnlyModeTest.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY;
+import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheConfigurations;
+import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheNames;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Tests that {@link Ignite#createCache(CacheConfiguration)}/{@link Ignite#destroyCache(String)}/{@link IgniteCache#clear()}
+ * denied if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class CacheCreateDestroyClusterReadOnlyModeTest extends CacheCreateDestroyClusterReadOnlyModeAbstractTest {
+ /** */
+ @Test
+ public void testCacheCreateDenied() {
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (CacheConfiguration cfg : cacheConfigurations()) {
+ for (Ignite node : G.allGrids()) {
+ executeAndCheckException(() -> node.createCache(cfg), cfg.getName());
+ executeAndCheckException(() -> node.createCache(cfg.getName()), cfg.getName());
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testGetOrCreateNotExistedCacheDenied() {
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (CacheConfiguration cfg : cacheConfigurations()) {
+ for (Ignite node : G.allGrids()) {
+ executeAndCheckException(() -> node.getOrCreateCache(cfg), cfg.getName());
+ executeAndCheckException(() -> node.getOrCreateCache(cfg.getName()), cfg.getName());
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testGetOrCreateExistedCacheAllowed() {
+ grid(0).getOrCreateCaches(asList(cacheConfigurations()));
+
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (CacheConfiguration cfg : cacheConfigurations()) {
+ for (Ignite node : G.allGrids()) {
+ try (IgniteCache cache = node.getOrCreateCache(cfg)) {
+ assertNotNull(cfg.getName() + " " + node.name(), cache);
+ }
+
+ try (IgniteCache cache = node.getOrCreateCache(cfg.getName())) {
+ assertNotNull(cfg.getName() + " " + node.name(), cache);
+ }
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testCachesCreateDenied() {
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ List<CacheConfiguration> cfgs = asList(cacheConfigurations());
+
+ for (Ignite node : G.allGrids())
+ executeAndCheckException(() -> node.createCaches(cfgs), cacheNames().toString());
+ }
+
+ /** */
+ @Test
+ public void testGetOrCreateNotExistedCachesDenied() {
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ List<CacheConfiguration> cfgs = asList(cacheConfigurations());
+
+ for (Ignite node : G.allGrids())
+ executeAndCheckException(() -> node.getOrCreateCaches(cfgs), cacheNames().toString());
+ }
+
+ /** */
+ @Test
+ public void testGetOrCreateExistedCachesAllowed() {
+ List<CacheConfiguration> cfgs = asList(cacheConfigurations());
+
+ grid(0).getOrCreateCaches(cfgs);
+
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (Ignite node : G.allGrids()) {
+ Collection<IgniteCache> caches = node.getOrCreateCaches(cfgs);
+
+ assertEquals(cfgs.toString(), cfgs.size(), caches.size());
+ }
+ }
+
+ /** */
+ @Test
+ public void testGetCreatedCacheAllowed() {
+ grid(0).createCaches(asList(cacheConfigurations()));
+
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (String cacheName : cacheNames()) {
+ for (Ignite node : G.allGrids())
+ assertNotNull(cacheName + " " + node.name(), node.cache(cacheName));
+ }
+ }
+
+ /** */
+ @Test
+ public void testCacheDestroyDenied() {
+ grid(0).createCaches(asList(cacheConfigurations()));
+
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (String cacheName : cacheNames()) {
+ for (Ignite node : G.allGrids())
+ executeAndCheckException(() -> node.destroyCache(cacheName), cacheName);
+ }
+ }
+
+ /** */
+ @Test
+ public void testCachesDestroyDenied() {
+ grid(0).createCaches(asList(cacheConfigurations()));
+
+ grid(0).cluster().state(ACTIVE_READ_ONLY);
+
+ G.allGrids().forEach(n -> assertEquals(n.name(), ACTIVE_READ_ONLY, n.cluster().state()));
+
+ for (Ignite node : G.allGrids())
+ executeAndCheckException(() -> node.destroyCaches(cacheNames()), cacheNames().toString());
+ }
+
+ /** */
+ private void executeAndCheckException(GridTestUtils.RunnableX clo, String cacheName) {
+ Throwable ex = assertThrows(log, clo, Exception.class, null);
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, cacheName);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterReadOnlyModeTestUtils.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterReadOnlyModeTestUtils.java
index 56a041a..a12f9cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterReadOnlyModeTestUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/ClusterReadOnlyModeTestUtils.java
@@ -28,9 +28,12 @@ import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.QueryEntity;
import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.X;
+import org.jetbrains.annotations.Nullable;
import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
@@ -89,44 +92,55 @@ public class ClusterReadOnlyModeTestUtils {
* @param cacheNames Checked cache names.
*/
public static void assertCachesReadOnlyMode(boolean readOnly, Collection<String> cacheNames) {
+ for (Ignite node : G.allGrids())
+ assertCachesReadOnlyMode(node, readOnly, cacheNames);
+ }
+
+ /**
+ * Asserts that all caches in read-only or in read/write mode. All cache operations will be performed from the
+ * {@code node} node.
+ *
+ * @param node Node initiator cache operations.
+ * @param readOnly If {@code true} then cache must be in read only mode, else in read/write mode.
+ * @param cacheNames Checked cache names.
+ */
+ public static void assertCachesReadOnlyMode(Ignite node, boolean readOnly, Collection<String> cacheNames) {
Random rnd = new Random();
- for (Ignite ignite : G.allGrids()) {
- for (String cacheName : cacheNames) {
- IgniteCache<Integer, Integer> cache = ignite.cache(cacheName);
-
- for (int i = 0; i < 10; i++) {
- cache.get(rnd.nextInt(100)); // All gets must succeed.
-
- if (readOnly) {
- // All puts must fail.
- try {
- cache.put(rnd.nextInt(100), rnd.nextInt());
-
- fail("Put must fail for cache " + cacheName);
- }
- catch (Exception ignored) {
- // No-op.
- }
-
- // All removes must fail.
- try {
- cache.remove(rnd.nextInt(100));
-
- fail("Remove must fail for cache " + cacheName);
- }
- catch (Exception ignored) {
- // No-op.
- }
+ for (String cacheName : cacheNames) {
+ IgniteCache<Integer, Integer> cache = node.cache(cacheName);
+
+ for (int i = 0; i < 10; i++) {
+ cache.get(rnd.nextInt(100)); // All gets must succeed.
+
+ if (readOnly) {
+ // All puts must fail.
+ try {
+ cache.put(rnd.nextInt(100), rnd.nextInt());
+
+ fail("Put must fail for cache " + cacheName);
+ }
+ catch (Exception ignored) {
+ // No-op.
}
- else {
- int key = rnd.nextInt(100);
- cache.put(key, rnd.nextInt()); // All puts must succeed.
+ // All removes must fail.
+ try {
+ cache.remove(rnd.nextInt(100));
- cache.remove(key); // All removes must succeed.
+ fail("Remove must fail for cache " + cacheName);
+ }
+ catch (Exception ignored) {
+ // No-op.
}
}
+ else {
+ int key = rnd.nextInt(100);
+
+ cache.put(key, rnd.nextInt()); // All puts must succeed.
+
+ cache.remove(key); // All removes must succeed.
+ }
}
}
}
@@ -164,6 +178,17 @@ public class ClusterReadOnlyModeTestUtils {
}
/**
+ * Checks that given {@code ex} exception has a cause of {@link IgniteClusterReadOnlyException}.
+ *
+ * @param ex Exception for the check.
+ * @param name Name of object (optional).
+ */
+ public static void checkRootCause(Throwable ex, @Nullable String name) {
+ if (!X.hasCause(ex, IgniteClusterReadOnlyException.class))
+ throw new AssertionError("IgniteClusterReadOnlyException not found on " + name, ex);
+ }
+
+ /**
* @param cacheMode Cache mode.
* @param atomicityMode Atomicity mode.
* @param grpName Cache group name.
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeAbstractTest.java
new file mode 100644
index 0000000..ef330e4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeAbstractTest.java
@@ -0,0 +1,263 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.BiConsumer;
+import java.util.function.Consumer;
+import java.util.function.Predicate;
+import java.util.stream.Stream;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+
+import static java.util.stream.Collectors.toList;
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Class with common logic for tests {@link IgniteCache} API when cluster in a {@link ClusterState#ACTIVE_READ_ONLY}
+ * mode.
+ */
+public abstract class IgniteCacheClusterReadOnlyModeAbstractTest extends GridCommonAbstractTest {
+ /** Key. */
+ protected static final int KEY = 10;
+
+ /** Value. */
+ protected static final int VAL = 11;
+
+ /** Key 2. */
+ protected static final int KEY_2 = 20;
+
+ /** Value 2. */
+ protected static final int VAL_2 = 21;
+
+ /** Key 3. */
+ protected static final int KEY_3 = 30;
+
+ /** Value 3. */
+ protected static final int VAL_3 = 31;
+
+ /** Unknown key. */
+ protected static final int UNKNOWN_KEY = 3;
+
+ /** Map with all pairs in caches. */
+ protected static final Map<Integer, Integer> kvMap;
+
+ /** */
+ protected static final Predicate<CacheConfiguration> ATOMIC_CACHES_PRED = cfg -> cfg.getAtomicityMode() == ATOMIC;
+
+ /** */
+ protected static final Predicate<CacheConfiguration> TX_CACHES_PRED = cfg -> cfg.getAtomicityMode() == TRANSACTIONAL;
+
+ /** */
+ protected static final Predicate<CacheConfiguration> MVCC_CACHES_PRED = cfg -> cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT;
+
+ /** */
+ protected static final Predicate<CacheConfiguration> NO_MVCC_CACHES_PRED = ATOMIC_CACHES_PRED.or(TX_CACHES_PRED);
+
+ /** Started cache configurations. */
+ protected static Collection<CacheConfiguration<?, ?>> cacheConfigurations;
+
+ /** Started cache names. */
+ protected static Collection<String> cacheNames;
+
+ static {
+ Map<Integer, Integer> map = new HashMap<>();
+
+ map.put(KEY, VAL);
+ map.put(KEY_2, VAL_2);
+ map.put(KEY_3, VAL_3);
+
+ kvMap = Collections.unmodifiableMap(map);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ CacheConfiguration<?, ?>[] cfgs = cacheConfigurations();
+
+ cacheConfigurations = Collections.unmodifiableCollection(Arrays.asList(cfgs));
+
+ cacheNames = Collections.unmodifiableSet(
+ cacheConfigurations.stream()
+ .map(CacheConfiguration::getName)
+ .collect(toSet())
+ );
+
+ return super.getConfiguration(igniteInstanceName)
+ .setCacheConfiguration(cfgs);
+ }
+
+ /**
+ * @return Cache configurations for node start.
+ */
+ protected CacheConfiguration<?, ?>[] cacheConfigurations() {
+ CacheConfiguration<?, ?>[] cfgs = ClusterReadOnlyModeTestUtils.cacheConfigurations();
+
+ for (CacheConfiguration cfg : cfgs)
+ cfg.setReadFromBackup(true);
+
+ return cfgs;
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ cacheNames = null;
+ cacheConfigurations = null;
+
+ startGrids(2);
+ startClientGridsMultiThreaded(3, 2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ for (String cacheName : cacheNames) {
+ grid(0).cache(cacheName).put(KEY, VAL);
+ grid(0).cache(cacheName).put(KEY_2, VAL_2);
+ grid(0).cache(cacheName).put(KEY_3, VAL_3);
+ }
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ cacheNames = null;
+ cacheConfigurations = null;
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ commonChecks();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ commonChecks();
+
+ super.afterTest();
+ }
+
+ /** */
+ protected void performActionReadOnlyExceptionExpected(Consumer<IgniteCache<Integer, Integer>> clo) {
+ performActionReadOnlyExceptionExpected(clo, null);
+ }
+
+ /** */
+ protected void performActionReadOnlyExceptionExpected(
+ Consumer<IgniteCache<Integer, Integer>> clo,
+ @Nullable Predicate<CacheConfiguration> cfgFilter
+ ) {
+ performAction(
+ cache -> {
+ Throwable ex = assertThrows(log, () -> clo.accept(cache), Exception.class, null);
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, cache.getName());
+ },
+ cfgFilter
+ );
+ }
+
+ /** */
+ protected void performAction(Consumer<IgniteCache<Integer, Integer>> clo) {
+ performAction(clo, null);
+ }
+
+ /** */
+ protected void performAction(BiConsumer<Ignite, IgniteCache<Integer, Integer>> clo) {
+ performAction(clo, null);
+ }
+
+ /** */
+ protected void performAction(
+ Consumer<IgniteCache<Integer, Integer>> clo,
+ @Nullable Predicate<CacheConfiguration> cfgFilter
+ ) {
+ performAction((node, cache) -> clo.accept(cache), cfgFilter);
+ }
+
+ /** */
+ protected void performAction(
+ BiConsumer<Ignite, IgniteCache<Integer, Integer>> clo,
+ @Nullable Predicate<CacheConfiguration> cfgFilter
+ ) {
+ Collection<String> names = cfgFilter == null ?
+ cacheNames :
+ cacheConfigurations.stream()
+ .filter(cfgFilter)
+ .map(CacheConfiguration::getName)
+ .collect(toList());
+
+ for (Ignite node : G.allGrids()) {
+ for (String name : names)
+ clo.accept(node, node.cache(name));
+ }
+ }
+
+ /** */
+ private void commonChecks() {
+ assertEquals(kvMap.toString(), 3, kvMap.size());
+
+ for (Ignite node : G.allGrids()) {
+ assertEquals(node.name(), ClusterState.ACTIVE_READ_ONLY, node.cluster().state());
+
+ for (String cacheName : cacheNames) {
+ IgniteCache<Integer, Integer> cache = node.cache(cacheName);
+
+ assertEquals(node.name() + " " + cacheName, kvMap.size(), cache.size());
+
+ for (Map.Entry<Integer, Integer> entry : kvMap.entrySet())
+ assertEquals(node.name() + " " + cacheName, entry.getValue(), cache.get(entry.getKey()));
+
+ assertNull(node.name() + " " + cacheName, cache.get(UNKNOWN_KEY));
+ }
+ }
+ }
+
+ /** */
+ protected static CacheConfiguration<?, ?>[] filterAndAddNearCacheConfig(CacheConfiguration<?, ?>[] cfgs) {
+ return Stream.of(cfgs)
+ // Near caches doesn't support in a MVCC mode.
+ .filter(cfg -> cfg.getAtomicityMode() != CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)
+ .map(cfg -> cfg.setNearConfiguration(new NearCacheConfiguration<>()))
+ .toArray(CacheConfiguration[]::new);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeSelfTest.java
new file mode 100644
index 0000000..5a764c7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheClusterReadOnlyModeSelfTest.java
@@ -0,0 +1,531 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheEntry;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.ScanQuery;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.transactions.Transaction;
+import org.apache.ignite.transactions.TransactionConcurrency;
+import org.apache.ignite.transactions.TransactionIsolation;
+import org.junit.Test;
+
+import static java.lang.String.valueOf;
+import static java.util.Arrays.asList;
+import static java.util.Collections.singleton;
+import static java.util.stream.Collectors.toMap;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT;
+import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
+
+/**
+ * Tests most of public API methods of {@link IgniteCache} when cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteCacheClusterReadOnlyModeSelfTest extends IgniteCacheClusterReadOnlyModeAbstractTest {
+ /** */
+ @Test
+ public void testGetAndPutIfAbsentDeniedIfKeyIsPresented() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutIfAbsent(KEY, VAL));
+ }
+
+ /** */
+ @Test
+ public void testGetAndPutIfAbsentDeniedIfKeyIsAbsent() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutIfAbsent(UNKNOWN_KEY, VAL));
+ }
+
+ /** */
+ @Test
+ public void testGetAndPutIfAbsentAsyncDeniedIfKeyIsPresented() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutIfAbsentAsync(KEY, VAL).get());
+ }
+
+ /** */
+ @Test
+ public void testGetAndPutIfAbsentAsyncDeniedIfKeyIsAbsent() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutIfAbsentAsync(UNKNOWN_KEY, VAL).get());
+ }
+
+ /** */
+ @Test
+ public void testLockDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.lock(KEY).lock(), TX_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testLockAllDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.lockAll(asList(KEY, KEY_2)).lock(), TX_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testScanQueryAllowed() {
+ performAction(cache -> {
+ try (QueryCursor qry = cache.query(new ScanQuery<>())) {
+ for (Object o : qry.getAll()) {
+ IgniteBiTuple<Integer, Integer> tuple = (IgniteBiTuple<Integer, Integer>)o;
+
+ assertEquals(o.toString(), kvMap.get(tuple.getKey()), tuple.getValue());
+ }
+ }
+ });
+ }
+
+ /** */
+ @Test
+ public void testSizeAllowed() {
+ performAction(cache -> assertEquals(kvMap.size(), cache.size()));
+ }
+
+ /** */
+ @Test
+ public void testSizeAsyncAllowed() {
+ performAction(cache -> assertEquals(kvMap.size(), (long)cache.sizeAsync().get()));
+ }
+
+ /** */
+ @Test
+ public void testSizeLongAllowed() {
+ performAction(cache -> assertEquals(kvMap.size(), cache.sizeLong()));
+ }
+
+ /** */
+ @Test
+ public void testSizeLongAsyncAllowed() {
+ performAction(cache -> assertEquals(kvMap.size(), (long)cache.sizeLongAsync().get()));
+ }
+
+ /** */
+ @Test
+ public void testGetAllowed() {
+ performAction(cache -> assertEquals(VAL, (int)cache.get(KEY)));
+ performAction(cache -> assertNull(cache.get(UNKNOWN_KEY)));
+ }
+
+ /** */
+ @Test
+ public void testGetAsyncAllowed() {
+ performAction(cache -> assertEquals(VAL, (int)cache.getAsync(KEY).get()));
+ performAction(cache -> assertNull(cache.getAsync(UNKNOWN_KEY).get()));
+ }
+
+ /** */
+ @Test
+ public void testGetEntryAllowed() {
+ performAction(cache -> {
+ CacheEntry entry = cache.getEntry(KEY);
+
+ assertEquals(KEY, entry.getKey());
+ assertEquals(VAL, entry.getValue());
+ });
+
+ performAction(cache -> assertNull(cache.getEntry(UNKNOWN_KEY)));
+ }
+
+ /** */
+ @Test
+ public void testGetEntryAsyncAllowed() {
+ performAction(cache -> {
+ CacheEntry entry = cache.getEntryAsync(KEY).get();
+
+ assertEquals(KEY, entry.getKey());
+ assertEquals(VAL, entry.getValue());
+ });
+
+ performAction(cache -> assertNull(cache.getEntryAsync(UNKNOWN_KEY).get()));
+ }
+
+ /** */
+ @Test
+ public void testGetAllAllowed() {
+ performAction(cache -> assertEquals(kvMap, cache.getAll(kvMap.keySet())));
+ }
+
+ /** */
+ @Test
+ public void testGetAllAsyncAllowed() {
+ performAction(cache -> assertEquals(kvMap, (cache.getAllAsync(kvMap.keySet()).get())));
+ }
+
+ /** */
+ @Test
+ public void testGetEntriesAllowed() {
+ performAction(cache -> {
+ for (Object o : cache.getEntries(kvMap.keySet())) {
+ CacheEntry<Integer, Integer> entry = (CacheEntry<Integer, Integer>)o;
+
+ assertEquals(kvMap.get(entry.getKey()), entry.getValue());
+ }
+ });
+ }
+
+ /** */
+ @Test
+ public void testGetEntriesAsyncAllowed() {
+ performAction(cache -> {
+ for (Object o : cache.getEntriesAsync(kvMap.keySet()).get()) {
+ CacheEntry<Integer, Integer> entry = (CacheEntry<Integer, Integer>)o;
+
+ assertEquals(kvMap.get(entry.getKey()), entry.getValue());
+ }
+ });
+ }
+
+ /** */
+ @Test
+ public void testGetAllOutTxAllowed() {
+ performAction(
+ (node, cache) -> {
+ for (TransactionConcurrency level : TransactionConcurrency.values()) {
+ for (TransactionIsolation isolation : TransactionIsolation.values()) {
+ CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
+
+ if (level == OPTIMISTIC && cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
+ // Only pessimistic transactions are supported when MVCC is enabled.
+ continue;
+ }
+
+ Transaction tx = node.transactions().txStart(level, isolation);
+
+ try {
+ cache.get(UNKNOWN_KEY);
+
+ assertEquals(kvMap, cache.getAllOutTx(kvMap.keySet()));
+
+ tx.commit();
+ }
+ catch (Exception e) {
+ RuntimeException ex = new RuntimeException(new AssertionError(
+ "Got exception on node: " + node.name() + " cache: " + cache.getName() + " isolation: " + isolation + " txLevel: " + level,
+ e
+ ));
+
+ log.error("", ex);
+
+ tx.rollback();
+
+ throw ex;
+ }
+ }
+ }
+ },
+ TX_CACHES_PRED.or(MVCC_CACHES_PRED)
+ );
+ }
+
+ /** */
+ @Test
+ public void testGetAllOutTxAsyncAllowed() {
+ performAction(
+ (node, cache) -> {
+ for (TransactionConcurrency level : TransactionConcurrency.values()) {
+ for (TransactionIsolation isolation : TransactionIsolation.values()) {
+ CacheConfiguration cfg = cache.getConfiguration(CacheConfiguration.class);
+
+ if (level == OPTIMISTIC && cfg.getAtomicityMode() == TRANSACTIONAL_SNAPSHOT) {
+ // Only pessimistic transactions are supported when MVCC is enabled.
+ continue;
+ }
+
+ Transaction tx = node.transactions().txStart(level, isolation);
+
+ try {
+ cache.get(UNKNOWN_KEY);
+
+ assertEquals(kvMap, cache.getAllOutTxAsync(kvMap.keySet()).get());
+
+ tx.commit();
+ }
+ catch (Exception e) {
+ RuntimeException ex = new RuntimeException(new AssertionError(
+ "Got exception on node: " + node.name() + " cache: " + cache.getName() + " isolation: " + isolation + " txLevel: " + level,
+ e
+ ));
+
+ log.error("", ex);
+
+ tx.rollback();
+
+ throw ex;
+ }
+ }
+ }
+ },
+ TX_CACHES_PRED.or(MVCC_CACHES_PRED)
+ );
+ }
+
+ /** */
+ @Test
+ public void testContainsKeyAllowed() {
+ performAction(cache -> assertTrue(KEY + "", cache.containsKey(KEY)));
+ performAction(cache -> assertFalse(UNKNOWN_KEY + "", cache.containsKey(UNKNOWN_KEY)));
+ }
+
+ /** */
+ @Test
+ public void testContainsKeyAsyncAllowed() {
+ performAction(cache -> assertTrue(KEY + "", cache.containsKeyAsync(KEY).get()));
+ performAction(cache -> assertFalse(UNKNOWN_KEY + "", cache.containsKeyAsync(UNKNOWN_KEY).get()));
+ }
+
+ /** */
+ @Test
+ public void testContainsKeysAllowed() {
+ performAction(cache -> assertTrue(valueOf(kvMap.keySet()), cache.containsKeys(kvMap.keySet())));
+ performAction(cache -> assertFalse(UNKNOWN_KEY + "", cache.containsKeys(singleton(UNKNOWN_KEY))));
+ }
+
+ /** */
+ @Test
+ public void testContainsKeysAsyncAllowed() {
+ performAction(cache -> assertTrue(valueOf(kvMap.keySet()), cache.containsKeysAsync(kvMap.keySet()).get()));
+ performAction(cache -> assertFalse(UNKNOWN_KEY + "", cache.containsKeysAsync(singleton(UNKNOWN_KEY)).get()));
+ }
+
+ /** */
+ @Test
+ public void testPutDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.put(KEY, VAL + 1));
+ performActionReadOnlyExceptionExpected(cache -> cache.put(UNKNOWN_KEY, 777));
+ }
+
+ /** */
+ @Test
+ public void testPutAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.putAsync(KEY, VAL + 1).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.putAsync(UNKNOWN_KEY, 777).get());
+ }
+
+ /** */
+ @Test
+ public void testGetAndPutDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPut(KEY, VAL + 1));
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPut(UNKNOWN_KEY, 777));
+ }
+
+ /** */
+ @Test
+ public void testGetAndPutAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutAsync(KEY, VAL + 1).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndPutAsync(UNKNOWN_KEY, 777).get());
+ }
+
+ /** */
+ @Test
+ public void testPutAllDenied() {
+ Map<Integer, Integer> newMap = kvMap.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue() + 1));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.putAll(newMap));
+ }
+
+ /** */
+ @Test
+ public void testPutAllAsyncDenied() {
+ Map<Integer, Integer> newMap = kvMap.entrySet().stream().collect(toMap(Map.Entry::getKey, e -> e.getValue() + 1));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.putAllAsync(newMap).get());
+ }
+
+ /** */
+ @Test
+ public void testPutIfAbsentDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.putIfAbsent(KEY, VAL + 1));
+ performActionReadOnlyExceptionExpected(cache -> cache.putIfAbsent(UNKNOWN_KEY, 777));
+ }
+
+ /** */
+ @Test
+ public void testPutIfAbsentAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.putIfAbsentAsync(KEY, VAL + 1).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.putIfAbsentAsync(UNKNOWN_KEY, 777).get());
+ }
+
+ /** */
+ @Test
+ public void testRemoveDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.remove(KEY));
+ performActionReadOnlyExceptionExpected(cache -> cache.remove(UNKNOWN_KEY));
+ }
+
+ /** */
+ @Test
+ public void testRemoveAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAsync(KEY).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAsync(UNKNOWN_KEY).get());
+ }
+
+ /** */
+ @Test
+ public void testRemoveWithOldValueDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.remove(KEY, VAL));
+ }
+
+ /** */
+ @Test
+ public void testRemoveWithOldValueAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAsync(KEY, VAL).get());
+ }
+
+ /** */
+ @Test
+ public void testGetAndRemoveDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndRemove(KEY));
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndRemove(UNKNOWN_KEY));
+ }
+
+ /** */
+ @Test
+ public void testGetAndRemoveAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndRemoveAsync(KEY).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndRemoveAsync(UNKNOWN_KEY).get());
+ }
+
+ /** */
+ @Test
+ public void testReplaceWithOldValueDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.replace(KEY, VAL, VAL + 1));
+ }
+
+ /** */
+ @Test
+ public void testReplaceWithOldValueAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.replaceAsync(KEY, VAL, VAL + 1).get());
+ }
+
+ /** */
+ @Test
+ public void testReplaceDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.replace(KEY,VAL + 1));
+ }
+
+ /** */
+ @Test
+ public void testReplaceAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.replaceAsync(KEY, VAL + 1).get());
+ }
+
+ /** */
+ @Test
+ public void testGetAndReplaceDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndReplace(KEY,VAL + 1));
+ }
+
+ /** */
+ @Test
+ public void testGetAndReplaceAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.getAndReplaceAsync(KEY, VAL + 1).get());
+ }
+
+ /** */
+ @Test
+ public void testRemoveAllWithKeysDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAll(kvMap.keySet()));
+ }
+
+ /** */
+ @Test
+ public void testRemoveAllWithKeysAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAllAsync(kvMap.keySet()).get());
+ }
+
+ /** */
+ @Test
+ public void testRemoveAllDenied() {
+ performActionReadOnlyExceptionExpected(IgniteCache::removeAll);
+ }
+
+ /** */
+ @Test
+ public void testRemoveAllAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.removeAllAsync().get());
+ }
+
+ /** */
+ @Test
+ public void testClearDenied() {
+ performActionReadOnlyExceptionExpected(IgniteCache::clear, NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testClearAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.clearAsync().get(), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testClearWithKeyDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.clear(KEY), NO_MVCC_CACHES_PRED);
+ performActionReadOnlyExceptionExpected(cache -> cache.clear(UNKNOWN_KEY), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testClearWithKeyAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.clearAsync(KEY).get(), NO_MVCC_CACHES_PRED);
+ performActionReadOnlyExceptionExpected(cache -> cache.clearAsync(UNKNOWN_KEY).get(), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testClearAllDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.clearAll(kvMap.keySet()), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testClearAllAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.clearAllAsync(kvMap.keySet()).get(), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testLocalClearDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.localClear(KEY), NO_MVCC_CACHES_PRED);
+ performActionReadOnlyExceptionExpected(cache -> cache.localClear(UNKNOWN_KEY), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testLocalClearAllDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.localClearAll(kvMap.keySet()), NO_MVCC_CACHES_PRED);
+ }
+
+ /** */
+ @Test
+ public void testCloseAllowed() {
+ performAction((node, cache) -> {
+ if (!node.configuration().isClientMode()) {
+ // FIXME https://issues.apache.org/jira/browse/IGNITE-13102
+ return;
+ }
+
+ assertFalse(cache.isClosed());
+
+ cache.close();
+
+ assertTrue(cache.isClosed());
+ });
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeClusterReadOnlyModeSelfTest.java
new file mode 100644
index 0000000..7e602dd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheInvokeClusterReadOnlyModeSelfTest.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheEntryProcessor;
+import org.apache.ignite.cluster.ClusterState;
+import org.junit.Test;
+
+/**
+ * Tests that {@link IgniteCache#invoke(Object, EntryProcessor, Object...)}, {@link IgniteCache#invokeAll(Map, Object...)}
+ * overloaded and async methods works fine when cluster in a {@link ClusterState#ACTIVE_READ_ONLY} mode.
+ */
+public class IgniteCacheInvokeClusterReadOnlyModeSelfTest extends IgniteCacheClusterReadOnlyModeAbstractTest {
+ /** Cache entry processor. */
+ private static final CacheEntryProcessor<Integer, Integer, Object> CACHE_ENTRY_PROCESSOR =
+ (entry, args) -> updateValue(entry);
+
+ /** Entry processor. */
+ private static final EntryProcessor<Integer, Integer, Object> ENTRY_PROCESSOR = (entry, args) -> updateValue(entry);
+
+ /** */
+ @Test
+ public void testInvokeCacheEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invoke(Integer.valueOf(KEY), CACHE_ENTRY_PROCESSOR));
+ performActionReadOnlyExceptionExpected(cache -> cache.invoke(Integer.valueOf(UNKNOWN_KEY), CACHE_ENTRY_PROCESSOR));
+ }
+
+ /** */
+ @Test
+ public void testInvokeEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invoke(Integer.valueOf(KEY), ENTRY_PROCESSOR));
+ performActionReadOnlyExceptionExpected(cache -> cache.invoke(Integer.valueOf(UNKNOWN_KEY), ENTRY_PROCESSOR));
+ }
+
+ /** */
+ @Test
+ public void testInvokeAsyncCacheEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAsync(KEY, CACHE_ENTRY_PROCESSOR).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAsync(UNKNOWN_KEY, CACHE_ENTRY_PROCESSOR).get());
+ }
+
+ /** */
+ @Test
+ public void testInvokeAsyncEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAsync(KEY, ENTRY_PROCESSOR).get());
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAsync(UNKNOWN_KEY, ENTRY_PROCESSOR).get());
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllCacheEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAll(kvMap.keySet(), CACHE_ENTRY_PROCESSOR));
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllEntryProcessorDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAll(kvMap.keySet(), ENTRY_PROCESSOR));
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllCacheEntryProcessorAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAllAsync(kvMap.keySet(), CACHE_ENTRY_PROCESSOR).get());
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllEntryProcessorAsyncDenied() {
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAllAsync(kvMap.keySet(), ENTRY_PROCESSOR).get());
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllCacheEntryProcessorsDenied() {
+ Map<Integer, CacheEntryProcessor<Integer, Integer, Object>> map = new HashMap<>();
+
+ kvMap.keySet().forEach(k -> map.put(k, CACHE_ENTRY_PROCESSOR));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAll(map));
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllEntryProcessorsDenied() {
+ Map<Integer, EntryProcessor<Integer, Integer, Object>> map = new HashMap<>();
+
+ kvMap.keySet().forEach(k -> map.put(k, ENTRY_PROCESSOR));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAll(map));
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllAsyncCacheEntryProcessorsDenied() {
+ Map<Integer, CacheEntryProcessor<Integer, Integer, Object>> map = new HashMap<>();
+
+ kvMap.keySet().forEach(k -> map.put(k, CACHE_ENTRY_PROCESSOR));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAllAsync(map).get());
+ }
+
+ /** */
+ @Test
+ public void testInvokeAllAsyncEntryProcessorsDenied() {
+ Map<Integer, EntryProcessor<Integer, Integer, Object>> map = new HashMap<>();
+
+ kvMap.keySet().forEach(k -> map.put(k, ENTRY_PROCESSOR));
+
+ performActionReadOnlyExceptionExpected(cache -> cache.invokeAllAsync(map).get());
+ }
+
+ /** */
+ private static Object updateValue(MutableEntry<Integer, Integer> entry) {
+ assertEquals(kvMap.get(entry.getKey()), entry.getValue());
+
+ entry.setValue(entry.getValue() == null ? 0 : entry.getValue() + 1);
+
+ return null;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreClusterReadOnlyModeSelfTest.java
new file mode 100644
index 0000000..b4386e7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreClusterReadOnlyModeSelfTest.java
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.stream.Stream;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import javax.cache.integration.CacheLoaderException;
+import javax.cache.integration.CacheWriterException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static java.util.stream.Collectors.toSet;
+import static org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY;
+
+/**
+ * Checks that third party stores works fine if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteCacheStoreClusterReadOnlyModeSelfTest extends GridCommonAbstractTest {
+ /** Nodes count. */
+ private static final int NODES_CNT = 2;
+
+ /** Key. */
+ private static final int KEY = 10;
+
+ /** Value. */
+ private static final int VAL = 11;
+
+ /** */
+ private static final Map<String, TestCacheStore> cacheStores = new ConcurrentHashMap<>();
+
+ /** Started cache configurations. */
+ private Collection<CacheConfiguration<?, ?>> cacheConfigurations;
+
+ /** Started cache names. */
+ private Collection<String> cacheNames;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ CacheConfiguration<?, ?>[] cfgs = cacheConfigurations();
+
+ cacheConfigurations = Collections.unmodifiableCollection(Arrays.asList(cfgs));
+
+ cacheNames = Collections.unmodifiableSet(
+ cacheConfigurations.stream()
+ .map(CacheConfiguration::getName)
+ .collect(toSet())
+ );
+
+ return super.getConfiguration(igniteInstanceName)
+ .setFailureHandler(new StopNodeFailureHandler())
+ .setCacheConfiguration(cfgs);
+ }
+
+ /**
+ * @return Cache configurations for node start.
+ */
+ protected CacheConfiguration<?, ?>[] cacheConfigurations() {
+ return Stream.of(ClusterReadOnlyModeTestUtils.cacheConfigurations())
+ // 3'rd party store doesn't support in a MVCC mode.
+ .filter(cfg -> cfg.getAtomicityMode() != CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT)
+ .map(cfg -> cfg.setReadThrough(true))
+ .map(cfg -> cfg.setWriteBehindEnabled(true))
+ .map(cfg -> cfg.setWriteThrough(true))
+ .map(cfg -> cfg.setCacheStoreFactory(new TestCacheStoreFactory(cfg.getName())))
+ .toArray(CacheConfiguration[]::new);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ cacheStores.clear();
+
+ IgniteEx crd = startGrids(NODES_CNT);
+
+ for (String name : cacheNames)
+ crd.cache(name).put(KEY, VAL);
+
+ crd.cluster().state(ACTIVE_READ_ONLY);
+
+ for (Ignite node : G.allGrids())
+ assertEquals(ACTIVE_READ_ONLY, node.cluster().state());
+
+ assertEquals(NODES_CNT, crd.cluster().nodes().size());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ cacheStores.clear();
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testLoadFromCacheStoreOnGetAllowed() {
+ checkBefore();
+
+ fillStores();
+
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ for (int i = 0; i < NODES_CNT; i++)
+ assertEquals(name, i, node.cache(name).get(i));
+ }
+ }
+
+ checkAfter();
+ }
+
+ /** */
+ @Test
+ public void testLoadCacheAllowed() {
+ checkBefore();
+
+ fillStores();
+
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ for (int i = 0; i < NODES_CNT; i++) {
+ int j = i;
+
+ node.cache(name).loadCache((k, v) -> ((int)k) % NODES_CNT == j);
+ }
+ }
+ }
+
+ checkAfter();
+ }
+
+ /** */
+ @Test
+ public void testLoadCacheAsyncAllowed() {
+ checkBefore();
+
+ fillStores();
+
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ for (int i = 0; i < NODES_CNT; i++) {
+ int j = i;
+
+ node.cache(name).loadCacheAsync((k, v) -> ((int)k) % NODES_CNT == j).get();
+ }
+ }
+ }
+
+ checkAfter();
+ }
+
+ /** */
+ @Test
+ public void testLocalLoadCacheAllowed() {
+ checkBefore();
+
+ fillStores();
+
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ for (int i = 0; i < NODES_CNT; i++)
+ node.cache(name).localLoadCache(null);
+ }
+ }
+
+ checkAfter();
+ }
+
+ /** */
+ @Test
+ public void testLocalLoadCacheAsyncAllowed() {
+ checkBefore();
+
+ fillStores();
+
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ for (int i = 0; i < NODES_CNT; i++)
+ node.cache(name).localLoadCacheAsync(null).get();
+ }
+ }
+
+ checkAfter();
+ }
+
+ /** */
+ private void checkAfter() {
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ IgniteCache<Object, Object> cache = node.cache(name);
+
+ cache.loadCache(null);
+
+ assertEquals(name, VAL, cache.get(KEY));
+
+ for (int i = 0; i < NODES_CNT; i++)
+ assertEquals(name + " " + node.name(), i, cache.get(i));
+
+ assertEquals(name, NODES_CNT + 1, cache.size());
+ }
+ }
+ }
+
+ /** */
+ private void checkBefore() {
+ for (String name : cacheNames) {
+ for (Ignite node : G.allGrids()) {
+ assertEquals(name, VAL, node.cache(name).get(KEY));
+ assertEquals(name, 1, node.cache(name).size());
+
+ for (int i = 0; i < NODES_CNT; i++)
+ assertNull(name, node.cache(name).get(i));
+ }
+ }
+ }
+
+ /** */
+ private void fillStores() {
+ for (TestCacheStore store : cacheStores.values()) {
+ for (int i = 0; i < NODES_CNT; i++)
+ store.map.put(i, i);
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestCacheStoreFactory implements Factory<CacheStore<Integer, Integer>> {
+ /** Cache name. */
+ private final String name;
+
+ /** */
+ private TestCacheStoreFactory(String name) {
+ this.name = name;
+ }
+
+ /** {@inheritDoc} */
+ @Override public CacheStore<Integer, Integer> create() {
+ return cacheStores.computeIfAbsent(name, k -> new TestCacheStore());
+ }
+ }
+
+ /**
+ *
+ */
+ private static class TestCacheStore extends CacheStoreAdapter<Integer, Integer> {
+ /** Map storage. */
+ private final Map<Integer, Integer> map = new ConcurrentHashMap<>();
+
+ /** {@inheritDoc} */
+ @Override public Integer load(Integer key) throws CacheLoaderException {
+ return map.get(key);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void write(
+ Cache.Entry<? extends Integer, ? extends Integer> entry
+ ) throws CacheWriterException {
+ map.put(entry.getKey(), entry.getValue());
+ }
+
+ /** {@inheritDoc} */
+ @Override public void delete(Object key) throws CacheWriterException {
+ map.remove(key);
+ }
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClusterActivateDeactivateTestWithPersistence.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClusterActivateDeactivateTestWithPersistence.java
index 7b30ed2..ad0daa5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClusterActivateDeactivateTestWithPersistence.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteClusterActivateDeactivateTestWithPersistence.java
@@ -212,10 +212,12 @@ public class IgniteClusterActivateDeactivateTestWithPersistence extends IgniteCl
Ignite srv = startGrids(srvs);
- srv.cluster().state(activationMode);
+ srv.cluster().state(ACTIVE);
srv.createCaches(Arrays.asList(cacheConfigurations1()));
+ srv.cluster().state(activationMode);
+
Map<Integer, Integer> cacheData = new LinkedHashMap<>();
for (CacheConfiguration ccfg : cacheConfigurations1()) {
@@ -404,13 +406,15 @@ public class IgniteClusterActivateDeactivateTestWithPersistence extends IgniteCl
Ignite srv = startGrids(SRVS);
- srv.cluster().state(state);
+ srv.cluster().state(ACTIVE);
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME)
.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
srv.createCache(ccfg);
+ srv.cluster().state(state);
+
stopAllGrids();
ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME + 1)
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheClusterReadOnlyModeSelfTest.java
new file mode 100644
index 0000000..65d63ab
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheClusterReadOnlyModeSelfTest.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+/**
+ * Tests most of public API methods of near {@link IgniteCache} when cluster in a {@link ClusterState#ACTIVE_READ_ONLY}
+ * state.
+ */
+public class IgniteNearCacheClusterReadOnlyModeSelfTest extends IgniteCacheClusterReadOnlyModeSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheConfiguration<?, ?>[] cacheConfigurations() {
+ return filterAndAddNearCacheConfig(super.cacheConfigurations());
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheInvokeClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheInvokeClusterReadOnlyModeSelfTest.java
new file mode 100644
index 0000000..b5d69dc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteNearCacheInvokeClusterReadOnlyModeSelfTest.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.Map;
+import javax.cache.processor.EntryProcessor;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+
+/**
+ * Tests that {@link IgniteCache#invoke(Object, EntryProcessor, Object...)}, {@link IgniteCache#invokeAll(Map, Object...)}
+ * overloaded and async methods works fine with near cache when cluster in a {@link ClusterState#ACTIVE_READ_ONLY} mode.
+ */
+public class IgniteNearCacheInvokeClusterReadOnlyModeSelfTest extends IgniteCacheInvokeClusterReadOnlyModeSelfTest {
+ /** {@inheritDoc} */
+ @Override protected CacheConfiguration<?, ?>[] cacheConfigurations() {
+ return filterAndAddNearCacheConfig(super.cacheConfigurations());
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicLongClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicLongClusterReadOnlyTest.java
new file mode 100644
index 0000000..49d5c02
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicLongClusterReadOnlyTest.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteAtomicLong;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getAtomicConfigurations;
+
+/**
+ * Tests methods of {@link IgniteAtomicLong} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteAtomicLongClusterReadOnlyTest extends GridCommonAbstractTest {
+ /** Initial value. */
+ private static final int INITIAL_VAL = 0;
+
+ /** Ignite atomic longs. */
+ private static List<IgniteAtomicLong> atomicLongs = new ArrayList<>();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ atomicLongs.add(grid(0).atomicLong(e.getKey(), e.getValue(), INITIAL_VAL, true));
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ atomicLongs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ atomicLongs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testGetInstanceWithoutCreateAllowed() {
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ assertNotNull(e.getKey(), grid(0).atomicLong(e.getKey(), e.getValue(), INITIAL_VAL, false));
+ }
+
+ /** */
+ @Test
+ public void testGetAllowed() {
+ atomicLongs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** */
+ @Test
+ public void testGetAndIncrementDenied() {
+ performAction(IgniteAtomicLong::getAndIncrement);
+ }
+
+ /** */
+ @Test
+ public void testIncrementAndGetDenied() {
+ performAction(IgniteAtomicLong::incrementAndGet);
+ }
+
+ /** */
+ @Test
+ public void testGetAndDecrementDenied() {
+ performAction(IgniteAtomicLong::getAndDecrement);
+ }
+
+ /** */
+ @Test
+ public void testDecrementAndGetDenied() {
+ performAction(IgniteAtomicLong::decrementAndGet);
+ }
+
+ /** */
+ @Test
+ public void testGetAndSetDenied() {
+ performAction(l -> l.getAndSet(5));
+ }
+
+ /** */
+ @Test
+ public void testCompareAndSetDenied() {
+ performAction(l -> l.compareAndSet(INITIAL_VAL, 5));
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(IgniteAtomicLong::close);
+ }
+
+ /** */
+ @Test
+ public void testAddAndGetDenied() {
+ performAction(l -> l.addAndGet(5));
+ }
+
+ /** */
+ @Test
+ public void testGetAndAddDenied() {
+ performAction(l -> l.getAndAdd(5));
+ }
+
+ /** */
+ void performAction(Consumer<IgniteAtomicLong> action) {
+ IgniteDataStructuresTestUtils.performAction(log, atomicLongs, IgniteAtomicLong::name, action);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicReferenceClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicReferenceClusterReadOnlyTest.java
new file mode 100644
index 0000000..d66e0c7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicReferenceClusterReadOnlyTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteAtomicReference;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getAtomicConfigurations;
+
+/**
+ * Tests methods of {@link IgniteAtomicReference} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteAtomicReferenceClusterReadOnlyTest extends GridCommonAbstractTest {
+ /** Initial value. */
+ private static final int INITIAL_VAL = 0;
+
+ /** Ignite atomic longs. */
+ private static List<IgniteAtomicReference> atomicRefs = new ArrayList<>();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ atomicRefs.add(grid(0).atomicReference(e.getKey(), e.getValue(), INITIAL_VAL, true));
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ atomicRefs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ atomicRefs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testGetInstanceWithoutCreateAllowed() {
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ assertNotNull(e.getKey(), grid(0).atomicReference(e.getKey(), e.getValue(), INITIAL_VAL, false));
+ }
+
+ /** */
+ @Test
+ public void testGetAllowed() {
+ atomicRefs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(IgniteAtomicReference::close);
+ }
+
+ /** */
+ @Test
+ public void testSetDenied() {
+ performAction(r -> r.set(1));
+ }
+
+ /** */
+ @Test
+ public void testCompareAndSetDenied() {
+ performAction(r -> r.compareAndSet(INITIAL_VAL, 1));
+ }
+
+ /** */
+ void performAction(Consumer<IgniteAtomicReference> action) {
+ IgniteDataStructuresTestUtils.performAction(log, atomicRefs, IgniteAtomicReference::name, action);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicSequenceClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicSequenceClusterReadOnlyTest.java
new file mode 100644
index 0000000..d7d55d7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicSequenceClusterReadOnlyTest.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteAtomicSequence;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getAtomicConfigurations;
+
+/**
+ * Tests methods of {@link IgniteAtomicSequence} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteAtomicSequenceClusterReadOnlyTest extends GridCommonAbstractTest {
+ /** Initial value. */
+ private static final int INITIAL_VAL = 0;
+
+ /** Ignite atomic longs. */
+ private static List<IgniteAtomicSequence> atomicSeqs = new ArrayList<>();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ atomicSeqs.add(grid(0).atomicSequence(e.getKey(), e.getValue(), INITIAL_VAL, true));
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ atomicSeqs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ atomicSeqs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testGetAllowed() {
+ atomicSeqs.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get()));
+ }
+
+ /** */
+ @Test
+ public void testGetInstanceWithoutCreateAllowed() {
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ assertNotNull(e.getKey(), grid(0).atomicSequence(e.getKey(), e.getValue(), INITIAL_VAL, false));
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(IgniteAtomicSequence::close);
+ }
+
+ /** */
+ @Test
+ public void testGetAndIncrementDenied() {
+ performAction(IgniteAtomicSequence::getAndIncrement);
+ }
+
+ /** */
+ @Test
+ public void testIncrementAndGetDenied() {
+ performAction(IgniteAtomicSequence::incrementAndGet);
+ }
+
+ /** */
+ @Test
+ public void testAddAndGetDenied() {
+ performAction(l -> l.addAndGet(5));
+ }
+
+ /** */
+ @Test
+ public void testGetAndAddDenied() {
+ performAction(l -> l.getAndAdd(5));
+ }
+
+ /** */
+ void performAction(Consumer<IgniteAtomicSequence> action) {
+ IgniteDataStructuresTestUtils.performAction(log, atomicSeqs, IgniteAtomicSequence::name, action);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicStampedClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicStampedClusterReadOnlyTest.java
new file mode 100644
index 0000000..5a27c88
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteAtomicStampedClusterReadOnlyTest.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteAtomicStamped;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getAtomicConfigurations;
+
+/**
+ * Tests methods of {@link IgniteAtomicStamped} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteAtomicStampedClusterReadOnlyTest extends GridCommonAbstractTest {
+ /** Initial value. */
+ private static final int INITIAL_VAL = 1;
+
+ /** Initial stamp. */
+ private static final int INITIAL_STAMP = 0;
+
+ /** Ignite atomic longs. */
+ private static List<IgniteAtomicStamped> atomicStamps = new ArrayList<>();
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE);
+
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ atomicStamps.add(grid(0).atomicStamped(e.getKey(), e.getValue(), INITIAL_VAL, INITIAL_STAMP, true));
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get().get1()));
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_STAMP, l.get().get2()));
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get().get1()));
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_STAMP, l.get().get2()));
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testGetInstanceWithoutCreateAllowed() {
+ for (Map.Entry<String, AtomicConfiguration> e : getAtomicConfigurations().entrySet())
+ assertNotNull(grid(0).atomicStamped(e.getKey(), e.getValue(), INITIAL_VAL, INITIAL_STAMP, false));
+ }
+
+ /** */
+ @Test
+ public void testGetAllowed() {
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.get().get1()));
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_STAMP, l.get().get2()));
+ }
+
+ /** */
+ @Test
+ public void testGetStampAllowed() {
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_STAMP, l.stamp()));
+ }
+
+ /** */
+ @Test
+ public void testGetValueAllowed() {
+ atomicStamps.forEach(l -> assertEquals(l.name(), INITIAL_VAL, l.value()));
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(IgniteAtomicStamped::close);
+ }
+
+ /** */
+ @Test
+ public void testSetDenied() {
+ performAction(s -> s.set(INITIAL_VAL + 1, INITIAL_STAMP + 1));
+ }
+
+ /** */
+ @Test
+ public void testCompareAndSetDenied() {
+ performAction(s -> s.compareAndSet(INITIAL_VAL, INITIAL_VAL + 1,INITIAL_STAMP, INITIAL_STAMP + 1));
+ }
+
+ /** */
+ void performAction(Consumer<IgniteAtomicStamped> action) {
+ IgniteDataStructuresTestUtils.performAction(log, atomicStamps, IgniteAtomicStamped::name, action);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionsClusterReadOnlyAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionsClusterReadOnlyAbstractTest.java
new file mode 100644
index 0000000..7357557
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCollectionsClusterReadOnlyAbstractTest.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.IgniteSet;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getCollectionConfigurations;
+
+/**
+ * Abstract class for test common methods of {@link IgniteQueue} and {@link IgniteSet} behaviour if cluster in a
+ * {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public abstract class IgniteCollectionsClusterReadOnlyAbstractTest extends GridCommonAbstractTest {
+ /** Node count. */
+ private static final int NODE_CNT = 2;
+
+ /** Element in a queue. */
+ private static final int ELEM = 1;
+
+ /** Collection size. */
+ private static final int COLLECTION_SIZE = 2;
+
+ /** Element not in a queue. */
+ static final int UNKNOWN_ELEM = 777;
+
+ /** Collection of Ignite collections (IgniteQueue or IgniteSet). */
+ static Collection<? extends Collection> igniteCollections;
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setConsistentId(igniteInstanceName);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(NODE_CNT).cluster().state(ClusterState.ACTIVE);
+
+ igniteCollections = createAndFillCollections();
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ igniteCollections = null;
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ commonChecks();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ commonChecks();
+
+ super.afterTest();
+ }
+
+ /**
+ * @param col Given collection.
+ * @return Name of collection.
+ */
+ abstract String name(Collection col);
+
+ /**
+ * Creates distributed collection with given {@code name} and {@code cfg} configuration.
+ *
+ * @param name Collection's name.
+ * @param cfg Collection's config.
+ * @return Distributed collection.
+ */
+ abstract Collection createCollection(String name, CollectionConfiguration cfg);
+
+ /** */
+ @Test
+ public void testClearDenied() {
+ performAction(Collection::clear);
+ }
+
+ /** */
+ @Test
+ public void testRemoveDenied() {
+ performAction(c -> c.remove(ELEM));
+ }
+
+ /** */
+ @Test
+ public void testRemoveAllDenied() {
+ performAction(c -> c.removeAll(Arrays.asList(ELEM, name(c))));
+
+ igniteCollections.forEach(c -> assertFalse(name(c), c.contains(UNKNOWN_ELEM)));
+
+ performAction(c -> c.removeAll(Arrays.asList(UNKNOWN_ELEM, name(c))));
+ }
+
+ /** */
+ @Test
+ public void testRetainAllDenied() {
+ igniteCollections.forEach(c -> assertFalse(name(c), c.contains(UNKNOWN_ELEM)));
+
+ performAction(c -> c.retainAll(Arrays.asList(UNKNOWN_ELEM, name(c))));
+
+ // All elements in a collection is a collection in retainAll. So nothing to remove.
+ igniteCollections.forEach(c -> c.retainAll(Arrays.asList(ELEM, name(c))));
+ }
+
+ /** */
+ @Test
+ public void testSizeAllowed() {
+ igniteCollections.forEach(c -> assertEquals(name(c), COLLECTION_SIZE, c.size()));
+ }
+
+ /** */
+ @Test
+ public void testIsEmptyAllowed() {
+ igniteCollections.forEach(c -> assertFalse(name(c), c.isEmpty()));
+ }
+
+ /** */
+ @Test
+ public void testAddDenied() {
+ performAction(queue -> queue.add("tmp"));
+ }
+
+ /** */
+ @Test
+ public void testAddAllDenied() {
+ performAction(queue -> queue.addAll(Arrays.asList("tmp", "tmp2")));
+ }
+
+ /** */
+ @Test
+ public void testContainsAllowed() {
+ for (Collection col : igniteCollections) {
+ assertTrue(name(col), col.contains(ELEM));
+ assertFalse(name(col), col.contains(UNKNOWN_ELEM));
+ }
+ }
+
+ /** */
+ @Test
+ public void testContainsAllAllowed() {
+ for (Collection col : igniteCollections) {
+ assertTrue(name(col), col.containsAll(Arrays.asList(ELEM, name(col))));
+ assertFalse(name(col), col.containsAll(Arrays.asList(UNKNOWN_ELEM, name(col))));
+ }
+ }
+
+ private void commonChecks() {
+ igniteCollections.forEach(c -> assertEquals(name(c), COLLECTION_SIZE, c.size()));
+ igniteCollections.forEach(c -> assertTrue(name(c), c.containsAll(Arrays.asList(ELEM, name(c)))));
+
+ G.allGrids().forEach(n -> assertEquals(ClusterState.ACTIVE_READ_ONLY, n.cluster().state()));
+ }
+
+ /**
+ * Performs given {@code action} for all presented collections and check that {@link IgniteClusterReadOnlyException}
+ * had been thrown.
+ *
+ * @param action Action with a collection.
+ * @see IgniteDataStructuresTestUtils#performAction(IgniteLogger, Collection, Function, Consumer)
+ */
+ void performAction(Consumer<? super Collection> action) {
+ IgniteDataStructuresTestUtils.performAction(log, igniteCollections, this::name, action);
+ }
+
+ /** */
+ private Collection<Collection> createAndFillCollections() {
+ List<Collection> collections = new ArrayList<>();
+
+ for (Map.Entry<String, CollectionConfiguration> e : getCollectionConfigurations().entrySet()) {
+ Collection col = createCollection(e.getKey(), e.getValue());
+
+ assertTrue(col.add(name(col)));
+ assertTrue(col.add(ELEM));
+
+ assertEquals(name(col), COLLECTION_SIZE, col.size());
+
+ collections.add(col);
+ }
+
+ return collections;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCountDownLatchClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCountDownLatchClusterReadOnlyTest.java
new file mode 100644
index 0000000..3d30385
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteCountDownLatchClusterReadOnlyTest.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.function.Consumer;
+import org.apache.ignite.IgniteCountDownLatch;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static java.util.Collections.singleton;
+
+/**
+ * Tests methods of {@link IgniteCountDownLatch} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteCountDownLatchClusterReadOnlyTest extends GridCommonAbstractTest {
+ /** Latch name. */
+ private static final String LATCH_NAME = "test-latch";
+
+ /** Latch initial value. */
+ private static final int LATCH_INITIAL_VALUE = 10;
+
+ /** Latch. */
+ private static IgniteCountDownLatch latch;
+
+ /** Latch. */
+ private static IgniteCountDownLatch latchForClose;
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ IgniteEx crd = startGrids(2);
+
+ crd.cluster().state(ClusterState.ACTIVE);
+
+ latch = crd.countDownLatch(LATCH_NAME, LATCH_INITIAL_VALUE, false, true);
+ latchForClose = crd.countDownLatch(LATCH_NAME + "2", 1, false, true);
+
+ latchForClose.countDown();
+
+ crd.cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ assertEquals(latch.name(), LATCH_INITIAL_VALUE, latch.count());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ assertEquals(latch.name(), LATCH_INITIAL_VALUE, latch.count());
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testCountAllowed() {
+ assertEquals(LATCH_INITIAL_VALUE, latch.count());
+ }
+
+ /** */
+ @Test
+ public void testGetInstanceWithoutCreateAllowed() {
+ assertNotNull(grid(0).countDownLatch(LATCH_NAME, LATCH_INITIAL_VALUE, false, false));
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ assertEquals(0, latchForClose.count());
+
+ IgniteDataStructuresTestUtils.performAction(
+ log,
+ singleton(latchForClose),
+ IgniteCountDownLatch::name,
+ IgniteCountDownLatch::close
+ );
+ }
+
+ /** */
+ @Test
+ public void testCountDown() {
+ performAction(IgniteCountDownLatch::countDown);
+ }
+
+ /** */
+ @Test
+ public void testCountDown2() {
+ performAction(l -> l.countDown(2));
+ }
+
+ /** */
+ @Test
+ public void testCountDownAll() {
+ performAction(IgniteCountDownLatch::countDownAll);
+ }
+
+ /** */
+ private void performAction(Consumer<IgniteCountDownLatch> action) {
+ IgniteDataStructuresTestUtils.performAction(log, singleton(latch), IgniteCountDownLatch::name, action);
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresCreateDeniedInClusterReadOnlyMode.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresCreateDeniedInClusterReadOnlyMode.java
new file mode 100644
index 0000000..c40cbff
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresCreateDeniedInClusterReadOnlyMode.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.Map;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getAtomicConfigurations;
+import static org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresTestUtils.getCollectionConfigurations;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Tests that Ignite data structures can't be created if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} mode.
+ */
+public class IgniteDataStructuresCreateDeniedInClusterReadOnlyMode extends GridCommonAbstractTest {
+ /** {@inheritDoc} */
+ @Override protected void beforeTestsStarted() throws Exception {
+ super.beforeTestsStarted();
+
+ stopAllGrids();
+
+ startGrids(2);
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTestsStopped() throws Exception {
+ stopAllGrids();
+
+ super.afterTestsStopped();
+ }
+
+ /** */
+ @Test
+ public void testAtomicLong() {
+ for (Map.Entry<String, AtomicConfiguration> t : getAtomicConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).atomicLong(t.getKey(), t.getValue(), 0, true),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testAtomicReference() {
+ for (Map.Entry<String, AtomicConfiguration> t : getAtomicConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).atomicReference(t.getKey(), t.getValue(), null, true),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testIgniteSet() {
+ for (Map.Entry<String, CollectionConfiguration> t : getCollectionConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).set(t.getKey(), t.getValue()),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testIgniteQueue() {
+ for (Map.Entry<String, CollectionConfiguration> t : getCollectionConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).queue(t.getKey(), 0, t.getValue()),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testIgniteAtomicSequence() {
+ for (Map.Entry<String, AtomicConfiguration> t : getAtomicConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).atomicSequence(t.getKey(), t.getValue(), 0, true),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testIgniteAtomicStamped() {
+ for (Map.Entry<String, AtomicConfiguration> t : getAtomicConfigurations().entrySet()) {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).atomicStamped(t.getKey(), t.getValue(), 0, 0, true),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, t.getKey());
+ }
+ }
+
+ /** */
+ @Test
+ public void testIgniteCountDownLatch() {
+ Throwable ex = assertThrows(
+ log,
+ () -> grid(0).countDownLatch("test-latch", 10, false, true),
+ Exception.class,
+ null
+ );
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, "test-latch");
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresTestUtils.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresTestUtils.java
new file mode 100644
index 0000000..fa7beec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteDataStructuresTestUtils.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.apache.ignite.IgniteLogger;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.AtomicConfiguration;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils;
+import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ *
+ */
+class IgniteDataStructuresTestUtils {
+ /** */
+ private IgniteDataStructuresTestUtils() {
+ // No-op
+ }
+
+ /**
+ * Performs given {@code action} for all presented elements of given {@code collection} and heck that
+ * {@link IgniteClusterReadOnlyException} had been thrown.
+ *
+ * @param log Logger
+ * @param collection Collection for applying action
+ * @param nameExtractor Function for extraction element collection nam
+ * @param action Action.
+ * @param <E> Type of element's collection.
+ */
+ static <E> void performAction(
+ IgniteLogger log,
+ Collection<E> collection,
+ Function<E, String> nameExtractor,
+ Consumer<? super E> action
+ ) {
+ for (E e : collection) {
+ Throwable ex = assertThrows(log, () -> action.accept(e), Exception.class, null);
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(ex, nameExtractor.apply(e));
+ }
+ }
+
+ /**
+ * @return All variations of configurations according to backups and cache mode.
+ */
+ public static Map<String, AtomicConfiguration> getAtomicConfigurations() {
+ Map<String, AtomicConfiguration> configs = new HashMap<>();
+
+ for (int backups : Arrays.asList(0, 1)) {
+ for (CacheMode cacheMode : CacheMode.values()) {
+ if (cacheMode == CacheMode.LOCAL) {
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-13076
+ continue;
+ }
+
+ AtomicConfiguration cfg = new AtomicConfiguration()
+ .setBackups(backups)
+ .setCacheMode(cacheMode)
+ .setGroupName(cacheMode + "-grp-" + backups);
+
+ AtomicConfiguration old = configs.put("" + backups + cacheMode, cfg);
+
+ assert old == null : old;
+ }
+ }
+
+ return configs;
+ }
+
+ /**
+ * @return All variations of configurations according to atomicity mode, backups, cache mode and collocation flag.
+ */
+ public static Map<String, CollectionConfiguration> getCollectionConfigurations() {
+ Map<String, CollectionConfiguration> configs = new HashMap<>();
+
+ for (boolean collocated : Arrays.asList(true, false)) {
+ for (CacheAtomicityMode atomicityMode : Arrays.asList(TRANSACTIONAL, ATOMIC)) {
+ for (int backups : Arrays.asList(0, 1)) {
+ for (CacheMode cacheMode : CacheMode.values()) {
+ if (cacheMode == CacheMode.LOCAL) {
+ // TODO: https://issues.apache.org/jira/browse/IGNITE-13076
+ continue;
+ }
+
+ CollectionConfiguration cfg = new CollectionConfiguration()
+ .setCollocated(collocated)
+ .setAtomicityMode(atomicityMode)
+ .setBackups(backups)
+ .setCacheMode(cacheMode)
+ .setGroupName(cacheMode + "-grp-" + backups);
+
+ CollectionConfiguration old = configs.put("" + collocated + atomicityMode + backups + cacheMode, cfg);
+
+ assert old == null : old;
+ }
+ }
+ }
+ }
+
+ return configs;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteQueueClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteQueueClusterReadOnlyTest.java
new file mode 100644
index 0000000..b6bb791
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteQueueClusterReadOnlyTest.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteQueue;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.junit.Test;
+
+/**
+ * Tests specific methods of {@link IgniteQueue} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteQueueClusterReadOnlyTest extends IgniteCollectionsClusterReadOnlyAbstractTest {
+ /** */
+ @Test
+ public void testOfferDenied() {
+ performAction(c -> cast(c).offer("tmp"));
+ }
+
+ /** */
+ @Test
+ public void testPollDenied() {
+ performAction(c -> cast(c).poll());
+ }
+
+ /** */
+ @Test
+ public void testPeekAllowed() {
+ igniteCollections.forEach(c -> assertEquals(name(c), name(c), cast(c).peek()));
+ }
+
+ /** */
+ @Test
+ public void testPutDenied() {
+ performAction(c -> cast(c).put("tmp"));
+ }
+
+ /** */
+ @Test
+ public void testTakeDenied() {
+ performAction(c -> cast(c).take());
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(c -> cast(c).close());
+ }
+
+ @Override public void testRemoveDenied() {
+ super.testRemoveDenied();
+
+ igniteCollections.forEach(c -> assertFalse(name(c), c.contains(UNKNOWN_ELEM)));
+
+ // Unknown element doesn't exist in a collection. So exception won't be thrown.
+ igniteCollections.forEach(c -> assertFalse(name(c), c.remove(UNKNOWN_ELEM)));
+ }
+
+ /** {@inheritDoc} */
+ @Override String name(Collection col) {
+ assertTrue(col + "", col instanceof IgniteQueue);
+
+ return ((IgniteQueue)col).name();
+ }
+
+ /** {@inheritDoc} */
+ @Override Collection createCollection(String name, CollectionConfiguration cfg) {
+ return grid(0).queue(name, 0, cfg);
+ }
+
+ /** */
+ private IgniteQueue cast(Collection col) {
+ return (IgniteQueue)col;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSetClusterReadOnlyTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSetClusterReadOnlyTest.java
new file mode 100644
index 0000000..9868404
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/datastructures/IgniteSetClusterReadOnlyTest.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache.datastructures;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteSet;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CollectionConfiguration;
+import org.junit.Test;
+
+/**
+ * Tests specific methods of {@link IgniteSet} behaviour if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class IgniteSetClusterReadOnlyTest extends IgniteCollectionsClusterReadOnlyAbstractTest {
+ /** {@inheritDoc} */
+ @Override String name(Collection col) {
+ assertTrue(col + "", col instanceof IgniteSet);
+
+ return ((IgniteSet)col).name();
+ }
+
+ /** {@inheritDoc} */
+ @Override Collection createCollection(String name, CollectionConfiguration cfg) {
+ return grid(0).set(name, cfg);
+ }
+
+ /** */
+ @Test
+ public void testCloseDenied() {
+ performAction(c -> cast(c).close());
+ }
+
+ /** */
+ @Test
+ @Override public void testRemoveDenied() {
+ super.testRemoveDenied();
+
+ igniteCollections.forEach(c -> assertFalse(name(c), c.contains(UNKNOWN_ELEM)));
+
+ performAction(c -> assertFalse(name(c), c.remove(UNKNOWN_ELEM)));
+ }
+
+ /** */
+ private IgniteSet cast(Collection c) {
+ return (IgniteSet)c;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterReadOnlyModeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterReadOnlyModeSelfTest.java
index 29220e6..97eb926 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterReadOnlyModeSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cluster/ClusterReadOnlyModeSelfTest.java
@@ -29,6 +29,8 @@ import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.failure.StopNodeFailureHandler;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.processors.cache.distributed.dht.IgniteClusterReadOnlyException;
+import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager;
+import org.apache.ignite.internal.processors.cache.persistence.metastorage.MetaStorage;
import org.apache.ignite.internal.processors.service.GridServiceAssignmentsKey;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.testframework.GridTestUtils;
@@ -46,14 +48,14 @@ import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTes
/**
* Checks main functionality of cluster read-only mode. In this mode cluster will be available only for read operations,
* all data modification operations in user caches will be rejected with {@link IgniteClusterReadOnlyException}
- *
- * 1) Read-only mode could be enabled on active cluster only.
- * 2) Read-only mode doesn't store on PDS (i.e. after cluster restart enabled read-only mode will be forgotten)
- * 3) Updates to ignite-sys-cache will be available with enabled read-only mode.
- * 4) Updates to distributed metastorage will be available with enabled read-only mode.
- * 5) Read-only mode can't be enabled inside transaction.
- * 6) Lock can't be get with enabled read-only mode.
- *
+ * <br/>
+ * 1) Read-only mode could be enabled on active cluster only. <br/>
+ * 2) Read-only mode doesn't store on PDS (i.e. after cluster restart enabled read-only mode will be forgotten) <br/>
+ * 3) Updates to ignite-sys-cache will be available with enabled read-only mode. <br/>
+ * 4) Updates to distributed metastorage will be available with enabled read-only mode. <br/>
+ * 5) Updates to local metastorage will be available with enabled read-only mode. <br/>
+ * 6) Read-only mode can't be enabled inside transaction.<br/>
+ * 7) Lock can't be get with enabled read-only mode. <br/>
*/
public class ClusterReadOnlyModeSelfTest extends GridCommonAbstractTest {
/** Server nodes count. */
@@ -91,6 +93,45 @@ public class ClusterReadOnlyModeSelfTest extends GridCommonAbstractTest {
/** */
@Test
+ public void testMetaStorageAvailableForUpdatesOnReadOnlyCluster() throws Exception {
+ IgniteEx node = startGrid(0);
+
+ node.cluster().state(ACTIVE);
+
+ IgniteCacheDatabaseSharedManager db = node.context().cache().context().database();
+
+ MetaStorage metaStorage = db.metaStorage();
+
+ db.checkpointReadLock();
+
+ try {
+ metaStorage.write("key", "val");
+ }
+ finally {
+ db.checkpointReadUnlock();
+ }
+
+ node.cluster().state(ACTIVE_READ_ONLY);
+
+ db.checkpointReadLock();
+
+ try {
+ assertEquals("val", metaStorage.read("key"));
+
+ metaStorage.write("key", "new_val");
+
+ assertEquals("new_val", metaStorage.read("key"));
+
+ metaStorage.remove("key");
+
+ assertNull(metaStorage.read("key"));
+ } finally {
+ db.checkpointReadUnlock();
+ }
+ }
+
+ /** */
+ @Test
public void testDistributedMetastorageAvailableForUpdatesOnReadOnlyCluster() throws Exception {
IgniteEx node = startGrids(SERVER_NODES_COUNT);
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceClusterReadOnlyModeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceClusterReadOnlyModeTest.java
new file mode 100644
index 0000000..9187a359
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceClusterReadOnlyModeTest.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.service;
+
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeAbstractTest;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceContext;
+import org.junit.Test;
+
+import static org.apache.ignite.cluster.ClusterState.ACTIVE_READ_ONLY;
+import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.assertCachesReadOnlyMode;
+import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
+
+/**
+ * Checks that updates from deployed service will be rejected, if cluster in a {@link ClusterState#ACTIVE_READ_ONLY}
+ * mode.
+ */
+public class GridServiceClusterReadOnlyModeTest extends ClusterReadOnlyModeAbstractTest {
+ /** Wait timeout. */
+ private static final long WAIT_TIMEOUT = 60_000L;
+
+ /** Barrier. */
+ private static final CyclicBarrier BARRIER = new CyclicBarrier(2);
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ grid(0).services().cancelAll();
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ grid(0).services().cancelAll();
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void test() throws BrokenBarrierException, InterruptedException, TimeoutException {
+ grid(0).services().deployClusterSingleton("updater-service", new CacheUpdaterService());
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+
+ changeClusterReadOnlyMode(true);
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+
+ changeClusterReadOnlyMode(false);
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ *
+ */
+ private static class CacheUpdaterService implements Service {
+ /** */
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ /** {@inheritDoc} */
+ @Override public void cancel(ServiceContext ctx) {
+ /* No-op. */
+ }
+
+ /** {@inheritDoc} */
+ @Override public void init(ServiceContext ctx) throws Exception {
+ /* No-op. */
+ }
+
+ /** {@inheritDoc} */
+ @Override public void execute(ServiceContext ctx) throws Exception {
+ assertCachesReadOnlyMode(ignite, false, CACHE_NAMES);
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+
+ assertTrue(waitForCondition(() -> ignite.cluster().state() == ACTIVE_READ_ONLY, WAIT_TIMEOUT));
+
+ assertCachesReadOnlyMode(ignite, true, CACHE_NAMES);
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+
+ assertTrue(waitForCondition(() -> ignite.cluster().state() != ACTIVE_READ_ONLY, WAIT_TIMEOUT));
+
+ assertCachesReadOnlyMode(ignite, false, CACHE_NAMES);
+
+ BARRIER.await(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
+ }
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeployClusterReadOnlyModeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeployClusterReadOnlyModeTest.java
new file mode 100644
index 0000000..eb4ecb1
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/service/GridServiceDeployClusterReadOnlyModeTest.java
@@ -0,0 +1,393 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.service;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteServices;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.failure.StopNodeFailureHandler;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.services.Service;
+import org.apache.ignite.services.ServiceConfiguration;
+import org.apache.ignite.services.ServiceContext;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Test;
+
+import static java.util.stream.Collectors.toSet;
+
+/**
+ * Checks that {@link Service} deploy/cancel by {@link IgniteServices} API works fine if cluster in a
+ * {@link ClusterState#ACTIVE_READ_ONLY} mode.
+ */
+public class GridServiceDeployClusterReadOnlyModeTest extends GridCommonAbstractTest {
+ /** Service name. */
+ private static final String SERVICE_NAME = "test-service";
+
+ /** Nodes count. */
+ private static int NODES_CNT = 2;
+
+ /** Service initialize flag. */
+ private static final Map<String, Boolean> SERVICE_INIT_FLAGS = new HashMap<>();
+
+ /** Service execute flag. */
+ private static final Map<String, Boolean> SERVICE_EXECUTE_FLAGS = new HashMap<>();
+
+ /** Service cancel flag. */
+ private static final Map<String, Boolean> SERVICE_CANCEL_FLAGS = new HashMap<>();
+
+ /** {@inheritDoc} */
+ @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
+ return super.getConfiguration(igniteInstanceName)
+ .setFailureHandler(new StopNodeFailureHandler());
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ stopAllGrids();
+
+ SERVICE_INIT_FLAGS.clear();
+ SERVICE_EXECUTE_FLAGS.clear();
+ SERVICE_CANCEL_FLAGS.clear();
+
+ startGrids(NODES_CNT);
+ }
+
+ /** {@inheritDoc} */
+ @Override protected void afterTest() throws Exception {
+ stopAllGrids();
+
+ super.afterTest();
+ }
+
+ /** */
+ @Test
+ public void testDeployClusterSingletonAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deployClusterSingleton(SERVICE_NAME, new TestService()), true);
+
+ cancelServiceAndCheck(true);
+ }
+
+ /** */
+ @Test
+ public void testDeployClusterSingletonAsyncAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deployClusterSingletonAsync(SERVICE_NAME, new TestService()).get(), true);
+
+ cancelServiceAndCheck(true);
+ }
+
+ /** */
+ @Test
+ public void testDeployNodeSingletonAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deployNodeSingleton(SERVICE_NAME, new TestService()), false);
+
+ cancelServiceAndCheck(false);
+ }
+
+ /** */
+ @Test
+ public void testDeployNodeSingletonAsyncAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deployNodeSingletonAsync(SERVICE_NAME, new TestService()).get(), false);
+
+ cancelServiceAndCheck(false);
+ }
+
+ /** */
+ @Test
+ public void testDeployMultipleAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(
+ s -> s.deployMultiple(SERVICE_NAME, new TestService(), NODES_CNT, 1),
+ false
+ );
+
+ cancelServiceAndCheck(false);
+ }
+
+ /** */
+ @Test
+ public void testDeployMultipleAsyncAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(
+ s -> s.deployMultipleAsync(SERVICE_NAME, new TestService(), NODES_CNT, 1).get(),
+ false
+ );
+
+ cancelServiceAndCheck(false);
+ }
+
+ /** */
+ @Test
+ public void testDeployAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deploy(serviceConfiguration(SERVICE_NAME)), true);
+
+ cancelServiceAndCheck(true);
+ }
+
+ /** */
+ @Test
+ public void testDeployAsyncAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ deployServiceAndCheck(s -> s.deployAsync(serviceConfiguration(SERVICE_NAME)).get(), true);
+
+ cancelServiceAndCheck(true);
+ }
+
+ /** */
+ @Test
+ public void testDeployAllAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ Collection<String> serviceNames = new HashSet<>();
+
+ for (int i = 0; i < 2; i++)
+ serviceNames.add(SERVICE_NAME + "_" + i);
+
+ Set<ServiceConfiguration> configs = serviceNames.stream()
+ .map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
+ .collect(toSet());
+
+ grid(0).services().deployAll(configs);
+
+ for (String serviceName : serviceNames)
+ checkServiceDeployed(serviceName, true);
+
+ grid(0).services().cancelAll(serviceNames);
+
+ for (String serviceName : serviceNames)
+ checkServiceCanceled(serviceName, true);
+ }
+
+ /** */
+ @Test
+ public void testDeployAllAsyncAllowed() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ Collection<String> serviceNames = new HashSet<>();
+
+ for (int i = 0; i < 2; i++)
+ serviceNames.add(SERVICE_NAME + "_" + i);
+
+ Set<ServiceConfiguration> configs = serviceNames.stream()
+ .map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
+ .collect(toSet());
+
+ grid(0).services().deployAllAsync(configs).get();
+
+ for (String serviceName : serviceNames)
+ checkServiceDeployed(serviceName, true);
+
+ grid(0).services().cancelAll(serviceNames);
+
+ for (String serviceName : serviceNames)
+ checkServiceCanceled(serviceName, true);
+ }
+
+ /** */
+ @Test
+ public void testCancelAllowed() {
+ deployServiceAndCheck(services -> services.deploy(serviceConfiguration(SERVICE_NAME)), true);
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ cancelServiceAndCheck(true);
+ }
+
+ /** */
+ @Test
+ public void testCancelAsyncAllowed() {
+ deployServiceAndCheck(services -> services.deploy(serviceConfiguration(SERVICE_NAME)), true);
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ grid(0).services().cancelAsync(SERVICE_NAME).get();
+
+ checkServiceCanceled(true);
+ }
+
+ /** */
+ @Test
+ public void testCancelAllAllowed() {
+ Collection<String> serviceNames = new HashSet<>();
+
+ for (int i = 0; i < 2; i++)
+ serviceNames.add(SERVICE_NAME + "_" + i);
+
+ Set<ServiceConfiguration> configs = serviceNames.stream()
+ .map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
+ .collect(toSet());
+
+ grid(0).services().deployAll(configs);
+
+ for (String serviceName : serviceNames)
+ checkServiceDeployed(serviceName, true);
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ grid(0).services().cancelAll(serviceNames);
+
+ for (String name : serviceNames)
+ checkServiceCanceled(name, true);
+ }
+
+ /** */
+ @Test
+ public void testCancelAllAsyncAllowed() {
+ Collection<String> serviceNames = new HashSet<>();
+
+ for (int i = 0; i < 2; i++)
+ serviceNames.add(SERVICE_NAME + "_" + i);
+
+ Set<ServiceConfiguration> configs = serviceNames.stream()
+ .map(GridServiceDeployClusterReadOnlyModeTest::serviceConfiguration)
+ .collect(toSet());
+
+ grid(0).services().deployAll(configs);
+
+ for (String serviceName : serviceNames)
+ checkServiceDeployed(serviceName, true);
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ grid(0).services().cancelAllAsync(serviceNames).get();
+
+ for (String name : serviceNames)
+ checkServiceCanceled(name, true);
+ }
+
+ /** */
+ private void deployServiceAndCheck(Consumer<IgniteServices> clo, boolean singleNode) {
+ clo.accept(grid(0).services());
+
+ checkServiceDeployed(singleNode);
+ }
+
+ /** */
+ private void cancelServiceAndCheck(boolean singleNode) {
+ grid(0).services().cancel(SERVICE_NAME);
+
+ checkServiceCanceled(singleNode);
+ }
+
+ /** */
+ private static void checkServiceCanceled(boolean singleNode) {
+ checkServiceCanceled(SERVICE_NAME, singleNode);
+ }
+
+ /** */
+ private static void checkServiceCanceled(String name, boolean singleNode) {
+ checkMap(SERVICE_CANCEL_FLAGS, name, singleNode ? 1 : NODES_CNT, true);
+ }
+
+ /** */
+ private static void checkServiceDeployed(boolean singleNode) {
+ checkServiceDeployed(SERVICE_NAME, singleNode);
+ }
+
+ /** */
+ private static void checkServiceDeployed(String name, boolean singleNode) {
+ checkMap(SERVICE_INIT_FLAGS, name, singleNode ? 1 : NODES_CNT, true);
+ checkMap(SERVICE_EXECUTE_FLAGS, name, singleNode ? 1 : NODES_CNT, true);
+ checkMap(SERVICE_CANCEL_FLAGS, name, singleNode ? 1 : NODES_CNT, false);
+ }
+
+ /** */
+ private static void checkMap(Map<String, Boolean> map, String prefix, int expectedCount, boolean expectedValue) {
+ Collection<String> matchedNames = new HashSet<>();
+
+ for (Map.Entry<String, Boolean> entry : map.entrySet()) {
+ if (entry.getKey().startsWith(prefix)) {
+ matchedNames.add(entry.getKey());
+
+ assertEquals(entry.getKey(), expectedValue, entry.getValue().booleanValue());
+ }
+ }
+
+ assertEquals(matchedNames.toString(), expectedCount, matchedNames.size());
+ }
+
+ /** */
+ private static ServiceConfiguration serviceConfiguration(String name) {
+ return new ServiceConfiguration()
+ .setTotalCount(1)
+ .setName(name)
+ .setService(new TestService());
+ }
+
+ /** */
+ private static String name(String serviceName, String nodeName) {
+ return serviceName + nodeName;
+ }
+
+ /**
+ *
+ */
+ private static class TestService implements Service {
+ /** */
+ @IgniteInstanceResource
+ private Ignite ignite;
+
+ /** {@inheritDoc} */
+ @Override public void cancel(ServiceContext ctx) {
+ String key = name(ctx.name(), ignite.name());
+
+ assertFalse(key, SERVICE_CANCEL_FLAGS.get(key));
+
+ SERVICE_CANCEL_FLAGS.put(key, true);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void init(ServiceContext ctx) throws Exception {
+ String key = name(ctx.name(), ignite.name());
+
+ SERVICE_INIT_FLAGS.put(key, true);
+ SERVICE_EXECUTE_FLAGS.put(key, false);
+ SERVICE_CANCEL_FLAGS.put(key, false);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void execute(ServiceContext ctx) throws Exception {
+ String key = name(ctx.name(), ignite.name());
+
+ assertFalse(key, SERVICE_EXECUTE_FLAGS.get(key));
+
+ SERVICE_EXECUTE_FLAGS.put(key, true);
+ }
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
index 42216ca..0e09d4c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheDataStructuresSelfTestSuite.java
@@ -28,11 +28,19 @@ import org.apache.ignite.internal.processors.cache.consistency.SingleBackupImpli
import org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueCleanupSelfTest;
import org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueClientDisconnectTest;
import org.apache.ignite.internal.processors.cache.datastructures.GridCacheQueueMultiNodeConsistencySelfTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteAtomicLongClusterReadOnlyTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteAtomicReferenceClusterReadOnlyTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteAtomicSequenceClusterReadOnlyTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteAtomicStampedClusterReadOnlyTest;
import org.apache.ignite.internal.processors.cache.datastructures.IgniteClientDataStructuresTest;
import org.apache.ignite.internal.processors.cache.datastructures.IgniteClientDiscoveryDataStructuresTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteCountDownLatchClusterReadOnlyTest;
import org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructureUniqueNameTest;
import org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructureWithJobTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteDataStructuresCreateDeniedInClusterReadOnlyMode;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteQueueClusterReadOnlyTest;
import org.apache.ignite.internal.processors.cache.datastructures.IgniteSequenceInternalCleanupTest;
+import org.apache.ignite.internal.processors.cache.datastructures.IgniteSetClusterReadOnlyTest;
import org.apache.ignite.internal.processors.cache.datastructures.SemaphoreFailoverNoWaitingAcquirerTest;
import org.apache.ignite.internal.processors.cache.datastructures.SemaphoreFailoverSafeReleasePermitsTest;
import org.apache.ignite.internal.processors.cache.datastructures.local.GridCacheLocalAtomicQueueApiSelfTest;
@@ -204,6 +212,15 @@ import org.junit.runners.Suite;
ExplicitTransactionalReadRepairTest.class,
SingleBackupExplicitTransactionalReadRepairTest.class,
ReplicatedExplicitTransactionalReadRepairTest.class,
+
+ IgniteAtomicLongClusterReadOnlyTest.class,
+ IgniteAtomicReferenceClusterReadOnlyTest.class,
+ IgniteAtomicSequenceClusterReadOnlyTest.class,
+ IgniteAtomicStampedClusterReadOnlyTest.class,
+ IgniteCountDownLatchClusterReadOnlyTest.class,
+ IgniteDataStructuresCreateDeniedInClusterReadOnlyMode.class,
+ IgniteQueueClusterReadOnlyTest.class,
+ IgniteSetClusterReadOnlyTest.class
})
public class IgniteCacheDataStructuresSelfTestSuite {
}
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
index 30d8d63..f5065a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheFullApiSelfTestSuite.java
@@ -18,6 +18,11 @@
package org.apache.ignite.testsuites;
import org.apache.ignite.internal.processors.cache.GridCacheClearSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheClusterReadOnlyModeSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheInvokeClusterReadOnlyModeSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheStoreClusterReadOnlyModeSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteNearCacheClusterReadOnlyModeSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteNearCacheInvokeClusterReadOnlyModeSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicFullApiSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicNearEnabledFullApiSelfTest;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAtomicReloadAllSelfTest;
@@ -164,6 +169,12 @@ import org.junit.runners.Suite;
GridCachePartitionedMultiNodeWithGroupFullApiSelfTest.class,
GridCachePartitionedNearDisabledMultiNodeWithGroupFullApiSelfTest.class,
+ IgniteCacheClusterReadOnlyModeSelfTest.class,
+ IgniteNearCacheClusterReadOnlyModeSelfTest.class,
+ IgniteCacheInvokeClusterReadOnlyModeSelfTest.class,
+ IgniteNearCacheInvokeClusterReadOnlyModeSelfTest.class,
+ IgniteCacheStoreClusterReadOnlyModeSelfTest.class,
+
//suite.addTest(new JUnit4TestAdapter(GridActivateExtensionTest.class));
})
public class IgniteCacheFullApiSelfTestSuite {
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite5.java
index 8514db0..189934d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheMvccTestSuite5.java
@@ -27,6 +27,7 @@ import org.apache.ignite.cache.affinity.AffinityDistributionLoggingTest;
import org.apache.ignite.cache.affinity.AffinityHistoryCleanupTest;
import org.apache.ignite.cache.affinity.local.LocalAffinityFunctionTest;
import org.apache.ignite.internal.GridCachePartitionExchangeManagerHistSizeTest;
+import org.apache.ignite.internal.processors.cache.CacheCreateDestroyClusterReadOnlyModeTest;
import org.apache.ignite.internal.processors.cache.CacheSerializableTransactionsTest;
import org.apache.ignite.internal.processors.cache.ClientSlowDiscoveryTransactionRemapTest;
import org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTest;
@@ -75,6 +76,7 @@ public class IgniteCacheMvccTestSuite5 {
ignoredTests.add(IgniteCacheStoreCollectionTest.class);
ignoredTests.add(EntryVersionConsistencyReadThroughTest.class);
ignoredTests.add(ClusterReadOnlyModeTest.class);
+ ignoredTests.add(CacheCreateDestroyClusterReadOnlyModeTest.class);
ignoredTests.add(NotMappedPartitionInTxTest.class);
ignoredTests.add(IgniteCacheTxIteratorSelfTest.class);
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
index d3fec85..d96d929 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteCacheTestSuite5.java
@@ -29,6 +29,7 @@ import org.apache.ignite.cache.affinity.local.LocalAffinityFunctionTest;
import org.apache.ignite.internal.GridCacheHashMapPutAllWarningsTest;
import org.apache.ignite.internal.GridCachePartitionExchangeManagerHistSizeTest;
import org.apache.ignite.internal.GridCachePartitionExchangeManagerWarningsTest;
+import org.apache.ignite.internal.processors.cache.CacheCreateDestroyClusterReadOnlyModeTest;
import org.apache.ignite.internal.processors.cache.CacheKeepBinaryTransactionTest;
import org.apache.ignite.internal.processors.cache.CacheNearReaderUpdateTest;
import org.apache.ignite.internal.processors.cache.CacheRebalancingSelfTest;
@@ -113,6 +114,7 @@ public class IgniteCacheTestSuite5 {
GridTestUtils.addTestIfNeeded(suite, ClusterStateThinClientReplicatedSelfTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, ClusterStateNoRebalanceReplicatedTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, ClusterReadOnlyModeTest.class, ignoredTests);
+ GridTestUtils.addTestIfNeeded(suite, CacheCreateDestroyClusterReadOnlyModeTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, IgniteCachePartitionLossPolicySelfTest.class, ignoredTests);
GridTestUtils.addTestIfNeeded(suite, IgniteCacheGroupsPartitionLossPolicySelfTest.class, ignoredTests);
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceGridTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceGridTestSuite.java
index 11851d1..877417c 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceGridTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteServiceGridTestSuite.java
@@ -20,7 +20,9 @@ package org.apache.ignite.testsuites;
import org.apache.ignite.internal.ComputeJobCancelWithServiceSelfTest;
import org.apache.ignite.internal.processors.service.ClosureServiceClientsNodesTest;
import org.apache.ignite.internal.processors.service.GridServiceClientNodeTest;
+import org.apache.ignite.internal.processors.service.GridServiceClusterReadOnlyModeTest;
import org.apache.ignite.internal.processors.service.GridServiceContinuousQueryRedeployTest;
+import org.apache.ignite.internal.processors.service.GridServiceDeployClusterReadOnlyModeTest;
import org.apache.ignite.internal.processors.service.GridServiceDeploymentCompoundFutureSelfTest;
import org.apache.ignite.internal.processors.service.GridServiceDeploymentExceptionPropagationTest;
import org.apache.ignite.internal.processors.service.GridServicePackagePrivateSelfTest;
@@ -113,6 +115,8 @@ import org.junit.runners.Suite;
ServiceDeploymentProcessIdSelfTest.class,
ServiceHotRedeploymentViaDeploymentSpiTest.class,
GridServiceProxyTopologyInitializationTest.class,
+ GridServiceDeployClusterReadOnlyModeTest.class,
+ GridServiceClusterReadOnlyModeTest.class,
})
public class IgniteServiceGridTestSuite {
}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSqlDdlClusterReadOnlyModeTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSqlDdlClusterReadOnlyModeTest.java
new file mode 100644
index 0000000..c50e36c
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheSqlDdlClusterReadOnlyModeTest.java
@@ -0,0 +1,172 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.processors.cache;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cluster.ClusterState;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.processors.query.IgniteSQLException;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.junit.Test;
+
+import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheConfigurations;
+import static org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeTestUtils.cacheNames;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrows;
+
+/**
+ * Tests that DDL requests works fine, if cluster in a {@link ClusterState#ACTIVE_READ_ONLY} state.
+ */
+public class GridCacheSqlDdlClusterReadOnlyModeTest extends CacheCreateDestroyClusterReadOnlyModeAbstractTest {
+ /** Sql select query error message. */
+ private static final String SQL_SELECT_ERROR_MSG = "Failed to parse query. Column \"CITY\" not found";
+
+ /** {@inheritDoc} */
+ @Override protected void beforeTest() throws Exception {
+ super.beforeTest();
+
+ grid(0).getOrCreateCache(DEFAULT_CACHE_NAME);
+ }
+
+ /** */
+ @Test
+ public void testCreateTableDenied() {
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ for (String ddl : generateCreateTableDDL()) {
+ for (Ignite node : G.allGrids()) {
+ Throwable t = assertThrows(log, () -> execute(node, ddl), Exception.class, null);
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(t, node.name() + " sql: " + ddl);
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testDropTableDenied() {
+ createTables();
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ for (String cacheName : cacheNames()) {
+ String sql = "drop table " + tableName(cacheName);
+
+ for (Ignite node : G.allGrids()) {
+ Throwable t = assertThrows(log, () -> execute(node, sql), Exception.class, null);
+
+ ClusterReadOnlyModeTestUtils.checkRootCause(t, node.name() + " sql: " + sql);
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testCreateDropIndexAllowed() {
+ createTables();
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ for (String cacheName : cacheNames()) {
+ for (Ignite node : G.allGrids()) {
+ String indexName = "age_idx_" + tableName(cacheName);
+ assertNotNull(execute(node, "create index " + indexName + " on " + tableName(cacheName) + " (age)"));
+
+ assertNotNull(execute(node, "drop index " + indexName));
+ }
+ }
+ }
+
+ /** */
+ @Test
+ public void testAlterTableAllowed() {
+ createTables();
+
+ grid(0).cluster().state(ClusterState.ACTIVE_READ_ONLY);
+
+ for (CacheConfiguration cfg : cacheConfigurations()) {
+ String cacheName = cfg.getName();
+
+ if (cfg.getAtomicityMode() == CacheAtomicityMode.TRANSACTIONAL_SNAPSHOT) {
+ // Drop column doesn't support in MVCC mode.
+ continue;
+ }
+
+ for (Ignite node : G.allGrids()) {
+ String selectSql = "select city from " + tableName(cacheName);
+
+ assertThrows(log, () -> execute(node, selectSql), IgniteSQLException.class, SQL_SELECT_ERROR_MSG);
+
+ execute(node, "alter table " + tableName(cacheName) + " add column city varchar");
+
+ assertNotNull(execute(node, selectSql));
+
+ execute(node, "alter table " + tableName(cacheName) + " drop column city");
+
+ assertThrows(log, () -> execute(node, selectSql), IgniteSQLException.class, SQL_SELECT_ERROR_MSG);
+ }
+ }
+ }
+
+ /** */
+ private static List<String> generateCreateTableDDL() {
+ List<String> ddls = new ArrayList<>();
+
+ for (CacheConfiguration cfg : cacheConfigurations()) {
+ SB sb = new SB("CREATE TABLE ");
+
+ sb.a(tableName(cfg.getName()));
+ sb.a(" (id int, city_id int, age int, PRIMARY KEY (id)) WITH \"");
+ sb.a("backups=").a(cfg.getBackups()).a(",");
+ sb.a("CACHE_NAME=").a(cfg.getName()).a(",");
+
+ if (cfg.getGroupName() != null)
+ sb.a("CACHE_GROUP=").a(cfg.getGroupName()).a(",");
+
+ sb.a("ATOMICITY=").a(cfg.getAtomicityMode()).a(",");
+ sb.a("TEMPLATE=").a(cfg.getCacheMode());
+ sb.a("\"");
+
+ ddls.add(sb.toString());
+ }
+ return ddls;
+ }
+
+ /** */
+ private void createTables() {
+ for (String ddl : generateCreateTableDDL())
+ execute(grid(0), ddl);
+
+ for (String cacheName : cacheNames())
+ execute(grid(0), "INSERT INTO " + tableName(cacheName) + " (id, city_id, age) VALUES (1, 1, 1)");
+ }
+
+ /** */
+ private static Object execute(Ignite node, String sql, Object... args) {
+ return node.cache(DEFAULT_CACHE_NAME).query(new SqlFieldsQuery(sql).setArgs(args)).getAll();
+ }
+
+ /** */
+ private static String tableName(String cacheName) {
+ return "tbl_" + cacheName;
+ }
+}
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
index 75f3ba1..b016375 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteCacheWithIndexingTestSuite.java
@@ -35,6 +35,7 @@ import org.apache.ignite.internal.processors.cache.ClusterReadOnlyModeSqlTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffHeapSelfTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffheapIndexEntryEvictTest;
import org.apache.ignite.internal.processors.cache.GridCacheOffheapIndexGetSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheSqlDdlClusterReadOnlyModeTest;
import org.apache.ignite.internal.processors.cache.GridIndexingWithNoopSwapSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheConfigurationPrimitiveTypesSelfTest;
import org.apache.ignite.internal.processors.cache.IgniteCacheGroupsSqlTest;
@@ -98,6 +99,7 @@ import org.junit.runners.Suite;
BinaryTypeRegistrationTest.class,
ClusterReadOnlyModeSqlTest.class,
+ GridCacheSqlDdlClusterReadOnlyModeTest.class,
ClusterReadOnlyModeDoesNotBreakSqlSelectTest.class,