opwvhk commented on code in PR #2652:
URL: https://github.com/apache/avro/pull/2652#discussion_r1450514906


##########
lang/java/avro/src/test/java/org/apache/avro/TestUuidConversions.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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
+ *
+ *     https://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.avro;
+
+import org.apache.avro.generic.GenericFixed;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource;
+
+import java.util.UUID;
+import java.util.stream.Stream;
+
+public class TestUuidConversions {
+
+  private Conversions.UUIDConversion uuidConversion = new 
Conversions.UUIDConversion();
+
+  private Schema fixed = Schema.createFixed("fixed", "doc", "", Long.BYTES * 
2);
+  private Schema fixedUUid = LogicalTypes.uuid().addToSchema(fixed);
+
+  @ParameterizedTest
+  @MethodSource("uuidData")
+  void uuidFixed(UUID uuid) {
+    GenericFixed value = uuidConversion.toFixed(uuid, fixedUUid, 
LogicalTypes.uuid());
+    UUID uuid1 = uuidConversion.fromFixed(value, fixedUUid, 
LogicalTypes.uuid());
+    Assertions.assertEquals(uuid, uuid1);
+  }
+
+  @ParameterizedTest
+  @MethodSource("uuidData")
+  void uuidFixedReverse(UUID uuid) {
+    Conversions.UUIDConversion bigEndianConversion = new 
Conversions.UUIDConversion(true);
+    Conversions.UUIDConversion littleEndianConversion = new 
Conversions.UUIDConversion(false);
+
+    // simulate uuid from other endian source, assume it's big endian 
(nevermind if
+    // current jvm is big endian, as we simulate).
+    UUID reverserUUID = new 
UUID(Long.reverseBytes(uuid.getMostSignificantBits()),
+        Long.reverseBytes(uuid.getLeastSignificantBits()));

Review Comment:
   As a UUID is a 128-bit "label", switching between LittleEndian and BigEndian 
byte order also switches the order of the long values: the most significant 64 
bits are in the first half for BE data, but in the last half for LE data.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to