You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by vi...@apache.org on 2019/02/13 11:16:44 UTC
[hadoop] branch branch-3.1 updated: HADOOP-16108. Tail Follow
Interval Should Allow To Specify The Sleep Interval To Save Unnecessary
RPC's. Contributed by Ayush Saxena.
This is an automated email from the ASF dual-hosted git repository.
vinayakumarb pushed a commit to branch branch-3.1
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.1 by this push:
new c450f9f HADOOP-16108. Tail Follow Interval Should Allow To Specify The Sleep Interval To Save Unnecessary RPC's. Contributed by Ayush Saxena.
c450f9f is described below
commit c450f9f2c427b1716e0d6a318be91f1b9dd41537
Author: Vinayakumar B <vi...@apache.org>
AuthorDate: Wed Feb 13 09:29:37 2019 +0530
HADOOP-16108. Tail Follow Interval Should Allow To Specify The Sleep Interval To Save Unnecessary RPC's. Contributed by Ayush Saxena.
---
.../main/java/org/apache/hadoop/fs/shell/Tail.java | 25 ++++++++--
.../java/org/apache/hadoop/fs/shell/TestTail.java | 57 ++++++++++++++++++++++
.../hadoop-common/src/test/resources/testConf.xml | 6 ++-
3 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java
index 1d49bf1..8a75a60 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/Tail.java
@@ -28,6 +28,8 @@ import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.PathIsDirectoryException;
import org.apache.hadoop.io.IOUtils;
+import com.google.common.annotations.VisibleForTesting;
+
/**
* Get a listing of all files in that match the file patterns.
*/
@@ -40,20 +42,37 @@ class Tail extends FsCommand {
}
public static final String NAME = "tail";
- public static final String USAGE = "[-f] <file>";
+ public static final String USAGE = "[-f] [-s <sleep interval>] <file>";
public static final String DESCRIPTION =
- "Show the last 1KB of the file.\n" +
- "-f: Shows appended data as the file grows.\n";
+ "Show the last 1KB of the file.\n"
+ + "-f: Shows appended data as the file grows.\n"
+ + "-s: With -f , "
+ + "defines the sleep interval between iterations in milliseconds.\n";
private long startingOffset = -1024;
private boolean follow = false;
private long followDelay = 5000; // milliseconds
+ @VisibleForTesting
+ public long getFollowDelay() {
+ return followDelay;
+ }
+
@Override
protected void processOptions(LinkedList<String> args) throws IOException {
CommandFormat cf = new CommandFormat(1, 1, "f");
+ cf.addOptionWithValue("s");
cf.parse(args);
follow = cf.getOpt("f");
+ if (follow) {
+ String sleep = cf.getOptValue("s");
+ if (sleep != null && !sleep.isEmpty()) {
+ long sleepInterval = Long.parseLong(sleep);
+ if (sleepInterval > 0) {
+ followDelay = sleepInterval;
+ }
+ }
+ }
}
// TODO: HADOOP-7234 will add glob support; for now, be backwards compat
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestTail.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestTail.java
new file mode 100644
index 0000000..31a5a4e
--- /dev/null
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/shell/TestTail.java
@@ -0,0 +1,57 @@
+/**
+ * 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.hadoop.fs.shell;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.util.LinkedList;
+
+import org.junit.Test;
+
+/**
+ * Test class to verify Tail shell command.
+ */
+public class TestTail {
+
+ // check follow delay with -s parameter.
+ @Test
+ public void testSleepParameter() throws IOException {
+ Tail tail = new Tail();
+ LinkedList<String> options = new LinkedList<String>();
+ options.add("-f");
+ options.add("-s");
+ options.add("10000");
+ options.add("/path");
+ tail.processOptions(options);
+ assertEquals(10000, tail.getFollowDelay());
+ }
+
+ // check follow delay without -s parameter.
+ @Test
+ public void testFollowParameter() throws IOException {
+ Tail tail = new Tail();
+ LinkedList<String> options = new LinkedList<String>();
+ options.add("-f");
+ options.add("/path");
+ tail.processOptions(options);
+ // Follow delay should be the default 5000 ms.
+ assertEquals(5000, tail.getFollowDelay());
+ }
+}
\ No newline at end of file
diff --git a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml
index 1798563..29a88fc 100644
--- a/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml
+++ b/hadoop-common-project/hadoop-common/src/test/resources/testConf.xml
@@ -1001,7 +1001,7 @@
<comparators>
<comparator>
<type>RegexpComparator</type>
- <expected-output>^-tail \[-f\] <file> :\s*</expected-output>
+ <expected-output>^-tail \[-f\] \[-s <sleep interval>\] <file> :\s*</expected-output>
</comparator>
<comparator>
<type>RegexpComparator</type>
@@ -1011,6 +1011,10 @@
<type>RegexpComparator</type>
<expected-output>^( |\t)*-f\s+Shows appended data as the file grows.( )*</expected-output>
</comparator>
+ <comparator>
+ <type>RegexpComparator</type>
+ <expected-output>^( |\t)*-s\s+With -f , defines the sleep interval between iterations in milliseconds.( )*</expected-output>
+ </comparator>
</comparators>
</test>
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org