You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zookeeper.apache.org by maoling <gi...@git.apache.org> on 2018/09/16 13:02:13 UTC
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
GitHub user maoling opened a pull request:
https://github.com/apache/zookeeper/pull/630
ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does not handle FileNotFoundException gracefully
- More details in [ZOOKEEPER-2284](https://issues.apache.org/jira/browse/ZOOKEEPER-2284) .Thanks [arshad.mohammad](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=arshad.mohammad) for original work!
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/maoling/zookeeper ZOOKEEPER-2284
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/zookeeper/pull/630.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #630
----
commit e41ddc261e4ee2d97cc26f5eda664e9abe849807
Author: maoling <ma...@...>
Date: 2018-09-16T12:36:50Z
ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does not handle FileNotFoundException gracefully
----
---
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
Posted by maoling <gi...@git.apache.org>.
GitHub user maoling reopened a pull request:
https://github.com/apache/zookeeper/pull/630
ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does not handle FileNotFoundException gracefully
- More details in [ZOOKEEPER-2284](https://issues.apache.org/jira/browse/ZOOKEEPER-2284) .Thanks [arshad.mohammad](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=arshad.mohammad) for original work!
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/maoling/zookeeper ZOOKEEPER-2284
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/zookeeper/pull/630.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #630
----
commit e41ddc261e4ee2d97cc26f5eda664e9abe849807
Author: maoling <ma...@...>
Date: 2018-09-16T12:36:50Z
ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does not handle FileNotFoundException gracefully
----
---
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/630#discussion_r218679868
--- Diff: src/java/test/org/apache/zookeeper/ZKUtilTest.java ---
@@ -0,0 +1,88 @@
+/**
+ * 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.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ZKUtilTest {
+ private static final File testData = new File(System.getProperty("test.data.dir", "build/test/data"));
+
+ @BeforeClass
+ public static void init() {
+ testData.mkdirs();
+ }
+
+ @Test
+ public void testValidateFileInput() throws IOException {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNull(error);
+ }
+
+ @Test
+ public void testValidateFileInputNotExist() {
+ String fileName = UUID.randomUUID().toString();
+ File file = new File(testData, fileName);
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "File '" + absolutePath + "' does not exist.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testValidateFileInputDirectory() throws Exception {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ // delete file, as we need directory not file
+ file.delete();
+ file.mkdir();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testUnreadableFileInput() throws Exception {
+ //skip this test on Windows, coverage on Linux
+ assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
+ File file = File.createTempFile("test", ".junit", testData);
+ file.setReadable(false, false);
+ file.deleteOnExit();
--- End diff --
Why not an explicit delete ?
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on the issue:
https://github.com/apache/zookeeper/pull/630
retest this please
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:
https://github.com/apache/zookeeper/pull/630
Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/2220/
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:
https://github.com/apache/zookeeper/pull/630
Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/2379/
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on the issue:
https://github.com/apache/zookeeper/pull/630
retest this please
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:
https://github.com/apache/zookeeper/pull/630
Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/2218/
---
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
Posted by maoling <gi...@git.apache.org>.
Github user maoling commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/630#discussion_r219150200
--- Diff: src/java/test/org/apache/zookeeper/ZKUtilTest.java ---
@@ -0,0 +1,88 @@
+/**
+ * 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.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ZKUtilTest {
+ private static final File testData = new File(System.getProperty("test.data.dir", "build/test/data"));
+
+ @BeforeClass
+ public static void init() {
+ testData.mkdirs();
+ }
+
+ @Test
+ public void testValidateFileInput() throws IOException {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNull(error);
+ }
+
+ @Test
+ public void testValidateFileInputNotExist() {
+ String fileName = UUID.randomUUID().toString();
+ File file = new File(testData, fileName);
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "File '" + absolutePath + "' does not exist.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testValidateFileInputDirectory() throws Exception {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ // delete file, as we need directory not file
+ file.delete();
+ file.mkdir();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testUnreadableFileInput() throws Exception {
+ //skip this test on Windows, coverage on Linux
+ assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
+ File file = File.createTempFile("test", ".junit", testData);
+ file.setReadable(false, false);
+ file.deleteOnExit();
--- End diff --
@eolivelli
file.deleteOnExit() will delete the file after JVM exit.it is equivalent to file.delete() at the end.
so we should not worry about this.
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on the issue:
https://github.com/apache/zookeeper/pull/630
I am working with CI integration. Sorry for the confusion
---
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
Posted by maoling <gi...@git.apache.org>.
Github user maoling closed the pull request at:
https://github.com/apache/zookeeper/pull/630
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by asfgit <gi...@git.apache.org>.
Github user asfgit commented on the issue:
https://github.com/apache/zookeeper/pull/630
Can one of the admins verify this patch?
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by maoling <gi...@git.apache.org>.
Github user maoling commented on the issue:
https://github.com/apache/zookeeper/pull/630
https://builds.apache.org/job/PreCommit-ZOOKEEPER-github-pr-build/2218/ may be not related.
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by dineshappavoo <gi...@git.apache.org>.
Github user dineshappavoo commented on the issue:
https://github.com/apache/zookeeper/pull/630
LGTM. 👍
---
[GitHub] zookeeper issue #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatter does...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on the issue:
https://github.com/apache/zookeeper/pull/630
Why did you close this one?
---
[GitHub] zookeeper pull request #630: ZOOKEEPER-2284:LogFormatter and SnapshotFormatt...
Posted by eolivelli <gi...@git.apache.org>.
Github user eolivelli commented on a diff in the pull request:
https://github.com/apache/zookeeper/pull/630#discussion_r219151901
--- Diff: src/java/test/org/apache/zookeeper/ZKUtilTest.java ---
@@ -0,0 +1,88 @@
+/**
+ * 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.zookeeper;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.UUID;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class ZKUtilTest {
+ private static final File testData = new File(System.getProperty("test.data.dir", "build/test/data"));
+
+ @BeforeClass
+ public static void init() {
+ testData.mkdirs();
+ }
+
+ @Test
+ public void testValidateFileInput() throws IOException {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNull(error);
+ }
+
+ @Test
+ public void testValidateFileInputNotExist() {
+ String fileName = UUID.randomUUID().toString();
+ File file = new File(testData, fileName);
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "File '" + absolutePath + "' does not exist.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testValidateFileInputDirectory() throws Exception {
+ File file = File.createTempFile("test", ".junit", testData);
+ file.deleteOnExit();
+ // delete file, as we need directory not file
+ file.delete();
+ file.mkdir();
+ String absolutePath = file.getAbsolutePath();
+ String error = ZKUtil.validateFileInput(absolutePath);
+ assertNotNull(error);
+ String expectedMessage = "'" + absolutePath + "' is a direcory. it must be a file.";
+ assertEquals(expectedMessage, error);
+ }
+
+ @Test
+ public void testUnreadableFileInput() throws Exception {
+ //skip this test on Windows, coverage on Linux
+ assumeTrue(!org.apache.zookeeper.Shell.WINDOWS);
+ File file = File.createTempFile("test", ".junit", testData);
+ file.setReadable(false, false);
+ file.deleteOnExit();
--- End diff --
Personally I don't like File#deleteOnExit because it is not clear when it will take effect, and it is clearer to have an explicit file.delete when the file is not needed anymore.
In this case, for this simple test, I have no strong objection.
The best solution would be to use JUnit TemporaryFolder Rule.
---