From 9bc99ba7ae717d91334cc0111e03afa832db6e50 Mon Sep 17 00:00:00 2001 From: Xinyuan Lin Date: Fri, 27 Nov 2026 14:31:48 -0800 Subject: [PATCH] test(amber): remove the duplicate local-file document spec Workflow Core's ReadonlyLocalFileDocumentSpec, added by #6095, makes every assertion this Amber suite makes: the URI, the backing file, reading through an input stream, and the five unsupported accessors, with exact messages instead of substrings. DocumentFactorySpec covers the factory's file-scheme dispatch that this suite went through. --- .../ReadonlyLocalFileDocumentSpec.scala | 111 ------------------ 1 file changed, 111 deletions(-) delete mode 100644 amber/src/test/scala/org/apache/texera/workflow/common/storage/ReadonlyLocalFileDocumentSpec.scala diff --git a/amber/src/test/scala/org/apache/texera/workflow/common/storage/ReadonlyLocalFileDocumentSpec.scala b/amber/src/test/scala/org/apache/texera/workflow/common/storage/ReadonlyLocalFileDocumentSpec.scala deleted file mode 100644 index a5837bed8b8..00000000000 --- a/amber/src/test/scala/org/apache/texera/workflow/common/storage/ReadonlyLocalFileDocumentSpec.scala +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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.texera.amber.engine.common.storage - -import org.apache.texera.amber.core.storage.DocumentFactory -import org.apache.texera.amber.core.storage.model.ReadonlyVirtualDocument -import org.scalatest.BeforeAndAfter -import org.scalatest.flatspec.AnyFlatSpec -import org.scalatest.matchers.should.Matchers - -import java.io.{ByteArrayOutputStream, File, InputStream} -import java.nio.file.Files -import scala.util.Using - -class ReadonlyLocalFileDocumentSpec extends AnyFlatSpec with Matchers with BeforeAndAfter { - - var tempFile: File = _ - var fileDocument: ReadonlyVirtualDocument[_] = _ - - val initialContent = - "Initial Content\nsome more content to make the text longer\nadf\t\ttestteset" - - before { - // Create a temporary file with initial content - tempFile = File.createTempFile("test", ".txt") - Files.write(tempFile.toPath, initialContent.getBytes) - fileDocument = DocumentFactory.openReadonlyDocument(tempFile.toURI) - } - - after { - // Delete the temporary file - Files.deleteIfExists(tempFile.toPath) - } - - private def readAllBytes(inputStream: InputStream): Array[Byte] = { - val buffer = new ByteArrayOutputStream() - val data = new Array[Byte](1024) - var nRead = 0 - while ({ - nRead = inputStream.read(data, 0, data.length) - nRead != -1 - }) { - buffer.write(data, 0, nRead) - } - buffer.flush() - buffer.toByteArray - } - - "ReadonlyLocalFileDocument" should "correctly report its URI" in { - fileDocument.getURI should be(tempFile.toURI) - } - - it should "allow reading from the file" in { - val content = Using(fileDocument.asInputStream()) { inStream => - new String(readAllBytes(inStream)) - }.getOrElse(fail("Failed to read from the file")) - - content should equal(initialContent) - } - - it should "return the file itself when asFile is called" in { - fileDocument.asFile() should be(tempFile) - } - - it should "throw NotImplementedError for unsupported getItem method" in { - intercept[NotImplementedError] { - fileDocument.getItem(0) - }.getMessage should include("getItem is not supported") - } - - it should "throw NotImplementedError for unsupported get method" in { - intercept[NotImplementedError] { - fileDocument.get() - }.getMessage should include("get is not supported") - } - - it should "throw NotImplementedError for unsupported getRange method" in { - intercept[NotImplementedError] { - fileDocument.getRange(0, 1) - }.getMessage should include("getRange is not supported") - } - - it should "throw NotImplementedError for unsupported getAfter method" in { - intercept[NotImplementedError] { - fileDocument.getAfter(0) - }.getMessage should include("getAfter is not supported") - } - - it should "throw NotImplementedError for unsupported getCount method" in { - intercept[NotImplementedError] { - fileDocument.getCount - }.getMessage should include("getCount is not supported") - } -}