From ab8f364646ee5d59c2eb501e6d4328496c09555f Mon Sep 17 00:00:00 2001 From: Scott Sandre Date: Thu, 31 Oct 2024 13:36:53 -0700 Subject: [PATCH] Create ActionSerializerSuite.scala --- .../defaults/ActionSerializerSuite.scala | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/ActionSerializerSuite.scala diff --git a/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/ActionSerializerSuite.scala b/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/ActionSerializerSuite.scala new file mode 100644 index 0000000000..fef4911515 --- /dev/null +++ b/kernel/kernel-defaults/src/test/scala/io/delta/kernel/defaults/ActionSerializerSuite.scala @@ -0,0 +1,50 @@ +/* + * Copyright (2024) The Delta Lake Project Authors. + * + * Licensed 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 io.delta.kernel.defaults; + +import io.delta.kernel.defaults.internal.json.JsonUtils +import io.delta.kernel.internal.actions.Protocol +import org.scalatest.funsuite.AnyFunSuite + +import java.util.Collections +import scala.collection.JavaConverters._ + +// TODO: this class should actually write the actions to a json file and read them back +// TODO: do this for all action types +class ActionSerializerSuite extends AnyFunSuite { + test("protocol to json") { + { + val protocol = new Protocol(1, 2, Collections.emptySet(), Collections.emptySet()) + val json = JsonUtils.rowToJson(protocol.toRow) + assert(json === """{"minReaderVersion":1,"minWriterVersion":2}""") + } + { + val protocol = new Protocol(3, 7, Collections.emptySet(), Collections.emptySet()) + val json = JsonUtils.rowToJson(protocol.toRow) + // scalastyle:off line.size.limit + assert(json === """{"minReaderVersion":3,"minWriterVersion":7,"readerFeatures":[],"writerFeatures":[]}""") + // scalastyle:on line.size.limit + } + { + val protocol = new Protocol(3, 7, Set("columnMapping").asJava, Set("appendOnly").asJava) + val json = JsonUtils.rowToJson(protocol.toRow) + // scalastyle:off line.size.limit + assert(json === """{"minReaderVersion":3,"minWriterVersion":7,"readerFeatures":["columnMapping"],"writerFeatures":["appendOnly"]}""") + // scalastyle:on line.size.limit + } + } +}