You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by mm...@apache.org on 2021/08/25 00:52:27 UTC

[ignite] branch master updated: IGNITE-15355 Fix method corruptDataEntry used for tests (#9347)

This is an automated email from the ASF dual-hosted git repository.

mmuzaf 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 825d19a  IGNITE-15355 Fix method corruptDataEntry used for tests (#9347)
825d19a is described below

commit 825d19a718de44b0242f5661cb1697fd76dea731
Author: Maxim Muzafarov <mm...@apache.org>
AuthorDate: Wed Aug 25 03:52:00 2021 +0300

    IGNITE-15355 Fix method corruptDataEntry used for tests (#9347)
---
 .../util/GridCommandHandlerClusterByClassTest.java | 72 ++--------------
 .../apache/ignite/util/GridCommandHandlerTest.java | 63 +-------------
 .../GridCacheDatabaseSharedManager.java            |  4 +-
 .../persistence/NoUnnecessaryRebalanceTest.java}   | 96 ++++++++--------------
 .../ignite/testsuites/IgnitePdsTestSuite4.java     |  4 +-
 .../apache/ignite/{ => util}/TestStorageUtils.java | 83 ++++++++-----------
 6 files changed, 81 insertions(+), 241 deletions(-)

diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
index 762ac0c..f39baf5 100644
--- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
+++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerClusterByClassTest.java
@@ -61,13 +61,8 @@ import org.apache.ignite.internal.commandline.CommandList;
 import org.apache.ignite.internal.commandline.CommonArgParser;
 import org.apache.ignite.internal.commandline.argument.CommandArg;
 import org.apache.ignite.internal.commandline.cache.CacheSubcommands;
-import org.apache.ignite.internal.pagemem.wal.record.DataEntry;
 import org.apache.ignite.internal.processors.cache.CacheGroupContext;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheOperation;
-import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
@@ -112,6 +107,7 @@ import static org.apache.ignite.testframework.GridTestUtils.readResource;
 import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.util.TestStorageUtils.corruptDataEntry;
 
 /**
  * Command line handler test.
@@ -483,7 +479,7 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
      * Tests that both update counter and hash conflicts are detected.
      */
     @Test
-    public void testCacheIdleVerifyTwoConflictTypes() {
+    public void testCacheIdleVerifyTwoConflictTypes() throws Exception {
         IgniteEx ignite = crd;
 
         createCacheAndPreload(ignite, 100);
@@ -823,7 +819,11 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
      * @param cacheFilter cacheFilter.
      * @param dump Whether idle_verify should be launched with dump option or not.
      */
-    private void corruptingAndCheckDefaultCache(IgniteEx ignite, String cacheFilter, boolean dump) throws IOException {
+    private void corruptingAndCheckDefaultCache(
+        IgniteEx ignite,
+        String cacheFilter,
+        boolean dump
+    ) throws IOException, IgniteCheckedException {
         injectTestSystemOut();
 
         GridCacheContext<Object, Object> cacheCtx = ignite.cachex(DEFAULT_CACHE_NAME).context();
@@ -913,7 +913,6 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
 
             U.log(log, dumpWithConflicts);
 
-            // Non-persistent caches do not have counter conflicts
             assertContains(log, dumpWithConflicts, "found 4 conflict partitions: [counterConflicts=2, " +
                 "hashConflicts=2]");
         }
@@ -1488,63 +1487,6 @@ public class GridCommandHandlerClusterByClassTest extends GridCommandHandlerClus
     }
 
     /**
-     * Corrupts data entry.
-     *
-     * @param ctx Context.
-     * @param key Key.
-     * @param breakCntr Break counter.
-     * @param breakData Break data.
-     */
-    private void corruptDataEntry(
-        GridCacheContext<Object, Object> ctx,
-        Object key,
-        boolean breakCntr,
-        boolean breakData
-    ) {
-        int partId = ctx.affinity().partition(key);
-
-        try {
-            long updateCntr = ctx.topology().localPartition(partId).updateCounter();
-
-            Object valToPut = ctx.cache().keepBinary().get(key);
-
-            if (breakCntr)
-                updateCntr++;
-
-            if (breakData)
-                valToPut = valToPut.toString() + " broken";
-
-            // Create data entry
-            DataEntry dataEntry = new DataEntry(
-                ctx.cacheId(),
-                new KeyCacheObjectImpl(key, null, partId),
-                new CacheObjectImpl(valToPut, null),
-                GridCacheOperation.UPDATE,
-                new GridCacheVersion(),
-                new GridCacheVersion(),
-                0L,
-                partId,
-                updateCntr,
-                DataEntry.EMPTY_FLAGS
-            );
-
-            GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ctx.shared().database();
-
-            db.checkpointReadLock();
-
-            try {
-                U.invoke(GridCacheDatabaseSharedManager.class, db, "applyUpdate", ctx, dataEntry);
-            }
-            finally {
-                db.checkpointReadUnlock();
-            }
-        }
-        catch (IgniteCheckedException e) {
-            e.printStackTrace();
-        }
-    }
-
-    /**
      * Test is that when the --help control.sh command is executed, output
      * will contain non-experimental commands. In case system property
      * {@link IgniteSystemProperties#IGNITE_ENABLE_EXPERIMENTAL_COMMAND} =
diff --git a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
index 22c5fcd..eb4e4ba 100644
--- a/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
+++ b/modules/control-utility/src/test/java/org/apache/ignite/util/GridCommandHandlerTest.java
@@ -79,14 +79,10 @@ import org.apache.ignite.internal.client.util.GridConcurrentHashSet;
 import org.apache.ignite.internal.commandline.CommandHandler;
 import org.apache.ignite.internal.commandline.cache.argument.FindAndDeleteGarbageArg;
 import org.apache.ignite.internal.managers.communication.GridIoMessage;
-import org.apache.ignite.internal.pagemem.wal.record.DataEntry;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.ClusterStateTestUtils;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccCandidate;
-import org.apache.ignite.internal.processors.cache.GridCacheOperation;
-import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtTxFinishRequest;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearLockResponse;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxFinishRequest;
@@ -99,7 +95,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx
 import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
 import org.apache.ignite.internal.processors.cache.transactions.TransactionProxyImpl;
 import org.apache.ignite.internal.processors.cache.verify.IdleVerifyResultV2;
-import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
 import org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpConfiguration;
 import org.apache.ignite.internal.processors.cache.warmup.BlockedWarmUpStrategy;
 import org.apache.ignite.internal.processors.cache.warmup.WarmUpTestPluginProvider;
@@ -172,6 +167,7 @@ import static org.apache.ignite.testframework.GridTestUtils.waitForCondition;
 import static org.apache.ignite.transactions.TransactionConcurrency.OPTIMISTIC;
 import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
 import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.util.TestStorageUtils.corruptDataEntry;
 
 /**
  * Command line handler test.
@@ -2622,63 +2618,6 @@ public class GridCommandHandlerTest extends GridCommandHandlerClusterPerMethodAb
         }
     }
 
-    /**
-     * Corrupts data entry.
-     *
-     * @param ctx Context.
-     * @param key Key.
-     * @param breakCntr Break counter.
-     * @param breakData Break data.
-     */
-    private void corruptDataEntry(
-        GridCacheContext<Object, Object> ctx,
-        Object key,
-        boolean breakCntr,
-        boolean breakData
-    ) {
-        int partId = ctx.affinity().partition(key);
-
-        try {
-            long updateCntr = ctx.topology().localPartition(partId).updateCounter();
-
-            Object valToPut = ctx.cache().keepBinary().get(key);
-
-            if (breakCntr)
-                updateCntr++;
-
-            if (breakData)
-                valToPut = valToPut.toString() + " broken";
-
-            // Create data entry
-            DataEntry dataEntry = new DataEntry(
-                ctx.cacheId(),
-                new KeyCacheObjectImpl(key, null, partId),
-                new CacheObjectImpl(valToPut, null),
-                GridCacheOperation.UPDATE,
-                new GridCacheVersion(),
-                new GridCacheVersion(),
-                0L,
-                partId,
-                updateCntr,
-                DataEntry.EMPTY_FLAGS
-            );
-
-            GridCacheDatabaseSharedManager db = (GridCacheDatabaseSharedManager)ctx.shared().database();
-
-            db.checkpointReadLock();
-
-            try {
-                U.invoke(GridCacheDatabaseSharedManager.class, db, "applyUpdate", ctx, dataEntry);
-            }
-            finally {
-                db.checkpointReadUnlock();
-            }
-        }
-        catch (IgniteCheckedException e) {
-            e.printStackTrace();
-        }
-    }
-
     /** */
     @Test
     public void testKillHangingLocalTransactions() throws Exception {
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
index 36a077e..a9ab274 100755
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/persistence/GridCacheDatabaseSharedManager.java
@@ -2881,7 +2881,9 @@ public class GridCacheDatabaseSharedManager extends IgniteCacheDatabaseSharedMan
      * @param dataEntry Data entry to apply.
      * @throws IgniteCheckedException If failed to restore.
      */
-    private void applyUpdate(GridCacheContext cacheCtx, DataEntry dataEntry) throws IgniteCheckedException {
+    private void applyUpdate(GridCacheContext<?, ?> cacheCtx, DataEntry dataEntry) throws IgniteCheckedException {
+        assert cacheCtx.offheap() instanceof GridCacheOffheapManager;
+
         int partId = dataEntry.partitionId();
 
         if (partId == -1)
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/NoUnnecessaryRebalancesTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/NoUnnecessaryRebalanceTest.java
similarity index 53%
rename from modules/core/src/test/java/org/apache/ignite/cache/NoUnnecessaryRebalancesTest.java
rename to modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/NoUnnecessaryRebalanceTest.java
index a972c6d..3096490 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/NoUnnecessaryRebalancesTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/persistence/NoUnnecessaryRebalanceTest.java
@@ -15,45 +15,38 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.cache;
+package org.apache.ignite.internal.processors.cache.persistence;
 
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction;
-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;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.TestRecordingCommunicationSpi;
-import org.apache.ignite.internal.managers.communication.GridIoMessage;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheGroupIdMessage;
 import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionSupplyMessage;
-import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
+import org.apache.ignite.internal.util.typedef.G;
 import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.lang.IgniteInClosure;
-import org.apache.ignite.plugin.extensions.communication.Message;
-import org.apache.ignite.spi.IgniteSpiException;
 import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.junit.Assert;
 import org.junit.Test;
 
-import static org.apache.ignite.TestStorageUtils.corruptDataEntry;
+import static org.apache.ignite.util.TestStorageUtils.corruptDataEntry;
 
 /**
- * Tests check that unnecessary rebalances doesn't happen
+ * Tests check that unnecessary rebalance doesn't happen.
  */
-public class NoUnnecessaryRebalancesTest extends GridCommonAbstractTest {
-    /** */
+public class NoUnnecessaryRebalanceTest extends GridCommonAbstractTest {
+    /** Cache configuration name prefix. */
     private static final String CACHE_NAME = "testCache";
 
-    /** */
-    private static final int nodeCount = 3;
+    /** Number of cluster nodes. */
+    private static final int NODE_COUNT = 3;
 
     /**
      * @return Grid test configuration.
@@ -62,27 +55,24 @@ public class NoUnnecessaryRebalancesTest extends GridCommonAbstractTest {
     @Override protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
         IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
 
-        cfg.setCommunicationSpi(new SpecialSpi());
+        cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
 
-        cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(
-            new DataRegionConfiguration().setPersistenceEnabled(true).setMaxSize(200 * 1024 * 1024)
-        ));
+        cfg.setDataStorageConfiguration(new DataStorageConfiguration()
+            .setDefaultDataRegionConfiguration(new DataRegionConfiguration()
+                .setPersistenceEnabled(true)));
 
         return cfg;
     }
 
     /**
-     * Test check that cache creation doesn't invoke rebalance on cache in other cache group
+     * Test check that cache creation doesn't invoke rebalance on cache in other cache group.
      * @throws Exception If failed.
      */
     @Test
-    public void testNoRebalancesOnCacheCreation() throws Exception {
-        startGrids(nodeCount);
-
-        Ignite g0 = grid(0);
+    public void testNoRebalanceOnCacheCreation() throws Exception {
+        Ignite g0 = startGrids(NODE_COUNT);
 
         g0.cluster().state(ClusterState.ACTIVE);
-
         g0.createCache(getCacheConfiguration(0));
 
         awaitPartitionMapExchange();
@@ -96,51 +86,29 @@ public class NoUnnecessaryRebalancesTest extends GridCommonAbstractTest {
 
         GridCacheContext<Object, Object> cacheCtx0 = grid(0).cachex(CACHE_NAME + 0).context();
 
-        corruptDataEntry(cacheCtx0, 1, true, false, new GridCacheVersion(0, 0, 0), "broken");
+        corruptDataEntry(cacheCtx0, 1, true, false);
+
+        G.allGrids().forEach(n -> TestRecordingCommunicationSpi.spi(n)
+            .record((node, msg) -> msg instanceof GridDhtPartitionSupplyMessage));
 
         g0.createCache(getCacheConfiguration(1));
 
         awaitPartitionMapExchange(true, true, null);
 
-        Assert.assertFalse(SpecialSpi.rebGrpIds.contains(CU.cacheId(CACHE_NAME + 0)));
-    }
+        List<Object> msgs = new ArrayList<>();
+
+        G.allGrids().forEach(n -> msgs.addAll(TestRecordingCommunicationSpi.spi(n).recordedMessages(true)));
 
-    /** */
-    private CacheConfiguration<Object, Object> getCacheConfiguration(int idx) {
-        return new CacheConfiguration<>(CACHE_NAME + idx)
-            .setBackups(2)
-            .setAffinity(new RendezvousAffinityFunction().setPartitions(8));
+        assertFalse(msgs.stream().map(o -> ((GridCacheGroupIdMessage)o).groupId()).collect(Collectors.toSet())
+            .contains(CU.cacheId(CACHE_NAME + 0)));
     }
 
     /**
-     * Wrapper of communication spi to detect on which cache groups rebalances were happened.
+     * @param postFix Cache name postfix.
+     * @return Cache configuration.
      */
-    public static class SpecialSpi extends TestRecordingCommunicationSpi {
-        /** Cache groups on which rebalances were happened */
-        public static final Set<Integer> rebGrpIds = new HashSet<>();
-
-        /** Lock object. */
-        private static final Object mux = new Object();
-
-        /** */
-        public static Set<Integer> allRebalances() {
-            synchronized (mux) {
-                return Collections.unmodifiableSet(rebGrpIds);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
-            if (((GridIoMessage)msg).message() instanceof GridDhtPartitionSupplyMessage) {
-                GridDhtPartitionSupplyMessage supplyMsg = (GridDhtPartitionSupplyMessage) ((GridIoMessage)msg).message();
-
-                synchronized (mux) {
-                    rebGrpIds.add(supplyMsg.groupId());
-                }
-            }
-
-            super.sendMessage(node, msg, ackC);
-        }
+    private CacheConfiguration<Object, Object> getCacheConfiguration(int postFix) {
+        return new CacheConfiguration<>(CACHE_NAME + postFix).setBackups(2);
     }
 
     /** {@inheritDoc} */
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java
index c0972b6..1a70180 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePdsTestSuite4.java
@@ -23,7 +23,6 @@ import java.util.List;
 import org.apache.ignite.cache.AutoReleaseSegmentSelfTest;
 import org.apache.ignite.cache.BreakRebalanceChainTest;
 import org.apache.ignite.cache.CircledRebalanceTest;
-import org.apache.ignite.cache.NoUnnecessaryRebalancesTest;
 import org.apache.ignite.cache.NotOptimizedRebalanceTest;
 import org.apache.ignite.cache.RebalanceAfterResettingLostPartitionTest;
 import org.apache.ignite.cache.RebalanceCancellationTest;
@@ -47,6 +46,7 @@ import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsRemoveDu
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsRestartAfterFailedToWriteMetaPageTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsSpuriousRebalancingOnNodeJoinTest;
 import org.apache.ignite.internal.processors.cache.persistence.IgnitePdsTaskCancelingTest;
+import org.apache.ignite.internal.processors.cache.persistence.NoUnnecessaryRebalanceTest;
 import org.apache.ignite.internal.processors.cache.persistence.PendingTreeCorruptionTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsCacheWalDisabledOnRebalancingTest;
 import org.apache.ignite.internal.processors.cache.persistence.db.IgnitePdsPageReplacementDuringPartitionClearTest;
@@ -124,7 +124,7 @@ public class IgnitePdsTestSuite4 {
         GridTestUtils.addTestIfNeeded(suite, OffHeapLockStackTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, HistoricalReservationTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, CircledRebalanceTest.class, ignoredTests);
-        GridTestUtils.addTestIfNeeded(suite, NoUnnecessaryRebalancesTest.class, ignoredTests);
+        GridTestUtils.addTestIfNeeded(suite, NoUnnecessaryRebalanceTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, ToStringDumpHelperTest.class, ignoredTests);
         GridTestUtils.addTestIfNeeded(suite, PageLockTrackerResourcesTest.class, ignoredTests);
 
diff --git a/modules/core/src/test/java/org/apache/ignite/TestStorageUtils.java b/modules/core/src/test/java/org/apache/ignite/util/TestStorageUtils.java
similarity index 51%
rename from modules/core/src/test/java/org/apache/ignite/TestStorageUtils.java
rename to modules/core/src/test/java/org/apache/ignite/util/TestStorageUtils.java
index c9282b4..535b1cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/TestStorageUtils.java
+++ b/modules/core/src/test/java/org/apache/ignite/util/TestStorageUtils.java
@@ -15,8 +15,9 @@
  * limitations under the License.
  */
 
-package org.apache.ignite;
+package org.apache.ignite.util;
 
+import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.cache.CacheEntry;
 import org.apache.ignite.internal.pagemem.wal.record.DataEntry;
@@ -25,10 +26,9 @@ import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheOperation;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 import org.apache.ignite.internal.processors.cache.KeyCacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.persistence.GridCacheDatabaseSharedManager;
+import org.apache.ignite.internal.processors.cache.distributed.dht.topology.GridDhtLocalPartition;
 import org.apache.ignite.internal.processors.cache.persistence.IgniteCacheDatabaseSharedManager;
 import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
-import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
  * Test methods for storage manipulation.
@@ -41,65 +41,54 @@ public class TestStorageUtils {
      * @param key Key.
      * @param breakCntr Break counter.
      * @param breakData Break data.
-     * @param ver GridCacheVersion to use.
-     * @param brokenValPostfix Postfix to add to value if breakData flag is set to true.
      */
     public static void corruptDataEntry(
         GridCacheContext<?, ?> ctx,
         Object key,
         boolean breakCntr,
-        boolean breakData,
-        GridCacheVersion ver,
-        String brokenValPostfix
-    ) {
-        int partId = ctx.affinity().partition(key);
-
-        try {
-            long updateCntr = ctx.topology().localPartition(partId).updateCounter();
+        boolean breakData
+    ) throws IgniteCheckedException {
+        assert !ctx.isLocal();
 
-            CacheEntry<Object, Object> e = ctx.cache().keepBinary().getEntry(key);
-
-            Object valToPut = e.getValue();
+        int partId = ctx.affinity().partition(key);
+        GridDhtLocalPartition locPart = ctx.topology().localPartition(partId);
 
-            KeyCacheObject keyCacheObj = e.getKey() instanceof BinaryObject ?
-                (KeyCacheObject)e.getKey() :
-                new KeyCacheObjectImpl(e.getKey(), null, partId);
+        CacheEntry<Object, Object> e = ctx.cache().keepBinary().getEntry(key);
 
-            if (breakCntr)
-                updateCntr++;
+        KeyCacheObject keyCacheObj = e.getKey() instanceof BinaryObject ?
+            (KeyCacheObject)e.getKey() :
+            new KeyCacheObjectImpl(e.getKey(), null, partId);
 
-            if (breakData)
-                valToPut = e.getValue().toString() + brokenValPostfix;
+        DataEntry dataEntry = new DataEntry(ctx.cacheId(),
+            keyCacheObj,
+            new CacheObjectImpl(breakData ? e.getValue().toString() + "brokenValPostfix" : e.getValue(), null),
+            GridCacheOperation.UPDATE,
+            new GridCacheVersion(),
+            new GridCacheVersion(),
+            0L,
+            partId,
+            breakCntr ? locPart.updateCounter() + 1 : locPart.updateCounter(),
+            DataEntry.EMPTY_FLAGS);
 
-            // Create data entry
+        IgniteCacheDatabaseSharedManager db = ctx.shared().database();
 
-            DataEntry dataEntry = new DataEntry(
-                ctx.cacheId(),
-                keyCacheObj,
-                new CacheObjectImpl(valToPut, null),
-                GridCacheOperation.UPDATE,
-                new GridCacheVersion(),
-                ver,
-                0L,
-                partId,
-                updateCntr,
-                DataEntry.EMPTY_FLAGS
-            );
+        db.checkpointReadLock();
 
-            IgniteCacheDatabaseSharedManager db = ctx.shared().database();
+        try {
+            assert dataEntry.op() == GridCacheOperation.UPDATE;
 
-            db.checkpointReadLock();
+            ctx.offheap().update(ctx,
+                dataEntry.key(),
+                dataEntry.value(),
+                dataEntry.writeVersion(),
+                dataEntry.expireTime(),
+                locPart,
+                null);
 
-            try {
-                U.invoke(GridCacheDatabaseSharedManager.class, db, "applyUpdate", ctx, dataEntry,
-                    false);
-            }
-            finally {
-                db.checkpointReadUnlock();
-            }
+            ctx.offheap().dataStore(locPart).updateInitialCounter(dataEntry.partitionCounter() - 1, 1);
         }
-        catch (IgniteCheckedException e) {
-            e.printStackTrace();
+        finally {
+            db.checkpointReadUnlock();
         }
     }
 }