This is an automated email from the ASF dual-hosted git repository.
korlov 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 92bef18f223 IGNITE-26632 Catalog. Unable to add new serializer with
version 1 (#6827)
92bef18f223 is described below
commit 92bef18f2237ea2a37eeb00b1d36f67c2520120a
Author: korlov42 <[email protected]>
AuthorDate: Wed Oct 22 11:20:20 2025 +0300
IGNITE-26632 Catalog. Unable to add new serializer with version 1 (#6827)
---
.../storage/CatalogEntrySerializationTest.java | 729 ++++++++++++---------
...logSerializationCompatibilityV2ReadsV1Test.java | 15 -
...logSerializationCompatibilityV2ReadsV2Test.java | 17 +
.../AlterTableProperties_1.bin | Bin
4 files changed, 421 insertions(+), 340 deletions(-)
diff --git
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java
index c8c2e140247..891485bdd82 100644
---
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java
+++
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogEntrySerializationTest.java
@@ -21,25 +21,29 @@ import static
org.apache.ignite.internal.catalog.commands.CatalogUtils.DEFAULT_F
import static org.apache.ignite.internal.hlc.HybridTimestamp.hybridTimestamp;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.empty;
-import static org.hamcrest.Matchers.hasSize;
-import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import it.unimi.dsi.fastutil.shorts.ShortArrayList;
import it.unimi.dsi.fastutil.shorts.ShortList;
import java.io.IOException;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Base64;
+import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
+import java.util.function.Function;
import java.util.stream.Stream;
import org.apache.ignite.internal.catalog.Catalog;
import org.apache.ignite.internal.catalog.commands.DefaultValue;
@@ -69,8 +73,6 @@ import
org.apache.ignite.internal.catalog.storage.serialization.CatalogObjectSer
import
org.apache.ignite.internal.catalog.storage.serialization.CatalogSerializer;
import
org.apache.ignite.internal.catalog.storage.serialization.MarshallableEntry;
import
org.apache.ignite.internal.catalog.storage.serialization.MarshallableEntryType;
-import
org.apache.ignite.internal.catalog.storage.serialization.UpdateLogMarshaller;
-import
org.apache.ignite.internal.catalog.storage.serialization.UpdateLogMarshallerImpl;
import org.apache.ignite.internal.testframework.BaseIgniteAbstractTest;
import org.apache.ignite.internal.type.NativeType;
import org.apache.ignite.internal.type.NativeTypes;
@@ -78,15 +80,24 @@ import
org.apache.ignite.internal.util.io.IgniteUnsafeDataInput;
import org.apache.ignite.internal.util.io.IgniteUnsafeDataOutput;
import org.apache.ignite.sql.ColumnType;
import org.assertj.core.api.BDDAssertions;
+import org.assertj.core.api.RecursiveComparisonAssert;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.ArgumentsProvider;
+import org.junit.jupiter.params.provider.ArgumentsSource;
import org.junit.jupiter.params.provider.MethodSource;
+import org.junit.jupiter.params.support.AnnotationConsumer;
+import org.junit.jupiter.params.support.ParameterDeclarations;
/**
* Tests to verify catalog storage entries serialization.
+ *
+ * <p>The main purpose of this class is to make sure that every marshallable
entry can be marshalled and then
+ * successfully unmarshalled back by the same version of serializer.
*/
public class CatalogEntrySerializationTest extends BaseIgniteAbstractTest {
private static final long SEED = System.nanoTime();
@@ -96,196 +107,350 @@ public class CatalogEntrySerializationTest extends
BaseIgniteAbstractTest {
/** This field should be ignored for version 1. */
private static final String UPDATE_TIMESTAMP_FIELD_NAME_REGEX =
".*updateTimestamp";
- private UpdateLogMarshallerImpl marshaller;
+ private AssertionConfiguration assertionConfiguration = assertion ->
assertion;
@BeforeEach
public void setup() {
log.info("Seed: {}", SEED);
}
- private static Stream<Arguments> marshallableEntryTypes() {
- return Arrays.stream(MarshallableEntryType.values())
- .filter(t -> t != MarshallableEntryType.VERSIONED_UPDATE)
- .flatMap(t ->
resolveVersions(t.container()).intStream().mapToObj(v -> Arguments.of(t, v)));
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.ALTER_COLUMN)
+ void alterColumnEntry(int serializerVersion) {
+ CatalogTableColumnDescriptor desc1 =
newCatalogTableColumnDescriptor("c0", null);
+ CatalogTableColumnDescriptor desc2 =
+ newCatalogTableColumnDescriptor("c1",
DefaultValue.constant(UUID.randomUUID()));
+ CatalogTableColumnDescriptor desc3 =
+ newCatalogTableColumnDescriptor("c2",
DefaultValue.functionCall("function"));
+ CatalogTableColumnDescriptor desc4 =
newCatalogTableColumnDescriptor("c3", DefaultValue.constant(null));
+
+ checkSerialization(serializerVersion, new AlterColumnEntry(1, desc1));
+ checkSerialization(serializerVersion, new AlterColumnEntry(1, desc2));
+ checkSerialization(serializerVersion, new AlterColumnEntry(1, desc3));
+ checkSerialization(serializerVersion, new AlterColumnEntry(1, desc4));
}
- private static ShortList resolveVersions(Class<?> clazz) {
- ShortList versions = new ShortArrayList();
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.ALTER_ZONE)
+ void alterZoneEntry(int serializerVersion) {
+ CatalogStorageProfilesDescriptor profiles =
+ new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
+ UpdateEntry entry1 = new
AlterZoneEntry(newCatalogZoneDescriptor("zone1", profiles));
+
+ checkSerialization(serializerVersion, entry1);
+ }
- for (Class<?> declaredClass : clazz.getDeclaredClasses()) {
- if (CatalogObjectSerializer.class.isAssignableFrom(declaredClass))
{
- CatalogSerializer catalogSerializer =
declaredClass.getAnnotation(CatalogSerializer.class);
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_ZONE)
+ void newZoneEntry(int serializerVersion) {
+ CatalogStorageProfilesDescriptor profiles =
+ new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
- versions.add(catalogSerializer.version());
- }
+ UpdateEntry entry1 = new
NewZoneEntry(newCatalogZoneDescriptor("zone1", profiles));
+ checkSerialization(serializerVersion, entry1);
+
+ UpdateEntry entry2 = new
NewZoneEntry(newCatalogZoneDescriptor("zone2", profiles));
+ checkSerialization(serializerVersion, entry2);
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DROP_COLUMN)
+ void dropColumnEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new DropColumnsEntry(1,
Set.of("C1", "C2")));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DROP_INDEX)
+ void dropIndexEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new DropIndexEntry(231));
+ checkSerialization(serializerVersion, new DropIndexEntry(465));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DROP_TABLE)
+ void dropTableEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new DropTableEntry(23));
+ checkSerialization(serializerVersion, new DropTableEntry(3));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DROP_ZONE)
+ void dropZoneEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new DropZoneEntry(123));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.MAKE_INDEX_AVAILABLE)
+ void makeIndexAvailableEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new
MakeIndexAvailableEntry(321));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.REMOVE_INDEX)
+ void removeIndexEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new RemoveIndexEntry(231));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.START_BUILDING_INDEX)
+ void startBuildingIndexEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new
StartBuildingIndexEntry(321));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_COLUMN)
+ void newColumnEntry(int serializerVersion) {
+ CatalogTableColumnDescriptor columnDescriptor1 =
newCatalogTableColumnDescriptor("c1", DefaultValue.constant(null));
+ CatalogTableColumnDescriptor columnDescriptor2 =
newCatalogTableColumnDescriptor("c2", DefaultValue.functionCall("func"));
+
+ checkSerialization(serializerVersion, new NewColumnsEntry(11,
List.of(columnDescriptor1, columnDescriptor2)));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_INDEX)
+ void newIndexEntry(int serializerVersion) {
+ CatalogSortedIndexDescriptor sortedIndexDescriptor =
newSortedIndexDescriptor("idx1");
+ CatalogHashIndexDescriptor hashIndexDescriptor =
newHashIndexDescriptor("idx2");
+
+ checkSerialization(serializerVersion, new
NewIndexEntry(sortedIndexDescriptor));
+ checkSerialization(serializerVersion, new
NewIndexEntry(hashIndexDescriptor));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_SYS_VIEW)
+ void newSystemViewEntry(int serializerVersion) {
+ CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c1", null);
+ CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c2", null);
+
+ CatalogSystemViewDescriptor nodeDesc =
+ new CatalogSystemViewDescriptor(1, 2, "view1", List.of(col1,
col2), SystemViewType.NODE);
+ CatalogSystemViewDescriptor clusterDesc =
+ new CatalogSystemViewDescriptor(1, 2, "view1", List.of(col1,
col2), SystemViewType.CLUSTER);
+
+ NewSystemViewEntry nodeEntry = new NewSystemViewEntry(nodeDesc);
+ NewSystemViewEntry clusterEntry = new NewSystemViewEntry(clusterDesc);
+
+ checkSerialization(serializerVersion, nodeEntry);
+ checkSerialization(serializerVersion, clusterEntry);
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_TABLE)
+ void newTableEntry(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
}
- assertThat(versions, not(empty()));
+ CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c0", null);
+ CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c1", null);
+ CatalogTableColumnDescriptor col3 =
newCatalogTableColumnDescriptor("c3", null);
+ CatalogTableColumnDescriptor col4 =
newCatalogTableColumnDescriptor("c2", null);
+
+ List<CatalogTableColumnDescriptor> columns = List.of(col1, col2, col3,
col4);
+
+ checkSerialization(serializerVersion, new
NewTableEntry(newTableDescriptor("Table1", columns, List.of("c1", "c2"),
null)));
+ checkSerialization(serializerVersion, new
NewTableEntry(newTableDescriptor("Table1", columns, List.of("c1", "c2"),
List.of())));
+ checkSerialization(serializerVersion, new
NewTableEntry(newTableDescriptor("Table1", columns, List.of("c1", "c2"),
List.of("c2"))));
+ checkSerialization(serializerVersion, new
NewTableEntry(newTableDescriptor("Table1", columns, List.of("c1", "c2"),
List.of("c1"))));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.RENAME_TABLE)
+ void renameTableEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new RenameTableEntry(1,
"newName"));
+ }
- return versions;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.ID_GENERATOR)
+ void idGeneratorEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new
ObjectIdGenUpdateEntry(Integer.MAX_VALUE));
}
- @ParameterizedTest
- @MethodSource("marshallableEntryTypes")
- void test(MarshallableEntryType type, int version) {
- marshaller = new UpdateLogMarshallerImpl(version);
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.SNAPSHOT)
+ void snapshotEntry(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
+ }
+
+ CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c1", null);
+ CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c2", null);
+
+ List<CatalogTableColumnDescriptor> columns = List.of(col1, col2);
+
+ CatalogTableDescriptor[] tables = {
+ newTableDescriptor("Table1", columns),
+ newTableDescriptor("Table2", columns)
+ };
+
+ CatalogIndexDescriptor[] indexes = {
+ newSortedIndexDescriptor("idx1"),
+ newHashIndexDescriptor("idx2")
+ };
+
+ CatalogSystemViewDescriptor[] views = {
+ new CatalogSystemViewDescriptor(1, 2, "view1", columns,
SystemViewType.NODE),
+ new CatalogSystemViewDescriptor(1, 2, "view2", columns,
SystemViewType.CLUSTER)
+ };
- switch (type) {
- case ALTER_COLUMN:
- checkAlterColumnEntry(version);
- break;
+ CatalogStorageProfilesDescriptor profiles =
+ new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
- case ALTER_ZONE:
- checkAlterZoneEntry(version);
- break;
+ CatalogZoneDescriptor zone1 = newCatalogZoneDescriptor("zone1",
profiles);
- case NEW_ZONE:
- checkNewZoneEntry(version);
- break;
+ SnapshotEntry entry = new SnapshotEntry(new Catalog(2, 0L, 1,
+ List.of(zone1),
+ List.of(new CatalogSchemaDescriptor(1, "desc", tables,
indexes, views, hybridTimestamp(1))), zone1.id()));
- case DROP_COLUMN:
- checkSerialization(version, new DropColumnsEntry(1,
Set.of("C1", "C2")));
- break;
+ checkSerialization(serializerVersion, entry);
+ }
- case DROP_INDEX:
- checkSerialization(version, new DropIndexEntry(231), new
DropIndexEntry(231));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.VERSIONED_UPDATE)
+ void versionedUpdateEntry(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
+ }
- case DROP_TABLE:
- checkSerialization(version, new DropTableEntry(23), new
DropTableEntry(3));
- break;
+ CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c1", null);
+ CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c2", null);
- case DROP_ZONE:
- checkSerialization(version, new DropZoneEntry(123));
- break;
+ List<CatalogTableColumnDescriptor> columns = List.of(col1, col2);
- case MAKE_INDEX_AVAILABLE:
- checkSerialization(version, new MakeIndexAvailableEntry(321));
- break;
+ CatalogStorageProfilesDescriptor profiles =
+ new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
- case REMOVE_INDEX:
- checkSerialization(version, new RemoveIndexEntry(231));
- break;
+ VersionedUpdate entry = new VersionedUpdate(2, 321, List.of(
+ new NewTableEntry(newTableDescriptor("Table1", columns)),
+ new NewIndexEntry(newSortedIndexDescriptor("idx1")),
+ new NewZoneEntry(newCatalogZoneDescriptor("zone1", profiles))
+ ));
- case START_BUILDING_INDEX:
- checkSerialization(version, new StartBuildingIndexEntry(321));
- break;
+ checkSerialization(serializerVersion, entry);
+ }
- case NEW_COLUMN:
- checkNewColumnsEntry(version);
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.RENAME_INDEX)
+ void renameIndexEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new RenameIndexEntry(1,
"newName"));
+ }
- case NEW_INDEX:
- checkNewIndexEntry(version);
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.SET_DEFAULT_ZONE)
+ void setDefaultZoneEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new SetDefaultZoneEntry(1));
+ checkSerialization(serializerVersion, new
SetDefaultZoneEntry(Integer.MAX_VALUE));
+ }
- case NEW_SYS_VIEW:
- checkNewSystemViewEntry(version);
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.NEW_SCHEMA)
+ void newSchemaEntry(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
+ }
- case NEW_TABLE:
- checkNewTableEntry(version);
- break;
+ checkSerialization(serializerVersion, new
NewSchemaEntry(newSchemaDescriptor("PUBLIC")));
+ }
- case RENAME_TABLE:
- checkSerialization(version, new RenameTableEntry(1,
"newName"));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DROP_SCHEMA)
+ void dropSchemaEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new DropSchemaEntry(1));
+ }
- case ID_GENERATOR:
- checkSerialization(version, new
ObjectIdGenUpdateEntry(Integer.MAX_VALUE));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_HASH_INDEX)
+ void descriptorHashIndex(int serializerVersion) {
+ checkSerialization(serializerVersion, newHashIndexDescriptor("foo"));
+ }
- case SNAPSHOT:
- checkSnapshotEntry();
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_SORTED_INDEX)
+ void descriptorSortedIndex(int serializerVersion) {
+ checkSerialization(serializerVersion, newSortedIndexDescriptor("foo"));
+ }
- case RENAME_INDEX:
- checkSerialization(version, new RenameIndexEntry(1,
"newName"));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_SCHEMA)
+ void descriptorSchema(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
+ }
- case SET_DEFAULT_ZONE:
- checkSerialization(version, new SetDefaultZoneEntry(1), new
SetDefaultZoneEntry(Integer.MAX_VALUE));
- break;
+ checkSerialization(serializerVersion,
newSchemaDescriptor("my_schema1"));
+ }
- case NEW_SCHEMA:
- checkSerialization(version, new
NewSchemaEntry(newSchemaDescriptor("PUBLIC")));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+
@MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_STORAGE_PROFILE)
+ void descriptorStorageProfile(int serializerVersion) {
+ checkSerialization(serializerVersion, new
CatalogStorageProfileDescriptor("profile1"));
+ }
- case DROP_SCHEMA:
- checkSerialization(version, new DropSchemaEntry(1));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+
@MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_STORAGE_PROFILES)
+ void descriptorStorageProfiles(int serializerVersion) {
+ checkSerialization(serializerVersion, new
CatalogStorageProfilesDescriptor(List.of(
+ new CatalogStorageProfileDescriptor("profile1"),
+ new CatalogStorageProfileDescriptor("profile2")
+ )));
+ }
- case DESCRIPTOR_HASH_INDEX:
- checkDescriptorSerialization(newHashIndexDescriptor("foo"));
- break;
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_SYSTEM_VIEW)
+ void descriptorSystemView(int serializerVersion) {
+ CatalogTableColumnDescriptor column =
newCatalogTableColumnDescriptor("column", null);
+ CatalogSystemViewDescriptor view = new CatalogSystemViewDescriptor(1,
2, "sys_view", List.of(column), SystemViewType.NODE);
+ checkSerialization(serializerVersion, view);
+ }
- case DESCRIPTOR_SORTED_INDEX:
- checkDescriptorSerialization(newSortedIndexDescriptor("foo"));
- break;
-
- case DESCRIPTOR_SCHEMA:
-
checkDescriptorSerialization(newSchemaDescriptor("my_schema1"));
- break;
-
- case DESCRIPTOR_STORAGE_PROFILE:
- checkDescriptorSerialization(new
CatalogStorageProfileDescriptor("profile1"));
- break;
-
- case DESCRIPTOR_STORAGE_PROFILES:
- checkDescriptorSerialization(new
CatalogStorageProfilesDescriptor(List.of(
- new CatalogStorageProfileDescriptor("profile1"),
- new CatalogStorageProfileDescriptor("profile2")
- )));
- break;
-
- case DESCRIPTOR_SYSTEM_VIEW:
- CatalogTableColumnDescriptor column =
newCatalogTableColumnDescriptor("column", null);
- CatalogSystemViewDescriptor view = new
CatalogSystemViewDescriptor(1, 2, "sys_view", List.of(column),
SystemViewType.NODE);
-
- checkDescriptorSerialization(view);
- break;
-
- case DESCRIPTOR_TABLE:
- checkDescriptorSerialization(newTableDescriptor("some_table",
List.of(newCatalogTableColumnDescriptor("c1", null))));
- break;
-
- case DESCRIPTOR_TABLE_COLUMN:
-
checkDescriptorSerialization(newCatalogTableColumnDescriptor("c1", null));
- break;
-
- case DESCRIPTOR_TABLE_VERSION:
- checkDescriptorSerialization(new
TableVersion(List.of(newCatalogTableColumnDescriptor("column", null))));
- break;
-
- case DESCRIPTOR_TABLE_SCHEMA_VERSIONS:
- TableVersion ver1 = new TableVersion(List.of(
- newCatalogTableColumnDescriptor("column1", null)
- ));
-
- TableVersion ver2 = new TableVersion(List.of(
- newCatalogTableColumnDescriptor("column1", null),
- newCatalogTableColumnDescriptor("column2", null)
- ));
-
- checkDescriptorSerialization(new
CatalogTableSchemaVersions(ver1, ver2));
- break;
-
- case DESCRIPTOR_ZONE:
- CatalogStorageProfilesDescriptor profiles =
- new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
-
checkDescriptorSerialization(newCatalogZoneDescriptor("myZone", profiles));
- break;
-
- case ALTER_TABLE_PROPERTIES:
- checkSerialization(version, new AlterTablePropertiesEntry(123,
null, null));
- checkSerialization(version, new AlterTablePropertiesEntry(123,
0.2, null));
- checkSerialization(version, new AlterTablePropertiesEntry(123,
null, 500L));
- checkSerialization(version, new AlterTablePropertiesEntry(123,
0.2, 500L));
- break;
-
- default:
- throw new UnsupportedOperationException("Test not implemented
" + type);
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_TABLE)
+ void descriptorTable(int serializerVersion) {
+ if (serializerVersion == 1) {
+ ignoreDifferenceInUpdateTime();
}
+
+ checkSerialization(serializerVersion, newTableDescriptor("some_table",
List.of(newCatalogTableColumnDescriptor("c1", null))));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_TABLE_COLUMN)
+ void descriptorTableColumn(int serializerVersion) {
+ checkSerialization(serializerVersion,
newCatalogTableColumnDescriptor("c1", null));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+
@MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_TABLE_VERSION)
+ void descriptorTableVersion(int serializerVersion) {
+ checkSerialization(serializerVersion, new
TableVersion(List.of(newCatalogTableColumnDescriptor("column", null))));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+
@MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_TABLE_SCHEMA_VERSIONS)
+ void descriptorTableSchemaVersions(int serializerVersion) {
+ TableVersion ver1 = new
TableVersion(List.of(newCatalogTableColumnDescriptor("column1", null)));
+ TableVersion ver2 = new TableVersion(List.of(
+ newCatalogTableColumnDescriptor("column1", null),
+ newCatalogTableColumnDescriptor("column2", null)
+ ));
+ checkSerialization(serializerVersion, new
CatalogTableSchemaVersions(ver1, ver2));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.DESCRIPTOR_ZONE)
+ void descriptorZone(int serializerVersion) {
+ CatalogStorageProfilesDescriptor profiles =
+ new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
+ checkSerialization(serializerVersion,
newCatalogZoneDescriptor("myZone", profiles));
+ }
+
+ @ParameterizedTest(name = "serializerVersion={0}")
+ @MarshallableEntryTypeSource(MarshallableEntryType.ALTER_TABLE_PROPERTIES)
+ void alterTablePropertiesEntry(int serializerVersion) {
+ checkSerialization(serializerVersion, new
AlterTablePropertiesEntry(123, null, null));
+ checkSerialization(serializerVersion, new
AlterTablePropertiesEntry(123, 0.2, null));
+ checkSerialization(serializerVersion, new
AlterTablePropertiesEntry(123, null, 500L));
+ checkSerialization(serializerVersion, new
AlterTablePropertiesEntry(123, 0.2, 500L));
}
@ParameterizedTest(name = "{0}")
@@ -358,175 +523,47 @@ public class CatalogEntrySerializationTest extends
BaseIgniteAbstractTest {
}
}
- private void checkAlterZoneEntry(int version) {
- CatalogStorageProfilesDescriptor profiles =
- new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
- UpdateEntry entry1 = new
AlterZoneEntry(newCatalogZoneDescriptor("zone1", profiles));
-
- checkSerialization(version, entry1, entry1);
- }
-
- private void checkNewZoneEntry(int version) {
- CatalogStorageProfilesDescriptor profiles =
- new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
-
- UpdateEntry entry1 = new
NewZoneEntry(newCatalogZoneDescriptor("zone1", profiles));
- UpdateEntry entry2 = new
NewZoneEntry(newCatalogZoneDescriptor("zone2", profiles));
- checkSerialization(version, entry1, entry2);
- }
-
- private void checkAlterColumnEntry(int version) {
- CatalogTableColumnDescriptor desc1 =
newCatalogTableColumnDescriptor("c0", null);
- CatalogTableColumnDescriptor desc2 =
- newCatalogTableColumnDescriptor("c1",
DefaultValue.constant(UUID.randomUUID()));
- CatalogTableColumnDescriptor desc3 =
- newCatalogTableColumnDescriptor("c2",
DefaultValue.functionCall("function"));
- CatalogTableColumnDescriptor desc4 =
newCatalogTableColumnDescriptor("c3", DefaultValue.constant(null));
-
- UpdateEntry entry1 = new AlterColumnEntry(1, desc1);
- UpdateEntry entry2 = new AlterColumnEntry(1, desc2);
- UpdateEntry entry3 = new AlterColumnEntry(1, desc3);
- UpdateEntry entry4 = new AlterColumnEntry(1, desc4);
-
- checkSerialization(version, entry1, entry2, entry3, entry4);
- }
-
- private void checkNewColumnsEntry(int version) {
- CatalogTableColumnDescriptor columnDescriptor1 =
newCatalogTableColumnDescriptor("c1", DefaultValue.constant(null));
- CatalogTableColumnDescriptor columnDescriptor2 =
newCatalogTableColumnDescriptor("c2", DefaultValue.functionCall("func"));
-
- checkSerialization(version, new NewColumnsEntry(11,
List.of(columnDescriptor1, columnDescriptor2)));
- }
-
- private void checkNewIndexEntry(int version) {
- CatalogSortedIndexDescriptor sortedIndexDescriptor =
newSortedIndexDescriptor("idx1");
- CatalogHashIndexDescriptor hashIndexDescriptor =
newHashIndexDescriptor("idx2");
-
- NewIndexEntry sortedIdxEntry = new
NewIndexEntry(sortedIndexDescriptor);
- NewIndexEntry hashIdxEntry = new NewIndexEntry(hashIndexDescriptor);
-
- checkSerialization(version, sortedIdxEntry, hashIdxEntry);
- }
-
- private void checkNewTableEntry(int version) {
- CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c0", null);
- CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c1", null);
- CatalogTableColumnDescriptor col3 =
newCatalogTableColumnDescriptor("c3", null);
- CatalogTableColumnDescriptor col4 =
newCatalogTableColumnDescriptor("c2", null);
-
- List<CatalogTableColumnDescriptor> columns = List.of(col1, col2, col3,
col4);
-
- NewTableEntry entry1 = new NewTableEntry(newTableDescriptor("Table1",
columns, List.of("c1", "c2"), null));
- NewTableEntry entry2 = new NewTableEntry(newTableDescriptor("Table1",
columns, List.of("c1", "c2"), List.of()));
- NewTableEntry entry3 = new NewTableEntry(newTableDescriptor("Table1",
columns, List.of("c1", "c2"), List.of("c2")));
- NewTableEntry entry4 = new NewTableEntry(newTableDescriptor("Table1",
columns, List.of("c1", "c2"), List.of("c1")));
-
- checkSerialization(version, entry1, entry2, entry3, entry4);
- }
-
- private void checkNewSystemViewEntry(int version) {
- CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c1", null);
- CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c2", null);
-
- CatalogSystemViewDescriptor nodeDesc =
- new CatalogSystemViewDescriptor(1, 2, "view1", List.of(col1,
col2), SystemViewType.NODE);
- CatalogSystemViewDescriptor clusterDesc =
- new CatalogSystemViewDescriptor(1, 2, "view1", List.of(col1,
col2), SystemViewType.CLUSTER);
-
- NewSystemViewEntry nodeEntry = new NewSystemViewEntry(nodeDesc);
- NewSystemViewEntry clusterEntry = new NewSystemViewEntry(clusterDesc);
-
- checkSerialization(version, nodeEntry, clusterEntry);
- }
-
- private void checkSnapshotEntry() {
- CatalogTableColumnDescriptor col1 =
newCatalogTableColumnDescriptor("c1", null);
- CatalogTableColumnDescriptor col2 =
newCatalogTableColumnDescriptor("c2", null);
-
- List<CatalogTableColumnDescriptor> columns = List.of(col1, col2);
-
- CatalogTableDescriptor[] tables = {
- newTableDescriptor("Table1", columns),
- newTableDescriptor("Table2", columns)
- };
-
- CatalogIndexDescriptor[] indexes = {
- newSortedIndexDescriptor("idx1"),
- newHashIndexDescriptor("idx2")
- };
-
- CatalogSystemViewDescriptor[] views = {
- new CatalogSystemViewDescriptor(1, 2, "view1", columns,
SystemViewType.NODE),
- new CatalogSystemViewDescriptor(1, 2, "view2", columns,
SystemViewType.CLUSTER)
- };
-
- CatalogStorageProfilesDescriptor profiles =
- new CatalogStorageProfilesDescriptor(List.of(new
CatalogStorageProfileDescriptor("default")));
-
- CatalogZoneDescriptor zone1 = newCatalogZoneDescriptor("zone1",
profiles);
-
- SnapshotEntry entry = new SnapshotEntry(new Catalog(2, 0L, 1,
- List.of(zone1),
- List.of(new CatalogSchemaDescriptor(1, "desc", tables,
indexes, views, hybridTimestamp(1))), zone1.id()));
-
- SnapshotEntry deserialized = (SnapshotEntry)
marshaller.unmarshall(marshaller.marshall(entry));
-
-
BDDAssertions.assertThat(deserialized).usingRecursiveComparison().isEqualTo(entry);
- }
-
- /**
- * Creates a {@link VersionedUpdate} from the provided entries and
validates that it is serialized and deserialized
- * correctly using the {@link UpdateLogMarshaller}.
- *
- * @param version Version.
- * @param entry Update entry to serialize.
- */
- private void checkSerialization(int version, UpdateEntry ... entry) {
- VersionedUpdate expected = newVersionedUpdate(entry);
-
- byte[] bytes = marshaller.marshall(expected);
-
- VersionedUpdate deserialized = (VersionedUpdate)
marshaller.unmarshall(bytes);
-
- assertThat(deserialized.version(), is(expected.version()));
- assertThat(deserialized.delayDurationMs(),
is(expected.delayDurationMs()));
-
- int expectedSize = expected.entries().size();
+ @Test
+ void ensureAllMarshallableEntryTypesAreCovered() {
+ EnumSet<MarshallableEntryType> missedTypes =
EnumSet.allOf(MarshallableEntryType.class);
- assertThat(deserialized.entries(), hasSize(expectedSize));
+ for (Method method :
CatalogEntrySerializationTest.class.getDeclaredMethods()) {
+ if
(!method.isAnnotationPresent(MarshallableEntryTypeSource.class)) {
+ continue;
+ }
- for (int i = 0; i < expectedSize; i++) {
- UpdateEntry expectedEntry = expected.entries().get(i);
- UpdateEntry actualEntry = deserialized.entries().get(i);
+ MarshallableEntryTypeSource typeSource =
method.getAnnotation(MarshallableEntryTypeSource.class);
- assertEqualsRecursive(version, expectedEntry, actualEntry);
+ missedTypes.remove(typeSource.value());
}
+
+ assertThat("All marshallable entries must be covered. "
+ + "Please add new test method for every missed entry type
using following template:\n\n"
+ + " @ParameterizedTest(name = \"serializerVersion={0}\")\n"
+ + "
@MarshallableEntryTypeSource(MarshallableEntryType.MY_ENTRY_TYPE)\n"
+ + " void myMarshallableEntry(int serializerVersion) {\n"
+ + " MarshallableEntry entry = ... // create entry
here\n"
+ + "\n"
+ + " checkSerialization(serializerVersion, entry);\n"
+ + " }\n", missedTypes, empty());
}
- /**
- * Checks that provided entry is serialized and deserialized correctly
using
- * {@link IgniteUnsafeDataOutput} and {@link IgniteUnsafeDataInput}
respectively.
- *
- * @param entry Entry to check deserialization.
- */
- private static void checkDescriptorSerialization(MarshallableEntry entry) {
+ private void checkSerialization(int serializerVersion, MarshallableEntry
entry) {
CatalogEntrySerializerProvider serializers =
CatalogEntrySerializerProvider.DEFAULT_PROVIDER;
try {
- for (int v = 1; v <=
serializers.latestSerializerVersion(entry.typeId()); v++) {
- byte[] bytes;
+ byte[] bytes;
- try (CatalogObjectDataOutput output = new
CatalogObjectDataOutput(serializers)) {
- serializers.get(v, entry.typeId()).writeTo(entry, output);
+ try (CatalogObjectDataOutput output = new
CatalogObjectDataOutput(serializers)) {
+ serializers.get(serializerVersion,
entry.typeId()).writeTo(entry, output);
- bytes = output.array();
- }
+ bytes = output.array();
+ }
- try (CatalogObjectDataInput input = new
CatalogObjectDataInput(serializers, bytes)) {
- MarshallableEntry deserialized = serializers.get(v,
entry.typeId()).readFrom(input);
+ try (CatalogObjectDataInput input = new
CatalogObjectDataInput(serializers, bytes)) {
+ MarshallableEntry deserialized =
serializers.get(serializerVersion, entry.typeId()).readFrom(input);
- assertEqualsRecursive(v, entry, deserialized);
- }
+ assertEqualsRecursive(entry, deserialized);
}
} catch (IOException e) {
throw new RuntimeException(e);
@@ -552,13 +589,6 @@ public class CatalogEntrySerializationTest extends
BaseIgniteAbstractTest {
);
}
- private static VersionedUpdate newVersionedUpdate(UpdateEntry ... entry) {
- int updateVer = 101;
- long delayDuration = Long.MIN_VALUE;
-
- return new VersionedUpdate(updateVer, delayDuration, List.of(entry));
- }
-
private static CatalogTableColumnDescriptor
newCatalogTableColumnDescriptor(String name, @Nullable DefaultValue
defaultValue) {
return new CatalogTableColumnDescriptor(name, ColumnType.STRING,
false, 10, 5, 127, defaultValue);
}
@@ -598,6 +628,7 @@ public class CatalogEntrySerializationTest extends
BaseIgniteAbstractTest {
.primaryKeyColumns(pkCols)
.colocationColumns(colCols)
.storageProfile("default")
+ .timestamp(hybridTimestamp(3))
.build();
}
@@ -625,14 +656,62 @@ public class CatalogEntrySerializationTest extends
BaseIgniteAbstractTest {
return new CatalogSchemaDescriptor(1, name, tables, indexes, views,
hybridTimestamp(3));
}
- private static <T> void assertEqualsRecursive(int version, T expected, T
actual) {
- var assertion = BDDAssertions.assertThat(actual)
- .usingRecursiveComparison();
+ private <T> void assertEqualsRecursive(T expected, T actual) {
+ RecursiveComparisonAssert<?> assertion = assertionConfiguration.apply(
+ BDDAssertions.assertThat(actual).usingRecursiveComparison()
+ );
+
+ assertion.isEqualTo(expected);
+ }
+
+ private void ignoreDifferenceInUpdateTime() {
+ assertionConfiguration = assertionConfiguration.andThen(assertion ->
+
assertion.ignoringFieldsMatchingRegexes(UPDATE_TIMESTAMP_FIELD_NAME_REGEX));
+ }
+
+ static class MarshallableEntryTypeArgumentsProvider
+ implements ArgumentsProvider,
AnnotationConsumer<MarshallableEntryTypeSource> {
+
+ private MarshallableEntryType enumValue;
- if (version == 1) {
- assertion =
assertion.ignoringFieldsMatchingRegexes(UPDATE_TIMESTAMP_FIELD_NAME_REGEX);
+ @Override
+ public void accept(MarshallableEntryTypeSource annotation) {
+ this.enumValue = annotation.value();
}
- assertion.isEqualTo(expected);
+ @Override
+ public Stream<? extends Arguments>
provideArguments(ParameterDeclarations parameters, ExtensionContext context) {
+ return
resolveVersions(enumValue.container()).intStream().mapToObj(Arguments::of);
+ }
+
+ private static ShortList resolveVersions(Class<?> clazz) {
+ ShortList versions = new ShortArrayList();
+
+ for (Class<?> declaredClass : clazz.getDeclaredClasses()) {
+ if
(CatalogObjectSerializer.class.isAssignableFrom(declaredClass)) {
+ CatalogSerializer catalogSerializer =
declaredClass.getAnnotation(CatalogSerializer.class);
+
+ versions.add(catalogSerializer.version());
+ }
+ }
+
+ assertThat(versions, not(empty()));
+
+ return versions;
+ }
+ }
+
+ @Target(ElementType.METHOD)
+ @Retention(RetentionPolicy.RUNTIME)
+ @ArgumentsSource(MarshallableEntryTypeArgumentsProvider.class)
+ @interface MarshallableEntryTypeSource {
+ MarshallableEntryType value();
+ }
+
+ @FunctionalInterface
+ private interface AssertionConfiguration extends
Function<RecursiveComparisonAssert<?>, RecursiveComparisonAssert<?>> {
+ default AssertionConfiguration andThen(AssertionConfiguration after) {
+ return assertion -> after.apply(apply(assertion));
+ }
}
}
diff --git
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV1Test.java
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV1Test.java
index ffa161ba32e..b4cabb46ba3 100644
---
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV1Test.java
+++
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV1Test.java
@@ -17,9 +17,6 @@
package org.apache.ignite.internal.catalog.storage;
-import java.util.List;
-import org.junit.jupiter.api.Test;
-
/**
* Tests for catalog storage objects. Protocol version 2 reads protocol 1.
*/
@@ -44,16 +41,4 @@ public class CatalogSerializationCompatibilityV2ReadsV1Test
extends CatalogSeria
protected boolean expectExactVersion() {
return false;
}
-
- @Test
- public void alterTableProperties() {
- // TODO: https://issues.apache.org/jira/browse/IGNITE-26632 move to
CatalogSerializationCompatibilityV2ReadsV2Test
- List<UpdateEntry> entries = List.of(
- new AlterTablePropertiesEntry(state.id(), null, null),
- new AlterTablePropertiesEntry(state.id(), 1.0d, null),
- new AlterTablePropertiesEntry(state.id(), null, 10L),
- new AlterTablePropertiesEntry(state.id(), 2.0d, 10L)
- );
- checker.compareEntries(entries, "AlterTableProperties",
entryVersion());
- }
}
diff --git
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV2Test.java
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV2Test.java
index 5c06e766f48..a1506e6c685 100644
---
a/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV2Test.java
+++
b/modules/catalog/src/test/java/org/apache/ignite/internal/catalog/storage/CatalogSerializationCompatibilityV2ReadsV2Test.java
@@ -17,6 +17,10 @@
package org.apache.ignite.internal.catalog.storage;
+import java.util.List;
+import
org.apache.ignite.internal.catalog.storage.serialization.MarshallableEntryType;
+import org.junit.jupiter.api.Test;
+
/**
* Tests for catalog storage objects. Protocol version 2 reads protocol 2.
*/
@@ -41,4 +45,17 @@ public class CatalogSerializationCompatibilityV2ReadsV2Test
extends CatalogSeria
protected boolean expectExactVersion() {
return true;
}
+
+ @Test
+ public void alterTableProperties() {
+ List<UpdateEntry> entries = List.of(
+ new AlterTablePropertiesEntry(state.id(), null, null),
+ new AlterTablePropertiesEntry(state.id(), 1.0d, null),
+ new AlterTablePropertiesEntry(state.id(), null, 10L),
+ new AlterTablePropertiesEntry(state.id(), 2.0d, 10L)
+ );
+
+
checker.addExpectedVersion(MarshallableEntryType.ALTER_TABLE_PROPERTIES.id(),
1);
+ checker.compareEntries(entries, "AlterTableProperties", 1);
+ }
}
diff --git
a/modules/catalog/src/test/resources/serialization_v1/AlterTableProperties_1.bin
b/modules/catalog/src/test/resources/serialization_v2/AlterTableProperties_1.bin
similarity index 100%
rename from
modules/catalog/src/test/resources/serialization_v1/AlterTableProperties_1.bin
rename to
modules/catalog/src/test/resources/serialization_v2/AlterTableProperties_1.bin