xtern commented on code in PR #3058:
URL: https://github.com/apache/ignite-3/pull/3058#discussion_r1469640591


##########
modules/catalog/src/test/java/org/apache/ignite/internal/catalog/serialization/CatalogEntrySerializationCompatibilityTest.java:
##########
@@ -0,0 +1,429 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal.catalog.serialization;
+
+import static 
org.apache.ignite.internal.testframework.IgniteTestUtils.assertThrows;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Objects;
+import org.apache.ignite.internal.catalog.Catalog;
+import org.apache.ignite.internal.catalog.storage.UpdateEntry;
+import org.apache.ignite.internal.catalog.storage.VersionedUpdate;
+import org.apache.ignite.internal.util.io.IgniteDataInput;
+import org.apache.ignite.internal.util.io.IgniteDataOutput;
+import org.apache.ignite.lang.MarshallerException;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests to verify catalog storage entries serialization compatibility.
+ */
+public class CatalogEntrySerializationCompatibilityTest {
+    private final CatalogEntrySerializerProvider serializerProvider = (typeId) 
-> {
+        switch (typeId) {
+            case 0:
+                return TestUpdateEntrySerializerV1.INSTANCE;
+
+            case 1:
+                return TestUpdateEntrySerializerV2.INSTANCE;
+
+            case 2:
+                return TestUpdateEntrySerializerV3.INSTANCE;
+
+            default:
+                throw new IllegalArgumentException("Unexpected type: " + 
typeId);
+        }
+    };
+
+    /**
+     * Checks whether the old version of an entity can be read by the new 
version's serializer.
+     */
+    @Test
+    public void readPreviousVersionEntry() {
+        // Writes a version 1 entry, reads it using the version 2 and 3 
serializer.
+        {
+            TestUpdateEntry entryV1 = TestEntryFactory.create(1);
+
+            UpdateLogMarshaller marshallerV1 = new UpdateLogMarshallerImpl(1, 
serializerProvider);
+
+            List<UpdateEntry> entries = List.of(entryV1, entryV1);
+
+            VersionedUpdate update = new VersionedUpdate(1, 2, entries);
+
+            byte[] bytesV1 = marshallerV1.marshall(update);
+
+            VersionedUpdate deserialized = marshallerV1.unmarshall(bytesV1);
+            assertThat(deserialized.entries(), equalTo(entries));
+
+            UpdateLogMarshaller marshallerV2 = new UpdateLogMarshallerImpl(2, 
serializerProvider);
+            deserialized = marshallerV2.unmarshall(bytesV1);
+            assertThat(deserialized.entries(), equalTo(entries));
+
+            UpdateLogMarshaller marshallerV3 = new UpdateLogMarshallerImpl(3, 
serializerProvider);
+            deserialized = marshallerV3.unmarshall(bytesV1);
+            assertThat(deserialized.entries(), equalTo(entries));
+        }
+
+        // Writes a version 2 entry, reads it using the version 3 serializer.
+        {
+            TestUpdateEntryV2 entryV2 = TestEntryFactory.create(2);
+
+            UpdateLogMarshaller marshallerV2 = new UpdateLogMarshallerImpl(2, 
serializerProvider);
+
+            List<UpdateEntry> entries = List.of(entryV2, entryV2);
+            VersionedUpdate update = new VersionedUpdate(1, 2, entries);
+
+            byte[] bytesV2 = marshallerV2.marshall(update);
+
+            VersionedUpdate deserialized = marshallerV2.unmarshall(bytesV2);
+            assertThat(deserialized.entries(), equalTo(entries));
+
+            UpdateLogMarshaller marshallerV3 = new UpdateLogMarshallerImpl(3, 
serializerProvider);
+            deserialized = marshallerV3.unmarshall(bytesV2);
+            assertThat(deserialized.entries(), equalTo(entries));
+        }
+    }
+
+    /**
+     * Checks whether the entry can be written in the previous format.
+     */
+    @Test
+    public void writePreviousVersionEntry() {

Review Comment:
   The purpose of the test is to check whether, after changing the protocol 
version, we can work on the old version. We need to be able to write entries in 
the old format until the entire cluster can use the new format.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to