diff options
-rw-r--r-- | documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/TestFileUtil.java | 12 | ||||
-rw-r--r-- | documentapi/src/tests/messages/testbase.cpp | 14 |
2 files changed, 6 insertions, 20 deletions
diff --git a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/TestFileUtil.java b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/TestFileUtil.java index 722e42bc3a5..8bc6f56e574 100644 --- a/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/TestFileUtil.java +++ b/documentapi/src/test/java/com/yahoo/documentapi/messagebus/protocol/test/TestFileUtil.java @@ -4,26 +4,16 @@ package com.yahoo.documentapi.messagebus.protocol.test; import java.io.FileOutputStream; import java.io.IOException; import java.nio.charset.Charset; -import java.nio.file.FileSystems; import java.nio.file.Files; -import java.nio.file.Path; import java.nio.file.Paths; -import static java.nio.file.StandardCopyOption.ATOMIC_MOVE; - public class TestFileUtil { protected static final String DATA_PATH = "./test/crosslanguagefiles"; public static void writeToFile(String path, byte[] data) throws IOException { - // Write to a temporary file to avoid racing with cross-language tests reading the - // exact same file we're trying to write. - String tmpPath = path + ".tmp"; - try (FileOutputStream stream = new FileOutputStream(tmpPath)) { + try (FileOutputStream stream = new FileOutputStream(path)) { stream.write(data); } - // We make the assumption that all file systems we run these tests on support some form - // of atomic moving rather than "move by content copy". - Files.move(FileSystems.getDefault().getPath(tmpPath), FileSystems.getDefault().getPath(path), ATOMIC_MOVE); } /** diff --git a/documentapi/src/tests/messages/testbase.cpp b/documentapi/src/tests/messages/testbase.cpp index 9ccaa7abf2f..02c180853d4 100644 --- a/documentapi/src/tests/messages/testbase.cpp +++ b/documentapi/src/tests/messages/testbase.cpp @@ -175,18 +175,14 @@ TestBase::dump(const mbus::Blob& blob) const bool TestBase::writeFile(const string &filename, const mbus::Blob& blob) const { - std::string tmp_filename = filename + ".tmp"; - int file = open(tmp_filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); + int file = open(filename.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0644); if (file == -1) { return false; } - if (write(file, blob.data(), blob.size()) != static_cast<ssize_t>(blob.size())) { - throw vespalib::Exception("write failed"); + if (write(file, blob.data(), blob.size()) != (ssize_t)blob.size()) { + throw vespalib::Exception("write failed"); } close(file); - if (rename(tmp_filename.c_str(), filename.c_str()) != 0) { - throw vespalib::Exception("rename failed"); - } return true; } @@ -199,8 +195,8 @@ TestBase::readFile(const string &filename) const if (file != -1) { lseek(file, 0, SEEK_SET); if (read(file, blob.data(), len) != len) { - throw vespalib::Exception("read failed"); - } + throw vespalib::Exception("read failed"); + } close(file); } |