You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "rpuch (via GitHub)" <gi...@apache.org> on 2024/10/18 11:49:41 UTC
[PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
rpuch opened a new pull request, #4596:
URL: https://github.com/apache/ignite-3/pull/4596
https://issues.apache.org/jira/browse/IGNITE-23494
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #4596:
URL: https://github.com/apache/ignite-3/pull/4596#discussion_r1810047171
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
+ Assignments originalAssignments = force ? Assignments.forced(nodes, 1000L) : Assignments.of(nodes, 1000L);
+
+ byte[] bytes = VersionedSerialization.toBytes(originalAssignments, serializer);
+ Assignments restoredAssignments = VersionedSerialization.fromBytes(bytes, serializer);
+
+ assertThat(restoredAssignments, equalTo(originalAssignments));
+ }
+
+ @Test
+ void v1NotForcedCanBeDeserialized() {
+ byte[] bytes = Base64.getDecoder().decode("Ae++QwMCYQECYgAA6AMAAAAAAAA=");
Review Comment:
Introduced named constants, their names explain what it is
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch merged PR #4596:
URL: https://github.com/apache/ignite-3/pull/4596
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #4596:
URL: https://github.com/apache/ignite-3/pull/4596#discussion_r1810037080
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
+ Assignments originalAssignments = force ? Assignments.forced(nodes, 1000L) : Assignments.of(nodes, 1000L);
+
+ byte[] bytes = VersionedSerialization.toBytes(originalAssignments, serializer);
+ Assignments restoredAssignments = VersionedSerialization.fromBytes(bytes, serializer);
Review Comment:
The test is about ability to restore (in the future) something serialized with version 1 (in the past). The check you mention is not needed in this scenario. Even more, if we change the format and start serializing with version 2, this check will start failing.
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
Posted by "denis-chudov (via GitHub)" <gi...@apache.org>.
denis-chudov commented on code in PR #4596:
URL: https://github.com/apache/ignite-3/pull/4596#discussion_r1808558477
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
+ Assignments originalAssignments = force ? Assignments.forced(nodes, 1000L) : Assignments.of(nodes, 1000L);
+
+ byte[] bytes = VersionedSerialization.toBytes(originalAssignments, serializer);
+ Assignments restoredAssignments = VersionedSerialization.fromBytes(bytes, serializer);
Review Comment:
lets also check that serialization of restoredAssignments also produces those hardcoded bytes, if it's important.
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
+ Assignments originalAssignments = force ? Assignments.forced(nodes, 1000L) : Assignments.of(nodes, 1000L);
+
+ byte[] bytes = VersionedSerialization.toBytes(originalAssignments, serializer);
+ Assignments restoredAssignments = VersionedSerialization.fromBytes(bytes, serializer);
+
+ assertThat(restoredAssignments, equalTo(originalAssignments));
+ }
+
+ @Test
+ void v1NotForcedCanBeDeserialized() {
+ byte[] bytes = Base64.getDecoder().decode("Ae++QwMCYQECYgAA6AMAAAAAAAA=");
Review Comment:
what is this?) let's do this magic base64 constant and explain what is stored there
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
Review Comment:
lets test multi-letter names as well
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] IGNITE-23494 Do not use ByteUtils#toBytes to serialize assignments [ignite-3]
Posted by "rpuch (via GitHub)" <gi...@apache.org>.
rpuch commented on code in PR #4596:
URL: https://github.com/apache/ignite-3/pull/4596#discussion_r1810047557
##########
modules/partition-distribution/src/test/java/org/apache/ignite/internal/partitiondistribution/AssignmentsSerializerTest.java:
##########
@@ -0,0 +1,86 @@
+/*
+ * 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.partitiondistribution;
+
+import static java.util.Comparator.comparing;
+import static java.util.stream.Collectors.toList;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.is;
+
+import java.util.Base64;
+import java.util.List;
+import java.util.Set;
+import org.apache.ignite.internal.versioned.VersionedSerialization;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
+
+class AssignmentsSerializerTest {
+ private final AssignmentsSerializer serializer = new AssignmentsSerializer();
+
+ @ParameterizedTest
+ @ValueSource(booleans = {true, false})
+ void serializationAndDeserialization(boolean force) {
+ Set<Assignment> nodes = Set.of(Assignment.forPeer("a"), Assignment.forLearner("b"));
Review Comment:
Changed names to longer ones
--
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-unsubscribe@ignite.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org