You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ib...@apache.org on 2024/04/09 14:53:50 UTC

(ignite-3) branch main updated: IGNITE-21995 Do not disable thread assertions in tests (#3565)

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

ibessonov pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 77bbc39bff IGNITE-21995 Do not disable thread assertions in tests (#3565)
77bbc39bff is described below

commit 77bbc39bff10605e7a3c36359fe88d9c39ffe7a5
Author: Roman Puchkovskiy <ro...@gmail.com>
AuthorDate: Tue Apr 9 18:53:44 2024 +0400

    IGNITE-21995 Do not disable thread assertions in tests (#3565)
---
 .../apache/ignite/internal/wrapper/Wrappers.java   |  22 ++++-
 ...IndexNodeFinishedRwTransactionsCheckerTest.java |  10 +-
 .../ItPrimaryReplicaChoiceTest.java                | 110 +++++++++++++--------
 .../ignite/internal/table/ItTableScanTest.java     |  17 ++--
 .../storage/ThreadAssertingMvPartitionStorage.java |   8 +-
 .../storage/index/ThreadAssertingIndexStorage.java |   8 +-
 6 files changed, 120 insertions(+), 55 deletions(-)

diff --git a/modules/core/src/main/java/org/apache/ignite/internal/wrapper/Wrappers.java b/modules/core/src/main/java/org/apache/ignite/internal/wrapper/Wrappers.java
index d67e8d6322..3120229e91 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/wrapper/Wrappers.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/wrapper/Wrappers.java
@@ -17,21 +17,41 @@
 
 package org.apache.ignite.internal.wrapper;
 
+import org.jetbrains.annotations.Nullable;
+
 /**
  * Utils for unwrapping {@link Wrapper} instances.
  */
 public class Wrappers {
     /**
-     * Unwraps an object. Either invokes {@link Wrapper#unwrap(Class)} if it's a Wrapper, or tries to cast directly otherwise.
+     * Unwraps an object (that is not {@code null}). Either invokes {@link Wrapper#unwrap(Class)} if it's a Wrapper, or tries to cast
+     * directly otherwise.
      *
      * @param object Object to unwrap.
      * @param classToUnwrap Class which is to be unwrapped.
      */
     public static <T> T unwrap(Object object, Class<T> classToUnwrap) {
+        assert object != null : "Object to unwrap is null";
+
         if (object instanceof Wrapper) {
             return ((Wrapper) object).unwrap(classToUnwrap);
         }
 
         return classToUnwrap.cast(object);
     }
+
+    /**
+     * Unwraps an object or returns {@code null} if it's {@code null}.
+     *
+     * @param object Object to unwrap.
+     * @param classToUnwrap Class which is to be unwrapped.
+     * @see #unwrap(Object, Class)
+     */
+    public static @Nullable <T> T unwrapNullable(@Nullable Object object, Class<T> classToUnwrap) {
+        if (object == null) {
+            return null;
+        }
+
+        return unwrap(object, classToUnwrap);
+    }
 }
diff --git a/modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItIndexNodeFinishedRwTransactionsCheckerTest.java b/modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItIndexNodeFinishedRwTransactionsCheckerTest.java
index d6c9a40d68..8120d9b4a3 100644
--- a/modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItIndexNodeFinishedRwTransactionsCheckerTest.java
+++ b/modules/index/src/integrationTest/java/org/apache/ignite/internal/index/ItIndexNodeFinishedRwTransactionsCheckerTest.java
@@ -36,15 +36,15 @@ import org.apache.ignite.internal.ClusterPerClassIntegrationTest;
 import org.apache.ignite.internal.app.IgniteImpl;
 import org.apache.ignite.internal.index.message.IndexMessagesFactory;
 import org.apache.ignite.internal.index.message.IsNodeFinishedRwTransactionsStartedBeforeResponse;
-import org.apache.ignite.internal.lang.IgniteSystemProperties;
 import org.apache.ignite.internal.network.NetworkMessage;
 import org.apache.ignite.internal.storage.MvPartitionStorage;
 import org.apache.ignite.internal.storage.engine.MvTableStorage;
+import org.apache.ignite.internal.storage.impl.TestMvPartitionStorage;
 import org.apache.ignite.internal.storage.impl.schema.TestProfileConfigurationSchema;
 import org.apache.ignite.internal.table.InternalTable;
 import org.apache.ignite.internal.table.TableImpl;
 import org.apache.ignite.internal.testframework.IgniteTestUtils;
-import org.apache.ignite.internal.testframework.WithSystemProperty;
+import org.apache.ignite.internal.wrapper.Wrappers;
 import org.apache.ignite.table.Table;
 import org.apache.ignite.table.Tuple;
 import org.apache.ignite.tx.Transaction;
@@ -56,7 +56,6 @@ import org.junit.jupiter.params.ParameterizedTest;
 import org.junit.jupiter.params.provider.ValueSource;
 
 /** For testing {@link IndexNodeFinishedRwTransactionsChecker}. */
-@WithSystemProperty(key = IgniteSystemProperties.THREAD_ASSERTIONS_ENABLED, value = "false")
 public class ItIndexNodeFinishedRwTransactionsCheckerTest extends ClusterPerClassIntegrationTest {
     private static final IndexMessagesFactory FACTORY = new IndexMessagesFactory();
 
@@ -282,7 +281,10 @@ public class ItIndexNodeFinishedRwTransactionsCheckerTest extends ClusterPerClas
         var awaitStartUpdateAnyMvPartitionStorageFuture = new CompletableFuture<Void>();
 
         for (int partitionId = 0; partitionId < mvTableStorage.getTableDescriptor().getPartitions(); partitionId++) {
-            MvPartitionStorage mvPartitionStorage = mvTableStorage.getMvPartition(partitionId);
+            MvPartitionStorage mvPartitionStorage = Wrappers.unwrapNullable(
+                    mvTableStorage.getMvPartition(partitionId),
+                    TestMvPartitionStorage.class
+            );
 
             doAnswer(invocation -> {
                 awaitStartUpdateAnyMvPartitionStorageFuture.complete(null);
diff --git a/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ItPrimaryReplicaChoiceTest.java b/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ItPrimaryReplicaChoiceTest.java
index ed549094c7..ce15a3b875 100644
--- a/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ItPrimaryReplicaChoiceTest.java
+++ b/modules/placement-driver/src/integrationTest/java/org/apache/ignite/internal/placementdriver/ItPrimaryReplicaChoiceTest.java
@@ -22,9 +22,11 @@ import static java.util.stream.Collectors.toSet;
 import static org.apache.ignite.internal.SessionUtils.executeUpdate;
 import static org.apache.ignite.internal.TestWrappers.unwrapTableImpl;
 import static org.apache.ignite.internal.TestWrappers.unwrapTableViewInternal;
+import static org.apache.ignite.internal.testframework.IgniteTestUtils.bypassingThreadAssertions;
 import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
 import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
 import static org.apache.ignite.internal.util.CompletableFutures.falseCompletedFuture;
+import static org.apache.ignite.internal.wrapper.Wrappers.unwrapNullable;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -43,7 +45,6 @@ import org.apache.ignite.internal.binarytuple.BinaryTupleBuilder;
 import org.apache.ignite.internal.catalog.CatalogManager;
 import org.apache.ignite.internal.catalog.descriptors.CatalogObjectDescriptor;
 import org.apache.ignite.internal.lang.IgniteStringFormatter;
-import org.apache.ignite.internal.lang.IgniteSystemProperties;
 import org.apache.ignite.internal.placementdriver.event.PrimaryReplicaEvent;
 import org.apache.ignite.internal.raft.Peer;
 import org.apache.ignite.internal.raft.service.RaftGroupService;
@@ -54,16 +55,17 @@ import org.apache.ignite.internal.storage.impl.TestMvPartitionStorage;
 import org.apache.ignite.internal.storage.impl.schema.TestProfileConfigurationSchema;
 import org.apache.ignite.internal.storage.index.impl.TestHashIndexStorage;
 import org.apache.ignite.internal.storage.index.impl.TestSortedIndexStorage;
+import org.apache.ignite.internal.table.InternalTable;
 import org.apache.ignite.internal.table.NodeUtils;
 import org.apache.ignite.internal.table.TableViewInternal;
 import org.apache.ignite.internal.testframework.IgniteTestUtils;
-import org.apache.ignite.internal.testframework.WithSystemProperty;
 import org.apache.ignite.internal.testframework.flow.TestFlowUtils;
 import org.apache.ignite.internal.tx.InternalTransaction;
 import org.apache.ignite.internal.tx.impl.ReadWriteTransactionImpl;
 import org.apache.ignite.internal.utils.PrimaryReplica;
 import org.apache.ignite.internal.wrapper.Wrappers;
 import org.apache.ignite.network.ClusterNode;
+import org.apache.ignite.table.Table;
 import org.apache.ignite.table.Tuple;
 import org.apache.ignite.tx.TransactionOptions;
 import org.jetbrains.annotations.Nullable;
@@ -75,18 +77,19 @@ import org.junit.jupiter.api.TestInfo;
  * TODO: IGNITE-20485 Configure the lease interval as less as possible to decrease the duration of tests.
  * The test class checks invariant of a primary replica choice.
  */
+@SuppressWarnings("resource")
 public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
     private static final int AWAIT_PRIMARY_REPLICA_TIMEOUT = 10;
 
-    public static final int PART_ID = 0;
+    private static final int PART_ID = 0;
 
     private static final String ZONE_NAME = "ZONE_TABLE";
 
     private static final String TABLE_NAME = "TEST_TABLE";
 
-    public static final String HASH_IDX = "HASH_IDX";
+    private static final String HASH_IDX = "HASH_IDX";
 
-    public static final String SORTED_IDX = "SORTED_IDX";
+    private static final String SORTED_IDX = "SORTED_IDX";
 
     @BeforeEach
     @Override
@@ -199,15 +202,15 @@ public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
      * @throws Exception If failed.
      */
     @Test
-    @WithSystemProperty(key = IgniteSystemProperties.THREAD_ASSERTIONS_ENABLED, value = "false")
     public void testClearingTransactionResourcesWhenPrimaryChange() throws Exception {
-        TableViewInternal tbl = unwrapTableViewInternal(node(0).tables().table(TABLE_NAME));
+        Table publicTableOnNode0 = node(0).tables().table(TABLE_NAME);
+        TableViewInternal unwrappedTableOnNode0 = unwrapTableViewInternal(publicTableOnNode0);
 
         for (int i = 0; i < 10; i++) {
-            assertTrue(tbl.recordView().insert(null, Tuple.create().set("key", i).set("val", "preload val")));
+            assertTrue(publicTableOnNode0.recordView().insert(null, Tuple.create().set("key", i).set("val", "preload val")));
         }
 
-        var tblReplicationGrp = new TablePartitionId(tbl.tableId(), PART_ID);
+        var tblReplicationGrp = new TablePartitionId(unwrappedTableOnNode0.tableId(), PART_ID);
 
         CompletableFuture<ReplicaMeta> primaryReplicaFut = node(0).placementDriver().awaitPrimaryReplica(
                 tblReplicationGrp,
@@ -220,7 +223,7 @@ public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
 
         String primary = primaryReplicaFut.get().getLeaseholder();
 
-        IgniteImpl ignite = node(primary);
+        IgniteImpl primaryIgnite = node(primary);
 
         int hashIdxId = getIndexId(HASH_IDX);
         int sortedIdxId = getIndexId(SORTED_IDX);
@@ -228,60 +231,85 @@ public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
         InternalTransaction rwTx = (InternalTransaction) node(0).transactions().begin();
         InternalTransaction roTx = (InternalTransaction) node(0).transactions().begin(new TransactionOptions().readOnly(true));
 
-        assertTrue(tbl.recordView().insert(rwTx, Tuple.create().set("key", 42).set("val", "val 42")));
+        assertTrue(publicTableOnNode0.recordView().insert(rwTx, Tuple.create().set("key", 42).set("val", "val 42")));
 
         BinaryTuple idxKey = new BinaryTuple(1, new BinaryTupleBuilder(1).appendString("preload val").build());
 
         // Start cursors in the RW transaction.
-        scanSingleEntryAndLeaveCursorOpen(tbl, rwTx, null, null);
-        scanSingleEntryAndLeaveCursorOpen(tbl, rwTx, hashIdxId, idxKey);
-        scanSingleEntryAndLeaveCursorOpen(tbl, rwTx, sortedIdxId, null);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, rwTx, null, null);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, rwTx, hashIdxId, idxKey);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, rwTx, sortedIdxId, null);
 
         // Start cursors in the RO transaction.
-        scanSingleEntryAndLeaveCursorOpen(tbl, roTx, null, null);
-        scanSingleEntryAndLeaveCursorOpen(tbl, roTx, hashIdxId, idxKey);
-        scanSingleEntryAndLeaveCursorOpen(tbl, roTx, sortedIdxId, null);
-
-        TableViewInternal tableViewInternal = unwrapTableViewInternal(ignite.tables().table(TABLE_NAME));
-        var partitionStorage = (TestMvPartitionStorage) tableViewInternal
-                .internalTable().storage().getMvPartition(PART_ID);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, roTx, null, null);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, roTx, hashIdxId, idxKey);
+        scanSingleEntryAndLeaveCursorOpen(unwrappedTableOnNode0, roTx, sortedIdxId, null);
+
+        TableViewInternal unwrappedTableFromPrimary = unwrapTableViewInternal(primaryIgnite.tables().table(TABLE_NAME));
+        TestMvPartitionStorage partitionStorage = unwrapNullable(
+                unwrappedTableFromPrimary.internalTable().storage().getMvPartition(PART_ID),
+                TestMvPartitionStorage.class
+        );
 
-        var hashIdxStorage = (TestHashIndexStorage) tableViewInternal
-                .internalTable().storage().getIndex(PART_ID, hashIdxId);
+        TestHashIndexStorage hashIdxStorage = unwrapNullable(
+                unwrappedTableFromPrimary.internalTable().storage().getIndex(PART_ID, hashIdxId),
+                TestHashIndexStorage.class
+        );
 
-        var sortedIdxStorage = (TestSortedIndexStorage) tableViewInternal
-                .internalTable().storage().getIndex(PART_ID, sortedIdxId);
+        TestSortedIndexStorage sortedIdxStorage = unwrapNullable(
+                unwrappedTableFromPrimary.internalTable().storage().getIndex(PART_ID, sortedIdxId),
+                TestSortedIndexStorage.class
+        );
 
-        assertTrue(ignite.txManager().lockManager().locks(rwTx.id()).hasNext());
+        assertTrue(primaryIgnite.txManager().lockManager().locks(rwTx.id()).hasNext());
         assertEquals(6, partitionStorage.pendingCursors() + hashIdxStorage.pendingCursors() + sortedIdxStorage.pendingCursors());
 
         NodeUtils.transferPrimary(cluster.runningNodes().collect(toSet()), tblReplicationGrp, null);
 
-        assertTrue(ignite.txManager().lockManager().locks(rwTx.id()).hasNext());
+        assertTrue(primaryIgnite.txManager().lockManager().locks(rwTx.id()).hasNext());
         assertEquals(6, partitionStorage.pendingCursors() + hashIdxStorage.pendingCursors() + sortedIdxStorage.pendingCursors());
 
         rwTx.rollback();
 
-
-        assertFalse(ignite.txManager().lockManager().locks(rwTx.id()).hasNext());
+        assertFalse(primaryIgnite.txManager().lockManager().locks(rwTx.id()).hasNext());
         assertEquals(3, partitionStorage.pendingCursors() + hashIdxStorage.pendingCursors() + sortedIdxStorage.pendingCursors());
     }
 
     /**
      * Starts a scan procedure for a specific transaction and reads only the first line from the cursor.
      *
-     * @param tbl Scanned table.
+     * @param unwrappedTable Scanned table.
      * @param tx Transaction.
      * @param idxId Index id.
-     * @throws Exception If failed.
      */
-    private void scanSingleEntryAndLeaveCursorOpen(TableViewInternal tbl, InternalTransaction tx, Integer idxId, BinaryTuple exactKey)
-            throws Exception {
+    private void scanSingleEntryAndLeaveCursorOpen(
+            TableViewInternal unwrappedTable,
+            InternalTransaction tx,
+            Integer idxId,
+            BinaryTuple exactKey
+    ) {
+        bypassingThreadAssertions(() -> {
+            try {
+                scanSingleEntryAndLeaveCursorOpen0(unwrappedTable, tx, idxId, exactKey);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+        });
+    }
+
+    private void scanSingleEntryAndLeaveCursorOpen0(
+            TableViewInternal unwrappedTable,
+            InternalTransaction tx,
+            Integer idxId,
+            BinaryTuple exactKey
+    ) throws Exception {
+        InternalTable internalTable = unwrappedTable.internalTable();
+
         Publisher<BinaryRow> publisher;
 
         if (tx.isReadOnly()) {
             CompletableFuture<ReplicaMeta> primaryReplicaFut = node(0).placementDriver().getPrimaryReplica(
-                    new TablePartitionId(tbl.tableId(), PART_ID),
+                    new TablePartitionId(unwrappedTable.tableId(), PART_ID),
                     node(0).clock().now()
             );
 
@@ -294,23 +322,23 @@ public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
             ClusterNode primaryNode = node(0).clusterNodes().stream().filter(node -> node.id().equals(primaryId)).findAny().get();
 
             if (idxId == null) {
-                publisher = tbl.internalTable().scan(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, tx.coordinatorId());
+                publisher = internalTable.scan(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, tx.coordinatorId());
             } else if (exactKey == null) {
-                publisher = tbl.internalTable().scan(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, idxId, null, null, 0, null,
+                publisher = internalTable.scan(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, idxId, null, null, 0, null,
                         tx.coordinatorId());
             } else {
-                publisher = tbl.internalTable().lookup(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, idxId, exactKey, null,
+                publisher = internalTable.lookup(PART_ID, tx.id(), tx.readTimestamp(), primaryNode, idxId, exactKey, null,
                         tx.coordinatorId());
             }
         } else if (idxId == null) {
-            publisher = tbl.internalTable().scan(PART_ID, tx);
+            publisher = unwrappedTable.internalTable().scan(PART_ID, tx);
         } else if (exactKey == null) {
-            publisher = tbl.internalTable().scan(PART_ID, tx, idxId, null, null, 0, null);
+            publisher = unwrappedTable.internalTable().scan(PART_ID, tx, idxId, null, null, 0, null);
         } else {
             ReadWriteTransactionImpl rwTx = Wrappers.unwrap(tx, ReadWriteTransactionImpl.class);
 
             CompletableFuture<ReplicaMeta> primaryReplicaFut = node(0).placementDriver().getPrimaryReplica(
-                    new TablePartitionId(tbl.tableId(), PART_ID),
+                    new TablePartitionId(unwrappedTable.tableId(), PART_ID),
                     node(0).clock().now()
             );
 
@@ -322,7 +350,7 @@ public class ItPrimaryReplicaChoiceTest extends ClusterPerTestIntegrationTest {
 
             ClusterNode primaryNode = node(0).clusterNodes().stream().filter(node -> node.id().equals(primaryId)).findAny().get();
 
-            publisher = tbl.internalTable().lookup(
+            publisher = unwrappedTable.internalTable().lookup(
                     PART_ID,
                     rwTx.id(),
                     rwTx.commitPartition(),
diff --git a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItTableScanTest.java b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItTableScanTest.java
index 06508bf3e3..43f410e3ac 100644
--- a/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItTableScanTest.java
+++ b/modules/runner/src/integrationTest/java/org/apache/ignite/internal/table/ItTableScanTest.java
@@ -25,6 +25,7 @@ import static org.apache.ignite.internal.testframework.IgniteTestUtils.runRace;
 import static org.apache.ignite.internal.testframework.IgniteTestUtils.waitForCondition;
 import static org.apache.ignite.internal.testframework.flow.TestFlowUtils.subscribeToPublisher;
 import static org.apache.ignite.internal.testframework.matchers.CompletableFutureMatcher.willCompleteSuccessfully;
+import static org.apache.ignite.internal.wrapper.Wrappers.unwrapNullable;
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.hasSize;
@@ -54,7 +55,6 @@ import org.apache.ignite.internal.catalog.CatalogManager;
 import org.apache.ignite.internal.catalog.descriptors.CatalogObjectDescriptor;
 import org.apache.ignite.internal.lang.IgniteBiTuple;
 import org.apache.ignite.internal.lang.IgniteStringFormatter;
-import org.apache.ignite.internal.lang.IgniteSystemProperties;
 import org.apache.ignite.internal.lang.RunnableX;
 import org.apache.ignite.internal.placementdriver.PlacementDriver;
 import org.apache.ignite.internal.placementdriver.ReplicaMeta;
@@ -69,7 +69,6 @@ import org.apache.ignite.internal.sql.BaseSqlIntegrationTest;
 import org.apache.ignite.internal.storage.impl.TestMvPartitionStorage;
 import org.apache.ignite.internal.storage.index.impl.TestSortedIndexStorage;
 import org.apache.ignite.internal.testframework.IgniteTestUtils;
-import org.apache.ignite.internal.testframework.WithSystemProperty;
 import org.apache.ignite.internal.tx.InternalTransaction;
 import org.apache.ignite.internal.utils.PrimaryReplica;
 import org.apache.ignite.network.ClusterNode;
@@ -89,7 +88,6 @@ import org.junit.jupiter.params.provider.ValueSource;
 /**
  * Tests to check a scan internal command.
  */
-@WithSystemProperty(key = IgniteSystemProperties.THREAD_ASSERTIONS_ENABLED, value = "false")
 public class ItTableScanTest extends BaseSqlIntegrationTest {
     /** Table name. */
     private static final String TABLE_NAME = "test";
@@ -148,10 +146,15 @@ public class ItTableScanTest extends BaseSqlIntegrationTest {
     private void checkCursorsAreClosed(IgniteImpl ignite) {
         int sortedIdxId = getIndexId(ignite, SORTED_IDX);
 
-        var partitionStorage = (TestMvPartitionStorage) unwrapTableViewInternal(ignite.tables().table(TABLE_NAME))
-                .internalTable().storage().getMvPartition(PART_ID);
-        var sortedIdxStorage = (TestSortedIndexStorage) unwrapTableViewInternal(ignite.tables().table(TABLE_NAME))
-                .internalTable().storage().getIndex(PART_ID, sortedIdxId);
+        TableViewInternal tableViewInternal = unwrapTableViewInternal(ignite.tables().table(TABLE_NAME));
+        TestMvPartitionStorage partitionStorage = unwrapNullable(
+                tableViewInternal.internalTable().storage().getMvPartition(PART_ID),
+                TestMvPartitionStorage.class
+        );
+        TestSortedIndexStorage sortedIdxStorage = unwrapNullable(
+                tableViewInternal.internalTable().storage().getIndex(PART_ID, sortedIdxId),
+                TestSortedIndexStorage.class
+        );
 
         try {
             assertTrue(
diff --git a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/ThreadAssertingMvPartitionStorage.java b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/ThreadAssertingMvPartitionStorage.java
index d320b5b37f..701ff5cf04 100644
--- a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/ThreadAssertingMvPartitionStorage.java
+++ b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/ThreadAssertingMvPartitionStorage.java
@@ -28,6 +28,7 @@ import org.apache.ignite.internal.storage.gc.GcEntry;
 import org.apache.ignite.internal.util.Cursor;
 import org.apache.ignite.internal.worker.ThreadAssertingCursor;
 import org.apache.ignite.internal.worker.ThreadAssertions;
+import org.apache.ignite.internal.wrapper.Wrapper;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -35,7 +36,7 @@ import org.jetbrains.annotations.Nullable;
  *
  * @see ThreadAssertions
  */
-public class ThreadAssertingMvPartitionStorage implements MvPartitionStorage {
+public class ThreadAssertingMvPartitionStorage implements MvPartitionStorage, Wrapper {
     private final MvPartitionStorage partitionStorage;
 
     /** Constructor. */
@@ -164,4 +165,9 @@ public class ThreadAssertingMvPartitionStorage implements MvPartitionStorage {
     public void close() {
         partitionStorage.close();
     }
+
+    @Override
+    public <T> T unwrap(Class<T> classToUnwrap) {
+        return classToUnwrap.cast(partitionStorage);
+    }
 }
diff --git a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/ThreadAssertingIndexStorage.java b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/ThreadAssertingIndexStorage.java
index 50fcaa6553..1b8c9a97ff 100644
--- a/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/ThreadAssertingIndexStorage.java
+++ b/modules/storage-api/src/main/java/org/apache/ignite/internal/storage/index/ThreadAssertingIndexStorage.java
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.storage.StorageException;
 import org.apache.ignite.internal.util.Cursor;
 import org.apache.ignite.internal.worker.ThreadAssertingCursor;
 import org.apache.ignite.internal.worker.ThreadAssertions;
+import org.apache.ignite.internal.wrapper.Wrapper;
 import org.jetbrains.annotations.Nullable;
 
 /**
@@ -33,7 +34,7 @@ import org.jetbrains.annotations.Nullable;
  *
  * @see ThreadAssertions
  */
-abstract class ThreadAssertingIndexStorage implements IndexStorage {
+abstract class ThreadAssertingIndexStorage implements IndexStorage, Wrapper {
     private final IndexStorage indexStorage;
 
     /** Constructor. */
@@ -73,4 +74,9 @@ abstract class ThreadAssertingIndexStorage implements IndexStorage {
 
         indexStorage.setNextRowIdToBuild(rowId);
     }
+
+    @Override
+    public <T> T unwrap(Class<T> classToUnwrap) {
+        return classToUnwrap.cast(indexStorage);
+    }
 }