From 44a574951b0246dc25e39d0770544e4987efeda5 Mon Sep 17 00:00:00 2001 From: HÃ¥kon Hallingstad Date: Mon, 7 Oct 2019 16:44:03 +0200 Subject: Support atomic writes with FileWriter --- .../hosted/node/admin/task/util/file/FileWriterTest.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'node-admin/src/test/java/com/yahoo') diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileWriterTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileWriterTest.java index 2bc64a3fdb3..e1a0ed5d972 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileWriterTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/task/util/file/FileWriterTest.java @@ -21,6 +21,7 @@ import static org.mockito.Mockito.verify; public class FileWriterTest { private final FileSystem fileSystem = TestFileSystem.create(); + private final TaskContext context = mock(TaskContext.class); @Test public void testWrite() { @@ -35,7 +36,6 @@ public class FileWriterTest { .withOwner(owner) .withGroup(group) .onlyIfFileDoesNotAlreadyExist(); - TaskContext context = mock(TaskContext.class); assertTrue(writer.converge(context)); verify(context, times(1)).recordSystemModification(any(), eq("Creating file " + path)); @@ -50,4 +50,15 @@ public class FileWriterTest { assertFalse(writer.converge(context)); assertEquals(fileTime, unixPath.getLastModifiedTime()); } + + @Test + public void testAtomicWrite() { + FileWriter writer = new FileWriter(fileSystem.getPath("/foo/bar")) + .atomicWrite(true); + + assertTrue(writer.converge(context, "content")); + + verify(context).recordSystemModification(any(), eq("Creating file /foo/bar")); + assertEquals("content", new UnixPath(writer.path()).readUtf8File()); + } } -- cgit v1.2.3