zookeeper-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nkal...@apache.org
Subject [zookeeper] branch master updated: ZOOKEEPER-3836: Use Commons and JDK Functions in ClientBase
Date Mon, 09 Nov 2020 14:33:23 GMT
This is an automated email from the ASF dual-hosted git repository.

nkalmar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new 7f66c76  ZOOKEEPER-3836: Use Commons and JDK Functions in ClientBase
7f66c76 is described below

commit 7f66c7680f7b79eb1ba1cf253b4534de88ad3404
Author: David Mollitor <dmollitor@apache.org>
AuthorDate: Mon Nov 9 15:33:15 2020 +0100

    ZOOKEEPER-3836: Use Commons and JDK Functions in ClientBase
    
    Related to #1357
    
    Author: David Mollitor <dmollitor@apache.org>
    
    Reviewers: Enrico Olivelli <eolivelli@apache.org>, Norbert Kalmar <nkalmar@apache.org>
    
    Closes #1358 from belugabehr/ZOOKEEPER-3836
---
 .../zookeeper/test/AtomicFileOutputStreamTest.java | 16 +++++++------
 .../java/org/apache/zookeeper/test/ClientBase.java | 28 ----------------------
 2 files changed, 9 insertions(+), 35 deletions(-)

diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java
b/zookeeper-server/src/test/java/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java
index 2d93175..a3d7096 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/AtomicFileOutputStreamTest.java
@@ -18,6 +18,7 @@
 
 package org.apache.zookeeper.test;
 
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -27,6 +28,7 @@ import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.nio.file.Files;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.common.AtomicFileOutputStream;
 import org.junit.jupiter.api.AfterEach;
@@ -64,7 +66,7 @@ public class AtomicFileOutputStreamTest extends ZKTestCase {
         fos.close();
         assertTrue(dstFile.exists());
 
-        String readBackData = ClientBase.readFile(dstFile);
+        String readBackData = new String(Files.readAllBytes(dstFile.toPath()), UTF_8);
         assertEquals(TEST_STRING, readBackData);
     }
 
@@ -82,12 +84,12 @@ public class AtomicFileOutputStreamTest extends ZKTestCase {
         fos.flush();
 
         // Original contents still in place
-        assertEquals("", ClientBase.readFile(dstFile));
+        assertEquals("", new String(Files.readAllBytes(dstFile.toPath()), UTF_8));
 
         fos.close();
 
         // New contents replace original file
-        String readBackData = ClientBase.readFile(dstFile);
+        String readBackData = new String(Files.readAllBytes(dstFile.toPath()), UTF_8);
         assertEquals(TEST_STRING, readBackData);
     }
 
@@ -112,9 +114,9 @@ public class AtomicFileOutputStreamTest extends ZKTestCase {
         }
 
         // Should not have touched original file
-        assertEquals(TEST_STRING_2, ClientBase.readFile(dstFile));
+        assertEquals(TEST_STRING_2, new String(Files.readAllBytes(dstFile.toPath()), UTF_8));
 
-        assertEquals(dstFile.getName(), ClientBase.join(",", testDir.list()), "Temporary
file should have been cleaned up");
+        assertEquals(dstFile.getName(), String.join(",", testDir.list()), "Temporary file
should have been cleaned up");
     }
 
     /**
@@ -172,7 +174,7 @@ public class AtomicFileOutputStreamTest extends ZKTestCase {
         fos2.abort();
 
         // Should not have touched original file
-        assertEquals(TEST_STRING, ClientBase.readFile(dstFile));
+        assertEquals(TEST_STRING, new String(Files.readAllBytes(dstFile.toPath()), UTF_8));
         assertEquals(1, testDir.list().length);
     }
 
@@ -193,7 +195,7 @@ public class AtomicFileOutputStreamTest extends ZKTestCase {
         fos2.abort();
 
         // Should not have touched original file
-        assertEquals(TEST_STRING, ClientBase.readFile(dstFile));
+        assertEquals(TEST_STRING, new String(Files.readAllBytes(dstFile.toPath()), UTF_8));
         assertEquals(1, testDir.list().length);
     }
 
diff --git a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientBase.java b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientBase.java
index c628e4f..43c2fad 100644
--- a/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientBase.java
+++ b/zookeeper-server/src/test/java/org/apache/zookeeper/test/ClientBase.java
@@ -23,10 +23,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.junit.jupiter.api.Assertions.fail;
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.net.ConnectException;
 import java.net.ProtocolException;
@@ -52,7 +49,6 @@ import org.apache.zookeeper.Watcher.Event.KeeperState;
 import org.apache.zookeeper.ZKTestCase;
 import org.apache.zookeeper.ZooKeeper;
 import org.apache.zookeeper.client.ZKClientConfig;
-import org.apache.zookeeper.common.IOUtils;
 import org.apache.zookeeper.common.Time;
 import org.apache.zookeeper.common.X509Exception.SSLContextException;
 import org.apache.zookeeper.server.ServerCnxnFactory;
@@ -700,30 +696,6 @@ public abstract class ClientBase extends ZKTestCase {
         }
     }
 
-    public static String readFile(File file) throws IOException {
-        ByteArrayOutputStream os = new ByteArrayOutputStream();
-        BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
-        try {
-            IOUtils.copyBytes(is, os, 1024, true);
-        } finally {
-            is.close();
-        }
-        return os.toString();
-    }
-
-    public static String join(String separator, Object[] parts) {
-        StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        for (Object part : parts) {
-            if (!first) {
-                sb.append(separator);
-                first = false;
-            }
-            sb.append(part);
-        }
-        return sb.toString();
-    }
-
     public static ZooKeeper createZKClient(String cxnString) throws Exception {
         return createZKClient(cxnString, CONNECTION_TIMEOUT);
     }


Mime
View raw message